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

Side by Side Diff: ppapi/tests/test_case.h

Issue 8477015: Make it possible to enable/disable specific ppapi tests. Migrate PostMessage tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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 Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium 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 #ifndef PPAPI_TESTS_TEST_CASE_H_ 5 #ifndef PPAPI_TESTS_TEST_CASE_H_
6 #define PPAPI_TESTS_TEST_CASE_H_ 6 #define PPAPI_TESTS_TEST_CASE_H_
7 7
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <string> 10 #include <string>
(...skipping 20 matching lines...) Expand all
31 class TestCase { 31 class TestCase {
32 public: 32 public:
33 explicit TestCase(TestingInstance* instance); 33 explicit TestCase(TestingInstance* instance);
34 virtual ~TestCase(); 34 virtual ~TestCase();
35 35
36 // Optionally override to do testcase specific initialization. 36 // Optionally override to do testcase specific initialization.
37 // Default implementation just returns true. 37 // Default implementation just returns true.
38 virtual bool Init(); 38 virtual bool Init();
39 39
40 // Override to implement the test. It will be called after the plugin is 40 // Override to implement the test. It will be called after the plugin is
41 // first displayed. 41 // first displayed, passing a string. The implementation should run all tests
42 virtual void RunTest() = 0; 42 // that contain the test_filter as a substring. E.g., passing an empty string
43 // should run all tests.
44 virtual void RunTests(const std::string& test_filter) = 0;
43 45
44 static std::string MakeFailureMessage(const char* file, int line, 46 static std::string MakeFailureMessage(const char* file, int line,
45 const char* cmd); 47 const char* cmd);
46 48
47 #if !(defined __native_client__) 49 #if !(defined __native_client__)
48 // Returns the scriptable test object for the current test, if any. 50 // Returns the scriptable test object for the current test, if any.
49 // Internally, this uses CreateTestObject which each test overrides. 51 // Internally, this uses CreateTestObject which each test overrides.
50 pp::VarPrivate GetTestObject(); 52 pp::VarPrivate GetTestObject();
51 #endif 53 #endif
52 54
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 static TestCase* Test##name##_FactoryMethod(TestingInstance* instance) { \ 135 static TestCase* Test##name##_FactoryMethod(TestingInstance* instance) { \
134 return new Test##name(instance); \ 136 return new Test##name(instance); \
135 } \ 137 } \
136 static TestCaseFactory g_Test##name_factory( \ 138 static TestCaseFactory g_Test##name_factory( \
137 #name, &Test##name##_FactoryMethod \ 139 #name, &Test##name##_FactoryMethod \
138 ) 140 )
139 141
140 // Helper macro for calling functions implementing specific tests in the 142 // Helper macro for calling functions implementing specific tests in the
141 // RunTest function. This assumes the function name is TestFoo where Foo is the 143 // RunTest function. This assumes the function name is TestFoo where Foo is the
142 // test |name|. 144 // test |name|.
143 #define RUN_TEST(name) \ 145 #define RUN_TEST(name, test_filter) \
144 do { \ 146 if (std::string(#name).find(test_filter) != std::string::npos) { \
145 force_async_ = false; \ 147 force_async_ = false; \
146 instance_->LogTest(#name, Test##name()); \ 148 instance_->LogTest(#name, Test##name()); \
147 } while (false) 149 }
148 150
149 // Like RUN_TEST above but forces functions taking callbacks to complete 151 // Like RUN_TEST above but forces functions taking callbacks to complete
150 // asynchronously on success or error. 152 // asynchronously on success or error.
151 #define RUN_TEST_FORCEASYNC(name) \ 153 #define RUN_TEST_FORCEASYNC(name, test_filter) \
152 do { \ 154 if (std::string(#name"ForceAsync").find(test_filter) != std::string::npos) { \
153 force_async_ = true; \ 155 force_async_ = true; \
154 instance_->LogTest(#name"ForceAsync", Test##name()); \ 156 instance_->LogTest(#name"ForceAsync", Test##name()); \
155 } while (false) 157 }
156 158
157 #define RUN_TEST_FORCEASYNC_AND_NOT(name) \ 159 #define RUN_TEST_FORCEASYNC_AND_NOT(name, test_filter) \
158 do { \ 160 do { \
159 RUN_TEST_FORCEASYNC(name); \ 161 RUN_TEST_FORCEASYNC(name, test_filter); \
160 RUN_TEST(name); \ 162 RUN_TEST(name, test_filter); \
161 } while (false) 163 } while (false)
162 164
163 165
164 // Helper macros for checking values in tests, and returning a location 166 // Helper macros for checking values in tests, and returning a location
165 // description of the test fails. 167 // description of the test fails.
166 #define ASSERT_TRUE(cmd) \ 168 #define ASSERT_TRUE(cmd) \
167 if (!(cmd)) { \ 169 if (!(cmd)) { \
168 return MakeFailureMessage(__FILE__, __LINE__, #cmd); \ 170 return MakeFailureMessage(__FILE__, __LINE__, #cmd); \
169 } 171 }
170 #define ASSERT_FALSE(cmd) ASSERT_TRUE(!(cmd)) 172 #define ASSERT_FALSE(cmd) ASSERT_TRUE(!(cmd))
171 #define ASSERT_EQ(a, b) ASSERT_TRUE((a) == (b)) 173 #define ASSERT_EQ(a, b) ASSERT_TRUE((a) == (b))
172 #define ASSERT_NE(a, b) ASSERT_TRUE((a) != (b)) 174 #define ASSERT_NE(a, b) ASSERT_TRUE((a) != (b))
173 175
174 #define ASSERT_DOUBLE_EQ(a, b) ASSERT_TRUE( \ 176 #define ASSERT_DOUBLE_EQ(a, b) ASSERT_TRUE( \
175 std::fabs((a)-(b)) <= std::numeric_limits<double>::epsilon()) 177 std::fabs((a)-(b)) <= std::numeric_limits<double>::epsilon())
176 178
177 #define PASS() return std::string() 179 #define PASS() return std::string()
178 180
179 #endif // PPAPI_TESTS_TEST_CASE_H_ 181 #endif // PPAPI_TESTS_TEST_CASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698