I have this code in C++11
struct Callbacks
{
using StartFunc = std::function<bool()>;
StartFunc start;
using FinishFunc = std::function<bool(int status)>;
FinishFunc finish;
};
// this registers the callbacks and calls the 2 functions
int do_something(const Callbacks& callbacks)
{
...
callbacks.start(true);
...
callbacks.finish(true);
}
And I want to mock the callbacks, to make sure they are called properly. I read How to use gmock to mock up a std::function? and I did something like this
MockFunction<Callbacks::start> startFuncMock;
MockFunction<Callbacks::stop> finishFuncMock;
but when I call my function
Callbacks cb;
cb.start = startFuncMock; // this does not compile
do_something(cb);
How can I make it work? thanks