malsyned / pfstest

Professional Firmware Services Unit Test Framework
Other
1 stars 0 forks source link

Callbacks on mocks #22

Open malsyned opened 6 years ago

malsyned commented 6 years ago

Sometimes, it's unavoidable that a mock needs to have side-effects.

I think a pretty light-weight and satisfying solution would be something like this:

void my_callback(void *);
some_type *my_callback_data;
do_side_effect(my_callback, my_callback_data, some_expectation);

Where a side-effect function is a void func(void *). In this design, the side-effect function wouldn't get access to any of the arguments to the call it is side-effecting, but it could use the void* to hold a counter if it needs to have a different side-effect on different calls.

malsyned commented 6 years ago

The void* could also be the expectation itself or some other tag used to give different side effects for different expectations.