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

Side by Side Diff: base/test/gtest_xml_util.cc

Issue 2606153003: Report failed expect/assert to test launcher summary output. (Closed)
Patch Set: Fix msvc warning. Created 3 years, 11 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/test/gtest_xml_util.h" 5 #include "base/test/gtest_xml_util.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/base64.h"
9 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
12 #include "base/test/gtest_util.h" 14 #include "base/test/gtest_util.h"
13 #include "base/test/launcher/test_launcher.h" 15 #include "base/test/launcher/test_launcher.h"
14 #include "third_party/libxml/chromium/libxml_utils.h" 16 #include "third_party/libxml/chromium/libxml_utils.h"
15 17
16 namespace base { 18 namespace base {
17 19
18 namespace { 20 namespace {
19 21
20 // This is used for the xml parser to report errors. This assumes the context 22 // This is used for the xml parser to report errors. This assumes the context
(...skipping 22 matching lines...) Expand all
43 ScopedXmlErrorFunc error_func(&xml_errors, &XmlErrorFunc); 45 ScopedXmlErrorFunc error_func(&xml_errors, &XmlErrorFunc);
44 46
45 XmlReader xml_reader; 47 XmlReader xml_reader;
46 if (!xml_reader.Load(xml_contents)) 48 if (!xml_reader.Load(xml_contents))
47 return false; 49 return false;
48 50
49 enum { 51 enum {
50 STATE_INIT, 52 STATE_INIT,
51 STATE_TESTSUITE, 53 STATE_TESTSUITE,
52 STATE_TESTCASE, 54 STATE_TESTCASE,
55 STATE_TEST_RESULT,
53 STATE_FAILURE, 56 STATE_FAILURE,
54 STATE_END, 57 STATE_END,
55 } state = STATE_INIT; 58 } state = STATE_INIT;
56 59
57 while (xml_reader.Read()) { 60 while (xml_reader.Read()) {
58 xml_reader.SkipToElement(); 61 xml_reader.SkipToElement();
59 std::string node_name(xml_reader.NodeName()); 62 std::string node_name(xml_reader.NodeName());
60 63
61 switch (state) { 64 switch (state) {
62 case STATE_INIT: 65 case STATE_INIT:
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 std::string failure_message; 141 std::string failure_message;
139 if (!xml_reader.NodeAttribute("message", &failure_message)) 142 if (!xml_reader.NodeAttribute("message", &failure_message))
140 return false; 143 return false;
141 144
142 DCHECK(!results->empty()); 145 DCHECK(!results->empty());
143 results->back().status = TestResult::TEST_FAILURE; 146 results->back().status = TestResult::TEST_FAILURE;
144 147
145 state = STATE_FAILURE; 148 state = STATE_FAILURE;
146 } else if (node_name == "testcase" && xml_reader.IsClosingElement()) { 149 } else if (node_name == "testcase" && xml_reader.IsClosingElement()) {
147 // Deliberately empty. 150 // Deliberately empty.
151 } else if (node_name == "x-test-result-part" &&
152 !xml_reader.IsClosingElement()) {
153 std::string result_type;
154 if (!xml_reader.NodeAttribute("type", &result_type))
155 return false;
156
157 std::string file_name;
158 if (!xml_reader.NodeAttribute("file", &file_name))
159 return false;
160
161 std::string line_number_str;
162 if (!xml_reader.NodeAttribute("line", &line_number_str))
163 return false;
164
165 int line_number;
166 if (!StringToInt(line_number_str, &line_number))
167 return false;
168
169 TestResultPart::Type type;
170 if (!TestResultPart::TypeFromString(result_type, &type))
171 return false;
172
173 TestResultPart test_result_part;
174 test_result_part.type = type;
175 test_result_part.file_name = file_name,
176 test_result_part.line_number = line_number;
177 DCHECK(!results->empty());
178 results->back().test_result_parts.push_back(test_result_part);
179
180 state = STATE_TEST_RESULT;
148 } else { 181 } else {
149 return false; 182 return false;
150 } 183 }
184 break;
185 case STATE_TEST_RESULT:
186 if (node_name == "summary" && !xml_reader.IsClosingElement()) {
187 std::string summary;
188 if (!xml_reader.ReadElementContent(&summary))
189 return false;
190
191 DCHECK(!results->empty());
192 DCHECK(!results->back().test_result_parts.empty());
193 results->back().test_result_parts.back().summary = summary;
194 } else if (node_name == "summary" && xml_reader.IsClosingElement()) {
195 } else if (node_name == "summary-encoded" &&
196 !xml_reader.IsClosingElement()) {
197 std::string summary;
198 if (!xml_reader.ReadElementContent(&summary))
199 return false;
200
201 if (!Base64Decode(summary, &summary))
202 return false;
203
204 DCHECK(!results->empty());
205 DCHECK(!results->back().test_result_parts.empty());
206 results->back().test_result_parts.back().summary = summary;
207 } else if (node_name == "summary-encoded" &&
208 xml_reader.IsClosingElement()) {
209 } else if (node_name == "message" && !xml_reader.IsClosingElement()) {
210 std::string message;
211 if (!xml_reader.ReadElementContent(&message))
212 return false;
213
214 DCHECK(!results->empty());
215 DCHECK(!results->back().test_result_parts.empty());
216 results->back().test_result_parts.back().message = message;
217 } else if (node_name == "message" && xml_reader.IsClosingElement()) {
218 } else if (node_name == "message-encoded" &&
219 !xml_reader.IsClosingElement()) {
220 std::string message;
221 if (!xml_reader.ReadElementContent(&message))
222 return false;
223
224 if (!Base64Decode(message, &message))
225 return false;
226
227 DCHECK(!results->empty());
228 DCHECK(!results->back().test_result_parts.empty());
229 results->back().test_result_parts.back().message = message;
230 } else if (node_name == "message" && xml_reader.IsClosingElement()) {
231 } else if (node_name == "x-test-result-part" &&
232 xml_reader.IsClosingElement()) {
233 state = STATE_TESTCASE;
234 } else {
235 return false;
236 }
151 break; 237 break;
152 case STATE_FAILURE: 238 case STATE_FAILURE:
153 if (node_name == "failure" && xml_reader.IsClosingElement()) 239 if (node_name == "failure" && xml_reader.IsClosingElement())
154 state = STATE_TESTCASE; 240 state = STATE_TESTCASE;
155 else 241 else
156 return false; 242 return false;
157 break; 243 break;
158 case STATE_END: 244 case STATE_END:
159 // If we are here and there are still XML elements, the file has wrong 245 // If we are here and there are still XML elements, the file has wrong
160 // format. 246 // format.
161 return false; 247 return false;
162 } 248 }
163 } 249 }
164 250
165 *crashed = (state != STATE_END); 251 *crashed = (state != STATE_END);
166 return true; 252 return true;
167 } 253 }
168 254
169 } // namespace base 255 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698