malsyned / pfstest

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

Replacement for when() that checks argument list lengths (and reads better too maybe) #69

Open malsyned opened 2 years ago

malsyned commented 2 years ago

I did this spike of a couple of new macros and an additional bit of output for automock.py that would make unit tests fail when argument list lengths changed (preventing SIGSEGV) and also may make find-replaces on mocked function names work better, depending on how clever the tool is trying to be.

I think I want to implement it for real in PFSTest.


#define the_call(call) when(mock_wrapper_ ## call)
#define return_from(exp, result) do_return(result, exp)
typedef pfstest_expectation_t *expectation;

#define mock_wrapper_hw_adc_new(a1, a2, a3) mock_hw_adc_new, a1, a2, a3

test(something)
{
    return_from(
        the_call(hw_adc_new(the_int(0),
                           anything(),
                           capture_arg(&adc0_callbacks))),
        the_pointer(adc0));

    return_from(
        the_call(hw_adc_new(the_int(1),
                            anything(),
                            capture_arg(&adc0_callbacks))),
        the_pointer(adc1));

    verify(the_call(hw_adc_new(the_int(1),
                               anything(),
                               capture_arg(&adc0_callbacks))));

    expectation e = the_call(hw_adc_new(the_int(0),
                                        anything(),
                                        capture_arg(&adc0_callbacks)));
    return_from(e, the_pointer(adc0));
}```