-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestMPT.c
185 lines (151 loc) · 4.11 KB
/
TestMPT.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "MacroPowerToys.h"
#define TYPES_LIST int, char, void*
#define NAMES a, b, c
void TEST__MPT_APPEND_LISTS_ITEMS(MPT_APPEND_LISTS_ITEMS( TYPES_LIST, NAMES ))
{
(void)a;
(void)b;
(void)c;
}
void TEST__MPT_APPEND_LISTS_ITEMS__EMPTY(MPT_APPEND_LISTS_ITEMS( ) void)
{
}
void TEST__MPT_CONCAT_LISTS_ITEMS(void)
{
int MPT_CONCAT_LISTS_ITEMS(a, b, 1, 2);
(void)a1;
(void)b2;
//Test empty
int MPT_CONCAT_LISTS_ITEMS( ) c3;
(void)c3;
}
int TEST__MPT_ARGS_COUNT(int a1, int b2)
{
(void)a1;
(void)b2;
return MPT_ARGS_COUNT(a1, b2);
}
int TEST__MPT_ARGS_COUNT__EMPTY(void)
{
return MPT_ARGS_COUNT();
}
void TEST__MPT_COUNT_TO(void)
{
int MPT_COUNT_TO_3_(a, b);
(void)a1b;
(void)a2b;
(void)a3b;
int MPT_COUNT_TO_0_(a, b) c;
(void)c;
}
void TEST__MPT_COUNT_TO_MINUS_1(void)
{
int MPT_COUNT_TO_4_MINUS_1(a, b);
(void)a1b;
(void)a2b;
(void)a3b;
}
void TEST__MPT_GET_LAST_ARG(int a, int b, int c)
{
(void)a;
(void)b;
(void)c;
int last = MPT_GET_LAST_ARG(a, b, c);
assert(last == c);
}
#define STR(x) #x
#define DELAYED_STR(x) MPT_COMPOSE(STR, (x))
void TEST__MPT_ARE_ARGS_EMPTY(void)
{
assert( strcmp( DELAYED_STR( MPT_ARE_ARGS_EMPTY() ), "EMPTY") == 0 );
assert( strcmp( DELAYED_STR( MPT_ARE_ARGS_EMPTY(1) ), "NOT_EMPTY") == 0 );
assert( strcmp( DELAYED_STR( MPT_ARE_ARGS_EMPTY(1, 2) ), "NOT_EMPTY") == 0 );
}
void TEST__UTILS(void)
{
int MPT_CONCAT( ITEM_1, ITEM_2 );
(void)ITEM_1ITEM_2;
MPT_COMPOSE( int, ITEM_2 );
(void) ITEM_2;
int MPT_REMOVE_PARENTHESIS( (ITEM_1, ITEM_3) );
(void)ITEM_1;
(void)ITEM_3;
}
float TEST__REMOVE_PARENTHESIS_IN_LIST( MPT_REMOVE_PARENTHESIS_IN_LIST((int a), (float b), int c) )
{
return a + b + c;
}
void TEST__MPT_OVERLOAD_MACRO(void)
{
#define MACRO_FUNC_0() 0
#define MACRO_FUNC_1( a ) a
#define MACRO_FUNC_2( a, b ) a + b
#define MACRO_FUNC( ... ) MPT_OVERLOAD_MACRO( MACRO_FUNC, __VA_ARGS__ )
assert( MACRO_FUNC() == 0 );
assert( MACRO_FUNC(10) == 10 );
assert( MACRO_FUNC(1, 2) == 3 );
}
void TEST__MPT_PREFIX_SUFFIX_ARGS(void)
{
int MPT_PREFIX_SUFFIX_ARGS( a, b, 1, 2, 3 );
(void)a1b;
(void)a2b;
(void)a3b;
int MPT_PREFIX_SUFFIX_ARGS( a, /* */, 1, 2, 3 );
(void)a1;
(void)a2;
(void)a3;
MPT_PREFIX_SUFFIX_ARGS( a, b );
}
void TEST__MPT_PREPEND_APPEND_ARGS (
MPT_APPEND_LISTS_ITEMS
(
MPT_PREPEND_APPEND_ARGS
(
const,
*,
int,
float,
char
),
a1,
a2,
a3
)
)
{
(void)a1;
(void)a2;
(void)a3;
}
void TEST__MPT_PREPEND_APPEND_ARGS__EMPTY(MPT_PREPEND_APPEND_ARGS(a, b, ) void)
{
}
int main(int argc, char** argv)
{
(void)argc;
(void)argv;
TEST__MPT_APPEND_LISTS_ITEMS(1, 'a', NULL);
TEST__MPT_CONCAT_LISTS_ITEMS();
assert( TEST__MPT_ARGS_COUNT(1, 2) == 2 );
assert( TEST__MPT_ARGS_COUNT__EMPTY() == 0 );
TEST__MPT_COUNT_TO();
TEST__MPT_COUNT_TO_MINUS_1();
TEST__MPT_GET_LAST_ARG(1, 2, 3);
TEST__MPT_ARE_ARGS_EMPTY();
TEST__UTILS();
assert( TEST__REMOVE_PARENTHESIS_IN_LIST(5, 6.f, 2) == 13 );
TEST__MPT_OVERLOAD_MACRO();
TEST__MPT_PREFIX_SUFFIX_ARGS();
int testInt;
float testFloat;
char testChar;
TEST__MPT_PREPEND_APPEND_ARGS(&testInt, &testFloat, &testChar);
TEST__MPT_PREPEND_APPEND_ARGS__EMPTY();
printf("All tests passed\n");
return 0;
}