Google Test: how to test all possible pairs of N types?
Asked Answered
C

0

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

Crossexamine answered 3/12, 2019 at 16:22 Comment(2)
#9122528 might be of help. C++17 might offer better options than those mentioned there.Azerbaijan
Does this answer your question? Create a type list combination of types in C++Tawnatawney

© 2022 - 2024 — McMap. All rights reserved.