如何在 Google Mock C++ 中模拟带有默认参数的方法?

问题描述 投票:0回答:1

如何在 Google Mock 中模拟带有可选参数的方法?例如: 我尝试了这个,但它不起作用:

template <typename T>
class A
{ 
public:
    virtual void set_enable(const int test, const bool enabled = true ) const;
};

template <typename T>
class MockA : public A<T>
{
    MOCK_CONST_METHOD2_T( set_enable, void(const int test, const bool enabled ) );
    void set_enable(const int test /*, const bool enabled = true*/ ) const
    {
        set_enable( test, true);
    }
};

然后致电:

MockA mockA;
EXPECT_CALL(mockA, set_enable(_,true)).Times(Exactly(1));

当我运行测试时,它显示“分段错误”

c++ mocking googletest googlemock
1个回答
0
投票

不确定如何标记为如何在 Google Mock 中使用可选参数模拟方法?或考虑文档https://google.github.io/googletest/gmock_cook_book.html作为旧版本的 gmock 的副本虽然这个特定的问题与我目前正在试图弄清楚的事情是一致的。

© www.soinside.com 2019 - 2024. All rights reserved.