Skip to content
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
4 changes: 2 additions & 2 deletions Crc32.NET.Tests/BytePatternsTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !NETCORE
#if NETFRAMEWORK
using System;
using System.Linq;
using Force.Crc32.Tests.Crc32Implementations;
Expand Down Expand Up @@ -91,4 +91,4 @@ private void TestByteSequence(byte[] data)
}
}

#endif
#endif
36 changes: 12 additions & 24 deletions Crc32.NET.Tests/Crc32.NET.Tests.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp1.0;netcoreapp2.0;net461</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<DebugType>portable</DebugType>
<AssemblyName>Crc32.NET.Tests</AssemblyName>
<OutputType>Exe</OutputType>
Expand All @@ -13,34 +13,22 @@
<ProjectReference Include="..\Crc32.NET\Crc32.NET.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="K4os.Hash.Crc" Version="1.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170106-08" />
<PackageReference Include="CRC32C.Standard" Version="1.0.0" />
<PackageReference Include="NUnit" Version="3.10.1" />
<PackageReference Include="Crc32" Version="1.1.0" />
<PackageReference Include="K4os.Hash.Crc" Version="1.1.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0'">
<PackageReference Include="NETStandard.Library" Version="2.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net461'">
<PackageReference Include="CH.Crc32" Version="1.0" />
<PackageReference Include="Crc32" Version="1.0.0" />
<PackageReference Include="Crc32C.NET" Version="1.0.5.0" />
<PackageReference Include="Crc32" Version="1.1.0" />
<PackageReference Include="Crc32C.NET" Version="1.0.5" />
<PackageReference Include="Dexiom.QuickCrc32" Version="1.0.3" />
<PackageReference Include="Klinkby.Checksum" Version="1.0.2.1" />
<PackageReference Include="System.Data.HashFunction.Core" Version="1.8.2.2" />
<PackageReference Include="System.Data.HashFunction.CRC" Version="1.8.2.2" />
<PackageReference Include="System.Data.HashFunction.Interfaces" Version="1.0.0.2" />
<PackageReference Include="Klinkby.Checksum" Version="1.0.2" />
<PackageReference Include="System.Data.HashFunction.Core" Version="2.0.0" />
<PackageReference Include="System.Data.HashFunction.CRC" Version="2.0.0" />
<PackageReference Include="System.Data.HashFunction.Interfaces" Version="2.0.0" />
<PackageReference Include="CRC32C.Standard" Version="1.0.0" />
<!--PackageReference Include="NUnit" Version="3.6.0" /-->
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<DefineConstants>$(DefineConstants);NETCORE;;NETCORE13</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">
<DefineConstants>$(DefineConstants);NETCORE;NETCORE20</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<DefineConstants>$(DefineConstants);COREVERSION</DefineConstants>
</PropertyGroup>
</Project>
</Project>
4 changes: 2 additions & 2 deletions Crc32.NET.Tests/Crc32Implementations/CH_Crc32_Crc.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !NETCORE
#if NETFRAMEWORK

namespace Force.Crc32.Tests.Crc32Implementations
{
Expand All @@ -14,4 +14,4 @@ public override uint Calculate(byte[] data)
}
}
}
#endif
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !NETCORE
#if NETFRAMEWORK
namespace Force.Crc32.Tests.Crc32Implementations
{
public class Crc32C_Crc32CAlgorithm : CrcCalculator
Expand All @@ -13,4 +13,4 @@ public override uint Calculate(byte[] data)
}
}
}
#endif
#endif
4 changes: 1 addition & 3 deletions Crc32.NET.Tests/Crc32Implementations/Crc32C_Standard.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if NETCORE
namespace Force.Crc32.Tests.Crc32Implementations
namespace Force.Crc32.Tests.Crc32Implementations
{
public class Crc32C_Standard : CrcCalculator
{
Expand All @@ -15,4 +14,3 @@ public override uint Calculate(byte[] data)
}
}
}
#endif
4 changes: 1 addition & 3 deletions Crc32.NET.Tests/Crc32Implementations/Crc32_Crc32Algorithm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if !NETCORE
using Crc = Crc32.Crc32Algorithm;
using Crc = Crc32.Crc32Algorithm;

namespace Force.Crc32.Tests.Crc32Implementations
{
Expand All @@ -15,4 +14,3 @@ public override uint Calculate(byte[] data)
}
}
}
#endif
5 changes: 4 additions & 1 deletion Crc32.NET.Tests/Crc32Implementations/CrcCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
{
public abstract class CrcCalculator
{
protected CrcCalculator(string name)
protected CrcCalculator(string name, bool isSupported = true)
{
Name = name;
IsSupported = isSupported;
}

public string Name { get; private set; }

public bool IsSupported { get; private set; }

public abstract uint Calculate(byte[] data);
}
}
4 changes: 2 additions & 2 deletions Crc32.NET.Tests/Crc32Implementations/Dexiom_Quick_Crc32.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !NETCORE
#if NETFRAMEWORK
namespace Force.Crc32.Tests.Crc32Implementations
{
public class Dexiom_Quick_Crc32 : CrcCalculator
Expand All @@ -14,4 +14,4 @@ public override uint Calculate(byte[] data)
}
}
}
#endif
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Force.Crc32.Tests.Crc32Implementations
{
using Algorithm = Force.Crc32.Intrinsics.Crc32Algorithm;

public class Force_Intrinsics_Crc32_Crc32Algorithm : CrcCalculator
{
public Force_Intrinsics_Crc32_Crc32Algorithm()
: base("Force.Crc32.Intrinsics.Crc32Algorithm", Algorithm.IsSupported)
{
}

public override uint Calculate(byte[] data)
{
return Algorithm.Compute(data);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Force.Crc32.Tests.Crc32Implementations
{
using Algorithm = Force.Crc32.Intrinsics.Crc32CAlgorithm;

public class Force_Intrinsics_Crc32_Crc32CAlgorithm : CrcCalculator
{
public Force_Intrinsics_Crc32_Crc32CAlgorithm()
: base("Force.Crc32.Intrinsics.Crc32CAlgorithm", Algorithm.IsSupported)
{
}

public override uint Calculate(byte[] data)
{
return Algorithm.Compute(data);
}
}
}
4 changes: 1 addition & 3 deletions Crc32.NET.Tests/Crc32Implementations/K4os_Hash_Crc.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if COREVERSION
namespace Force.Crc32.Tests.Crc32Implementations
namespace Force.Crc32.Tests.Crc32Implementations
{
public class K4os_Hash_Crc : CrcCalculator
{
Expand All @@ -13,4 +12,3 @@ public override uint Calculate(byte[] data)
}
}
}
#endif
4 changes: 2 additions & 2 deletions Crc32.NET.Tests/Crc32Implementations/Klinkby_Checkum_Crc32.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !NETCORE
#if NETFRAMEWORK
namespace Force.Crc32.Tests.Crc32Implementations
{
public class Klinkby_Checkum_Crc32 : CrcCalculator
Expand All @@ -13,4 +13,4 @@ public override uint Calculate(byte[] data)
}
}
}
#endif
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !NETCORE
#if NETFRAMEWORK
using System;
using System.Data.HashFunction;

Expand All @@ -19,4 +19,4 @@ public override uint Calculate(byte[] data)
private readonly CRC _crc;
}
}
#endif
#endif
29 changes: 25 additions & 4 deletions Crc32.NET.Tests/ImplementationCTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

using NUnit.Framework;

#if !NETCORE
#if NETFRAMEWORK
using E = Crc32C.Crc32CAlgorithm;
#endif


namespace Force.Crc32.Tests
{
[TestFixture]
public class ImplementationCTest
{
#if !NETCORE
[TestCase("Hello", 3)]
[TestCase("Nazdar", 0)]
[TestCase("Ahoj", 1)]
Expand All @@ -23,11 +23,20 @@ public void ResultConsistency(string text, int offset)
{
var bytes = Encoding.ASCII.GetBytes(text);

#if NETFRAMEWORK
var crc1 = E.Compute(bytes.Skip(offset).ToArray());
var crc2 = Crc32CAlgorithm.Append(0, bytes, offset, bytes.Length - offset);
Assert.That(crc2, Is.EqualTo(crc1));
}
#elif NETCOREAPP3_0_OR_GREATER
if(Intrinsics.Crc32CAlgorithm.IsSupported)
{
var crc32C = new Ralph.Crc32C.Crc32C();
crc32C.Update(bytes, offset, bytes.Length - offset);
var crc3 = Intrinsics.Crc32CAlgorithm.Compute(bytes, offset, bytes.Length - offset);
Assert.That(crc3, Is.EqualTo(crc32C.GetIntValue()));
}
#endif
}

[Test]
public void ResultConsistency2()
Expand All @@ -36,7 +45,19 @@ public void ResultConsistency2()
Assert.That(Crc32CAlgorithm.Compute(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }), Is.EqualTo(0xB219DB69));
}

#if !NETCORE
#if NETCOREAPP3_0_OR_GREATER
[Test]
public void ResultConsistencyIntrinsics()
{
if(Intrinsics.Crc32CAlgorithm.IsSupported)
{
Assert.That(Intrinsics.Crc32CAlgorithm.Compute(new byte[] { 1 }), Is.EqualTo(0xA016D052));
Assert.That(Intrinsics.Crc32CAlgorithm.Compute(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }), Is.EqualTo(0xB219DB69));
}
}
#endif

#if NETFRAMEWORK
[Test]
public void ResultConsistencyAsHashAlgorithm()
{
Expand Down
29 changes: 25 additions & 4 deletions Crc32.NET.Tests/ImplementationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using NUnit.Framework;

#if !NETCORE
#if NETFRAMEWORK
using E = Crc32.Crc32Algorithm;
#endif

Expand All @@ -15,7 +15,6 @@ namespace Force.Crc32.Tests
public class ImplementationTest
{

#if !NETCORE
[TestCase("Hello", 3)]
[TestCase("Nazdar", 0)]
[TestCase("Ahoj", 1)]
Expand All @@ -25,11 +24,20 @@ public void ResultConsistency(string text, int offset)
{
var bytes = Encoding.ASCII.GetBytes(text);

#if NETFRAMEWORK
var crc1 = E.Compute(bytes.Skip(offset).ToArray());
var crc2 = Crc32Algorithm.Append(0, bytes, offset, bytes.Length - offset);
Assert.That(crc2, Is.EqualTo(crc1));
}
#endif
#if NET5_0_OR_GREATER
if(Intrinsics.Crc32Algorithm.IsSupported)
{
var crc1 = K4os.Hash.Crc.Crc32.DigestOf(bytes, offset, bytes.Length - offset);
var crc2 = Intrinsics.Crc32Algorithm.Compute(bytes, offset, bytes.Length - offset);
Assert.That(crc2, Is.EqualTo(crc1));
}
#endif
}

[Test]
public void ResultConsistency2()
Expand All @@ -38,7 +46,20 @@ public void ResultConsistency2()
Assert.That(Crc32Algorithm.Compute(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }), Is.EqualTo(622876539));
}

#if !NETCORE
#if NET5_0_OR_GREATER
[Test]
public void ResultConsistencyIntrinsics()
{
if(Intrinsics.Crc32Algorithm.IsSupported)
{
Assert.That(Intrinsics.Crc32Algorithm.Compute(new byte[] { 1 }), Is.EqualTo(2768625435));
Assert.That(Intrinsics.Crc32Algorithm.Compute(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }), Is.EqualTo(622876539));
}
}
#endif


#if NETFRAMEWORK
[Test]
public void ResultConsistencyAsHashAlgorithm()
{
Expand Down
Loading