Changeset 694


Ignore:
Timestamp:
27/07/2006 00:13:14 (6 years ago)
Author:
chris
Message:
  • testbbackupd.cpp
  • Added tests for comparing restored file attributes on Win32
  • Re-enabled existing file attribute tests
  • Deal appropriately with openfile() returning INVALID_HANDLE_VALUE
File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/chris/general/test/bbackupd/testbbackupd.cpp

    r671 r694  
    561561} 
    562562 
     563bool set_file_time(const char* filename, FILETIME creationTime,  
     564        FILETIME lastModTime, FILETIME lastAccessTime) 
     565{ 
     566        HANDLE handle = openfile(filename, O_RDWR, 0); 
     567        TEST_THAT(handle != INVALID_HANDLE_VALUE); 
     568        if (handle == INVALID_HANDLE_VALUE) return false; 
     569                 
     570        BOOL success = SetFileTime(handle, &creationTime, &lastAccessTime, 
     571                &lastModTime); 
     572        TEST_THAT(success); 
     573 
     574        TEST_THAT(CloseHandle(handle)); 
     575        return success; 
     576} 
     577 
    563578int test_bbackupd() 
    564579{ 
     
    9861001                compareReturnValue = ::system(BBACKUPQUERY " -q " 
    9871002                        "-c testfiles/bbackupd.conf -l testfiles/query10.log " 
     1003                        "\"compare -cE Test1 testfiles/restore-Test1\" " 
     1004                        "quit"); 
     1005                TEST_RETURN(compareReturnValue, 1); 
     1006                TestRemoteProcessMemLeaks("bbackupquery.memleaks"); 
     1007                 
    9881008                #ifdef WIN32 
    989                         "\"compare -cAE Test1 testfiles/restore-Test1\" " 
    990                 #else 
     1009                // make one of the files read-only, expect a compare failure 
     1010                compareReturnValue = ::system("attrib +r " 
     1011                        "testfiles\\restore-Test1\\f1.dat"); 
     1012                TEST_RETURN(compareReturnValue, 0); 
     1013 
     1014                compareReturnValue = ::system(BBACKUPQUERY " -q " 
     1015                        "-c testfiles/bbackupd.conf -l testfiles/query10a.log " 
    9911016                        "\"compare -cE Test1 testfiles/restore-Test1\" " 
     1017                        "quit"); 
     1018                TEST_RETURN(compareReturnValue, 2); 
     1019                TestRemoteProcessMemLeaks("bbackupquery.memleaks"); 
     1020         
     1021                // set it back, expect no failures 
     1022                compareReturnValue = ::system("attrib -r " 
     1023                        "testfiles\\restore-Test1\\f1.dat"); 
     1024                TEST_RETURN(compareReturnValue, 0); 
     1025 
     1026                compareReturnValue = ::system(BBACKUPQUERY " -q " 
     1027                        "-c testfiles/bbackupd.conf -l testfiles/query10a.log " 
     1028                        "\"compare -cE Test1 testfiles/restore-Test1\" " 
     1029                        "quit"); 
     1030                TEST_RETURN(compareReturnValue, 1); 
     1031                TestRemoteProcessMemLeaks("bbackupquery.memleaks"); 
     1032 
     1033                // change the timestamp on a file, expect a compare failure 
     1034                char* testfile = "testfiles\\restore-Test1\\f1.dat"; 
     1035                HANDLE handle = openfile(testfile, O_RDWR, 0); 
     1036                TEST_THAT(handle != INVALID_HANDLE_VALUE); 
     1037                 
     1038                FILETIME creationTime, lastModTime, lastAccessTime; 
     1039                TEST_THAT(GetFileTime(handle, &creationTime, &lastAccessTime,  
     1040                        &lastModTime) != 0); 
     1041                TEST_THAT(CloseHandle(handle)); 
     1042 
     1043                FILETIME dummyTime = lastModTime; 
     1044                dummyTime.dwHighDateTime -= 100; 
     1045 
     1046                // creation time is backed up, so changing it should cause 
     1047                // a compare failure 
     1048                TEST_THAT(set_file_time(testfile, dummyTime, lastModTime, 
     1049                        lastAccessTime)); 
     1050                compareReturnValue = ::system(BBACKUPQUERY " -q " 
     1051                        "-c testfiles/bbackupd.conf -l testfiles/query10a.log " 
     1052                        "\"compare -cE Test1 testfiles/restore-Test1\" " 
     1053                        "quit"); 
     1054                TEST_RETURN(compareReturnValue, 2); 
     1055                TestRemoteProcessMemLeaks("bbackupquery.memleaks"); 
     1056 
     1057                // last access time is not backed up, so it cannot be compared 
     1058                TEST_THAT(set_file_time(testfile, creationTime, lastModTime, 
     1059                        dummyTime)); 
     1060                compareReturnValue = ::system(BBACKUPQUERY " -q " 
     1061                        "-c testfiles/bbackupd.conf -l testfiles/query10a.log " 
     1062                        "\"compare -cE Test1 testfiles/restore-Test1\" " 
     1063                        "quit"); 
     1064                TEST_RETURN(compareReturnValue, 1); 
     1065                TestRemoteProcessMemLeaks("bbackupquery.memleaks"); 
     1066 
     1067                // last write time is backed up, so changing it should cause 
     1068                // a compare failure 
     1069                TEST_THAT(set_file_time(testfile, creationTime, dummyTime, 
     1070                        lastAccessTime)); 
     1071                compareReturnValue = ::system(BBACKUPQUERY " -q " 
     1072                        "-c testfiles/bbackupd.conf -l testfiles/query10a.log " 
     1073                        "\"compare -cE Test1 testfiles/restore-Test1\" " 
     1074                        "quit"); 
     1075                TEST_RETURN(compareReturnValue, 2); 
     1076                TestRemoteProcessMemLeaks("bbackupquery.memleaks"); 
     1077 
     1078                // set back to original values, check that compare succeeds 
     1079                TEST_THAT(set_file_time(testfile, creationTime, lastModTime, 
     1080                        lastAccessTime)); 
     1081                compareReturnValue = ::system(BBACKUPQUERY " -q " 
     1082                        "-c testfiles/bbackupd.conf -l testfiles/query10a.log " 
     1083                        "\"compare -cE Test1 testfiles/restore-Test1\" " 
     1084                        "quit"); 
     1085                TEST_RETURN(compareReturnValue, 1); 
     1086                TestRemoteProcessMemLeaks("bbackupquery.memleaks"); 
    9921087                #endif 
    993                         "quit"); 
    994  
    995                 TEST_RETURN(compareReturnValue, 1); 
    996                 TestRemoteProcessMemLeaks("bbackupquery.memleaks"); 
    9971088 
    9981089                printf("Add files with current time\n"); 
     
    11651256                                " -q -c testfiles/bbackupd.conf " 
    11661257                                "-l testfiles/query11.log " 
    1167                                 "\"compare " 
    1168                         #ifdef WIN32 
    1169                                 // cannot restore attributes, so don't compare 
    1170                                 "-cAE " 
    1171                         #else 
    1172                                 "-cE " 
    1173                         #endif 
     1258                                "\"compare -cE " 
    11741259                                "Test1/x1 testfiles/restore-Test1-x1-2\" quit"); 
    11751260                        TEST_RETURN(compareReturnValue, 1); 
     
    11901275                // Now we have about three seconds to work 
    11911276 
    1192                 HANDLE handle = openfile("testfiles/TestDir1/lockedfile", 
     1277                handle = openfile("testfiles/TestDir1/lockedfile", 
    11931278                        O_CREAT | O_EXCL, 0); 
    1194                 TEST_THAT(handle != 0); 
     1279                TEST_THAT(handle != INVALID_HANDLE_VALUE); 
    11951280 
    11961281                if (handle != 0) 
     
    12251310                        handle = openfile("testfiles/TestDir1/lockedfile", 
    12261311                                O_CREAT | O_EXCL, 0); 
    1227                         TEST_THAT(handle != 0); 
     1312                        TEST_THAT(handle != INVALID_HANDLE_VALUE); 
    12281313 
    12291314                        compareReturnValue = ::system(BBACKUPQUERY  
Note: See TracChangeset for help on using the changeset viewer.