diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/backupstore/StoreTestUtils.h | 31 | ||||
-rw-r--r-- | lib/common/Test.h | 29 |
2 files changed, 45 insertions, 15 deletions
diff --git a/lib/backupstore/StoreTestUtils.h b/lib/backupstore/StoreTestUtils.h index f65ae3df..39013422 100644 --- a/lib/backupstore/StoreTestUtils.h +++ b/lib/backupstore/StoreTestUtils.h @@ -10,6 +10,8 @@ #ifndef STORETESTUTILS__H #define STORETESTUTILS__H +#include "Test.h" + class BackupProtocolCallable; class BackupProtocolClient; class SocketStreamTLS; @@ -78,10 +80,31 @@ bool create_account(int soft, int hard); //! Deletes the standard test account, for testing behaviour with no account. bool delete_account(); -#define TEST_COMMAND_RETURNS_ERROR(command, error) \ - TEST_CHECK_THROWS(command, ConnectionException, \ - Conn_Protocol_UnexpectedReply); \ - TEST_EQUAL(BackupProtocolError::error, protocol.GetLastErrorType()); +#define TEST_COMMAND_RETURNS_ERROR_OR(protocol, command, error, or_statements) \ + { \ + TEST_CHECK_THROWS_OR(protocol . command, ConnectionException, \ + Conn_Protocol_UnexpectedReply, or_statements); \ + int type, subtype; \ + protocol.GetLastError(type, subtype); \ + if (type == BackupProtocolError::ErrorType) \ + { \ + TEST_EQUAL_LINE(BackupProtocolError::error, subtype, \ + "command returned error: " << \ + BackupProtocolError::GetMessage(subtype)); \ + if (subtype != BackupProtocolError::error) \ + { \ + or_statements; \ + } \ + } \ + else \ + { \ + TEST_FAIL_WITH_MESSAGE("command returned success"); \ + or_statements; \ + } \ + } + +#define TEST_COMMAND_RETURNS_ERROR(protocol, command, error) \ + TEST_COMMAND_RETURNS_ERROR_OR(protocol, command, error,) #endif // STORETESTUTILS__H 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) \ |