meekrosoft / fff

A testing micro framework for creating function test doubles
Other
766 stars 167 forks source link

Functions with more than 10 parameters #2

Closed siliconarm closed 11 years ago

siliconarm commented 11 years ago

Hi! This is an amazing project, congratulations!

I have some functions with 15 or more parameters (legacy code nightmare) I tried rebuild the header changing $MAX_ARGS in ruby script, but it doesn't work, the new header file includes new macros for support this functions but FAKE_VOID_FUNC mapping doesn't work and i must call FAKE_VOID_FUNC15 direcly.

In other side, support for the ellipsis operator (...) seems great feature!

apattillo commented 11 years ago

I know this post is old, but I had the same issue today. Changing MAX_ARGS to 15 and rebuilding seemed to create the macros (FAKE_VOID_FUNC10 - 14, etc) just fine. The problem for me was with the following macros:

PP_ARG_MINUS2_N
PP_RSEQ_N_MINUS2
PP_ARG_MINUS1_N
PP_RSEQ_N_MINUS1

These macros return the number of parameters (minus 1 for void func, or minus 2 for value func). The value returned is later appended to the FAKE_*_FUNC macro to call the macro for the appropriate number of parameters (FAKE_VOID_FUNC4, for example).

In the generator script, when the macros for the additional parameters are added (beyond 9), the enumerations in these macros also need to be updated. For MAX_ARGS at 15, here are the values I'm using for each macro:

#define PP_ARG_MINUS2_N(returnVal, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, N, ...)   N
#define PP_RSEQ_N_MINUS2()     14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
#define PP_ARG_MINUS1_N(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, N, ...)   N
#define PP_RSEQ_N_MINUS1()     14,13,12,11,10,9,8,7,6,5,4,3,2,1,0

I just changed the fff.h file directly (I did not bother with the generator script, since I'll likely never have to change it again).

Great framework by the way...

meekrosoft commented 11 years ago

Thanks guys, I see that there is a definite need for this. Let me add it this week and get back to you.

meekrosoft commented 11 years ago

Added support for up to 20 arguments today - hope this helps you guys!

apattillo commented 11 years ago

Thanks! Very nice work...