Is it possible to return different values using ON_CALL WillByDefault? for example
class FooMock {
  MOCK_METHOD0(foo, int());
}
void bar()
{
  FooMock mock;
  int f = 0;
  ON_CALL(mock, foo()).WillByDefault(Return(f));
  EXPECT_TRUE(f==mock.foo()); // this is correct
  f++;
  EXPECT_TRUE(f==mock.foo()); // it is failed, because ON_CALL returns f=0
}
Does exists some way to return new value of variable?
Yes there is a way, change your code to:
ON_CALL(mock, foo())
       .WillByDefault(ReturnPointee(&f));
Read more about ReturnPointee in this link (in the Returning Live Values from Mock Methods section)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With