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 #include "ppapi/tests/test_case.h" | 5 #include "ppapi/tests/test_case.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // There may be a trailing comma; ignore empty strings. | 74 // There may be a trailing comma; ignore empty strings. |
75 remaining_tests->erase(std::string()); | 75 remaining_tests->erase(std::string()); |
76 } | 76 } |
77 | 77 |
78 } // namespace | 78 } // namespace |
79 | 79 |
80 TestCase::TestCase(TestingInstance* instance) | 80 TestCase::TestCase(TestingInstance* instance) |
81 : instance_(instance), | 81 : instance_(instance), |
82 testing_interface_(NULL), | 82 testing_interface_(NULL), |
83 callback_type_(PP_REQUIRED), | 83 callback_type_(PP_REQUIRED), |
84 have_populated_remaining_tests_(false) { | 84 have_populated_filter_tests_(false) { |
85 // Get the testing_interface_ if it is available, so that we can do Resource | 85 // Get the testing_interface_ if it is available, so that we can do Resource |
86 // and Var checks on shutdown (see CheckResourcesAndVars). If it is not | 86 // and Var checks on shutdown (see CheckResourcesAndVars). If it is not |
87 // available, testing_interface_ will be NULL. Some tests do not require it. | 87 // available, testing_interface_ will be NULL. Some tests do not require it. |
88 testing_interface_ = GetTestingInterface(); | 88 testing_interface_ = GetTestingInterface(); |
89 } | 89 } |
90 | 90 |
91 TestCase::~TestCase() { | 91 TestCase::~TestCase() { |
92 } | 92 } |
93 | 93 |
94 bool TestCase::Init() { | 94 bool TestCase::Init() { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 bool TestCase::ShouldRunAllTests(const std::string& filter) { | 174 bool TestCase::ShouldRunAllTests(const std::string& filter) { |
175 // If only the TestCase is listed, we're running all the tests in RunTests. | 175 // If only the TestCase is listed, we're running all the tests in RunTests. |
176 return (StripTestCase(filter) == std::string()); | 176 return (StripTestCase(filter) == std::string()); |
177 } | 177 } |
178 | 178 |
179 bool TestCase::ShouldRunTest(const std::string& test_name, | 179 bool TestCase::ShouldRunTest(const std::string& test_name, |
180 const std::string& filter) { | 180 const std::string& filter) { |
181 if (ShouldRunAllTests(filter)) | 181 if (ShouldRunAllTests(filter)) |
182 return true; | 182 return true; |
183 | 183 |
184 // Lazily initialize our "remaining_tests_" map. | 184 // Lazily initialize our "filter_tests_" map. |
185 if (!have_populated_remaining_tests_) { | 185 if (!have_populated_filter_tests_) { |
186 ParseTestFilter(filter, &remaining_tests_); | 186 ParseTestFilter(filter, &filter_tests_); |
187 have_populated_remaining_tests_ = true; | 187 remaining_tests_ = filter_tests_; |
| 188 have_populated_filter_tests_ = true; |
188 } | 189 } |
189 std::map<std::string, bool>::iterator iter = remaining_tests_.find(test_name); | 190 std::map<std::string, bool>::iterator iter = filter_tests_.find(test_name); |
190 if (iter == remaining_tests_.end()) { | 191 if (iter == filter_tests_.end()) { |
191 // The test name wasn't listed in the filter. Don't run it, but store it | 192 // The test name wasn't listed in the filter. Don't run it, but store it |
192 // so TestingInstance::ExecuteTests can report an error later. | 193 // so TestingInstance::ExecuteTests can report an error later. |
193 skipped_tests_.insert(test_name); | 194 skipped_tests_.insert(test_name); |
194 return false; | 195 return false; |
195 } | 196 } |
196 bool should_run_test = iter->second; | 197 remaining_tests_.erase(test_name); |
197 remaining_tests_.erase(iter); | 198 return iter->second; |
198 return should_run_test; | |
199 } | 199 } |
200 | 200 |
201 PP_TimeTicks TestCase::NowInTimeTicks() { | 201 PP_TimeTicks TestCase::NowInTimeTicks() { |
202 return pp::Module::Get()->core()->GetTimeTicks(); | 202 return pp::Module::Get()->core()->GetTimeTicks(); |
203 } | 203 } |
204 | 204 |
205 std::string TestCase::CheckResourcesAndVars(std::string errors) { | 205 std::string TestCase::CheckResourcesAndVars(std::string errors) { |
206 if (!errors.empty()) | 206 if (!errors.empty()) |
207 return errors; | 207 return errors; |
208 | 208 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 void TestCase::RunOnThreadInternal(void (*thread_func)(void*), | 257 void TestCase::RunOnThreadInternal(void (*thread_func)(void*), |
258 void* thread_param, | 258 void* thread_param, |
259 const PPB_Testing_Dev* testing_interface) { | 259 const PPB_Testing_Dev* testing_interface) { |
260 PP_ThreadType thread; | 260 PP_ThreadType thread; |
261 PP_CreateThread(&thread, thread_func, thread_param); | 261 PP_CreateThread(&thread, thread_func, thread_param); |
262 // Run a message loop so pepper calls can be dispatched. The background | 262 // Run a message loop so pepper calls can be dispatched. The background |
263 // thread will set result_ and make us Quit when it's done. | 263 // thread will set result_ and make us Quit when it's done. |
264 testing_interface->RunMessageLoop(instance_->pp_instance()); | 264 testing_interface->RunMessageLoop(instance_->pp_instance()); |
265 PP_JoinThread(thread); | 265 PP_JoinThread(thread); |
266 } | 266 } |
OLD | NEW |