The C++ Googletest is fairly well documented as to how to write templated tests for standard types. What I need, however, is write tests where the template is an enum and the implementations are specific values of that enum. I can't figure out how to make this work with the tools available (or whether it's even possible).
Copying the examples, I've been trying something along the lines of:
enum Dinosaur { Trex = 0, Stegosaur = 1, Triceratops = 2 };
using MyDinosaurs = ::testing::Types<
Dinosaur::Trex,
Dinosaur::Stegosaur,
Dinosaur::Triceratops>; // This line does not compile, since Dinosaur::Trex etc aren't actually types
template <Dinosaur Dinosaur_T>
class DinosaurTest : public ::testing::Test
{
private:
DinosaurFactory<Dinosaur_T> m_dinosaurFactory;
};
TYPED_TEST_SUITE(DinosaurTest, MyDinosaurs);
TYPED_TEST_P(DinosaurTest, DinosaurEnumTest)
{
ASSERT_NE(nullptr, m_dinosaurFactory.Create());
}
REGISTER_TYPED_TEST_SUITE_P(DinosaurTest, DinosaurEnumTest);
INSTANTIATE_TYPED_TEST_SUITE_P(MyDinosaurTestSuite, DinosaurTest, MyDinosaurs); // This line then also does not compile, since 'MyDinosaurs' isn't a valid list of types
How can I make a test in this fashion work for enums?