|
|
|||
File indexing completed on 2026-11-19 10:45:45
0001 // Copyright 2008, Google Inc. 0002 // All rights reserved. 0003 // 0004 // Redistribution and use in source and binary forms, with or without 0005 // modification, are permitted provided that the following conditions are 0006 // met: 0007 // 0008 // * Redistributions of source code must retain the above copyright 0009 // notice, this list of conditions and the following disclaimer. 0010 // * Redistributions in binary form must reproduce the above 0011 // copyright notice, this list of conditions and the following disclaimer 0012 // in the documentation and/or other materials provided with the 0013 // distribution. 0014 // * Neither the name of Google Inc. nor the names of its 0015 // contributors may be used to endorse or promote products derived from 0016 // this software without specific prior written permission. 0017 // 0018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 0019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 0020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 0021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 0022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0029 0030 // Macros and functions for implementing parameterized tests 0031 // in Google C++ Testing and Mocking Framework (Google Test) 0032 0033 // IWYU pragma: private, include "gtest/gtest.h" 0034 // IWYU pragma: friend gtest/.* 0035 // IWYU pragma: friend gmock/.* 0036 0037 #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_ 0038 #define GOOGLETEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_ 0039 0040 // Value-parameterized tests allow you to test your code with different 0041 // parameters without writing multiple copies of the same test. 0042 // 0043 // Here is how you use value-parameterized tests: 0044 0045 #if 0 0046 0047 // To write value-parameterized tests, first you should define a fixture 0048 // class. It is usually derived from testing::TestWithParam<T> (see below for 0049 // another inheritance scheme that's sometimes useful in more complicated 0050 // class hierarchies), where the type of your parameter values. 0051 // TestWithParam<T> is itself derived from testing::Test. T can be any 0052 // copyable type. If it's a raw pointer, you are responsible for managing the 0053 // lifespan of the pointed values. 0054 0055 class FooTest : public ::testing::TestWithParam<const char*> { 0056 // You can implement all the usual class fixture members here. 0057 }; 0058 0059 // Then, use the TEST_P macro to define as many parameterized tests 0060 // for this fixture as you want. The _P suffix is for "parameterized" 0061 // or "pattern", whichever you prefer to think. 0062 0063 TEST_P(FooTest, DoesBlah) { 0064 // Inside a test, access the test parameter with the GetParam() method 0065 // of the TestWithParam<T> class: 0066 EXPECT_TRUE(foo.Blah(GetParam())); 0067 ... 0068 } 0069 0070 TEST_P(FooTest, HasBlahBlah) { 0071 ... 0072 } 0073 0074 // Finally, you can use INSTANTIATE_TEST_SUITE_P to instantiate the test 0075 // case with any set of parameters you want. Google Test defines a number 0076 // of functions for generating test parameters. They return what we call 0077 // (surprise!) parameter generators. Here is a summary of them, which 0078 // are all in the testing namespace: 0079 // 0080 // 0081 // Range(begin, end [, step]) - Yields values {begin, begin+step, 0082 // begin+step+step, ...}. The values do not 0083 // include end. step defaults to 1. 0084 // Values(v1, v2, ..., vN) - Yields values {v1, v2, ..., vN}. 0085 // ValuesIn(container) - Yields values from a C-style array, an STL 0086 // ValuesIn(begin,end) container, or an iterator range [begin, end). 0087 // Bool() - Yields sequence {false, true}. 0088 // Combine(g1, g2, ..., gN) - Yields all combinations (the Cartesian product 0089 // for the math savvy) of the values generated 0090 // by the N generators. 0091 // 0092 // For more details, see comments at the definitions of these functions below 0093 // in this file. 0094 // 0095 // The following statement will instantiate tests from the FooTest test suite 0096 // each with parameter values "meeny", "miny", and "moe". 0097 0098 INSTANTIATE_TEST_SUITE_P(InstantiationName, 0099 FooTest, 0100 Values("meeny", "miny", "moe")); 0101 0102 // To distinguish different instances of the pattern, (yes, you 0103 // can instantiate it more than once) the first argument to the 0104 // INSTANTIATE_TEST_SUITE_P macro is a prefix that will be added to the 0105 // actual test suite name. Remember to pick unique prefixes for different 0106 // instantiations. The tests from the instantiation above will have 0107 // these names: 0108 // 0109 // * InstantiationName/FooTest.DoesBlah/0 for "meeny" 0110 // * InstantiationName/FooTest.DoesBlah/1 for "miny" 0111 // * InstantiationName/FooTest.DoesBlah/2 for "moe" 0112 // * InstantiationName/FooTest.HasBlahBlah/0 for "meeny" 0113 // * InstantiationName/FooTest.HasBlahBlah/1 for "miny" 0114 // * InstantiationName/FooTest.HasBlahBlah/2 for "moe" 0115 // 0116 // You can use these names in --gtest_filter. 0117 // 0118 // This statement will instantiate all tests from FooTest again, each 0119 // with parameter values "cat" and "dog": 0120 0121 const char* pets[] = {"cat", "dog"}; 0122 INSTANTIATE_TEST_SUITE_P(AnotherInstantiationName, FooTest, ValuesIn(pets)); 0123 0124 // The tests from the instantiation above will have these names: 0125 // 0126 // * AnotherInstantiationName/FooTest.DoesBlah/0 for "cat" 0127 // * AnotherInstantiationName/FooTest.DoesBlah/1 for "dog" 0128 // * AnotherInstantiationName/FooTest.HasBlahBlah/0 for "cat" 0129 // * AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog" 0130 // 0131 // Please note that INSTANTIATE_TEST_SUITE_P will instantiate all tests 0132 // in the given test suite, whether their definitions come before or 0133 // AFTER the INSTANTIATE_TEST_SUITE_P statement. 0134 // 0135 // Please also note that generator expressions (including parameters to the 0136 // generators) are evaluated in InitGoogleTest(), after main() has started. 0137 // This allows the user on one hand, to adjust generator parameters in order 0138 // to dynamically determine a set of tests to run and on the other hand, 0139 // give the user a chance to inspect the generated tests with Google Test 0140 // reflection API before RUN_ALL_TESTS() is executed. 0141 // 0142 // You can see samples/sample7_unittest.cc and samples/sample8_unittest.cc 0143 // for more examples. 0144 // 0145 // In the future, we plan to publish the API for defining new parameter 0146 // generators. But for now this interface remains part of the internal 0147 // implementation and is subject to change. 0148 // 0149 // 0150 // A parameterized test fixture must be derived from testing::Test and from 0151 // testing::WithParamInterface<T>, where T is the type of the parameter 0152 // values. Inheriting from TestWithParam<T> satisfies that requirement because 0153 // TestWithParam<T> inherits from both Test and WithParamInterface. In more 0154 // complicated hierarchies, however, it is occasionally useful to inherit 0155 // separately from Test and WithParamInterface. For example: 0156 0157 class BaseTest : public ::testing::Test { 0158 // You can inherit all the usual members for a non-parameterized test 0159 // fixture here. 0160 }; 0161 0162 class DerivedTest : public BaseTest, public ::testing::WithParamInterface<int> { 0163 // The usual test fixture members go here too. 0164 }; 0165 0166 TEST_F(BaseTest, HasFoo) { 0167 // This is an ordinary non-parameterized test. 0168 } 0169 0170 TEST_P(DerivedTest, DoesBlah) { 0171 // GetParam works just the same here as if you inherit from TestWithParam. 0172 EXPECT_TRUE(foo.Blah(GetParam())); 0173 } 0174 0175 #endif // 0 0176 0177 #include <functional> 0178 #include <iterator> 0179 #include <utility> 0180 0181 #include "gtest/internal/gtest-internal.h" 0182 #include "gtest/internal/gtest-param-util.h" // IWYU pragma: export 0183 #include "gtest/internal/gtest-port.h" 0184 0185 namespace testing { 0186 0187 // Functions producing parameter generators. 0188 // 0189 // Google Test uses these generators to produce parameters for value- 0190 // parameterized tests. When a parameterized test suite is instantiated 0191 // with a particular generator, Google Test creates and runs tests 0192 // for each element in the sequence produced by the generator. 0193 // 0194 // In the following sample, tests from test suite FooTest are instantiated 0195 // each three times with parameter values 3, 5, and 8: 0196 // 0197 // class FooTest : public TestWithParam<int> { ... }; 0198 // 0199 // TEST_P(FooTest, TestThis) { 0200 // } 0201 // TEST_P(FooTest, TestThat) { 0202 // } 0203 // INSTANTIATE_TEST_SUITE_P(TestSequence, FooTest, Values(3, 5, 8)); 0204 // 0205 0206 // Range() returns generators providing sequences of values in a range. 0207 // 0208 // Synopsis: 0209 // Range(start, end) 0210 // - returns a generator producing a sequence of values {start, start+1, 0211 // start+2, ..., }. 0212 // Range(start, end, step) 0213 // - returns a generator producing a sequence of values {start, start+step, 0214 // start+step+step, ..., }. 0215 // Notes: 0216 // * The generated sequences never include end. For example, Range(1, 5) 0217 // returns a generator producing a sequence {1, 2, 3, 4}. Range(1, 9, 2) 0218 // returns a generator producing {1, 3, 5, 7}. 0219 // * start and end must have the same type. That type may be any integral or 0220 // floating-point type or a user defined type satisfying these conditions: 0221 // * It must be assignable (have operator=() defined). 0222 // * It must have operator+() (operator+(int-compatible type) for 0223 // two-operand version). 0224 // * It must have operator<() defined. 0225 // Elements in the resulting sequences will also have that type. 0226 // * Condition start < end must be satisfied in order for resulting sequences 0227 // to contain any elements. 0228 // 0229 template <typename T, typename IncrementT> 0230 internal::ParamGenerator<T> Range(T start, T end, IncrementT step) { 0231 return internal::ParamGenerator<T>( 0232 new internal::RangeGenerator<T, IncrementT>(start, end, step)); 0233 } 0234 0235 template <typename T> 0236 internal::ParamGenerator<T> Range(T start, T end) { 0237 return Range(start, end, 1); 0238 } 0239 0240 // ValuesIn() function allows generation of tests with parameters coming from 0241 // a container. 0242 // 0243 // Synopsis: 0244 // ValuesIn(const T (&array)[N]) 0245 // - returns a generator producing sequences with elements from 0246 // a C-style array. 0247 // ValuesIn(const Container& container) 0248 // - returns a generator producing sequences with elements from 0249 // an STL-style container. 0250 // ValuesIn(Iterator begin, Iterator end) 0251 // - returns a generator producing sequences with elements from 0252 // a range [begin, end) defined by a pair of STL-style iterators. These 0253 // iterators can also be plain C pointers. 0254 // 0255 // Please note that ValuesIn copies the values from the containers 0256 // passed in and keeps them to generate tests in RUN_ALL_TESTS(). 0257 // 0258 // Examples: 0259 // 0260 // This instantiates tests from test suite StringTest 0261 // each with C-string values of "foo", "bar", and "baz": 0262 // 0263 // const char* strings[] = {"foo", "bar", "baz"}; 0264 // INSTANTIATE_TEST_SUITE_P(StringSequence, StringTest, ValuesIn(strings)); 0265 // 0266 // This instantiates tests from test suite StlStringTest 0267 // each with STL strings with values "a" and "b": 0268 // 0269 // ::std::vector< ::std::string> GetParameterStrings() { 0270 // ::std::vector< ::std::string> v; 0271 // v.push_back("a"); 0272 // v.push_back("b"); 0273 // return v; 0274 // } 0275 // 0276 // INSTANTIATE_TEST_SUITE_P(CharSequence, 0277 // StlStringTest, 0278 // ValuesIn(GetParameterStrings())); 0279 // 0280 // 0281 // This will also instantiate tests from CharTest 0282 // each with parameter values 'a' and 'b': 0283 // 0284 // ::std::list<char> GetParameterChars() { 0285 // ::std::list<char> list; 0286 // list.push_back('a'); 0287 // list.push_back('b'); 0288 // return list; 0289 // } 0290 // ::std::list<char> l = GetParameterChars(); 0291 // INSTANTIATE_TEST_SUITE_P(CharSequence2, 0292 // CharTest, 0293 // ValuesIn(l.begin(), l.end())); 0294 // 0295 template <typename ForwardIterator> 0296 internal::ParamGenerator< 0297 typename std::iterator_traits<ForwardIterator>::value_type> 0298 ValuesIn(ForwardIterator begin, ForwardIterator end) { 0299 typedef typename std::iterator_traits<ForwardIterator>::value_type ParamType; 0300 return internal::ParamGenerator<ParamType>( 0301 new internal::ValuesInIteratorRangeGenerator<ParamType>(begin, end)); 0302 } 0303 0304 template <typename T, size_t N> 0305 internal::ParamGenerator<T> ValuesIn(const T (&array)[N]) { 0306 return ValuesIn(array, array + N); 0307 } 0308 0309 template <class Container> 0310 internal::ParamGenerator<typename Container::value_type> ValuesIn( 0311 const Container& container) { 0312 return ValuesIn(container.begin(), container.end()); 0313 } 0314 0315 // Values() allows generating tests from explicitly specified list of 0316 // parameters. 0317 // 0318 // Synopsis: 0319 // Values(T v1, T v2, ..., T vN) 0320 // - returns a generator producing sequences with elements v1, v2, ..., vN. 0321 // 0322 // For example, this instantiates tests from test suite BarTest each 0323 // with values "one", "two", and "three": 0324 // 0325 // INSTANTIATE_TEST_SUITE_P(NumSequence, 0326 // BarTest, 0327 // Values("one", "two", "three")); 0328 // 0329 // This instantiates tests from test suite BazTest each with values 1, 2, 3.5. 0330 // The exact type of values will depend on the type of parameter in BazTest. 0331 // 0332 // INSTANTIATE_TEST_SUITE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5)); 0333 // 0334 // 0335 template <typename... T> 0336 internal::ValueArray<T...> Values(T... v) { 0337 return internal::ValueArray<T...>(std::move(v)...); 0338 } 0339 0340 // Bool() allows generating tests with parameters in a set of (false, true). 0341 // 0342 // Synopsis: 0343 // Bool() 0344 // - returns a generator producing sequences with elements {false, true}. 0345 // 0346 // It is useful when testing code that depends on Boolean flags. Combinations 0347 // of multiple flags can be tested when several Bool()'s are combined using 0348 // Combine() function. 0349 // 0350 // In the following example all tests in the test suite FlagDependentTest 0351 // will be instantiated twice with parameters false and true. 0352 // 0353 // class FlagDependentTest : public testing::TestWithParam<bool> { 0354 // virtual void SetUp() { 0355 // external_flag = GetParam(); 0356 // } 0357 // } 0358 // INSTANTIATE_TEST_SUITE_P(BoolSequence, FlagDependentTest, Bool()); 0359 // 0360 inline internal::ParamGenerator<bool> Bool() { return Values(false, true); } 0361 0362 // Combine() allows the user to combine two or more sequences to produce 0363 // values of a Cartesian product of those sequences' elements. 0364 // 0365 // Synopsis: 0366 // Combine(gen1, gen2, ..., genN) 0367 // - returns a generator producing sequences with elements coming from 0368 // the Cartesian product of elements from the sequences generated by 0369 // gen1, gen2, ..., genN. The sequence elements will have a type of 0370 // std::tuple<T1, T2, ..., TN> where T1, T2, ..., TN are the types 0371 // of elements from sequences produces by gen1, gen2, ..., genN. 0372 // 0373 // Example: 0374 // 0375 // This will instantiate tests in test suite AnimalTest each one with 0376 // the parameter values tuple("cat", BLACK), tuple("cat", WHITE), 0377 // tuple("dog", BLACK), and tuple("dog", WHITE): 0378 // 0379 // enum Color { BLACK, GRAY, WHITE }; 0380 // class AnimalTest 0381 // : public testing::TestWithParam<std::tuple<const char*, Color> > {...}; 0382 // 0383 // TEST_P(AnimalTest, AnimalLooksNice) {...} 0384 // 0385 // INSTANTIATE_TEST_SUITE_P(AnimalVariations, AnimalTest, 0386 // Combine(Values("cat", "dog"), 0387 // Values(BLACK, WHITE))); 0388 // 0389 // This will instantiate tests in FlagDependentTest with all variations of two 0390 // Boolean flags: 0391 // 0392 // class FlagDependentTest 0393 // : public testing::TestWithParam<std::tuple<bool, bool> > { 0394 // virtual void SetUp() { 0395 // // Assigns external_flag_1 and external_flag_2 values from the tuple. 0396 // std::tie(external_flag_1, external_flag_2) = GetParam(); 0397 // } 0398 // }; 0399 // 0400 // TEST_P(FlagDependentTest, TestFeature1) { 0401 // // Test your code using external_flag_1 and external_flag_2 here. 0402 // } 0403 // INSTANTIATE_TEST_SUITE_P(TwoBoolSequence, FlagDependentTest, 0404 // Combine(Bool(), Bool())); 0405 // 0406 template <typename... Generator> 0407 internal::CartesianProductHolder<Generator...> Combine(const Generator&... g) { 0408 return internal::CartesianProductHolder<Generator...>(g...); 0409 } 0410 0411 // ConvertGenerator() wraps a parameter generator in order to cast each produced 0412 // value through a known type before supplying it to the test suite 0413 // 0414 // Synopsis: 0415 // ConvertGenerator<T>(gen) 0416 // - returns a generator producing the same elements as generated by gen, but 0417 // each T-typed element is static_cast to a type deduced from the interface 0418 // that accepts this generator, and then returned 0419 // 0420 // It is useful when using the Combine() function to get the generated 0421 // parameters in a custom type instead of std::tuple 0422 // 0423 // Example: 0424 // 0425 // This will instantiate tests in test suite AnimalTest each one with 0426 // the parameter values tuple("cat", BLACK), tuple("cat", WHITE), 0427 // tuple("dog", BLACK), and tuple("dog", WHITE): 0428 // 0429 // enum Color { BLACK, GRAY, WHITE }; 0430 // struct ParamType { 0431 // using TupleT = std::tuple<const char*, Color>; 0432 // std::string animal; 0433 // Color color; 0434 // ParamType(TupleT t) : animal(std::get<0>(t)), color(std::get<1>(t)) {} 0435 // }; 0436 // class AnimalTest 0437 // : public testing::TestWithParam<ParamType> {...}; 0438 // 0439 // TEST_P(AnimalTest, AnimalLooksNice) {...} 0440 // 0441 // INSTANTIATE_TEST_SUITE_P(AnimalVariations, AnimalTest, 0442 // ConvertGenerator<ParamType::TupleT>( 0443 // Combine(Values("cat", "dog"), 0444 // Values(BLACK, WHITE)))); 0445 // 0446 template <typename RequestedT> 0447 internal::ParamConverterGenerator<RequestedT> ConvertGenerator( 0448 internal::ParamGenerator<RequestedT> gen) { 0449 return internal::ParamConverterGenerator<RequestedT>(std::move(gen)); 0450 } 0451 0452 // As above, but takes a callable as a second argument. The callable converts 0453 // the generated parameter to the test fixture's parameter type. This allows you 0454 // to use a parameter type that does not have a converting constructor from the 0455 // generated type. 0456 // 0457 // Example: 0458 // 0459 // This will instantiate tests in test suite AnimalTest each one with 0460 // the parameter values tuple("cat", BLACK), tuple("cat", WHITE), 0461 // tuple("dog", BLACK), and tuple("dog", WHITE): 0462 // 0463 // enum Color { BLACK, GRAY, WHITE }; 0464 // struct ParamType { 0465 // std::string animal; 0466 // Color color; 0467 // }; 0468 // class AnimalTest 0469 // : public testing::TestWithParam<ParamType> {...}; 0470 // 0471 // TEST_P(AnimalTest, AnimalLooksNice) {...} 0472 // 0473 // INSTANTIATE_TEST_SUITE_P( 0474 // AnimalVariations, AnimalTest, 0475 // ConvertGenerator(Combine(Values("cat", "dog"), Values(BLACK, WHITE)), 0476 // [](std::tuple<std::string, Color> t) { 0477 // return ParamType{.animal = std::get<0>(t), 0478 // .color = std::get<1>(t)}; 0479 // })); 0480 // 0481 template <typename T, int&... ExplicitArgumentBarrier, typename Gen, 0482 typename Func, 0483 typename StdFunction = decltype(std::function(std::declval<Func>()))> 0484 internal::ParamConverterGenerator<T, StdFunction> ConvertGenerator(Gen&& gen, 0485 Func&& f) { 0486 return internal::ParamConverterGenerator<T, StdFunction>( 0487 std::forward<Gen>(gen), std::forward<Func>(f)); 0488 } 0489 0490 // As above, but infers the T from the supplied std::function instead of 0491 // having the caller specify it. 0492 template <int&... ExplicitArgumentBarrier, typename Gen, typename Func, 0493 typename StdFunction = decltype(std::function(std::declval<Func>()))> 0494 auto ConvertGenerator(Gen&& gen, Func&& f) { 0495 constexpr bool is_single_arg_std_function = 0496 internal::IsSingleArgStdFunction<StdFunction>::value; 0497 if constexpr (is_single_arg_std_function) { 0498 return ConvertGenerator< 0499 typename internal::FuncSingleParamType<StdFunction>::type>( 0500 std::forward<Gen>(gen), std::forward<Func>(f)); 0501 } else { 0502 static_assert(is_single_arg_std_function, 0503 "The call signature must contain a single argument."); 0504 } 0505 } 0506 0507 #define TEST_P(test_suite_name, test_name) \ 0508 class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ 0509 : public test_suite_name, \ 0510 private ::testing::internal::GTestNonCopyable { \ 0511 public: \ 0512 GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \ 0513 void TestBody() override; \ 0514 \ 0515 private: \ 0516 static int AddToRegistry() { \ 0517 ::testing::UnitTest::GetInstance() \ 0518 ->parameterized_test_registry() \ 0519 .GetTestSuitePatternHolder<test_suite_name>( \ 0520 GTEST_STRINGIFY_(test_suite_name), \ 0521 ::testing::internal::CodeLocation(__FILE__, __LINE__)) \ 0522 ->AddTestPattern( \ 0523 GTEST_STRINGIFY_(test_suite_name), GTEST_STRINGIFY_(test_name), \ 0524 new ::testing::internal::TestMetaFactory<GTEST_TEST_CLASS_NAME_( \ 0525 test_suite_name, test_name)>(), \ 0526 ::testing::internal::CodeLocation(__FILE__, __LINE__)); \ 0527 return 0; \ 0528 } \ 0529 [[maybe_unused]] static int gtest_registering_dummy_; \ 0530 }; \ 0531 int GTEST_TEST_CLASS_NAME_(test_suite_name, \ 0532 test_name)::gtest_registering_dummy_ = \ 0533 GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::AddToRegistry(); \ 0534 void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody() 0535 0536 // The last argument to INSTANTIATE_TEST_SUITE_P allows the user to specify 0537 // generator and an optional function or functor that generates custom test name 0538 // suffixes based on the test parameters. Such a function or functor should 0539 // accept one argument of type testing::TestParamInfo<class ParamType>, and 0540 // return std::string. 0541 // 0542 // testing::PrintToStringParamName is a builtin test suffix generator that 0543 // returns the value of testing::PrintToString(GetParam()). 0544 // 0545 // Note: test names must be non-empty, unique, and may only contain ASCII 0546 // alphanumeric characters or underscore. Because PrintToString adds quotes 0547 // to std::string and C strings, it won't work for these types. 0548 0549 #define GTEST_EXPAND_(arg) arg 0550 #define GTEST_GET_FIRST_(first, ...) first 0551 #define GTEST_GET_SECOND_(first, second, ...) second 0552 0553 #define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name, ...) \ 0554 static ::testing::internal::ParamGenerator<test_suite_name::ParamType> \ 0555 gtest_##prefix##test_suite_name##_EvalGenerator_() { \ 0556 return GTEST_EXPAND_(GTEST_GET_FIRST_(__VA_ARGS__, DUMMY_PARAM_)); \ 0557 } \ 0558 static ::std::string gtest_##prefix##test_suite_name##_EvalGenerateName_( \ 0559 const ::testing::TestParamInfo<test_suite_name::ParamType>& info) { \ 0560 if (::testing::internal::AlwaysFalse()) { \ 0561 ::testing::internal::TestNotEmpty(GTEST_EXPAND_(GTEST_GET_SECOND_( \ 0562 __VA_ARGS__, \ 0563 ::testing::internal::DefaultParamName<test_suite_name::ParamType>, \ 0564 DUMMY_PARAM_))); \ 0565 auto t = std::make_tuple(__VA_ARGS__); \ 0566 static_assert(std::tuple_size<decltype(t)>::value <= 2, \ 0567 "Too Many Args!"); \ 0568 } \ 0569 return ((GTEST_EXPAND_(GTEST_GET_SECOND_( \ 0570 __VA_ARGS__, \ 0571 ::testing::internal::DefaultParamName<test_suite_name::ParamType>, \ 0572 DUMMY_PARAM_))))(info); \ 0573 } \ 0574 [[maybe_unused]] static int gtest_##prefix##test_suite_name##_dummy_ = \ 0575 ::testing::UnitTest::GetInstance() \ 0576 ->parameterized_test_registry() \ 0577 .GetTestSuitePatternHolder<test_suite_name>( \ 0578 GTEST_STRINGIFY_(test_suite_name), \ 0579 ::testing::internal::CodeLocation(__FILE__, __LINE__)) \ 0580 ->AddTestSuiteInstantiation( \ 0581 GTEST_STRINGIFY_(prefix), \ 0582 >est_##prefix##test_suite_name##_EvalGenerator_, \ 0583 >est_##prefix##test_suite_name##_EvalGenerateName_, __FILE__, \ 0584 __LINE__) 0585 0586 // Allow Marking a Parameterized test class as not needing to be instantiated. 0587 #define GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(T) \ 0588 namespace gtest_do_not_use_outside_namespace_scope {} \ 0589 static const ::testing::internal::MarkAsIgnored gtest_allow_ignore_##T( \ 0590 GTEST_STRINGIFY_(T)) 0591 0592 // Legacy API is deprecated but still available 0593 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 0594 #define INSTANTIATE_TEST_CASE_P \ 0595 static_assert(::testing::internal::InstantiateTestCase_P_IsDeprecated(), \ 0596 ""); \ 0597 INSTANTIATE_TEST_SUITE_P 0598 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 0599 0600 } // namespace testing 0601 0602 #endif // GOOGLETEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|