summaryrefslogtreecommitdiff
path: root/xdelta3/testing/delta.h
diff options
context:
space:
mode:
authorjosh.macdonald <jmacd@users.noreply.github.com>2009-02-10 03:49:57 +0000
committerjosh.macdonald <jmacd@users.noreply.github.com>2009-02-10 03:49:57 +0000
commit1b96ad8ae09b53cdcd7dd03d4bac09ba8c61e5a6 (patch)
tree33aae63f229f1def8cd036dd4ec4fe3ec36a3055 /xdelta3/testing/delta.h
parent0b19bfedbd1f17004bdc6766a7ba5e61dddc20b0 (diff)
Templatize the test, expose issue 79.
Diffstat (limited to 'xdelta3/testing/delta.h')
-rw-r--r--xdelta3/testing/delta.h108
1 files changed, 50 insertions, 58 deletions
diff --git a/xdelta3/testing/delta.h b/xdelta3/testing/delta.h
index 58fbaac..b0cca7c 100644
--- a/xdelta3/testing/delta.h
+++ b/xdelta3/testing/delta.h
@@ -1,10 +1,40 @@
1// Mode: -*- C++ -*- 1// Mode: -*- C++ -*-
2 2
3namespace regtest {
4
5class Delta { 3class Delta {
6public: 4public:
7 Delta(const Block &block); 5 Delta(const Block &block) {
6 int ret;
7 xd3_config config;
8 memset(&stream_, 0, sizeof (stream_));
9 memset(&config, 0, sizeof (config));
10
11 xd3_init_config(&config, XD3_SKIP_EMIT | XD3_ADLER32_NOVER);
12
13 CHECK_EQ(0, xd3_config_stream (&stream_, &config));
14
15 xd3_avail_input (&stream_, block.Data(), block.Size());
16
17 bool done = false;
18 while (!done) {
19 ret = xd3_decode_input(&stream_);
20
21 switch (ret) {
22 case XD3_INPUT:
23 done = true;
24 break;
25 case XD3_OUTPUT:
26 CHECK_EQ(0, xd3_whole_append_window (&stream_));
27 break;
28 case XD3_GOTHEADER:
29 case XD3_WINSTART:
30 case XD3_WINFINISH:
31 break;
32 default:
33 DP(RINT "error code %s\n", xd3_strerror (ret));
34 abort();
35 }
36 }
37 }
8 38
9 ~Delta() { 39 ~Delta() {
10 xd3_free_stream(&stream_); 40 xd3_free_stream(&stream_);
@@ -18,62 +48,24 @@ public:
18 return stream_.whole_target.wininfolen; 48 return stream_.whole_target.wininfolen;
19 } 49 }
20 50
21 void Print() const; 51 void Print() const {
52 for (size_t i = 0; i < stream_.whole_target.instlen; i++) {
53 xd3_winst &winst = stream_.whole_target.inst[i];
54 switch (winst.type) {
55 case XD3_RUN:
56 DP(RINT "%"Q"u run %u\n", winst.position, winst.size);
57 break;
58 case XD3_ADD:
59 DP(RINT "%"Q"u add %u\n", winst.position, winst.size);
60 break;
61 default:
62 DP(RINT "%"Q"u copy %u @ %"Q"u (mode %u)\n",
63 winst.position, winst.size, winst.addr, winst.mode);
64 break;
65 }
66 }
67 }
22 68
23private: 69private:
24 xd3_stream stream_; 70 xd3_stream stream_;
25}; 71};
26
27Delta::Delta(const Block &block) {
28 int ret;
29 xd3_config config;
30 memset(&stream_, 0, sizeof (stream_));
31 memset(&config, 0, sizeof (config));
32
33 xd3_init_config(&config, XD3_SKIP_EMIT | XD3_ADLER32_NOVER);
34
35 CHECK_EQ(0, xd3_config_stream (&stream_, &config));
36
37 xd3_avail_input (&stream_, block.Data(), block.Size());
38
39 bool done = false;
40 while (!done) {
41 ret = xd3_decode_input(&stream_);
42
43 switch (ret) {
44 case XD3_INPUT:
45 done = true;
46 break;
47 case XD3_OUTPUT:
48 CHECK_EQ(0, xd3_whole_append_window (&stream_));
49 break;
50 case XD3_GOTHEADER:
51 case XD3_WINSTART:
52 case XD3_WINFINISH:
53 break;
54 default:
55 DP(RINT "error code %s\n", xd3_strerror (ret));
56 abort();
57 }
58 }
59}
60
61void Delta::Print() const {
62 for (size_t i = 0; i < stream_.whole_target.instlen; i++) {
63 xd3_winst &winst = stream_.whole_target.inst[i];
64 switch (winst.type) {
65 case XD3_RUN:
66 DP(RINT "%"Q"u run %u\n", winst.position, winst.size);
67 break;
68 case XD3_ADD:
69 DP(RINT "%"Q"u add %u\n", winst.position, winst.size);
70 break;
71 default:
72 DP(RINT "%"Q"u copy %u @ %"Q"u (mode %u)\n",
73 winst.position, winst.size, winst.addr, winst.mode);
74 break;
75 }
76 }
77}
78
79} // namespace