Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rdiff.net.exe command line wrapper for librsync.net #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion librsync.net.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.22823.1
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "librsync.net", "librsync.net\librsync.net.csproj", "{0B6D94BD-5BFE-49AE-A83D-C504FB504C4C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "librsyncTest", "librsyncTest\librsyncTest.csproj", "{44941F98-A1D9-4A65-AC05-E482FF26E9E2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "rdiff.net", "rdiff.net.exe\rdiff.net.csproj", "{9C8E4671-9350-4955-8E52-1517EC7A0843}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "rdiff.netTest", "rDiff.NetTest\rdiff.netTest.csproj", "{ACB4F794-0C3B-421A-8218-9D3E71D76F2A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +25,14 @@ Global
{44941F98-A1D9-4A65-AC05-E482FF26E9E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{44941F98-A1D9-4A65-AC05-E482FF26E9E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{44941F98-A1D9-4A65-AC05-E482FF26E9E2}.Release|Any CPU.Build.0 = Release|Any CPU
{9C8E4671-9350-4955-8E52-1517EC7A0843}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9C8E4671-9350-4955-8E52-1517EC7A0843}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C8E4671-9350-4955-8E52-1517EC7A0843}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C8E4671-9350-4955-8E52-1517EC7A0843}.Release|Any CPU.Build.0 = Release|Any CPU
{ACB4F794-0C3B-421A-8218-9D3E71D76F2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ACB4F794-0C3B-421A-8218-9D3E71D76F2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ACB4F794-0C3B-421A-8218-9D3E71D76F2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ACB4F794-0C3B-421A-8218-9D3E71D76F2A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
36 changes: 36 additions & 0 deletions rDiff.NetTest/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("rDiff.NetTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("rDiff.NetTest")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("acb4f794-0c3b-421a-8218-9d3e71d76f2a")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
64 changes: 64 additions & 0 deletions rDiff.NetTest/RDiffDotNetTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Security.Cryptography;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using rdiff.net.exe;

namespace rDiff.NetTest
{
[TestClass]
public class rDiffDotNetTest
{
string originalFilePath = "./TestFiles/Original.txt";
string newFilePath = "./TestFiles/Modified.txt";
string patchedFilePath = "./TestFiles/Patched.txt";
string deltaPath = "./TestFiles/Original.txt.delta";
string signaturePath = "./TestFiles/Original.txt.signature";

[TestMethod]
public void E2ETest()
{
rDiffDotNet.ComputeSignature(originalFilePath, signaturePath);
rDiffDotNet.ComputeDelta(newFilePath, signaturePath, deltaPath);
rDiffDotNet.ApplyDelta(originalFilePath, deltaPath, patchedFilePath);
Assert.IsTrue(VerifyFilesAreIdentical(newFilePath, patchedFilePath));
}

[TestMethod]
public void DiffTest()
{
//makes sure that both methods of generating deltas (file+file and file+signature)
//create the same delta file.
rDiffDotNet.ComputeSignature(originalFilePath, signaturePath);
rDiffDotNet.ComputeDelta(newFilePath, signaturePath, deltaPath);

string deltaPath2 = deltaPath + "2";
rDiffDotNet.ComputeDeltaFromFiles(originalFilePath, newFilePath, deltaPath2);

Assert.IsTrue(VerifyFilesAreIdentical(deltaPath, deltaPath2));
}

[TestMethod]
public void DiffTestE2E()
{
rDiffDotNet.ComputeDeltaFromFiles(originalFilePath, newFilePath, deltaPath);
rDiffDotNet.ApplyDelta(originalFilePath, deltaPath, patchedFilePath);
Assert.IsTrue(VerifyFilesAreIdentical(newFilePath, patchedFilePath));
}

private static bool VerifyFilesAreIdentical(string newFilePath, string patchedFilePath)
{
MD5 md5 = MD5.Create();
using (var newFile = new FileStream(newFilePath, FileMode.Open))
{
using (var patchedFile = new FileStream(patchedFilePath, FileMode.Open))
{
byte[] originalHash = md5.ComputeHash(newFile);
byte[] patchedHash = md5.ComputeHash(patchedFile);
return originalHash.SequenceEqual(patchedHash);
}
}
}
}
}
Loading