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

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

Issue 23132002: GTTF: Add a basic new unit test launcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed gyp cycle Created 7 years, 4 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_util.h ('k') | base/test/run_all_unittests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/test/gtest_xml_util.h"
6
7 #include "base/file_util.h"
8 #include "base/logging.h"
9 #include "base/test/test_launcher.h"
10 #include "third_party/libxml/chromium/libxml_utils.h"
11
12 namespace base {
13
14 bool ProcessGTestOutput(const base::FilePath& output_file,
15 std::vector<TestResult>* results) {
16 DCHECK(results);
17
18 std::string xml_contents;
19 if (!file_util::ReadFileToString(output_file, &xml_contents))
20 return false;
21
22 XmlReader xml_reader;
23 if (!xml_reader.Load(xml_contents))
24 return false;
25
26 enum {
27 STATE_INIT,
28 STATE_TESTSUITE,
29 STATE_TESTCASE,
30 STATE_FAILURE,
31 STATE_END,
32 } state = STATE_INIT;
33
34 while (xml_reader.Read()) {
35 xml_reader.SkipToElement();
36 std::string node_name(xml_reader.NodeName());
37
38 switch (state) {
39 case STATE_INIT:
40 if (node_name == "testsuites" && !xml_reader.IsClosingElement())
41 state = STATE_TESTSUITE;
42 else
43 return false;
44 break;
45 case STATE_TESTSUITE:
46 if (node_name == "testsuites" && xml_reader.IsClosingElement())
47 state = STATE_END;
48 else if (node_name == "testsuite" && !xml_reader.IsClosingElement())
49 state = STATE_TESTCASE;
50 else
51 return false;
52 break;
53 case STATE_TESTCASE:
54 if (node_name == "testsuite" && xml_reader.IsClosingElement()) {
55 state = STATE_TESTSUITE;
56 } else if (node_name == "testcase" && !xml_reader.IsClosingElement()) {
57 std::string test_status;
58 if (!xml_reader.NodeAttribute("status", &test_status))
59 return false;
60
61 if (test_status != "run" && test_status != "notrun")
62 return false;
63 if (test_status != "run")
64 break;
65
66 TestResult result;
67 if (!xml_reader.NodeAttribute("classname", &result.test_case_name))
68 return false;
69 if (!xml_reader.NodeAttribute("name", &result.test_name))
70 return false;
71
72 std::string test_time_str;
73 if (!xml_reader.NodeAttribute("time", &test_time_str))
74 return false;
75 result.elapsed_time =
76 TimeDelta::FromMicroseconds(strtod(test_time_str.c_str(), NULL) *
77 Time::kMicrosecondsPerSecond);
78
79 result.success = true;
80
81 results->push_back(result);
82 } else if (node_name == "failure" && !xml_reader.IsClosingElement()) {
83 std::string failure_message;
84 if (!xml_reader.NodeAttribute("message", &failure_message))
85 return false;
86
87 DCHECK(!results->empty());
88 results->at(results->size() - 1).success = false;
89
90 state = STATE_FAILURE;
91 } else if (node_name == "testcase" && xml_reader.IsClosingElement()) {
92 // Deliberately empty.
93 } else {
94 return false;
95 }
96 break;
97 case STATE_FAILURE:
98 if (node_name == "failure" && xml_reader.IsClosingElement())
99 state = STATE_TESTCASE;
100 else
101 return false;
102 break;
103 case STATE_END:
104 // If we are here and there are still XML elements, the file has wrong
105 // format.
106 return false;
107 }
108 }
109
110 return true;
111 }
112
113 } // namespace base
OLDNEW
« no previous file with comments | « base/test/gtest_xml_util.h ('k') | base/test/run_all_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698