-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
8,199 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2012 | ||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Crc32.NET.Core", "Crc32.NET\Crc32.NET.Core.xproj", "{4889B52E-03E0-4632-9655-B209FBCD6EBA}" | ||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Crc32.NET", "Crc32.NET\Crc32.NET.xproj", "{4889B52E-03E0-4632-9655-B209FBCD6EBA}" | ||
EndProject | ||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Crc32.NET.Tests", "Crc32.NET.Tests\Crc32.NET.Tests.xproj", "{561519E1-4C48-4934-B56D-042835CD2D29}" | ||
EndProject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
|
||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>{561519E1-4C48-4934-B56D-042835CD2D29}</ProjectGuid> | ||
<RootNamespace>Crc32.NET.Tests</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath> | ||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
Crc32.NET.Tests/Crc32Implementations/Crc32C_Crc32CAlgorithm.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#if !NETCORE | ||
namespace Force.Crc32.Tests.Crc32Implementations | ||
{ | ||
public class Crc32C_Crc32CAlgorithm : CrcCalculator | ||
{ | ||
public Crc32C_Crc32CAlgorithm() : base("Crc32C.Crc32CAlgorithm") | ||
{ | ||
} | ||
|
||
public override uint Calculate(byte[] data) | ||
{ | ||
return Crc32C.Crc32CAlgorithm.Compute(data); | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Crc32.NET.Tests/Crc32Implementations/Force_Crc32_Crc32CAlgorithm.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Force.Crc32.Tests.Crc32Implementations | ||
{ | ||
public class Force_Crc32_Crc32CAlgorithm : CrcCalculator | ||
{ | ||
public Force_Crc32_Crc32CAlgorithm() : base("Force.Crc32.Crc32CAlgorithm") | ||
{ | ||
} | ||
|
||
public override uint Calculate(byte[] data) | ||
{ | ||
return Crc32CAlgorithm.Compute(data); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
using NUnit.Framework; | ||
|
||
#if !NETCORE | ||
using E = Crc32C.Crc32CAlgorithm; | ||
#endif | ||
|
||
namespace Force.Crc32.Tests | ||
{ | ||
[TestFixture] | ||
public class ImplementationCTest | ||
{ | ||
#if !NETCORE | ||
[TestCase("Hello", 3)] | ||
[TestCase("Nazdar", 0)] | ||
[TestCase("Ahoj", 1)] | ||
[TestCase("Very long text.Very long text.Very long text.Very long text.Very long text.Very long text.Very long text", 0)] | ||
[TestCase("Very long text.Very long text.Very long text.Very long text.Very long text.Very long text.Very long text", 3)] | ||
public void ResultConsistency(string text, int offset) | ||
{ | ||
var bytes = Encoding.ASCII.GetBytes(text); | ||
|
||
var crc1 = E.Compute(bytes.Skip(offset).ToArray()); | ||
var crc2 = Crc32CAlgorithm.Append(0, bytes, offset, bytes.Length - offset); | ||
Assert.That(crc2, Is.EqualTo(crc1)); | ||
} | ||
#endif | ||
|
||
[Test] | ||
public void ResultConsistency2() | ||
{ | ||
Assert.That(Crc32CAlgorithm.Compute(new byte[] { 1 }), Is.EqualTo(0xA016D052)); | ||
Assert.That(Crc32CAlgorithm.Compute(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }), Is.EqualTo(0xB219DB69)); | ||
} | ||
|
||
#if !NETCORE | ||
[Test] | ||
public void ResultConsistencyAsHashAlgorithm() | ||
{ | ||
var bytes = new byte[30000]; | ||
new Random().NextBytes(bytes); | ||
var e = new E(); | ||
// other implementation is little-endian | ||
var c = new Crc32CAlgorithm(false); | ||
var crc1 = BitConverter.ToInt32(e.ComputeHash(bytes), 0); | ||
var crc2 = BitConverter.ToInt32(c.ComputeHash(bytes), 0); | ||
Console.WriteLine(crc1.ToString("X8")); | ||
Console.WriteLine(crc2.ToString("X8")); | ||
Assert.That(crc1, Is.EqualTo(crc2)); | ||
} | ||
#endif | ||
|
||
[Test] | ||
public void PartIsWhole() | ||
{ | ||
var bytes = new byte[30000]; | ||
new Random().NextBytes(bytes); | ||
var r1 = Crc32CAlgorithm.Append(0, bytes, 0, 15000); | ||
var r2 = Crc32CAlgorithm.Append(r1, bytes, 15000, 15000); | ||
var r3 = Crc32CAlgorithm.Append(0, bytes, 0, 30000); | ||
Assert.That(r2, Is.EqualTo(r3)); | ||
} | ||
|
||
[Test] | ||
public void Result_Is_BigEndian() | ||
{ | ||
var bytes = new byte[30000]; | ||
new Random().NextBytes(bytes); | ||
var crc1 = Crc32CAlgorithm.Append(0, bytes, 0, bytes.Length); | ||
var crc2Bytes = new Crc32CAlgorithm().ComputeHash(bytes); | ||
if (BitConverter.IsLittleEndian) crc2Bytes = crc2Bytes.Reverse().ToArray(); | ||
var crc2 = BitConverter.ToUInt32(crc2Bytes, 0); | ||
Assert.That(crc2, Is.EqualTo(crc1)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"version": "1.0.0-*", | ||
"buildOptions": { | ||
"debugType": "portable" | ||
}, | ||
"dependencies": { | ||
"Crc32.NET": "1.1.0", | ||
"NUnit": "3.6.0" | ||
}, | ||
|
||
"testRunner": "nunit", | ||
|
||
"frameworks": { | ||
"netcoreapp1.0": { | ||
"imports": "portable-net45+win8", | ||
"buildOptions": { | ||
"define": ["NETCORE"] | ||
}, | ||
"dependencies": { | ||
"NETStandard.Library": "1.6.1", | ||
"dotnet-test-nunit": "3.4.0-beta-3", | ||
"Microsoft.NETCore.App": { | ||
"version": "1.1.0-*", | ||
"type": "platform" | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.