How can I pass a C++ lambda function to invoke() as a mock implementation of the function foo()?
I want something like this in my test.
//! lambda function to implement mocked alternative function
auto mock_foo = [](bar_t *bar, int len)
{
bar->a = 10;
bar->b = 11;
bar->x = len;
};
MOCKER(foo).stubs().will(invoke(mock_foo));
I couldn't get that to work with auto, but it does work if explicitly declare a function pointer (but it's more unnecessary boiler plate)
//! lambda function to implement mocked alternative function
void (*mock_foo)(bar_t *bar, int len) = [](bar_t *bar, int len)
{
bar->a = 10;
bar->b = 11;
bar->x = len;
};
MOCKER(foo).stubs().will(invoke(mock_foo));
How can I avoid the unnecessary boiler plate and use auto with my lamda function?
I should also be able to use an anonymous lambda function directly in invoke().
//! lambda function to implement mocked alternative function
MOCKER(foo).stubs().will(invoke(
[](bar_t *bar, int len)
{
bar->a = 10;
bar->b = 11;
bar->x = len;
};
));
How can I pass a C++ lambda function to
invoke()as a mock implementation of the functionfoo()?I want something like this in my test.
I couldn't get that to work with
auto, but it does work if explicitly declare a function pointer (but it's more unnecessary boiler plate)How can I avoid the unnecessary boiler plate and use
autowith my lamda function?I should also be able to use an anonymous lambda function directly in
invoke().