|
117 | 117 | CHECK_FALSE_LOCATION(condition, "CHECK_FALSE", #condition, text, __FILE__, __LINE__)
|
118 | 118 |
|
119 | 119 | #define CHECK_TRUE_LOCATION(condition, checkString, conditionString, text, file, line)\
|
120 |
| - { UtestShell::getCurrent()->assertTrue((condition), checkString, conditionString, text, file, line); } |
| 120 | + do { UtestShell::getCurrent()->assertTrue((condition), checkString, conditionString, text, file, line); } while(0) |
121 | 121 |
|
122 | 122 | #define CHECK_FALSE_LOCATION(condition, checkString, conditionString, text, file, line)\
|
123 |
| - { UtestShell::getCurrent()->assertTrue(!(condition), checkString, conditionString, text, file, line); } |
| 123 | + do { UtestShell::getCurrent()->assertTrue(!(condition), checkString, conditionString, text, file, line); } while(0) |
124 | 124 |
|
125 | 125 | //This check needs the operator!=(), and a StringFrom(YourType) function
|
126 | 126 | #define CHECK_EQUAL(expected, actual)\
|
|
130 | 130 | CHECK_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__)
|
131 | 131 |
|
132 | 132 | #define CHECK_EQUAL_LOCATION(expected, actual, text, file, line)\
|
133 |
| - { if ((expected) != (actual)) { \ |
| 133 | + do { if ((expected) != (actual)) { \ |
134 | 134 | if ((actual) != (actual)) \
|
135 | 135 | UtestShell::getCurrent()->print("WARNING:\n\tThe \"Actual Parameter\" parameter is evaluated multiple times resulting in different values.\n\tThus the value in the error message is probably incorrect.", file, line); \
|
136 | 136 | if ((expected) != (expected)) \
|
|
140 | 140 | else \
|
141 | 141 | { \
|
142 | 142 | UtestShell::getCurrent()->assertLongsEqual((long)0, (long)0, NULLPTR, file, line); \
|
143 |
| - } } |
| 143 | + } } while(0) |
144 | 144 |
|
145 | 145 | #define CHECK_COMPARE(first, relop, second)\
|
146 | 146 | CHECK_COMPARE_TEXT(first, relop, second, NULLPTR)
|
|
149 | 149 | CHECK_COMPARE_LOCATION(first, relop, second, text, __FILE__, __LINE__)
|
150 | 150 |
|
151 | 151 | #define CHECK_COMPARE_LOCATION(first, relop, second, text, file, line)\
|
152 |
| - { SimpleString conditionString;\ |
153 |
| - conditionString += StringFrom(first); conditionString += " ";\ |
154 |
| - conditionString += #relop; conditionString += " ";\ |
155 |
| - conditionString += StringFrom(second);\ |
156 |
| - UtestShell::getCurrent()->assertCompare((first) relop (second), "CHECK_COMPARE", conditionString.asCharString(), text, __FILE__, __LINE__);\ |
157 |
| - } |
| 152 | + do { SimpleString conditionString;\ |
| 153 | + conditionString += StringFrom(first); conditionString += " ";\ |
| 154 | + conditionString += #relop; conditionString += " ";\ |
| 155 | + conditionString += StringFrom(second);\ |
| 156 | + UtestShell::getCurrent()->assertCompare((first) relop (second), "CHECK_COMPARE", conditionString.asCharString(), text, __FILE__, __LINE__);\ |
| 157 | + } while(0) |
158 | 158 |
|
159 | 159 | //This check checks for char* string equality using strcmp.
|
160 | 160 | //This makes up for the fact that CHECK_EQUAL only compares the pointers to char*'s
|
|
165 | 165 | STRCMP_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__)
|
166 | 166 |
|
167 | 167 | #define STRCMP_EQUAL_LOCATION(expected, actual, text, file, line)\
|
168 |
| - { UtestShell::getCurrent()->assertCstrEqual(expected, actual, text, file, line); } |
| 168 | + do { UtestShell::getCurrent()->assertCstrEqual(expected, actual, text, file, line); } while(0) |
169 | 169 |
|
170 | 170 | #define STRNCMP_EQUAL(expected, actual, length)\
|
171 | 171 | STRNCMP_EQUAL_LOCATION(expected, actual, length, NULLPTR, __FILE__, __LINE__)
|
|
174 | 174 | STRNCMP_EQUAL_LOCATION(expected, actual, length, text, __FILE__, __LINE__)
|
175 | 175 |
|
176 | 176 | #define STRNCMP_EQUAL_LOCATION(expected, actual, length, text, file, line)\
|
177 |
| - { UtestShell::getCurrent()->assertCstrNEqual(expected, actual, length, text, file, line); } |
| 177 | + do { UtestShell::getCurrent()->assertCstrNEqual(expected, actual, length, text, file, line); } while(0) |
178 | 178 |
|
179 | 179 | #define STRCMP_NOCASE_EQUAL(expected, actual)\
|
180 | 180 | STRCMP_NOCASE_EQUAL_LOCATION(expected, actual, NULLPTR, __FILE__, __LINE__)
|
|
183 | 183 | STRCMP_NOCASE_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__)
|
184 | 184 |
|
185 | 185 | #define STRCMP_NOCASE_EQUAL_LOCATION(expected, actual, text, file, line)\
|
186 |
| - { UtestShell::getCurrent()->assertCstrNoCaseEqual(expected, actual, text, file, line); } |
| 186 | + do { UtestShell::getCurrent()->assertCstrNoCaseEqual(expected, actual, text, file, line); } while(0) |
187 | 187 |
|
188 | 188 | #define STRCMP_CONTAINS(expected, actual)\
|
189 | 189 | STRCMP_CONTAINS_LOCATION(expected, actual, NULLPTR, __FILE__, __LINE__)
|
|
192 | 192 | STRCMP_CONTAINS_LOCATION(expected, actual, text, __FILE__, __LINE__)
|
193 | 193 |
|
194 | 194 | #define STRCMP_CONTAINS_LOCATION(expected, actual, text, file, line)\
|
195 |
| - { UtestShell::getCurrent()->assertCstrContains(expected, actual, text, file, line); } |
| 195 | + do { UtestShell::getCurrent()->assertCstrContains(expected, actual, text, file, line); } while(0) |
196 | 196 |
|
197 | 197 | #define STRCMP_NOCASE_CONTAINS(expected, actual)\
|
198 | 198 | STRCMP_NOCASE_CONTAINS_LOCATION(expected, actual, NULLPTR, __FILE__, __LINE__)
|
|
201 | 201 | STRCMP_NOCASE_CONTAINS_LOCATION(expected, actual, text, __FILE__, __LINE__)
|
202 | 202 |
|
203 | 203 | #define STRCMP_NOCASE_CONTAINS_LOCATION(expected, actual, text, file, line)\
|
204 |
| - { UtestShell::getCurrent()->assertCstrNoCaseContains(expected, actual, text, file, line); } |
| 204 | + do { UtestShell::getCurrent()->assertCstrNoCaseContains(expected, actual, text, file, line); } while(0) |
205 | 205 |
|
206 | 206 | //Check two long integers for equality
|
207 | 207 | #define LONGS_EQUAL(expected, actual)\
|
|
217 | 217 | UNSIGNED_LONGS_EQUAL_LOCATION((expected), (actual), text, __FILE__, __LINE__)
|
218 | 218 |
|
219 | 219 | #define LONGS_EQUAL_LOCATION(expected, actual, text, file, line)\
|
220 |
| - { UtestShell::getCurrent()->assertLongsEqual((long)expected, (long)actual, text, file, line); } |
| 220 | + do { UtestShell::getCurrent()->assertLongsEqual((long)expected, (long)actual, text, file, line); } while(0) |
221 | 221 |
|
222 | 222 | #define UNSIGNED_LONGS_EQUAL_LOCATION(expected, actual, text, file, line)\
|
223 |
| - { UtestShell::getCurrent()->assertUnsignedLongsEqual((unsigned long)expected, (unsigned long)actual, text, file, line); } |
| 223 | + do { UtestShell::getCurrent()->assertUnsignedLongsEqual((unsigned long)expected, (unsigned long)actual, text, file, line); } while(0) |
224 | 224 |
|
225 | 225 | #define LONGLONGS_EQUAL(expected, actual)\
|
226 | 226 | LONGLONGS_EQUAL_LOCATION(expected, actual, NULLPTR, __FILE__, __LINE__)
|
|
235 | 235 | UNSIGNED_LONGLONGS_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__)
|
236 | 236 |
|
237 | 237 | #define LONGLONGS_EQUAL_LOCATION(expected, actual, text, file, line)\
|
238 |
| - { UtestShell::getCurrent()->assertLongLongsEqual((long long)expected, (long long)actual, text, file, line); } |
| 238 | + do { UtestShell::getCurrent()->assertLongLongsEqual((long long)expected, (long long)actual, text, file, line); } while(0) |
239 | 239 |
|
240 | 240 | #define UNSIGNED_LONGLONGS_EQUAL_LOCATION(expected, actual, text, file, line)\
|
241 |
| - { UtestShell::getCurrent()->assertUnsignedLongLongsEqual((unsigned long long)expected, (unsigned long long)actual, text, file, line); } |
| 241 | + do { UtestShell::getCurrent()->assertUnsignedLongLongsEqual((unsigned long long)expected, (unsigned long long)actual, text, file, line); } while(0) |
242 | 242 |
|
243 | 243 | #define BYTES_EQUAL(expected, actual)\
|
244 | 244 | LONGS_EQUAL((expected) & 0xff,(actual) & 0xff)
|
|
250 | 250 | SIGNED_BYTES_EQUAL_LOCATION(expected, actual, __FILE__, __LINE__)
|
251 | 251 |
|
252 | 252 | #define SIGNED_BYTES_EQUAL_LOCATION(expected, actual, file, line) \
|
253 |
| - { UtestShell::getCurrent()->assertSignedBytesEqual(expected, actual, NULLPTR, file, line); } |
| 253 | + do { UtestShell::getCurrent()->assertSignedBytesEqual(expected, actual, NULLPTR, file, line); } while(0) |
254 | 254 |
|
255 | 255 | #define SIGNED_BYTES_EQUAL_TEXT(expected, actual, text)\
|
256 | 256 | SIGNED_BYTES_EQUAL_TEXT_LOCATION(expected, actual, text, __FILE__, __LINE__)
|
257 | 257 |
|
258 | 258 | #define SIGNED_BYTES_EQUAL_TEXT_LOCATION(expected, actual, text, file, line) \
|
259 |
| - { UtestShell::getCurrent()->assertSignedBytesEqual(expected, actual, text, file, line); } |
| 259 | + do { UtestShell::getCurrent()->assertSignedBytesEqual(expected, actual, text, file, line); } while(0) |
260 | 260 |
|
261 | 261 | #define POINTERS_EQUAL(expected, actual)\
|
262 | 262 | POINTERS_EQUAL_LOCATION((expected), (actual), NULLPTR, __FILE__, __LINE__)
|
|
265 | 265 | POINTERS_EQUAL_LOCATION((expected), (actual), text, __FILE__, __LINE__)
|
266 | 266 |
|
267 | 267 | #define POINTERS_EQUAL_LOCATION(expected, actual, text, file, line)\
|
268 |
| - { UtestShell::getCurrent()->assertPointersEqual((const void *)expected, (const void *)actual, text, file, line); } |
| 268 | + do { UtestShell::getCurrent()->assertPointersEqual((const void *)expected, (const void *)actual, text, file, line); } while(0) |
269 | 269 |
|
270 | 270 | #define FUNCTIONPOINTERS_EQUAL(expected, actual)\
|
271 | 271 | FUNCTIONPOINTERS_EQUAL_LOCATION((expected), (actual), NULLPTR, __FILE__, __LINE__)
|
|
274 | 274 | FUNCTIONPOINTERS_EQUAL_LOCATION((expected), (actual), text, __FILE__, __LINE__)
|
275 | 275 |
|
276 | 276 | #define FUNCTIONPOINTERS_EQUAL_LOCATION(expected, actual, text, file, line)\
|
277 |
| - { UtestShell::getCurrent()->assertFunctionPointersEqual((void (*)())expected, (void (*)())actual, text, file, line); } |
| 277 | + do { UtestShell::getCurrent()->assertFunctionPointersEqual((void (*)())expected, (void (*)())actual, text, file, line); } while(0) |
278 | 278 |
|
279 | 279 | //Check two doubles for equality within a tolerance threshold
|
280 | 280 | #define DOUBLES_EQUAL(expected, actual, threshold)\
|
|
284 | 284 | DOUBLES_EQUAL_LOCATION(expected, actual, threshold, text, __FILE__, __LINE__)
|
285 | 285 |
|
286 | 286 | #define DOUBLES_EQUAL_LOCATION(expected, actual, threshold, text, file, line)\
|
287 |
| - { UtestShell::getCurrent()->assertDoublesEqual(expected, actual, threshold, text, file, line); } |
| 287 | + do { UtestShell::getCurrent()->assertDoublesEqual(expected, actual, threshold, text, file, line); } while(0) |
288 | 288 |
|
289 | 289 | #define MEMCMP_EQUAL(expected, actual, size)\
|
290 | 290 | MEMCMP_EQUAL_LOCATION(expected, actual, size, NULLPTR, __FILE__, __LINE__)
|
|
293 | 293 | MEMCMP_EQUAL_LOCATION(expected, actual, size, text, __FILE__, __LINE__)
|
294 | 294 |
|
295 | 295 | #define MEMCMP_EQUAL_LOCATION(expected, actual, size, text, file, line)\
|
296 |
| - { UtestShell::getCurrent()->assertBinaryEqual(expected, actual, size, text, file, line); } |
| 296 | + do { UtestShell::getCurrent()->assertBinaryEqual(expected, actual, size, text, file, line); } while(0) |
297 | 297 |
|
298 | 298 | #define BITS_EQUAL(expected, actual, mask)\
|
299 | 299 | BITS_LOCATION(expected, actual, mask, NULLPTR, __FILE__, __LINE__)
|
|
302 | 302 | BITS_LOCATION(expected, actual, mask, text, __FILE__, __LINE__)
|
303 | 303 |
|
304 | 304 | #define BITS_LOCATION(expected, actual, mask, text, file, line)\
|
305 |
| - { UtestShell::getCurrent()->assertBitsEqual(expected, actual, mask, sizeof(actual), text, file, line); } |
| 305 | + do { UtestShell::getCurrent()->assertBitsEqual(expected, actual, mask, sizeof(actual), text, file, line); } while(0) |
306 | 306 |
|
307 | 307 | #define ENUMS_EQUAL_INT(expected, actual)\
|
308 | 308 | ENUMS_EQUAL_TYPE(int, expected, actual)
|
|
317 | 317 | ENUMS_EQUAL_TYPE_LOCATION(underlying_type, expected, actual, text, __FILE__, __LINE__)
|
318 | 318 |
|
319 | 319 | #define ENUMS_EQUAL_TYPE_LOCATION(underlying_type, expected, actual, text, file, line)\
|
320 |
| - { underlying_type expected_underlying_value = (underlying_type)(expected); \ |
| 320 | + do { underlying_type expected_underlying_value = (underlying_type)(expected); \ |
321 | 321 | underlying_type actual_underlying_value = (underlying_type)(actual); \
|
322 | 322 | if (expected_underlying_value != actual_underlying_value) { \
|
323 | 323 | UtestShell::getCurrent()->assertEquals(true, StringFrom(expected_underlying_value).asCharString(), StringFrom(actual_underlying_value).asCharString(), text, file, line); \
|
|
326 | 326 | { \
|
327 | 327 | UtestShell::getCurrent()->assertLongsEqual((long)0, long(0), NULLPTR, file, line); \
|
328 | 328 | } \
|
329 |
| - } |
| 329 | + } while(0) |
330 | 330 |
|
331 | 331 | //Fail if you get to this macro
|
332 | 332 | //The macro FAIL may already be taken, so allow FAIL_TEST too
|
|
335 | 335 | FAIL_LOCATION(text, __FILE__,__LINE__)
|
336 | 336 |
|
337 | 337 | #define FAIL_LOCATION(text, file, line)\
|
338 |
| - { UtestShell::getCurrent()->fail(text, file, line); } |
| 338 | + do { UtestShell::getCurrent()->fail(text, file, line); } while(0) |
339 | 339 | #endif
|
340 | 340 |
|
341 | 341 | #define FAIL_TEST(text)\
|
342 | 342 | FAIL_TEST_LOCATION(text, __FILE__,__LINE__)
|
343 | 343 |
|
344 | 344 | #define FAIL_TEST_LOCATION(text, file,line)\
|
345 |
| - { UtestShell::getCurrent()->fail(text, file, line); } |
| 345 | + do { UtestShell::getCurrent()->fail(text, file, line); } while(0) |
346 | 346 |
|
347 | 347 | #define TEST_EXIT\
|
348 |
| - { UtestShell::getCurrent()->exitTest(); } |
| 348 | + do { UtestShell::getCurrent()->exitTest(); } while(0) |
349 | 349 |
|
350 | 350 | #define UT_PRINT_LOCATION(text, file, line) \
|
351 |
| - { UtestShell::getCurrent()->print(text, file, line); } |
| 351 | + do { UtestShell::getCurrent()->print(text, file, line); } while(0) |
352 | 352 |
|
353 | 353 | #define UT_PRINT(text) \
|
354 | 354 | UT_PRINT_LOCATION(text, __FILE__, __LINE__)
|
355 | 355 |
|
356 | 356 | #if CPPUTEST_USE_STD_CPP_LIB
|
357 | 357 | #define CHECK_THROWS(expected, expression) \
|
358 |
| - { \ |
| 358 | + do { \ |
359 | 359 | SimpleString failure_msg("expected to throw "#expected "\nbut threw nothing"); \
|
360 | 360 | bool caught_expected = false; \
|
361 | 361 | try { \
|
|
371 | 371 | else { \
|
372 | 372 | UtestShell::getCurrent()->countCheck(); \
|
373 | 373 | } \
|
374 |
| - } |
| 374 | + } while(0) |
375 | 375 | #endif /* CPPUTEST_USE_STD_CPP_LIB */
|
376 | 376 |
|
377 |
| -#define UT_CRASH() { UtestShell::crash(); } |
| 377 | +#define UT_CRASH() do { UtestShell::crash(); } while(0) |
378 | 378 | #define RUN_ALL_TESTS(ac, av) CommandLineTestRunner::RunAllTests(ac, av)
|
379 | 379 |
|
380 | 380 | #endif /*D_UTestMacros_h*/
|
0 commit comments