1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#ifndef UNITTEST_CHECKMACROS_H
#define UNITTEST_CHECKMACROS_H
#include "Checks.h"
#include "AssertException.h"
#include "MemoryOutStream.h"
#include "TestDetails.h"
#ifdef CHECK
#error UnitTest++ redefines CHECK
#endif
#define CHECK(value) \
do \
{ \
try { \
if (!UnitTest::Check(value)) \
testResults_.OnTestFailure( UnitTest::TestDetails(m_details, __LINE__), #value); \
} \
catch (...) { \
testResults_.OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), \
"Unhandled exception in CHECK(" #value ")"); \
} \
} while (0)
#define CHECK_EQUAL(expected, actual) \
do \
{ \
try { \
UnitTest::CheckEqual(testResults_, expected, actual, UnitTest::TestDetails(m_details, __LINE__)); \
} \
catch (...) { \
testResults_.OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), \
"Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
} \
} while (0)
#define CHECK_CLOSE(expected, actual, tolerance) \
do \
{ \
try { \
UnitTest::CheckClose(testResults_, expected, actual, tolerance, UnitTest::TestDetails(m_details, __LINE__)); \
} \
catch (...) { \
testResults_.OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), \
"Unhandled exception in CHECK_CLOSE(" #expected ", " #actual ")"); \
} \
} while (0)
#define CHECK_ARRAY_EQUAL(expected, actual, count) \
do \
{ \
try { \
UnitTest::CheckArrayEqual(testResults_, expected, actual, count, UnitTest::TestDetails(m_details, __LINE__)); \
} \
catch (...) { \
testResults_.OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), \
"Unhandled exception in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"); \
} \
} while (0)
#define CHECK_ARRAY_CLOSE(expected, actual, count, tolerance) \
do \
{ \
try { \
UnitTest::CheckArrayClose(testResults_, expected, actual, count, tolerance, UnitTest::TestDetails(m_details, __LINE__)); \
} \
catch (...) { \
testResults_.OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), \
"Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \
} \
} while (0)
#define CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, tolerance) \
do \
{ \
try { \
UnitTest::CheckArray2DClose(testResults_, expected, actual, rows, columns, tolerance, UnitTest::TestDetails(m_details, __LINE__)); \
} \
catch (...) { \
testResults_.OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), \
"Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \
} \
} while (0)
#define CHECK_THROW(expression, ExpectedExceptionType) \
do \
{ \
bool caught_ = false; \
try { expression; } \
catch (ExpectedExceptionType const&) { caught_ = true; } \
catch (...) {} \
if (!caught_) \
testResults_.OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), "Expected exception: \"" #ExpectedExceptionType "\" not thrown"); \
} while(0)
#define CHECK_ASSERT(expression) \
CHECK_THROW(expression, UnitTest::AssertException);
#endif
|