OLD | NEW |
---|---|
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 | 62 |
63 // Makes sure the test is run over HTTP. | 63 // Makes sure the test is run over HTTP. |
64 bool EnsureRunningOverHTTP(); | 64 bool EnsureRunningOverHTTP(); |
65 | 65 |
66 // Pointer to the instance that owns us. | 66 // Pointer to the instance that owns us. |
67 TestingInstance* instance_; | 67 TestingInstance* instance_; |
68 | 68 |
69 // NULL unless InitTestingInterface is called. | 69 // NULL unless InitTestingInterface is called. |
70 const PPB_Testing_Dev* testing_interface_; | 70 const PPB_Testing_Dev* testing_interface_; |
71 | 71 |
72 // Force asynchronous completion of any operation taking a callback. | |
73 bool force_async_; | |
74 | |
72 private: | 75 private: |
73 // Holds the test object, if any was retrieved from CreateTestObject. | 76 // Holds the test object, if any was retrieved from CreateTestObject. |
74 pp::Var test_object_; | 77 pp::Var test_object_; |
75 }; | 78 }; |
76 | 79 |
77 // This class is an implementation detail. | 80 // This class is an implementation detail. |
78 class TestCaseFactory { | 81 class TestCaseFactory { |
79 public: | 82 public: |
80 typedef TestCase* (*Method)(TestingInstance* instance); | 83 typedef TestCase* (*Method)(TestingInstance* instance); |
81 | 84 |
(...skipping 25 matching lines...) Expand all Loading... | |
107 #define REGISTER_TEST_CASE(name) \ | 110 #define REGISTER_TEST_CASE(name) \ |
108 static TestCase* Test##name##_FactoryMethod(TestingInstance* instance) { \ | 111 static TestCase* Test##name##_FactoryMethod(TestingInstance* instance) { \ |
109 return new Test##name(instance); \ | 112 return new Test##name(instance); \ |
110 } \ | 113 } \ |
111 static TestCaseFactory g_Test##name_factory( \ | 114 static TestCaseFactory g_Test##name_factory( \ |
112 #name, &Test##name##_FactoryMethod \ | 115 #name, &Test##name##_FactoryMethod \ |
113 ) | 116 ) |
114 | 117 |
115 // Helper macro for calling functions implementing specific tests in the | 118 // Helper macro for calling functions implementing specific tests in the |
116 // RunTest function. This assumes the function name is TestFoo where Foo is the | 119 // RunTest function. This assumes the function name is TestFoo where Foo is the |
117 // test name, | 120 // test |name|. |
118 #define RUN_TEST(name) \ | 121 #define RUN_TEST(name) \ |
119 instance_->LogTest(#name, Test##name()); | 122 instance_->LogTest(#name, Test##name()); |
120 | 123 |
124 // Helper macro for repeating the same test involving callbacks with and | |
125 // without force_async option. | |
126 #define RUN_ASYNC_TEST(name) \ | |
127 force_async_ = false; \ | |
128 instance_->LogTest(#name, Test##name()); \ | |
piman
2011/06/07 17:32:14
Wouldn't it be useful to log different strings in
polina
2011/06/09 23:53:51
Done.
| |
129 force_async_ = true; \ | |
130 instance_->LogTest(#name, Test##name()); | |
131 | |
121 // Helper macros for checking values in tests, and returning a location | 132 // Helper macros for checking values in tests, and returning a location |
122 // description of the test fails. | 133 // description of the test fails. |
123 #define ASSERT_TRUE(cmd) \ | 134 #define ASSERT_TRUE(cmd) \ |
124 if (!(cmd)) { \ | 135 if (!(cmd)) { \ |
125 return MakeFailureMessage(__FILE__, __LINE__, #cmd); \ | 136 return MakeFailureMessage(__FILE__, __LINE__, #cmd); \ |
126 } | 137 } |
127 #define ASSERT_FALSE(cmd) ASSERT_TRUE(!(cmd)) | 138 #define ASSERT_FALSE(cmd) ASSERT_TRUE(!(cmd)) |
128 #define ASSERT_EQ(a, b) ASSERT_TRUE((a) == (b)) | 139 #define ASSERT_EQ(a, b) ASSERT_TRUE((a) == (b)) |
129 #define ASSERT_NE(a, b) ASSERT_TRUE((a) != (b)) | 140 #define ASSERT_NE(a, b) ASSERT_TRUE((a) != (b)) |
130 | 141 |
131 #define ASSERT_DOUBLE_EQ(a, b) ASSERT_TRUE( \ | 142 #define ASSERT_DOUBLE_EQ(a, b) ASSERT_TRUE( \ |
132 std::fabs((a)-(b)) <= std::numeric_limits<double>::epsilon()) | 143 std::fabs((a)-(b)) <= std::numeric_limits<double>::epsilon()) |
133 | 144 |
134 #define PASS() return std::string() | 145 #define PASS() return std::string() |
135 | 146 |
136 #endif // PPAPI_TESTS_TEST_CASE_H_ | 147 #endif // PPAPI_TESTS_TEST_CASE_H_ |
OLD | NEW |