I have a mock function:
MOCK_METHOD4(my_func, int(double, double, void* (*cb) (int), int p1));
I want to invoke 2nd (0-based) argument of above function with the 3rd argument as parameter, i.e., invoke "cb" function with "p1" as parameter. How can I do that?
I can invoke "cb" with some custom value using InvokeArgument:
ON_CALL(mockObj, my_func(_, _, _, _)).
WillByDefault(DoAll(
IgnoreResult(InvokeArgument<2>(10)),
Return(0)));
But I want to invoke it with an actual parameter passed to the same mocked function call.
EXPECT_CALL not only defines the behavior, but also sets an expectation that the method will be called with the given arguments, for the given number of times (and in the given order when you specify the order too).
first, you use some simple macros to describe the interface you want to mock, and they will expand to the implementation of your mock class; next, you create some mock objects and specify its expectations and behavior using an intuitive syntax; then you exercise code that uses the mock objects.
You can define an ACTION
to invoke your callback. Something like below:
ACTION(CallCb) {
arg2(arg3);
}
...
ON_CALL(*mockObj, my_func(_, _, _, _))
.WillByDefault(
DoAll(CallCb(),
Return(0)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With