Invoke a function on a passed argument

Skip to first unread message


Jan 13, 2017, 11:57:42 AM1/13/17
to Google C++ Mocking Framework

EXPECT_CALL(_http, post(testing::_, testing::_, testing::_)).WillOnce(testing::Invoke(Argument<2>.complete(200, ""));

My idea is to invoke a function complete(int, string) on the 3rd argument passed in post call. 

Could anyone help?

Samuel Benzaquen

Jan 13, 2017, 3:06:17 PM1/13/17
to mrp, Google C++ Mocking Framework
The simplest solution is to use a lambda in the Invoke call.

EXPECT_CALL(_http, post(testing::_, testing::_, testing::_)).WillOnce(testing::Invoke(
    [] (Arg1 arg1, Arg2 arg2, Arg3 arg3) { arg2.complete(200, ""); }));
When the builtin actions don't do what you need, a lambda is a good escape hatch.


You received this message because you are subscribed to the Google Groups "Google C++ Mocking Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
For more options, visit


Jan 17, 2017, 2:12:16 PM1/17/17
to Google C++ Mocking Framework,
Thanks Samuel.

I modified my EXPECT_CALL as :

EXPECT_CALL(_http, post(testing::_, testing::_, testing::_))
[] (const std::shared_ptr <HttpCallback> &callback)
callback->complete(200, "");

and it worked.
Reply all
Reply to author
0 new messages