| 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 <string> | 11 #include <string> |
| 11 | 12 |
| 12 #include "ppapi/c/pp_resource.h" | 13 #include "ppapi/c/pp_resource.h" |
| 13 #include "ppapi/c/dev/ppb_testing_dev.h" | 14 #include "ppapi/c/dev/ppb_testing_dev.h" |
| 14 #include "ppapi/cpp/dev/scrollbar_dev.h" | 15 #include "ppapi/cpp/dev/scrollbar_dev.h" |
| 15 #include "ppapi/cpp/view.h" | 16 #include "ppapi/cpp/view.h" |
| 16 | 17 |
| 17 #if (defined __native_client__) | 18 #if (defined __native_client__) |
| 18 #include "ppapi/cpp/var.h" | 19 #include "ppapi/cpp/var.h" |
| 19 #else | 20 #else |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // A function that is invoked whenever DidChangeView is called on the | 64 // A function that is invoked whenever DidChangeView is called on the |
| 64 // associated TestingInstance. Default implementation does nothing. TestCases | 65 // associated TestingInstance. Default implementation does nothing. TestCases |
| 65 // that want to handle view changes should override this method. | 66 // that want to handle view changes should override this method. |
| 66 virtual void DidChangeView(const pp::View& view); | 67 virtual void DidChangeView(const pp::View& view); |
| 67 | 68 |
| 68 // A function that is invoked whenever HandleInputEvent is called on the | 69 // A function that is invoked whenever HandleInputEvent is called on the |
| 69 // associated TestingInstance. Default implementation returns false. TestCases | 70 // associated TestingInstance. Default implementation returns false. TestCases |
| 70 // that want to handle view changes should override this method. | 71 // that want to handle view changes should override this method. |
| 71 virtual bool HandleInputEvent(const pp::InputEvent& event); | 72 virtual bool HandleInputEvent(const pp::InputEvent& event); |
| 72 | 73 |
| 74 void IgnoreLeakedVar(int64_t id); |
| 75 |
| 76 TestingInstance* instance() { return instance_; } |
| 77 |
| 78 const PPB_Testing_Dev* testing_interface() { return testing_interface_; } |
| 79 |
| 73 protected: | 80 protected: |
| 74 #if !(defined __native_client__) | 81 #if !(defined __native_client__) |
| 75 // Overridden by each test to supply a ScriptableObject corresponding to the | 82 // Overridden by each test to supply a ScriptableObject corresponding to the |
| 76 // test. There can only be one object created for all test in a given class | 83 // test. There can only be one object created for all tests in a given class, |
| 77 // so be sure your object is designed to be re-used. | 84 // so be sure your object is designed to be re-used. |
| 78 // | 85 // |
| 79 // This object should be created on the heap. Ownership will be passed to the | 86 // This object should be created on the heap. Ownership will be passed to the |
| 80 // caller. Return NULL if there is no supported test object (the default). | 87 // caller. Return NULL if there is no supported test object (the default). |
| 81 virtual pp::deprecated::ScriptableObject* CreateTestObject(); | 88 virtual pp::deprecated::ScriptableObject* CreateTestObject(); |
| 82 #endif | 89 #endif |
| 83 | 90 |
| 84 // Checks whether the testing interface is available. Returns true if it is, | 91 // Checks whether the testing interface is available. Returns true if it is, |
| 85 // false otherwise. If it is not available, adds a descriptive error. This is | 92 // false otherwise. If it is not available, adds a descriptive error. This is |
| 86 // for use by tests that require the testing interface. | 93 // for use by tests that require the testing interface. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 101 // Pointer to the instance that owns us. | 108 // Pointer to the instance that owns us. |
| 102 TestingInstance* instance_; | 109 TestingInstance* instance_; |
| 103 | 110 |
| 104 // NULL unless InitTestingInterface is called. | 111 // NULL unless InitTestingInterface is called. |
| 105 const PPB_Testing_Dev* testing_interface_; | 112 const PPB_Testing_Dev* testing_interface_; |
| 106 | 113 |
| 107 // Force asynchronous completion of any operation taking a callback. | 114 // Force asynchronous completion of any operation taking a callback. |
| 108 bool force_async_; | 115 bool force_async_; |
| 109 | 116 |
| 110 private: | 117 private: |
| 118 // Var ids that should be ignored when checking for leaks on shutdown. |
| 119 std::set<int64_t> ignored_leaked_vars_; |
| 120 |
| 111 #if !(defined __native_client__) | 121 #if !(defined __native_client__) |
| 112 // Holds the test object, if any was retrieved from CreateTestObject. | 122 // Holds the test object, if any was retrieved from CreateTestObject. |
| 113 pp::VarPrivate test_object_; | 123 pp::VarPrivate test_object_; |
| 114 #endif | 124 #endif |
| 115 }; | 125 }; |
| 116 | 126 |
| 117 // This class is an implementation detail. | 127 // This class is an implementation detail. |
| 118 class TestCaseFactory { | 128 class TestCaseFactory { |
| 119 public: | 129 public: |
| 120 typedef TestCase* (*Method)(TestingInstance* instance); | 130 typedef TestCase* (*Method)(TestingInstance* instance); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 #define ASSERT_FALSE(cmd) ASSERT_TRUE(!(cmd)) | 212 #define ASSERT_FALSE(cmd) ASSERT_TRUE(!(cmd)) |
| 203 #define ASSERT_EQ(a, b) ASSERT_TRUE((a) == (b)) | 213 #define ASSERT_EQ(a, b) ASSERT_TRUE((a) == (b)) |
| 204 #define ASSERT_NE(a, b) ASSERT_TRUE((a) != (b)) | 214 #define ASSERT_NE(a, b) ASSERT_TRUE((a) != (b)) |
| 205 | 215 |
| 206 #define ASSERT_DOUBLE_EQ(a, b) ASSERT_TRUE( \ | 216 #define ASSERT_DOUBLE_EQ(a, b) ASSERT_TRUE( \ |
| 207 std::fabs((a)-(b)) <= std::numeric_limits<double>::epsilon()) | 217 std::fabs((a)-(b)) <= std::numeric_limits<double>::epsilon()) |
| 208 | 218 |
| 209 #define PASS() return std::string() | 219 #define PASS() return std::string() |
| 210 | 220 |
| 211 #endif // PPAPI_TESTS_TEST_CASE_H_ | 221 #endif // PPAPI_TESTS_TEST_CASE_H_ |
| OLD | NEW |