googletest/googletest/test/gtest_xml_output_unittest_.cc
Go to the documentation of this file.
1 // Copyright 2006, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 // Unit test for Google Test XML output.
31 //
32 // A user can specify XML output in a Google Test program to run via
33 // either the GTEST_OUTPUT environment variable or the --gtest_output
34 // flag. This is used for testing such functionality.
35 //
36 // This program will be invoked from a Python unit test. Don't run it
37 // directly.
38 
39 #include "gtest/gtest.h"
40 
42 using ::testing::TestEventListeners;
43 using ::testing::TestWithParam;
44 using ::testing::UnitTest;
47 
48 class SuccessfulTest : public Test {
49 };
50 
51 TEST_F(SuccessfulTest, Succeeds) {
52  SUCCEED() << "This is a success.";
53  ASSERT_EQ(1, 1);
54 }
55 
56 class FailedTest : public Test {
57 };
58 
59 TEST_F(FailedTest, Fails) {
60  ASSERT_EQ(1, 2);
61 }
62 
63 class DisabledTest : public Test {
64 };
65 
66 TEST_F(DisabledTest, DISABLED_test_not_run) {
67  FAIL() << "Unexpected failure: Disabled test should not be run";
68 }
69 
70 class SkippedTest : public Test {
71 };
72 
73 TEST_F(SkippedTest, Skipped) {
74  GTEST_SKIP();
75 }
76 
77 TEST_F(SkippedTest, SkippedWithMessage) {
78  GTEST_SKIP() << "It is good practice to tell why you skip a test.";
79 }
80 
81 TEST_F(SkippedTest, SkippedAfterFailure) {
82  EXPECT_EQ(1, 2);
83  GTEST_SKIP() << "It is good practice to tell why you skip a test.";
84 }
85 
86 TEST(MixedResultTest, Succeeds) {
87  EXPECT_EQ(1, 1);
88  ASSERT_EQ(1, 1);
89 }
90 
91 TEST(MixedResultTest, Fails) {
92  EXPECT_EQ(1, 2);
93  ASSERT_EQ(2, 3);
94 }
95 
96 TEST(MixedResultTest, DISABLED_test) {
97  FAIL() << "Unexpected failure: Disabled test should not be run";
98 }
99 
100 TEST(XmlQuotingTest, OutputsCData) {
101  FAIL() << "XML output: "
102  "<?xml encoding=\"utf-8\"><top><![CDATA[cdata text]]></top>";
103 }
104 
105 // Helps to test that invalid characters produced by test code do not make
106 // it into the XML file.
107 TEST(InvalidCharactersTest, InvalidCharactersInMessage) {
108  FAIL() << "Invalid characters in brackets [\x1\x2]";
109 }
110 
111 class PropertyRecordingTest : public Test {
112  public:
113  static void SetUpTestSuite() { RecordProperty("SetUpTestSuite", "yes"); }
114  static void TearDownTestSuite() {
115  RecordProperty("TearDownTestSuite", "aye");
116  }
117 };
118 
120  RecordProperty("key_1", "1");
121 }
122 
123 TEST_F(PropertyRecordingTest, IntValuedProperty) {
124  RecordProperty("key_int", 1);
125 }
126 
127 TEST_F(PropertyRecordingTest, ThreeProperties) {
128  RecordProperty("key_1", "1");
129  RecordProperty("key_2", "2");
130  RecordProperty("key_3", "3");
131 }
132 
133 TEST_F(PropertyRecordingTest, TwoValuesForOneKeyUsesLastValue) {
134  RecordProperty("key_1", "1");
135  RecordProperty("key_1", "2");
136 }
137 
138 TEST(NoFixtureTest, RecordProperty) {
139  RecordProperty("key", "1");
140 }
141 
144 }
145 
147  const std::string& value) {
149 }
150 
151 TEST(NoFixtureTest, ExternalUtilityThatCallsRecordIntValuedProperty) {
152  ExternalUtilityThatCallsRecordProperty("key_for_utility_int", 1);
153 }
154 
155 TEST(NoFixtureTest, ExternalUtilityThatCallsRecordStringValuedProperty) {
156  ExternalUtilityThatCallsRecordProperty("key_for_utility_string", "1");
157 }
158 
159 // Verifies that the test parameter value is output in the 'value_param'
160 // XML attribute for value-parameterized tests.
161 class ValueParamTest : public TestWithParam<int> {};
162 TEST_P(ValueParamTest, HasValueParamAttribute) {}
163 TEST_P(ValueParamTest, AnotherTestThatHasValueParamAttribute) {}
165 
166 // Verifies that the type parameter name is output in the 'type_param'
167 // XML attribute for typed tests.
168 template <typename T> class TypedTest : public Test {};
171 TYPED_TEST(TypedTest, HasTypeParamAttribute) {}
172 
173 // Verifies that the type parameter name is output in the 'type_param'
174 // XML attribute for type-parameterized tests.
175 template <typename T>
176 class TypeParameterizedTestSuite : public Test {};
178 TYPED_TEST_P(TypeParameterizedTestSuite, HasTypeParamAttribute) {}
183 
184 int main(int argc, char** argv) {
185  InitGoogleTest(&argc, argv);
186 
187  if (argc > 1 && strcmp(argv[1], "--shut_down_xml") == 0) {
188  TestEventListeners& listeners = UnitTest::GetInstance()->listeners();
189  delete listeners.Release(listeners.default_xml_generator());
190  }
191  testing::Test::RecordProperty("ad_hoc_property", "42");
192  return RUN_ALL_TESTS();
193 }
INSTANTIATE_TEST_SUITE_P
INSTANTIATE_TEST_SUITE_P(Single, ValueParamTest, Values(33, 42))
Test
void Test(StringPiece pattern, const RE2::Options &options, StringPiece text)
Definition: bloaty/third_party/re2/re2/fuzzing/re2_fuzzer.cc:20
ExternalUtilityThatCallsRecordProperty
void ExternalUtilityThatCallsRecordProperty(const std::string &key, int value)
Definition: googletest/googletest/test/gtest_xml_output_unittest_.cc:142
TYPED_TEST_SUITE_P
TYPED_TEST_SUITE_P(TypeParameterizedTestSuite)
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
TYPED_TEST_SUITE
TYPED_TEST_SUITE(TypedTest, TypedTestTypes)
GTEST_SKIP
#define GTEST_SKIP()
Definition: perf_counters_gtest.cc:10
PropertyRecordingTest
Definition: bloaty/third_party/googletest/googletest/test/gtest_xml_output_unittest_.cc:102
main
int main(int argc, char **argv)
Definition: googletest/googletest/test/gtest_xml_output_unittest_.cc:184
TypeParameterizedTestSuiteTypes
testing::Types< int, long > TypeParameterizedTestSuiteTypes
Definition: googletest/googletest/test/gtest_xml_output_unittest_.cc:180
TYPED_TEST_P
TYPED_TEST_P(TypeParameterizedTestSuite, HasTypeParamAttribute)
Definition: googletest/googletest/test/gtest_xml_output_unittest_.cc:178
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
TYPED_TEST
TYPED_TEST(TypedTest, HasTypeParamAttribute)
Definition: googletest/googletest/test/gtest_xml_output_unittest_.cc:171
testing::internal::ProxyTypeList
Definition: googletest/googletest/include/gtest/internal/gtest-type-util.h:155
ValueParamTest
Definition: bloaty/third_party/googletest/googletest/test/googletest-list-tests-unittest_.cc:93
INSTANTIATE_TYPED_TEST_SUITE_P
INSTANTIATE_TYPED_TEST_SUITE_P(Single, TypeParameterizedTestSuite, TypeParameterizedTestSuiteTypes)
TypeParameterizedTestSuite
Definition: googletest/googletest/test/gtest_list_output_unittest_.cc:64
TEST_F
TEST_F(SuccessfulTest, Succeeds)
Definition: googletest/googletest/test/gtest_xml_output_unittest_.cc:51
PropertyRecordingTest::TearDownTestSuite
static void TearDownTestSuite()
Definition: googletest/googletest/test/gtest_xml_output_unittest_.cc:114
SkippedTest
Definition: bloaty/third_party/googletest/googletest/test/gtest_xml_output_unittest_.cc:70
FAIL
@ FAIL
Definition: call_creds.cc:42
testing::Test::RecordProperty
static void RecordProperty(const std::string &key, const std::string &value)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:2274
PropertyRecordingTest::SetUpTestSuite
static void SetUpTestSuite()
Definition: googletest/googletest/test/gtest_xml_output_unittest_.cc:113
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
TypedTest
Definition: bloaty/third_party/googletest/googletest/test/googletest-list-tests-unittest_.cc:116
REGISTER_TYPED_TEST_SUITE_P
REGISTER_TYPED_TEST_SUITE_P(TypeParameterizedTestSuite, HasTypeParamAttribute)
value
const char * value
Definition: hpack_parser_table.cc:165
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
key
const char * key
Definition: hpack_parser_table.cc:164
testing::Values
internal::ValueArray< T... > Values(T... v)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest-param-test.h:335
SUCCEED
#define SUCCEED()
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1939
FailedTest
Definition: bloaty/third_party/googletest/googletest/test/gtest_xml_output_unittest_.cc:56
TypedTestTypes
testing::Types< int, long > TypedTestTypes
Definition: googletest/googletest/test/gtest_xml_output_unittest_.cc:169
DisabledTest
Definition: bloaty/third_party/googletest/googletest/test/gtest_xml_output_unittest_.cc:63
TEST
TEST(MixedResultTest, Succeeds)
Definition: googletest/googletest/test/gtest_xml_output_unittest_.cc:86
SuccessfulTest
Definition: bloaty/third_party/googletest/googletest/test/gtest_xml_output_unittest_.cc:48
TEST_P
TEST_P(ValueParamTest, HasValueParamAttribute)
Definition: googletest/googletest/test/gtest_xml_output_unittest_.cc:162
Test
Definition: hpack_parser_test.cc:43
ASSERT_EQ
#define ASSERT_EQ(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2056


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:59