| 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 <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "ppapi/c/pp_resource.h" | 13 #include "ppapi/c/pp_resource.h" |
| 14 #include "ppapi/c/dev/ppb_testing_dev.h" | 14 #include "ppapi/c/dev/ppb_testing_dev.h" |
| 15 #include "ppapi/cpp/dev/scrollbar_dev.h" | 15 #include "ppapi/cpp/dev/scrollbar_dev.h" |
| 16 #include "ppapi/cpp/view.h" | 16 #include "ppapi/cpp/view.h" |
| 17 #include "ppapi/tests/test_utils.h" |
| 17 | 18 |
| 18 #if (defined __native_client__) | 19 #if (defined __native_client__) |
| 19 #include "ppapi/cpp/var.h" | 20 #include "ppapi/cpp/var.h" |
| 20 #else | 21 #else |
| 21 #include "ppapi/cpp/private/var_private.h" | 22 #include "ppapi/cpp/private/var_private.h" |
| 22 #endif | 23 #endif |
| 23 | 24 |
| 24 class TestingInstance; | 25 class TestingInstance; |
| 25 | 26 |
| 26 namespace pp { | 27 namespace pp { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 bool MatchesFilter(const std::string& test_name, const std::string& filter); | 102 bool MatchesFilter(const std::string& test_name, const std::string& filter); |
| 102 | 103 |
| 103 // Check for leaked resources and vars at the end of the test. If any exist, | 104 // Check for leaked resources and vars at the end of the test. If any exist, |
| 104 // return a string with some information about the error. Otherwise, return | 105 // return a string with some information about the error. Otherwise, return |
| 105 // an empty string. | 106 // an empty string. |
| 106 std::string CheckResourcesAndVars(); | 107 std::string CheckResourcesAndVars(); |
| 107 | 108 |
| 108 // Pointer to the instance that owns us. | 109 // Pointer to the instance that owns us. |
| 109 TestingInstance* instance_; | 110 TestingInstance* instance_; |
| 110 | 111 |
| 112 protected: |
| 111 // NULL unless InitTestingInterface is called. | 113 // NULL unless InitTestingInterface is called. |
| 112 const PPB_Testing_Dev* testing_interface_; | 114 const PPB_Testing_Dev* testing_interface_; |
| 113 | 115 |
| 114 // Force asynchronous completion of any operation taking a callback. | 116 // TODO(dmichael): Remove this, it's for temporary backwards compatibility so |
| 117 // I don't have to change all the tests at once. |
| 115 bool force_async_; | 118 bool force_async_; |
| 116 | 119 |
| 120 void set_callback_type(CallbackType callback_type) { |
| 121 callback_type_ = callback_type; |
| 122 // TODO(dmichael): Remove this; see comment on force_async_. |
| 123 force_async_ = (callback_type_ == PP_REQUIRED); |
| 124 } |
| 125 CallbackType callback_type() const { |
| 126 return callback_type_; |
| 127 } |
| 128 |
| 117 private: | 129 private: |
| 130 // Passed when creating completion callbacks in some tests. This determines |
| 131 // what kind of callback we use for the test. |
| 132 CallbackType callback_type_; |
| 133 |
| 118 // Var ids that should be ignored when checking for leaks on shutdown. | 134 // Var ids that should be ignored when checking for leaks on shutdown. |
| 119 std::set<int64_t> ignored_leaked_vars_; | 135 std::set<int64_t> ignored_leaked_vars_; |
| 120 | 136 |
| 121 #if !(defined __native_client__) | 137 #if !(defined __native_client__) |
| 122 // Holds the test object, if any was retrieved from CreateTestObject. | 138 // Holds the test object, if any was retrieved from CreateTestObject. |
| 123 pp::VarPrivate test_object_; | 139 pp::VarPrivate test_object_; |
| 124 #endif | 140 #endif |
| 125 }; | 141 }; |
| 126 | 142 |
| 127 // This class is an implementation detail. | 143 // This class is an implementation detail. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 } \ | 176 } \ |
| 161 static TestCaseFactory g_Test##name_factory( \ | 177 static TestCaseFactory g_Test##name_factory( \ |
| 162 #name, &Test##name##_FactoryMethod \ | 178 #name, &Test##name##_FactoryMethod \ |
| 163 ) | 179 ) |
| 164 | 180 |
| 165 // Helper macro for calling functions implementing specific tests in the | 181 // Helper macro for calling functions implementing specific tests in the |
| 166 // RunTest function. This assumes the function name is TestFoo where Foo is the | 182 // RunTest function. This assumes the function name is TestFoo where Foo is the |
| 167 // test |name|. | 183 // test |name|. |
| 168 #define RUN_TEST(name, test_filter) \ | 184 #define RUN_TEST(name, test_filter) \ |
| 169 if (MatchesFilter(#name, test_filter)) { \ | 185 if (MatchesFilter(#name, test_filter)) { \ |
| 170 force_async_ = false; \ | 186 set_callback_type(PP_OPTIONAL); \ |
| 171 std::string error_message = Test##name(); \ | 187 std::string error_message = Test##name(); \ |
| 172 if (error_message.empty()) \ | 188 if (error_message.empty()) \ |
| 173 error_message = CheckResourcesAndVars(); \ | 189 error_message = CheckResourcesAndVars(); \ |
| 174 instance_->LogTest(#name, error_message); \ | 190 instance_->LogTest(#name, error_message); \ |
| 175 } | 191 } |
| 176 | 192 |
| 177 #define RUN_TEST_WITH_REFERENCE_CHECK(name, test_filter) \ | 193 #define RUN_TEST_WITH_REFERENCE_CHECK(name, test_filter) \ |
| 178 if (MatchesFilter(#name, test_filter)) { \ | 194 if (MatchesFilter(#name, test_filter)) { \ |
| 179 force_async_ = false; \ | 195 set_callback_type(PP_OPTIONAL); \ |
| 180 uint32_t objects = testing_interface_->GetLiveObjectsForInstance( \ | 196 uint32_t objects = testing_interface_->GetLiveObjectsForInstance( \ |
| 181 instance_->pp_instance()); \ | 197 instance_->pp_instance()); \ |
| 182 std::string error_message = Test##name(); \ | 198 std::string error_message = Test##name(); \ |
| 183 if (error_message.empty() && \ | 199 if (error_message.empty() && \ |
| 184 testing_interface_->GetLiveObjectsForInstance( \ | 200 testing_interface_->GetLiveObjectsForInstance( \ |
| 185 instance_->pp_instance()) != objects) \ | 201 instance_->pp_instance()) != objects) \ |
| 186 error_message = MakeFailureMessage(__FILE__, __LINE__, \ | 202 error_message = MakeFailureMessage(__FILE__, __LINE__, \ |
| 187 "reference leak check"); \ | 203 "reference leak check"); \ |
| 188 instance_->LogTest(#name, error_message); \ | 204 instance_->LogTest(#name, error_message); \ |
| 189 } | 205 } |
| 190 | 206 |
| 191 // Like RUN_TEST above but forces functions taking callbacks to complete | 207 // Like RUN_TEST above but forces functions taking callbacks to complete |
| 192 // asynchronously on success or error. | 208 // asynchronously on success or error. |
| 193 #define RUN_TEST_FORCEASYNC(name, test_filter) \ | 209 #define RUN_TEST_FORCEASYNC(name, test_filter) \ |
| 194 if (MatchesFilter(#name"ForceAsync", test_filter)) { \ | 210 if (MatchesFilter(#name"ForceAsync", test_filter)) { \ |
| 195 force_async_ = true; \ | 211 set_callback_type(PP_REQUIRED); \ |
| 196 instance_->LogTest(#name"ForceAsync", Test##name()); \ | 212 instance_->LogTest(#name"ForceAsync", Test##name()); \ |
| 197 } | 213 } |
| 198 | 214 |
| 199 #define RUN_TEST_FORCEASYNC_AND_NOT(name, test_filter) \ | 215 #define RUN_TEST_FORCEASYNC_AND_NOT(name, test_filter) \ |
| 200 do { \ | 216 do { \ |
| 201 RUN_TEST_FORCEASYNC(name, test_filter); \ | 217 RUN_TEST_FORCEASYNC(name, test_filter); \ |
| 202 RUN_TEST(name, test_filter); \ | 218 RUN_TEST(name, test_filter); \ |
| 203 } while (false) | 219 } while (false) |
| 204 | 220 |
| 205 | 221 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 220 #define ASSERT_SUBTEST_SUCCESS(function) \ | 236 #define ASSERT_SUBTEST_SUCCESS(function) \ |
| 221 do { \ | 237 do { \ |
| 222 std::string result = (function); \ | 238 std::string result = (function); \ |
| 223 if (!result.empty()) \ | 239 if (!result.empty()) \ |
| 224 return result; \ | 240 return result; \ |
| 225 } while (false) | 241 } while (false) |
| 226 | 242 |
| 227 #define PASS() return std::string() | 243 #define PASS() return std::string() |
| 228 | 244 |
| 229 #endif // PPAPI_TESTS_TEST_CASE_H_ | 245 #endif // PPAPI_TESTS_TEST_CASE_H_ |
| OLD | NEW |