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 // Unit test for Google Test test filters.
31 //
32 // A user can specify which test(s) in a Google Test program to run via
33 // either the GTEST_FILTER environment variable or the --gtest_filter
34 // flag. This is used for testing such functionality.
35 //
36 // The program will be invoked from a Python unit test. Don't run it
37 // directly.
38 
39 #include "gtest/gtest.h"
40 
41 namespace {
42 
43 // Test HasFixtureTest.
44 
45 class HasFixtureTest : public testing::Test {};
46 
47 TEST_F(HasFixtureTest, Test0) {}
48 
49 TEST_F(HasFixtureTest, Test1) { FAIL() << "Expected failure."; }
50 
51 TEST_F(HasFixtureTest, Test2) { FAIL() << "Expected failure."; }
52 
53 TEST_F(HasFixtureTest, Test3) { FAIL() << "Expected failure."; }
54 
55 TEST_F(HasFixtureTest, Test4) { FAIL() << "Expected failure."; }
56 
57 // Test HasSimpleTest.
58 
59 TEST(HasSimpleTest, Test0) {}
60 
61 TEST(HasSimpleTest, Test1) { FAIL() << "Expected failure."; }
62 
63 TEST(HasSimpleTest, Test2) { FAIL() << "Expected failure."; }
64 
65 TEST(HasSimpleTest, Test3) { FAIL() << "Expected failure."; }
66 
67 TEST(HasSimpleTest, Test4) { FAIL() << "Expected failure."; }
68 
69 // Test HasDisabledTest.
70 
71 TEST(HasDisabledTest, Test0) {}
72 
73 TEST(HasDisabledTest, DISABLED_Test1) { FAIL() << "Expected failure."; }
74 
75 TEST(HasDisabledTest, Test2) { FAIL() << "Expected failure."; }
76 
77 TEST(HasDisabledTest, Test3) { FAIL() << "Expected failure."; }
78 
79 TEST(HasDisabledTest, Test4) { FAIL() << "Expected failure."; }
80 
81 // Test HasDeathTest
82 
83 TEST(HasDeathTest, Test0) { EXPECT_DEATH_IF_SUPPORTED(exit(1), ".*"); }
84 
85 TEST(HasDeathTest, Test1) {
86  EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
87 }
88 
89 TEST(HasDeathTest, Test2) {
90  EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
91 }
92 
93 TEST(HasDeathTest, Test3) {
94  EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
95 }
96 
97 TEST(HasDeathTest, Test4) {
98  EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
99 }
100 
101 // Test DISABLED_HasDisabledSuite
102 
103 TEST(DISABLED_HasDisabledSuite, Test0) {}
104 
105 TEST(DISABLED_HasDisabledSuite, Test1) { FAIL() << "Expected failure."; }
106 
107 TEST(DISABLED_HasDisabledSuite, Test2) { FAIL() << "Expected failure."; }
108 
109 TEST(DISABLED_HasDisabledSuite, Test3) { FAIL() << "Expected failure."; }
110 
111 TEST(DISABLED_HasDisabledSuite, Test4) { FAIL() << "Expected failure."; }
112 
113 // Test HasParametersTest
114 
115 class HasParametersTest : public testing::TestWithParam<int> {};
116 
117 TEST_P(HasParametersTest, Test1) { FAIL() << "Expected failure."; }
118 
119 TEST_P(HasParametersTest, Test2) { FAIL() << "Expected failure."; }
120 
121 INSTANTIATE_TEST_SUITE_P(HasParametersSuite, HasParametersTest,
122  testing::Values(1, 2));
123 
124 class MyTestListener : public ::testing::EmptyTestEventListener {
125  void OnTestSuiteStart(const ::testing::TestSuite& test_suite) override {
126  printf("We are in OnTestSuiteStart of %s.\n", test_suite.name());
127  }
128 
129  void OnTestStart(const ::testing::TestInfo& test_info) override {
130  printf("We are in OnTestStart of %s.%s.\n", test_info.test_suite_name(),
131  test_info.name());
132  }
133 
134  void OnTestPartResult(
135  const ::testing::TestPartResult& test_part_result) override {
136  printf("We are in OnTestPartResult %s:%d.\n", test_part_result.file_name(),
137  test_part_result.line_number());
138  }
139 
140  void OnTestEnd(const ::testing::TestInfo& test_info) override {
141  printf("We are in OnTestEnd of %s.%s.\n", test_info.test_suite_name(),
142  test_info.name());
143  }
144 
145  void OnTestSuiteEnd(const ::testing::TestSuite& test_suite) override {
146  printf("We are in OnTestSuiteEnd of %s.\n", test_suite.name());
147  }
148 };
149 
150 TEST(HasSkipTest, Test0) { SUCCEED() << "Expected success."; }
151 
152 TEST(HasSkipTest, Test1) { GTEST_SKIP() << "Expected skip."; }
153 
154 TEST(HasSkipTest, Test2) { FAIL() << "Expected failure."; }
155 
156 TEST(HasSkipTest, Test3) { FAIL() << "Expected failure."; }
157 
158 TEST(HasSkipTest, Test4) { FAIL() << "Expected failure."; }
159 
160 } // namespace
161 
162 int main(int argc, char** argv) {
163  ::testing::InitGoogleTest(&argc, argv);
164  ::testing::UnitTest::GetInstance()->listeners().Append(new MyTestListener());
165  return RUN_ALL_TESTS();
166 }
internal::ValueArray< T...> Values(T...v)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
#define TEST_F(test_fixture, test_name)
Definition: gtest.h:2224
#define TEST(test_suite_name, test_name)
Definition: gtest.h:2192
void OnTestEnd(const TestInfo &) override
Definition: gtest.h:1008
void Append(TestEventListener *listener)
Definition: gtest.cc:5171
void OnTestStart(const TestInfo &) override
Definition: gtest.h:1005
void OnTestSuiteStart(const TestSuite &) override
Definition: gtest.h:999
TestEventListeners & listeners()
Definition: gtest.cc:5386
int main()
Definition: ad_example.cpp:171
void OnTestPartResult(const TestPartResult &) override
Definition: gtest.h:1007
#define TEST_P(test_suite_name, test_name)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: gtest.h:2334
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: gtest.cc:6885
static UnitTest * GetInstance()
Definition: gtest.cc:5239
#define GTEST_SKIP()
Definition: gtest.h:1730
void OnTestSuiteEnd(const TestSuite &) override
Definition: gtest.h:1009
#define FAIL()
Definition: gtest.h:1769
#define SUCCEED()
Definition: gtest.h:1779
#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name,...)