2

我可以在一个 MOCK_EXPECT 调用中同时调用返回和调用操作吗?喜欢,

MOCK_EXPECT(a.method).calls(functor).returns(value);

谢谢

4

1 回答 1

2

The return value of the functor is the value that will be returned to the caller. Therefore giving an additional explicit return value via .returns makes little sense.

However you can still specify the return value at the expect call (as opposed to in the functor) by using a wrapper functor:

MOCK_EXPECT(a.method).calls([]() -> int {
    functor(); /* return value of functor is discarded */
    return 42; /* 42 is returned instead */
});
于 2013-10-02T07:57:56.073 回答