Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: tests/ppapi_test_lib/test_interface.h

Issue 7292002: Remove plugin connection to PPAPI scriptable objects (var deprecated). Also (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. 1 // Copyright (c) 2011 The Native Client Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Functions and constants for test registration and setup. 5 // Functions and constants for test registration and setup.
6 // 6 //
7 // NOTE: These must be implemented by the tester: 7 // NOTE: These must be implemented by the tester:
8 // - SetupTests() 8 // - SetupTests()
9 // - SetupPluginInterfaces() 9 // - SetupPluginInterfaces()
10 // 10 //
11 // Sample Usage: 11 // Sample Usage:
12 // 12 //
13 // void MyCallback(void* user_data, int32_t result) { ... } 13 // void MyCallback(void* user_data, int32_t result) { ... }
14 // 14 //
15 // PP_Var TestPPBFooDeprecated() { 15 // PP_Var TestPPBFooDeprecated() {
polina 2011/07/12 08:58:01 please remove
sehr (please use chromium) 2011/07/12 16:44:23 Done.
16 // // sync test case 16 // // sync test case
17 // PP_Resource my_resource = PPBFoo()->Create(kInvalidInstance); 17 // PP_Resource my_resource = PPBFoo()->Create(kInvalidInstance);
18 // EXPECT(my_resource == kInvalidResource); 18 // EXPECT(my_resource == kInvalidResource);
19 // 19 //
20 // // async test case 20 // // async test case
21 // PP_CompletionCallback testable_callback = MakeTestableCompletionCallback( 21 // PP_CompletionCallback testable_callback = MakeTestableCompletionCallback(
22 // "MyCallback", MyCallback, NULL); 22 // "MyCallback", MyCallback, NULL);
23 // int32_t pp_error = PPBFoo()->AsyncFunction(testable_callback); 23 // int32_t pp_error = PPBFoo()->AsyncFunction(testable_callback);
24 // EXPECT(pp_error == PP_OK_COMPLETIONPENDING); 24 // EXPECT(pp_error == PP_OK_COMPLETIONPENDING);
25 // 25 //
26 // return TEST_PASSED; 26 // return TEST_PASSED;
27 // } 27 // }
28 // 28 //
29 // void TestPPBFoo() { 29 // void TestPPBFoo() {
30 // // sync test case 30 // // sync test case
31 // PP_Resource my_resource = PPBFoo()->Create(kInvalidInstance); 31 // PP_Resource my_resource = PPBFoo()->Create(kInvalidInstance);
32 // EXPECT_ASYNC(my_resource == kInvalidResource); 32 // EXPECT_ASYNC(my_resource == kInvalidResource);
polina 2011/07/12 08:58:01 If it's not too much trouble, could you also pleas
sehr (please use chromium) 2011/07/12 16:44:23 Done.
33 // 33 //
34 // // async test case 34 // // async test case
35 // PP_CompletionCallback testable_callback = MakeTestableCompletionCallback( 35 // PP_CompletionCallback testable_callback = MakeTestableCompletionCallback(
36 // "MyCallback", MyCallback, NULL); 36 // "MyCallback", MyCallback, NULL);
37 // int32_t pp_error = PPBFoo()->AsyncFunction(testable_callback); 37 // int32_t pp_error = PPBFoo()->AsyncFunction(testable_callback);
38 // EXPECT_ASYNC(pp_error == PP_OK_COMPLETIONPENDING); 38 // EXPECT_ASYNC(pp_error == PP_OK_COMPLETIONPENDING);
39 // 39 //
40 // TEST_PASSED_ASYNC; 40 // TEST_PASSED_ASYNC;
41 // } 41 // }
42 // 42 //
43 // void SetupTests() { 43 // void SetupTests() {
44 // RegisterScriptableTest("TestFooDeprecated", TestPPBFooDeprecated);
45 // RegisterTest("TestPPBFoo", TestPPBFoo); 44 // RegisterTest("TestPPBFoo", TestPPBFoo);
46 // } 45 // }
47 // 46 //
48 // const PPP_Bar ppp_bar_interface = { ... }; 47 // const PPP_Bar ppp_bar_interface = { ... };
49 // 48 //
50 // void SetupPluginInterface() { 49 // void SetupPluginInterface() {
51 // RegisterPluginInterface(PPP_BAR_INTERFACE, &ppp_bar_interface); 50 // RegisterPluginInterface(PPP_BAR_INTERFACE, &ppp_bar_interface);
52 // } 51 // }
53 // 52 //
54 53
55 #ifndef NATIVE_CLIENT_TESTS_PPAPI_TEST_PPB_TEMPLATE_TEST_INTERFACE_H 54 #ifndef NATIVE_CLIENT_TESTS_PPAPI_TEST_PPB_TEMPLATE_TEST_INTERFACE_H
56 #define NATIVE_CLIENT_TESTS_PPAPI_TEST_PPB_TEMPLATE_TEST_INTERFACE_H 55 #define NATIVE_CLIENT_TESTS_PPAPI_TEST_PPB_TEMPLATE_TEST_INTERFACE_H
57 56
58 #include <stdio.h> 57 #include <stdio.h>
59 #include <limits> 58 #include <limits>
60 59
61 #include "native_client/src/include/nacl_string.h" 60 #include "native_client/src/include/nacl_string.h"
62 61
63 #include "ppapi/c/pp_completion_callback.h" 62 #include "ppapi/c/pp_completion_callback.h"
64 #include "ppapi/c/pp_instance.h" 63 #include "ppapi/c/pp_instance.h"
65 #include "ppapi/c/pp_module.h" 64 #include "ppapi/c/pp_module.h"
66 #include "ppapi/c/pp_resource.h" 65 #include "ppapi/c/pp_resource.h"
67 #include "ppapi/c/pp_var.h" 66 #include "ppapi/c/pp_var.h"
68 67
69 //////////////////////////////////////////////////////////////////////////////// 68 ////////////////////////////////////////////////////////////////////////////////
70 // These must be implemented by the tester 69 // These must be implemented by the tester
71 //////////////////////////////////////////////////////////////////////////////// 70 ////////////////////////////////////////////////////////////////////////////////
72 71
73 // Use RegisterTest() to register each TestFunction. 72 // Use RegisterTest() to register each TestFunction.
74 // Use RegisterScriptableTest() to register each ScriptableTestFunction.
75 void SetupTests(); 73 void SetupTests();
76 // Use RegisterPluginInterface() to register custom PPP_ interfaces other than 74 // Use RegisterPluginInterface() to register custom PPP_ interfaces other than
77 // PPP_Instance that is required and provided by default. 75 // PPP_Instance that is required and provided by default.
78 void SetupPluginInterfaces(); 76 void SetupPluginInterfaces();
79 77
80 //////////////////////////////////////////////////////////////////////////////// 78 ////////////////////////////////////////////////////////////////////////////////
81 // Test helpers 79 // Test helpers
82 //////////////////////////////////////////////////////////////////////////////// 80 ////////////////////////////////////////////////////////////////////////////////
83 81
84 // Registers test_function, so it is callable from JS using 82 // Registers test_function, so it is callable from JS using
85 // plugin.postMessage(test_name); 83 // plugin.postMessage(test_name);
86 typedef void (*TestFunction)(); 84 typedef void (*TestFunction)();
87 void RegisterTest(nacl::string test_name, TestFunction test_function); 85 void RegisterTest(nacl::string test_name, TestFunction test_function);
88 86
89 // DEPRECATED: Registers test_function, so it is callable from JS
90 // using plugin.test_name().
91 typedef PP_Var (*ScriptableTestFunction)();
92 void RegisterScriptableTest(nacl::string test_name,
93 ScriptableTestFunction test_function);
94
95 // Registers ppp_interface, so it is returned by PPP_GetInterface(). 87 // Registers ppp_interface, so it is returned by PPP_GetInterface().
96 void RegisterPluginInterface(const char* interface_name, 88 void RegisterPluginInterface(const char* interface_name,
97 const void* ppp_interface); 89 const void* ppp_interface);
98 90
99 // Helper for creating user callbacks whose invocation will be reported to JS. 91 // Helper for creating user callbacks whose invocation will be reported to JS.
100 PP_CompletionCallback MakeTestableCompletionCallback( 92 PP_CompletionCallback MakeTestableCompletionCallback(
101 const char* callback_name, // same as passed JS waitForCallback() 93 const char* callback_name, // same as passed JS waitForCallback()
102 PP_CompletionCallback_Func func, 94 PP_CompletionCallback_Func func,
103 void* user_data); 95 void* user_data);
104 96
105 // Uses PPB_Messaging interface to post "test_name:message". 97 // Uses PPB_Messaging interface to post "test_name:message".
106 void PostTestMessage(nacl::string test_name, nacl::string message); 98 void PostTestMessage(nacl::string test_name, nacl::string message);
107 99
108 // Use these macros to verify the result of a test and report failures. 100 // Use these macros to verify the result of a test and report failures.
polina 2011/07/12 08:58:01 s/these macros//
sehr (please use chromium) 2011/07/12 16:44:23 Done.
109 // TODO(polina): rename EXPECT_ASYNC to EXPECT when sync scripting is removed. 101 // TODO(polina): rename EXPECT_ASYNC to EXPECT when sync scripting is removed.
110 #define EXPECT_ASYNC(expr) do { \ 102 #define EXPECT_ASYNC(expr) do { \
111 if (!(expr)) { \ 103 if (!(expr)) { \
112 char error[1024]; \ 104 char error[1024]; \
113 snprintf(error, sizeof(error), \ 105 snprintf(error, sizeof(error), \
114 "ERROR at %s:%d: %s\n", __FILE__, __LINE__, #expr); \ 106 "ERROR at %s:%d: %s\n", __FILE__, __LINE__, #expr); \
115 fprintf(stderr, "%s", error); \ 107 fprintf(stderr, "%s", error); \
116 PostTestMessage(__FUNCTION__, error); \ 108 PostTestMessage(__FUNCTION__, error); \
117 } \ 109 } \
118 } while (0) 110 } while (0)
119 111
120 #define EXPECT(expr) do { \ 112 #define EXPECT(expr) do { \
polina 2011/07/12 08:58:01 this can go away
sehr (please use chromium) 2011/07/12 16:44:23 Done.
121 if (!(expr)) { \ 113 if (!(expr)) { \
122 char error[1024]; \ 114 char error[1024]; \
123 snprintf(error, sizeof(error), \ 115 snprintf(error, sizeof(error), \
124 "ERROR at %s:%d: %s\n", __FILE__, __LINE__, #expr); \ 116 "ERROR at %s:%d: %s\n", __FILE__, __LINE__, #expr); \
125 fprintf(stderr, "%s", error); \ 117 fprintf(stderr, "%s", error); \
126 return PP_MakeBool(PP_FALSE); \ 118 return PP_MakeBool(PP_FALSE); \
127 } \ 119 } \
128 } while (0) 120 } while (0)
129 121
130 // Use these macros to report success. 122 // Use these macros to report success.
polina 2011/07/12 08:58:01 s/these macros//
sehr (please use chromium) 2011/07/12 16:44:23 Done.
131 #define TEST_PASSED_ASYNC PostTestMessage(__FUNCTION__, "PASSED"); 123 #define TEST_PASSED_ASYNC PostTestMessage(__FUNCTION__, "PASSED");
132 #define TEST_PASSED PP_MakeBool(PP_TRUE) // Usage: return TEST_PASSED; 124 #define TEST_PASSED PP_MakeBool(PP_TRUE) // Usage: return TEST_PASSED;
polina 2011/07/12 08:58:01 this can go away
sehr (please use chromium) 2011/07/12 16:44:23 Done.
133 125
134 // Use this constant for stress testing 126 // Use this constant for stress testing
135 // (i.e. creating and using a large number of resources). 127 // (i.e. creating and using a large number of resources).
136 const int kManyResources = 1000; 128 const int kManyResources = 1000;
137 129
138 const PP_Instance kInvalidInstance = 0; 130 const PP_Instance kInvalidInstance = 0;
139 const PP_Module kInvalidModule = 0; 131 const PP_Module kInvalidModule = 0;
140 const PP_Resource kInvalidResource = 0; 132 const PP_Resource kInvalidResource = 0;
141 133
142 // These should not exist. 134 // These should not exist.
143 // Chrome uses the bottom 2 bits to differentiate between different id types. 135 // Chrome uses the bottom 2 bits to differentiate between different id types.
144 // 00 - module, 01 - instance, 10 - resource, 11 - var. 136 // 00 - module, 01 - instance, 10 - resource, 11 - var.
145 const PP_Instance kNotAnInstance = 0xFFFFF0; 137 const PP_Instance kNotAnInstance = 0xFFFFF0;
146 const PP_Resource kNotAResource = 0xAAAAA0; 138 const PP_Resource kNotAResource = 0xAAAAA0;
147 139
148 // Interface pointers and ids corresponding to this plugin; 140 // Interface pointers and ids corresponding to this plugin;
149 // set at initialization/creation. 141 // set at initialization/creation.
150 PP_Instance pp_instance(); 142 PP_Instance pp_instance();
151 PP_Module pp_module(); 143 PP_Module pp_module();
152 144
153 #endif // NATIVE_CLIENT_TESTS_PPAPI_TEST_PPB_TEMPLATE_TEST_INTERFACE_H 145 #endif // NATIVE_CLIENT_TESTS_PPAPI_TEST_PPB_TEMPLATE_TEST_INTERFACE_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698