Changeset 919


Ignore:
Timestamp:
01/09/2006 09:03:32 (5 years ago)
Author:
chris
Message:

Revert to trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/chris/merge/test/backupstore/testbackupstore.cpp

    r710 r919  
    426426         
    427427        free(data); 
    428         in.Close(); 
    429         TEST_THAT(unlink("testfiles/test_download") == 0); 
     428        unlink("testfiles/test_download"); 
    430429} 
    431430 
     
    932931                TEST_THAT(loginConf->GetClientStoreMarker() == 0); 
    933932 
    934 #ifndef WIN32 
    935933                // Check that we can't open a new connection which requests write permissions 
    936934                { 
     
    944942                        protocol.QueryFinished(); 
    945943                } 
    946 #endif 
    947944                 
    948945                // Set the client store marker 
    949946                protocol.QuerySetClientStoreMarker(0x8732523ab23aLL); 
    950947 
    951 #ifndef WIN32 
    952948                // Open a new connection which is read only 
    953949                SocketStreamTLS connReadOnly; 
     
    968964                        TEST_THAT(loginConf->GetClientStoreMarker() == 0x8732523ab23aLL); 
    969965                } 
    970 #else // WIN32 
    971                 BackupProtocolClient& protocolReadOnly(protocol); 
    972 #endif 
    973966 
    974967                test_server_1(protocol, protocolReadOnly); 
     968 
     969 
    975970                // Create and upload some test files 
    976971                int64_t maxID = 0; 
     
    14441439                         
    14451440                // Finish the connections 
    1446 #ifndef WIN32 
    14471441                protocolReadOnly.QueryFinished(); 
    1448 #endif 
    14491442                protocol.QueryFinished(); 
    14501443                 
    14511444                // Close logs 
    1452 #ifndef WIN32 
    14531445                ::fclose(protocolReadOnlyLog); 
    1454 #endif 
    14551446                ::fclose(protocolLog); 
    14561447        } 
     
    15301521                // The test block to a file 
    15311522                { 
    1532                         FileStream f("testfiles" DIRECTORY_SEPARATOR  
    1533                                 "testenc1", O_WRONLY | O_CREAT | O_EXCL); 
     1523                        FileStream f("testfiles/testenc1", O_WRONLY | O_CREAT | O_EXCL); 
    15341524                        f.Write(encfile, sizeof(encfile)); 
    15351525                } 
     
    15371527                // Encode it 
    15381528                { 
    1539                         FileStream out("testfiles" DIRECTORY_SEPARATOR  
    1540                                 "testenc1_enc", O_WRONLY | O_CREAT | O_EXCL); 
    1541                         BackupStoreFilenameClear name("testfiles" 
    1542                                 DIRECTORY_SEPARATOR "testenc1"); 
    1543  
    1544                         std::auto_ptr<IOStream> encoded( 
    1545                                 BackupStoreFile::EncodeFile( 
    1546                                         "testfiles" DIRECTORY_SEPARATOR 
    1547                                         "testenc1", 32, name)); 
     1529                        FileStream out("testfiles/testenc1_enc", O_WRONLY | O_CREAT | O_EXCL); 
     1530                        BackupStoreFilenameClear name("testfiles/testenc1"); 
     1531 
     1532                        std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/testenc1", 32, name)); 
    15481533                        encoded->CopyStreamTo(out); 
    15491534                } 
     
    15511536                // Verify it 
    15521537                { 
    1553                         FileStream enc("testfiles" DIRECTORY_SEPARATOR  
    1554                                 "testenc1_enc"); 
     1538                        FileStream enc("testfiles/testenc1_enc"); 
    15551539                        TEST_THAT(BackupStoreFile::VerifyEncodedFileFormat(enc) == true); 
    15561540                } 
     
    15581542                // Decode it 
    15591543                { 
    1560                         FileStream enc("testfiles" DIRECTORY_SEPARATOR  
    1561                                 "testenc1_enc"); 
    1562                         BackupStoreFile::DecodeFile(enc, "testfiles" 
    1563                                 DIRECTORY_SEPARATOR "testenc1_orig",  
    1564                                 IOStream::TimeOutInfinite); 
     1544                        FileStream enc("testfiles/testenc1_enc"); 
     1545                        BackupStoreFile::DecodeFile(enc, "testfiles/testenc1_orig", IOStream::TimeOutInfinite); 
    15651546                } 
    15661547                 
    15671548                // Read in rebuilt original, and compare contents 
    15681549                { 
    1569                         TEST_THAT(TestGetFileSize("testfiles"  
    1570                                 DIRECTORY_SEPARATOR "testenc1_orig")  
    1571                                 == sizeof(encfile)); 
    1572                         FileStream in("testfiles" DIRECTORY_SEPARATOR  
    1573                                 "testenc1_orig"); 
     1550                        TEST_THAT(TestGetFileSize("testfiles/testenc1_orig") == sizeof(encfile)); 
     1551                        FileStream in("testfiles/testenc1_orig"); 
    15741552                        int encfile_i[ENCFILE_SIZE]; 
    15751553                        in.Read(encfile_i, sizeof(encfile_i)); 
     
    15791557                // Check how many blocks it had, and test the stream based interface 
    15801558                { 
    1581                         FileStream enc("testfiles" DIRECTORY_SEPARATOR  
    1582                                 "testenc1_enc"); 
     1559                        FileStream enc("testfiles/testenc1_enc"); 
    15831560                        std::auto_ptr<BackupStoreFile::DecodedStream> decoded(BackupStoreFile::DecodeFileStream(enc, IOStream::TimeOutInfinite)); 
    15841561                        CollectInBufferStream d; 
     
    15941571                { 
    15951572                        #define FILE_SIZE_JUST_OVER     ((4096*2)+58) 
    1596                         FileStream f("testfiles" DIRECTORY_SEPARATOR  
    1597                                 "testenc2", O_WRONLY | O_CREAT | O_EXCL); 
     1573                        FileStream f("testfiles/testenc2", O_WRONLY | O_CREAT | O_EXCL); 
    15981574                        f.Write(encfile + 2, FILE_SIZE_JUST_OVER); 
    1599                         f.Close(); 
    16001575                        BackupStoreFilenameClear name("testenc2"); 
    1601                         std::auto_ptr<IOStream> encoded( 
    1602                                 BackupStoreFile::EncodeFile( 
    1603                                         "testfiles" DIRECTORY_SEPARATOR 
    1604                                         "testenc2", 32, name)); 
     1576                        std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/testenc2", 32, name)); 
    16051577                        CollectInBufferStream e; 
    16061578                        encoded->CopyStreamTo(e); 
     
    16181590                // Test that reordered streams work too 
    16191591                { 
    1620                         FileStream enc("testfiles" DIRECTORY_SEPARATOR  
    1621                                 "testenc1_enc"); 
     1592                        FileStream enc("testfiles/testenc1_enc"); 
    16221593                        std::auto_ptr<IOStream> reordered(BackupStoreFile::ReorderFileToStreamOrder(&enc, false)); 
    16231594                        std::auto_ptr<BackupStoreFile::DecodedStream> decoded(BackupStoreFile::DecodeFileStream(*reordered, IOStream::TimeOutInfinite)); 
     
    16311602                } 
    16321603                 
    1633 #ifndef WIN32            
    16341604                // Try out doing this on a symlink 
    16351605                { 
     
    16451615                        BackupStoreFile::DecodeFile(b, "testfiles/testsymlink_2", IOStream::TimeOutInfinite); 
    16461616                } 
    1647 #endif 
    16481617        } 
    16491618 
     
    16511620        { 
    16521621                RaidFileWrite::CreateDirectory(0, "test-info"); 
    1653                 BackupStoreInfo::CreateNew(76, "test-info" DIRECTORY_SEPARATOR,  
    1654                         0, 3461231233455433LL, 2934852487LL); 
    1655                 TEST_CHECK_THROWS(BackupStoreInfo::CreateNew(76,  
    1656                         "test-info" DIRECTORY_SEPARATOR, 0, 0, 0),  
    1657                         RaidFileException, CannotOverwriteExistingFile); 
    1658                 std::auto_ptr<BackupStoreInfo> info( 
    1659                         BackupStoreInfo::Load(76,  
    1660                                 "test-info" DIRECTORY_SEPARATOR, 0, true)); 
     1622                BackupStoreInfo::CreateNew(76, "test-info/", 0, 3461231233455433LL, 2934852487LL); 
     1623                TEST_CHECK_THROWS(BackupStoreInfo::CreateNew(76, "test-info/", 0, 0, 0), RaidFileException, CannotOverwriteExistingFile); 
     1624                std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(76, "test-info/", 0, true)); 
    16611625                TEST_CHECK_THROWS(info->Save(), BackupStoreException, StoreInfoIsReadOnly); 
    16621626                TEST_CHECK_THROWS(info->ChangeBlocksUsed(1), BackupStoreException, StoreInfoIsReadOnly); 
     
    16671631        } 
    16681632        { 
    1669                 std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(76,  
    1670                         "test-info" DIRECTORY_SEPARATOR, 0, false)); 
     1633                std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(76, "test-info/", 0, false)); 
    16711634                info->ChangeBlocksUsed(8); 
    16721635                info->ChangeBlocksInOldFiles(9); 
     
    16861649        } 
    16871650        { 
    1688                 std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(76,  
    1689                         "test-info" DIRECTORY_SEPARATOR, 0, true)); 
     1651                std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(76, "test-info/", 0, true)); 
    16901652                TEST_THAT(info->GetBlocksUsed() == 7); 
    16911653                TEST_THAT(info->GetBlocksInOldFiles() == 5); 
     
    17051667        TLSContext context; 
    17061668        context.Initialise(false /* client */, 
    1707                         "testfiles" DIRECTORY_SEPARATOR "clientCerts.pem", 
    1708                         "testfiles" DIRECTORY_SEPARATOR "clientPrivKey.pem", 
    1709                         "testfiles" DIRECTORY_SEPARATOR "clientTrustedCAs.pem"); 
     1669                        "testfiles/clientCerts.pem", 
     1670                        "testfiles/clientPrivKey.pem", 
     1671                        "testfiles/clientTrustedCAs.pem"); 
    17101672 
    17111673        // First, try logging in without an account having been created... just make sure login fails. 
    1712  
    1713 #ifdef WIN32 
    1714         int pid = LaunchServer("..\\..\\bin\\bbstored\\bbstored testfiles/bbstored.conf", "testfiles/bbstored.pid"); 
    1715 #else 
    17161674        int pid = LaunchServer("../../bin/bbstored/bbstored testfiles/bbstored.conf", "testfiles/bbstored.pid"); 
    1717 #endif 
    1718  
    17191675        TEST_THAT(pid != -1 && pid != 0); 
    17201676        if(pid > 0) 
     
    17451701 
    17461702                // Create an account for the test client 
    1747 #ifdef WIN32 
    1748                 TEST_THAT_ABORTONFAIL(::system("..\\..\\bin\\bbstoreaccounts\\bbstoreaccounts -c testfiles/bbstored.conf create 01234567 0 10000B 20000B") == 0); 
    1749 #else 
    17501703                TEST_THAT_ABORTONFAIL(::system("../../bin/bbstoreaccounts/bbstoreaccounts -c testfiles/bbstored.conf create 01234567 0 10000B 20000B") == 0); 
    17511704                TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); 
    1752 #endif 
    1753  
    17541705                TEST_THAT(TestDirExists("testfiles/0_0/backup/01234567")); 
    17551706                TEST_THAT(TestDirExists("testfiles/0_1/backup/01234567")); 
     
    17751726                ::sleep(1); 
    17761727                TEST_THAT(!ServerIsAlive(pid)); 
    1777 #ifndef WIN32 
    17781728                TestRemoteProcessMemLeaks("bbstored.memleaks"); 
    1779 #endif 
    17801729                 
    17811730                // Set a new limit on the account -- leave the hard limit high to make sure the target for 
    17821731                // freeing space is the soft limit. 
    1783  
    1784 #ifdef WIN32 
    1785                 TEST_THAT_ABORTONFAIL(::system("..\\..\\bin\\bbstoreaccounts\\bbstoreaccounts -c testfiles/bbstored.conf setlimit 01234567 10B 20000B") == 0); 
    1786 #else 
    17871732                TEST_THAT_ABORTONFAIL(::system("../../bin/bbstoreaccounts/bbstoreaccounts -c testfiles/bbstored.conf setlimit 01234567 10B 20000B") == 0); 
    17881733                TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); 
    1789 #endif 
    17901734 
    17911735                // Start things up 
    1792 #ifdef WIN32 
    1793                 pid = LaunchServer("..\\..\\bin\\bbstored\\bbstored testfiles/bbstored.conf", "testfiles/bbstored.pid"); 
    1794 #else 
    17951736                pid = LaunchServer("../../bin/bbstored/bbstored testfiles/bbstored.conf", "testfiles/bbstored.pid"); 
    1796 #endif 
    1797  
    17981737                ::sleep(1); 
    17991738                TEST_THAT(ServerIsAlive(pid)); 
     
    18201759                 
    18211760                // Set a really small hard limit 
    1822 #ifdef WIN32 
    1823                 TEST_THAT_ABORTONFAIL(::system("..\\..\\bin\\bbstoreaccounts\\bbstoreaccounts -c testfiles/bbstored.conf setlimit 01234567 10B 20B") == 0); 
    1824 #else 
    18251761                TEST_THAT_ABORTONFAIL(::system("../../bin/bbstoreaccounts/bbstoreaccounts -c testfiles/bbstored.conf setlimit 01234567 10B 20B") == 0); 
    18261762                TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); 
    1827 #endif 
    18281763 
    18291764                // Try to upload a file and create a directory, and check an error is generated 
     
    18741809                ::sleep(1); 
    18751810                TEST_THAT(!ServerIsAlive(pid)); 
    1876  
    1877 #ifndef WIN32 
    18781811                TestRemoteProcessMemLeaks("bbstored.memleaks"); 
    1879 #endif 
    18801812        } 
    18811813 
     
    18891821        // Create an account for the test client 
    18901822        TEST_THAT_ABORTONFAIL(::system("../../bin/bbstoreaccounts/bbstoreaccounts -c testfiles/bbstored.conf create 01234567 0 30000B 40000B") == 0); 
    1891  
    1892 #ifndef WIN32 
    18931823        TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); 
    1894 #endif 
    18951824 
    18961825        // First, try logging in without an account having been created... just make sure login fails. 
    1897  
    1898 #ifdef WIN32 
    1899         int pid = LaunchServer("..\\..\\bin\\bbstored\\bbstored testfiles/bbstored_multi.conf", "testfiles/bbstored.pid"); 
    1900 #else 
    19011826        int pid = LaunchServer("../../bin/bbstored/bbstored testfiles/bbstored_multi.conf", "testfiles/bbstored.pid"); 
    1902 #endif 
    1903  
    19041827        TEST_THAT(pid != -1 && pid != 0); 
    19051828        if(pid > 0) 
     
    19181841                ::sleep(1); 
    19191842                TEST_THAT(!ServerIsAlive(pid)); 
    1920 #ifndef WIN32 
    19211843                TestRemoteProcessMemLeaks("bbstored.memleaks"); 
    1922 #endif 
    19231844        } 
    19241845 
     
    19271848} 
    19281849 
    1929 #ifdef WIN32 
    1930 WCHAR* ConvertUtf8ToWideString(const char* pString); 
    1931 std::string ConvertPathToAbsoluteUnicode(const char *pFileName); 
    1932 #endif 
    1933  
    19341850int test(int argc, const char *argv[]) 
    19351851{ 
    1936 #ifdef WIN32 
    1937         // Under win32 we must initialise the Winsock library 
    1938         // before using sockets 
    1939  
    1940         WSADATA info; 
    1941         TEST_THAT(WSAStartup(0x0101, &info) != SOCKET_ERROR) 
    1942  
    1943         // this had better work, or bbstored will die when combining diffs 
    1944         char* file = "foo"; 
    1945         std::string abs = ConvertPathToAbsoluteUnicode(file); 
    1946         WCHAR* wfile = ConvertUtf8ToWideString(abs.c_str()); 
    1947  
    1948         DWORD accessRights = FILE_READ_ATTRIBUTES |  
    1949                 FILE_LIST_DIRECTORY | FILE_READ_EA | FILE_WRITE_ATTRIBUTES | 
    1950                 FILE_WRITE_DATA | FILE_WRITE_EA /*| FILE_ALL_ACCESS*/; 
    1951         DWORD shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; 
    1952  
    1953         HANDLE h1 = CreateFileW(wfile, accessRights, shareMode, 
    1954                 NULL, OPEN_ALWAYS, FILE_FLAG_BACKUP_SEMANTICS, NULL); 
    1955         assert(h1 != INVALID_HANDLE_VALUE); 
    1956         TEST_THAT(h1 != INVALID_HANDLE_VALUE); 
    1957  
    1958         accessRights = FILE_READ_ATTRIBUTES |  
    1959                 FILE_LIST_DIRECTORY | FILE_READ_EA; 
    1960  
    1961         HANDLE h2 = CreateFileW(wfile, accessRights, shareMode, 
    1962                 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); 
    1963         assert(h2 != INVALID_HANDLE_VALUE); 
    1964         TEST_THAT(h2 != INVALID_HANDLE_VALUE); 
    1965  
    1966         CloseHandle(h2); 
    1967         CloseHandle(h1); 
    1968  
    1969         h1 = openfile("foo", O_CREAT | O_RDWR, 0); 
    1970         TEST_THAT(h1 != INVALID_HANDLE_VALUE); 
    1971         h2 = openfile("foo", O_RDWR, 0); 
    1972         TEST_THAT(h2 != INVALID_HANDLE_VALUE); 
    1973         CloseHandle(h2); 
    1974         CloseHandle(h1); 
    1975 #endif 
    1976  
    19771852        // SSL library 
    19781853        SSLLib::Initialise(); 
     
    19911866        // Use the setup crypto command to set up all these keys, so that the bbackupquery command can be used 
    19921867        // for seeing what's going on. 
    1993 #ifdef WIN32 
    1994         BackupClientCryptoKeys_Setup("testfiles\\bbackupd.keys");        
    1995 #else 
    19961868        BackupClientCryptoKeys_Setup("testfiles/bbackupd.keys");         
    1997 #endif 
    19981869         
    19991870        // encode in some filenames -- can't do static initialisation because the key won't be set up when these are initialised 
Note: See TracChangeset for help on using the changeset viewer.