You can use Times
.
// This is the final call
EXPECT_CALL(obj, IsDone())
.WillOnce(Return(true));
// These are the intermediate calls
EXPECT_CALL(obj, IsDone())
.Times(N)
.WillRepeatedly(Return(false))
.RetiresOnSaturation();
The mock object's IsDone
method will return false the first N times it's called. After that, the most recent expectation will have been satisfied, so we instruct it to no longer apply by using RetiresOnSaturation
. Subsequent calls to IsDone
will be handled by the first expectation, causing it to return true. If it's called any more times, the test will fail.
If you omit RetiresOnSaturation
, then the second expectation will continue to apply; it will continue returning false, and you'll get messages alerting you that the "over-saturated and active" expectation is failing.