I have a mock method. When it is called, I'd like it to call another function before calling its normal behavior. Something like :
EXPECT_CALL(*my_obj, MockedMethod(_,_,_,_,_,_))
.WillOnce(DoAll(
Invoke(my_obj, &SomeAdditionalMethodIWantToCall),
Invoke(my_obj, &DefaultBehavior),
));
The only problem is that SomeAdditionalMethodIWantToCall
expects parameter that not at all related to the one provided to MockedMethod
. I'd like to be able to give them but I am struggling with the syntax. I wish there was something like (in fake syntax) :
EXPECT_CALL(*my_obj, MockedMethod(_,_,_,_,_,_))
.WillOnce(DoAll(
Invoke(my_obj, &SomeAdditionalMethodIWantToCall, arg1, arg2, arg3),
Invoke(my_obj, &DefaultBehavior),
));
I have looked for such a thing in the documentation without any success.
In Using a Function or a Functor as an Action, we have :
Invoke(f)
,Invoke(object_pointer, &class::method)
,InvokeWithoutArgs(f)
,InvokeWithoutArgs(object_pointer, &class::method)
which will just forward (or not) the parameter provided to the mocked function when it is called.InvokeArgument<N>(arg1, arg2, ..., argk)
seems to be for calling one of the parameter.
WithArg<N>(a)
andWithArgs<N1, N2, ..., Nk>(a)
seem to be to select which parameters from the original function get forwarded.
I guess I am missing something quite obvious but I am a bit stuck here so any suggestion will help.
InvokeUnrelatedFunction
action, all i get is a compiler error saying thatarg1
is not declared at the point where i try to invoke the action. What could be the cause of that? – Pollinate