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

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
« no previous file with comments | « tests/ppapi_test_lib/scriptable_object.cc ('k') | tests/ppapi_test_lib/test_interface.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // void TestPPBFoo() {
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 // TEST_PASSED;
27 // }
28 //
29 // void TestPPBFoo() {
30 // // sync test case
31 // PP_Resource my_resource = PPBFoo()->Create(kInvalidInstance);
32 // EXPECT_ASYNC(my_resource == kInvalidResource);
33 //
34 // // async test case
35 // PP_CompletionCallback testable_callback = MakeTestableCompletionCallback(
36 // "MyCallback", MyCallback, NULL);
37 // int32_t pp_error = PPBFoo()->AsyncFunction(testable_callback);
38 // EXPECT_ASYNC(pp_error == PP_OK_COMPLETIONPENDING);
39 //
40 // TEST_PASSED_ASYNC;
41 // } 27 // }
42 // 28 //
43 // void SetupTests() { 29 // void SetupTests() {
44 // RegisterScriptableTest("TestFooDeprecated", TestPPBFooDeprecated);
45 // RegisterTest("TestPPBFoo", TestPPBFoo); 30 // RegisterTest("TestPPBFoo", TestPPBFoo);
46 // } 31 // }
47 // 32 //
48 // const PPP_Bar ppp_bar_interface = { ... }; 33 // const PPP_Bar ppp_bar_interface = { ... };
49 // 34 //
50 // void SetupPluginInterface() { 35 // void SetupPluginInterface() {
51 // RegisterPluginInterface(PPP_BAR_INTERFACE, &ppp_bar_interface); 36 // RegisterPluginInterface(PPP_BAR_INTERFACE, &ppp_bar_interface);
52 // } 37 // }
53 // 38 //
54 39
55 #ifndef NATIVE_CLIENT_TESTS_PPAPI_TEST_PPB_TEMPLATE_TEST_INTERFACE_H 40 #ifndef NATIVE_CLIENT_TESTS_PPAPI_TEST_PPB_TEMPLATE_TEST_INTERFACE_H
56 #define NATIVE_CLIENT_TESTS_PPAPI_TEST_PPB_TEMPLATE_TEST_INTERFACE_H 41 #define NATIVE_CLIENT_TESTS_PPAPI_TEST_PPB_TEMPLATE_TEST_INTERFACE_H
57 42
58 #include <stdio.h> 43 #include <stdio.h>
59 #include <limits> 44 #include <limits>
60 45
61 #include "native_client/src/include/nacl_string.h" 46 #include "native_client/src/include/nacl_string.h"
62 47
63 #include "ppapi/c/pp_completion_callback.h" 48 #include "ppapi/c/pp_completion_callback.h"
64 #include "ppapi/c/pp_instance.h" 49 #include "ppapi/c/pp_instance.h"
65 #include "ppapi/c/pp_module.h" 50 #include "ppapi/c/pp_module.h"
66 #include "ppapi/c/pp_resource.h" 51 #include "ppapi/c/pp_resource.h"
67 #include "ppapi/c/pp_var.h" 52 #include "ppapi/c/pp_var.h"
68 53
69 //////////////////////////////////////////////////////////////////////////////// 54 ////////////////////////////////////////////////////////////////////////////////
70 // These must be implemented by the tester 55 // These must be implemented by the tester
71 //////////////////////////////////////////////////////////////////////////////// 56 ////////////////////////////////////////////////////////////////////////////////
72 57
73 // Use RegisterTest() to register each TestFunction. 58 // Use RegisterTest() to register each TestFunction.
74 // Use RegisterScriptableTest() to register each ScriptableTestFunction.
75 void SetupTests(); 59 void SetupTests();
76 // Use RegisterPluginInterface() to register custom PPP_ interfaces other than 60 // Use RegisterPluginInterface() to register custom PPP_ interfaces other than
77 // PPP_Instance that is required and provided by default. 61 // PPP_Instance that is required and provided by default.
78 void SetupPluginInterfaces(); 62 void SetupPluginInterfaces();
79 63
80 //////////////////////////////////////////////////////////////////////////////// 64 ////////////////////////////////////////////////////////////////////////////////
81 // Test helpers 65 // Test helpers
82 //////////////////////////////////////////////////////////////////////////////// 66 ////////////////////////////////////////////////////////////////////////////////
83 67
84 // Registers test_function, so it is callable from JS using 68 // Registers test_function, so it is callable from JS using
85 // plugin.postMessage(test_name); 69 // plugin.postMessage(test_name);
86 typedef void (*TestFunction)(); 70 typedef void (*TestFunction)();
87 void RegisterTest(nacl::string test_name, TestFunction test_function); 71 void RegisterTest(nacl::string test_name, TestFunction test_function);
88 72
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(). 73 // Registers ppp_interface, so it is returned by PPP_GetInterface().
96 void RegisterPluginInterface(const char* interface_name, 74 void RegisterPluginInterface(const char* interface_name,
97 const void* ppp_interface); 75 const void* ppp_interface);
98 76
99 // Helper for creating user callbacks whose invocation will be reported to JS. 77 // Helper for creating user callbacks whose invocation will be reported to JS.
100 PP_CompletionCallback MakeTestableCompletionCallback( 78 PP_CompletionCallback MakeTestableCompletionCallback(
101 const char* callback_name, // same as passed JS waitForCallback() 79 const char* callback_name, // same as passed JS waitForCallback()
102 PP_CompletionCallback_Func func, 80 PP_CompletionCallback_Func func,
103 void* user_data); 81 void* user_data);
104 82
105 // Uses PPB_Messaging interface to post "test_name:message". 83 // Uses PPB_Messaging interface to post "test_name:message".
106 void PostTestMessage(nacl::string test_name, nacl::string message); 84 void PostTestMessage(nacl::string test_name, nacl::string message);
107 85
108 // Use these macros to verify the result of a test and report failures. 86 // Use to verify the result of a test and report failures.
109 // TODO(polina): rename EXPECT_ASYNC to EXPECT when sync scripting is removed. 87 #define EXPECT(expr) do { \
110 #define EXPECT_ASYNC(expr) do { \
111 if (!(expr)) { \ 88 if (!(expr)) { \
112 char error[1024]; \ 89 char error[1024]; \
113 snprintf(error, sizeof(error), \ 90 snprintf(error, sizeof(error), \
114 "ERROR at %s:%d: %s\n", __FILE__, __LINE__, #expr); \ 91 "ERROR at %s:%d: %s\n", __FILE__, __LINE__, #expr); \
115 fprintf(stderr, "%s", error); \ 92 fprintf(stderr, "%s", error); \
116 PostTestMessage(__FUNCTION__, error); \ 93 PostTestMessage(__FUNCTION__, error); \
117 } \ 94 } \
118 } while (0) 95 } while (0)
119 96
120 #define EXPECT(expr) do { \ 97 // Use to report success.
121 if (!(expr)) { \ 98 #define TEST_PASSED PostTestMessage(__FUNCTION__, "PASSED");
122 char error[1024]; \
123 snprintf(error, sizeof(error), \
124 "ERROR at %s:%d: %s\n", __FILE__, __LINE__, #expr); \
125 fprintf(stderr, "%s", error); \
126 return PP_MakeBool(PP_FALSE); \
127 } \
128 } while (0)
129
130 // Use these macros to report success.
131 #define TEST_PASSED_ASYNC PostTestMessage(__FUNCTION__, "PASSED");
132 #define TEST_PASSED PP_MakeBool(PP_TRUE) // Usage: return TEST_PASSED;
133 99
134 // Use this constant for stress testing 100 // Use this constant for stress testing
135 // (i.e. creating and using a large number of resources). 101 // (i.e. creating and using a large number of resources).
136 const int kManyResources = 1000; 102 const int kManyResources = 1000;
137 103
138 const PP_Instance kInvalidInstance = 0; 104 const PP_Instance kInvalidInstance = 0;
139 const PP_Module kInvalidModule = 0; 105 const PP_Module kInvalidModule = 0;
140 const PP_Resource kInvalidResource = 0; 106 const PP_Resource kInvalidResource = 0;
141 107
142 // These should not exist. 108 // These should not exist.
143 // Chrome uses the bottom 2 bits to differentiate between different id types. 109 // Chrome uses the bottom 2 bits to differentiate between different id types.
144 // 00 - module, 01 - instance, 10 - resource, 11 - var. 110 // 00 - module, 01 - instance, 10 - resource, 11 - var.
145 const PP_Instance kNotAnInstance = 0xFFFFF0; 111 const PP_Instance kNotAnInstance = 0xFFFFF0;
146 const PP_Resource kNotAResource = 0xAAAAA0; 112 const PP_Resource kNotAResource = 0xAAAAA0;
147 113
148 // Interface pointers and ids corresponding to this plugin; 114 // Interface pointers and ids corresponding to this plugin;
149 // set at initialization/creation. 115 // set at initialization/creation.
150 PP_Instance pp_instance(); 116 PP_Instance pp_instance();
151 PP_Module pp_module(); 117 PP_Module pp_module();
152 118
153 #endif // NATIVE_CLIENT_TESTS_PPAPI_TEST_PPB_TEMPLATE_TEST_INTERFACE_H 119 #endif // NATIVE_CLIENT_TESTS_PPAPI_TEST_PPB_TEMPLATE_TEST_INTERFACE_H
OLDNEW
« no previous file with comments | « tests/ppapi_test_lib/scriptable_object.cc ('k') | tests/ppapi_test_lib/test_interface.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698