diff options
Diffstat (limited to 'xdelta3/testing')
-rw-r--r-- | xdelta3/testing/file.h | 4 | ||||
-rw-r--r-- | xdelta3/testing/regtest.cc | 29 | ||||
-rw-r--r-- | xdelta3/testing/test.h | 8 |
3 files changed, 28 insertions, 13 deletions
diff --git a/xdelta3/testing/file.h b/xdelta3/testing/file.h index dae97de..b775f4f 100644 --- a/xdelta3/testing/file.h +++ b/xdelta3/testing/file.h | |||
@@ -211,8 +211,8 @@ inline void BlockIterator::Get(Block *block) const { | |||
211 | gen.Rand32(); | 211 | gen.Rand32(); |
212 | } | 212 | } |
213 | 213 | ||
214 | for (size_t i = seg_offset; i < pos->second.length; i++) { | 214 | for (size_t i = seg_offset; |
215 | CHECK_LT(got, blksize_); | 215 | i < pos->second.length && got < blksize_; i++) { |
216 | block->data_[got++] = gen.Rand32(); | 216 | block->data_[got++] = gen.Rand32(); |
217 | } | 217 | } |
218 | 218 | ||
diff --git a/xdelta3/testing/regtest.cc b/xdelta3/testing/regtest.cc index 0e541ec..12499ba 100644 --- a/xdelta3/testing/regtest.cc +++ b/xdelta3/testing/regtest.cc | |||
@@ -255,14 +255,29 @@ void TestModifyMutator() { | |||
255 | 255 | ||
256 | spec0.GenerateFixedSize(Constants::BLOCK_SIZE * 3); | 256 | spec0.GenerateFixedSize(Constants::BLOCK_SIZE * 3); |
257 | 257 | ||
258 | ChangeList cl1; | 258 | struct { |
259 | cl1.push_back(Change(Change::MODIFY, Constants::BLOCK_SIZE, 0)); | 259 | size_t size; |
260 | spec0.Print(); | 260 | size_t addr; |
261 | spec0.ModifyTo(ChangeListMutator(cl1), &spec1); | 261 | } test_cases[] = { |
262 | spec1.Print(); | 262 | { Constants::BLOCK_SIZE, 0 }, |
263 | CHECK_EQ(Constants::BLOCK_SIZE, CmpDifferentBytes(spec0, spec1)); | 263 | { Constants::BLOCK_SIZE / 2, 1 }, |
264 | InMemoryEncodeDecode(spec0, spec1); | 264 | { Constants::BLOCK_SIZE, 1 }, |
265 | { Constants::BLOCK_SIZE * 2, 1 }, | ||
266 | }; | ||
267 | |||
268 | for (size_t i = 0; i < SIZEOF_ARRAY(test_cases); i++) { | ||
269 | ChangeList cl1; | ||
270 | cl1.push_back(Change(Change::MODIFY, test_cases[i].size, test_cases[i].addr)); | ||
271 | spec0.Print(); | ||
272 | spec0.ModifyTo(ChangeListMutator(cl1), &spec1); | ||
273 | spec1.Print(); | ||
274 | |||
275 | size_t diff = CmpDifferentBytes(spec0, spec1); | ||
276 | CHECK_LE(diff, test_cases[i].size); | ||
277 | CHECK_GE(diff, test_cases[i].size - (2 * test_cases[i].size / 256)); | ||
265 | 278 | ||
279 | InMemoryEncodeDecode(spec0, spec1); | ||
280 | } | ||
266 | } | 281 | } |
267 | 282 | ||
268 | int main(int argc, char **argv) { | 283 | int main(int argc, char **argv) { |
diff --git a/xdelta3/testing/test.h b/xdelta3/testing/test.h index 53692fa..12f6b34 100644 --- a/xdelta3/testing/test.h +++ b/xdelta3/testing/test.h | |||
@@ -15,15 +15,15 @@ extern "C" { | |||
15 | 15 | ||
16 | #define CHECK_OP(x,y,OP) \ | 16 | #define CHECK_OP(x,y,OP) \ |
17 | do {if (!((x) OP (y))) { \ | 17 | do {if (!((x) OP (y))) { \ |
18 | cerr << "Check failed: " << #x " " #OP " " #y << endl; \ | 18 | cerr << __FILE__ << ":" << __LINE__ << " Check failed: " << #x " " #OP " " #y << endl; \ |
19 | cerr << "Expected: " << x << endl; \ | 19 | cerr << __FILE__ << ":" << __LINE__ << " Expected: " << x << endl; \ |
20 | cerr << "Actual: " << y << endl; \ | 20 | cerr << __FILE__ << ":" << __LINE__ << " Actual: " << y << endl; \ |
21 | abort(); \ | 21 | abort(); \ |
22 | } } while (false) | 22 | } } while (false) |
23 | 23 | ||
24 | #define CHECK(x) \ | 24 | #define CHECK(x) \ |
25 | do {if (!(x)) { \ | 25 | do {if (!(x)) { \ |
26 | cerr << "Check failed: " << #x << endl; \ | 26 | cerr << __FILE__ << ":" << __LINE__ << " Check failed: " << #x << endl; \ |
27 | abort(); \ | 27 | abort(); \ |
28 | } } while (false) | 28 | } } while (false) |
29 | 29 | ||