rollbear/trompeloeil

How to mock a function that operates on the value passed in by reference/pointer

lowkin18 opened this issue · 3 comments

I am unclear on how I can mock a function that takes a pointer and passes back through this pointer.

for example

void get_current(float *current)
{
     *current = 10
}

how do I create the mock expectation for this?
ALLOW_CALL(mockObj, get_current(_))??

I need to be able to set the returned current to some values for passing/failing conditions

Any help would be appreciated.

Assign to it using the positional parameters, for example in a .SIDE_EFFECT(). _1 will be the pointer. *_1 is whatever it points to.

Example: https://godbolt.org/z/WGcqva164

I wouldn't call this frequent, but you're not the first to ask, so I've added an entry to the FAQ.

Thank you very much!