diff options
author | Chris Wilson <chris+github@qwirx.com> | 2014-09-04 01:36:21 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2014-09-04 01:36:21 +0000 |
commit | 5549d3f6f42a22d355b4d83402824b03106bd79a (patch) | |
tree | 8a99503d52bf6b0f24038c548da4b4a5b622c7db /test/bbackupd/testbbackupd.cpp | |
parent | e00bd81ce959d02d3fa62e7e75956162f8e70c7e (diff) |
More use of functions to simplify testbbackupd.
Merged back changes from the test refactor branch to reduce diffs.
Diffstat (limited to 'test/bbackupd/testbbackupd.cpp')
-rw-r--r-- | test/bbackupd/testbbackupd.cpp | 69 |
1 files changed, 16 insertions, 53 deletions
diff --git a/test/bbackupd/testbbackupd.cpp b/test/bbackupd/testbbackupd.cpp index 12b22856..7dd1b2c5 100644 --- a/test/bbackupd/testbbackupd.cpp +++ b/test/bbackupd/testbbackupd.cpp @@ -768,35 +768,6 @@ int64_t SearchDir(BackupStoreDirectory& rDir, return id; } -std::auto_ptr<BackupProtocolClient> Connect(TLSContext& rContext) -{ - SocketStreamTLS* pConn = new SocketStreamTLS; - std::auto_ptr<SocketStream> apConn(pConn); - pConn->Open(rContext, Socket::TypeINET, "localhost", 22011); - - std::auto_ptr<BackupProtocolClient> client; - client.reset(new BackupProtocolClient(apConn)); - client->Handshake(); - std::auto_ptr<BackupProtocolVersion> - serverVersion(client->QueryVersion( - BACKUP_STORE_SERVER_VERSION)); - if(serverVersion->GetVersion() != - BACKUP_STORE_SERVER_VERSION) - { - THROW_EXCEPTION(BackupStoreException, - WrongServerVersion); - } - return client; -} - -std::auto_ptr<BackupProtocolClient> ConnectAndLogin(TLSContext& rContext, - int flags) -{ - std::auto_ptr<BackupProtocolClient> client(Connect(rContext)); - client->QueryLogin(0x01234567, flags); - return client; -} - std::auto_ptr<BackupStoreDirectory> ReadDirectory ( BackupProtocolCallable& rClient, @@ -1077,9 +1048,23 @@ bool touch_and_wait(const std::string& filename) return true; } +TLSContext context; + #define TEST_COMPARE(...) \ TEST_THAT(compare(BackupQueries::ReturnCode::__VA_ARGS__)); +bool search_for_file(const std::string& filename) +{ + std::auto_ptr<BackupProtocolCallable> client = + connect_and_login(context, BackupProtocolLogin::Flags_ReadOnly); + + std::auto_ptr<BackupStoreDirectory> dir = ReadDirectory(*client); + int64_t testDirId = SearchDir(*dir, filename); + client->QueryFinished(); + + return (testDirId != 0); +} + int test_bbackupd() { // First, wait for a normal period to make sure the last changes @@ -1087,7 +1072,6 @@ int test_bbackupd() // wait_for_backup_operation(); // Connection gubbins - TLSContext context; context.Initialise(false /* client */, "testfiles/clientCerts.pem", "testfiles/clientPrivKey.pem", @@ -2188,15 +2172,7 @@ int test_bbackupd() TEST_THAT(!TestFileExists("testfiles/notifyran.backup-finish.2")); // Did it actually get created? Should not have been! - std::auto_ptr<BackupProtocolCallable> client = - connect_and_login(context, - BackupProtocolLogin::Flags_ReadOnly); - - std::auto_ptr<BackupStoreDirectory> dir = - ReadDirectory(*client); - int64_t testDirId = SearchDir(*dir, "Test2"); - TEST_THAT(testDirId == 0); - client->QueryFinished(); + TEST_THAT_OR(!search_for_file("Test2"), FAIL); } // create the location directory and unpack some files into it @@ -2216,20 +2192,7 @@ int test_bbackupd() TEST_THAT( TestFileExists("testfiles/notifyran.backup-finish.2")); TEST_THAT(!TestFileExists("testfiles/notifyran.backup-finish.3")); - // BLOCK - { - std::auto_ptr<BackupProtocolCallable> client = - connect_and_login(context, - BackupProtocolLogin::Flags_ReadOnly); - - std::auto_ptr<BackupStoreDirectory> dir = - ReadDirectory(*client, - BackupProtocolListDirectory::RootDirectory); - int64_t testDirId = SearchDir(*dir, "Test2"); - TEST_THAT(testDirId != 0); - - client->QueryFinished(); - } + TEST_THAT_OR(search_for_file("Test2"), FAIL); printf("\n==== Testing that redundant locations are deleted on time\n"); |