Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
googletest-failfast-unittest_.cc
Go to the documentation of this file.
1 // Copyright 2005, 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 
31 // Unit test for Google Test test filters.
32 //
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.
36 //
37 // The program will be invoked from a Python unit test. Don't run it
38 // directly.
39 
40 #include "gtest/gtest.h"
41 
42 namespace {
43 
44 // Test HasFixtureTest.
45 
46 class HasFixtureTest : public testing::Test {};
47 
48 TEST_F(HasFixtureTest, Test0) {}
49 
50 TEST_F(HasFixtureTest, Test1) { FAIL() << "Expected failure."; }
51 
52 TEST_F(HasFixtureTest, Test2) { FAIL() << "Expected failure."; }
53 
54 TEST_F(HasFixtureTest, Test3) { FAIL() << "Expected failure."; }
55 
56 TEST_F(HasFixtureTest, Test4) { FAIL() << "Expected failure."; }
57 
58 // Test HasSimpleTest.
59 
60 TEST(HasSimpleTest, Test0) {}
61 
62 TEST(HasSimpleTest, Test1) { FAIL() << "Expected failure."; }
63 
64 TEST(HasSimpleTest, Test2) { FAIL() << "Expected failure."; }
65 
66 TEST(HasSimpleTest, Test3) { FAIL() << "Expected failure."; }
67 
68 TEST(HasSimpleTest, Test4) { FAIL() << "Expected failure."; }
69 
70 // Test HasDisabledTest.
71 
72 TEST(HasDisabledTest, Test0) {}
73 
74 TEST(HasDisabledTest, DISABLED_Test1) { FAIL() << "Expected failure."; }
75 
76 TEST(HasDisabledTest, Test2) { FAIL() << "Expected failure."; }
77 
78 TEST(HasDisabledTest, Test3) { FAIL() << "Expected failure."; }
79 
80 TEST(HasDisabledTest, Test4) { FAIL() << "Expected failure."; }
81 
82 // Test HasDeathTest
83 
84 TEST(HasDeathTest, Test0) { EXPECT_DEATH_IF_SUPPORTED(exit(1), ".*"); }
85 
86 TEST(HasDeathTest, Test1) {
87  EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
88 }
89 
90 TEST(HasDeathTest, Test2) {
91  EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
92 }
93 
94 TEST(HasDeathTest, Test3) {
95  EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
96 }
97 
98 TEST(HasDeathTest, Test4) {
99  EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
100 }
101 
102 // Test DISABLED_HasDisabledSuite
103 
104 TEST(DISABLED_HasDisabledSuite, Test0) {}
105 
106 TEST(DISABLED_HasDisabledSuite, Test1) { FAIL() << "Expected failure."; }
107 
108 TEST(DISABLED_HasDisabledSuite, Test2) { FAIL() << "Expected failure."; }
109 
110 TEST(DISABLED_HasDisabledSuite, Test3) { FAIL() << "Expected failure."; }
111 
112 TEST(DISABLED_HasDisabledSuite, Test4) { FAIL() << "Expected failure."; }
113 
114 // Test HasParametersTest
115 
116 class HasParametersTest : public testing::TestWithParam<int> {};
117 
118 TEST_P(HasParametersTest, Test1) { FAIL() << "Expected failure."; }
119 
120 TEST_P(HasParametersTest, Test2) { FAIL() << "Expected failure."; }
121 
122 INSTANTIATE_TEST_SUITE_P(HasParametersSuite, HasParametersTest,
123  testing::Values(1, 2));
124 
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());
128  }
129 
130  void OnTestStart(const ::testing::TestInfo& test_info) override {
131  printf("We are in OnTestStart of %s.%s.\n", test_info.test_suite_name(),
132  test_info.name());
133  }
134 
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());
139  }
140 
141  void OnTestEnd(const ::testing::TestInfo& test_info) override {
142  printf("We are in OnTestEnd of %s.%s.\n", test_info.test_suite_name(),
143  test_info.name());
144  }
145 
146  void OnTestSuiteEnd(const ::testing::TestSuite& test_suite) override {
147  printf("We are in OnTestSuiteEnd of %s.\n", test_suite.name());
148  }
149 };
150 
151 TEST(HasSkipTest, Test0) { SUCCEED() << "Expected success."; }
152 
153 TEST(HasSkipTest, Test1) { GTEST_SKIP() << "Expected skip."; }
154 
155 TEST(HasSkipTest, Test2) { FAIL() << "Expected failure."; }
156 
157 TEST(HasSkipTest, Test3) { FAIL() << "Expected failure."; }
158 
159 TEST(HasSkipTest, Test4) { FAIL() << "Expected failure."; }
160 
161 } // namespace
162 
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();
167 }
internal::ValueArray< T...> Values(T...v)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
#define TEST_F(test_fixture, test_name)
Definition: gtest.h:2379
#define TEST(test_suite_name, test_name)
Definition: gtest.h:2348
void OnTestEnd(const TestInfo &) override
Definition: gtest.h:1172
void Append(TestEventListener *listener)
Definition: gtest.cc:4930
void OnTestStart(const TestInfo &) override
Definition: gtest.h:1170
void OnTestSuiteStart(const TestSuite &) override
Definition: gtest.h:1164
TestEventListeners & listeners()
Definition: gtest.cc:5129
int main()
Definition: ad_example.cpp:191
void OnTestPartResult(const TestPartResult &) override
Definition: gtest.h:1171
#define TEST_P(test_suite_name, test_name)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: gtest.h:2484
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: gtest.cc:6527
static UnitTest * GetInstance()
Definition: gtest.cc:4998
#define GTEST_SKIP()
Definition: gtest.h:1903
void OnTestSuiteEnd(const TestSuite &) override
Definition: gtest.h:1173
#define FAIL()
Definition: gtest.h:1942
#define SUCCEED()
Definition: gtest.h:1951
#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name,...)