| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- #ifndef UNITTEST_CHECKMACROS_H
- #define UNITTEST_CHECKMACROS_H
- #include "Checks.h"
- #include "AssertException.h"
- #include "MemoryOutStream.h"
- #include "TestDetails.h"
- #include "CurrentTest.h"
- #ifdef CHECK
- #error UnitTest++ redefines CHECK
- #endif
- #ifdef CHECK_EQUAL
- #error UnitTest++ redefines CHECK_EQUAL
- #endif
- #ifdef CHECK_CLOSE
- #error UnitTest++ redefines CHECK_CLOSE
- #endif
- #ifdef CHECK_ARRAY_EQUAL
- #error UnitTest++ redefines CHECK_ARRAY_EQUAL
- #endif
- #ifdef CHECK_ARRAY_CLOSE
- #error UnitTest++ redefines CHECK_ARRAY_CLOSE
- #endif
- #ifdef CHECK_ARRAY2D_CLOSE
- #error UnitTest++ redefines CHECK_ARRAY2D_CLOSE
- #endif
- #define CHECK(value) \
- do \
- { \
- try { \
- if (!UnitTest::Check(value)) \
- UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \
- } \
- catch (...) { \
- UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
- "Unhandled exception in CHECK(" #value ")"); \
- } \
- } while (0)
- #define CHECK_EQUAL(expected, actual) \
- do \
- { \
- try { \
- UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
- } \
- catch (...) { \
- UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
- "Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
- } \
- } while (0)
- #define CHECK_CLOSE(expected, actual, tolerance) \
- do \
- { \
- try { \
- UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
- } \
- catch (...) { \
- UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
- "Unhandled exception in CHECK_CLOSE(" #expected ", " #actual ")"); \
- } \
- } while (0)
- #define CHECK_ARRAY_EQUAL(expected, actual, count) \
- do \
- { \
- try { \
- UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
- } \
- catch (...) { \
- UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
- "Unhandled exception in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"); \
- } \
- } while (0)
- #define CHECK_ARRAY_CLOSE(expected, actual, count, tolerance) \
- do \
- { \
- try { \
- UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
- } \
- catch (...) { \
- UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::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(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
- } \
- catch (...) { \
- UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::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_) \
- UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), "Expected exception: \"" #ExpectedExceptionType "\" not thrown"); \
- } while(0)
- #define CHECK_ASSERT(expression) \
- CHECK_THROW(expression, UnitTest::AssertException);
- #endif
|