7

This code will run the TestMultiTypes test for both the [float, double] and [char, int] type pairs:

template <typename T>
class UtilsTestFixture2Types : public ::testing::Test {};

using Test2Types = ::testing::Types < std::pair<float, double>, std::pair<char, int> >;

TYPED_TEST_CASE_P( UtilsTestFixture2Types );

TYPED_TEST_P( UtilsTestFixture2Types, TestMultiTypes )
{
    typename TypeParam::first_type  p1 = 123;
    typename TypeParam::second_type p2 = 234;
    EXPECT_EQ( true, p2 < p1 );   // This will fail
}

REGISTER_TYPED_TEST_CASE_P( UtilsTestFixture2Types, TestMultiTypes );
INSTANTIATE_TYPED_TEST_CASE_P( Prefix, UtilsTestFixture2Types, Test2Types );

Now, suppose I have to run the test on all possible pairs of N types. Do I have to list them all manually, or is there a simple way to let Google Test know I want to test the combinations of all possible N values?

References: C++ Multiple parameters with GTest TYPED_TEST

Pietro
  • 12,086
  • 26
  • 100
  • 193
  • 1
    https://stackoverflow.com/questions/9122028/how-to-create-the-cartesian-product-of-a-type-list might be of help. C++17 might offer better options than those mentioned there. – Thomas Dec 03 '19 at 16:27
  • 1
    Does this answer your question? [Create a type list combination of types in C++](https://stackoverflow.com/questions/55005063/create-a-type-list-combination-of-types-in-c) – Marek R Dec 03 '19 at 16:44

0 Answers0