eranpeer / FakeIt

C++ mocking made easy. A simple yet very expressive, headers only library for c++ mocking.
MIT License
1.23k stars 169 forks source link

Is it possible to fake a function that invokes a callback that is one of its parameters? #175

Closed TrueWodzu closed 2 years ago

TrueWodzu commented 5 years ago

Hi,

I wanted to ask, because I haven't seen such example. If I have a function like this:

bool MyFunction(MyCallback callback) { callback(param1, param2); return true; }

Is it possible to fake it in a way that it will call the callback which is inside of it?

Thanks.

alibabashack commented 4 years ago

Yes, see https://github.com/eranpeer/FakeIt/wiki/Quickstart You can use the lambda expression forms:

When(Method(mock,foo)).Do([](int a)->int{ ... });
When(Method(mock,foo)).AlwaysDo([](int a)->int{ ... });