summaryrefslogtreecommitdiff
path: root/lib/backupstore/StoreTestUtils.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/backupstore/StoreTestUtils.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/backupstore/StoreTestUtils.h')
-rw-r--r--lib/backupstore/StoreTestUtils.h31
1 files changed, 27 insertions, 4 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