Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / base / test / gtest_xml_unittest_result_printer.cc
blob192c228e2dd28a602dbe54f81dd4e28d487df40e
1 // Copyright 2015 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.
5 #include "base/test/gtest_xml_unittest_result_printer.h"
7 #include "base/files/file_util.h"
8 #include "base/logging.h"
9 #include "base/time/time.h"
11 namespace base {
13 XmlUnitTestResultPrinter::XmlUnitTestResultPrinter() : output_file_(NULL) {
16 XmlUnitTestResultPrinter::~XmlUnitTestResultPrinter() {
17 if (output_file_) {
18 fprintf(output_file_, "</testsuites>\n");
19 fflush(output_file_);
20 CloseFile(output_file_);
24 bool XmlUnitTestResultPrinter::Initialize(const FilePath& output_file_path) {
25 DCHECK(!output_file_);
26 output_file_ = OpenFile(output_file_path, "w");
27 if (!output_file_)
28 return false;
30 fprintf(output_file_,
31 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<testsuites>\n");
32 fflush(output_file_);
34 return true;
37 void XmlUnitTestResultPrinter::OnTestCaseStart(
38 const testing::TestCase& test_case) {
39 fprintf(output_file_, " <testsuite>\n");
40 fflush(output_file_);
43 void XmlUnitTestResultPrinter::OnTestStart(
44 const testing::TestInfo& test_info) {
45 // This is our custom extension - it helps to recognize which test was
46 // running when the test binary crashed. Note that we cannot even open the
47 // <testcase> tag here - it requires e.g. run time of the test to be known.
48 fprintf(output_file_,
49 " <x-teststart name=\"%s\" classname=\"%s\" />\n",
50 test_info.name(),
51 test_info.test_case_name());
52 fflush(output_file_);
55 void XmlUnitTestResultPrinter::OnTestEnd(const testing::TestInfo& test_info) {
56 fprintf(output_file_,
57 " <testcase name=\"%s\" status=\"run\" time=\"%.3f\""
58 " classname=\"%s\">\n",
59 test_info.name(),
60 static_cast<double>(test_info.result()->elapsed_time()) /
61 Time::kMillisecondsPerSecond,
62 test_info.test_case_name());
63 if (test_info.result()->Failed()) {
64 fprintf(output_file_,
65 " <failure message=\"\" type=\"\"></failure>\n");
67 fprintf(output_file_, " </testcase>\n");
68 fflush(output_file_);
71 void XmlUnitTestResultPrinter::OnTestCaseEnd(
72 const testing::TestCase& test_case) {
73 fprintf(output_file_, " </testsuite>\n");
74 fflush(output_file_);
77 } // namespace base