fff: mocking a value returned by reference from another module

81 views Asked by At

Working with the Fake Function Framework, I have this bit of code (paraphrased):

void sched_step(void) {
    event_t event;
    int status;

    status = queue_fetch(&event);
    if (status == OK) {
        do_something_with(&event);
        ...
    }
}

When writing unit tests for the sched module, I want to control what queue_fetch() returns by reference, that is, I want to fake the value of event without dragging in the entire queue module.

I haven't been able to wrap my head around how to do this in fff. Can someone show me the way?

1

There are 1 answers

0
mikelong On

Perhaps you can find some inspiration in the examples for mocking an external dependency: https://github.com/meekrosoft/fff/blob/master/examples/embedded_ui/src/UI_test_ansic.c

And the readme contains some help on how to return a reference from a fake.