comparison ext/UnitTest++/src/CheckMacros.h @ 37:0d325e9d5953

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