Changeset 2427 for box/trunk/test


Ignore:
Timestamp:
03/01/2009 08:59:08 (3 years ago)
Author:
chris
Message:

Move TEST_EQUAL macro into lib/common/Test.h, rename to TEST_EQUAL_LINE,
provide TEST_EQUAL that only takes two arguments for simplicity.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/test/bbackupd/testbbackupd.cpp

    r2386 r2427  
    8787// two cycles and a bit 
    8888#define TIME_TO_WAIT_FOR_BACKUP_OPERATION       12 
    89  
    90 // utility macro for comparing two strings in a line 
    91 #define TEST_EQUAL(_expected, _found, _line) \ 
    92 { \ 
    93         std::ostringstream _oss1; \ 
    94         _oss1 << _expected; \ 
    95         std::string _exp_str = _oss1.str(); \ 
    96         \ 
    97         std::ostringstream _oss2; \ 
    98         _oss2 << _found; \ 
    99         std::string _found_str = _oss2.str(); \ 
    100         \ 
    101         if(_exp_str != _found_str) \ 
    102         { \ 
    103                 std::string _line_str = _line; \ 
    104                 printf("Expected <%s> but found <%s> in <%s>\n", \ 
    105                         _exp_str.c_str(), _found_str.c_str(), _line_str.c_str()); \ 
    106                 \ 
    107                 std::ostringstream _oss3; \ 
    108                 _oss3 << #_found << " != " << #_expected << " in " << _line; \ 
    109                 \ 
    110                 TEST_FAIL_WITH_MESSAGE(_oss3.str().c_str()); \ 
    111         } \ 
    112 } 
    113  
    114 // utility macro for testing a line 
    115 #define TEST_LINE(_condition, _line) \ 
    116         TEST_THAT(_condition); \ 
    117         if (!(_condition)) \ 
    118         { \ 
    119                 printf("Test failed on <%s>\n", _line.c_str()); \ 
    120         } 
    12189 
    12290void wait_for_backup_operation(int seconds = TIME_TO_WAIT_FOR_BACKUP_OPERATION) 
     
    703671        } 
    704672         
    705         TEST_EQUAL(0, result, "Daemon exit code"); 
     673        TEST_EQUAL_LINE(0, result, "Daemon exit code"); 
    706674         
    707675        // ensure that no child processes end up running tests! 
     
    916884                memset(buffer, 0, sizeof(buffer)); 
    917885 
    918                 TEST_EQUAL(sizeof(buffer), write(fd, buffer, sizeof(buffer)), 
     886                TEST_EQUAL_LINE(sizeof(buffer), 
     887                        write(fd, buffer, sizeof(buffer)), 
    919888                        "Buffer write"); 
    920889                TEST_THAT(close(fd) == 0); 
     
    937906                TEST_THAT(fd > 0); 
    938907                // write again, to update the file's timestamp 
    939                 TEST_EQUAL(sizeof(buffer), write(fd, buffer, sizeof(buffer)), 
     908                TEST_EQUAL_LINE(sizeof(buffer), 
     909                        write(fd, buffer, sizeof(buffer)), 
    940910                        "Buffer write"); 
    941911                TEST_THAT(close(fd) == 0);       
     
    970940                        TEST_THAT(reader.GetLine(line)); 
    971941                        std::string comp = "Receive Success(0x"; 
    972                         TEST_EQUAL(comp, line.substr(0, comp.size()), line); 
     942                        TEST_EQUAL_LINE(comp, line.substr(0, comp.size()), 
     943                                line); 
    973944                        TEST_THAT(reader.GetLine(line)); 
    974                         TEST_EQUAL("Receiving stream, size 124", line, line); 
     945                        TEST_EQUAL("Receiving stream, size 124", line); 
    975946                        TEST_THAT(reader.GetLine(line)); 
    976                         TEST_EQUAL("Send GetIsAlive()", line, line); 
     947                        TEST_EQUAL("Send GetIsAlive()", line); 
    977948                        TEST_THAT(reader.GetLine(line)); 
    978                         TEST_EQUAL("Receive IsAlive()", line, line); 
     949                        TEST_EQUAL("Receive IsAlive()", line); 
    979950 
    980951                        TEST_THAT(reader.GetLine(line)); 
    981952                        comp = "Send StoreFile(0x3,"; 
    982                         TEST_EQUAL(comp, line.substr(0, comp.size()), line); 
     953                        TEST_EQUAL_LINE(comp, line.substr(0, comp.size()), 
     954                                line); 
    983955                        comp = ",\"f1\")"; 
    984956                        std::string sub = line.substr(line.size() - comp.size()); 
    985                         TEST_EQUAL(comp, sub, line); 
     957                        TEST_EQUAL_LINE(comp, sub, line); 
    986958                        std::string comp2 = ",0x0,"; 
    987959                        sub = line.substr(line.size() - comp.size() - 
     
    1009981                TEST_THAT(fd > 0); 
    1010982                // write again, to update the file's timestamp 
    1011                 TEST_EQUAL(sizeof(buffer), write(fd, buffer, sizeof(buffer)), 
     983                TEST_EQUAL_LINE(sizeof(buffer), 
     984                        write(fd, buffer, sizeof(buffer)), 
    1012985                        "Buffer write"); 
    1013986                TEST_THAT(close(fd) == 0);       
     
    10391012                        TEST_THAT(reader.GetLine(line)); 
    10401013                        std::string comp = "Receive Success(0x"; 
    1041                         TEST_EQUAL(comp, line.substr(0, comp.size()), line); 
     1014                        TEST_EQUAL_LINE(comp, line.substr(0, comp.size()), 
     1015                                line); 
    10421016                        TEST_THAT(reader.GetLine(line)); 
    1043                         TEST_EQUAL("Receiving stream, size 124", line, line); 
     1017                        TEST_EQUAL("Receiving stream, size 124", line); 
    10441018 
    10451019                        // delaying for 4 seconds in one step means that 
     
    10501024                        TEST_THAT(reader.GetLine(line)); 
    10511025                        comp = "Send StoreFile(0x3,"; 
    1052                         TEST_EQUAL(comp, line.substr(0, comp.size()), line); 
     1026                        TEST_EQUAL_LINE(comp, line.substr(0, comp.size()), 
     1027                                line); 
    10531028                        comp = ",0x0,\"f1\")"; 
    10541029                        std::string sub = line.substr(line.size() - comp.size()); 
    1055                         TEST_EQUAL(comp, sub, line); 
     1030                        TEST_EQUAL_LINE(comp, sub, line); 
    10561031                } 
    10571032 
     
    10711046                TEST_THAT(fd > 0); 
    10721047                // write again, to update the file's timestamp 
    1073                 TEST_EQUAL(sizeof(buffer), write(fd, buffer, sizeof(buffer)), 
     1048                TEST_EQUAL_LINE(sizeof(buffer), 
     1049                        write(fd, buffer, sizeof(buffer)), 
    10741050                        "Buffer write"); 
    10751051                TEST_THAT(close(fd) == 0);       
     
    11011077                        TEST_THAT(reader.GetLine(line)); 
    11021078                        std::string comp = "Receive Success(0x"; 
    1103                         TEST_EQUAL(comp, line.substr(0, comp.size()), line); 
     1079                        TEST_EQUAL_LINE(comp, line.substr(0, comp.size()), 
     1080                                line); 
    11041081                        TEST_THAT(reader.GetLine(line)); 
    1105                         TEST_EQUAL("Receiving stream, size 124", line, line); 
     1082                        TEST_EQUAL("Receiving stream, size 124", line); 
    11061083 
    11071084                        // delaying for 3 seconds in steps of 1 second 
     
    11121089                         
    11131090                        TEST_THAT(reader.GetLine(line)); 
    1114                         TEST_EQUAL("Send GetIsAlive()", line, line); 
     1091                        TEST_EQUAL("Send GetIsAlive()", line); 
    11151092                        TEST_THAT(reader.GetLine(line)); 
    1116                         TEST_EQUAL("Receive IsAlive()", line, line); 
     1093                        TEST_EQUAL("Receive IsAlive()", line); 
    11171094                        TEST_THAT(reader.GetLine(line)); 
    1118                         TEST_EQUAL("Send GetIsAlive()", line, line); 
     1095                        TEST_EQUAL("Send GetIsAlive()", line); 
    11191096                        TEST_THAT(reader.GetLine(line)); 
    1120                         TEST_EQUAL("Receive IsAlive()", line, line); 
     1097                        TEST_EQUAL("Receive IsAlive()", line); 
    11211098 
    11221099                        // but two matching blocks should have been found 
     
    11251102                        TEST_THAT(reader.GetLine(line)); 
    11261103                        comp = "Send StoreFile(0x3,"; 
    1127                         TEST_EQUAL(comp, line.substr(0, comp.size()), line); 
     1104                        TEST_EQUAL_LINE(comp, line.substr(0, comp.size()), 
     1105                                line); 
    11281106                        comp = ",\"f1\")"; 
    11291107                        std::string sub = line.substr(line.size() - comp.size()); 
    1130                         TEST_EQUAL(comp, sub, line); 
     1108                        TEST_EQUAL_LINE(comp, sub, line); 
    11311109                        std::string comp2 = ",0x0,"; 
    11321110                        sub = line.substr(line.size() - comp.size() - 
     
    11571135                TEST_THAT(fd > 0); 
    11581136                // write again, to update the file's timestamp 
    1159                 TEST_EQUAL(sizeof(buffer), write(fd, buffer, sizeof(buffer)), 
     1137                TEST_EQUAL_LINE(sizeof(buffer), 
     1138                        write(fd, buffer, sizeof(buffer)), 
    11601139                        "Buffer write"); 
    11611140                TEST_THAT(close(fd) == 0);       
     
    12031182                        std::string line; 
    12041183                        TEST_THAT(reader.GetLine(line)); 
    1205                         TEST_EQUAL("Receive Success(0x3)", line, line); 
     1184                        TEST_EQUAL("Receive Success(0x3)", line); 
    12061185                        TEST_THAT(reader.GetLine(line)); 
    1207                         TEST_EQUAL("Receiving stream, size 425", line, line); 
     1186                        TEST_EQUAL("Receiving stream, size 425", line); 
    12081187                        TEST_THAT(reader.GetLine(line)); 
    1209                         TEST_EQUAL("Send GetIsAlive()", line, line); 
     1188                        TEST_EQUAL("Send GetIsAlive()", line); 
    12101189                        TEST_THAT(reader.GetLine(line)); 
    1211                         TEST_EQUAL("Receive IsAlive()", line, line); 
     1190                        TEST_EQUAL("Receive IsAlive()", line); 
    12121191                        TEST_THAT(reader.GetLine(line)); 
    1213                         TEST_EQUAL("Send GetIsAlive()", line, line); 
     1192                        TEST_EQUAL("Send GetIsAlive()", line); 
    12141193                        TEST_THAT(reader.GetLine(line)); 
    1215                         TEST_EQUAL("Receive IsAlive()", line, line); 
     1194                        TEST_EQUAL("Receive IsAlive()", line); 
    12161195                } 
    12171196 
     
    13431322                        std::auto_ptr<BackupProtocolClientAccountUsage> usage( 
    13441323                                client->QueryGetAccountUsage()); 
    1345                         TEST_EQUAL(24, usage->GetBlocksUsed(), "blocks used"); 
    1346                         TEST_EQUAL(0,  usage->GetBlocksInDeletedFiles(), 
     1324                        TEST_EQUAL_LINE(24, usage->GetBlocksUsed(), 
     1325                                "blocks used"); 
     1326                        TEST_EQUAL_LINE(0,  usage->GetBlocksInDeletedFiles(), 
    13471327                                "deleted blocks"); 
    1348                         TEST_EQUAL(16, usage->GetBlocksInDirectories(), 
     1328                        TEST_EQUAL_LINE(16, usage->GetBlocksInDirectories(), 
    13491329                                "directory blocks"); 
    13501330 
     
    14681448                        std::auto_ptr<BackupProtocolClientAccountUsage> usage( 
    14691449                                client->QueryGetAccountUsage()); 
    1470                         TEST_EQUAL(24, usage->GetBlocksUsed(), "blocks used"); 
    1471                         TEST_EQUAL(4, usage->GetBlocksInDeletedFiles(), 
     1450                        TEST_EQUAL_LINE(24, usage->GetBlocksUsed(), 
     1451                                "blocks used"); 
     1452                        TEST_EQUAL_LINE(4, usage->GetBlocksInDeletedFiles(), 
    14721453                                "deleted blocks"); 
    1473                         TEST_EQUAL(16, usage->GetBlocksInDirectories(), 
     1454                        TEST_EQUAL_LINE(16, usage->GetBlocksInDirectories(), 
    14741455                                "directory blocks"); 
    14751456                        // d1/f3 and d1/f4 are the only two files on the 
     
    15231504                        std::auto_ptr<BackupProtocolClientAccountUsage> usage( 
    15241505                                client->QueryGetAccountUsage()); 
    1525                         TEST_EQUAL(16, usage->GetBlocksUsed(), "blocks used"); 
    1526                         TEST_EQUAL(0, usage->GetBlocksInDeletedFiles(), 
     1506                        TEST_EQUAL_LINE(16, usage->GetBlocksUsed(), 
     1507                                "blocks used"); 
     1508                        TEST_EQUAL_LINE(0, usage->GetBlocksInDeletedFiles(), 
    15271509                                "deleted blocks"); 
    1528                         TEST_EQUAL(12, usage->GetBlocksInDirectories(), 
     1510                        TEST_EQUAL_LINE(12, usage->GetBlocksInDirectories(), 
    15291511                                "directory blocks"); 
    15301512                        // d1/f3 and d1/f4 are the only two files on the 
     
    15771559                        std::auto_ptr<BackupProtocolClientAccountUsage> usage( 
    15781560                                client->QueryGetAccountUsage()); 
    1579                         TEST_EQUAL(22, usage->GetBlocksUsed(), "blocks used"); 
    1580                         TEST_EQUAL(0, usage->GetBlocksInDeletedFiles(), 
     1561                        TEST_EQUAL_LINE(22, usage->GetBlocksUsed(), 
     1562                                "blocks used"); 
     1563                        TEST_EQUAL_LINE(0, usage->GetBlocksInDeletedFiles(), 
    15811564                                "deleted blocks"); 
    1582                         TEST_EQUAL(14, usage->GetBlocksInDirectories(), 
     1565                        TEST_EQUAL_LINE(14, usage->GetBlocksInDirectories(), 
    15831566                                "directory blocks"); 
    15841567                        // d2/f6, d6/d8 and d6/d8/f7 are new 
     
    18631846                TEST_THAT(gl.GetLine(line)); 
    18641847                TEST_THAT(line != "before"); 
    1865                 TEST_EQUAL("after", line, line); 
     1848                TEST_EQUAL("after", line); 
    18661849 
    18671850                #undef SYM_DIR 
     
    18811864                TEST_THAT(stat("testfiles/symlink-to-TestDir1", &stat_st) == 0); 
    18821865                TEST_THAT(lstat("testfiles/symlink-to-TestDir1", &lstat_st) == 0); 
    1883                 TEST_EQUAL((stat_st.st_dev ^ 0xFFFF), lstat_st.st_dev, 
     1866                TEST_EQUAL_LINE((stat_st.st_dev ^ 0xFFFF), lstat_st.st_dev, 
    18841867                        "stat vs lstat"); 
    18851868 
     
    22202203                        std::string data("hello world\n"); 
    22212204                        fs.Write(data.c_str(), data.size()); 
    2222                         TEST_EQUAL(12, fs.GetPosition(), "FileStream position"); 
     2205                        TEST_EQUAL_LINE(12, fs.GetPosition(), 
     2206                                "FileStream position"); 
    22232207                        fs.Close(); 
    22242208                } 
Note: See TracChangeset for help on using the changeset viewer.