gtest_xml_output_unittest_.cc
Go to the documentation of this file.
00001 // Copyright 2006, Google Inc.
00002 // All rights reserved.
00003 //
00004 // Redistribution and use in source and binary forms, with or without
00005 // modification, are permitted provided that the following conditions are
00006 // met:
00007 //
00008 //     * Redistributions of source code must retain the above copyright
00009 // notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above
00011 // copyright notice, this list of conditions and the following disclaimer
00012 // in the documentation and/or other materials provided with the
00013 // distribution.
00014 //     * Neither the name of Google Inc. nor the names of its
00015 // contributors may be used to endorse or promote products derived from
00016 // this software without specific prior written permission.
00017 //
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 
00030 // Author: eefacm@gmail.com (Sean Mcafee)
00031 
00032 // Unit test for Google Test XML output.
00033 //
00034 // A user can specify XML output in a Google Test program to run via
00035 // either the GTEST_OUTPUT environment variable or the --gtest_output
00036 // flag.  This is used for testing such functionality.
00037 //
00038 // This program will be invoked from a Python unit test.  Don't run it
00039 // directly.
00040 
00041 #include "gtest/gtest.h"
00042 
00043 using ::testing::InitGoogleTest;
00044 using ::testing::TestEventListeners;
00045 using ::testing::TestWithParam;
00046 using ::testing::UnitTest;
00047 using ::testing::Test;
00048 using ::testing::Values;
00049 
00050 class SuccessfulTest : public Test {
00051 };
00052 
00053 TEST_F(SuccessfulTest, Succeeds) {
00054   SUCCEED() << "This is a success.";
00055   ASSERT_EQ(1, 1);
00056 }
00057 
00058 class FailedTest : public Test {
00059 };
00060 
00061 TEST_F(FailedTest, Fails) {
00062   ASSERT_EQ(1, 2);
00063 }
00064 
00065 class DisabledTest : public Test {
00066 };
00067 
00068 TEST_F(DisabledTest, DISABLED_test_not_run) {
00069   FAIL() << "Unexpected failure: Disabled test should not be run";
00070 }
00071 
00072 TEST(MixedResultTest, Succeeds) {
00073   EXPECT_EQ(1, 1);
00074   ASSERT_EQ(1, 1);
00075 }
00076 
00077 TEST(MixedResultTest, Fails) {
00078   EXPECT_EQ(1, 2);
00079   ASSERT_EQ(2, 3);
00080 }
00081 
00082 TEST(MixedResultTest, DISABLED_test) {
00083   FAIL() << "Unexpected failure: Disabled test should not be run";
00084 }
00085 
00086 TEST(XmlQuotingTest, OutputsCData) {
00087   FAIL() << "XML output: "
00088             "<?xml encoding=\"utf-8\"><top><![CDATA[cdata text]]></top>";
00089 }
00090 
00091 // Helps to test that invalid characters produced by test code do not make
00092 // it into the XML file.
00093 TEST(InvalidCharactersTest, InvalidCharactersInMessage) {
00094   FAIL() << "Invalid characters in brackets [\x1\x2]";
00095 }
00096 
00097 class PropertyRecordingTest : public Test {
00098  public:
00099   static void SetUpTestCase() { RecordProperty("SetUpTestCase", "yes"); }
00100   static void TearDownTestCase() { RecordProperty("TearDownTestCase", "aye"); }
00101 };
00102 
00103 TEST_F(PropertyRecordingTest, OneProperty) {
00104   RecordProperty("key_1", "1");
00105 }
00106 
00107 TEST_F(PropertyRecordingTest, IntValuedProperty) {
00108   RecordProperty("key_int", 1);
00109 }
00110 
00111 TEST_F(PropertyRecordingTest, ThreeProperties) {
00112   RecordProperty("key_1", "1");
00113   RecordProperty("key_2", "2");
00114   RecordProperty("key_3", "3");
00115 }
00116 
00117 TEST_F(PropertyRecordingTest, TwoValuesForOneKeyUsesLastValue) {
00118   RecordProperty("key_1", "1");
00119   RecordProperty("key_1", "2");
00120 }
00121 
00122 TEST(NoFixtureTest, RecordProperty) {
00123   RecordProperty("key", "1");
00124 }
00125 
00126 void ExternalUtilityThatCallsRecordProperty(const std::string& key, int value) {
00127   testing::Test::RecordProperty(key, value);
00128 }
00129 
00130 void ExternalUtilityThatCallsRecordProperty(const std::string& key,
00131                                             const std::string& value) {
00132   testing::Test::RecordProperty(key, value);
00133 }
00134 
00135 TEST(NoFixtureTest, ExternalUtilityThatCallsRecordIntValuedProperty) {
00136   ExternalUtilityThatCallsRecordProperty("key_for_utility_int", 1);
00137 }
00138 
00139 TEST(NoFixtureTest, ExternalUtilityThatCallsRecordStringValuedProperty) {
00140   ExternalUtilityThatCallsRecordProperty("key_for_utility_string", "1");
00141 }
00142 
00143 // Verifies that the test parameter value is output in the 'value_param'
00144 // XML attribute for value-parameterized tests.
00145 class ValueParamTest : public TestWithParam<int> {};
00146 TEST_P(ValueParamTest, HasValueParamAttribute) {}
00147 TEST_P(ValueParamTest, AnotherTestThatHasValueParamAttribute) {}
00148 INSTANTIATE_TEST_CASE_P(Single, ValueParamTest, Values(33, 42));
00149 
00150 #if GTEST_HAS_TYPED_TEST
00151 // Verifies that the type parameter name is output in the 'type_param'
00152 // XML attribute for typed tests.
00153 template <typename T> class TypedTest : public Test {};
00154 typedef testing::Types<int, long> TypedTestTypes;
00155 TYPED_TEST_CASE(TypedTest, TypedTestTypes);
00156 TYPED_TEST(TypedTest, HasTypeParamAttribute) {}
00157 #endif
00158 
00159 #if GTEST_HAS_TYPED_TEST_P
00160 // Verifies that the type parameter name is output in the 'type_param'
00161 // XML attribute for type-parameterized tests.
00162 template <typename T> class TypeParameterizedTestCase : public Test {};
00163 TYPED_TEST_CASE_P(TypeParameterizedTestCase);
00164 TYPED_TEST_P(TypeParameterizedTestCase, HasTypeParamAttribute) {}
00165 REGISTER_TYPED_TEST_CASE_P(TypeParameterizedTestCase, HasTypeParamAttribute);
00166 typedef testing::Types<int, long> TypeParameterizedTestCaseTypes;
00167 INSTANTIATE_TYPED_TEST_CASE_P(Single,
00168                               TypeParameterizedTestCase,
00169                               TypeParameterizedTestCaseTypes);
00170 #endif
00171 
00172 int main(int argc, char** argv) {
00173   InitGoogleTest(&argc, argv);
00174 
00175   if (argc > 1 && strcmp(argv[1], "--shut_down_xml") == 0) {
00176     TestEventListeners& listeners = UnitTest::GetInstance()->listeners();
00177     delete listeners.Release(listeners.default_xml_generator());
00178   }
00179   testing::Test::RecordProperty("ad_hoc_property", "42");
00180   return RUN_ALL_TESTS();
00181 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:04