summaryrefslogtreecommitdiff
path: root/xdelta3/testing/regtest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'xdelta3/testing/regtest.cc')
-rw-r--r--xdelta3/testing/regtest.cc48
1 files changed, 41 insertions, 7 deletions
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,
33void InMemoryEncodeDecode(const TestOptions &options, 33void 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
606void 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
602void TestMergeCommand() { 639void 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}