| 1 |
#!perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
print <<'EOF'; |
| 7 |
|
| 8 |
#ifndef MOCK_TABLE_HEADER |
| 9 |
#define MOCK_TABLE_HEADER |
| 10 |
|
| 11 |
/* DO NOT EDIT THIS FILE */ |
| 12 |
/* auto-generated by build_mock_table.pl */ |
| 13 |
|
| 14 |
#define MOCK_VA_NUM_ARGS(...) MOCK_VA_NUM_ARGS_IMPL_((__VA_ARGS__, 63, 62, 61, 60, \ |
| 15 |
59, 58, 57, 56, 55, 54, 53, 52, 51, 50, \ |
| 16 |
49, 48, 47, 46, 45, 44, 43, 42, 41, 40, \ |
| 17 |
39, 38, 37, 36, 35, 34, 33, 32, 31, 30, \ |
| 18 |
29, 28, 27, 26, 25, 24, 23, 22, 21, 20, \ |
| 19 |
19, 18, 17, 16, 15, 14, 13, 12, 11, 10, \ |
| 20 |
9, 8, 7, 6, 5, 4, 3, 2, 1)) |
| 21 |
#define MOCK_VA_NUM_ARGS_IMPL_(tuple) MOCK_VA_NUM_ARGS_IMPL tuple |
| 22 |
|
| 23 |
#define MOCK_VA_NUM_ARGS_IMPL( \ |
| 24 |
_1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \ |
| 25 |
_11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \ |
| 26 |
_21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \ |
| 27 |
_31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \ |
| 28 |
_41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \ |
| 29 |
_51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \ |
| 30 |
_61,_62,_63,N,...) N |
| 31 |
|
| 32 |
|
| 33 |
#define MOCK_macro_dispatcher(func, ...) MOCK_macro_dispatcher_(func, MOCK_VA_NUM_ARGS(__VA_ARGS__)) |
| 34 |
|
| 35 |
// the three levels of indirection are a work-around for broken variadic macro support in Visual C++ |
| 36 |
#define MOCK_macro_dispatcher_(func, nargs) MOCK_macro_dispatcher__(func, nargs) |
| 37 |
#define MOCK_macro_dispatcher__(func, nargs) MOCK_macro_dispatcher___(func, nargs) |
| 38 |
#define MOCK_macro_dispatcher___(func, nargs) func ## nargs |
| 39 |
|
| 40 |
#define PP_NARG(...) MOCK_macro_dispatcher(mock, __VA_ARGS__) |
| 41 |
|
| 42 |
//mock1 works for 1 or 0 |
| 43 |
#define mock1(test_reporter, function_name, mock_file, mock_line, arguments_string, ...)\ |
| 44 |
mock_(test_reporter, function_name, mock_file, mock_line, arguments_string, __VA_ARGS__) |
| 45 |
|
| 46 |
EOF |
| 47 |
|
| 48 |
my @macros; |
| 49 |
my @mocks = ("mock_", "mock_"); |
| 50 |
|
| 51 |
for my $i (2 .. 63) { |
| 52 |
push(@mocks, sprintf("mock%d", $i)); |
| 53 |
push(@macros, define_mock($i)); |
| 54 |
} |
| 55 |
|
| 56 |
my @reverse_mocks = reverse(@mocks); |
| 57 |
|
| 58 |
my @chunk; |
| 59 |
print "#define PP_RSEQ_N() \\\n"; |
| 60 |
while (@chunk = splice(@reverse_mocks, 0, 10)) { |
| 61 |
print "\t"; |
| 62 |
print join(", ", @chunk); |
| 63 |
if (@reverse_mocks) { |
| 64 |
print ",\\\n"; |
| 65 |
} |
| 66 |
else { |
| 67 |
print "\n"; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
print "\n"; |
| 72 |
print join("\n", @macros); |
| 73 |
print "\n"; |
| 74 |
print "#endif /* MOCK_TABLE_HEADER */\n"; |
| 75 |
|
| 76 |
sub define_mock { |
| 77 |
my ($num_args) = @_; |
| 78 |
|
| 79 |
my @args; |
| 80 |
my $i; |
| 81 |
for ($i = 0; $i < $num_args; $i++) { |
| 82 |
push(@args, sprintf "arg%d", $i); |
| 83 |
} |
| 84 |
|
| 85 |
my $macro = sprintf("#define mock%d", $num_args); |
| 86 |
$macro .= "(test_reporter, function_name, mock_file, mock_line, arguments_string, "; |
| 87 |
$macro .= join(", ", @args); |
| 88 |
$macro .= ")\\\n"; |
| 89 |
$macro .= " mock_(test_reporter, function_name, mock_file, mock_line, arguments_string, "; |
| 90 |
$macro .= join(", ", (map "(intptr_t) $_", @args)); |
| 91 |
$macro .= ")\n"; |
| 92 |
|
| 93 |
return $macro; |
| 94 |
} |
| 95 |
|