Changeset 1941
- Timestamp:
- 06/12/2007 08:52:33 (4 years ago)
- File:
-
- 1 edited
-
box/trunk/test/bbackupd/testbbackupd.cpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/test/bbackupd/testbbackupd.cpp
r1936 r1941 79 79 // two cycles and a bit 80 80 #define TIME_TO_WAIT_FOR_BACKUP_OPERATION 12 81 82 // utility macro for comparing two strings in a line 83 #define TEST_EQUAL(expected, found, line) \ 84 { \ 85 std::string exp_str = expected; \ 86 std::string found_str = found; \ 87 TEST_THAT(exp_str == found_str); \ 88 if(exp_str != found_str) \ 89 { \ 90 printf("Expected <%s> but found <%s> in <%s>\n", \ 91 exp_str.c_str(), found_str.c_str(), line.c_str()); \ 92 } \ 93 } 94 95 // utility macro for testing a line 96 #define TEST_LINE(condition, line) \ 97 TEST_THAT(condition); \ 98 if (!(condition)) \ 99 { \ 100 printf("Test failed on <%s>\n", line.c_str()); \ 101 } 81 102 82 103 void wait_for_backup_operation(int seconds = TIME_TO_WAIT_FOR_BACKUP_OPERATION) … … 814 835 int fd = open("testfiles/TestDir1/spacetest/f1", O_WRONLY); 815 836 TEST_THAT(fd > 0); 837 816 838 char buffer[10000]; 839 memset(buffer, 0, sizeof(buffer)); 840 817 841 TEST_THAT(write(fd, buffer, sizeof(buffer)) == sizeof(buffer)); 818 842 TEST_THAT(close(fd) == 0); … … 822 846 stop_internal_daemon(pid); 823 847 848 // two-second delay on the first read() of f1 849 // should mean that a single keepalive is sent, 850 // and diff does not abort. 824 851 intercept_setup_delay("testfiles/TestDir1/spacetest/f1", 825 852 0, 2000, SYS_read, 1); … … 863 890 TEST_THAT(reader.GetLine(line)); 864 891 std::string comp = "Receive Success(0x"; 865 TEST_ THAT(line.substr(0, comp.size()) == comp);892 TEST_EQUAL(comp, line.substr(0, comp.size()), line); 866 893 TEST_THAT(reader.GetLine(line)); 867 TEST_ THAT(line == "Receiving stream, size 124");894 TEST_EQUAL("Receiving stream, size 124", line, line); 868 895 TEST_THAT(reader.GetLine(line)); 869 TEST_ THAT(line == "Send GetIsAlive()");896 TEST_EQUAL("Send GetIsAlive()", line, line); 870 897 TEST_THAT(reader.GetLine(line)); 871 TEST_ THAT(line == "Receive IsAlive()");898 TEST_EQUAL("Receive IsAlive()", line, line); 872 899 873 900 TEST_THAT(reader.GetLine(line)); 874 901 comp = "Send StoreFile(0x3,"; 875 TEST_ THAT(line.substr(0, comp.size()) == comp);902 TEST_EQUAL(comp, line.substr(0, comp.size()), line); 876 903 comp = ",\"f1\")"; 877 904 std::string sub = line.substr(line.size() - comp.size()); 878 879 TEST_THAT(sub == comp); 880 if (sub != comp) 881 { 882 printf("Expected <%s> but found <%s> in <%s>\n", 883 comp.c_str(), sub.c_str(), line.c_str()); 884 } 905 TEST_EQUAL(comp, sub, line); 906 std::string comp2 = ",0x0,"; 907 sub = line.substr(line.size() - comp.size() - 908 comp2.size() + 1, comp2.size()); 909 TEST_LINE(comp2 != sub, line); 885 910 } 886 911 … … 892 917 } 893 918 919 // four-second delay on first read() of f1 920 // should mean that no keepalives were sent, 921 // because diff was immediately aborted 922 // before any matching blocks could be found. 894 923 intercept_setup_delay("testfiles/TestDir1/spacetest/f1", 895 924 0, 4000, SYS_read, 1); … … 939 968 TEST_THAT(reader.GetLine(line)); 940 969 comp = "Send StoreFile(0x3,"; 941 TEST_ THAT(line.substr(0, comp.size()) == comp);970 TEST_EQUAL(comp, line.substr(0, comp.size()), line); 942 971 comp = ",0x0,\"f1\")"; 943 972 std::string sub = line.substr(line.size() - comp.size()); 944 945 TEST_THAT(sub == comp); 946 if (sub != comp) 947 { 948 printf("Expected <%s> but found <%s> in <%s>\n", 949 comp.c_str(), sub.c_str(), line.c_str()); 950 } 973 TEST_EQUAL(comp, sub, line); 951 974 } 952 975 … … 1013 1036 TEST_THAT(line == "Receive IsAlive()"); 1014 1037 1015 // should not be a diff, so previous version1016 // should be 0x01038 // but two matching blocks should have been found 1039 // already, so the upload should be a diff. 1017 1040 1018 1041 TEST_THAT(reader.GetLine(line)); 1019 1042 comp = "Send StoreFile(0x3,"; 1020 TEST_ THAT(line.substr(0, comp.size()) == comp);1021 comp = ", 0x0,\"f1\")";1043 TEST_EQUAL(comp, line.substr(0, comp.size()), line); 1044 comp = ",\"f1\")"; 1022 1045 std::string sub = line.substr(line.size() - comp.size()); 1023 1024 TEST_THAT(sub == comp); 1025 if (sub != comp) 1026 { 1027 printf("Expected <%s> but found <%s> in <%s>\n", 1028 comp.c_str(), sub.c_str(), line.c_str()); 1029 } 1046 TEST_EQUAL(comp, sub, line); 1047 std::string comp2 = ",0x0,"; 1048 sub = line.substr(line.size() - comp.size() - 1049 comp2.size() + 1, comp2.size()); 1050 TEST_LINE(comp2 != sub, line); 1030 1051 } 1031 1052 … … 1096 1117 std::string line; 1097 1118 TEST_THAT(reader.GetLine(line)); 1098 TEST_ THAT(line == "Receive Success(0x3)");1119 TEST_EQUAL("Receive Success(0x3)", line, line); 1099 1120 TEST_THAT(reader.GetLine(line)); 1100 TEST_ THAT(line == "Receiving stream, size 425");1121 TEST_EQUAL("Receiving stream, size 425", line, line); 1101 1122 TEST_THAT(reader.GetLine(line)); 1102 TEST_ THAT(line == "Send GetIsAlive()");1123 TEST_EQUAL("Send GetIsAlive()", line, line); 1103 1124 TEST_THAT(reader.GetLine(line)); 1104 TEST_ THAT(line == "Receive IsAlive()");1125 TEST_EQUAL("Receive IsAlive()", line, line); 1105 1126 TEST_THAT(reader.GetLine(line)); 1106 TEST_ THAT(line == "Send GetIsAlive()");1127 TEST_EQUAL("Send GetIsAlive()", line, line); 1107 1128 TEST_THAT(reader.GetLine(line)); 1108 TEST_ THAT(line == "Receive IsAlive()");1129 TEST_EQUAL("Receive IsAlive()", line, line); 1109 1130 } 1110 1131
Note: See TracChangeset
for help on using the changeset viewer.
