C++ 模板类型化测试方法
这就是我所拥有的:C++ 模板类型化测试方法,c++,templates,googletest,C++,Templates,Googletest,这就是我所拥有的: /* Can't change 'base' struct. */ struct base { public: template<typename T> void printVal() { std::cout << T::x << std::endl; } }; struct testFixture : public base , public ::testing::Test { usi
/* Can't change 'base' struct. */
struct base {
public:
template<typename T>
void printVal() {
std::cout << T::x << std::endl;
}
};
struct testFixture
: public base
, public ::testing::Test {
using base::printVal;
};
TEST_F(testFixture, testF) {
printVal<A>();
printVal<B>();
printVal<C>();
}
有没有一种方法可以通过googletest获得这种类型的功能?找到了答案
“模板化”夹具:
template <typename T>
struct testFixture
: public base
, public ::testing::Test {
using base::printVal;
void printVal() {
base::printVal<T>();
}
};
模板
结构测试夹具
:公共基地
,public::testing::Test{
使用base::printVal;
void printVal(){
base::printVal();
}
};
然后继续正常操作:
typedef ::testing::Types<A, B, C> MyTypes;
TYPED_TEST_CASE(testFixture, MyTypes);
TYPED_TEST(testFixture, typedTest) {
this->template printVal<TypeParam>();
}
typedef::testing::Types MyTypes;
类型化测试用例(testFixture,MyTypes);
类型测试(测试夹具、类型测试){
此->模板printVal();
}
template <typename T>
struct testFixture
: public base
, public ::testing::Test {
using base::printVal;
void printVal() {
base::printVal<T>();
}
};
typedef ::testing::Types<A, B, C> MyTypes;
TYPED_TEST_CASE(testFixture, MyTypes);
TYPED_TEST(testFixture, typedTest) {
this->template printVal<TypeParam>();
}