Add WX_ASSERT_FAILS_WITH_ASSERT_MESSAGE helper.

This is similar to the existing WX_ASSERT_FAILS_WITH_ASSERT, but allows to
specify the message to give if the expected assertion is not triggered.
This commit is contained in:
Vadim Zeitlin
2015-04-03 16:31:23 +02:00
parent 636d08323f
commit 7811394694

View File

@@ -78,14 +78,19 @@ public:
#if wxDEBUG_LEVEL
// some old cppunit versions don't define CPPUNIT_ASSERT_THROW so roll our
// own
#define WX_ASSERT_FAILS_WITH_ASSERT(cond) \
{ \
#define WX_ASSERT_FAILS_WITH_ASSERT_MESSAGE(msg, code) \
wxSTATEMENT_MACRO_BEGIN \
bool throwsAssert = false; \
try { cond ; } \
try { code ; } \
catch ( const TestAssertFailure& ) { throwsAssert = true; } \
if ( !throwsAssert ) \
CPPUNIT_FAIL("expected assertion not generated"); \
}
CPPUNIT_FAIL(msg); \
wxSTATEMENT_MACRO_END
#define WX_ASSERT_FAILS_WITH_ASSERT(code) \
WX_ASSERT_FAILS_WITH_ASSERT_MESSAGE( \
"expected assertion not generated", code)
#else
// there are no assertions in this build so we can't do anything (we used
// to check that the condition failed but this didn't work well as in