diff options
author | josh.macdonald <jmacd@users.noreply.github.com> | 2008-08-07 05:19:18 +0000 |
---|---|---|
committer | josh.macdonald <jmacd@users.noreply.github.com> | 2008-08-07 05:19:18 +0000 |
commit | ba2e003158b0fb9ad95b19d73c3e1c04eb9e1e0d (patch) | |
tree | 2e6582d50d18f44725eace7b89693127f45d6f70 | |
parent | ece1ef18cb2c0d3b8883e292707b3398b7b3d23c (diff) |
Add TmpFile class and begin testing merge command via xd3_main_cmdline().
-rw-r--r-- | xdelta3/Makefile | 5 | ||||
-rw-r--r-- | xdelta3/testing/file.h | 52 | ||||
-rw-r--r-- | xdelta3/testing/regtest.cc | 48 | ||||
-rw-r--r-- | xdelta3/testing/test.h | 4 |
4 files changed, 100 insertions, 9 deletions
diff --git a/xdelta3/Makefile b/xdelta3/Makefile index aa35a4a..2b61a46 100644 --- a/xdelta3/Makefile +++ b/xdelta3/Makefile | |||
@@ -55,7 +55,7 @@ WIXDIR = "/cygdrive/c/Program Files/wix2.0.4820" | |||
55 | CFLAGS= -Wall -Wshadow -fno-builtin | 55 | CFLAGS= -Wall -Wshadow -fno-builtin |
56 | 56 | ||
57 | # $Format: "REL=$Xdelta3Version$" $ | 57 | # $Format: "REL=$Xdelta3Version$" $ |
58 | REL=3.0t | 58 | REL=3.0u_pre0 |
59 | 59 | ||
60 | RELDIR = xdelta$(REL) | 60 | RELDIR = xdelta$(REL) |
61 | 61 | ||
@@ -67,6 +67,9 @@ EXTRA = Makefile COPYING linkxd3lib.c badcopy.c xdelta3.swig \ | |||
67 | examples/compare_test.c examples/speed_test.c \ | 67 | examples/compare_test.c examples/speed_test.c \ |
68 | examples/test.h examples/checksum_test.cc \ | 68 | examples/test.h examples/checksum_test.cc \ |
69 | xdelta3.py xdelta3_wrap.c xdelta3.wxs xdelta3.wxi \ | 69 | xdelta3.py xdelta3_wrap.c xdelta3.wxs xdelta3.wxi \ |
70 | testing/cmp.h testing/delta.h testing/file.h \ | ||
71 | testing/modify.h testing/random.h testing/segment.h \ | ||
72 | testing/sizes.h testing/test.h testing/Makefile \ | ||
70 | README readme.txt | 73 | README readme.txt |
71 | 74 | ||
72 | SWIG_FLAGS = -DXD3_DEBUG=1 \ | 75 | SWIG_FLAGS = -DXD3_DEBUG=1 \ |
diff --git a/xdelta3/testing/file.h b/xdelta3/testing/file.h index 9511d1c..1205bc0 100644 --- a/xdelta3/testing/file.h +++ b/xdelta3/testing/file.h | |||
@@ -3,6 +3,7 @@ namespace regtest { | |||
3 | 3 | ||
4 | class Block; | 4 | class Block; |
5 | class BlockIterator; | 5 | class BlockIterator; |
6 | class TmpFile; | ||
6 | 7 | ||
7 | class FileSpec { | 8 | class FileSpec { |
8 | public: | 9 | public: |
@@ -82,6 +83,8 @@ class FileSpec { | |||
82 | 83 | ||
83 | void PrintData() const; | 84 | void PrintData() const; |
84 | 85 | ||
86 | void WriteTmpFile(TmpFile *f) const; | ||
87 | |||
85 | typedef BlockIterator iterator; | 88 | typedef BlockIterator iterator; |
86 | 89 | ||
87 | private: | 90 | private: |
@@ -125,7 +128,9 @@ public: | |||
125 | size_ = 0; | 128 | size_ = 0; |
126 | } | 129 | } |
127 | 130 | ||
128 | void Block::Print() const; | 131 | void Print() const; |
132 | |||
133 | void WriteTmpFile(TmpFile *f) const; | ||
129 | 134 | ||
130 | private: | 135 | private: |
131 | void SetSize(size_t size) { | 136 | void SetSize(size_t size) { |
@@ -208,6 +213,39 @@ private: | |||
208 | size_t blksize_; | 213 | size_t blksize_; |
209 | }; | 214 | }; |
210 | 215 | ||
216 | class TmpFile { | ||
217 | public: | ||
218 | // TODO this is a little unportable! | ||
219 | TmpFile() { | ||
220 | static int static_counter = 0; | ||
221 | char buf[32]; | ||
222 | snprintf(buf, 32, "/tmp/regtest.%d", static_counter++); | ||
223 | filename_.append(buf); | ||
224 | main_file_init(&file_); | ||
225 | CHECK_EQ(0, main_file_open(&file_, filename_.c_str(), XO_WRITE)); | ||
226 | } | ||
227 | |||
228 | ~TmpFile() { | ||
229 | unlink(filename_.c_str()); | ||
230 | main_file_cleanup(&file_); | ||
231 | } | ||
232 | |||
233 | void Append(const Block *block) { | ||
234 | CHECK_EQ(0, main_file_write(&file_, | ||
235 | block->Data(), block->Size(), | ||
236 | "tmpfile write failed")); | ||
237 | } | ||
238 | |||
239 | const char* Name() const { | ||
240 | CHECK_EQ(0, main_file_close(&file_)); | ||
241 | return filename_.c_str(); | ||
242 | } | ||
243 | |||
244 | private: | ||
245 | string filename_; | ||
246 | mutable main_file file_; | ||
247 | }; | ||
248 | |||
211 | inline void BlockIterator::Get(Block *block) const { | 249 | inline void BlockIterator::Get(Block *block) const { |
212 | xoff_t offset = blkno_ * blksize_; | 250 | xoff_t offset = blkno_ * blksize_; |
213 | const SegmentMap &table = spec_.table_; | 251 | const SegmentMap &table = spec_.table_; |
@@ -287,5 +325,17 @@ inline void Block::Print() const { | |||
287 | DP(RINT "\n"); | 325 | DP(RINT "\n"); |
288 | } | 326 | } |
289 | 327 | ||
328 | inline void FileSpec::WriteTmpFile(TmpFile *f) const { | ||
329 | Block block; | ||
330 | for (BlockIterator iter(*this); !iter.Done(); iter.Next()) { | ||
331 | iter.Get(&block); | ||
332 | f->Append(&block); | ||
333 | } | ||
334 | } | ||
335 | |||
336 | inline void Block::WriteTmpFile(TmpFile *f) const { | ||
337 | f->Append(this); | ||
338 | } | ||
339 | |||
290 | } // namespace regtest | 340 | } // namespace regtest |
291 | 341 | ||
diff --git a/xdelta3/testing/regtest.cc b/xdelta3/testing/regtest.cc index 307d9e2..7da4110 100644 --- a/xdelta3/testing/regtest.cc +++ b/xdelta3/testing/regtest.cc | |||
@@ -31,8 +31,8 @@ struct TestOptions { | |||
31 | 31 | ||
32 | // TODO! the smatcher setup isn't working, | 32 | // TODO! the smatcher setup isn't working, |
33 | void InMemoryEncodeDecode(const TestOptions &options, | 33 | void InMemoryEncodeDecode(const TestOptions &options, |
34 | FileSpec &source_file, | 34 | const FileSpec &source_file, |
35 | FileSpec &target_file, | 35 | const FileSpec &target_file, |
36 | Block *coded_data) { | 36 | Block *coded_data) { |
37 | xd3_stream encode_stream; | 37 | xd3_stream encode_stream; |
38 | xd3_config encode_config; | 38 | xd3_config encode_config; |
@@ -42,6 +42,10 @@ void InMemoryEncodeDecode(const TestOptions &options, | |||
42 | xd3_config decode_config; | 42 | xd3_config decode_config; |
43 | xd3_source decode_source; | 43 | xd3_source decode_source; |
44 | 44 | ||
45 | if (coded_data) { | ||
46 | coded_data->Reset(); | ||
47 | } | ||
48 | |||
45 | memset(&encode_stream, 0, sizeof (encode_stream)); | 49 | memset(&encode_stream, 0, sizeof (encode_stream)); |
46 | memset(&encode_source, 0, sizeof (encode_source)); | 50 | memset(&encode_source, 0, sizeof (encode_source)); |
47 | 51 | ||
@@ -599,6 +603,39 @@ void TestNonBlockingProgress() { | |||
599 | InMemoryEncodeDecode(options, spec1, spec2, NULL); | 603 | InMemoryEncodeDecode(options, spec1, spec2, NULL); |
600 | } | 604 | } |
601 | 605 | ||
606 | void FourWayMergeTest(const TestOptions &options, | ||
607 | const FileSpec &spec0, | ||
608 | const FileSpec &spec1, | ||
609 | const FileSpec &spec2, | ||
610 | const FileSpec &spec3) { | ||
611 | Block delta01, delta12, delta23; | ||
612 | |||
613 | InMemoryEncodeDecode(options, spec0, spec1, &delta01); | ||
614 | InMemoryEncodeDecode(options, spec1, spec2, &delta12); | ||
615 | InMemoryEncodeDecode(options, spec2, spec3, &delta23); | ||
616 | |||
617 | TmpFile f0, d01, d12, d23; | ||
618 | |||
619 | spec0.WriteTmpFile(&f0); | ||
620 | delta01.WriteTmpFile(&d01); | ||
621 | delta12.WriteTmpFile(&d12); | ||
622 | delta23.WriteTmpFile(&d23); | ||
623 | |||
624 | // Merge 2 | ||
625 | TmpFile out; | ||
626 | const char* argv[] = { | ||
627 | "xdelta3", | ||
628 | "merge", | ||
629 | "-m", (char*)d01.Name(), | ||
630 | (char*)d12.Name(), | ||
631 | (char*)out.Name(), | ||
632 | NULL, | ||
633 | }; | ||
634 | |||
635 | CHECK_EQ(0, xd3_main_cmdline(SIZEOF_ARRAY(argv) - 1, (char**)argv)); | ||
636 | |||
637 | } | ||
638 | |||
602 | void TestMergeCommand() { | 639 | void TestMergeCommand() { |
603 | /* Repeat random-input testing for a number of iterations. | 640 | /* Repeat random-input testing for a number of iterations. |
604 | * Test 2, 3, and 4-file scenarios (i.e., 1, 2, and 3-delta merges). */ | 641 | * Test 2, 3, and 4-file scenarios (i.e., 1, 2, and 3-delta merges). */ |
@@ -651,11 +688,8 @@ void TestMergeCommand() { | |||
651 | spec1.ModifyTo(ChangeListMutator(cl2), &spec2); | 688 | spec1.ModifyTo(ChangeListMutator(cl2), &spec2); |
652 | spec2.ModifyTo(ChangeListMutator(cl3), &spec3); | 689 | spec2.ModifyTo(ChangeListMutator(cl3), &spec3); |
653 | 690 | ||
654 | Block delta01, delta12, delta23; | 691 | FourWayMergeTest(options, spec0, spec1, spec2, spec3); |
655 | 692 | FourWayMergeTest(options, spec3, spec2, spec1, spec0); | |
656 | InMemoryEncodeDecode(options, spec0, spec1, &delta01); | ||
657 | InMemoryEncodeDecode(options, spec1, spec2, &delta12); | ||
658 | InMemoryEncodeDecode(options, spec2, spec3, &delta23); | ||
659 | } | 693 | } |
660 | } | 694 | } |
661 | } | 695 | } |
diff --git a/xdelta3/testing/test.h b/xdelta3/testing/test.h index 968b8ca..32b62c0 100644 --- a/xdelta3/testing/test.h +++ b/xdelta3/testing/test.h | |||
@@ -28,6 +28,9 @@ do {if (!((x) OP (y))) { \ | |||
28 | abort(); \ | 28 | abort(); \ |
29 | } } while (false) | 29 | } } while (false) |
30 | 30 | ||
31 | #include <string> | ||
32 | using std::string; | ||
33 | |||
31 | #include <iostream> | 34 | #include <iostream> |
32 | using std::cerr; | 35 | using std::cerr; |
33 | using std::endl; | 36 | using std::endl; |
@@ -73,6 +76,7 @@ using regtest::Modify1stByte; | |||
73 | using regtest::FileSpec; | 76 | using regtest::FileSpec; |
74 | using regtest::Block; | 77 | using regtest::Block; |
75 | using regtest::BlockIterator; | 78 | using regtest::BlockIterator; |
79 | using regtest::TmpFile; | ||
76 | 80 | ||
77 | #include "cmp.h" | 81 | #include "cmp.h" |
78 | using regtest::CmpDifferentBytes; | 82 | using regtest::CmpDifferentBytes; |