Debian Codegraph @

src/vendor/azure-uamqp-c/deps/azure-macro-utils-c/tests/mu_eat_empty_args_test.c

raw
1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4 #include "test_helper.h"
5
6 #include "azure_macro_utils/macro_utils.h"
7
8 #include "mu_eat_empty_args_test.h"
9
10 /*this is both a "does it compile"? and a "does it produce the right values?" test*/
11 /*this file wants to test just the MU_EAT_EMPTY_ARGS feature*/
12
13 #define EMPTY_MACRO
14
15 /*the below line is expected to stop the compiler if it expands to anything... sort of*/
16 MU_EAT_EMPTY_ARGS()
17
18 /*the below line is expected to stop the compiler if it expands to anything... sort of*/
19 MU_EAT_EMPTY_ARGS(EMPTY_MACRO)
20
21 /*the below line is expected to stop the compiler if it expands to anything... sort of*/
22 MU_EAT_EMPTY_ARGS(,)
23
24 /*the below line is expected to stop the compiler if it expands to anything... sort of*/
25 MU_EAT_EMPTY_ARGS(EMPTY_MACRO, )
26
27 /*the below line is expected to stop the compiler if it expands to anything... sort of*/
28 MU_EAT_EMPTY_ARGS(, EMPTY_MACRO)
29
30 /*the below line is expected to stop the compiler if it expands to anything... sort of*/
31 MU_EAT_EMPTY_ARGS(EMPTY_MACRO, EMPTY_MACRO )
32
33 /*the below line is expected to stop the compiler if it expands to anything... sort of*/
34 MU_EAT_EMPTY_ARGS(EMPTY_MACRO, EMPTY_MACRO, EMPTY_MACRO)
35
36 /*the below line is expected to stop the compiler if it expands to anything... sort of*/
37 MU_EAT_EMPTY_ARGS(EMPTY_MACRO, EMPTY_MACRO, )
38
39 /*the below line is expected to stop the compiler if it expands to anything... sort of*/
40 MU_EAT_EMPTY_ARGS(EMPTY_MACRO, , EMPTY_MACRO)
41
42 /*the below line is expected to stop the compiler if it expands to anything... sort of*/
43 MU_EAT_EMPTY_ARGS(, EMPTY_MACRO, EMPTY_MACRO)
44
45 /*the below line is expected to stop the compiler if it expands to anything... sort of*/
46 MU_EAT_EMPTY_ARGS(, , EMPTY_MACRO)
47
48 /*the below line is expected to stop the compiler if it expands to anything... sort of*/
49 MU_EAT_EMPTY_ARGS(, EMPTY_MACRO, )
50
51 /*the below line is expected to stop the compiler if it expands to anything... sort of*/
52 MU_EAT_EMPTY_ARGS(EMPTY_MACRO, , )
53
54 /*the below line is expected to stop the compiler if it expands to anything... sort of*/
55 MU_EAT_EMPTY_ARGS(, , )
56
57
58 int run_mu_eat_empty_args_test(void)
59 {
60 int tester = 0;
61
62 tester = MU_EAT_EMPTY_ARGS() + tester; /*so this doesn't expand to anything, but should still compile, result = + result is perfectly valid C code*/ /*it could also expand to "0" :(*/
63 POOR_MANS_ASSERT(tester == 0);
64
65 tester = MU_EAT_EMPTY_ARGS(1); /*there's nothing to eat from "1", so it expands to "1"*/
66 POOR_MANS_ASSERT(tester == 1);
67
68 /*see that it eats / doesn't eat from 2 arguments*/
69
70 { /*scope because of repetitive naure of tests and copy&paste*/
71 int testerArray[] = { MU_EAT_EMPTY_ARGS(42 + 1,) }; /*eats 1 empty argument, expands to "42+1"*/
72
73 POOR_MANS_ASSERT(1 == (sizeof(testerArray) / sizeof(testerArray[0])));
74 POOR_MANS_ASSERT(42 + 1 == testerArray[0]);
75 }
76
77 { /*scope because of repetitive naure of tests and copy&paste*/
78 int testerArray[] = { MU_EAT_EMPTY_ARGS(,42 + 2) }; /*eats 1 empty argument, expands to "42+2"*/
79
80 POOR_MANS_ASSERT(1 == (sizeof(testerArray) / sizeof(testerArray[0])));
81 POOR_MANS_ASSERT(42 + 2 == testerArray[0]);
82 }
83
84 {
85 int testerArray[] = { MU_EAT_EMPTY_ARGS(42 + 3 ,42 + 4) }; /*doesn't eat anything*/
86
87 POOR_MANS_ASSERT(2 == (sizeof(testerArray) / sizeof(testerArray[0])));
88 POOR_MANS_ASSERT(testerArray[0] == 42 + 3);
89 POOR_MANS_ASSERT(testerArray[1] == 42 + 4);
90 }
91
92 /*see that it eats / doesn't eat from 3 arguments*/
93 {
94 int testerArray[] = { MU_EAT_EMPTY_ARGS(42 + 5 ,42 + 6, 42 + 7) }; /*doesn't eat anything*/
95
96 POOR_MANS_ASSERT(3 == (sizeof(testerArray) / sizeof(testerArray[0])));
97 POOR_MANS_ASSERT(testerArray[0] == 42 + 5);
98 POOR_MANS_ASSERT(testerArray[1] == 42 + 6);
99 POOR_MANS_ASSERT(testerArray[2] == 42 + 7);
100 }
101
102 /*see that it eats / doesn't eat from 3 arguments*/
103 {
104 int testerArray[] = { MU_EAT_EMPTY_ARGS( ,42 + 6, 42 + 7) }; /*eats first*/
105
106 POOR_MANS_ASSERT(2 == (sizeof(testerArray) / sizeof(testerArray[0])));
107 POOR_MANS_ASSERT(testerArray[0] == 42 + 6);
108 POOR_MANS_ASSERT(testerArray[1] == 42 + 7);
109 }
110
111 /*see that it eats / doesn't eat from 3 arguments*/
112 {
113 int testerArray[] = { MU_EAT_EMPTY_ARGS(42 + 5 ,, 42 + 7) }; /*eat middle*/
114
115 POOR_MANS_ASSERT(2 == (sizeof(testerArray) / sizeof(testerArray[0])));
116 POOR_MANS_ASSERT(testerArray[0] == 42 + 5);
117 POOR_MANS_ASSERT(testerArray[1] == 42 + 7);
118 }
119
120 /*see that it eats / doesn't eat from 3 arguments*/
121 {
122 int testerArray[] = { MU_EAT_EMPTY_ARGS(42 + 5 ,42 + 6, ) }; /*eats last*/
123
124 POOR_MANS_ASSERT(2 == (sizeof(testerArray) / sizeof(testerArray[0])));
125 POOR_MANS_ASSERT(testerArray[0] == 42 + 5);
126 POOR_MANS_ASSERT(testerArray[1] == 42 + 6);
127 }
128
129 /*see that it eats / doesn't eat from 3 arguments*/
130 {
131 int testerArray[] = { MU_EAT_EMPTY_ARGS(42 + 5 , , ) }; /*eats middle and last*/
132
133 POOR_MANS_ASSERT(1 == (sizeof(testerArray) / sizeof(testerArray[0])));
134 POOR_MANS_ASSERT(testerArray[0] == 42 + 5);
135 }
136
137 /*see that it eats / doesn't eat from 3 arguments*/
138 {
139 int testerArray[] = { MU_EAT_EMPTY_ARGS(,42 + 6, ) }; /*eats first and last*/
140
141 POOR_MANS_ASSERT(1 == (sizeof(testerArray) / sizeof(testerArray[0])));
142 POOR_MANS_ASSERT(testerArray[0] == 42 + 6);
143 }
144
145 /*see that it eats / doesn't eat from 3 arguments*/
146 {
147 int testerArray[] = { MU_EAT_EMPTY_ARGS(, , 42 + 7) }; /*eats first and middle*/
148
149 POOR_MANS_ASSERT(1 == (sizeof(testerArray) / sizeof(testerArray[0])));
150 POOR_MANS_ASSERT(testerArray[0] == 42 + 7);
151 }
152
153
154 /*see that it eats / doesn't eat from 10 arguments*/
155 {
156 int testerArray[] = { MU_EAT_EMPTY_ARGS (1,2,3,4,5,6,7,8,9,10)}; /*eats nothing*/
157
158 POOR_MANS_ASSERT(10 == (sizeof(testerArray) / sizeof(testerArray[0])));
159 POOR_MANS_ASSERT(testerArray[0] == 1);
160 POOR_MANS_ASSERT(testerArray[1] == 2);
161 POOR_MANS_ASSERT(testerArray[2] == 3);
162 POOR_MANS_ASSERT(testerArray[3] == 4);
163 POOR_MANS_ASSERT(testerArray[4] == 5);
164 POOR_MANS_ASSERT(testerArray[5] == 6);
165 POOR_MANS_ASSERT(testerArray[6] == 7);
166 POOR_MANS_ASSERT(testerArray[7] == 8);
167 POOR_MANS_ASSERT(testerArray[8] == 9);
168 POOR_MANS_ASSERT(testerArray[9] == 10);
169 }
170
171 /*see that it eats / doesn't eat from 10 arguments*/
172 {
173 int testerArray[] = { MU_EAT_EMPTY_ARGS(1,2, ,4,5,6,7,8,9,10) }; /*eats 3*/
174
175 POOR_MANS_ASSERT(9 == (sizeof(testerArray) / sizeof(testerArray[0])));
176 POOR_MANS_ASSERT(testerArray[0] == 1);
177 POOR_MANS_ASSERT(testerArray[1] == 2);
178 POOR_MANS_ASSERT(testerArray[2] == 4);
179 POOR_MANS_ASSERT(testerArray[3] == 5);
180 POOR_MANS_ASSERT(testerArray[4] == 6);
181 POOR_MANS_ASSERT(testerArray[5] == 7);
182 POOR_MANS_ASSERT(testerArray[6] == 8);
183 POOR_MANS_ASSERT(testerArray[7] == 9);
184 POOR_MANS_ASSERT(testerArray[8] == 10);
185 }
186
187 return 0;
188 }