summaryrefslogtreecommitdiff
path: root/xdelta3/testing/regtest.cc
diff options
context:
space:
mode:
authorjosh.macdonald <jmacd@users.noreply.github.com>2009-03-08 03:39:35 +0000
committerjosh.macdonald <jmacd@users.noreply.github.com>2009-03-08 03:39:35 +0000
commitc2ac8336ee676ec6f2d3a24e6eeb339a5fda30ba (patch)
treee0206139b17183de6393f9826da9873a15a2bc00 /xdelta3/testing/regtest.cc
parent9be16d928d7386488efc34bd99293b3360105da0 (diff)
Testing for issue 79. TODO around xdelta3.c:3926 successful.
Diffstat (limited to 'xdelta3/testing/regtest.cc')
-rw-r--r--xdelta3/testing/regtest.cc40
1 files changed, 27 insertions, 13 deletions
diff --git a/xdelta3/testing/regtest.cc b/xdelta3/testing/regtest.cc
index 910a8db..7618b38 100644
--- a/xdelta3/testing/regtest.cc
+++ b/xdelta3/testing/regtest.cc
@@ -64,21 +64,30 @@ void InMemoryEncodeDecode(const FileSpec &source_file,
64 xd3_set_source (&encode_stream, &encode_source); 64 xd3_set_source (&encode_stream, &encode_source);
65 xd3_set_source (&decode_stream, &decode_source); 65 xd3_set_source (&decode_stream, &decode_source);
66 66
67 BlockIterator source_iterator(source_file); 67 BlockIterator source_iterator(source_file, Constants::BLOCK_SIZE);
68 BlockIterator target_iterator(target_file); 68 BlockIterator target_iterator(target_file, Constants::READ_SIZE);
69 Block encode_source_block, decode_source_block; 69 Block encode_source_block, decode_source_block;
70 Block decoded_block, target_block; 70 Block decoded_block, target_block;
71 bool encoding = true; 71 bool encoding = true;
72 bool done = false; 72 bool done = false;
73 bool done_after_input = false;
73 74
74 DP(RINT "source %"Q"u target %"Q"u\n", 75 DP(RINT "source %"Q"u[%"Q"u] target %"Q"u[%lu] winsize %lu\n",
75 source_file.Size(), target_file.Size()); 76 source_file.Size(), Constants::BLOCK_SIZE,
77 target_file.Size(), Constants::READ_SIZE,
78 Constants::WINDOW_SIZE);
76 79
77 while (!done) { 80 while (!done) {
78 target_iterator.Get(&target_block); 81 target_iterator.Get(&target_block);
79 82
80 if (target_file.Blocks() == 0 || 83 xoff_t blks = target_iterator.Blocks();
81 target_iterator.Blkno() == (target_file.Blocks() - 1)) { 84
85 //DP(RINT "target in %s: %llu..%llu %"Q"u(%"Q"u) verified %"Q"u\n",
86 // encoding ? "encoding" : "decoding",
87 // target_iterator.Offset(), target_iterator.Offset() + target_block.Size(),
88 // target_iterator.Blkno(), blks, verified_bytes);
89
90 if (blks == 0 || target_iterator.Blkno() == (blks - 1)) {
82 xd3_set_flags(&encode_stream, XD3_FLUSH | encode_stream.flags); 91 xd3_set_flags(&encode_stream, XD3_FLUSH | encode_stream.flags);
83 } 92 }
84 93
@@ -93,7 +102,7 @@ void InMemoryEncodeDecode(const FileSpec &source_file,
93 ret = xd3_decode_input(&decode_stream); 102 ret = xd3_decode_input(&decode_stream);
94 } 103 }
95 104
96 //DP(RINT "%s = %s\n", encoding ? "encoding" : "decoding", 105 //DP(RINT "%s = %s\n", encoding ? "E " : " D",
97 // xd3_strerror(ret)); 106 // xd3_strerror(ret));
98 107
99 switch (ret) { 108 switch (ret) {
@@ -141,6 +150,11 @@ void InMemoryEncodeDecode(const FileSpec &source_file,
141 encoding = true; 150 encoding = true;
142 goto process; 151 goto process;
143 } else { 152 } else {
153 if (done_after_input) {
154 done = true;
155 continue;
156 }
157
144 if (target_block.Size() < target_iterator.BlockSize()) { 158 if (target_block.Size() < target_iterator.BlockSize()) {
145 encoding = false; 159 encoding = false;
146 } else { 160 } else {
@@ -152,8 +166,7 @@ void InMemoryEncodeDecode(const FileSpec &source_file,
152 case XD3_WINFINISH: 166 case XD3_WINFINISH:
153 if (encoding) { 167 if (encoding) {
154 if (encode_stream.flags & XD3_FLUSH) { 168 if (encode_stream.flags & XD3_FLUSH) {
155 done = true; 169 done_after_input = true;
156 continue;
157 } 170 }
158 encoding = false; 171 encoding = false;
159 } else { 172 } else {
@@ -285,7 +298,7 @@ void TestFirstByte() {
285 spec0.ModifyTo(Modify1stByte(), &spec1); 298 spec0.ModifyTo(Modify1stByte(), &spec1);
286 CHECK_EQ(1, CmpDifferentBytes(spec0, spec1)); 299 CHECK_EQ(1, CmpDifferentBytes(spec0, spec1));
287 300
288 SizeIterator<size_t, Sizes> si(&rand, 0); 301 SizeIterator<size_t, Sizes> si(&rand, Constants::TEST_ROUNDS);
289 302
290 for (; !si.Done(); si.Next()) { 303 for (; !si.Done(); si.Next()) {
291 size_t size = si.Get(); 304 size_t size = si.Get();
@@ -517,7 +530,7 @@ void TestNonBlockingProgress() {
517 FileSpec spec1(&rand); 530 FileSpec spec1(&rand);
518 FileSpec spec2(&rand); 531 FileSpec spec2(&rand);
519 532
520 spec0.GenerateFixedSize(Constants::BLOCK_SIZE * 2); 533 spec0.GenerateFixedSize(Constants::BLOCK_SIZE * 3);
521 534
522 // This is a lazy target match 535 // This is a lazy target match
523 Change ct(Change::OVERWRITE, 22, 536 Change ct(Change::OVERWRITE, 22,
@@ -581,7 +594,7 @@ void TestBlockInMemory() {
581 InMemoryEncodeDecode(spec0, spec1, &block); 594 InMemoryEncodeDecode(spec0, spec1, &block);
582 595
583 Delta delta(block); 596 Delta delta(block);
584 CHECK_EQ(1, delta.Windows()); 597 CHECK_EQ(spec1.Blocks(Constants::WINDOW_SIZE), delta.Windows());
585} 598}
586 599
587void FourWayMergeTest(const FileSpec &spec0, 600void FourWayMergeTest(const FileSpec &spec0,
@@ -616,7 +629,7 @@ void FourWayMergeTest(const FileSpec &spec0,
616 mcmd.push_back(out.Name()); 629 mcmd.push_back(out.Name());
617 mcmd.push_back(NULL); 630 mcmd.push_back(NULL);
618 631
619 DP(RINT "Running one merge: %s\n", CommandToString(mcmd).c_str()); 632 //DP(RINT "Running one merge: %s\n", CommandToString(mcmd).c_str());
620 CHECK_EQ(0, xd3_main_cmdline(mcmd.size() - 1, 633 CHECK_EQ(0, xd3_main_cmdline(mcmd.size() - 1,
621 const_cast<char**>(&mcmd[0]))); 634 const_cast<char**>(&mcmd[0])));
622 635
@@ -786,6 +799,7 @@ int main(int argc, char **argv) {
786 UnitTest<SmallBlock>(); 799 UnitTest<SmallBlock>();
787 MainTest<SmallBlock>(); 800 MainTest<SmallBlock>();
788 MainTest<MixedBlock>(); 801 MainTest<MixedBlock>();
802 MainTest<PrimeBlock>();
789 MainTest<OversizeBlock>(); 803 MainTest<OversizeBlock>();
790 MainTest<LargeBlock>(); 804 MainTest<LargeBlock>();
791 return 0; 805 return 0;