I am having an issue with Google Test. I have a code equivalent to what follows:
A.h
template<int N> class A {
...
};
test_A.cpp
#include "gtest/gtest.h"
#include "A.h"
template<typename T> class TestA : public ::testing::Test {};
TYPED_TEST_CASE_P(TestA);
TYPED_TEST_P(TestA, SomeTest){
TypeParam x = 0;
EXPECT_EQ(x,0);
...
}
REGISTER_TYPED_TEST_CASE_P(TestA, SomeTest);
typedef ::testing::Types<A<0>, A<1>, A<2>, A<3>, A<4>, A<5> ... A<511>, A<512>> MyTypes;
INSTANTIATE_TYPED_TEST_CASE_P(My, TestA, MyTypes);
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
To sum up, I want to run the test SomeTeston class A for many versions of N. With the type-parameterized test developed above, the problem is that with "typed test" method, I have to write manually all versions of class A I want to test.
With Google Test, you can also write value-parameterized tests, which is very convenient because you can use generators like Range:
INSTANTIATE_TEST_CASE_P(InstantiationName, TestA, ::testing::Range(0,512,1));
and then, you can access the values using the function GetParam() inside the test. This syntax would make what I want to do very easy to setup. However, it seems that the values are not resolved at compile time, and they are therefore not usable to specify templates values.
My questions are:
- Is there some syntax which is equivalent to value-parameterized testing in Google Test to specify all versions of
AI want to test? - If there is not, how can I generate my list of types
A<0>, ..., A<512>to be used with type-parameterized testing?
N.B: It has to be c++11 compliant.
Aucun commentaire:
Enregistrer un commentaire