diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/backupstore/testbackupstore.cpp | 75 | ||||
-rw-r--r-- | test/backupstorepatch/testbackupstorepatch.cpp | 16 | ||||
-rw-r--r-- | test/basicserver/testbasicserver.cpp | 26 | ||||
-rw-r--r-- | test/bbackupd/testbbackupd.cpp | 51 |
4 files changed, 61 insertions, 107 deletions
diff --git a/test/backupstore/testbackupstore.cpp b/test/backupstore/testbackupstore.cpp index 901cf31a..24144d65 100644 --- a/test/backupstore/testbackupstore.cpp +++ b/test/backupstore/testbackupstore.cpp @@ -661,18 +661,9 @@ void recursive_count_objects(const char *hostname, int64_t id, recursive_count_o "testfiles/clientTrustedCAs.pem"); // Get a connection - // TODO FIXME replace with test_server_login - SocketStreamTLS connReadOnly; - connReadOnly.Open(context, Socket::TypeINET, hostname, - BOX_PORT_BBSTORED_TEST); - BackupProtocolClient protocolReadOnly(connReadOnly); + BackupProtocolLocal2 protocolReadOnly(0x01234567, "test", + "backup/01234567/", 0, false); - { - std::auto_ptr<BackupProtocolVersion> serverVersion(protocolReadOnly.QueryVersion(BACKUP_STORE_SERVER_VERSION)); - TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); - std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocolReadOnly.QueryLogin(0x01234567, BackupProtocolLogin::Flags_ReadOnly)); - } - // Count objects recursive_count_objects_r(protocolReadOnly, id, results); @@ -1171,23 +1162,16 @@ bool test_multiple_uploads() SETUP(); TEST_THAT_THROWONFAIL(StartServer()); - std::auto_ptr<SocketStreamTLS> conn; std::auto_ptr<BackupProtocolCallable> apProtocol( - test_server_login("localhost", context, conn).release()); + test_server_login("localhost", context).release()); #ifndef WIN32 // Open a new connection which is read only - std::auto_ptr<SocketStreamTLS> conn2(new SocketStreamTLS); - // TODO FIXME replace with test_server_login - conn2->Open(context, Socket::TypeINET, "localhost", - BOX_PORT_BBSTORED_TEST); - BackupProtocolClient protocolReadOnly(*conn2); - - { - std::auto_ptr<BackupProtocolVersion> serverVersion(protocolReadOnly.QueryVersion(BACKUP_STORE_SERVER_VERSION)); - TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); - std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocolReadOnly.QueryLogin(0x01234567, BackupProtocolLogin::Flags_ReadOnly)); - } + // TODO FIXME replace protocolReadOnly with apProtocolReadOnly. + std::auto_ptr<BackupProtocolCallable> apProtocolReadOnly = + test_server_login("localhost", context, + BackupProtocolLogin::Flags_ReadOnly); + BackupProtocolCallable& protocolReadOnly(*apProtocolReadOnly); #else // WIN32 BackupProtocolCallable& protocolReadOnly(*apProtocol); #endif @@ -1266,7 +1250,7 @@ bool test_multiple_uploads() apProtocol->QueryFinished(); TEST_THAT(run_housekeeping_and_check_account()); - apProtocol = test_server_login("localhost", context, conn); + apProtocol = test_server_login("localhost", context); TEST_THAT(check_num_files(expected_num_current_files, expected_num_old_files, 0, 1)); @@ -1371,7 +1355,7 @@ bool test_multiple_uploads() " -c testfiles/bbstored.conf check 01234567 fix") == 0); TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); - apProtocol = test_server_login("localhost", context, conn); + apProtocol = test_server_login("localhost", context); TEST_THAT(check_num_files(UPLOAD_NUM - 4, 3, 2, 1)); @@ -1672,7 +1656,7 @@ bool test_multiple_uploads() apProtocol->QueryFinished(); TEST_THAT(run_housekeeping_and_check_account()); - apProtocol = test_server_login("localhost", context, conn); + apProtocol = test_server_login("localhost", context); // Query names -- test that invalid stuff returns not found OK { @@ -2053,12 +2037,9 @@ bool test_login_without_account() // BLOCK { // Open a connection to the server - SocketStreamTLS conn; - conn.Open(context, Socket::TypeINET, "localhost", - BOX_PORT_BBSTORED_TEST); - - // Make a protocol - BackupProtocolClient protocol(conn); + std::auto_ptr<BackupProtocolCallable> apProtocol(new + BackupProtocolClient(open_conn("localhost", context))); + BackupProtocolCallable& protocol(*apProtocol); // Check the version std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); @@ -2140,12 +2121,9 @@ bool test_login_with_disabled_account() // BLOCK { // Open a connection to the server - SocketStreamTLS conn; - conn.Open(context, Socket::TypeINET, "localhost", - BOX_PORT_BBSTORED_TEST); - - // Make a protocol - BackupProtocolClient protocol(conn); + std::auto_ptr<BackupProtocolCallable> apProtocol(new + BackupProtocolClient(open_conn("localhost", context))); + BackupProtocolCallable& protocol(*apProtocol); // Check the version std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); @@ -2189,8 +2167,7 @@ bool test_login_with_no_refcount_db() // the refcount db. TEST_EQUAL(0, ::unlink("testfiles/0_0/backup/01234567/refcount.rdb.rfw")); - std::auto_ptr<SocketStreamTLS> conn; - TEST_CHECK_THROWS(test_server_login("localhost", context, conn), + TEST_CHECK_THROWS(test_server_login("localhost", context), ConnectionException, Conn_TLSReadFailed); TEST_THAT(ServerIsAlive(bbstored_pid)); @@ -2328,20 +2305,10 @@ bool test_account_limits_respected() // Try to upload a file and create a directory, and check an error is generated { // Open a connection to the server - SocketStreamTLS conn; - conn.Open(context, Socket::TypeINET, "localhost", - BOX_PORT_BBSTORED_TEST); - - // Make a protocol - BackupProtocolClient protocol(conn); - - // Check the version - std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); - TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); + std::auto_ptr<BackupProtocolCallable> apProtocol = + test_server_login("localhost", context); + BackupProtocolCallable& protocol(*apProtocol); - // Login - std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, 0)); - int64_t modtime = 0; write_test_file(3); diff --git a/test/backupstorepatch/testbackupstorepatch.cpp b/test/backupstorepatch/testbackupstorepatch.cpp index 42594652..96b93308 100644 --- a/test/backupstorepatch/testbackupstorepatch.cpp +++ b/test/backupstorepatch/testbackupstorepatch.cpp @@ -345,12 +345,13 @@ int test(int argc, const char *argv[]) { // Open a connection to the server - SocketStreamTLS conn; - conn.Open(context, Socket::TypeINET, "localhost", + SocketStreamTLS *pConn = new SocketStreamTLS; + std::auto_ptr<SocketStream> apConn(pConn); + pConn->Open(context, Socket::TypeINET, "localhost", BOX_PORT_BBSTORED_TEST); // Make a protocol - BackupProtocolClient protocol(conn); + BackupProtocolClient protocol(apConn); // Login { @@ -454,7 +455,6 @@ int test(int argc, const char *argv[]) // Finish the connection protocol.QueryFinished(); - conn.Close(); } // Fill in initial dependency information @@ -528,10 +528,11 @@ int test(int argc, const char *argv[]) } // Open a connection to the server (need to do this each time, otherwise housekeeping won't delete files) - SocketStreamTLS conn; - conn.Open(context, Socket::TypeINET, "localhost", + SocketStreamTLS *pConn = new SocketStreamTLS; + std::auto_ptr<SocketStream> apConn(pConn); + pConn->Open(context, Socket::TypeINET, "localhost", BOX_PORT_BBSTORED_TEST); - BackupProtocolClient protocol(conn); + BackupProtocolClient protocol(apConn); { std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); @@ -583,7 +584,6 @@ int test(int argc, const char *argv[]) // Close the connection protocol.QueryFinished(); - conn.Close(); // Mark one of the elements as deleted if(test_file_remove_order[deleteIndex] == -1) diff --git a/test/basicserver/testbasicserver.cpp b/test/basicserver/testbasicserver.cpp index 5a13cb45..fe06e8c2 100644 --- a/test/basicserver/testbasicserver.cpp +++ b/test/basicserver/testbasicserver.cpp @@ -170,7 +170,7 @@ public: testserver() {} ~testserver() {} - void Connection(SocketStream &rStream); + void Connection(std::auto_ptr<SocketStream> apStream); virtual const char *DaemonName() const { @@ -210,9 +210,9 @@ const ConfigurationVerify *testserver::GetConfigVerify() const return &verify; } -void testserver::Connection(SocketStream &rStream) +void testserver::Connection(std::auto_ptr<SocketStream> apStream) { - testservers_connection(rStream); + testservers_connection(*apStream); } class testProtocolServer : public testserver @@ -221,7 +221,7 @@ public: testProtocolServer() {} ~testProtocolServer() {} - void Connection(SocketStream &rStream); + void Connection(std::auto_ptr<SocketStream> apStream); virtual const char *DaemonName() const { @@ -229,9 +229,9 @@ public: } }; -void testProtocolServer::Connection(SocketStream &rStream) +void testProtocolServer::Connection(std::auto_ptr<SocketStream> apStream) { - TestProtocolServer server(rStream); + TestProtocolServer server(apStream); TestContext context; server.DoServer(context); } @@ -243,7 +243,7 @@ public: testTLSserver() {} ~testTLSserver() {} - void Connection(SocketStreamTLS &rStream); + void Connection(std::auto_ptr<SocketStreamTLS> apStream); virtual const char *DaemonName() const { @@ -283,9 +283,9 @@ const ConfigurationVerify *testTLSserver::GetConfigVerify() const return &verify; } -void testTLSserver::Connection(SocketStreamTLS &rStream) +void testTLSserver::Connection(std::auto_ptr<SocketStreamTLS> apStream) { - testservers_connection(rStream); + testservers_connection(*apStream); } @@ -691,15 +691,15 @@ int test(int argc, const char *argv[]) TEST_THAT(ServerIsAlive(pid)); // Open a connection to it - SocketStream conn; + std::auto_ptr<SocketStream> apConn(new SocketStream); #ifdef WIN32 - conn.Open(Socket::TypeINET, "localhost", 2003); + apConn->Open(Socket::TypeINET, "localhost", 2003); #else - conn.Open(Socket::TypeUNIX, "testfiles/srv4.sock"); + apConn->Open(Socket::TypeUNIX, "testfiles/srv4.sock"); #endif // Create a protocol - TestProtocolClient protocol(conn); + TestProtocolClient protocol(apConn); // Simple query { diff --git a/test/bbackupd/testbbackupd.cpp b/test/bbackupd/testbbackupd.cpp index 4fdd12e9..28651233 100644 --- a/test/bbackupd/testbbackupd.cpp +++ b/test/bbackupd/testbbackupd.cpp @@ -468,10 +468,11 @@ void do_interrupted_restore(const TLSContext &context, int64_t restoredirid) // child process { // connect and log in - SocketStreamTLS conn; - conn.Open(context, Socket::TypeINET, "localhost", - 22011); - BackupProtocolClient protocol(conn); + SocketStreamTLS* pConn = new SocketStreamTLS; + std::auto_ptr<SocketStream> apConn(pConn); + pConn->Open(context, Socket::TypeINET, "localhost", 22011); + BackupProtocolClient protocol(apConn); + protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION); std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, @@ -567,17 +568,17 @@ int64_t SearchDir(BackupStoreDirectory& rDir, return id; } -SocketStreamTLS sSocket; - std::auto_ptr<BackupProtocolClient> Connect(TLSContext& rContext) { - sSocket.Open(rContext, Socket::TypeINET, - "localhost", 22011); - std::auto_ptr<BackupProtocolClient> connection; - connection.reset(new BackupProtocolClient(sSocket)); - connection->Handshake(); + 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(connection->QueryVersion( + serverVersion(client->QueryVersion( BACKUP_STORE_SERVER_VERSION)); if(serverVersion->GetVersion() != BACKUP_STORE_SERVER_VERSION) @@ -585,15 +586,15 @@ std::auto_ptr<BackupProtocolClient> Connect(TLSContext& rContext) THROW_EXCEPTION(BackupStoreException, WrongServerVersion); } - return connection; + return client; } std::auto_ptr<BackupProtocolClient> ConnectAndLogin(TLSContext& rContext, int flags) { - std::auto_ptr<BackupProtocolClient> connection(Connect(rContext)); - connection->QueryLogin(0x01234567, flags); - return connection; + std::auto_ptr<BackupProtocolClient> client(Connect(rContext)); + client->QueryLogin(0x01234567, flags); + return client; } std::auto_ptr<BackupStoreDirectory> ReadDirectory @@ -885,7 +886,6 @@ int test_bbackupd() } client->QueryFinished(); - sSocket.Close(); } // unpack the files for the initial test @@ -1274,7 +1274,6 @@ int test_bbackupd() TEST_THAT(check_num_blocks(*client, 10, expected_blocks_old, 0, 18, 28 + expected_blocks_old)); client->QueryFinished(); - sSocket.Close(); } std::string cmd = BBACKUPD " " + bbackupd_args + @@ -1381,7 +1380,6 @@ int test_bbackupd() TEST_THAT(check_num_files(4, 0, 0, 8)); TEST_THAT(check_num_blocks(*client, 8, 0, 0, 16, 24)); client->QueryFinished(); - sSocket.Close(); } if (failures) return 1; @@ -1515,7 +1513,6 @@ int test_bbackupd() // Log out. client->QueryFinished(); - sSocket.Close(); } BOX_TRACE("done."); @@ -1564,7 +1561,6 @@ int test_bbackupd() // Log out. client->QueryFinished(); - sSocket.Close(); } if (failures) return 1; @@ -1602,7 +1598,6 @@ int test_bbackupd() // i.e. 2 new files, 1 new directory client->QueryFinished(); - sSocket.Close(); } if (failures) return 1; @@ -1978,7 +1973,6 @@ int test_bbackupd() int64_t testDirId = SearchDir(*dir, "Test2"); TEST_THAT(testDirId == 0); client->QueryFinished(); - sSocket.Close(); } // create the location directory and unpack some files into it @@ -2018,7 +2012,6 @@ int test_bbackupd() TEST_THAT(testDirId != 0); client->QueryFinished(); - sSocket.Close(); } printf("\n==== Testing that redundant locations are deleted on time\n"); @@ -2060,7 +2053,6 @@ int test_bbackupd() TEST_THAT(testDirId != 0); client->QueryFinished(); - sSocket.Close(); } wait_for_sync_end(); @@ -2078,7 +2070,6 @@ int test_bbackupd() TEST_THAT(test_entry_deleted(*root_dir, "Test2")); client->QueryFinished(); - sSocket.Close(); } } @@ -2325,7 +2316,6 @@ int test_bbackupd() TEST_THAT(SearchDir(*dir, filename.c_str()) != 0); // Log out client->QueryFinished(); - sSocket.Close(); } // Check that bbackupquery shows the dir in console encoding @@ -3239,7 +3229,6 @@ int test_bbackupd() TEST_THAT(!SearchDir(*dir, "xx_not_this_dir_22")); TEST_THAT(!SearchDir(*dir, "somefile.excludethis")); client->QueryFinished(); - sSocket.Close(); } TEST_THAT(ServerIsAlive(bbackupd_pid)); @@ -3449,7 +3438,6 @@ int test_bbackupd() // Log out client->QueryFinished(); - sSocket.Close(); } // Compare the restored files @@ -3644,7 +3632,6 @@ int test_bbackupd() // Log out protocol->QueryFinished(); - sSocket.Close(); } catch(...) { @@ -3734,7 +3721,7 @@ int test_bbackupd() == Restore_Complete); client->QueryFinished(); - sSocket.Close(); + client.reset(); // Then check it has restored the correct stuff TEST_COMPARE(Compare_Same); @@ -3764,7 +3751,7 @@ int test_bbackupd() == Restore_Complete); client->QueryFinished(); - sSocket.Close(); + client.reset(); // Do a compare with the now undeleted files compareReturnValue = ::system(BBACKUPQUERY " " |