我有一个问题,使用谷歌模拟将函数参数匹配到特定的对象。googlemock中自定义类型的匹配参数
考虑下面的代码:
class Foo
{
public:
struct Bar
{
int foobar;
}
void myMethod(const Bar& bar);
}
现在我有一些测试代码,它看起来是这样的:
Foo::Bar bar;
EXPECT_CALL(fooMock, myMethod(Eq(bar));
所以我想确保当富:: myMethod的被称为,该参数看起来像我本地实例化的条形对象。
当我尝试这种方法,我得到这样一个错误信息:
gmock/gmock-matchers.h(738): error C2678: binary '==' : no operator found which takes a left-hand operand of type 'const Foo::Bar' (or there is no acceptable conversion)
我试图定义的==操作符和玩弄=(至少==作为游离功能的成员),用公式(ByRef(bar)),但我无法解决这个问题。帮助使用
Field(&Foo::Bar::foobar, x)
但这种方式我要检查我的struct各个领域,这似乎像很多输入的工作的唯一的事情...
我从来没有与正确定义'运营商=='免费的功能问题。你的签名是否正确? – arne
请发布您的'operator =='定义和错误消息。 –
布尔操作符==(const Foo :: Bar&first,const Foo :: Bar&second) – anhoppe