diff options
author | Chris Wilson <chris+github@qwirx.com> | 2014-02-27 23:34:54 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2014-02-27 23:34:54 +0000 |
commit | f211f55a3118d1a7213d26f8b54a3f37edbc1774 (patch) | |
tree | 3b0d63ef5696802bf5eeaecf8cd77f03c8477c14 /lib/backupstore/StoreTestUtils.h | |
parent | 893a7a5d47f17940df770be7074001145d8bee5a (diff) |
Move test utilities into a separate file, to share with testbbackupd.
Diffstat (limited to 'lib/backupstore/StoreTestUtils.h')
-rw-r--r-- | lib/backupstore/StoreTestUtils.h | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/lib/backupstore/StoreTestUtils.h b/lib/backupstore/StoreTestUtils.h new file mode 100644 index 00000000..ad4ff14c --- /dev/null +++ b/lib/backupstore/StoreTestUtils.h @@ -0,0 +1,79 @@ +// -------------------------------------------------------------------------- +// +// File +// Name: StoreTestUtils.h +// Purpose: Utilities for housekeeping and checking a test store +// Created: 18/02/14 +// +// -------------------------------------------------------------------------- + +#ifndef STORETESTUTILS__H +#define STORETESTUTILS__H + +class BackupProtocolCallable; +class BackupProtocolClient; +class SocketStreamTLS; +class TLSContext; + +//! Simplifies calling setUp() with the current function name in each test. +#define SETUP() if (!setUp(__FUNCTION__)) return true; // skip this test + +//! Holds the expected reference counts of each object. +extern std::vector<uint32_t> ExpectedRefCounts; + +//! Holds the PID of the currently running bbstored test server. +extern int bbstored_pid; + +//! Sets up (cleans up) test environment at the start of every test. +bool setUp(const char* function_name); + +//! Checks account for errors and shuts down daemons at end of every test. +void tearDown(); + +//! Sets the expected refcount of an object, resizing vector if necessary. +void set_refcount(int64_t ObjectID, uint32_t RefCount = 1); + +//! Initialises a TLSContext object using the standard certficate filenames. +void init_context(TLSContext& rContext); + +//! Opens a connection to the server (bbstored). +std::auto_ptr<SocketStreamTLS> open_conn(const char *hostname, + TLSContext& rContext); + +//! Opens a connection to the server (bbstored) and logs in. +std::auto_ptr<BackupProtocolClient> test_server_login(const char *hostname, + TLSContext& rContext, std::auto_ptr<SocketStreamTLS>& rapConn); + +//! Checks the number of files of each type in the store against expectations. +bool check_num_files(int files, int old, int deleted, int dirs); + +//! Checks the number of blocks in files of each type against expectations. +bool check_num_blocks(BackupProtocolCallable& Client, int Current, int Old, + int Deleted, int Dirs, int Total); + +//! Checks an account for errors, returning true if it's OK, for use in assertions. +bool check_account(Log::Level log_level = Log::WARNING); + +//! Runs housekeeping on an account, to remove old and deleted files if necessary. +int64_t run_housekeeping(BackupStoreAccountDatabase::Entry& rAccount); + +//! Runs housekeeping and checks the account, returning true if it's OK. +bool run_housekeeping_and_check_account(); + +//! Tests that all object reference counts have the expected values. +bool check_reference_counts(); + +//! Starts the bbstored test server running, which must not already be running. +bool StartServer(); + +//! Stops the currently running bbstored test server. +bool StopServer(); + +//! Creates the standard test account, for example after delete_account(). +bool create_account(int soft, int hard); + +//! Deletes the standard test account, for testing behaviour with no account. +bool delete_account(); + +#endif // STORETESTUTILS__H + |