OLD | NEW |
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 #include "ppapi/tests/testing_instance.h" | 5 #include "ppapi/tests/testing_instance.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <sstream> | 9 #include <sstream> |
10 #include <vector> | 10 #include <vector> |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 } | 49 } |
50 else if (std::strcmp(argn[i], "protocol") == 0) | 50 else if (std::strcmp(argn[i], "protocol") == 0) |
51 protocol_ = argv[i]; | 51 protocol_ = argv[i]; |
52 } | 52 } |
53 // Create the proper test case from the argument. | 53 // Create the proper test case from the argument. |
54 for (uint32_t i = 0; i < argc; i++) { | 54 for (uint32_t i = 0; i < argc; i++) { |
55 if (std::strcmp(argn[i], "testcase") == 0) { | 55 if (std::strcmp(argn[i], "testcase") == 0) { |
56 if (argv[i][0] == '\0') | 56 if (argv[i][0] == '\0') |
57 break; | 57 break; |
58 current_case_ = CaseForTestName(argv[i]); | 58 current_case_ = CaseForTestName(argv[i]); |
| 59 test_filter_ = FilterForTestName(argv[i]); |
59 if (!current_case_) | 60 if (!current_case_) |
60 errors_.append(std::string("Unknown test case ") + argv[i]); | 61 errors_.append(std::string("Unknown test case ") + argv[i]); |
61 else if (!current_case_->Init()) | 62 else if (!current_case_->Init()) |
62 errors_.append(" Test case could not initialize."); | 63 errors_.append(" Test case could not initialize."); |
63 return true; | 64 return true; |
64 } | 65 } |
65 } | 66 } |
66 | 67 |
67 // In DidChangeView, we'll dump out a list of all available tests. | 68 // In DidChangeView, we'll dump out a list of all available tests. |
68 return true; | 69 return true; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 PostMessage(pp::Var("TESTING_MESSAGE:ClearConsole")); | 138 PostMessage(pp::Var("TESTING_MESSAGE:ClearConsole")); |
138 | 139 |
139 if (!errors_.empty()) { | 140 if (!errors_.empty()) { |
140 // Catch initialization errors and output the current error string to | 141 // Catch initialization errors and output the current error string to |
141 // the console. | 142 // the console. |
142 LogError("Plugin initialization failed: " + errors_); | 143 LogError("Plugin initialization failed: " + errors_); |
143 } else if (!current_case_) { | 144 } else if (!current_case_) { |
144 LogAvailableTests(); | 145 LogAvailableTests(); |
145 errors_.append("FAIL: Only listed tests"); | 146 errors_.append("FAIL: Only listed tests"); |
146 } else { | 147 } else { |
147 current_case_->RunTest(); | 148 current_case_->RunTests(test_filter_); |
148 // Automated PyAuto tests rely on finding the exact strings below. | 149 // Automated PyAuto tests rely on finding the exact strings below. |
149 LogHTML(errors_.empty() ? | 150 LogHTML(errors_.empty() ? |
150 "<span class=\"pass\">[SHUTDOWN]</span> All tests passed." : | 151 "<span class=\"pass\">[SHUTDOWN]</span> All tests passed." : |
151 "<span class=\"fail\">[SHUTDOWN]</span> Some tests failed."); | 152 "<span class=\"fail\">[SHUTDOWN]</span> Some tests failed."); |
152 } | 153 } |
153 | 154 |
154 // Declare we're done by setting a cookie to either "PASS" or the errors. | 155 // Declare we're done by setting a cookie to either "PASS" or the errors. |
155 ReportProgress(errors_.empty() ? "PASS" : errors_); | 156 ReportProgress(errors_.empty() ? "PASS" : errors_); |
156 PostMessage(pp::Var("TESTING_MESSAGE:DidExecuteTests")); | 157 PostMessage(pp::Var("TESTING_MESSAGE:DidExecuteTests")); |
157 } | 158 } |
158 | 159 |
159 TestCase* TestingInstance::CaseForTestName(const char* name) { | 160 TestCase* TestingInstance::CaseForTestName(const std::string& name) { |
| 161 std::string case_name = name.substr(0, name.find_first_of('_')); |
160 TestCaseFactory* iter = TestCaseFactory::head_; | 162 TestCaseFactory* iter = TestCaseFactory::head_; |
161 while (iter != NULL) { | 163 while (iter != NULL) { |
162 if (std::strcmp(name, iter->name_) == 0) | 164 if (case_name == iter->name_) |
163 return iter->method_(this); | 165 return iter->method_(this); |
164 iter = iter->next_; | 166 iter = iter->next_; |
165 } | 167 } |
166 return NULL; | 168 return NULL; |
167 } | 169 } |
168 | 170 |
| 171 std::string TestingInstance::FilterForTestName(const std::string& name) { |
| 172 size_t delim = name.find_first_of('_'); |
| 173 if (delim != std::string::npos) |
| 174 return name.substr(delim+1); |
| 175 return ""; |
| 176 } |
| 177 |
169 void TestingInstance::LogAvailableTests() { | 178 void TestingInstance::LogAvailableTests() { |
170 // Print out a listing of all tests. | 179 // Print out a listing of all tests. |
171 std::vector<std::string> test_cases; | 180 std::vector<std::string> test_cases; |
172 TestCaseFactory* iter = TestCaseFactory::head_; | 181 TestCaseFactory* iter = TestCaseFactory::head_; |
173 while (iter != NULL) { | 182 while (iter != NULL) { |
174 test_cases.push_back(iter->name_); | 183 test_cases.push_back(iter->name_); |
175 iter = iter->next_; | 184 iter = iter->next_; |
176 } | 185 } |
177 std::sort(test_cases.begin(), test_cases.end()); | 186 std::sort(test_cases.begin(), test_cases.end()); |
178 | 187 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 } | 243 } |
235 }; | 244 }; |
236 | 245 |
237 namespace pp { | 246 namespace pp { |
238 | 247 |
239 Module* CreateModule() { | 248 Module* CreateModule() { |
240 return new ::Module(); | 249 return new ::Module(); |
241 } | 250 } |
242 | 251 |
243 } // namespace pp | 252 } // namespace pp |
OLD | NEW |