Add support for up to 20 arguments

This commit is contained in:
Mike Long
2013-06-26 07:43:25 +08:00
parent 0f9f1d939d
commit c38a1343a4
8 changed files with 3256 additions and 14 deletions

View File

@@ -4,7 +4,7 @@
$cpp_output = true
$MAX_ARGS = 10
$MAX_ARGS = 20
$DEFAULT_ARG_HISTORY = 50
$MAX_CALL_HISTORY = 50
@@ -357,10 +357,10 @@ def output_macro_counting_shortcuts
#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, 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, N, ...) N
#define PP_RSEQ_N_MINUS2() \
9,8,7,6,5,4,3,2,1,0
19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
#define FAKE_VALUE_FUNC(...) \
@@ -380,10 +380,10 @@ def output_macro_counting_shortcuts
#define PP_NARG_MINUS1_(...) \
PP_ARG_MINUS1_N(__VA_ARGS__)
#define PP_ARG_MINUS1_N(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N
#define PP_ARG_MINUS1_N(_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_MINUS1() \
9,8,7,6,5,4,3,2,1,0
20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
#define FAKE_VOID_FUNC(...) \
FUNC_VOID_(PP_NARG_MINUS1(__VA_ARGS__), __VA_ARGS__)
@@ -410,8 +410,10 @@ end
# lets generate!!
output_c_and_cpp{
define_fff_globals
$MAX_ARGS.times {|arg_count| output_macro(arg_count, false, false)}
$MAX_ARGS.times {|arg_count| output_macro(arg_count, false, true)}
# Create fake generators for 0..MAX_ARGS
num_fake_generators = $MAX_ARGS + 1
num_fake_generators.times {|arg_count| output_macro(arg_count, false, false)}
num_fake_generators.times {|arg_count| output_macro(arg_count, false, true)}
# generate the varargs variants
(2..$MAX_ARGS).each {|arg_count| output_macro(arg_count, true, false)}
(2..$MAX_ARGS).each {|arg_count| output_macro(arg_count, true, true)}

3214
fff.h

File diff suppressed because it is too large Load Diff

View File

@@ -29,7 +29,7 @@ FAKE_VALUE_FUNC(enum MYBOOL, enumfunc0);
FAKE_VALUE_FUNC(struct MyStruct, structfunc0);
FAKE_VOID_FUNC3_VARARG(voidfunc3var, 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);
void setup()
{
@@ -98,6 +98,8 @@ int main()
RUN_TEST(FFFTestSuite, use_vararg_fake_with_different_number_of_arguments);
RUN_TEST(FFFTestSuite, can_capture_upto_20_arguments_correctly);
printf("\n-------------\n");
printf("Complete\n");
printf("-------------\n\n");

View File

@@ -20,6 +20,7 @@ DEFINE_FFF_GLOBALS
FAKE_VOID_FUNC(voidfunc1, int);
FAKE_VOID_FUNC(voidfunc2, char, 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);
class FFFTestSuite: public testing::Test
{

View File

@@ -66,6 +66,8 @@ int main()
RUN_TEST(FFFTestSuite, use_vararg_fake_with_different_number_of_arguments);
RUN_TEST(FFFTestSuite, can_capture_upto_20_arguments_correctly);
printf("\n-------------\n");
printf("Complete\n");
printf("-------------\n\n");

View File

@@ -10,3 +10,4 @@ DEFINE_FAKE_VOID_FUNC3_VARARG(voidfunc3var, const char *, int, ...);
#ifndef __cplusplus
DEFINE_FAKE_VALUE_FUNC3(int, strlcpy3, char* const, const char* const, const size_t);
#endif /* __cplusplus */
DEFINE_FAKE_VOID_FUNC20(voidfunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int);

View File

@@ -11,6 +11,7 @@ void voidfunc1(int);
void voidfunc2(char, char);
long longfunc0();
void voidfunc3var(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);
enum MYBOOL { FALSE = 899, TRUE };
struct MyStruct {
@@ -27,8 +28,10 @@ DECLARE_FAKE_VALUE_FUNC0(long, longfunc0);
DECLARE_FAKE_VALUE_FUNC0(enum MYBOOL, enumfunc0);
DECLARE_FAKE_VALUE_FUNC0(struct MyStruct, structfunc0);
DECLARE_FAKE_VOID_FUNC3_VARARG(voidfunc3var, const char *, int, ...);
DECLARE_FAKE_VOID_FUNC20(voidfunc20, 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);
DECLARE_FAKE_VALUE_FUNC3(int, strlcpy3, char* const, const char* const, const size_t);
#endif /* __cplusplus */
#endif /* GLOBAL_FAKES_H_ */

View File

@@ -247,3 +247,30 @@ TEST_F(FFFTestSuite, use_vararg_fake_with_different_number_of_arguments)
voidfunc3var("3 parameters", 3, 10, 20, 30);
}
#endif /* __cplusplus */
TEST_F(FFFTestSuite, can_capture_upto_20_arguments_correctly)
{
voidfunc20(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19);
ASSERT_EQ(0, voidfunc20_fake.arg0_val);
ASSERT_EQ(1, voidfunc20_fake.arg1_val);
ASSERT_EQ(2, voidfunc20_fake.arg2_val);
ASSERT_EQ(3, voidfunc20_fake.arg3_val);
ASSERT_EQ(4, voidfunc20_fake.arg4_val);
ASSERT_EQ(5, voidfunc20_fake.arg5_val);
ASSERT_EQ(6, voidfunc20_fake.arg6_val);
ASSERT_EQ(7, voidfunc20_fake.arg7_val);
ASSERT_EQ(8, voidfunc20_fake.arg8_val);
ASSERT_EQ(9, voidfunc20_fake.arg9_val);
ASSERT_EQ(10, voidfunc20_fake.arg10_val);
ASSERT_EQ(11, voidfunc20_fake.arg11_val);
ASSERT_EQ(12, voidfunc20_fake.arg12_val);
ASSERT_EQ(13, voidfunc20_fake.arg13_val);
ASSERT_EQ(14, voidfunc20_fake.arg14_val);
ASSERT_EQ(15, voidfunc20_fake.arg15_val);
ASSERT_EQ(16, voidfunc20_fake.arg16_val);
ASSERT_EQ(17, voidfunc20_fake.arg17_val);
ASSERT_EQ(18, voidfunc20_fake.arg18_val);
ASSERT_EQ(19, voidfunc20_fake.arg19_val);
}