Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: ppapi/tests/test_case.h

Issue 8982006: Add GetLiveVars to PPB_Testing_Dev. Fix leaks it uncovered. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 #if !(defined __native_client__) 73 #if !(defined __native_client__)
74 // Overridden by each test to supply a ScriptableObject corresponding to the 74 // Overridden by each test to supply a ScriptableObject corresponding to the
75 // test. There can only be one object created for all test in a given class 75 // test. There can only be one object created for all test in a given class
76 // so be sure your object is designed to be re-used. 76 // so be sure your object is designed to be re-used.
77 // 77 //
78 // This object should be created on the heap. Ownership will be passed to the 78 // This object should be created on the heap. Ownership will be passed to the
79 // caller. Return NULL if there is no supported test object (the default). 79 // caller. Return NULL if there is no supported test object (the default).
80 virtual pp::deprecated::ScriptableObject* CreateTestObject(); 80 virtual pp::deprecated::ScriptableObject* CreateTestObject();
81 #endif 81 #endif
82 82
83 // Initializes the testing interface. 83 // Checks whether the testing interface is available. Returns true if it is,
84 bool InitTestingInterface(); 84 // false otherwise. If it is not available, adds a descriptive error. This is
85 // for use by tests that require the testing interface.
86 bool CheckTestingInterface();
85 87
86 // Makes sure the test is run over HTTP. 88 // Makes sure the test is run over HTTP.
87 bool EnsureRunningOverHTTP(); 89 bool EnsureRunningOverHTTP();
88 90
89 // Return true if the given test name matches the filter. This is true if 91 // Return true if the given test name matches the filter. This is true if
90 // (a) filter is empty or (b) test_name and filter match exactly. 92 // (a) filter is empty or (b) test_name and filter match exactly.
91 bool MatchesFilter(const std::string& test_name, const std::string& filter); 93 bool MatchesFilter(const std::string& test_name, const std::string& filter);
92 94
95 // Check for leaked resources and vars at the end of the test. If any exist,
96 // return a string with some information about the error. Otherwise, return
97 // an empty string.
98 std::string CheckResourcesAndVars();
99
93 // Pointer to the instance that owns us. 100 // Pointer to the instance that owns us.
94 TestingInstance* instance_; 101 TestingInstance* instance_;
95 102
96 // NULL unless InitTestingInterface is called. 103 // NULL unless InitTestingInterface is called.
97 const PPB_Testing_Dev* testing_interface_; 104 const PPB_Testing_Dev* testing_interface_;
98 105
99 // Force asynchronous completion of any operation taking a callback. 106 // Force asynchronous completion of any operation taking a callback.
100 bool force_async_; 107 bool force_async_;
101 108
102 private: 109 private:
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 static TestCaseFactory g_Test##name_factory( \ 150 static TestCaseFactory g_Test##name_factory( \
144 #name, &Test##name##_FactoryMethod \ 151 #name, &Test##name##_FactoryMethod \
145 ) 152 )
146 153
147 // Helper macro for calling functions implementing specific tests in the 154 // Helper macro for calling functions implementing specific tests in the
148 // RunTest function. This assumes the function name is TestFoo where Foo is the 155 // RunTest function. This assumes the function name is TestFoo where Foo is the
149 // test |name|. 156 // test |name|.
150 #define RUN_TEST(name, test_filter) \ 157 #define RUN_TEST(name, test_filter) \
151 if (MatchesFilter(#name, test_filter)) { \ 158 if (MatchesFilter(#name, test_filter)) { \
152 force_async_ = false; \ 159 force_async_ = false; \
153 instance_->LogTest(#name, Test##name()); \ 160 std::string error_message = Test##name(); \
161 if (error_message.empty()) \
162 error_message = CheckResourcesAndVars(); \
163 instance_->LogTest(#name, error_message); \
154 } 164 }
155 165
156 #define RUN_TEST_WITH_REFERENCE_CHECK(name, test_filter) \ 166 #define RUN_TEST_WITH_REFERENCE_CHECK(name, test_filter) \
157 if (MatchesFilter(#name, test_filter)) { \ 167 if (MatchesFilter(#name, test_filter)) { \
158 force_async_ = false; \ 168 force_async_ = false; \
159 uint32_t objects = testing_interface_->GetLiveObjectsForInstance( \ 169 uint32_t objects = testing_interface_->GetLiveObjectsForInstance( \
160 instance_->pp_instance()); \ 170 instance_->pp_instance()); \
161 std::string error_message = Test##name(); \ 171 std::string error_message = Test##name(); \
162 if (error_message.empty() && \ 172 if (error_message.empty() && \
163 testing_interface_->GetLiveObjectsForInstance( \ 173 testing_interface_->GetLiveObjectsForInstance( \
(...skipping 27 matching lines...) Expand all
191 #define ASSERT_FALSE(cmd) ASSERT_TRUE(!(cmd)) 201 #define ASSERT_FALSE(cmd) ASSERT_TRUE(!(cmd))
192 #define ASSERT_EQ(a, b) ASSERT_TRUE((a) == (b)) 202 #define ASSERT_EQ(a, b) ASSERT_TRUE((a) == (b))
193 #define ASSERT_NE(a, b) ASSERT_TRUE((a) != (b)) 203 #define ASSERT_NE(a, b) ASSERT_TRUE((a) != (b))
194 204
195 #define ASSERT_DOUBLE_EQ(a, b) ASSERT_TRUE( \ 205 #define ASSERT_DOUBLE_EQ(a, b) ASSERT_TRUE( \
196 std::fabs((a)-(b)) <= std::numeric_limits<double>::epsilon()) 206 std::fabs((a)-(b)) <= std::numeric_limits<double>::epsilon())
197 207
198 #define PASS() return std::string() 208 #define PASS() return std::string()
199 209
200 #endif // PPAPI_TESTS_TEST_CASE_H_ 210 #endif // PPAPI_TESTS_TEST_CASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698