是否可以使用ON_CALL WillByDefault返回不同的值? 例如
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
}
是否存在某种返回变量新值的方法?
答案 0 :(得分:1)
是的,有一种方法,将您的代码更改为:
ON_CALL(mock, foo())
.WillByDefault(ReturnPointee(&f));
详细了解ReturnPointee
in this link(Returning Live Values from Mock Methods
部分)