Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
googletest-list-tests-unittest_.cc
Go to the documentation of this file.
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 
85 
87 
89  MyInstantiation, ValueParamTest,
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
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<
115  int*, MyArray<bool, 42> >
117 
119 
121 
123 
124 // A group of type-parameterized tests.
125 
126 template <typename T>
127 class TypeParamTest : public testing::Test {};
128 
130 
132 
134 
136 
138 
139 int main(int argc, char** argv) {
140  ::testing::InitGoogleTest(&argc, argv);
141 
142  return RUN_ALL_TESTS();
143 }
#define TYPED_TEST_P(SuiteName, TestName)
internal::ValueArray< T...> Values(T...v)
#define TEST_F(test_fixture, test_name)
Definition: gtest.h:2224
#define TEST(test_suite_name, test_name)
Definition: gtest.h:2192
#define TYPED_TEST_SUITE(CaseName, Types,...)
#define INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, SuiteName, Types,...)
int main()
Definition: ad_example.cpp:171
const std::string & value() const
void PrintTo(const T &value,::std::ostream *os)
#define TEST_P(test_suite_name, test_name)
#define TYPED_TEST(CaseName, TestName)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: gtest.h:2334
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: gtest.cc:6885
#define TYPED_TEST_SUITE_P(SuiteName)
testing::Types< VeryLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogName, int *, MyArray< bool, 42 > > MyTypes
#define REGISTER_TYPED_TEST_SUITE_P(SuiteName,...)
#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name,...)
MyType(const std::string &a_value)