1b89a7cc2SEnji Cooper // Copyright 2006, Google Inc.
2b89a7cc2SEnji Cooper // All rights reserved.
3b89a7cc2SEnji Cooper //
4b89a7cc2SEnji Cooper // Redistribution and use in source and binary forms, with or without
5b89a7cc2SEnji Cooper // modification, are permitted provided that the following conditions are
6b89a7cc2SEnji Cooper // met:
7b89a7cc2SEnji Cooper //
8b89a7cc2SEnji Cooper // * Redistributions of source code must retain the above copyright
9b89a7cc2SEnji Cooper // notice, this list of conditions and the following disclaimer.
10b89a7cc2SEnji Cooper // * Redistributions in binary form must reproduce the above
11b89a7cc2SEnji Cooper // copyright notice, this list of conditions and the following disclaimer
12b89a7cc2SEnji Cooper // in the documentation and/or other materials provided with the
13b89a7cc2SEnji Cooper // distribution.
14b89a7cc2SEnji Cooper // * Neither the name of Google Inc. nor the names of its
15b89a7cc2SEnji Cooper // contributors may be used to endorse or promote products derived from
16b89a7cc2SEnji Cooper // this software without specific prior written permission.
17b89a7cc2SEnji Cooper //
18b89a7cc2SEnji Cooper // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19b89a7cc2SEnji Cooper // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20b89a7cc2SEnji Cooper // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21b89a7cc2SEnji Cooper // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22b89a7cc2SEnji Cooper // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23b89a7cc2SEnji Cooper // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24b89a7cc2SEnji Cooper // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25b89a7cc2SEnji Cooper // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26b89a7cc2SEnji Cooper // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27b89a7cc2SEnji Cooper // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28b89a7cc2SEnji Cooper // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29b89a7cc2SEnji Cooper
30b89a7cc2SEnji Cooper // Unit test for Google Test's --gtest_list_tests flag.
31b89a7cc2SEnji Cooper //
32b89a7cc2SEnji Cooper // A user can ask Google Test to list all tests that will run
33b89a7cc2SEnji Cooper // so that when using a filter, a user will know what
34b89a7cc2SEnji Cooper // tests to look for. The tests will not be run after listing.
35b89a7cc2SEnji Cooper //
36b89a7cc2SEnji Cooper // This program will be invoked from a Python unit test.
37b89a7cc2SEnji Cooper // Don't run it directly.
38b89a7cc2SEnji Cooper
39*28f6c2f2SEnji Cooper #include <ostream>
40*28f6c2f2SEnji Cooper #include <string>
41*28f6c2f2SEnji Cooper
42b89a7cc2SEnji Cooper #include "gtest/gtest.h"
43b89a7cc2SEnji Cooper
44b89a7cc2SEnji Cooper // Several different test cases and tests that will be listed.
TEST(Foo,Bar1)45*28f6c2f2SEnji Cooper TEST(Foo, Bar1) {}
46b89a7cc2SEnji Cooper
TEST(Foo,Bar2)47*28f6c2f2SEnji Cooper TEST(Foo, Bar2) {}
48b89a7cc2SEnji Cooper
TEST(Foo,DISABLED_Bar3)49*28f6c2f2SEnji Cooper TEST(Foo, DISABLED_Bar3) {}
50b89a7cc2SEnji Cooper
TEST(Abc,Xyz)51*28f6c2f2SEnji Cooper TEST(Abc, Xyz) {}
52b89a7cc2SEnji Cooper
TEST(Abc,Def)53*28f6c2f2SEnji Cooper TEST(Abc, Def) {}
54b89a7cc2SEnji Cooper
TEST(FooBar,Baz)55*28f6c2f2SEnji Cooper TEST(FooBar, Baz) {}
56b89a7cc2SEnji Cooper
57*28f6c2f2SEnji Cooper class FooTest : public testing::Test {};
58b89a7cc2SEnji Cooper
TEST_F(FooTest,Test1)59*28f6c2f2SEnji Cooper TEST_F(FooTest, Test1) {}
60b89a7cc2SEnji Cooper
TEST_F(FooTest,DISABLED_Test2)61*28f6c2f2SEnji Cooper TEST_F(FooTest, DISABLED_Test2) {}
62b89a7cc2SEnji Cooper
TEST_F(FooTest,Test3)63*28f6c2f2SEnji Cooper TEST_F(FooTest, Test3) {}
64b89a7cc2SEnji Cooper
TEST(FooDeathTest,Test1)65*28f6c2f2SEnji Cooper TEST(FooDeathTest, Test1) {}
66b89a7cc2SEnji Cooper
67b89a7cc2SEnji Cooper // A group of value-parameterized tests.
68b89a7cc2SEnji Cooper
69b89a7cc2SEnji Cooper class MyType {
70b89a7cc2SEnji Cooper public:
MyType(const std::string & a_value)71b89a7cc2SEnji Cooper explicit MyType(const std::string& a_value) : value_(a_value) {}
72b89a7cc2SEnji Cooper
value() const73b89a7cc2SEnji Cooper const std::string& value() const { return value_; }
74b89a7cc2SEnji Cooper
75b89a7cc2SEnji Cooper private:
76b89a7cc2SEnji Cooper std::string value_;
77b89a7cc2SEnji Cooper };
78b89a7cc2SEnji Cooper
79b89a7cc2SEnji Cooper // Teaches Google Test how to print a MyType.
PrintTo(const MyType & x,std::ostream * os)80*28f6c2f2SEnji Cooper void PrintTo(const MyType& x, std::ostream* os) { *os << x.value(); }
81b89a7cc2SEnji Cooper
82*28f6c2f2SEnji Cooper class ValueParamTest : public testing::TestWithParam<MyType> {};
83b89a7cc2SEnji Cooper
TEST_P(ValueParamTest,TestA)84*28f6c2f2SEnji Cooper TEST_P(ValueParamTest, TestA) {}
85b89a7cc2SEnji Cooper
TEST_P(ValueParamTest,TestB)86*28f6c2f2SEnji Cooper TEST_P(ValueParamTest, TestB) {}
87b89a7cc2SEnji Cooper
88*28f6c2f2SEnji Cooper INSTANTIATE_TEST_SUITE_P(
89b89a7cc2SEnji Cooper MyInstantiation, ValueParamTest,
90*28f6c2f2SEnji Cooper testing::Values(
91*28f6c2f2SEnji Cooper MyType("one line"), MyType("two\nlines"),
92*28f6c2f2SEnji Cooper MyType("a "
93*28f6c2f2SEnji Cooper "very\nloooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
94*28f6c2f2SEnji Cooper "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
95*28f6c2f2SEnji Cooper "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
96*28f6c2f2SEnji Cooper "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
97*28f6c2f2SEnji Cooper "ooooong line"))); // NOLINT
98b89a7cc2SEnji Cooper
99b89a7cc2SEnji Cooper // A group of typed tests.
100b89a7cc2SEnji Cooper
101b89a7cc2SEnji Cooper // A deliberately long type name for testing the line-truncating
102b89a7cc2SEnji Cooper // behavior when printing a type parameter.
103*28f6c2f2SEnji Cooper class
104*28f6c2f2SEnji Cooper VeryLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogName { // NOLINT
105b89a7cc2SEnji Cooper };
106b89a7cc2SEnji Cooper
107b89a7cc2SEnji Cooper template <typename T>
108*28f6c2f2SEnji Cooper class TypedTest : public testing::Test {};
109b89a7cc2SEnji Cooper
110b89a7cc2SEnji Cooper template <typename T, int kSize>
111*28f6c2f2SEnji Cooper class MyArray {};
112b89a7cc2SEnji Cooper
113*28f6c2f2SEnji Cooper typedef testing::Types<
114*28f6c2f2SEnji Cooper VeryLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogName, // NOLINT
115*28f6c2f2SEnji Cooper int*, MyArray<bool, 42> >
116*28f6c2f2SEnji Cooper MyTypes;
117b89a7cc2SEnji Cooper
118*28f6c2f2SEnji Cooper TYPED_TEST_SUITE(TypedTest, MyTypes);
119b89a7cc2SEnji Cooper
TYPED_TEST(TypedTest,TestA)120*28f6c2f2SEnji Cooper TYPED_TEST(TypedTest, TestA) {}
121b89a7cc2SEnji Cooper
TYPED_TEST(TypedTest,TestB)122*28f6c2f2SEnji Cooper TYPED_TEST(TypedTest, TestB) {}
123b89a7cc2SEnji Cooper
124b89a7cc2SEnji Cooper // A group of type-parameterized tests.
125b89a7cc2SEnji Cooper
126b89a7cc2SEnji Cooper template <typename T>
127*28f6c2f2SEnji Cooper class TypeParamTest : public testing::Test {};
128b89a7cc2SEnji Cooper
129*28f6c2f2SEnji Cooper TYPED_TEST_SUITE_P(TypeParamTest);
130b89a7cc2SEnji Cooper
TYPED_TEST_P(TypeParamTest,TestA)131*28f6c2f2SEnji Cooper TYPED_TEST_P(TypeParamTest, TestA) {}
132b89a7cc2SEnji Cooper
TYPED_TEST_P(TypeParamTest,TestB)133*28f6c2f2SEnji Cooper TYPED_TEST_P(TypeParamTest, TestB) {}
134b89a7cc2SEnji Cooper
135*28f6c2f2SEnji Cooper REGISTER_TYPED_TEST_SUITE_P(TypeParamTest, TestA, TestB);
136b89a7cc2SEnji Cooper
137*28f6c2f2SEnji Cooper INSTANTIATE_TYPED_TEST_SUITE_P(My, TypeParamTest, MyTypes);
138b89a7cc2SEnji Cooper
main(int argc,char ** argv)139b89a7cc2SEnji Cooper int main(int argc, char** argv) {
140b89a7cc2SEnji Cooper ::testing::InitGoogleTest(&argc, argv);
141b89a7cc2SEnji Cooper
142b89a7cc2SEnji Cooper return RUN_ALL_TESTS();
143b89a7cc2SEnji Cooper }
144