add tests to check that exceptions are thrown for wrong types

* Add JSONTEST_ASSERT_THROWS macro to test if an expression
  throws an exceptions.
* add JSONTEST_FIXTURE(ValueTest, typeChecksThrowExceptions)
This commit is contained in:
Chris Gilling
2014-08-08 16:22:28 -07:00
committed by Christopher Dunn
parent 7ebdabc059
commit 97c77b4a86
2 changed files with 79 additions and 12 deletions

View File

@@ -241,6 +241,20 @@ TestResult &checkStringEqual(TestResult &result,
__LINE__, \
#expected " == " #actual)
/// \brief Asserts that a given expression throws an exception
#define JSONTEST_ASSERT_THROWS(expr) \
{ \
bool _threw = false; \
try { \
expr; \
} catch (...) { \
_threw = true; \
} \
if (!_threw) \
result_->addFailure(__FILE__, __LINE__, \
"expected exception thrown: " #expr); \
}
/// \brief Begin a fixture test case.
#define JSONTEST_FIXTURE(FixtureType, name) \
class Test##FixtureType##name : public FixtureType { \