OLD | NEW |
---|---|
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 #ifndef BASE_TEST_GTEST_XML_UNITTEST_RESULT_PRINTER_H_ | 5 #ifndef BASE_TEST_GTEST_XML_UNITTEST_RESULT_PRINTER_H_ |
6 #define BASE_TEST_GTEST_XML_UNITTEST_RESULT_PRINTER_H_ | 6 #define BASE_TEST_GTEST_XML_UNITTEST_RESULT_PRINTER_H_ |
7 | 7 |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 | 15 |
16 class FilePath; | 16 class FilePath; |
17 | 17 |
18 // Generates an XML output file. Format is very close to GTest, but has | 18 // Generates an XML output file. Format is very close to GTest, but has |
19 // extensions needed by the test launcher. | 19 // extensions needed by the test launcher. |
20 class XmlUnitTestResultPrinter : public testing::EmptyTestEventListener { | 20 class XmlUnitTestResultPrinter : public testing::EmptyTestEventListener { |
21 public: | 21 public: |
22 XmlUnitTestResultPrinter(); | 22 XmlUnitTestResultPrinter(); |
23 ~XmlUnitTestResultPrinter() override; | 23 ~XmlUnitTestResultPrinter() override; |
24 | 24 |
25 // Some tests may contain broken EXPECT with a large message inside a loop | |
26 // with several thousands iterations and produce huge output (several | |
27 // gigabytes). Limit number of serialized test result parts to prevent it. | |
28 // Zero value disables test part results. | |
29 // Negative value disables limit. | |
30 void set_test_part_results_limit(int limit) { | |
Paweł Hajdan Jr.
2017/05/05 17:33:03
Instead of a setter, can we make this class read c
alex-ac
2017/05/07 12:07:24
Done.
| |
31 test_part_results_limit_ = limit; | |
32 } | |
33 int test_part_results_limit() const { return test_part_results_limit_; } | |
34 bool has_test_part_results_limit() const { | |
35 return test_part_results_limit_ >= 0; | |
36 } | |
37 | |
25 // Must be called before adding as a listener. Returns true on success. | 38 // Must be called before adding as a listener. Returns true on success. |
26 bool Initialize(const FilePath& output_file_path) WARN_UNUSED_RESULT; | 39 bool Initialize(const FilePath& output_file_path) WARN_UNUSED_RESULT; |
27 | 40 |
28 // CHECK/DCHECK failed. Print file/line and message to the xml. | 41 // CHECK/DCHECK failed. Print file/line and message to the xml. |
29 void OnAssert(const char* file, | 42 void OnAssert(const char* file, |
30 int line, | 43 int line, |
31 const std::string& summary, | 44 const std::string& summary, |
32 const std::string& message); | 45 const std::string& message); |
33 | 46 |
34 private: | 47 private: |
35 // testing::EmptyTestEventListener: | 48 // testing::EmptyTestEventListener: |
36 void OnTestCaseStart(const testing::TestCase& test_case) override; | 49 void OnTestCaseStart(const testing::TestCase& test_case) override; |
37 void OnTestStart(const testing::TestInfo& test_info) override; | 50 void OnTestStart(const testing::TestInfo& test_info) override; |
38 void OnTestEnd(const testing::TestInfo& test_info) override; | 51 void OnTestEnd(const testing::TestInfo& test_info) override; |
39 void OnTestCaseEnd(const testing::TestCase& test_case) override; | 52 void OnTestCaseEnd(const testing::TestCase& test_case) override; |
40 | 53 |
41 void WriteTestPartResult(const char* file, | 54 void WriteTestPartResult(const char* file, |
42 int line, | 55 int line, |
43 testing::TestPartResult::Type type, | 56 testing::TestPartResult::Type type, |
44 const std::string& summary, | 57 const std::string& summary, |
45 const std::string& message); | 58 const std::string& message); |
46 | 59 |
47 FILE* output_file_; | 60 FILE* output_file_; |
61 int test_part_results_limit_; | |
48 | 62 |
49 DISALLOW_COPY_AND_ASSIGN(XmlUnitTestResultPrinter); | 63 DISALLOW_COPY_AND_ASSIGN(XmlUnitTestResultPrinter); |
50 }; | 64 }; |
51 | 65 |
52 } // namespace base | 66 } // namespace base |
53 | 67 |
54 #endif // BASE_TEST_GTEST_XML_UNITTEST_RESULT_PRINTER_H_ | 68 #endif // BASE_TEST_GTEST_XML_UNITTEST_RESULT_PRINTER_H_ |
OLD | NEW |