OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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_unittest_result_printer.h" | 5 #include "base/test/gtest_xml_unittest_result_printer.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 if (!output_file_) | 28 if (!output_file_) |
29 return false; | 29 return false; |
30 | 30 |
31 fprintf(output_file_, | 31 fprintf(output_file_, |
32 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<testsuites>\n"); | 32 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<testsuites>\n"); |
33 fflush(output_file_); | 33 fflush(output_file_); |
34 | 34 |
35 return true; | 35 return true; |
36 } | 36 } |
37 | 37 |
38 void XmlUnitTestResultPrinter::OnAssert(const char* file, | |
39 int line, | |
40 const std::string& summary, | |
41 const std::string& message) { | |
42 if (!output_file_) | |
brettw
2017/04/17 22:20:34
This function seems to duplicate WriteTestPartResu
alex-ac
2017/04/18 06:34:21
Done.
| |
43 return; | |
44 | |
45 std::string encoded_summary; | |
46 Base64Encode(summary, &encoded_summary); | |
47 std::string encoded_message; | |
48 Base64Encode(message, &encoded_message); | |
49 fprintf(output_file_, | |
50 " <x-test-result-part type=\"fatal_failure\" " | |
51 "file=\"%s\" line=\"%d\">\n" | |
52 " <summary>%s</summary>\n" | |
53 " <message>%s</message>\n" | |
54 " </x-test-result-part>", | |
55 file, line, encoded_summary.c_str(), encoded_message.c_str()); | |
56 fflush(output_file_); | |
57 } | |
58 | |
38 void XmlUnitTestResultPrinter::OnTestCaseStart( | 59 void XmlUnitTestResultPrinter::OnTestCaseStart( |
39 const testing::TestCase& test_case) { | 60 const testing::TestCase& test_case) { |
40 fprintf(output_file_, " <testsuite>\n"); | 61 fprintf(output_file_, " <testsuite>\n"); |
41 fflush(output_file_); | 62 fflush(output_file_); |
42 } | 63 } |
43 | 64 |
44 void XmlUnitTestResultPrinter::OnTestStart( | 65 void XmlUnitTestResultPrinter::OnTestStart( |
45 const testing::TestInfo& test_info) { | 66 const testing::TestInfo& test_info) { |
46 // This is our custom extension - it helps to recognize which test was | 67 // This is our custom extension - it helps to recognize which test was |
47 // running when the test binary crashed. Note that we cannot even open the | 68 // running when the test binary crashed. Note that we cannot even open the |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 " <x-test-result-part type=\"%s\" file=\"%s\" line=\"%d\">\n" | 123 " <x-test-result-part type=\"%s\" file=\"%s\" line=\"%d\">\n" |
103 " <summary>%s</summary>\n" | 124 " <summary>%s</summary>\n" |
104 " <message>%s</message>\n" | 125 " <message>%s</message>\n" |
105 " </x-test-result-part>\n", | 126 " </x-test-result-part>\n", |
106 type, test_part_result.file_name(), test_part_result.line_number(), | 127 type, test_part_result.file_name(), test_part_result.line_number(), |
107 summary_encoded.c_str(), message_encoded.c_str()); | 128 summary_encoded.c_str(), message_encoded.c_str()); |
108 fflush(output_file_); | 129 fflush(output_file_); |
109 } | 130 } |
110 | 131 |
111 } // namespace base | 132 } // namespace base |
OLD | NEW |