Open mattconway1984 opened 1 year ago
Interesting. I'd not considered testing a callback function in this way. It has a certain elegance to it... in that the callback doesn't have to become public in order to test it.
I think this makes sense to be another CMock plugin. It's not a feature that would get used often, but certainly often enough to make it worth building! Thanks for the idea!
I think this also lends itself to pointer arguments which are pointers to a data structure, in some cases I've come across complex structures where the values of all members are not known or required (so the memory compare doesn't apply for this case where just several members need to be compared). This considered, maybe rather than InvokeCallback
something like GetPointerArg
would be better (i.e. capture the function pointer, or pointer to context data etc.), if the test knows its a function pointer it can "get" it and then call it.
There's no sane method to store a function pointer passed to a mocked function, you are forced to use
myFunction_AddCallback(myCallback)
to then grab the function pointer withinmyCallback
. Surely cMock is capable of identifying an argument that itself is a function pointer, and then adding a generated method such asmyFunction_InvokeCallbackArg_<ARGNAME>
.Consider the following header file:
Code Under Test:
Test Code: