Index: base/test/gtest_xml_unittest_result_printer.cc |
diff --git a/base/test/gtest_xml_unittest_result_printer.cc b/base/test/gtest_xml_unittest_result_printer.cc |
index 192c228e2dd28a602dbe54f81dd4e28d487df40e..9228d14fc9b126a0bf346914acb8b7a241b19bf6 100644 |
--- a/base/test/gtest_xml_unittest_result_printer.cc |
+++ b/base/test/gtest_xml_unittest_result_printer.cc |
@@ -4,12 +4,23 @@ |
#include "base/test/gtest_xml_unittest_result_printer.h" |
+#include "base/base64.h" |
#include "base/files/file_util.h" |
#include "base/logging.h" |
+#include "base/strings/string_util.h" |
#include "base/time/time.h" |
namespace base { |
+namespace { |
+ |
+bool NeedsEscaping(const std::string& text) { |
+ return !IsStringUTF8(text) || text.find('<') != std::string::npos || |
+ text.find('>') != std::string::npos; |
+} |
+ |
+} // namespace |
+ |
XmlUnitTestResultPrinter::XmlUnitTestResultPrinter() : output_file_(NULL) { |
} |
@@ -64,6 +75,9 @@ void XmlUnitTestResultPrinter::OnTestEnd(const testing::TestInfo& test_info) { |
fprintf(output_file_, |
" <failure message=\"\" type=\"\"></failure>\n"); |
} |
+ for (int i = 0; i < test_info.result()->total_part_count(); ++i) { |
+ WriteTestPartResult(test_info.result()->GetTestPartResult(i)); |
+ } |
fprintf(output_file_, " </testcase>\n"); |
fflush(output_file_); |
} |
@@ -74,4 +88,41 @@ void XmlUnitTestResultPrinter::OnTestCaseEnd( |
fflush(output_file_); |
} |
+void XmlUnitTestResultPrinter::WriteTestPartResult( |
+ const testing::TestPartResult& test_part_result) { |
+ const char* type = "unknown"; |
+ switch (test_part_result.type()) { |
+ case testing::TestPartResult::kSuccess: |
+ type = "success"; |
+ break; |
+ case testing::TestPartResult::kNonFatalFailure: |
+ type = "failure"; |
+ break; |
+ case testing::TestPartResult::kFatalFailure: |
+ type = "fatal_failure"; |
+ break; |
+ } |
+ std::string summary = test_part_result.summary(); |
+ std::string summary_tag("summary"); |
+ if (!NeedsEscaping(summary)) { |
Paweł Hajdan Jr.
2016/12/30 19:02:39
Shouldn't the condition be reversed?
By the way,
alex-ac
2016/12/30 22:10:20
I've deleted condition and now text is encoded in
|
+ Base64Encode(summary, &summary); |
+ summary_tag = "summary-encoded"; |
+ } |
+ std::string message = test_part_result.message(); |
+ std::string message_tag("message"); |
+ if (!NeedsEscaping(message)) { |
+ Base64Encode(message, &message); |
+ message_tag = "message-encoded"; |
+ } |
+ fprintf(output_file_, |
+ " <x-test-result-part type=\"%s\" file=\"%s\" line=\"%d\">\n" |
+ " <%s>%s</%s>\n" |
+ " <%s>%s</%s>\n" |
+ " </x-test-result-part>\n", |
+ type, test_part_result.file_name(), test_part_result.line_number(), |
+ summary_tag.c_str(), summary.c_str(), summary_tag.c_str(), |
+ message_tag.c_str(), message.c_str(), message_tag.c_str()); |
+ fflush(output_file_); |
+} |
+ |
} // namespace base |