2

Can I call both returns and calls action at the same time in a single MOCK_EXPECT call? Like,

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

Thanks

domlao
  • 15,663
  • 34
  • 95
  • 134

1 Answers1

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 */
});
ComicSansMS
  • 51,484
  • 14
  • 155
  • 166