Imported Upstream version 1.14.0
[platform/upstream/gtest.git] / googletest / test / googletest-list-tests-unittest_.cc
1 // Copyright 2006, 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's --gtest_list_tests flag.
31 //
32 // A user can ask Google Test to list all tests that will run
33 // so that when using a filter, a user will know what
34 // tests to look for. The tests will not be run after listing.
35 //
36 // This program will be invoked from a Python unit test.
37 // Don't run it directly.
38
39 #include <ostream>
40 #include <string>
41
42 #include "gtest/gtest.h"
43
44 // Several different test cases and tests that will be listed.
45 TEST(Foo, Bar1) {}
46
47 TEST(Foo, Bar2) {}
48
49 TEST(Foo, DISABLED_Bar3) {}
50
51 TEST(Abc, Xyz) {}
52
53 TEST(Abc, Def) {}
54
55 TEST(FooBar, Baz) {}
56
57 class FooTest : public testing::Test {};
58
59 TEST_F(FooTest, Test1) {}
60
61 TEST_F(FooTest, DISABLED_Test2) {}
62
63 TEST_F(FooTest, Test3) {}
64
65 TEST(FooDeathTest, Test1) {}
66
67 // A group of value-parameterized tests.
68
69 class MyType {
70  public:
71   explicit MyType(const std::string& a_value) : value_(a_value) {}
72
73   const std::string& value() const { return value_; }
74
75  private:
76   std::string value_;
77 };
78
79 // Teaches Google Test how to print a MyType.
80 void PrintTo(const MyType& x, std::ostream* os) { *os << x.value(); }
81
82 class ValueParamTest : public testing::TestWithParam<MyType> {};
83
84 TEST_P(ValueParamTest, TestA) {}
85
86 TEST_P(ValueParamTest, TestB) {}
87
88 INSTANTIATE_TEST_SUITE_P(
89     MyInstantiation, ValueParamTest,
90     testing::Values(
91         MyType("one line"), MyType("two\nlines"),
92         MyType("a "
93                "very\nloooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
94                "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
95                "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
96                "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
97                "ooooong line")));  // NOLINT
98
99 // A group of typed tests.
100
101 // A deliberately long type name for testing the line-truncating
102 // behavior when printing a type parameter.
103 class
104     VeryLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogName {  // NOLINT
105 };
106
107 template <typename T>
108 class TypedTest : public testing::Test {};
109
110 template <typename T, int kSize>
111 class MyArray {};
112
113 typedef testing::Types<
114     VeryLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogName,  // NOLINT
115     int*, MyArray<bool, 42> >
116     MyTypes;
117
118 TYPED_TEST_SUITE(TypedTest, MyTypes);
119
120 TYPED_TEST(TypedTest, TestA) {}
121
122 TYPED_TEST(TypedTest, TestB) {}
123
124 // A group of type-parameterized tests.
125
126 template <typename T>
127 class TypeParamTest : public testing::Test {};
128
129 TYPED_TEST_SUITE_P(TypeParamTest);
130
131 TYPED_TEST_P(TypeParamTest, TestA) {}
132
133 TYPED_TEST_P(TypeParamTest, TestB) {}
134
135 REGISTER_TYPED_TEST_SUITE_P(TypeParamTest, TestA, TestB);
136
137 INSTANTIATE_TYPED_TEST_SUITE_P(My, TypeParamTest, MyTypes);
138
139 int main(int argc, char** argv) {
140   ::testing::InitGoogleTest(&argc, argv);
141
142   return RUN_ALL_TESTS();
143 }