Changeset 2427 for box/trunk/test
- Timestamp:
- 03/01/2009 08:59:08 (3 years ago)
- File:
-
- 1 edited
-
box/trunk/test/bbackupd/testbbackupd.cpp (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/test/bbackupd/testbbackupd.cpp
r2386 r2427 87 87 // two cycles and a bit 88 88 #define TIME_TO_WAIT_FOR_BACKUP_OPERATION 12 89 90 // utility macro for comparing two strings in a line91 #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 line115 #define TEST_LINE(_condition, _line) \116 TEST_THAT(_condition); \117 if (!(_condition)) \118 { \119 printf("Test failed on <%s>\n", _line.c_str()); \120 }121 89 122 90 void wait_for_backup_operation(int seconds = TIME_TO_WAIT_FOR_BACKUP_OPERATION) … … 703 671 } 704 672 705 TEST_EQUAL (0, result, "Daemon exit code");673 TEST_EQUAL_LINE(0, result, "Daemon exit code"); 706 674 707 675 // ensure that no child processes end up running tests! … … 916 884 memset(buffer, 0, sizeof(buffer)); 917 885 918 TEST_EQUAL(sizeof(buffer), write(fd, buffer, sizeof(buffer)), 886 TEST_EQUAL_LINE(sizeof(buffer), 887 write(fd, buffer, sizeof(buffer)), 919 888 "Buffer write"); 920 889 TEST_THAT(close(fd) == 0); … … 937 906 TEST_THAT(fd > 0); 938 907 // 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)), 940 910 "Buffer write"); 941 911 TEST_THAT(close(fd) == 0); … … 970 940 TEST_THAT(reader.GetLine(line)); 971 941 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); 973 944 TEST_THAT(reader.GetLine(line)); 974 TEST_EQUAL("Receiving stream, size 124", line , line);945 TEST_EQUAL("Receiving stream, size 124", line); 975 946 TEST_THAT(reader.GetLine(line)); 976 TEST_EQUAL("Send GetIsAlive()", line , line);947 TEST_EQUAL("Send GetIsAlive()", line); 977 948 TEST_THAT(reader.GetLine(line)); 978 TEST_EQUAL("Receive IsAlive()", line , line);949 TEST_EQUAL("Receive IsAlive()", line); 979 950 980 951 TEST_THAT(reader.GetLine(line)); 981 952 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); 983 955 comp = ",\"f1\")"; 984 956 std::string sub = line.substr(line.size() - comp.size()); 985 TEST_EQUAL (comp, sub, line);957 TEST_EQUAL_LINE(comp, sub, line); 986 958 std::string comp2 = ",0x0,"; 987 959 sub = line.substr(line.size() - comp.size() - … … 1009 981 TEST_THAT(fd > 0); 1010 982 // 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)), 1012 985 "Buffer write"); 1013 986 TEST_THAT(close(fd) == 0); … … 1039 1012 TEST_THAT(reader.GetLine(line)); 1040 1013 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); 1042 1016 TEST_THAT(reader.GetLine(line)); 1043 TEST_EQUAL("Receiving stream, size 124", line , line);1017 TEST_EQUAL("Receiving stream, size 124", line); 1044 1018 1045 1019 // delaying for 4 seconds in one step means that … … 1050 1024 TEST_THAT(reader.GetLine(line)); 1051 1025 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); 1053 1028 comp = ",0x0,\"f1\")"; 1054 1029 std::string sub = line.substr(line.size() - comp.size()); 1055 TEST_EQUAL (comp, sub, line);1030 TEST_EQUAL_LINE(comp, sub, line); 1056 1031 } 1057 1032 … … 1071 1046 TEST_THAT(fd > 0); 1072 1047 // 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)), 1074 1050 "Buffer write"); 1075 1051 TEST_THAT(close(fd) == 0); … … 1101 1077 TEST_THAT(reader.GetLine(line)); 1102 1078 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); 1104 1081 TEST_THAT(reader.GetLine(line)); 1105 TEST_EQUAL("Receiving stream, size 124", line , line);1082 TEST_EQUAL("Receiving stream, size 124", line); 1106 1083 1107 1084 // delaying for 3 seconds in steps of 1 second … … 1112 1089 1113 1090 TEST_THAT(reader.GetLine(line)); 1114 TEST_EQUAL("Send GetIsAlive()", line , line);1091 TEST_EQUAL("Send GetIsAlive()", line); 1115 1092 TEST_THAT(reader.GetLine(line)); 1116 TEST_EQUAL("Receive IsAlive()", line , line);1093 TEST_EQUAL("Receive IsAlive()", line); 1117 1094 TEST_THAT(reader.GetLine(line)); 1118 TEST_EQUAL("Send GetIsAlive()", line , line);1095 TEST_EQUAL("Send GetIsAlive()", line); 1119 1096 TEST_THAT(reader.GetLine(line)); 1120 TEST_EQUAL("Receive IsAlive()", line , line);1097 TEST_EQUAL("Receive IsAlive()", line); 1121 1098 1122 1099 // but two matching blocks should have been found … … 1125 1102 TEST_THAT(reader.GetLine(line)); 1126 1103 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); 1128 1106 comp = ",\"f1\")"; 1129 1107 std::string sub = line.substr(line.size() - comp.size()); 1130 TEST_EQUAL (comp, sub, line);1108 TEST_EQUAL_LINE(comp, sub, line); 1131 1109 std::string comp2 = ",0x0,"; 1132 1110 sub = line.substr(line.size() - comp.size() - … … 1157 1135 TEST_THAT(fd > 0); 1158 1136 // 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)), 1160 1139 "Buffer write"); 1161 1140 TEST_THAT(close(fd) == 0); … … 1203 1182 std::string line; 1204 1183 TEST_THAT(reader.GetLine(line)); 1205 TEST_EQUAL("Receive Success(0x3)", line , line);1184 TEST_EQUAL("Receive Success(0x3)", line); 1206 1185 TEST_THAT(reader.GetLine(line)); 1207 TEST_EQUAL("Receiving stream, size 425", line , line);1186 TEST_EQUAL("Receiving stream, size 425", line); 1208 1187 TEST_THAT(reader.GetLine(line)); 1209 TEST_EQUAL("Send GetIsAlive()", line , line);1188 TEST_EQUAL("Send GetIsAlive()", line); 1210 1189 TEST_THAT(reader.GetLine(line)); 1211 TEST_EQUAL("Receive IsAlive()", line , line);1190 TEST_EQUAL("Receive IsAlive()", line); 1212 1191 TEST_THAT(reader.GetLine(line)); 1213 TEST_EQUAL("Send GetIsAlive()", line , line);1192 TEST_EQUAL("Send GetIsAlive()", line); 1214 1193 TEST_THAT(reader.GetLine(line)); 1215 TEST_EQUAL("Receive IsAlive()", line , line);1194 TEST_EQUAL("Receive IsAlive()", line); 1216 1195 } 1217 1196 … … 1343 1322 std::auto_ptr<BackupProtocolClientAccountUsage> usage( 1344 1323 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(), 1347 1327 "deleted blocks"); 1348 TEST_EQUAL (16, usage->GetBlocksInDirectories(),1328 TEST_EQUAL_LINE(16, usage->GetBlocksInDirectories(), 1349 1329 "directory blocks"); 1350 1330 … … 1468 1448 std::auto_ptr<BackupProtocolClientAccountUsage> usage( 1469 1449 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(), 1472 1453 "deleted blocks"); 1473 TEST_EQUAL (16, usage->GetBlocksInDirectories(),1454 TEST_EQUAL_LINE(16, usage->GetBlocksInDirectories(), 1474 1455 "directory blocks"); 1475 1456 // d1/f3 and d1/f4 are the only two files on the … … 1523 1504 std::auto_ptr<BackupProtocolClientAccountUsage> usage( 1524 1505 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(), 1527 1509 "deleted blocks"); 1528 TEST_EQUAL (12, usage->GetBlocksInDirectories(),1510 TEST_EQUAL_LINE(12, usage->GetBlocksInDirectories(), 1529 1511 "directory blocks"); 1530 1512 // d1/f3 and d1/f4 are the only two files on the … … 1577 1559 std::auto_ptr<BackupProtocolClientAccountUsage> usage( 1578 1560 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(), 1581 1564 "deleted blocks"); 1582 TEST_EQUAL (14, usage->GetBlocksInDirectories(),1565 TEST_EQUAL_LINE(14, usage->GetBlocksInDirectories(), 1583 1566 "directory blocks"); 1584 1567 // d2/f6, d6/d8 and d6/d8/f7 are new … … 1863 1846 TEST_THAT(gl.GetLine(line)); 1864 1847 TEST_THAT(line != "before"); 1865 TEST_EQUAL("after", line , line);1848 TEST_EQUAL("after", line); 1866 1849 1867 1850 #undef SYM_DIR … … 1881 1864 TEST_THAT(stat("testfiles/symlink-to-TestDir1", &stat_st) == 0); 1882 1865 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, 1884 1867 "stat vs lstat"); 1885 1868 … … 2220 2203 std::string data("hello world\n"); 2221 2204 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"); 2223 2207 fs.Close(); 2224 2208 }
Note: See TracChangeset
for help on using the changeset viewer.
