diff options
author | josh.macdonald <jmacd@users.noreply.github.com> | 2008-07-03 03:44:56 +0000 |
---|---|---|
committer | josh.macdonald <jmacd@users.noreply.github.com> | 2008-07-03 03:44:56 +0000 |
commit | 647321d6bb4c41593228c8c7a5c29e92e839885c (patch) | |
tree | 32277ddc33cfeaf72fe7854289990380520cb073 /xdelta3/testing/regtest.cc | |
parent | 39986a1759550d3d5083e710862295588837f719 (diff) |
Encode/Decode test operating correctly, now failing with source data.
Diffstat (limited to 'xdelta3/testing/regtest.cc')
-rw-r--r-- | xdelta3/testing/regtest.cc | 39 |
1 files changed, 39 insertions, 0 deletions
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() { |