Added CHECK_NO_THROW macro

Added CHECK_NO_THROW macro to check that an expression does not throw an
exception.
This commit is contained in:
jwellbelove 2014-11-01 12:41:48 +00:00
parent 9218ffc456
commit 7501a89497

View file

@ -156,7 +156,7 @@
UNITTEST_MULTILINE_MACRO_END
// CHECK_THROW and CHECK_ASSERT only exist when UNITTEST_NO_EXCEPTIONS isn't defined (see config.h)
// CHECK_THROW, CHECK_NO_THROW and CHECK_ASSERT only exist when UNITTEST_NO_EXCEPTIONS isn't defined (see config.h)
#ifndef UNITTEST_NO_EXCEPTIONS
#define CHECK_THROW(expression, ExpectedExceptionType) \
UNITTEST_MULTILINE_MACRO_BEGIN \
@ -168,6 +168,15 @@
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), "Expected exception: \"" #ExpectedExceptionType "\" not thrown"); \
UNITTEST_MULTILINE_MACRO_END
#define CHECK_NO_THROW(expression, NotExpectedExceptionType) \
UNITTEST_MULTILINE_MACRO_BEGIN \
bool caught_ = false; \
try { expression; } \
catch (NotExpectedExceptionType const&) { caught_ = true; } \
catch (...) {} \
if (caught_) \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), "Non-expected exception: \"" #NotExpectedExceptionType "\" thrown"); \
UNITTEST_MULTILINE_MACRO_END
#define CHECK_ASSERT(expression) \
UNITTEST_MULTILINE_MACRO_BEGIN \