Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
|
polina
2011/03/17 02:59:28
I don't know about open source code, but in other
| |
| 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_TEST_TEST_CASE_H_ | 5 #ifndef PPAPI_TESTS_TEST_CASE_H_ |
| 6 #define PPAPI_TEST_TEST_CASE_H_ | 6 #define PPAPI_TESTS_TEST_CASE_H_ |
| 7 | 7 |
| 8 #include <cmath> | |
| 9 #include <limits> | |
| 8 #include <string> | 10 #include <string> |
| 9 | 11 |
| 10 #include "ppapi/c/pp_resource.h" | 12 #include "ppapi/c/pp_resource.h" |
| 11 #include "ppapi/cpp/dev/scrollbar_dev.h" | 13 #include "ppapi/cpp/dev/scrollbar_dev.h" |
| 12 #include "ppapi/cpp/var.h" | 14 #include "ppapi/cpp/var.h" |
| 13 | 15 |
| 14 class TestingInstance; | 16 class TestingInstance; |
| 15 | 17 |
| 16 namespace pp { | 18 namespace pp { |
| 17 namespace deprecated { | 19 namespace deprecated { |
| 18 class ScriptableObject; | 20 class ScriptableObject; |
| 19 } | 21 } |
| 20 } | 22 } |
| 21 | 23 |
| 22 // Individual classes of tests derive from this generic test case. | 24 // Individual classes of tests derive from this generic test case. |
| 23 class TestCase { | 25 class TestCase { |
| 24 public: | 26 public: |
| 25 TestCase(TestingInstance* instance) : instance_(instance) {} | 27 explicit TestCase(TestingInstance* instance) : instance_(instance) {} |
| 26 virtual ~TestCase() {} | 28 virtual ~TestCase() {} |
| 27 | 29 |
| 28 // Optionally override to do testcase specific initialization. | 30 // Optionally override to do testcase specific initialization. |
| 29 virtual bool Init() { return true; } | 31 virtual bool Init() { return true; } |
| 30 | 32 |
| 31 // Override to implement the test. It will be called after the plugin is | 33 // Override to implement the test. It will be called after the plugin is |
| 32 // first displayed. | 34 // first displayed. |
| 33 virtual void RunTest() = 0; | 35 virtual void RunTest() = 0; |
| 34 | 36 |
| 35 std::string MakeFailureMessage(const char* file, int line, const char* cmd); | 37 std::string MakeFailureMessage(const char* file, int line, const char* cmd); |
| 36 | 38 |
| 37 // Returns the scriptable test object for the current test, if any. | 39 // Returns the scriptable test object for the current test, if any. |
| 38 // Internally, this uses CreateTestObject which each test overrides. | 40 // Internally, this uses CreateTestObject which each test overrides. |
| 39 pp::Var GetTestObject(); | 41 pp::Var GetTestObject(); |
| 40 | 42 |
| 43 // A function that is invoked whenever HandleMessage is called on the | |
| 44 // associated TestingInstance. Default implementation does nothing. TestCases | |
| 45 // that want to handle incoming postMessage events should override this | |
| 46 // method. | |
| 47 virtual void HandleMessage(const pp::Var& message_data); | |
| 48 | |
| 41 protected: | 49 protected: |
| 42 // Overridden by each test to supply a ScriptableObject corresponding to the | 50 // Overridden by each test to supply a ScriptableObject corresponding to the |
| 43 // test. There can only be one object created for all test in a given class | 51 // test. There can only be one object created for all test in a given class |
| 44 // so be sure your object is designed to be re-used. | 52 // so be sure your object is designed to be re-used. |
| 45 // | 53 // |
| 46 // This object should be created on the heap. Ownership will be passed to the | 54 // This object should be created on the heap. Ownership will be passed to the |
| 47 // caller. Return NULL if there is no supported test object (the default). | 55 // caller. Return NULL if there is no supported test object (the default). |
| 48 virtual pp::deprecated::ScriptableObject* CreateTestObject(); | 56 virtual pp::deprecated::ScriptableObject* CreateTestObject(); |
| 49 | 57 |
| 50 // Initializes the testing interface. | 58 // Initializes the testing interface. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 // Helper macros for checking values in tests, and returning a location | 116 // Helper macros for checking values in tests, and returning a location |
| 109 // description of the test fails. | 117 // description of the test fails. |
| 110 #define ASSERT_TRUE(cmd) \ | 118 #define ASSERT_TRUE(cmd) \ |
| 111 if (!(cmd)) { \ | 119 if (!(cmd)) { \ |
| 112 return MakeFailureMessage(__FILE__, __LINE__, #cmd); \ | 120 return MakeFailureMessage(__FILE__, __LINE__, #cmd); \ |
| 113 } | 121 } |
| 114 #define ASSERT_FALSE(cmd) ASSERT_TRUE(!(cmd)) | 122 #define ASSERT_FALSE(cmd) ASSERT_TRUE(!(cmd)) |
| 115 #define ASSERT_EQ(a, b) ASSERT_TRUE((a) == (b)) | 123 #define ASSERT_EQ(a, b) ASSERT_TRUE((a) == (b)) |
| 116 #define ASSERT_NE(a, b) ASSERT_TRUE((a) != (b)) | 124 #define ASSERT_NE(a, b) ASSERT_TRUE((a) != (b)) |
| 117 | 125 |
| 126 #define ASSERT_DOUBLE_EQ(a, b) ASSERT_TRUE( \ | |
| 127 std::fabs((a)-(b)) <= std::numeric_limits<double>::epsilon()) | |
| 128 | |
| 118 #define PASS() return std::string() | 129 #define PASS() return std::string() |
| 119 | 130 |
| 120 #endif // PPAPI_TEST_TEST_CASE_H_ | 131 #endif // PPAPI_TESTS_TEST_CASE_H_ |
| 132 | |
| OLD | NEW |