gmock-如何使用noexcept说明符模拟函数 [英] gmock - how to mock function with noexcept specifier

查看:179
本文介绍了gmock-如何使用noexcept说明符模拟函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要模拟以下功能:

 virtual void fun() noexcept = 0;

是否可以使用gmock?

Is it possible using gmock ?

Gmock具有以下宏:#define GMOCK_METHOD0_(tn, constness, ct, Method, ...),但有一条注释:// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!而且我不知道如何使用该宏(参数tn和ct表示什么)?

Gmock has the following macro:#define GMOCK_METHOD0_(tn, constness, ct, Method, ...) but there is a comment: // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! Moreover I don't know how to use that macro (what the parameters tn and ct means) ?

修改

以下模拟:

GMOCK_METHOD0_(, noexcept, ,fun, void());

使用gmock 1.7.0进行编译,但是当我使用gmock 1.8.1进行编译时,出现编译错误:

compiles with gmock 1.7.0 but when I compile it using gmock 1.8.1 I get the compilation errors:

main.cpp:17: error: expected identifier before ‘noexcept’
 GMOCK_METHOD0_(, noexcept, ,fun, void());
                  ^
gmock-generated-function-mockers.h:153: in definition of macro ‘GMOCK_METHOD0_’
   constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
   ^
main.cpp:17: error: expected ‘,’ or ‘...’ before ‘noexcept’
 GMOCK_METHOD0_(, noexcept, ,fun, void());
                  ^
gmock-generated-function-mockers.h:153: in definition of macro ‘GMOCK_METHOD0_’
   constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
   ^
main.cpp:-1: In member function ‘testing::internal::MockSpec<void()> MockX::gmock_fun(const testing::internal::WithoutMatchers&, int) const’:

gmock-generated-function-mockers.h:154: error: ‘AdjustConstness_noexcept’ is not a member of ‘testing::internal’
     return ::testing::internal::AdjustConstness_##constness(this)-> \
            ^
main.cpp:17: in expansion of macro ‘GMOCK_METHOD0_’
 GMOCK_METHOD0_(, noexcept, ,fun, void());
 ^

推荐答案

现在,从v1.10.0开始,使用新语法就可以做到这一点. 请参见更改日志

Now this is possible since v1.10.0 with the new syntax. see change log and new syntax explanation

新语法包含一个单独的参数规范以传递限定符

The new syntax contains a separate argument specs to pass the qualifiers

class MyMock {
   public:
      MOCK_METHOD(ReturnType, MethodName, (Args...), (Specs...));
};

这篇关于gmock-如何使用noexcept说明符模拟函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆