meekrosoft / fff

A testing micro framework for creating function test doubles
Other
777 stars 168 forks source link

(Feature request) Change call_history type to a function pointer #21

Closed dmcminniwc closed 7 years ago

dmcminniwc commented 7 years ago

Could fff be changed so that instead of fff_globals_t.call_history being an array of void pointers it is an array of function pointers? The reason for asking is that I am using fff in an embedded project which uses IAR for msp430, although I think you'd come across this with other compilers/architectures too. The particular processor architecture I'm using can address 20 bits but the data pointer size varies (16/16 or 32 bits) with the model selected (Small/Medium or Large respectively) in the project options whereas the function pointer size is always 32 bits. The function pointers in the call history get truncated in Small/Medium models because void * is treated as a data pointer and therefore its size changes with the model.

Changing from void *call_history[FFF_CALL_HISTORY_LEN]; to something like:

typedef void (*fft_function_t)(void);

typedef struct { 
    fff_function_t call_history[FFF_CALL_HISTORY_LEN];

would allow this to work correctly for this scenario and maintain compliance with C99 (section 6.3.2.3, paragraph 8 - I assume also other versions of the standard but haven't checked). The user would then cast their mock functions to (fff_function_t) when comparing to the call history elements.

Also the definition of REGISTER_CALL(function) would have to change to e.g.

#define REGISTER_CALL(function) \
   if(fff.call_history_idx < FFF_CALL_HISTORY_LEN) \
       fff.call_history[fff.call_history_idx++] = (fff_function_t)function;
usr42 commented 7 years ago

Hi dmcminniwc,

I created a branch to address your issue: https://github.com/usr42/fff/tree/issue21

Can you check if this is working for you? If yes I'll open a pull request to merge it to meekrosoft's repository.

Best regards, Balthasar

dmcminniwc commented 7 years ago

Yes, that is working for me.

usr42 commented 7 years ago

My pull request to fix for issue 13 is not merged yet. So I created a branch fixing your issue (13) without the changes to fix issue 13: https://github.com/usr42/fff/tree/issue21_without_issue13

I'll open a pull request for the cleaned branch.

meekrosoft commented 7 years ago

Thanks for the suggestion @dmcminniwc - this was an interesting use case.