diff options
Diffstat (limited to 'lib/common/Test.h')
-rw-r--r-- | lib/common/Test.h | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/lib/common/Test.h b/lib/common/Test.h index 77f9584c..dbe1e979 100644 --- a/lib/common/Test.h +++ b/lib/common/Test.h @@ -49,19 +49,20 @@ extern std::list<std::string> run_only_named_tests; #define TEST_ABORT_WITH_MESSAGE(msg) {TEST_FAIL_WITH_MESSAGE(msg); return 1;} -#define TEST_THAT(condition) {if(!(condition)) TEST_FAIL_WITH_MESSAGE("Condition [" #condition "] failed")} -#define TEST_THAT_ABORTONFAIL(condition) {if(!(condition)) TEST_ABORT_WITH_MESSAGE("Condition [" #condition "] failed")} -#define TEST_THAT_THROWONFAIL(condition) \ +#define TEST_THAT_OR(condition, or_command) \ + if(!(condition)) \ { \ - if(!(condition)) \ - { \ - THROW_EXCEPTION_MESSAGE(CommonException, \ - AssertFailed, "Condition [" #condition "] failed"); \ - } \ + TEST_FAIL_WITH_MESSAGE("Condition [" #condition "] failed"); \ + or_command; \ } +#define TEST_THAT(condition) TEST_THAT_OR(condition,) +#define TEST_THAT_ABORTONFAIL(condition) {if(!(condition)) TEST_ABORT_WITH_MESSAGE("Condition [" #condition "] failed")} +#define TEST_THAT_THROWONFAIL(condition) \ + TEST_THAT_OR(condition, THROW_EXCEPTION_MESSAGE(CommonException, \ + AssertFailed, "Condition [" #condition "] failed")); // NOTE: The 0- bit is to allow this to work with stuff which has negative constants for flags (eg ConnectionException) -#define TEST_CHECK_THROWS(statement, excepttype, subtype) \ +#define TEST_CHECK_THROWS_OR(statement, excepttype, subtype, or_command) \ { \ bool didthrow = false; \ HideExceptionMessageGuard hide; \ @@ -86,12 +87,15 @@ extern std::list<std::string> run_only_named_tests; } \ if(!didthrow) \ { \ - TEST_FAIL_WITH_MESSAGE("Didn't throw exception " #excepttype "(" #subtype ")") \ + TEST_FAIL_WITH_MESSAGE("Didn't throw exception " #excepttype "(" #subtype ")"); \ + or_command; \ } \ } +#define TEST_CHECK_THROWS(statement, excepttype, subtype) \ + TEST_CHECK_THROWS_OR(statement, excepttype, subtype,) // utility macro for comparing two strings in a line -#define TEST_EQUAL(_expected, _found) \ +#define TEST_EQUAL_OR(_expected, _found, or_command) \ { \ std::ostringstream _oss1; \ _oss1 << _expected; \ @@ -110,8 +114,11 @@ extern std::list<std::string> run_only_named_tests; _oss3 << #_found << " != " << #_expected; \ \ TEST_FAIL_WITH_MESSAGE(_oss3.str().c_str()); \ + or_command; \ } \ } +#define TEST_EQUAL(_expected, _found) \ + TEST_EQUAL_OR(_expected, _found,) // utility macro for comparing two strings in a line #define TEST_EQUAL_LINE(_expected, _found, _line) \ |