Sacado Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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
41using ::testing::InitGoogleTest;
42using ::testing::TestEventListeners;
43using ::testing::TestWithParam;
44using ::testing::UnitTest;
45using ::testing::Test;
46using ::testing::Values;
47
48class SuccessfulTest : public Test {
49};
50
52 SUCCEED() << "This is a success.";
53 ASSERT_EQ(1, 1);
54}
55
56class FailedTest : public Test {
57};
58
60 ASSERT_EQ(1, 2);
61}
62
63class DisabledTest : public Test {
64};
65
66TEST_F(DisabledTest, DISABLED_test_not_run) {
67 FAIL() << "Unexpected failure: Disabled test should not be run";
68}
69
70class SkippedTest : public Test {
71};
72
74 GTEST_SKIP();
75}
76
77TEST_F(SkippedTest, SkippedWithMessage) {
78 GTEST_SKIP() << "It is good practice to tell why you skip a test.";
79}
80
81TEST_F(SkippedTest, SkippedAfterFailure) {
82 EXPECT_EQ(1, 2);
83 GTEST_SKIP() << "It is good practice to tell why you skip a test.";
84}
85
86TEST(MixedResultTest, Succeeds) {
87 EXPECT_EQ(1, 1);
88 ASSERT_EQ(1, 1);
89}
90
91TEST(MixedResultTest, Fails) {
92 EXPECT_EQ(1, 2);
93 ASSERT_EQ(2, 3);
94}
95
96TEST(MixedResultTest, DISABLED_test) {
97 FAIL() << "Unexpected failure: Disabled test should not be run";
98}
99
100TEST(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.
107TEST(InvalidCharactersTest, InvalidCharactersInMessage) {
108 FAIL() << "Invalid characters in brackets [\x1\x2]";
109}
110
111class 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
123TEST_F(PropertyRecordingTest, IntValuedProperty) {
124 RecordProperty("key_int", 1);
125}
126
127TEST_F(PropertyRecordingTest, ThreeProperties) {
128 RecordProperty("key_1", "1");
129 RecordProperty("key_2", "2");
130 RecordProperty("key_3", "3");
131}
132
133TEST_F(PropertyRecordingTest, TwoValuesForOneKeyUsesLastValue) {
134 RecordProperty("key_1", "1");
135 RecordProperty("key_1", "2");
136}
137
138TEST(NoFixtureTest, RecordProperty) {
139 RecordProperty("key", "1");
140}
141
142void ExternalUtilityThatCallsRecordProperty(const std::string& key, int value) {
144}
145
146void ExternalUtilityThatCallsRecordProperty(const std::string& key,
147 const std::string& value) {
149}
150
151TEST(NoFixtureTest, ExternalUtilityThatCallsRecordIntValuedProperty) {
152 ExternalUtilityThatCallsRecordProperty("key_for_utility_int", 1);
153}
154
155TEST(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.
161class ValueParamTest : public TestWithParam<int> {};
162TEST_P(ValueParamTest, HasValueParamAttribute) {}
163TEST_P(ValueParamTest, AnotherTestThatHasValueParamAttribute) {}
165
166#if GTEST_HAS_TYPED_TEST
167// Verifies that the type parameter name is output in the 'type_param'
168// XML attribute for typed tests.
169template <typename T> class TypedTest : public Test {};
170typedef testing::Types<int, long> TypedTestTypes;
171TYPED_TEST_SUITE(TypedTest, TypedTestTypes);
172TYPED_TEST(TypedTest, HasTypeParamAttribute) {}
173#endif
174
175#if GTEST_HAS_TYPED_TEST_P
176// Verifies that the type parameter name is output in the 'type_param'
177// XML attribute for type-parameterized tests.
178template <typename T>
179class TypeParameterizedTestSuite : public Test {};
180TYPED_TEST_SUITE_P(TypeParameterizedTestSuite);
181TYPED_TEST_P(TypeParameterizedTestSuite, HasTypeParamAttribute) {}
182REGISTER_TYPED_TEST_SUITE_P(TypeParameterizedTestSuite, HasTypeParamAttribute);
183typedef testing::Types<int, long> TypeParameterizedTestSuiteTypes; // NOLINT
184INSTANTIATE_TYPED_TEST_SUITE_P(Single, TypeParameterizedTestSuite,
185 TypeParameterizedTestSuiteTypes);
186#endif
187
188int main(int argc, char** argv) {
189 InitGoogleTest(&argc, argv);
190
191 if (argc > 1 && strcmp(argv[1], "--shut_down_xml") == 0) {
192 TestEventListeners& listeners = UnitTest::GetInstance()->listeners();
193 delete listeners.Release(listeners.default_xml_generator());
194 }
195 testing::Test::RecordProperty("ad_hoc_property", "42");
196 return RUN_ALL_TESTS();
197}
INSTANTIATE_TYPED_TEST_SUITE_P(CacheFad, FadOpsUnitTest, FadTypes)
TYPED_TEST_P(FadBLASUnitTests, testSCAL1)
TYPED_TEST_SUITE_P(FadBLASUnitTests)
REGISTER_TYPED_TEST_SUITE_P(FadBLASUnitTests, testSCAL1, testSCAL2, testSCAL3, testSCAL4, testCOPY1, testCOPY2, testCOPY3, testCOPY4, testAXPY1, testAXPY2, testAXPY3, testAXPY4, testDOT1, testDOT2, testDOT3, testDOT4, testNRM21, testNRM22, testGEMV1, testGEMV2, testGEMV3, testGEMV4, testGEMV5, testGEMV6, testGEMV7, testGEMV8, testGEMV9, testTRMV1, testTRMV2, testTRMV3, testTRMV4, testGER1, testGER2, testGER3, testGER4, testGER5, testGER6, testGER7, testGEMM1, testGEMM2, testGEMM3, testGEMM4, testGEMM5, testGEMM6, testGEMM7, testGEMM8, testGEMM9, testGEMM10, testSYMM1, testSYMM2, testSYMM3, testSYMM4, testSYMM5, testSYMM6, testSYMM7, testSYMM8, testSYMM9, testTRMM1, testTRMM2, testTRMM3, testTRMM4, testTRMM5, testTRMM6, testTRMM7, testTRSM1, testTRSM2, testTRSM3, testTRSM4, testTRSM5, testTRSM6, testTRSM7)
int main()
Definition: ad_example.cpp:191
static void RecordProperty(const std::string &key, const std::string &value)
Definition: gtest.cc:2449
int value
TYPED_TEST_SUITE(TypedTest, MyTypes)
TYPED_TEST(TypedTest, TestA)
#define TEST_P(test_suite_name, test_name)
#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name,...)
#define TEST_F(test_fixture, test_name)
Definition: gtest.h:2379
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:2068
#define GTEST_SKIP()
Definition: gtest.h:1903
#define FAIL()
Definition: gtest.h:1942
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:2038
#define SUCCEED()
Definition: gtest.h:1951
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: gtest.h:2484
#define TEST(test_suite_name, test_name)
Definition: gtest.h:2348
void ExternalUtilityThatCallsRecordProperty(const std::string &key, int value)
internal::ProxyTypeList< Ts... > Types