8000 r20 | charles.nicholson | 2010-03-18 16:49:54 -0500 (Thu, 18 Mar 2010… · tobscher/unittest-cpp@534aca3 · GitHub
[go: up one dir, main page]

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

0 commit comments

Comments
 (0)
0