Skip to content

Commit 9be6d3d

Browse files
authored
Merge pull request #1215 from offa/macro_fixes
Empty expression warnings fixed
2 parents 465841a + 87497ab commit 9be6d3d

19 files changed

+222
-224
lines changed

include/CppUTest/MemoryLeakWarningPlugin.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
#include "TestPlugin.h"
3232
#include "MemoryLeakDetectorNewMacros.h"
3333

34-
#define IGNORE_ALL_LEAKS_IN_TEST() MemoryLeakWarningPlugin::getFirstPlugin()->ignoreAllLeaksInTest();
35-
#define EXPECT_N_LEAKS(n) MemoryLeakWarningPlugin::getFirstPlugin()->expectLeaksInTest(n);
34+
#define IGNORE_ALL_LEAKS_IN_TEST() MemoryLeakWarningPlugin::getFirstPlugin()->ignoreAllLeaksInTest()
35+
#define EXPECT_N_LEAKS(n) MemoryLeakWarningPlugin::getFirstPlugin()->expectLeaksInTest(n)
3636

3737
extern void crash_on_allocation_number(unsigned alloc_number);
3838

include/CppUTest/TestPlugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class SetPointerPlugin: public TestPlugin
9898
};
9999
};
100100

101-
#define UT_PTR_SET(a, b) { CppUTestStore( (void**)&a ); a = b; }
101+
#define UT_PTR_SET(a, b) do { CppUTestStore( (void**)&a ); a = b; } while(0)
102102

103103
///////////// Null Plugin
104104

include/CppUTest/UtestMacros.h

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@
117117
CHECK_FALSE_LOCATION(condition, "CHECK_FALSE", #condition, text, __FILE__, __LINE__)
118118

119119
#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)
121121

122122
#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)
124124

125125
//This check needs the operator!=(), and a StringFrom(YourType) function
126126
#define CHECK_EQUAL(expected, actual)\
@@ -130,7 +130,7 @@
130130
CHECK_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__)
131131

132132
#define CHECK_EQUAL_LOCATION(expected, actual, text, file, line)\
133-
{ if ((expected) != (actual)) { \
133+
do { if ((expected) != (actual)) { \
134134
if ((actual) != (actual)) \
135135
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); \
136136
if ((expected) != (expected)) \
@@ -140,7 +140,7 @@
140140
else \
141141
{ \
142142
UtestShell::getCurrent()->assertLongsEqual((long)0, (long)0, NULLPTR, file, line); \
143-
} }
143+
} } while(0)
144144

145145
#define CHECK_COMPARE(first, relop, second)\
146146
CHECK_COMPARE_TEXT(first, relop, second, NULLPTR)
@@ -149,12 +149,12 @@
149149
CHECK_COMPARE_LOCATION(first, relop, second, text, __FILE__, __LINE__)
150150

151151
#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)
158158

159159
//This check checks for char* string equality using strcmp.
160160
//This makes up for the fact that CHECK_EQUAL only compares the pointers to char*'s
@@ -165,7 +165,7 @@
165165
STRCMP_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__)
166166

167167
#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)
169169

170170
#define STRNCMP_EQUAL(expected, actual, length)\
171171
STRNCMP_EQUAL_LOCATION(expected, actual, length, NULLPTR, __FILE__, __LINE__)
@@ -174,7 +174,7 @@
174174
STRNCMP_EQUAL_LOCATION(expected, actual, length, text, __FILE__, __LINE__)
175175

176176
#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)
178178

179179
#define STRCMP_NOCASE_EQUAL(expected, actual)\
180180
STRCMP_NOCASE_EQUAL_LOCATION(expected, actual, NULLPTR, __FILE__, __LINE__)
@@ -183,7 +183,7 @@
183183
STRCMP_NOCASE_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__)
184184

185185
#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)
187187

188188
#define STRCMP_CONTAINS(expected, actual)\
189189
STRCMP_CONTAINS_LOCATION(expected, actual, NULLPTR, __FILE__, __LINE__)
@@ -192,7 +192,7 @@
192192
STRCMP_CONTAINS_LOCATION(expected, actual, text, __FILE__, __LINE__)
193193

194194
#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)
196196

197197
#define STRCMP_NOCASE_CONTAINS(expected, actual)\
198198
STRCMP_NOCASE_CONTAINS_LOCATION(expected, actual, NULLPTR, __FILE__, __LINE__)
@@ -201,7 +201,7 @@
201201
STRCMP_NOCASE_CONTAINS_LOCATION(expected, actual, text, __FILE__, __LINE__)
202202

203203
#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)
205205

206206
//Check two long integers for equality
207207
#define LONGS_EQUAL(expected, actual)\
@@ -217,10 +217,10 @@
217217
UNSIGNED_LONGS_EQUAL_LOCATION((expected), (actual), text, __FILE__, __LINE__)
218218

219219
#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)
221221

222222
#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)
224224

225225
#define LONGLONGS_EQUAL(expected, actual)\
226226
LONGLONGS_EQUAL_LOCATION(expected, actual, NULLPTR, __FILE__, __LINE__)
@@ -235,10 +235,10 @@
235235
UNSIGNED_LONGLONGS_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__)
236236

237237
#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)
239239

240240
#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)
242242

243243
#define BYTES_EQUAL(expected, actual)\
244244
LONGS_EQUAL((expected) & 0xff,(actual) & 0xff)
@@ -250,13 +250,13 @@
250250
SIGNED_BYTES_EQUAL_LOCATION(expected, actual, __FILE__, __LINE__)
251251

252252
#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)
254254

255255
#define SIGNED_BYTES_EQUAL_TEXT(expected, actual, text)\
256256
SIGNED_BYTES_EQUAL_TEXT_LOCATION(expected, actual, text, __FILE__, __LINE__)
257257

258258
#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)
260260

261261
#define POINTERS_EQUAL(expected, actual)\
262262
POINTERS_EQUAL_LOCATION((expected), (actual), NULLPTR, __FILE__, __LINE__)
@@ -265,7 +265,7 @@
265265
POINTERS_EQUAL_LOCATION((expected), (actual), text, __FILE__, __LINE__)
266266

267267
#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)
269269

270270
#define FUNCTIONPOINTERS_EQUAL(expected, actual)\
271271
FUNCTIONPOINTERS_EQUAL_LOCATION((expected), (actual), NULLPTR, __FILE__, __LINE__)
@@ -274,7 +274,7 @@
274274
FUNCTIONPOINTERS_EQUAL_LOCATION((expected), (actual), text, __FILE__, __LINE__)
275275

276276
#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)
278278

279279
//Check two doubles for equality within a tolerance threshold
280280
#define DOUBLES_EQUAL(expected, actual, threshold)\
@@ -284,7 +284,7 @@
284284
DOUBLES_EQUAL_LOCATION(expected, actual, threshold, text, __FILE__, __LINE__)
285285

286286
#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)
288288

289289
#define MEMCMP_EQUAL(expected, actual, size)\
290290
MEMCMP_EQUAL_LOCATION(expected, actual, size, NULLPTR, __FILE__, __LINE__)
@@ -293,7 +293,7 @@
293293
MEMCMP_EQUAL_LOCATION(expected, actual, size, text, __FILE__, __LINE__)
294294

295295
#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)
297297

298298
#define BITS_EQUAL(expected, actual, mask)\
299299
BITS_LOCATION(expected, actual, mask, NULLPTR, __FILE__, __LINE__)
@@ -302,7 +302,7 @@
302302
BITS_LOCATION(expected, actual, mask, text, __FILE__, __LINE__)
303303

304304
#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)
306306

307307
#define ENUMS_EQUAL_INT(expected, actual)\
308308
ENUMS_EQUAL_TYPE(int, expected, actual)
@@ -317,7 +317,7 @@
317317
ENUMS_EQUAL_TYPE_LOCATION(underlying_type, expected, actual, text, __FILE__, __LINE__)
318318

319319
#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); \
321321
underlying_type actual_underlying_value = (underlying_type)(actual); \
322322
if (expected_underlying_value != actual_underlying_value) { \
323323
UtestShell::getCurrent()->assertEquals(true, StringFrom(expected_underlying_value).asCharString(), StringFrom(actual_underlying_value).asCharString(), text, file, line); \
@@ -326,7 +326,7 @@
326326
{ \
327327
UtestShell::getCurrent()->assertLongsEqual((long)0, long(0), NULLPTR, file, line); \
328328
} \
329-
}
329+
} while(0)
330330

331331
//Fail if you get to this macro
332332
//The macro FAIL may already be taken, so allow FAIL_TEST too
@@ -335,27 +335,27 @@
335335
FAIL_LOCATION(text, __FILE__,__LINE__)
336336

337337
#define FAIL_LOCATION(text, file, line)\
338-
{ UtestShell::getCurrent()->fail(text, file, line); }
338+
do { UtestShell::getCurrent()->fail(text, file, line); } while(0)
339339
#endif
340340

341341
#define FAIL_TEST(text)\
342342
FAIL_TEST_LOCATION(text, __FILE__,__LINE__)
343343

344344
#define FAIL_TEST_LOCATION(text, file,line)\
345-
{ UtestShell::getCurrent()->fail(text, file, line); }
345+
do { UtestShell::getCurrent()->fail(text, file, line); } while(0)
346346

347347
#define TEST_EXIT\
348-
{ UtestShell::getCurrent()->exitTest(); }
348+
do { UtestShell::getCurrent()->exitTest(); } while(0)
349349

350350
#define UT_PRINT_LOCATION(text, file, line) \
351-
{ UtestShell::getCurrent()->print(text, file, line); }
351+
do { UtestShell::getCurrent()->print(text, file, line); } while(0)
352352

353353
#define UT_PRINT(text) \
354354
UT_PRINT_LOCATION(text, __FILE__, __LINE__)
355355

356356
#if CPPUTEST_USE_STD_CPP_LIB
357357
#define CHECK_THROWS(expected, expression) \
358-
{ \
358+
do { \
359359
SimpleString failure_msg("expected to throw "#expected "\nbut threw nothing"); \
360360
bool caught_expected = false; \
361361
try { \
@@ -371,10 +371,10 @@
371371
else { \
372372
UtestShell::getCurrent()->countCheck(); \
373373
} \
374-
}
374+
} while(0)
375375
#endif /* CPPUTEST_USE_STD_CPP_LIB */
376376

377-
#define UT_CRASH() { UtestShell::crash(); }
377+
#define UT_CRASH() do { UtestShell::crash(); } while(0)
378378
#define RUN_ALL_TESTS(ac, av) CommandLineTestRunner::RunAllTests(ac, av)
379379

380380
#endif /*D_UTestMacros_h*/

src/CppUTest/JUnitTestOutput.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ void JUnitTestOutput::resetTestGroupResult()
9292
JUnitTestCaseResultNode* cur = impl_->results_.head_;
9393
while (cur) {
9494
JUnitTestCaseResultNode* tmp = cur->next_;
95-
;
9695
delete cur->failure_;
9796
delete cur;
9897
cur = tmp;

src/CppUTest/MemoryLeakWarningPlugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void cpputest_free_location_with_leak_detection(void* buffer, const char* file,
128128
#undef new
129129

130130
#if CPPUTEST_USE_STD_CPP_LIB
131-
#define UT_THROW_BAD_ALLOC_WHEN_NULL(memory) if (memory == NULLPTR) throw std::bad_alloc();
131+
#define UT_THROW_BAD_ALLOC_WHEN_NULL(memory) if (memory == NULLPTR) throw std::bad_alloc()
132132
#else
133133
#define UT_THROW_BAD_ALLOC_WHEN_NULL(memory)
134134
#endif

src/CppUTest/TestFailure.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,5 +387,5 @@ FeatureUnsupportedFailure::FeatureUnsupportedFailure(UtestShell* test, const cha
387387
{
388388
message_ = createUserText(text);
389389

390-
message_ += StringFromFormat("The feature \"%s\" is not supported in this environment or with the feature set selected when building the library.", featureName.asCharString());;
390+
message_ += StringFromFormat("The feature \"%s\" is not supported in this environment or with the feature set selected when building the library.", featureName.asCharString());
391391
}

src/CppUTest/TestTestingFixture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ void TestTestingFixture::checkTestFailsWithProperTestLocation(const char* text,
4343
STRCMP_CONTAINS_LOCATION(text, output_->getOutput().asCharString(), "", file, line);
4444

4545
if (lineOfCodeExecutedAfterCheck)
46-
FAIL_LOCATION("The test should jump/throw on failure and not execute the next line. However, the next line was executed.", file, line)
46+
FAIL_LOCATION("The test should jump/throw on failure and not execute the next line. However, the next line was executed.", file, line);
4747
}
4848

src/CppUTestExt/MockActualCall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ void MockCheckedActualCall::checkExpectations()
386386
}
387387

388388
if (potentiallyMatchingExpectations_.hasFinalizedMatchingExpectations())
389-
FAIL("Actual call is in progress, but there are finalized matching expectations when checking expectations. This cannot happen.") // LCOV_EXCL_LINE
389+
FAIL("Actual call is in progress, but there are finalized matching expectations when checking expectations. This cannot happen."); // LCOV_EXCL_LINE
390390

391391
matchingExpectation_ = potentiallyMatchingExpectations_.removeFirstMatchingExpectation();
392392
if (matchingExpectation_) {

tests/CppUTest/SetPluginTest.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ class FunctionPointerUtestShell: public UtestShell
7777
TEST(SetPointerPluginTest, installTwoFunctionPointer)
7878
{
7979
FunctionPointerUtestShell *tst = new FunctionPointerUtestShell();
80-
;
8180

8281
fp1 = orig_func1;
8382
fp2 = orig_func2;

tests/CppUTest/SimpleStringTest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -610,17 +610,17 @@ TEST(SimpleString, StringFromFormatpointer)
610610
//this is not a great test. but %p is odd on mingw and even more odd on Solaris.
611611
SimpleString h1 = StringFromFormat("%p", (void*) 1);
612612
if (h1.size() == 3)
613-
STRCMP_EQUAL("0x1", h1.asCharString())
613+
STRCMP_EQUAL("0x1", h1.asCharString());
614614
else if (h1.size() == 8)
615-
STRCMP_EQUAL("00000001", h1.asCharString())
615+
STRCMP_EQUAL("00000001", h1.asCharString());
616616
else if (h1.size() == 9)
617-
STRCMP_EQUAL("0000:0001", h1.asCharString())
617+
STRCMP_EQUAL("0000:0001", h1.asCharString());
618618
else if (h1.size() == 16)
619-
STRCMP_EQUAL("0000000000000001", h1.asCharString())
619+
STRCMP_EQUAL("0000000000000001", h1.asCharString());
620620
else if (h1.size() == 1)
621-
STRCMP_EQUAL("1", h1.asCharString())
621+
STRCMP_EQUAL("1", h1.asCharString());
622622
else
623-
FAIL("Off %p behavior")
623+
FAIL("Off %p behavior");
624624
}
625625

626626
TEST(SimpleString, StringFromFormatLarge)

0 commit comments

Comments
 (0)