1
#ifndef UNITTEST_CHECKMACROS_H
2
#define UNITTEST_CHECKMACROS_H
5
#include "AssertException.h"
6
#include "MemoryOutStream.h"
7
#include "TestDetails.h"
8
#include "CurrentTest.h"
11
#error UnitTest++ redefines CHECK
15
#error UnitTest++ redefines CHECK_EQUAL
19
#error UnitTest++ redefines CHECK_CLOSE
22
#ifdef CHECK_ARRAY_EQUAL
23
#error UnitTest++ redefines CHECK_ARRAY_EQUAL
26
#ifdef CHECK_ARRAY_CLOSE
27
#error UnitTest++ redefines CHECK_ARRAY_CLOSE
30
#ifdef CHECK_ARRAY2D_CLOSE
31
#error UnitTest++ redefines CHECK_ARRAY2D_CLOSE
34
#define CHECK(value) \
38
if (!UnitTest::Check(value)) \
39
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \
42
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
43
"Unhandled exception in CHECK(" #value ")"); \
47
#define CHECK_EQUAL(expected, actual) \
51
UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
54
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
55
"Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
59
#define CHECK_CLOSE(expected, actual, tolerance) \
63
UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
66
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
67
"Unhandled exception in CHECK_CLOSE(" #expected ", " #actual ")"); \
71
#define CHECK_ARRAY_EQUAL(expected, actual, count) \
75
UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
78
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
79
"Unhandled exception in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"); \
83
#define CHECK_ARRAY_CLOSE(expected, actual, count, tolerance) \
87
UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
90
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
91
"Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \
95
#define CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, tolerance) \
99
UnitTest::CheckArray2DClose(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
102
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
103
"Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \
108
#define CHECK_THROW(expression, ExpectedExceptionType) \
111
bool caught_ = false; \
112
try { expression; } \
113
catch (ExpectedExceptionType const&) { caught_ = true; } \
116
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), "Expected exception: \"" #ExpectedExceptionType "\" not thrown"); \
119
#define CHECK_ASSERT(expression) \
120
CHECK_THROW(expression, UnitTest::AssertException);