diff options
author | josh.macdonald <jmacd@users.noreply.github.com> | 2008-08-08 04:08:12 +0000 |
---|---|---|
committer | josh.macdonald <jmacd@users.noreply.github.com> | 2008-08-08 04:08:12 +0000 |
commit | d21bd984620e5a095ac94120e4467aeff36788c5 (patch) | |
tree | 2e0d6b0d8d74f34fb9fb47cc1c40cfa8cf4e6c7e | |
parent | f0dd5487e10baa0e896fb0b2067151495250db40 (diff) |
The merge test isn't writing data for 0-byte target files because
InMemoryEncodeDecode fails at this where xdelta3-main.h succeeds.
This gets back to a TODO in -main.h about zero-size ambiguity.
-rw-r--r-- | xdelta3/testing/file.h | 9 | ||||
-rw-r--r-- | xdelta3/testing/regtest.cc | 29 | ||||
-rw-r--r-- | xdelta3/testing/test.h | 7 |
3 files changed, 35 insertions, 10 deletions
diff --git a/xdelta3/testing/file.h b/xdelta3/testing/file.h index 1205bc0..d3b9d4a 100644 --- a/xdelta3/testing/file.h +++ b/xdelta3/testing/file.h | |||
@@ -117,6 +117,11 @@ public: | |||
117 | } | 117 | } |
118 | 118 | ||
119 | uint8_t* Data() const { | 119 | uint8_t* Data() const { |
120 | if (data_ == NULL) { | ||
121 | CHECK_EQ(0, size_); | ||
122 | data_size_ = 1; | ||
123 | data_ = new uint8_t[1]; | ||
124 | } | ||
120 | return data_; | 125 | return data_; |
121 | } | 126 | } |
122 | 127 | ||
@@ -147,8 +152,8 @@ private: | |||
147 | 152 | ||
148 | friend class BlockIterator; | 153 | friend class BlockIterator; |
149 | 154 | ||
150 | uint8_t *data_; | 155 | mutable uint8_t *data_; |
151 | size_t data_size_; | 156 | mutable size_t data_size_; |
152 | size_t size_; | 157 | size_t size_; |
153 | }; | 158 | }; |
154 | 159 | ||
diff --git a/xdelta3/testing/regtest.cc b/xdelta3/testing/regtest.cc index 7da4110..8bfcf51 100644 --- a/xdelta3/testing/regtest.cc +++ b/xdelta3/testing/regtest.cc | |||
@@ -107,8 +107,8 @@ void InMemoryEncodeDecode(const TestOptions &options, | |||
107 | ret = xd3_decode_input(&decode_stream); | 107 | ret = xd3_decode_input(&decode_stream); |
108 | } | 108 | } |
109 | 109 | ||
110 | //DP(RINT "%s = %s\n", encoding ? "encoding" : "decoding", | 110 | DP(RINT "%s = %s\n", encoding ? "encoding" : "decoding", |
111 | // xd3_strerror(ret)); | 111 | xd3_strerror(ret)); |
112 | 112 | ||
113 | switch (ret) { | 113 | switch (ret) { |
114 | case XD3_OUTPUT: | 114 | case XD3_OUTPUT: |
@@ -146,11 +146,15 @@ void InMemoryEncodeDecode(const TestOptions &options, | |||
146 | 146 | ||
147 | case XD3_INPUT: | 147 | case XD3_INPUT: |
148 | if (!encoding) { | 148 | if (!encoding) { |
149 | if (target_block.Size() < target_iterator.BlockSize()) { | ||
150 | done = true; | ||
151 | continue; | ||
152 | } | ||
149 | encoding = true; | 153 | encoding = true; |
150 | goto process; | 154 | goto process; |
151 | } else { | 155 | } else { |
152 | if (target_block.Size() < target_iterator.BlockSize()) { | 156 | if (target_block.Size() < target_iterator.BlockSize()) { |
153 | done = true; | 157 | encoding = false; |
154 | } else { | 158 | } else { |
155 | target_iterator.Next(); | 159 | target_iterator.Next(); |
156 | } | 160 | } |
@@ -162,7 +166,7 @@ void InMemoryEncodeDecode(const TestOptions &options, | |||
162 | encoding = false; | 166 | encoding = false; |
163 | } else { | 167 | } else { |
164 | CHECK_EQ(0, CmpDifferentBlockBytes(decoded_block, target_block)); | 168 | CHECK_EQ(0, CmpDifferentBlockBytes(decoded_block, target_block)); |
165 | //DP(RINT "verified block %"Q"u\n", target_iterator.Blkno()); | 169 | DP(RINT "verified block %"Q"u\n", target_iterator.Blkno()); |
166 | decoded_block.Reset(); | 170 | decoded_block.Reset(); |
167 | encoding = true; | 171 | encoding = true; |
168 | } | 172 | } |
@@ -603,6 +607,21 @@ void TestNonBlockingProgress() { | |||
603 | InMemoryEncodeDecode(options, spec1, spec2, NULL); | 607 | InMemoryEncodeDecode(options, spec1, spec2, NULL); |
604 | } | 608 | } |
605 | 609 | ||
610 | void TestEmptyInMemory() { | ||
611 | MTRandom rand; | ||
612 | FileSpec spec0(&rand); | ||
613 | FileSpec spec1(&rand); | ||
614 | TestOptions options; | ||
615 | Block delta; | ||
616 | |||
617 | spec0.GenerateFixedSize(0); | ||
618 | spec1.GenerateFixedSize(0); | ||
619 | |||
620 | InMemoryEncodeDecode(options, spec0, spec1, &delta); | ||
621 | |||
622 | CHECK_LT(0, delta.Size()); | ||
623 | } | ||
624 | |||
606 | void FourWayMergeTest(const TestOptions &options, | 625 | void FourWayMergeTest(const TestOptions &options, |
607 | const FileSpec &spec0, | 626 | const FileSpec &spec0, |
608 | const FileSpec &spec1, | 627 | const FileSpec &spec1, |
@@ -633,7 +652,6 @@ void FourWayMergeTest(const TestOptions &options, | |||
633 | }; | 652 | }; |
634 | 653 | ||
635 | CHECK_EQ(0, xd3_main_cmdline(SIZEOF_ARRAY(argv) - 1, (char**)argv)); | 654 | CHECK_EQ(0, xd3_main_cmdline(SIZEOF_ARRAY(argv) - 1, (char**)argv)); |
636 | |||
637 | } | 655 | } |
638 | 656 | ||
639 | void TestMergeCommand() { | 657 | void TestMergeCommand() { |
@@ -708,6 +726,7 @@ int main(int argc, char **argv) { | |||
708 | // TEST(TestMoveMutator); | 726 | // TEST(TestMoveMutator); |
709 | // TEST(TestOverwriteMutator); | 727 | // TEST(TestOverwriteMutator); |
710 | // TEST(TestNonBlockingProgress); | 728 | // TEST(TestNonBlockingProgress); |
729 | TEST(TestEmptyInMemory); | ||
711 | TEST(TestMergeCommand); | 730 | TEST(TestMergeCommand); |
712 | return 0; | 731 | return 0; |
713 | } | 732 | } |
diff --git a/xdelta3/testing/test.h b/xdelta3/testing/test.h index 32b62c0..536673b 100644 --- a/xdelta3/testing/test.h +++ b/xdelta3/testing/test.h | |||
@@ -15,10 +15,11 @@ extern "C" { | |||
15 | #define CHECK_GE(x,y) CHECK_OP(x,y,>=) | 15 | #define CHECK_GE(x,y) CHECK_OP(x,y,>=) |
16 | 16 | ||
17 | #define CHECK_OP(x,y,OP) \ | 17 | #define CHECK_OP(x,y,OP) \ |
18 | do {if (!((x) OP (y))) { \ | 18 | do { typeof((x) OP (y)) _x(x), _y(y); \ |
19 | if (!(_x OP _y)) { \ | ||
19 | cerr << __FILE__ << ":" << __LINE__ << " Check failed: " << #x " " #OP " " #y << endl; \ | 20 | cerr << __FILE__ << ":" << __LINE__ << " Check failed: " << #x " " #OP " " #y << endl; \ |
20 | cerr << __FILE__ << ":" << __LINE__ << " Expected: " << x << endl; \ | 21 | cerr << __FILE__ << ":" << __LINE__ << " Expected: " << _x << endl; \ |
21 | cerr << __FILE__ << ":" << __LINE__ << " Actual: " << y << endl; \ | 22 | cerr << __FILE__ << ":" << __LINE__ << " Actual: " << _y << endl; \ |
22 | abort(); \ | 23 | abort(); \ |
23 | } } while (false) | 24 | } } while (false) |
24 | 25 | ||