googlemockmatcher

gmock matcher doesn't match my arguments by reference


I have a mocked function in a class like

int foo(const bar& b) const;

which is mocked like

MOCK_CONST_METHOD1(foo, int(const bar& b));

for which I've set set some default actions like

ON_CALL(anObject, foo(bar(0,0))).WillByDefault(Return(1));

My code under test calls

anObject.foo(bar(0,0);

but instead of returning 1, gmock gives me the following error:

Uninteresting mock function call - returning default value.
Function call: foo(@0xbfffcf90 8-byte object <00-00 00-00 00-00 00-00>)
The mock function has no default action set, and its return type has no default value set.

The operator == is defined for the object bar. Why can't gmock find my default actions?


Solution

  • The error was not in the code above. The ON_CALLstatement was after the code on test.

    Simple answer: Be sure to have the ON_CALL statements before any code calls the mocked methods.