OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <map> | 10 #include <map> |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 testing_interface_); | 152 testing_interface_); |
153 return runner.result(); | 153 return runner.result(); |
154 } | 154 } |
155 | 155 |
156 // Pointer to the instance that owns us. | 156 // Pointer to the instance that owns us. |
157 TestingInstance* instance_; | 157 TestingInstance* instance_; |
158 | 158 |
159 // NULL unless InitTestingInterface is called. | 159 // NULL unless InitTestingInterface is called. |
160 const PPB_Testing_Dev* testing_interface_; | 160 const PPB_Testing_Dev* testing_interface_; |
161 | 161 |
162 // TODO(dmichael): Remove this, it's for temporary backwards compatibility so | |
163 // I don't have to change all the tests at once. | |
164 bool force_async_; | |
165 | |
166 void set_callback_type(CallbackType callback_type) { | 162 void set_callback_type(CallbackType callback_type) { |
167 callback_type_ = callback_type; | 163 callback_type_ = callback_type; |
168 // TODO(dmichael): Remove this; see comment on force_async_. | |
169 force_async_ = (callback_type_ == PP_REQUIRED); | |
170 } | 164 } |
171 CallbackType callback_type() const { | 165 CallbackType callback_type() const { |
172 return callback_type_; | 166 return callback_type_; |
173 } | 167 } |
174 | 168 |
175 private: | 169 private: |
176 template <class T> | 170 template <class T> |
177 class ThreadedTestRunner { | 171 class ThreadedTestRunner { |
178 public: | 172 public: |
179 typedef std::string(T::*TestMethodType)(); | 173 typedef std::string(T::*TestMethodType)(); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 // Helper macros for checking values in tests, and returning a location | 363 // Helper macros for checking values in tests, and returning a location |
370 // description of the test fails. | 364 // description of the test fails. |
371 #define ASSERT_TRUE(cmd) \ | 365 #define ASSERT_TRUE(cmd) \ |
372 do { \ | 366 do { \ |
373 if (!(cmd)) \ | 367 if (!(cmd)) \ |
374 return MakeFailureMessage(__FILE__, __LINE__, #cmd); \ | 368 return MakeFailureMessage(__FILE__, __LINE__, #cmd); \ |
375 } while (false) | 369 } while (false) |
376 #define ASSERT_FALSE(cmd) ASSERT_TRUE(!(cmd)) | 370 #define ASSERT_FALSE(cmd) ASSERT_TRUE(!(cmd)) |
377 #define ASSERT_EQ(a, b) ASSERT_TRUE((a) == (b)) | 371 #define ASSERT_EQ(a, b) ASSERT_TRUE((a) == (b)) |
378 #define ASSERT_NE(a, b) ASSERT_TRUE((a) != (b)) | 372 #define ASSERT_NE(a, b) ASSERT_TRUE((a) != (b)) |
| 373 #define ASSERT_LT(a, b) ASSERT_TRUE((a) < (b)) |
| 374 #define ASSERT_LE(a, b) ASSERT_TRUE((a) <= (b)) |
| 375 #define ASSERT_GT(a, b) ASSERT_TRUE((a) > (b)) |
| 376 #define ASSERT_GE(a, b) ASSERT_TRUE((a) >= (b)) |
379 | 377 |
380 #define ASSERT_DOUBLE_EQ(a, b) ASSERT_TRUE( \ | 378 #define ASSERT_DOUBLE_EQ(a, b) ASSERT_TRUE( \ |
381 std::fabs((a)-(b)) <= std::numeric_limits<double>::epsilon()) | 379 std::fabs((a)-(b)) <= std::numeric_limits<double>::epsilon()) |
382 | 380 |
383 // Runs |function| as a subtest and asserts that it has passed. | 381 // Runs |function| as a subtest and asserts that it has passed. |
384 #define ASSERT_SUBTEST_SUCCESS(function) \ | 382 #define ASSERT_SUBTEST_SUCCESS(function) \ |
385 do { \ | 383 do { \ |
386 std::string result = (function); \ | 384 std::string result = (function); \ |
387 if (!result.empty()) \ | 385 if (!result.empty()) \ |
388 return result; \ | 386 return result; \ |
389 } while (false) | 387 } while (false) |
390 | 388 |
391 #define PASS() return std::string() | 389 #define PASS() return std::string() |
392 | 390 |
393 #endif // PPAPI_TESTS_TEST_CASE_H_ | 391 #endif // PPAPI_TESTS_TEST_CASE_H_ |
OLD | NEW |