I want to test a template function on a range of values and a range of types. So something like
template <class T>
void foo(Bar<T>&);
But the issue is I can't get the google test's value parametrised tests to work with template test suite. Most of my tests currently look like this:
TYPED_TEST(FooTest, foo) {
for (int repeats = 0 ...) { // don't want this
Bar<TypeParam> bar;
for (... i < repeats ...)
foo(bar);
EXPECT_EQ(bar, /*...*/);
}
}
So I am looking for a way to get rid of that first for loop and pass repeats as a const parameter instead. And just in case you are wondering here is the real test file. Although its not entirely this way right now because I am refactoring this code.
I have tried this so far:
using NumericTypes = ::testing::Types<uint8_t /*...*/ >;
template <class T>
class FooTest
: public ::testing::TestWithParam<const int> { };
TYPED_TEST_SUITE(FooTest,
NumericTypes,
TestingTypenames);
INSTANTIATE_TEST_SUITE_P(SomeFooTest,
FooTest,
testing::Range(0,3));
The error I am getting:
foo.cpp: error: template argument 1 is invalid
16 | INSTANTIATE_TEST_SUITE_P(SomeFooTest,
| ^~~~~~~~~~~~~~~~~~~~~~~~
So these type parametrized tests are making wonders for me its just the for loops that are bothering me. And in the new tests I am writing there would be 3 layers of for loops because I am testing nested lists and they will behave differently if they are nested.