Changeset 2535 for box/trunk/test
- Timestamp:
- 28/06/2009 13:04:25 (3 years ago)
- File:
-
- 1 edited
-
box/trunk/test/backupstore/testbackupstore.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/test/backupstore/testbackupstore.cpp
r2481 r2535 35 35 #include "BackupClientCryptoKeys.h" 36 36 #include "ServerControl.h" 37 #include "BackupStoreAccountDatabase.h" 38 #include "BackupStoreRefCountDatabase.h" 37 39 38 40 #include "MemLeakFindOn.h" … … 471 473 } 472 474 473 int64_t create_test_data_subdirs(BackupProtocolClient &protocol, int64_t indir, const char *name, int depth) 475 void create_file_in_dir(std::string name, std::string source, int64_t parentId, 476 BackupProtocolClient &protocol, BackupStoreRefCountDatabase& rRefCount) 477 { 478 BackupStoreFilenameClear name_encoded("file_One"); 479 std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile( 480 source.c_str(), parentId, name_encoded)); 481 std::auto_ptr<BackupProtocolClientSuccess> stored( 482 protocol.QueryStoreFile( 483 parentId, 484 0x123456789abcdefLL, /* modification time */ 485 0x7362383249872dfLL, /* attr hash */ 486 0, /* diff from ID */ 487 name_encoded, 488 *upload)); 489 int64_t objectId = stored->GetObjectID(); 490 TEST_EQUAL(objectId, rRefCount.GetLastObjectIDUsed()); 491 TEST_EQUAL(1, rRefCount.GetRefCount(objectId)) 492 } 493 494 int64_t create_test_data_subdirs(BackupProtocolClient &protocol, int64_t indir, 495 const char *name, int depth, BackupStoreRefCountDatabase& rRefCount) 474 496 { 475 497 // Create a directory … … 487 509 488 510 printf("Create subdirs, depth = %d, dirid = %llx\n", depth, subdirid); 511 512 std::auto_ptr<BackupStoreAccountDatabase> apAccounts( 513 BackupStoreAccountDatabase::Read("testfiles/accounts.txt")); 514 std::auto_ptr<BackupStoreRefCountDatabase> apReferences( 515 BackupStoreRefCountDatabase::Load( 516 apAccounts->GetEntry(0x1234567), true)); 517 TEST_EQUAL(subdirid, rRefCount.GetLastObjectIDUsed()); 518 TEST_EQUAL(1, rRefCount.GetRefCount(subdirid)) 489 519 490 520 // Put more directories in it, if we haven't gone down too far 491 521 if(depth > 0) 492 522 { 493 create_test_data_subdirs(protocol, subdirid, "dir_One", depth - 1); 494 create_test_data_subdirs(protocol, subdirid, "dir_Two", depth - 1); 523 create_test_data_subdirs(protocol, subdirid, "dir_One", 524 depth - 1, rRefCount); 525 create_test_data_subdirs(protocol, subdirid, "dir_Two", 526 depth - 1, rRefCount); 495 527 } 496 528 497 529 // Stick some files in it 498 { 499 BackupStoreFilenameClear name("file_One"); 500 std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile("testfiles/file1", subdirid, name)); 501 std::auto_ptr<BackupProtocolClientSuccess> stored(protocol.QueryStoreFile( 502 subdirid, 503 0x123456789abcdefLL, /* modification time */ 504 0x7362383249872dfLL, /* attr hash */ 505 0, /* diff from ID */ 506 name, 507 *upload)); 508 } 509 { 510 BackupStoreFilenameClear name("file_Two"); 511 std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile("testfiles/file1", subdirid, name)); 512 std::auto_ptr<BackupProtocolClientSuccess> stored(protocol.QueryStoreFile( 513 subdirid, 514 0x123456789abcdefLL, /* modification time */ 515 0x7362383249872dfLL, /* attr hash */ 516 0, /* diff from ID */ 517 name, 518 *upload)); 519 } 520 { 521 BackupStoreFilenameClear name("file_Three"); 522 std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile("testfiles/file1", subdirid, name)); 523 std::auto_ptr<BackupProtocolClientSuccess> stored(protocol.QueryStoreFile( 524 subdirid, 525 0x123456789abcdefLL, /* modification time */ 526 0x7362383249872dfLL, /* attr hash */ 527 0, /* diff from ID */ 528 name, 529 *upload)); 530 } 531 530 create_file_in_dir("file_One", "testfiles/file1", subdirid, protocol, 531 rRefCount); 532 create_file_in_dir("file_Two", "testfiles/file1", subdirid, protocol, 533 rRefCount); 534 create_file_in_dir("file_Three", "testfiles/file1", subdirid, protocol, 535 rRefCount); 532 536 return subdirid; 533 537 } … … 886 890 } 887 891 888 889 int test_server(const char *hostname) 890 { 891 // Context 892 TLSContext context; 893 context.Initialise(false /* client */, 892 void init_context(TLSContext& rContext) 893 { 894 rContext.Initialise(false /* client */, 894 895 "testfiles/clientCerts.pem", 895 896 "testfiles/clientPrivKey.pem", 896 897 "testfiles/clientTrustedCAs.pem"); 898 } 899 900 std::auto_ptr<SocketStreamTLS> open_conn(const char *hostname, 901 TLSContext& rContext) 902 { 903 init_context(rContext); 904 std::auto_ptr<SocketStreamTLS> conn(new SocketStreamTLS); 905 conn->Open(rContext, Socket::TypeINET, hostname, BOX_PORT_BBSTORED); 906 return conn; 907 } 908 909 std::auto_ptr<BackupProtocolClient> test_server_login(SocketStreamTLS& rConn) 910 { 911 // Make a protocol 912 std::auto_ptr<BackupProtocolClient> protocol(new 913 BackupProtocolClient(rConn)); 914 915 // Check the version 916 std::auto_ptr<BackupProtocolClientVersion> serverVersion( 917 protocol->QueryVersion(BACKUP_STORE_SERVER_VERSION)); 918 TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); 919 920 // Login 921 std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf( 922 protocol->QueryLogin(0x01234567, 0)); 923 924 return protocol; 925 } 926 927 int test_server(const char *hostname) 928 { 929 TLSContext context; 930 std::auto_ptr<SocketStreamTLS> conn = open_conn(hostname, context); 931 std::auto_ptr<BackupProtocolClient> apProtocol( 932 test_server_login(*conn)); 933 BackupProtocolClient& protocol(*apProtocol); 897 934 898 935 // Make some test attributes … … 912 949 // BLOCK 913 950 { 914 // Open a connection to the server915 SocketStreamTLS conn;916 conn.Open(context, Socket::TypeINET, hostname, BOX_PORT_BBSTORED);917 918 // Make a protocol919 BackupProtocolClient protocol(conn);920 921 951 // Get it logging 922 952 FILE *protocolLog = ::fopen("testfiles/protocol.log", "w"); 923 953 TEST_THAT(protocolLog != 0); 924 954 protocol.SetLogToFile(protocolLog); 925 926 // Check the version927 std::auto_ptr<BackupProtocolClientVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION));928 TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION);929 930 // Login931 std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, 0));932 933 // Check marker is 0934 TEST_THAT(loginConf->GetClientStoreMarker() == 0);935 955 936 956 #ifndef WIN32 … … 1436 1456 1437 1457 //} skip: 1458 1459 std::auto_ptr<BackupStoreAccountDatabase> apAccounts( 1460 BackupStoreAccountDatabase::Read( 1461 "testfiles/accounts.txt")); 1462 std::auto_ptr<BackupStoreRefCountDatabase> apRefCount( 1463 BackupStoreRefCountDatabase::Load( 1464 apAccounts->GetEntry(0x1234567), true)); 1438 1465 1439 1466 // Create some nice recursive directories 1440 1467 int64_t dirtodelete = create_test_data_subdirs(protocol, 1441 BackupProtocolClientListDirectory::RootDirectory, "test_delete", 6 /* depth */); 1468 BackupProtocolClientListDirectory::RootDirectory, 1469 "test_delete", 6 /* depth */, *apRefCount); 1442 1470 1443 1471 // And delete them … … 1761 1789 TEST_THAT(TestGetFileSize("testfiles/accounts.txt") > 8); 1762 1790 // make sure something is written to it 1791 1792 std::auto_ptr<BackupStoreAccountDatabase> apAccounts( 1793 BackupStoreAccountDatabase::Read("testfiles/accounts.txt")); 1794 1795 std::auto_ptr<BackupStoreRefCountDatabase> apReferences( 1796 BackupStoreRefCountDatabase::Load( 1797 apAccounts->GetEntry(0x1234567), true)); 1798 TEST_EQUAL(BACKUPSTORE_ROOT_DIRECTORY_ID, 1799 apReferences->GetLastObjectIDUsed()); 1800 TEST_EQUAL(1, apReferences->GetRefCount(BACKUPSTORE_ROOT_DIRECTORY_ID)) 1801 apReferences.reset(); 1802 1803 // Delete the refcount database and log in again, 1804 // check that it is recreated automatically but with 1805 // no objects in it, to ensure seamless upgrade. 1806 TEST_EQUAL(0, ::unlink("testfiles/0_0/backup/01234567/refcount.db.rfw")); 1807 1808 // Context 1809 TLSContext context; 1810 std::auto_ptr<SocketStreamTLS> conn = open_conn("localhost", 1811 context); 1812 test_server_login(*conn)->QueryFinished(); 1813 1814 apReferences = BackupStoreRefCountDatabase::Load( 1815 apAccounts->GetEntry(0x1234567), true); 1816 TEST_EQUAL(0, apReferences->GetLastObjectIDUsed()); 1763 1817 1764 1818 TEST_THAT(ServerIsAlive(pid));
Note: See TracChangeset
for help on using the changeset viewer.
