summaryrefslogtreecommitdiff
path: root/lib/common/Test.h
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2014-04-09 22:15:14 +0000
committerChris Wilson <chris+github@qwirx.com>2014-04-09 22:15:14 +0000
commitfdfd1a57aea36019c20fac5382fcdc1797474d46 (patch)
treed8944833723b10172aad2370663070659c271b08 /lib/common/Test.h
parent6ef93f7fece55945290db71c86b0f626a4e92e30 (diff)
Add some test helper _OR macros to execute commands when conditions fail.
This is useful to return from a test if an assertion/check fails, instead of throwing an exception. Also add logging of the actual error code received (with name) to TEST_COMMAND_RETURNS_ERROR(_OR).
Diffstat (limited to 'lib/common/Test.h')
-rw-r--r--lib/common/Test.h29
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) \