| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 return new Test##name(instance); \ | 123 return new Test##name(instance); \ |
| 124 } \ | 124 } \ |
| 125 static TestCaseFactory g_Test##name_factory( \ | 125 static TestCaseFactory g_Test##name_factory( \ |
| 126 #name, &Test##name##_FactoryMethod \ | 126 #name, &Test##name##_FactoryMethod \ |
| 127 ) | 127 ) |
| 128 | 128 |
| 129 // Helper macro for calling functions implementing specific tests in the | 129 // Helper macro for calling functions implementing specific tests in the |
| 130 // RunTest function. This assumes the function name is TestFoo where Foo is the | 130 // RunTest function. This assumes the function name is TestFoo where Foo is the |
| 131 // test |name|. | 131 // test |name|. |
| 132 #define RUN_TEST(name) \ | 132 #define RUN_TEST(name) \ |
| 133 force_async_ = false; \ | 133 do { \ |
| 134 instance_->LogTest(#name, Test##name()); | 134 force_async_ = false; \ |
| 135 instance_->LogTest(#name, Test##name()); \ |
| 136 } while (false) |
| 135 | 137 |
| 136 // Like RUN_TEST above but forces functions taking callbacks to complete | 138 // Like RUN_TEST above but forces functions taking callbacks to complete |
| 137 // asynchronously on success or error. | 139 // asynchronously on success or error. |
| 138 #define RUN_TEST_FORCEASYNC(name) \ | 140 #define RUN_TEST_FORCEASYNC(name) \ |
| 139 force_async_ = true; \ | 141 do { \ |
| 140 instance_->LogTest(#name"ForceAsync", Test##name()); | 142 force_async_ = true; \ |
| 143 instance_->LogTest(#name"ForceAsync", Test##name()); \ |
| 144 } while (false) |
| 141 | 145 |
| 142 #define RUN_TEST_FORCEASYNC_AND_NOT(name) \ | 146 #define RUN_TEST_FORCEASYNC_AND_NOT(name) \ |
| 143 RUN_TEST_FORCEASYNC(name); \ | 147 do { \ |
| 144 RUN_TEST(name); | 148 RUN_TEST_FORCEASYNC(name); \ |
| 149 RUN_TEST(name); \ |
| 150 } while (false) |
| 145 | 151 |
| 146 | 152 |
| 147 // Helper macros for checking values in tests, and returning a location | 153 // Helper macros for checking values in tests, and returning a location |
| 148 // description of the test fails. | 154 // description of the test fails. |
| 149 #define ASSERT_TRUE(cmd) \ | 155 #define ASSERT_TRUE(cmd) \ |
| 150 if (!(cmd)) { \ | 156 if (!(cmd)) { \ |
| 151 return MakeFailureMessage(__FILE__, __LINE__, #cmd); \ | 157 return MakeFailureMessage(__FILE__, __LINE__, #cmd); \ |
| 152 } | 158 } |
| 153 #define ASSERT_FALSE(cmd) ASSERT_TRUE(!(cmd)) | 159 #define ASSERT_FALSE(cmd) ASSERT_TRUE(!(cmd)) |
| 154 #define ASSERT_EQ(a, b) ASSERT_TRUE((a) == (b)) | 160 #define ASSERT_EQ(a, b) ASSERT_TRUE((a) == (b)) |
| 155 #define ASSERT_NE(a, b) ASSERT_TRUE((a) != (b)) | 161 #define ASSERT_NE(a, b) ASSERT_TRUE((a) != (b)) |
| 156 | 162 |
| 157 #define ASSERT_DOUBLE_EQ(a, b) ASSERT_TRUE( \ | 163 #define ASSERT_DOUBLE_EQ(a, b) ASSERT_TRUE( \ |
| 158 std::fabs((a)-(b)) <= std::numeric_limits<double>::epsilon()) | 164 std::fabs((a)-(b)) <= std::numeric_limits<double>::epsilon()) |
| 159 | 165 |
| 160 #define PASS() return std::string() | 166 #define PASS() return std::string() |
| 161 | 167 |
| 162 #endif // PPAPI_TESTS_TEST_CASE_H_ | 168 #endif // PPAPI_TESTS_TEST_CASE_H_ |
| OLD | NEW |