diff --git a/fakegen.rb b/fakegen.rb index 1e758fa..2b1f842 100644 --- a/fakegen.rb +++ b/fakegen.rb @@ -434,10 +434,10 @@ def output_macro_counting_shortcuts #define PP_NARG_MINUS2_(...) \ PP_ARG_MINUS2_N(__VA_ARGS__) -#define PP_ARG_MINUS2_N(returnVal, #{generate_arg_sequence($MAX_ARGS - 1, '_', false, ", ")}, N, ...) N +#define PP_ARG_MINUS2_N(returnVal, #{generate_arg_sequence($MAX_ARGS, '_', false, ", ")}, N, ...) N #define PP_RSEQ_N_MINUS2() \ - #{generate_arg_sequence($MAX_ARGS - 1, '', true, ',')} + #{generate_arg_sequence($MAX_ARGS, '', true, ',')} #define PP_NARG_MINUS1(...) \ diff --git a/fff.h b/fff.h index af69416..85db589 100644 --- a/fff.h +++ b/fff.h @@ -5816,9 +5816,9 @@ FFF_END_EXTERN_C \ #define PP_NARG_MINUS2_(...) PP_ARG_MINUS2_N(__VA_ARGS__) -#define PP_ARG_MINUS2_N(returnVal, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, N, ...) N +#define PP_ARG_MINUS2_N(returnVal, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, N, ...) N -#define PP_RSEQ_N_MINUS2() 19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 +#define PP_RSEQ_N_MINUS2() 20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 #define PP_NARG_MINUS1(...) PP_NARG_MINUS1_(__VA_ARGS__, PP_RSEQ_N_MINUS1()) diff --git a/test/fff_test_c.c b/test/fff_test_c.c index 7ea1960..6763439 100644 --- a/test/fff_test_c.c +++ b/test/fff_test_c.c @@ -32,6 +32,7 @@ FAKE_VOID_FUNC_VARARG(voidfunc3var, char *, int, ...); FAKE_VALUE_FUNC_VARARG(int, valuefunc3var, char *, int, ...); FAKE_VALUE_FUNC(int, strlcpy3, char* const, const char* const, const size_t); FAKE_VOID_FUNC(voidfunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); +FAKE_VALUE_FUNC(int, valuefunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); void setup() { @@ -104,6 +105,7 @@ int main() RUN_TEST(FFFTestSuite, use_value_vararg_fake_with_different_number_of_arguments); RUN_TEST(FFFTestSuite, can_capture_upto_20_arguments_correctly); + RUN_TEST(FFFTestSuite, value_func_can_capture_upto_20_arguments_correctly); printf("\n-------------\n"); printf("Complete\n"); diff --git a/test/fff_test_cpp.cpp b/test/fff_test_cpp.cpp index 208ff51..4a51b11 100644 --- a/test/fff_test_cpp.cpp +++ b/test/fff_test_cpp.cpp @@ -22,6 +22,7 @@ FAKE_VOID_FUNC(voidfunc2, char, char); FAKE_VOID_FUNC(voidfunc1outparam, char *); FAKE_VALUE_FUNC(long, longfunc0); FAKE_VOID_FUNC(voidfunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); +FAKE_VALUE_FUNC(int, valuefunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); class FFFTestSuite: public testing::Test { diff --git a/test/fff_test_global_c.c b/test/fff_test_global_c.c index 268693a..fb8ee57 100644 --- a/test/fff_test_global_c.c +++ b/test/fff_test_global_c.c @@ -70,6 +70,7 @@ int main() RUN_TEST(FFFTestSuite, use_value_vararg_fake_with_different_number_of_arguments); RUN_TEST(FFFTestSuite, can_capture_upto_20_arguments_correctly); + RUN_TEST(FFFTestSuite, value_func_can_capture_upto_20_arguments_correctly); printf("\n-------------\n"); printf("Complete\n"); diff --git a/test/global_fakes.c b/test/global_fakes.c index 0acfe05..d418761 100644 --- a/test/global_fakes.c +++ b/test/global_fakes.c @@ -14,3 +14,4 @@ DEFINE_FAKE_VALUE_FUNC_VARARG(int, valuefunc3var, const char *, int, ...); DEFINE_FAKE_VALUE_FUNC(int, strlcpy3, char* const, const char* const, const size_t); #endif /* __cplusplus */ DEFINE_FAKE_VOID_FUNC(voidfunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); +DEFINE_FAKE_VALUE_FUNC(int, valuefunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); diff --git a/test/global_fakes.h b/test/global_fakes.h index 57afb4d..3d02d52 100644 --- a/test/global_fakes.h +++ b/test/global_fakes.h @@ -14,6 +14,7 @@ long longfunc0(); void voidfunc3var(const char *fmt, int argc, ...); int valuefunc3var(const char *fmt, int argc, ...); void voidfunc20(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); +int valuefunc20(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); enum MYBOOL { FALSE = 899, TRUE }; struct MyStruct { @@ -33,6 +34,7 @@ DECLARE_FAKE_VALUE_FUNC(struct MyStruct, structfunc0); DECLARE_FAKE_VOID_FUNC_VARARG(voidfunc3var, const char *, int, ...); DECLARE_FAKE_VALUE_FUNC_VARARG(int, valuefunc3var, const char *, int, ...); DECLARE_FAKE_VOID_FUNC(voidfunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); +DECLARE_FAKE_VALUE_FUNC(int, valuefunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); #ifndef __cplusplus int strlcpy3(char* const, const char* const, const size_t); diff --git a/test/test_cases.include b/test/test_cases.include index b192c96..9ceed49 100644 --- a/test/test_cases.include +++ b/test/test_cases.include @@ -335,4 +335,32 @@ TEST_F(FFFTestSuite, can_capture_upto_20_arguments_correctly) ASSERT_EQ(19, voidfunc20_fake.arg19_val); } +TEST_F(FFFTestSuite, value_func_can_capture_upto_20_arguments_correctly) +{ + valuefunc20_fake.return_val = 42; + + int return_val = valuefunc20(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19); + + ASSERT_EQ(42, return_val); + ASSERT_EQ(0, valuefunc20_fake.arg0_val); + ASSERT_EQ(1, valuefunc20_fake.arg1_val); + ASSERT_EQ(2, valuefunc20_fake.arg2_val); + ASSERT_EQ(3, valuefunc20_fake.arg3_val); + ASSERT_EQ(4, valuefunc20_fake.arg4_val); + ASSERT_EQ(5, valuefunc20_fake.arg5_val); + ASSERT_EQ(6, valuefunc20_fake.arg6_val); + ASSERT_EQ(7, valuefunc20_fake.arg7_val); + ASSERT_EQ(8, valuefunc20_fake.arg8_val); + ASSERT_EQ(9, valuefunc20_fake.arg9_val); + ASSERT_EQ(10, valuefunc20_fake.arg10_val); + ASSERT_EQ(11, valuefunc20_fake.arg11_val); + ASSERT_EQ(12, valuefunc20_fake.arg12_val); + ASSERT_EQ(13, valuefunc20_fake.arg13_val); + ASSERT_EQ(14, valuefunc20_fake.arg14_val); + ASSERT_EQ(15, valuefunc20_fake.arg15_val); + ASSERT_EQ(16, valuefunc20_fake.arg16_val); + ASSERT_EQ(17, valuefunc20_fake.arg17_val); + ASSERT_EQ(18, valuefunc20_fake.arg18_val); + ASSERT_EQ(19, valuefunc20_fake.arg19_val); +}