Пример #1
0
        public void DeltaOfChangedFileShouldResultInNewDataSegments(string name, int numberOfFiles)
        {
            PackageGenerator.GeneratePackage(name, numberOfFiles);

            Run("signature " + name + " " + name + ".sig");
            Assert.That(ExitCode, Is.EqualTo(0));

            var newName = Path.ChangeExtension(name, "2.zip");

            PackageGenerator.ModifyPackage(name, newName, (int)(0.33 * numberOfFiles), (int)(0.10 * numberOfFiles));

            Run("delta " + name + ".sig " + newName + " " + name + ".delta");
            Assert.That(ExitCode, Is.EqualTo(0));

            Run("explain-delta " + name + ".delta");
            Assert.That(Regex.IsMatch(Output, "Copy: ([0-9A-F]+) to ([0-9A-F]+)\r\n"));
            Assert.That(Regex.IsMatch(Output, "Data: \\(([0-9]+) bytes\\)"));

            var originalSize       = new FileInfo(name).Length;
            var newSize            = new FileInfo(newName).Length;
            var deltaSize          = new FileInfo(name + ".delta").Length;
            var actualDifference   = Math.Abs(newSize - originalSize);
            var deltaToActualRatio = (double)deltaSize / actualDifference;

            Trace.WriteLine(string.Format("Delta ratio: {0:n3}", deltaToActualRatio));
            Assert.IsTrue(deltaSize * 2 < newSize, "Delta should be at least half the new file size");
            Assert.IsTrue(0.80 <= deltaToActualRatio && deltaToActualRatio <= 1.60, "Delta should be pretty close to the actual file differences");
        }
Пример #2
0
        public void ExecuteWithTimings(string name, int numberOfFiles, OctodiffAppVariant octodiff)
        {
            var newName  = Path.ChangeExtension(name, "2.zip");
            var copyName = Path.ChangeExtension(name, "2_out.zip");

            Time("Package creation", () => PackageGenerator.GeneratePackage(name, numberOfFiles));
            Time("Package modification", () => PackageGenerator.ModifyPackage(name, newName, (int)(0.33 * numberOfFiles), (int)(0.10 * numberOfFiles)));
            Time("Signature creation", () => Run("signature " + name + " " + name + ".sig", octodiff));
            Time("Delta creation", () => Run("delta " + name + ".sig " + newName + " " + name + ".delta", octodiff));
            Time("Patch application", () => Run("patch " + name + " " + name + ".delta" + " " + copyName, octodiff));
            Time("Patch application (no verify)", () => Run("patch " + name + " " + name + ".delta" + " " + copyName + " --skip-verification", octodiff));
        }
Пример #3
0
        public void PatchingShouldResultInPerfectCopy(string name, int numberOfFiles)
        {
            var newName  = Path.ChangeExtension(name, "2.zip");
            var copyName = Path.ChangeExtension(name, "2_out.zip");

            PackageGenerator.GeneratePackage(name, numberOfFiles);
            PackageGenerator.ModifyPackage(name, newName, (int)(0.33 * numberOfFiles), (int)(0.10 * numberOfFiles));

            Run("signature " + name + " " + name + ".sig");
            Run("delta " + name + ".sig " + newName + " " + name + ".delta");
            Run("patch " + name + " " + name + ".delta" + " " + copyName);
            Assert.That(ExitCode, Is.EqualTo(0));

            Assert.That(Sha1(newName), Is.EqualTo(Sha1(copyName)));
        }
Пример #4
0
        public void PatchingShouldResultInPerfectCopy(string name, int numberOfFiles, OctodiffAppVariant octodiff)
        {
            var newName  = Path.ChangeExtension(Path.Combine(TestContext.CurrentContext.TestDirectory, name), "2.zip");
            var copyName = Path.ChangeExtension(Path.Combine(TestContext.CurrentContext.TestDirectory, name), "2_out.zip");

            PackageGenerator.GeneratePackage(name, numberOfFiles);
            PackageGenerator.ModifyPackage(name, newName, (int)(0.33 * numberOfFiles), (int)(0.10 * numberOfFiles));

            Run("signature " + name + " " + name + ".sig", octodiff);
            Run("delta " + name + ".sig " + newName + " " + name + ".delta", octodiff);
            Run("patch " + name + " " + name + ".delta" + " " + copyName, octodiff);
            Assert.That(ExitCode, Is.EqualTo(0));

            Assert.That(Sha1(newName), Is.EqualTo(Sha1(copyName)));
        }
Пример #5
0
        public void PatchVerificationCanBeSkipped(string name, int numberOfFiles)
        {
            var newBasis = Path.ChangeExtension(name, "1.zip");
            var newName  = Path.ChangeExtension(name, "2.zip");
            var copyName = Path.ChangeExtension(name, "2_out.zip");

            PackageGenerator.GeneratePackage(name, numberOfFiles);
            PackageGenerator.ModifyPackage(name, newBasis, (int)(0.33 * numberOfFiles), (int)(0.10 * numberOfFiles));
            PackageGenerator.ModifyPackage(name, newName, (int)(0.33 * numberOfFiles), (int)(0.10 * numberOfFiles));

            Run("signature " + name + " " + name + ".sig");
            Run("delta " + name + ".sig " + newName + " " + name + ".delta");
            Run("patch " + newBasis + " " + name + ".delta" + " " + copyName + " --skip-verification");
            Assert.That(ExitCode, Is.EqualTo(0));
            Assert.That(Sha1(newName), Is.Not.EqualTo(Sha1(copyName)));
        }
Пример #6
0
        public void PatchVerificationShouldFailWhenFilesModified(string name, int numberOfFiles)
        {
            var newBasis = Path.ChangeExtension(name, "1.zip");
            var newName  = Path.ChangeExtension(name, "2.zip");
            var copyName = Path.ChangeExtension(name, "2_out.zip");

            PackageGenerator.GeneratePackage(name, numberOfFiles);
            PackageGenerator.ModifyPackage(name, newBasis, (int)(0.33 * numberOfFiles), (int)(0.10 * numberOfFiles));
            PackageGenerator.ModifyPackage(name, newName, (int)(0.33 * numberOfFiles), (int)(0.10 * numberOfFiles));

            Run("signature " + name + " " + name + ".sig");
            Run("delta " + name + ".sig " + newName + " " + name + ".delta");
            Run("patch " + newBasis + " " + name + ".delta" + " " + copyName);
            Assert.That(ExitCode, Is.EqualTo(4));
            Assert.That(Output, Is.StringContaining("Error: Verification of the patched file failed"));
        }
Пример #7
0
        public void PatchVerificationShouldFailWhenFilesModified(string name, int numberOfFiles, OctodiffAppVariant octodiff)
        {
            var newBasis = Path.ChangeExtension(Path.Combine(TestContext.CurrentContext.TestDirectory, name), "1.zip");
            var newName  = Path.ChangeExtension(Path.Combine(TestContext.CurrentContext.TestDirectory, name), "2.zip");
            var copyName = Path.ChangeExtension(Path.Combine(TestContext.CurrentContext.TestDirectory, name), "2_out.zip");

            PackageGenerator.GeneratePackage(name, numberOfFiles);
            PackageGenerator.ModifyPackage(name, newBasis, numberOfFiles, (int)(0.5 * numberOfFiles));
            PackageGenerator.ModifyPackage(name, newName, (int)(0.33 * numberOfFiles), (int)(0.10 * numberOfFiles));

            Run("signature " + name + " " + name + ".sig", octodiff);
            Run("delta " + name + ".sig " + newName + " " + name + ".delta", octodiff);
            Run("patch " + newBasis + " " + name + ".delta" + " " + copyName, octodiff);
            Assert.That(ExitCode, Is.EqualTo(2));
            Assert.That(Output, Does.Contain("Error: Verification of the patched file failed"));
        }