summaryrefslogtreecommitdiff
path: root/xdelta3/testing
diff options
context:
space:
mode:
Diffstat (limited to 'xdelta3/testing')
-rw-r--r--xdelta3/testing/file.h4
-rw-r--r--xdelta3/testing/regtest.cc155
2 files changed, 74 insertions, 85 deletions
diff --git a/xdelta3/testing/file.h b/xdelta3/testing/file.h
index 4153e5f..9511d1c 100644
--- a/xdelta3/testing/file.h
+++ b/xdelta3/testing/file.h
@@ -215,6 +215,10 @@ inline void BlockIterator::Get(Block *block) const {
215 block->SetSize(BytesOnBlock()); 215 block->SetSize(BytesOnBlock());
216 216
217 SegmentMap::const_iterator pos = table.upper_bound(offset); 217 SegmentMap::const_iterator pos = table.upper_bound(offset);
218 if (pos == table.begin()) {
219 CHECK_EQ(0, spec_.Size());
220 return;
221 }
218 --pos; 222 --pos;
219 223
220 while (got < block->size_) { 224 while (got < block->size_) {
diff --git a/xdelta3/testing/regtest.cc b/xdelta3/testing/regtest.cc
index d615196..307d9e2 100644
--- a/xdelta3/testing/regtest.cc
+++ b/xdelta3/testing/regtest.cc
@@ -561,6 +561,7 @@ void TestNonBlockingProgress() {
561 TestOptions options; 561 TestOptions options;
562 562
563 // TODO! this test assumes block_size == 128 563 // TODO! this test assumes block_size == 128
564 CHECK_EQ(128, Constants::BLOCK_SIZE);
564 565
565 spec0.GenerateFixedSize(Constants::BLOCK_SIZE * 2); 566 spec0.GenerateFixedSize(Constants::BLOCK_SIZE * 2);
566 567
@@ -598,97 +599,81 @@ void TestNonBlockingProgress() {
598 InMemoryEncodeDecode(options, spec1, spec2, NULL); 599 InMemoryEncodeDecode(options, spec1, spec2, NULL);
599} 600}
600 601
601} // anonymous namespace 602void TestMergeCommand() {
603 /* 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). */
605 MTRandom rand;
606 FileSpec spec0(&rand);
607 FileSpec spec1(&rand);
608 FileSpec spec2(&rand);
609 FileSpec spec3(&rand);
602 610
603int main(int argc, char **argv) { 611 TestOptions options;
604#define TEST(x) cerr << #x << "..." << endl; x()
605 TEST(TestRandomNumbers);
606 TEST(TestRandomFile);
607 TEST(TestFirstByte);
608 TEST(TestModifyMutator);
609 TEST(TestAddMutator);
610 TEST(TestDeleteMutator);
611 TEST(TestCopyMutator);
612 TEST(TestMoveMutator);
613 TEST(TestOverwriteMutator);
614 TEST(TestNonBlockingProgress);
615 return 0;
616}
617 612
618#if 0 613 SizeIterator<size_t, SmallSizes> si0(&rand, 10);
619static const random_parameters test_parameters[] = {
620 { 16384, 4096, 16, 0 },
621 { 16384, 4096, 0, 16 },
622 { 16384, 4096, 16, 16 },
623 { 16384, 4096, 128, 128 },
624};
625 614
626int 615 for (; !si0.Done(); si0.Next()) {
627test_merge_chain (random_file_spec *specs, int number) 616 size_t size0 = si0.Get();
628{
629 /* "number" is from 1 (a single delta) between specs[0] and
630 * specs[1], to N, an (N-1) chain from specs[0] to specs[N]. */
631 return 0;
632}
633 617
634static int 618 SizeIterator<size_t, SmallSizes> si1(&rand, 10);
635test_merge_command () 619 for (; !si1.Done(); si1.Next()) {
636{ 620 size_t change1 = si1.Get();
637 /* Repeat random-input testing for a number of iterations. 621
638 * Test 2, 3, and 4-file scenarios (i.e., 1, 2, and 3-delta merges). */ 622 if (change1 == 0) {
639 int ret; 623 continue;
640 int iter = 0, param = 0; 624 }
641 random_file_spec spec[4]; 625
642 626 DP(RINT "S0 = %lu\n", size0);
643 memset (spec, 0, sizeof (spec)); 627 DP(RINT "C1 = %lu\n", change1);
644 628
645 /* Repeat this loop for TESTS_PER_PARAMETER * #parameters * 2. The 629 size_t add1_pos = size0 ? rand.Rand32() % size0 : 0;
646 * first #parameters repeats are for the provided values, the second 630 size_t del2_pos = size0 ? rand.Rand32() % size0 : 0;
647 * set of repeats use random parameters. */ 631
648 for (; param < (2 * SIZEOF_ARRAY(test_parameters)); iter++) 632 spec0.GenerateFixedSize(size0);
649 { 633
650 if (iter % TESTS_PER_PARAMETER == 0) 634 ChangeList cl1, cl2, cl3;
651 { 635
652 if (param < SIZEOF_ARRAY(test_parameters)) 636 size_t change3 = change1;
653 { 637 size_t change3_pos;
654 set_test_parameters (&test_parameters[param]); 638
655 } 639 if (change3 >= size0) {
656 else 640 change3 = size0;
657 { 641 change3_pos = 0;
658 set_random_parameters (); 642 } else {
659 } 643 change3_pos = rand.Rand32() % (size0 - change3);
660 644 }
661 param++;
662
663 if ((ret = random_file_spec_generate (&spec[0]))) { return ret; }
664 if ((ret = random_file_spec_write (&spec[0]))) { return ret; }
665
666 if ((ret = random_file_spec_mutate (&spec[0], &spec[1]))) { return ret; }
667 if ((ret = random_file_spec_write (&spec[1]))) { return ret; }
668 if ((ret = random_file_spec_delta (&spec[0], &spec[1]))) { return ret; }
669
670 if ((ret = random_file_spec_mutate (&spec[1], &spec[2]))) { return ret; }
671 if ((ret = random_file_spec_write (&spec[2]))) { return ret; }
672 if ((ret = random_file_spec_delta (&spec[1], &spec[2]))) { return ret; }
673 }
674 645
675 /* Each iteration creates a new mutation. */ 646 cl1.push_back(Change(Change::ADD, change1, add1_pos));
676 if ((ret = random_file_spec_mutate (&spec[2], &spec[3]))) { return ret; } 647 cl2.push_back(Change(Change::DELETE, change1, del2_pos));
677 if ((ret = random_file_spec_write (&spec[3]))) { return ret; } 648 cl3.push_back(Change(Change::MODIFY, change3, change3_pos));
678 if ((ret = random_file_spec_delta (&spec[2], &spec[3]))) { return ret; } 649
679 650 spec0.ModifyTo(ChangeListMutator(cl1), &spec1);
680 /* Test 1, 2, and 3 */ 651 spec1.ModifyTo(ChangeListMutator(cl2), &spec2);
681 if ((ret = test_merge_chain (spec, 1))) { return ret; } 652 spec2.ModifyTo(ChangeListMutator(cl3), &spec3);
682 if ((ret = test_merge_chain (spec, 2))) { return ret; } 653
683 if ((ret = test_merge_chain (spec, 3))) { return ret; } 654 Block delta01, delta12, delta23;
684 655
685 /* Clear 1st input, shift inputs */ 656 InMemoryEncodeDecode(options, spec0, spec1, &delta01);
686 random_file_spec_clear (&spec[0]); 657 InMemoryEncodeDecode(options, spec1, spec2, &delta12);
687 random_file_spec_swap (&spec[0], &spec[1]); 658 InMemoryEncodeDecode(options, spec2, spec3, &delta23);
688 random_file_spec_swap (&spec[1], &spec[2]);
689 random_file_spec_swap (&spec[2], &spec[3]);
690 } 659 }
660 }
661}
691 662
663} // anonymous namespace
664
665int main(int argc, char **argv) {
666#define TEST(x) cerr << #x << "..." << endl; x()
667// TEST(TestRandomNumbers);
668// TEST(TestRandomFile);
669// TEST(TestFirstByte);
670// TEST(TestModifyMutator);
671// TEST(TestAddMutator);
672// TEST(TestDeleteMutator);
673// TEST(TestCopyMutator);
674// TEST(TestMoveMutator);
675// TEST(TestOverwriteMutator);
676// TEST(TestNonBlockingProgress);
677 TEST(TestMergeCommand);
692 return 0; 678 return 0;
693} 679}
694#endif