summaryrefslogtreecommitdiff
path: root/xdelta3/testing
diff options
context:
space:
mode:
authorjosh.macdonald <jmacd@users.noreply.github.com>2008-07-03 12:59:37 +0000
committerjosh.macdonald <jmacd@users.noreply.github.com>2008-07-03 12:59:37 +0000
commitd4f98ead39af5d47905166bfc2a6e1e94540bc23 (patch)
treec43d47174288727d56be8a2c0335e8b729daabe1 /xdelta3/testing
parent647321d6bb4c41593228c8c7a5c29e92e839885c (diff)
Test for encode/decode w/ single first-byte difference. Uncovered a couple of
incorrect assertions in xdelta3 proper. More tests coming...
Diffstat (limited to 'xdelta3/testing')
-rw-r--r--xdelta3/testing/regtest.cc32
-rw-r--r--xdelta3/testing/sizes.h55
-rw-r--r--xdelta3/testing/test.h4
3 files changed, 72 insertions, 19 deletions
diff --git a/xdelta3/testing/regtest.cc b/xdelta3/testing/regtest.cc
index f64111e..3b4d4c6 100644
--- a/xdelta3/testing/regtest.cc
+++ b/xdelta3/testing/regtest.cc
@@ -68,8 +68,8 @@ void InMemoryEncodeDecode(FileSpec &source_file, FileSpec &target_file) {
68 ret = xd3_decode_input(&decode_stream); 68 ret = xd3_decode_input(&decode_stream);
69 } 69 }
70 70
71 DP(RINT "%s = %s\n", encoding ? "encoding" : "decoding", 71 //DP(RINT "%s = %s\n", encoding ? "encoding" : "decoding",
72 xd3_strerror(ret)); 72 // xd3_strerror(ret));
73 73
74 switch (ret) { 74 switch (ret) {
75 case XD3_OUTPUT: 75 case XD3_OUTPUT:
@@ -117,7 +117,7 @@ void InMemoryEncodeDecode(FileSpec &source_file, FileSpec &target_file) {
117 encoding = false; 117 encoding = false;
118 } else { 118 } else {
119 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()); 120 //DP(RINT "verified block %"Q"u\n", target_iterator.Blkno());
121 decoded_block.Reset(); 121 decoded_block.Reset();
122 encoding = true; 122 encoding = true;
123 } 123 }
@@ -236,23 +236,18 @@ void TestFirstByte() {
236 spec0.GenerateFixedSize(Constants::BLOCK_SIZE + 1); 236 spec0.GenerateFixedSize(Constants::BLOCK_SIZE + 1);
237 spec0.ModifyTo<Modify1stByte>(&spec1); 237 spec0.ModifyTo<Modify1stByte>(&spec1);
238 CHECK_EQ(1, CmpDifferentBytes(spec0, spec1)); 238 CHECK_EQ(1, CmpDifferentBytes(spec0, spec1));
239}
240
241void TestBasicEncodeDecode() {
242 MTRandom rand;
243 FileSpec spec0(&rand);
244 FileSpec spec1(&rand);
245 spec0.GenerateFixedSize(1024);
246 spec0.ModifyTo<Modify1stByte>(&spec1);
247 InMemoryEncodeDecode(spec0, spec1);
248 239
249 spec0.GenerateFixedSize(Constants::BLOCK_SIZE); 240 SizeIterator<size_t, SmallSizes> si(&rand, 20);
250 spec0.ModifyTo<Modify1stByte>(&spec1);
251 InMemoryEncodeDecode(spec0, spec1);
252 241
253 spec0.GenerateFixedSize(Constants::BLOCK_SIZE * 2); 242 for (; !si.Done(); si.Next()) {
254 spec0.ModifyTo<Modify1stByte>(&spec1); 243 size_t size = si.Get();
255 InMemoryEncodeDecode(spec0, spec1); 244 if (size == 0) {
245 continue;
246 }
247 spec0.GenerateFixedSize(size);
248 spec0.ModifyTo<Modify1stByte>(&spec1);
249 InMemoryEncodeDecode(spec0, spec1);
250 }
256} 251}
257 252
258int main(int argc, char **argv) { 253int main(int argc, char **argv) {
@@ -260,7 +255,6 @@ int main(int argc, char **argv) {
260 TEST(TestRandomNumbers); 255 TEST(TestRandomNumbers);
261 TEST(TestRandomFile); 256 TEST(TestRandomFile);
262 TEST(TestFirstByte); 257 TEST(TestFirstByte);
263 TEST(TestBasicEncodeDecode);
264 return 0; 258 return 0;
265} 259}
266 260
diff --git a/xdelta3/testing/sizes.h b/xdelta3/testing/sizes.h
new file mode 100644
index 0000000..8913baa
--- /dev/null
+++ b/xdelta3/testing/sizes.h
@@ -0,0 +1,55 @@
1// -*- Mode: C++ -*-
2namespace regtest {
3
4template <typename T, typename U>
5class SizeIterator {
6 public:
7 SizeIterator(MTRandom *rand, size_t howmany)
8 : rand_(rand),
9 count_(0),
10 fixed_(U::sizes),
11 fixed_size_(SIZEOF_ARRAY(U::sizes)),
12 howmany_(howmany) { }
13
14 T Get() {
15 if (count_ < fixed_size_) {
16 return fixed_[count_];
17 }
18 return rand_->Rand<T>() % U::max_value;
19 }
20
21 bool Done() {
22 return count_ >= howmany_;
23 }
24
25 void Next() {
26 count_++;
27 }
28
29 private:
30 MTRandom *rand_;
31 size_t count_;
32 T* fixed_;
33 size_t fixed_size_;
34 size_t howmany_;
35};
36
37class SmallSizes {
38public:
39 static size_t sizes[];
40 static size_t max_value;
41};
42
43size_t SmallSizes::sizes[] = {
44 0, 1, 1024, 3333,
45 Constants::BLOCK_SIZE - 3333,
46 Constants::BLOCK_SIZE,
47 Constants::BLOCK_SIZE + 3333,
48 2 * Constants::BLOCK_SIZE - 3333,
49 2 * Constants::BLOCK_SIZE,
50 2 * Constants::BLOCK_SIZE + 3333,
51};
52
53size_t SmallSizes::max_value = Constants::BLOCK_SIZE * 3;
54
55} // namespace regtest
diff --git a/xdelta3/testing/test.h b/xdelta3/testing/test.h
index 74767fd..4d2dc8a 100644
--- a/xdelta3/testing/test.h
+++ b/xdelta3/testing/test.h
@@ -59,3 +59,7 @@ using regtest::Modify1stByte;
59 59
60#include "cmp.h" 60#include "cmp.h"
61using regtest::CmpDifferentBytes; 61using regtest::CmpDifferentBytes;
62
63#include "sizes.h"
64using regtest::SizeIterator;
65using regtest::SmallSizes;