diff options
Diffstat (limited to 'xdelta3')
-rw-r--r-- | xdelta3/testing/file.h | 20 | ||||
-rw-r--r-- | xdelta3/testing/regtest.cc | 39 |
2 files changed, 55 insertions, 4 deletions
diff --git a/xdelta3/testing/file.h b/xdelta3/testing/file.h index 2e25824..c281de9 100644 --- a/xdelta3/testing/file.h +++ b/xdelta3/testing/file.h | |||
@@ -158,6 +158,10 @@ public: | |||
158 | blkno_++; | 158 | blkno_++; |
159 | } | 159 | } |
160 | 160 | ||
161 | xoff_t Blkno() const { | ||
162 | return blkno_; | ||
163 | } | ||
164 | |||
161 | void SetBlock(xoff_t blkno) { | 165 | void SetBlock(xoff_t blkno) { |
162 | blkno_ = blkno; | 166 | blkno_ = blkno; |
163 | } | 167 | } |
@@ -165,11 +169,19 @@ public: | |||
165 | void Get(Block *block) const; | 169 | void Get(Block *block) const; |
166 | 170 | ||
167 | size_t BytesOnBlock() const { | 171 | size_t BytesOnBlock() const { |
168 | // Blocks() is unsigned, don't subtract | 172 | xoff_t blocks = spec_.Blocks(blksize_); |
169 | if (blkno_ + 1 < spec_.Blocks(blksize_)) { | 173 | xoff_t size = spec_.Size(); |
170 | return blksize_; | 174 | |
175 | CHECK((blkno_ < blocks) || | ||
176 | (blkno_ == blocks && size % blksize_ == 0)); | ||
177 | |||
178 | if (blkno_ == blocks) { | ||
179 | return 0; | ||
180 | } | ||
181 | if (blkno_ + 1 == blocks) { | ||
182 | return ((size - 1) % blksize_) + 1; | ||
171 | } | 183 | } |
172 | return spec_.Size() % blksize_; | 184 | return blksize_; |
173 | } | 185 | } |
174 | 186 | ||
175 | size_t BlockSize() const { | 187 | size_t BlockSize() const { |
diff --git a/xdelta3/testing/regtest.cc b/xdelta3/testing/regtest.cc index f0c55b4..f64111e 100644 --- a/xdelta3/testing/regtest.cc +++ b/xdelta3/testing/regtest.cc | |||
@@ -25,9 +25,22 @@ void InMemoryEncodeDecode(FileSpec &source_file, FileSpec &target_file) { | |||
25 | xd3_init_config(&encode_config, XD3_ADLER32); | 25 | xd3_init_config(&encode_config, XD3_ADLER32); |
26 | xd3_init_config(&decode_config, XD3_ADLER32); | 26 | xd3_init_config(&decode_config, XD3_ADLER32); |
27 | 27 | ||
28 | encode_config.winsize = Constants::BLOCK_SIZE; | ||
29 | |||
28 | CHECK_EQ(0, xd3_config_stream (&encode_stream, &encode_config)); | 30 | CHECK_EQ(0, xd3_config_stream (&encode_stream, &encode_config)); |
29 | CHECK_EQ(0, xd3_config_stream (&decode_stream, &decode_config)); | 31 | CHECK_EQ(0, xd3_config_stream (&decode_stream, &decode_config)); |
30 | 32 | ||
33 | encode_source.size = source_file.Size(); | ||
34 | encode_source.blksize = Constants::BLOCK_SIZE; | ||
35 | encode_source.curblkno = -1; | ||
36 | |||
37 | decode_source.size = source_file.Size(); | ||
38 | decode_source.blksize = Constants::BLOCK_SIZE; | ||
39 | decode_source.curblkno = -1; | ||
40 | |||
41 | xd3_set_source (&encode_stream, &encode_source); | ||
42 | xd3_set_source (&decode_stream, &decode_source); | ||
43 | |||
31 | BlockIterator source_iterator(source_file); | 44 | BlockIterator source_iterator(source_file); |
32 | BlockIterator target_iterator(target_file); | 45 | BlockIterator target_iterator(target_file); |
33 | Block encode_source_block, decode_source_block; | 46 | Block encode_source_block, decode_source_block; |
@@ -35,6 +48,9 @@ void InMemoryEncodeDecode(FileSpec &source_file, FileSpec &target_file) { | |||
35 | bool encoding = true; | 48 | bool encoding = true; |
36 | bool done = false; | 49 | bool done = false; |
37 | 50 | ||
51 | DP(RINT "source %"Q"u target %"Q"u\n", | ||
52 | source_file.Size(), target_file.Size()); | ||
53 | |||
38 | while (!done) { | 54 | while (!done) { |
39 | target_iterator.Get(&target_block); | 55 | target_iterator.Get(&target_block); |
40 | 56 | ||
@@ -52,6 +68,9 @@ void InMemoryEncodeDecode(FileSpec &source_file, FileSpec &target_file) { | |||
52 | ret = xd3_decode_input(&decode_stream); | 68 | ret = xd3_decode_input(&decode_stream); |
53 | } | 69 | } |
54 | 70 | ||
71 | DP(RINT "%s = %s\n", encoding ? "encoding" : "decoding", | ||
72 | xd3_strerror(ret)); | ||
73 | |||
55 | switch (ret) { | 74 | switch (ret) { |
56 | case XD3_OUTPUT: | 75 | case XD3_OUTPUT: |
57 | if (encoding) { | 76 | if (encoding) { |
@@ -87,6 +106,8 @@ void InMemoryEncodeDecode(FileSpec &source_file, FileSpec &target_file) { | |||
87 | } else { | 106 | } else { |
88 | if (target_block.Size() < target_iterator.BlockSize()) { | 107 | if (target_block.Size() < target_iterator.BlockSize()) { |
89 | done = true; | 108 | done = true; |
109 | } else { | ||
110 | target_iterator.Next(); | ||
90 | } | 111 | } |
91 | continue; | 112 | continue; |
92 | } | 113 | } |
@@ -96,6 +117,7 @@ void InMemoryEncodeDecode(FileSpec &source_file, FileSpec &target_file) { | |||
96 | encoding = false; | 117 | encoding = false; |
97 | } else { | 118 | } else { |
98 | CHECK_EQ(0, CmpDifferentBlockBytes(decoded_block, target_block)); | 119 | CHECK_EQ(0, CmpDifferentBlockBytes(decoded_block, target_block)); |
120 | DP(RINT "verified block %"Q"u\n", target_iterator.Blkno()); | ||
99 | decoded_block.Reset(); | 121 | decoded_block.Reset(); |
100 | encoding = true; | 122 | encoding = true; |
101 | } | 123 | } |
@@ -152,31 +174,48 @@ void TestRandomNumbers() { | |||
152 | void TestRandomFile() { | 174 | void TestRandomFile() { |
153 | MTRandom rand1; | 175 | MTRandom rand1; |
154 | FileSpec spec1(&rand1); | 176 | FileSpec spec1(&rand1); |
177 | BlockIterator bi(spec1); | ||
155 | 178 | ||
156 | spec1.GenerateFixedSize(0); | 179 | spec1.GenerateFixedSize(0); |
157 | CHECK_EQ(0, spec1.Size()); | 180 | CHECK_EQ(0, spec1.Size()); |
158 | CHECK_EQ(0, spec1.Segments()); | 181 | CHECK_EQ(0, spec1.Segments()); |
159 | CHECK_EQ(0, spec1.Blocks()); | 182 | CHECK_EQ(0, spec1.Blocks()); |
183 | bi.SetBlock(0); | ||
184 | CHECK_EQ(0, bi.BytesOnBlock()); | ||
160 | 185 | ||
161 | spec1.GenerateFixedSize(1); | 186 | spec1.GenerateFixedSize(1); |
162 | CHECK_EQ(1, spec1.Size()); | 187 | CHECK_EQ(1, spec1.Size()); |
163 | CHECK_EQ(1, spec1.Segments()); | 188 | CHECK_EQ(1, spec1.Segments()); |
164 | CHECK_EQ(1, spec1.Blocks()); | 189 | CHECK_EQ(1, spec1.Blocks()); |
190 | bi.SetBlock(0); | ||
191 | CHECK_EQ(1, bi.BytesOnBlock()); | ||
165 | 192 | ||
166 | spec1.GenerateFixedSize(Constants::BLOCK_SIZE); | 193 | spec1.GenerateFixedSize(Constants::BLOCK_SIZE); |
167 | CHECK_EQ(Constants::BLOCK_SIZE, spec1.Size()); | 194 | CHECK_EQ(Constants::BLOCK_SIZE, spec1.Size()); |
168 | CHECK_EQ(1, spec1.Segments()); | 195 | CHECK_EQ(1, spec1.Segments()); |
169 | CHECK_EQ(1, spec1.Blocks()); | 196 | CHECK_EQ(1, spec1.Blocks()); |
197 | bi.SetBlock(0); | ||
198 | CHECK_EQ(Constants::BLOCK_SIZE, bi.BytesOnBlock()); | ||
199 | bi.SetBlock(1); | ||
200 | CHECK_EQ(0, bi.BytesOnBlock()); | ||
170 | 201 | ||
171 | spec1.GenerateFixedSize(Constants::BLOCK_SIZE + 1); | 202 | spec1.GenerateFixedSize(Constants::BLOCK_SIZE + 1); |
172 | CHECK_EQ(Constants::BLOCK_SIZE + 1, spec1.Size()); | 203 | CHECK_EQ(Constants::BLOCK_SIZE + 1, spec1.Size()); |
173 | CHECK_EQ(2, spec1.Segments()); | 204 | CHECK_EQ(2, spec1.Segments()); |
174 | CHECK_EQ(2, spec1.Blocks()); | 205 | CHECK_EQ(2, spec1.Blocks()); |
206 | bi.SetBlock(0); | ||
207 | CHECK_EQ(Constants::BLOCK_SIZE, bi.BytesOnBlock()); | ||
208 | bi.SetBlock(1); | ||
209 | CHECK_EQ(1, bi.BytesOnBlock()); | ||
175 | 210 | ||
176 | spec1.GenerateFixedSize(Constants::BLOCK_SIZE * 2); | 211 | spec1.GenerateFixedSize(Constants::BLOCK_SIZE * 2); |
177 | CHECK_EQ(Constants::BLOCK_SIZE * 2, spec1.Size()); | 212 | CHECK_EQ(Constants::BLOCK_SIZE * 2, spec1.Size()); |
178 | CHECK_EQ(2, spec1.Segments()); | 213 | CHECK_EQ(2, spec1.Segments()); |
179 | CHECK_EQ(2, spec1.Blocks()); | 214 | CHECK_EQ(2, spec1.Blocks()); |
215 | bi.SetBlock(0); | ||
216 | CHECK_EQ(Constants::BLOCK_SIZE, bi.BytesOnBlock()); | ||
217 | bi.SetBlock(1); | ||
218 | CHECK_EQ(Constants::BLOCK_SIZE, bi.BytesOnBlock()); | ||
180 | } | 219 | } |
181 | 220 | ||
182 | void TestFirstByte() { | 221 | void TestFirstByte() { |