Skip to content

Commit 534aca3

Browse files
committed
r20 | charles.nicholson | 2010-03-18 16:49:54 -0500 (Thu, 18 Mar 2010) | 1 line
add UNITTEST_WIN32 macro, turn dllmacros.h into helpermacros.h, wrap do/while(0) in __pragma to avoid VS 'conditional expression is constant' warning
1 parent a0501f6 commit 534aca3

19 files changed

+63
-57
lines changed

config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// Standard defines documented here: http://predef.sourceforge.net
55

66
#if defined(_MSC_VER)
7-
#pragma warning(disable:4127) // conditional expression is constant
87
#pragma warning(disable:4702) // unreachable code
98
#pragma warning(disable:4722) // destructor never returns, potential memory leak
109

@@ -16,6 +15,7 @@
1615
#ifdef _USRDLL
1716
#define UNITTEST_WIN32_DLL
1817
#endif
18+
#define UNITTEST_WIN32
1919
#endif
2020

2121
#if defined(unix) || defined(__unix__) || defined(__unix) || defined(linux) || \
@@ -30,8 +30,8 @@
3030
// by default, MemoryOutStream is implemented in terms of std::ostringstream, which can be expensive.
3131
// uncomment this line to use the custom MemoryOutStream (no deps on std::ostringstream).
3232

33-
#define UNITTEST_USE_CUSTOM_STREAMS
33+
//#define UNITTEST_USE_CUSTOM_STREAMS
3434
#define UNITTEST_USE_DEFERRED_REPORTER
35-
#define UNITTEST_USE_EXCEPTIONS
35+
//#define UNITTEST_USE_EXCEPTIONS
3636

3737
#endif

src/AssertException.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "../config.h"
55
#ifdef UNITTEST_USE_EXCEPTIONS
66

7-
#include "DllMacros.h"
7+
#include "HelperMacros.h"
88
#include <exception>
99

1010
namespace UnitTest {

src/CheckMacros.h

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef UNITTEST_CHECKMACROS_H
22
#define UNITTEST_CHECKMACROS_H
33

4+
#include "HelperMacros.h"
45
#include "ExceptionMacros.h"
56
#include "Checks.h"
67
#include "AssertException.h"
@@ -34,9 +35,8 @@
3435
#endif
3536

3637
#define CHECK(value) \
37-
do \
38-
{ \
39-
UT_TRY \
38+
UNITTEST_MULTILINE_MACRO_BEGIN \
39+
UT_TRY \
4040
({ \
4141
if (!UnitTest::Check(value)) \
4242
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \
@@ -46,11 +46,10 @@
4646
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
4747
"Unhandled exception in CHECK(" #value ")"); \
4848
}) \
49-
} while (0)
49+
UNITTEST_MULTILINE_MACRO_END
5050

5151
#define CHECK_EQUAL(expected, actual) \
52-
do \
53-
{ \
52+
UNITTEST_MULTILINE_MACRO_BEGIN \
5453
UT_TRY \
5554
({ \
5655
UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
@@ -60,11 +59,10 @@
6059
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
6160
"Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
6261
}) \
63-
} while (0)
62+
UNITTEST_MULTILINE_MACRO_END
6463

6564
#define CHECK_CLOSE(expected, actual, tolerance) \
66-
do \
67-
{ \
65+
UNITTEST_MULTILINE_MACRO_BEGIN \
6866
UT_TRY \
6967
({ \
7068
UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
@@ -74,11 +72,10 @@
7472
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
7573
"Unhandled exception in CHECK_CLOSE(" #expected ", " #actual ")"); \
7674
}) \
77-
} while (0)
75+
UNITTEST_MULTILINE_MACRO_END
7876

7977
#define CHECK_ARRAY_EQUAL(expected, actual, count) \
80-
do \
81-
{ \
78+
UNITTEST_MULTILINE_MACRO_BEGIN \
8279
UT_TRY \
8380
({ \
8481
UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
@@ -88,11 +85,10 @@
8885
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
8986
"Unhandled exception in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"); \
9087
}) \
91-
} while (0)
88+
UNITTEST_MULTILINE_MACRO_END
9289

9390
#define CHECK_ARRAY_CLOSE(expected, actual, count, tolerance) \
94-
do \
95-
{ \
91+
UNITTEST_MULTILINE_MACRO_BEGIN \
9692
UT_TRY \
9793
({ \
9894
UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
@@ -102,11 +98,10 @@
10298
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
10399
"Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \
104100
}) \
105-
} while (0)
101+
UNITTEST_MULTILINE_MACRO_END
106102

107103
#define CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, tolerance) \
108-
do \
109-
{ \
104+
UNITTEST_MULTILINE_MACRO_BEGIN \
110105
UT_TRY \
111106
({ \
112107
UnitTest::CheckArray2DClose(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
@@ -116,29 +111,27 @@
116111
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
117112
"Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \
118113
}) \
119-
} while (0)
114+
UNITTEST_MULTILINE_MACRO_END
120115

121116

122117
// CHECK_THROW and CHECK_ASSERT only exist when UNITTEST_USE_EXCEPTIONS is defined (see Config.h)
123118
#ifdef UNITTEST_USE_EXCEPTIONS
124119
#define CHECK_THROW(expression, ExpectedExceptionType) \
125-
do \
126-
{ \
120+
UNITTEST_MULTILINE_MACRO_BEGIN \
127121
bool caught_ = false; \
128122
try { expression; } \
129123
catch (ExpectedExceptionType const&) { caught_ = true; } \
130124
catch (...) {} \
131125
if (!caught_) \
132126
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), "Expected exception: \"" #ExpectedExceptionType "\" not thrown"); \
133-
} while(0)
127+
UNITTEST_MULTILINE_MACRO_END
134128

135129

136130
#define CHECK_ASSERT(expression) \
137-
do \
138-
{ \
131+
UNITTEST_MULTILINE_MACRO_BEGIN \
139132
UnitTest::Detail::ExpectAssert(true); \
140133
CHECK_THROW(expression, UnitTest::AssertException); \
141134
UnitTest::Detail::ExpectAssert(false); \
142-
} while(0)
135+
UNITTEST_MULTILINE_MACRO_END
143136
#endif
144137
#endif

src/CurrentTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef UNITTEST_CURRENTTESTRESULTS_H
22
#define UNITTEST_CURRENTTESTRESULTS_H
33

4-
#include "DllMacros.h"
4+
#include "HelperMacros.h"
55

66
namespace UnitTest {
77

src/DeferredTestResult.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "../config.h"
55
#ifdef UNITTEST_USE_DEFERRED_REPORTER
66

7-
#include "DllMacros.h"
7+
#include "HelperMacros.h"
88
#include <string>
99
#include <vector>
1010

src/DllMacros.h renamed to src/HelperMacros.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
#ifndef UNITTEST_DLLMACROS_H
2-
#define UNITTEST_DLLMACROS_H
1+
#ifndef UNITTEST_HELPERMACROS_H
2+
#define UNITTEST_HELPERMACROS_H
33

44
#include "../config.h"
55

6+
#define UNITTEST_MULTILINE_MACRO_BEGIN do {
7+
8+
#ifdef UNITTEST_WIN32
9+
#define UNITTEST_MULTILINE_MACRO_END \
10+
} __pragma(warning(push)) __pragma(warning(disable:4127)) while (0) __pragma(warning(pop))
11+
#else
12+
#define UNITTEST_MULTILINE_MACRO_END } while(0)
13+
#endif
14+
15+
616
#ifdef UNITTEST_WIN32_DLL
717
#define UNITTEST_IMPORT __declspec(dllimport)
818
#define UNITTEST_EXPORT __declspec(dllexport)

src/MemoryOutStream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define UNITTEST_MEMORYOUTSTREAM_H
33

44
#include "../config.h"
5-
#include "DllMacros.h"
5+
#include "HelperMacros.h"
66

77
#ifndef UNITTEST_USE_CUSTOM_STREAMS
88

src/ReportAssert.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef UNITTEST_ASSERT_H
22
#define UNITTEST_ASSERT_H
33

4-
#include "DllMacros.h"
4+
#include "HelperMacros.h"
55

66
namespace UnitTest {
77

src/ReportAssertImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ UNITTEST_LINKAGE bool AssertExpected();
2727
#ifndef UNITTEST_USE_EXCEPTIONS
2828
UNITTEST_LINKAGE jmp_buf* GetAssertJmpBuf();
2929

30-
#ifdef _MSC_VER
30+
#ifdef UNITTEST_WIN32
3131
#define UNITTEST_SET_ASSERT_JUMP_TARGET() \
3232
__pragma(warning(push)) __pragma(warning(disable:4611)) \
3333
setjmp(*UnitTest::Detail::GetAssertJmpBuf()) \

src/TestDetails.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef UNITTEST_TESTDETAILS_H
22
#define UNITTEST_TESTDETAILS_H
33

4-
#include "DllMacros.h"
4+
#include "HelperMacros.h"
55

66
namespace UnitTest {
77

src/TestList.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef UNITTEST_TESTLIST_H
22
#define UNITTEST_TESTLIST_H
33

4-
#include "DllMacros.h"
4+
#include "HelperMacros.h"
55

66
namespace UnitTest {
77

src/TestReporter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef UNITTEST_TESTREPORTER_H
22
#define UNITTEST_TESTREPORTER_H
33

4-
#include "DllMacros.h"
4+
#include "HelperMacros.h"
55

66
namespace UnitTest {
77

src/TestReporterStdout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "TestDetails.h"
55

66
// cstdio doesn't pull in namespace std on VC6, so we do it here.
7-
#if defined(_MSC_VER) && (_MSC_VER == 1200)
7+
#if defined(UNITTEST_WIN32) && (_MSC_VER == 1200)
88
namespace std {}
99
#endif
1010

src/TestResults.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef UNITTEST_TESTRESULTS_H
22
#define UNITTEST_TESTRESULTS_H
33

4-
#include "DllMacros.h"
4+
#include "HelperMacros.h"
55

66
namespace UnitTest {
77

src/TimeConstraint.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define UNITTEST_TIMECONSTRAINT_H
33

44
#include "TimeHelpers.h"
5-
#include "DllMacros.h"
5+
#include "HelperMacros.h"
66

77
namespace UnitTest {
88

@@ -27,7 +27,10 @@ class UNITTEST_LINKAGE TimeConstraint
2727
#define UNITTEST_TIME_CONSTRAINT(ms) \
2828
UnitTest::TimeConstraint unitTest__timeConstraint__(ms, UnitTest::TestDetails(m_details, __LINE__))
2929

30-
#define UNITTEST_TIME_CONSTRAINT_EXEMPT() do { m_timeConstraintExempt = true; } while (0)
30+
#define UNITTEST_TIME_CONSTRAINT_EXEMPT() \
31+
UNITTEST_MULTILINE_MACRO_BEGIN \
32+
m_timeConstraintExempt = true; \
33+
UNITTEST_MULTILINE_MACRO_END
3134

3235
}
3336

src/Win32/TimeHelpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Timer::Timer()
99
: m_threadHandle(::GetCurrentThread())
1010
, m_startTime(0)
1111
{
12-
#if defined(_MSC_VER) && (_MSC_VER == 1200) // VC6 doesn't have DWORD_PTR
12+
#if defined(UNITTEST_WIN32) && (_MSC_VER == 1200) // VC6 doesn't have DWORD_PTR
1313
typedef unsigned long DWORD_PTR;
1414
#endif
1515

src/Win32/TimeHelpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define UNITTEST_TIMEHELPERS_H
33

44
#include "../../config.h"
5-
#include "../DllMacros.h"
5+
#include "../HelperMacros.h"
66

77
#ifdef UNITTEST_MINGW
88
#ifndef __int64

src/tests/TestExceptions.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ TEST(CheckCloseFailsOnException)
9393
RecordingReporter reporter;
9494
UnitTest::TestResults testResults(&reporter);
9595
ScopedCurrentTest scopedResults(testResults);
96-
CHECK_CLOSE ((float)ThrowingFunction(), 1.0001f, 0.1f);
96+
CHECK_CLOSE((float)ThrowingFunction(), 1.0001f, 0.1f);
9797
failure = (testResults.GetFailureCount() > 0);
9898
}
9999

@@ -108,7 +108,7 @@ TEST(CheckCloseFailureBecauseOfExceptionContainsCorrectDetails)
108108
UnitTest::TestResults testResults(&reporter);
109109
UnitTest::TestDetails testDetails("closeTest", "closeSuite", "filename", -1);
110110
ScopedCurrentTest scopedResults(testResults, &testDetails);
111-
CHECK_CLOSE ((float)ThrowingFunction(), 1.0001f, 0.1f); line = __LINE__;
111+
CHECK_CLOSE((float)ThrowingFunction(), 1.0001f, 0.1f); line = __LINE__;
112112
}
113113

114114
CHECK_EQUAL("closeTest", reporter.lastFailedTest);
@@ -123,7 +123,7 @@ TEST(CheckCloseFailureBecauseOfExceptionIncludesCheckContents)
123123
{
124124
UnitTest::TestResults testResults(&reporter);
125125
ScopedCurrentTest scopedResults(testResults);
126-
CHECK_CLOSE ((float)ThrowingFunction(), 1.0001f, 0.1f);
126+
CHECK_CLOSE((float)ThrowingFunction(), 1.0001f, 0.1f);
127127
}
128128

129129
CHECK(strstr(reporter.lastFailedMessage, "(float)ThrowingFunction()"));
@@ -149,7 +149,7 @@ TEST(CheckArrayCloseFailureBecauseOfExceptionContainsCorrectDetails)
149149
ScopedCurrentTest scopedResults(testResults, &testDetails);
150150

151151
int const data[4] = { 0, 1, 2, 3 };
152-
CHECK_ARRAY_CLOSE (data, ThrowingObject(), 4, 0.01f); line = __LINE__;
152+
CHECK_ARRAY_CLOSE(data, ThrowingObject(), 4, 0.01f); line = __LINE__;
153153
}
154154

155155
CHECK_EQUAL("arrayCloseTest", reporter.lastFailedTest);
@@ -168,7 +168,7 @@ TEST(CheckArrayCloseFailsOnException)
168168

169169
const float data[4] = { 0, 1, 2, 3 };
170170
ThrowingObject obj;
171-
CHECK_ARRAY_CLOSE (data, obj, 3, 0.01f);
171+
CHECK_ARRAY_CLOSE(data, obj, 3, 0.01f);
172172

173173
failure = (testResults.GetFailureCount() > 0);
174174
}
@@ -185,7 +185,7 @@ TEST(CheckArrayCloseFailureOnExceptionIncludesCheckContents)
185185

186186
const float data[4] = { 0, 1, 2, 3 };
187187
ThrowingObject obj;
188-
CHECK_ARRAY_CLOSE (data, obj, 3, 0.01f);
188+
CHECK_ARRAY_CLOSE(data, obj, 3, 0.01f);
189189
}
190190

191191
CHECK(strstr(reporter.lastFailedMessage, "data"));
@@ -253,7 +253,7 @@ TEST(CheckArray2DCloseFailureBecauseOfExceptionContainsCorrectDetails)
253253
ScopedCurrentTest scopedResults(testResults, &testDetails);
254254

255255
const float data[2][2] = { {0, 1}, {2, 3} };
256-
CHECK_ARRAY2D_CLOSE (data, ThrowingObject2D(), 2, 2, 0.01f); line = __LINE__;
256+
CHECK_ARRAY2D_CLOSE(data, ThrowingObject2D(), 2, 2, 0.01f); line = __LINE__;
257257
}
258258

259259
CHECK_EQUAL("array2DCloseTest", reporter.lastFailedTest);
@@ -272,7 +272,7 @@ TEST(CheckArray2DCloseFailsOnException)
272272

273273
const float data[2][2] = { {0, 1}, {2, 3} };
274274
ThrowingObject2D obj;
275-
CHECK_ARRAY2D_CLOSE (data, obj, 2, 2, 0.01f);
275+
CHECK_ARRAY2D_CLOSE(data, obj, 2, 2, 0.01f);
276276

277277
failure = (testResults.GetFailureCount() > 0);
278278
}
@@ -289,7 +289,7 @@ TEST(CheckArray2DCloseFailureOnExceptionIncludesCheckContents)
289289

290290
const float data[2][2] = { {0, 1}, {2, 3} };
291291
ThrowingObject2D obj;
292-
CHECK_ARRAY2D_CLOSE (data, obj, 2, 2, 0.01f);
292+
CHECK_ARRAY2D_CLOSE(data, obj, 2, 2, 0.01f);
293293
}
294294

295295
CHECK(strstr(reporter.lastFailedMessage, "data"));

0 commit comments

Comments
 (0)