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

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

Issue 2606153003: Report failed expect/assert to test launcher summary output. (Closed)
Patch Set: Always provide unencoded summary. 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
« no previous file with comments | « base/test/gtest_xml_unittest_result_printer.cc ('k') | base/test/launcher/test_result.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 if (!Base64Decode(summary, &summary))
192 return false;
193
194 DCHECK(!results->empty());
195 DCHECK(!results->back().test_result_parts.empty());
196 results->back().test_result_parts.back().summary = summary;
197 } else if (node_name == "summary" && xml_reader.IsClosingElement()) {
198 } else if (node_name == "message" && !xml_reader.IsClosingElement()) {
199 std::string message;
200 if (!xml_reader.ReadElementContent(&message))
201 return false;
202
203 if (!Base64Decode(message, &message))
204 return false;
205
206 DCHECK(!results->empty());
207 DCHECK(!results->back().test_result_parts.empty());
208 results->back().test_result_parts.back().message = message;
209 } else if (node_name == "message" && xml_reader.IsClosingElement()) {
210 } else if (node_name == "x-test-result-part" &&
211 xml_reader.IsClosingElement()) {
212 state = STATE_TESTCASE;
213 } else {
214 return false;
215 }
151 break; 216 break;
152 case STATE_FAILURE: 217 case STATE_FAILURE:
153 if (node_name == "failure" && xml_reader.IsClosingElement()) 218 if (node_name == "failure" && xml_reader.IsClosingElement())
154 state = STATE_TESTCASE; 219 state = STATE_TESTCASE;
155 else 220 else
156 return false; 221 return false;
157 break; 222 break;
158 case STATE_END: 223 case STATE_END:
159 // If we are here and there are still XML elements, the file has wrong 224 // If we are here and there are still XML elements, the file has wrong
160 // format. 225 // format.
161 return false; 226 return false;
162 } 227 }
163 } 228 }
164 229
165 *crashed = (state != STATE_END); 230 *crashed = (state != STATE_END);
166 return true; 231 return true;
167 } 232 }
168 233
169 } // namespace base 234 } // namespace base
OLDNEW
« no previous file with comments | « base/test/gtest_xml_unittest_result_printer.cc ('k') | base/test/launcher/test_result.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698