1 // Copyright 2005, Google Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
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
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.
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.
31 // Unit test for Google Test test filters.
33 // A user can specify which test(s) in a Google Test program to run via
34 // either the GTEST_FILTER environment variable or the --gtest_filter
35 // flag. This is used for testing such functionality.
37 // The program will be invoked from a Python unit test. Don't run it
40 #include "gtest/gtest.h"
44 // Test HasFixtureTest.
46 class HasFixtureTest
: public testing::Test
{};
48 TEST_F(HasFixtureTest
, Test0
) {}
50 TEST_F(HasFixtureTest
, Test1
) { FAIL() << "Expected failure."; }
52 TEST_F(HasFixtureTest
, Test2
) { FAIL() << "Expected failure."; }
54 TEST_F(HasFixtureTest
, Test3
) { FAIL() << "Expected failure."; }
56 TEST_F(HasFixtureTest
, Test4
) { FAIL() << "Expected failure."; }
58 // Test HasSimpleTest.
60 TEST(HasSimpleTest
, Test0
) {}
62 TEST(HasSimpleTest
, Test1
) { FAIL() << "Expected failure."; }
64 TEST(HasSimpleTest
, Test2
) { FAIL() << "Expected failure."; }
66 TEST(HasSimpleTest
, Test3
) { FAIL() << "Expected failure."; }
68 TEST(HasSimpleTest
, Test4
) { FAIL() << "Expected failure."; }
70 // Test HasDisabledTest.
72 TEST(HasDisabledTest
, Test0
) {}
74 TEST(HasDisabledTest
, DISABLED_Test1
) { FAIL() << "Expected failure."; }
76 TEST(HasDisabledTest
, Test2
) { FAIL() << "Expected failure."; }
78 TEST(HasDisabledTest
, Test3
) { FAIL() << "Expected failure."; }
80 TEST(HasDisabledTest
, Test4
) { FAIL() << "Expected failure."; }
84 TEST(HasDeathTest
, Test0
) { EXPECT_DEATH_IF_SUPPORTED(exit(1), ".*"); }
86 TEST(HasDeathTest
, Test1
) {
87 EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
90 TEST(HasDeathTest
, Test2
) {
91 EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
94 TEST(HasDeathTest
, Test3
) {
95 EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
98 TEST(HasDeathTest
, Test4
) {
99 EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
102 // Test DISABLED_HasDisabledSuite
104 TEST(DISABLED_HasDisabledSuite
, Test0
) {}
106 TEST(DISABLED_HasDisabledSuite
, Test1
) { FAIL() << "Expected failure."; }
108 TEST(DISABLED_HasDisabledSuite
, Test2
) { FAIL() << "Expected failure."; }
110 TEST(DISABLED_HasDisabledSuite
, Test3
) { FAIL() << "Expected failure."; }
112 TEST(DISABLED_HasDisabledSuite
, Test4
) { FAIL() << "Expected failure."; }
114 // Test HasParametersTest
116 class HasParametersTest
: public testing::TestWithParam
<int> {};
118 TEST_P(HasParametersTest
, Test1
) { FAIL() << "Expected failure."; }
120 TEST_P(HasParametersTest
, Test2
) { FAIL() << "Expected failure."; }
122 INSTANTIATE_TEST_SUITE_P(HasParametersSuite
, HasParametersTest
,
123 testing::Values(1, 2));
125 class MyTestListener
: public ::testing::EmptyTestEventListener
{
126 void OnTestSuiteStart(const ::testing::TestSuite
& test_suite
) override
{
127 printf("We are in OnTestSuiteStart of %s.\n", test_suite
.name());
130 void OnTestStart(const ::testing::TestInfo
& test_info
) override
{
131 printf("We are in OnTestStart of %s.%s.\n", test_info
.test_suite_name(),
135 void OnTestPartResult(
136 const ::testing::TestPartResult
& test_part_result
) override
{
137 printf("We are in OnTestPartResult %s:%d.\n", test_part_result
.file_name(),
138 test_part_result
.line_number());
141 void OnTestEnd(const ::testing::TestInfo
& test_info
) override
{
142 printf("We are in OnTestEnd of %s.%s.\n", test_info
.test_suite_name(),
146 void OnTestSuiteEnd(const ::testing::TestSuite
& test_suite
) override
{
147 printf("We are in OnTestSuiteEnd of %s.\n", test_suite
.name());
151 TEST(HasSkipTest
, Test0
) { SUCCEED() << "Expected success."; }
153 TEST(HasSkipTest
, Test1
) { GTEST_SKIP() << "Expected skip."; }
155 TEST(HasSkipTest
, Test2
) { FAIL() << "Expected failure."; }
157 TEST(HasSkipTest
, Test3
) { FAIL() << "Expected failure."; }
159 TEST(HasSkipTest
, Test4
) { FAIL() << "Expected failure."; }
163 int main(int argc
, char **argv
) {
164 ::testing::InitGoogleTest(&argc
, argv
);
165 ::testing::UnitTest::GetInstance()->listeners().Append(new MyTestListener());
166 return RUN_ALL_TESTS();