OLD | NEW |
1 // Copyright (c) 2010 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 <string.h> | 8 #include <cstring> |
| 9 #include <vector> |
9 | 10 |
10 #include "ppapi/cpp/module.h" | 11 #include "ppapi/cpp/module.h" |
11 #include "ppapi/cpp/var.h" | 12 #include "ppapi/cpp/var.h" |
12 #include "ppapi/tests/test_case.h" | 13 #include "ppapi/tests/test_case.h" |
13 | 14 |
14 TestCaseFactory* TestCaseFactory::head_ = NULL; | 15 TestCaseFactory* TestCaseFactory::head_ = NULL; |
15 | 16 |
16 // Returns a new heap-allocated test case for the given test, or NULL on | 17 // Returns a new heap-allocated test case for the given test, or NULL on |
17 // failure. | 18 // failure. |
18 TestingInstance::TestingInstance(PP_Instance instance) | 19 TestingInstance::TestingInstance(PP_Instance instance) |
19 : pp::Instance(instance), | 20 : pp::Instance(instance), |
20 current_case_(NULL), | 21 current_case_(NULL), |
21 executed_tests_(false), | 22 executed_tests_(false), |
22 nacl_mode_(false) { | 23 nacl_mode_(false) { |
23 callback_factory_.Initialize(this); | 24 callback_factory_.Initialize(this); |
24 } | 25 } |
25 | 26 |
26 bool TestingInstance::Init(uint32_t argc, | 27 bool TestingInstance::Init(uint32_t argc, |
27 const char* argn[], | 28 const char* argn[], |
28 const char* argv[]) { | 29 const char* argv[]) { |
29 for (uint32_t i = 0; i < argc; i++) { | 30 for (uint32_t i = 0; i < argc; i++) { |
30 if (strcmp(argn[i], "mode") == 0) { | 31 if (std::strcmp(argn[i], "mode") == 0) { |
31 if (strcmp(argv[i], "nacl") == 0) | 32 if (std::strcmp(argv[i], "nacl") == 0) |
32 nacl_mode_ = true; | 33 nacl_mode_ = true; |
33 break; | 34 break; |
34 } | 35 } |
35 } | 36 } |
36 // Create the proper test case from the argument. | 37 // Create the proper test case from the argument. |
37 for (uint32_t i = 0; i < argc; i++) { | 38 for (uint32_t i = 0; i < argc; i++) { |
38 if (strcmp(argn[i], "testcase") == 0) { | 39 if (std::strcmp(argn[i], "testcase") == 0) { |
39 if (argv[i][0] == '\0') | 40 if (argv[i][0] == '\0') |
40 break; | 41 break; |
41 current_case_ = CaseForTestName(argv[i]); | 42 current_case_ = CaseForTestName(argv[i]); |
42 if (!current_case_) | 43 if (!current_case_) |
43 errors_.append(std::string("Unknown test case ") + argv[i]); | 44 errors_.append(std::string("Unknown test case ") + argv[i]); |
44 else if (!current_case_->Init()) | 45 else if (!current_case_->Init()) |
45 errors_.append(" Test case could not initialize."); | 46 errors_.append(" Test case could not initialize."); |
46 return true; | 47 return true; |
47 } | 48 } |
48 } | 49 } |
49 | 50 |
50 // In DidChangeView, we'll dump out a list of all available tests. | 51 // In DidChangeView, we'll dump out a list of all available tests. |
51 return true; | 52 return true; |
52 } | 53 } |
53 | 54 |
54 pp::Var TestingInstance::GetInstanceObject() { | 55 pp::Var TestingInstance::GetInstanceObject() { |
55 return current_case_->GetTestObject(); | 56 return current_case_->GetTestObject(); |
56 } | 57 } |
57 | 58 |
| 59 void TestingInstance::HandleMessage(const pp::Var& message_data) { |
| 60 current_case_->HandleMessage(message_data); |
| 61 } |
| 62 |
58 void TestingInstance::DidChangeView(const pp::Rect& position, | 63 void TestingInstance::DidChangeView(const pp::Rect& position, |
59 const pp::Rect& clip) { | 64 const pp::Rect& clip) { |
60 if (!executed_tests_) { | 65 if (!executed_tests_) { |
61 executed_tests_ = true; | 66 executed_tests_ = true; |
62 pp::Module::Get()->core()->CallOnMainThread( | 67 pp::Module::Get()->core()->CallOnMainThread( |
63 0, | 68 0, |
64 callback_factory_.NewCallback(&TestingInstance::ExecuteTests)); | 69 callback_factory_.NewCallback(&TestingInstance::ExecuteTests)); |
65 } | 70 } |
66 } | 71 } |
67 | 72 |
68 void TestingInstance::LogTest(const std::string& test_name, | 73 void TestingInstance::LogTest(const std::string& test_name, |
69 const std::string& error_message) { | 74 const std::string& error_message) { |
70 std::string html; | 75 std::string html; |
71 html.append("<div class=\"test_line\"><span class=\"test_name\">"); | 76 html.append("<div class=\"test_line\"><span class=\"test_name\">"); |
72 html.append(test_name); | 77 html.append(test_name); |
73 html.append("</span> "); | 78 html.append("</span> "); |
74 if (error_message.empty()) { | 79 if (error_message.empty()) { |
75 html.append("<span class=\"pass\">PASS</span>"); | 80 html.append("<span class=\"pass\">PASS</span>"); |
76 } else { | 81 } else { |
77 html.append("<span class=\"fail\">FAIL</span>: <span class=\"err_msg\">"); | 82 html.append("<span class=\"fail\">FAIL</span>: <span class=\"err_msg\">"); |
78 html.append(error_message); | 83 html.append(error_message); |
79 html.append("</span>"); | 84 html.append("</span>"); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 118 |
114 // Declare we're done by setting a cookie to either "PASS" or the errors. | 119 // Declare we're done by setting a cookie to either "PASS" or the errors. |
115 SetCookie("COMPLETION_COOKIE", errors_.empty() ? "PASS" : errors_); | 120 SetCookie("COMPLETION_COOKIE", errors_.empty() ? "PASS" : errors_); |
116 | 121 |
117 window.Call("DidExecuteTests"); | 122 window.Call("DidExecuteTests"); |
118 } | 123 } |
119 | 124 |
120 TestCase* TestingInstance::CaseForTestName(const char* name) { | 125 TestCase* TestingInstance::CaseForTestName(const char* name) { |
121 TestCaseFactory* iter = TestCaseFactory::head_; | 126 TestCaseFactory* iter = TestCaseFactory::head_; |
122 while (iter != NULL) { | 127 while (iter != NULL) { |
123 if (strcmp(name, iter->name_) == 0) | 128 if (std::strcmp(name, iter->name_) == 0) |
124 return iter->method_(this); | 129 return iter->method_(this); |
125 iter = iter->next_; | 130 iter = iter->next_; |
126 } | 131 } |
127 return NULL; | 132 return NULL; |
128 } | 133 } |
129 | 134 |
130 void TestingInstance::LogAvailableTests() { | 135 void TestingInstance::LogAvailableTests() { |
131 // Print out a listing of all tests. | 136 // Print out a listing of all tests. |
132 std::vector<std::string> test_cases; | 137 std::vector<std::string> test_cases; |
133 TestCaseFactory* iter = TestCaseFactory::head_; | 138 TestCaseFactory* iter = TestCaseFactory::head_; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 } | 192 } |
188 }; | 193 }; |
189 | 194 |
190 namespace pp { | 195 namespace pp { |
191 | 196 |
192 Module* CreateModule() { | 197 Module* CreateModule() { |
193 return new ::Module(); | 198 return new ::Module(); |
194 } | 199 } |
195 | 200 |
196 } // namespace pp | 201 } // namespace pp |
OLD | NEW |