I have a problem matching a function argument to a specific object using google mock.
Consider the following code:
class Foo
{
public:
struct Bar
{
int foobar;
}
void myMethod(const Bar& bar);
}
Now I have some testing code, it could look like this:
Foo::Bar bar;
EXPECT_CALL(fooMock, myMethod(Eq(bar));
So I want to make sure that when Foo::myMethod is called, the argument looks like my locally instantiated bar object.
When I try this approach I get an error message like:
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)
I tried playing around with defining operator == and != (at least == both as member of free function), using Eq(ByRef(bar)) but I could not fix the issue. The only thing that helps is using
Field(&Foo::Bar::foobar, x)
but this way I have to check every field in my struct which seems like a lot of typing work...
operator==
as free functions. Did you get the signatures right? – Interferometeroperator==
definition and error message you got. – Fleabitten