Example #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");
        }
Example #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));
        }
Example #3
0
        public void DeltaOfUnchangedFileShouldResultInJustCopySegment(string name, int numberOfFiles)
        {
            PackageGenerator.GeneratePackage(name, numberOfFiles);

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

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

            Run("explain-delta " + name + ".delta");
            Assert.That(Regex.IsMatch(Output, "^Copy: 0 to ([0-9A-F]+)\r\n$"));
            Assert.That(Output, Does.Not.Contain("Data:"));
        }
Example #4
0
        public void ShouldCreateDifferentSignaturesBasedOnChunkSize(string name, int numberOfFiles)
        {
            PackageGenerator.GeneratePackage(name, numberOfFiles);

            Run("signature " + name + " " + name + ".sig.1 --chunk-size=128");
            Run("signature " + name + " " + name + ".sig.2 --chunk-size=256");
            Run("signature " + name + " " + name + ".sig.3 --chunk-size=1024");
            Run("signature " + name + " " + name + ".sig.4 --chunk-size=2048");
            Run("signature " + name + " " + name + ".sig.5 --chunk-size=31744");

            Assert.That(Length(name + ".sig.1") > Length(name + ".sig.2"));
            Assert.That(Length(name + ".sig.2") > Length(name + ".sig.3"));
            Assert.That(Length(name + ".sig.3") > Length(name + ".sig.4"));
            Assert.That(Length(name + ".sig.4") > Length(name + ".sig.5"));
        }
Example #5
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)));
        }
Example #6
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)));
        }
Example #7
0
        public void ShouldCreateSignature(string name, int numberOfFiles)
        {
            PackageGenerator.GeneratePackage(name, numberOfFiles);

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

            var basisSize     = new FileInfo(name).Length;
            var signatureSize = new FileInfo(name + ".sig").Length;
            var signatureSizePercentageOfBasis = signatureSize / (double)basisSize;

            Trace.WriteLine(string.Format("Basis size: {0:n0}", basisSize));
            Trace.WriteLine(string.Format("Signature size: {0:n0}", signatureSize));
            Trace.WriteLine(string.Format("Signature ratio: {0:n3}", signatureSizePercentageOfBasis));
            Assert.IsTrue(0.012 <= signatureSizePercentageOfBasis && signatureSizePercentageOfBasis <= 0.014);
        }
Example #8
0
        public void ShouldCreateSignature(string name, int numberOfFiles, OctodiffAppVariant octodiff)
        {
            PackageGenerator.GeneratePackage(name, numberOfFiles);

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

            var basisSize     = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, name)).Length;
            var signatureSize = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, name) + ".sig").Length;
            var signatureSizePercentageOfBasis = signatureSize / (double)basisSize;

            Trace.WriteLine(string.Format("Basis size: {0:n0}", basisSize));
            Trace.WriteLine(string.Format("Signature size: {0:n0}", signatureSize));
            Trace.WriteLine(string.Format("Signature ratio: {0:n3}", signatureSizePercentageOfBasis));
            Assert.IsTrue(0.006 <= signatureSizePercentageOfBasis && signatureSizePercentageOfBasis <= 0.014);
        }
Example #9
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)));
        }
Example #10
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"));
        }
Example #11
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"));
        }
Example #12
0
        public void ShouldCreateDifferentSignaturesBasedOnChunkSize(string name, int numberOfFiles, OctodiffAppVariant octodiff)
        {
            PackageGenerator.GeneratePackage(name, numberOfFiles);

            Run("signature " + name + " " + name + ".sig.1 --chunk-size=128", octodiff);
            Run("signature " + name + " " + name + ".sig.2 --chunk-size=256", octodiff);
            Run("signature " + name + " " + name + ".sig.3 --chunk-size=1024", octodiff);
            Run("signature " + name + " " + name + ".sig.4 --chunk-size=2048", octodiff);
            Run("signature " + name + " " + name + ".sig.5 --chunk-size=31744", octodiff);

            Assert.That(Length(Path.Combine(TestContext.CurrentContext.TestDirectory, name) + ".sig.1")
                        > Length(Path.Combine(TestContext.CurrentContext.TestDirectory, name) + ".sig.2"));
            Assert.That(Length(Path.Combine(TestContext.CurrentContext.TestDirectory, name) + ".sig.2")
                        > Length(Path.Combine(TestContext.CurrentContext.TestDirectory, name) + ".sig.3"));
            Assert.That(Length(Path.Combine(TestContext.CurrentContext.TestDirectory, name) + ".sig.3")
                        > Length(Path.Combine(TestContext.CurrentContext.TestDirectory, name) + ".sig.4"));
            Assert.That(Length(Path.Combine(TestContext.CurrentContext.TestDirectory, name) + ".sig.4")
                        > Length(Path.Combine(TestContext.CurrentContext.TestDirectory, name) + ".sig.5"));
        }