'How to use an inputed argument in GMOCK in C++?

I need to use the input parameter of a mock class function.

    EXPECT_CALL(*mockAdd, addThree(Matcher<int>())).WillOnce(RETURN(input_parameter + 4));

Give a function at passes in argument to the function. How do I use the given input in my mock. Given that I do not know what the input_parameter is. I do not want to assign the input_parameter.



Solution 1:[1]

lets try with testing::DoAll and testing::Invoke

EXPECT_CALL(*mockAdd, addThree(Matcher<int>())).WillOnce(DoAll(
    testing::Invoke([](int input_param)
    {
        // do anything here with input_param
    }),Return(input_parameter + 4))
);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 long.kl