Skip to content

Commit

Permalink
Fix FAKE_VALUE_FUNC with 20 parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
usr42 committed Jan 16, 2017
1 parent 0ec5f99 commit 190fa67
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 4 deletions.
4 changes: 2 additions & 2 deletions fakegen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(...) \
Expand Down
4 changes: 2 additions & 2 deletions fff.h
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 2 additions & 0 deletions test/fff_test_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions test/fff_test_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
1 change: 1 addition & 0 deletions test/fff_test_global_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions test/global_fakes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 2 additions & 0 deletions test/global_fakes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions test/test_cases.include
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 190fa67

Please sign in to comment.