Changeset 919
- Timestamp:
- 01/09/2006 09:03:32 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
box/chris/merge/test/backupstore/testbackupstore.cpp
r710 r919 426 426 427 427 free(data); 428 in.Close(); 429 TEST_THAT(unlink("testfiles/test_download") == 0); 428 unlink("testfiles/test_download"); 430 429 } 431 430 … … 932 931 TEST_THAT(loginConf->GetClientStoreMarker() == 0); 933 932 934 #ifndef WIN32935 933 // Check that we can't open a new connection which requests write permissions 936 934 { … … 944 942 protocol.QueryFinished(); 945 943 } 946 #endif947 944 948 945 // Set the client store marker 949 946 protocol.QuerySetClientStoreMarker(0x8732523ab23aLL); 950 947 951 #ifndef WIN32952 948 // Open a new connection which is read only 953 949 SocketStreamTLS connReadOnly; … … 968 964 TEST_THAT(loginConf->GetClientStoreMarker() == 0x8732523ab23aLL); 969 965 } 970 #else // WIN32971 BackupProtocolClient& protocolReadOnly(protocol);972 #endif973 966 974 967 test_server_1(protocol, protocolReadOnly); 968 969 975 970 // Create and upload some test files 976 971 int64_t maxID = 0; … … 1444 1439 1445 1440 // Finish the connections 1446 #ifndef WIN321447 1441 protocolReadOnly.QueryFinished(); 1448 #endif1449 1442 protocol.QueryFinished(); 1450 1443 1451 1444 // Close logs 1452 #ifndef WIN321453 1445 ::fclose(protocolReadOnlyLog); 1454 #endif1455 1446 ::fclose(protocolLog); 1456 1447 } … … 1530 1521 // The test block to a file 1531 1522 { 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); 1534 1524 f.Write(encfile, sizeof(encfile)); 1535 1525 } … … 1537 1527 // Encode it 1538 1528 { 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)); 1548 1533 encoded->CopyStreamTo(out); 1549 1534 } … … 1551 1536 // Verify it 1552 1537 { 1553 FileStream enc("testfiles" DIRECTORY_SEPARATOR 1554 "testenc1_enc"); 1538 FileStream enc("testfiles/testenc1_enc"); 1555 1539 TEST_THAT(BackupStoreFile::VerifyEncodedFileFormat(enc) == true); 1556 1540 } … … 1558 1542 // Decode it 1559 1543 { 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); 1565 1546 } 1566 1547 1567 1548 // Read in rebuilt original, and compare contents 1568 1549 { 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"); 1574 1552 int encfile_i[ENCFILE_SIZE]; 1575 1553 in.Read(encfile_i, sizeof(encfile_i)); … … 1579 1557 // Check how many blocks it had, and test the stream based interface 1580 1558 { 1581 FileStream enc("testfiles" DIRECTORY_SEPARATOR 1582 "testenc1_enc"); 1559 FileStream enc("testfiles/testenc1_enc"); 1583 1560 std::auto_ptr<BackupStoreFile::DecodedStream> decoded(BackupStoreFile::DecodeFileStream(enc, IOStream::TimeOutInfinite)); 1584 1561 CollectInBufferStream d; … … 1594 1571 { 1595 1572 #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); 1598 1574 f.Write(encfile + 2, FILE_SIZE_JUST_OVER); 1599 f.Close();1600 1575 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)); 1605 1577 CollectInBufferStream e; 1606 1578 encoded->CopyStreamTo(e); … … 1618 1590 // Test that reordered streams work too 1619 1591 { 1620 FileStream enc("testfiles" DIRECTORY_SEPARATOR 1621 "testenc1_enc"); 1592 FileStream enc("testfiles/testenc1_enc"); 1622 1593 std::auto_ptr<IOStream> reordered(BackupStoreFile::ReorderFileToStreamOrder(&enc, false)); 1623 1594 std::auto_ptr<BackupStoreFile::DecodedStream> decoded(BackupStoreFile::DecodeFileStream(*reordered, IOStream::TimeOutInfinite)); … … 1631 1602 } 1632 1603 1633 #ifndef WIN321634 1604 // Try out doing this on a symlink 1635 1605 { … … 1645 1615 BackupStoreFile::DecodeFile(b, "testfiles/testsymlink_2", IOStream::TimeOutInfinite); 1646 1616 } 1647 #endif1648 1617 } 1649 1618 … … 1651 1620 { 1652 1621 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)); 1661 1625 TEST_CHECK_THROWS(info->Save(), BackupStoreException, StoreInfoIsReadOnly); 1662 1626 TEST_CHECK_THROWS(info->ChangeBlocksUsed(1), BackupStoreException, StoreInfoIsReadOnly); … … 1667 1631 } 1668 1632 { 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)); 1671 1634 info->ChangeBlocksUsed(8); 1672 1635 info->ChangeBlocksInOldFiles(9); … … 1686 1649 } 1687 1650 { 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)); 1690 1652 TEST_THAT(info->GetBlocksUsed() == 7); 1691 1653 TEST_THAT(info->GetBlocksInOldFiles() == 5); … … 1705 1667 TLSContext context; 1706 1668 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"); 1710 1672 1711 1673 // First, try logging in without an account having been created... just make sure login fails. 1712 1713 #ifdef WIN321714 int pid = LaunchServer("..\\..\\bin\\bbstored\\bbstored testfiles/bbstored.conf", "testfiles/bbstored.pid");1715 #else1716 1674 int pid = LaunchServer("../../bin/bbstored/bbstored testfiles/bbstored.conf", "testfiles/bbstored.pid"); 1717 #endif1718 1719 1675 TEST_THAT(pid != -1 && pid != 0); 1720 1676 if(pid > 0) … … 1745 1701 1746 1702 // Create an account for the test client 1747 #ifdef WIN321748 TEST_THAT_ABORTONFAIL(::system("..\\..\\bin\\bbstoreaccounts\\bbstoreaccounts -c testfiles/bbstored.conf create 01234567 0 10000B 20000B") == 0);1749 #else1750 1703 TEST_THAT_ABORTONFAIL(::system("../../bin/bbstoreaccounts/bbstoreaccounts -c testfiles/bbstored.conf create 01234567 0 10000B 20000B") == 0); 1751 1704 TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); 1752 #endif1753 1754 1705 TEST_THAT(TestDirExists("testfiles/0_0/backup/01234567")); 1755 1706 TEST_THAT(TestDirExists("testfiles/0_1/backup/01234567")); … … 1775 1726 ::sleep(1); 1776 1727 TEST_THAT(!ServerIsAlive(pid)); 1777 #ifndef WIN321778 1728 TestRemoteProcessMemLeaks("bbstored.memleaks"); 1779 #endif1780 1729 1781 1730 // Set a new limit on the account -- leave the hard limit high to make sure the target for 1782 1731 // freeing space is the soft limit. 1783 1784 #ifdef WIN321785 TEST_THAT_ABORTONFAIL(::system("..\\..\\bin\\bbstoreaccounts\\bbstoreaccounts -c testfiles/bbstored.conf setlimit 01234567 10B 20000B") == 0);1786 #else1787 1732 TEST_THAT_ABORTONFAIL(::system("../../bin/bbstoreaccounts/bbstoreaccounts -c testfiles/bbstored.conf setlimit 01234567 10B 20000B") == 0); 1788 1733 TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); 1789 #endif1790 1734 1791 1735 // Start things up 1792 #ifdef WIN321793 pid = LaunchServer("..\\..\\bin\\bbstored\\bbstored testfiles/bbstored.conf", "testfiles/bbstored.pid");1794 #else1795 1736 pid = LaunchServer("../../bin/bbstored/bbstored testfiles/bbstored.conf", "testfiles/bbstored.pid"); 1796 #endif1797 1798 1737 ::sleep(1); 1799 1738 TEST_THAT(ServerIsAlive(pid)); … … 1820 1759 1821 1760 // Set a really small hard limit 1822 #ifdef WIN321823 TEST_THAT_ABORTONFAIL(::system("..\\..\\bin\\bbstoreaccounts\\bbstoreaccounts -c testfiles/bbstored.conf setlimit 01234567 10B 20B") == 0);1824 #else1825 1761 TEST_THAT_ABORTONFAIL(::system("../../bin/bbstoreaccounts/bbstoreaccounts -c testfiles/bbstored.conf setlimit 01234567 10B 20B") == 0); 1826 1762 TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); 1827 #endif1828 1763 1829 1764 // Try to upload a file and create a directory, and check an error is generated … … 1874 1809 ::sleep(1); 1875 1810 TEST_THAT(!ServerIsAlive(pid)); 1876 1877 #ifndef WIN321878 1811 TestRemoteProcessMemLeaks("bbstored.memleaks"); 1879 #endif1880 1812 } 1881 1813 … … 1889 1821 // Create an account for the test client 1890 1822 TEST_THAT_ABORTONFAIL(::system("../../bin/bbstoreaccounts/bbstoreaccounts -c testfiles/bbstored.conf create 01234567 0 30000B 40000B") == 0); 1891 1892 #ifndef WIN321893 1823 TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks"); 1894 #endif1895 1824 1896 1825 // First, try logging in without an account having been created... just make sure login fails. 1897 1898 #ifdef WIN321899 int pid = LaunchServer("..\\..\\bin\\bbstored\\bbstored testfiles/bbstored_multi.conf", "testfiles/bbstored.pid");1900 #else1901 1826 int pid = LaunchServer("../../bin/bbstored/bbstored testfiles/bbstored_multi.conf", "testfiles/bbstored.pid"); 1902 #endif1903 1904 1827 TEST_THAT(pid != -1 && pid != 0); 1905 1828 if(pid > 0) … … 1918 1841 ::sleep(1); 1919 1842 TEST_THAT(!ServerIsAlive(pid)); 1920 #ifndef WIN321921 1843 TestRemoteProcessMemLeaks("bbstored.memleaks"); 1922 #endif1923 1844 } 1924 1845 … … 1927 1848 } 1928 1849 1929 #ifdef WIN321930 WCHAR* ConvertUtf8ToWideString(const char* pString);1931 std::string ConvertPathToAbsoluteUnicode(const char *pFileName);1932 #endif1933 1934 1850 int test(int argc, const char *argv[]) 1935 1851 { 1936 #ifdef WIN321937 // Under win32 we must initialise the Winsock library1938 // before using sockets1939 1940 WSADATA info;1941 TEST_THAT(WSAStartup(0x0101, &info) != SOCKET_ERROR)1942 1943 // this had better work, or bbstored will die when combining diffs1944 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 #endif1976 1977 1852 // SSL library 1978 1853 SSLLib::Initialise(); … … 1991 1866 // Use the setup crypto command to set up all these keys, so that the bbackupquery command can be used 1992 1867 // for seeing what's going on. 1993 #ifdef WIN321994 BackupClientCryptoKeys_Setup("testfiles\\bbackupd.keys");1995 #else1996 1868 BackupClientCryptoKeys_Setup("testfiles/bbackupd.keys"); 1997 #endif1998 1869 1999 1870 // 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.
