热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何获取gtestTYPED_TEST参数类型

如何解决《如何获取gtestTYPED_TEST参数类型》经验,为你挑选了1个好方法。

我有一些在Windows(Visual Studio 2017)上编写的单元测试,我需要在Linux(GCC 4.9.2-我受此版本困扰...)上移植它们。我为我的问题提供了一个简单的示例,该示例在Windows上可以很好地编译(我认为它不应该像MyParamTypee模板基类的依赖类型那样进行编译),而不能在Linux上进行编译。

例:

#include 

template
struct MyTest : public testing::Test
{
    using MyParamType = T;
};

using MyTypes = testing::Types;
TYPED_TEST_CASE(MyTest, MyTypes);

TYPED_TEST(MyTest, MyTestName)
{
    MyParamType param;
} 

在成员函数'virtual void MyTest_MyTestName_Test :: TestBody()'中:错误:在此范围MyParamType参数中未声明'MyParamType';

通过更改为:

TYPED_TEST(MyTest, MyTestName)
{
    typename MyTest::MyParamType param;
}

代码可以编译,但是看起来很丑陋。

有没有一种简单/好的方法来从中获取模板参数类型TYPED_TEST



1> Richard Hodg..:

答案隐藏在文档中:

#include 

template
struct MyTest : public testing::Test
{
    using MyParamType = T;
};

using MyTypes = testing::Types;
TYPED_TEST_CASE(MyTest, MyTypes);

TYPED_TEST(MyTest, MyTestName)
{
    // To refer to typedefs in the fixture, add the 'typename TestFixture::'
    // prefix.  The 'typename' is required to satisfy the compiler.

    using MyParamType  = typename TestFixture::MyParamType;
}

https://github.com/google/googletest/blob/master/googletest/docs/advanced.md


推荐阅读
author-avatar
baobeimengmen6857124
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有