This is possible to do in two ways :
- with custom methods executor - create a class, with the same methods. And then use
Invoke()
to pass the call to that object
- using partial order call - create different expectations in different sequences, as explained here
With custom method executor
Something like this :
struct MethodsTracker {
void doFoo( int ) {
++ n;
}
void doFooAndBar( int, int ) {
++ n;
}
int n;
};
TEST_F( MyTest, CheckItInvokesAtLeastOne ) {
MethodsTracker tracker;
Api obj( mock );
EXPECT_CALL( mock, doFoo(_) ).Times( AnyNumber() ).WillByDefault( Invoke( &tracker, &MethodsTracker::doFoo ) );
EXPECT_CALL( mock, doFooAndBar(_,_) ).Times( AnyNumber() ).WillByDefault( Invoke( &tracker, &MethodsTracker::doFooAndBar ) );
obj.executeCall();
// at least one
EXPECT_GE( tracker.n, 1 );
}
using partial order call
TEST_F( MyTest, CheckItInvokesAtLeastOne ) {
MethodsTracker tracker;
Api obj( mock );
Sequence s1, s2, s3, s4;
EXPECT_CALL(mock, doFoo(_)).InSequence(s1).Times(AtLeast(1));
EXPECT_CALL(mock, doFooAndBar(_,_)).InSequence(s1).Times(AtLeast(0));
EXPECT_CALL(mock, doFoo(_)).InSequence(s2).Times(AtLeast(0));
EXPECT_CALL(mock, doFooAndBar(_,_)).InSequence(s2).Times(AtLeast(1));
EXPECT_CALL(mock, doFooAndBar(_,_)).InSequence(s3).Times(AtLeast(0));
EXPECT_CALL(mock, doFoo(_)).InSequence(s3).Times(AtLeast(1));
EXPECT_CALL(mock, doFooAndBar(_,_)).InSequence(s4).Times(AtLeast(1));
EXPECT_CALL(mock, doFoo(_)).InSequence(s4).Times(AtLeast(0));
obj.executeCall();
}
EXPECT_CALL(API, doFoo(_)).Times(1);
works? – Bioplasmwrapper.foo()
callsdoFoo()
, but I want to test to pass even ifwrapper.foo()
doesn't calldoFoo()
, as long as it callsdoFooAndBar()
instead. – Introduce