mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.2 KiB
51 lines
1.2 KiB
// Copyright (c) Six Labors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
using System;
|
|
using SixLabors.ImageSharp.Compression.Zlib;
|
|
using Xunit;
|
|
using SharpCrc32 = ICSharpCode.SharpZipLib.Checksum.Crc32;
|
|
|
|
namespace SixLabors.ImageSharp.Tests.Formats.Png
|
|
{
|
|
[Trait("Format", "Png")]
|
|
public class Crc32Tests
|
|
{
|
|
[Theory]
|
|
[InlineData(0)]
|
|
[InlineData(1)]
|
|
[InlineData(2)]
|
|
public void ReturnsCorrectWhenEmpty(uint input)
|
|
{
|
|
Assert.Equal(input, Crc32.Calculate(input, default));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(0)]
|
|
[InlineData(8)]
|
|
[InlineData(215)]
|
|
[InlineData(1024)]
|
|
[InlineData(1024 + 15)]
|
|
[InlineData(2034)]
|
|
[InlineData(4096)]
|
|
public void MatchesReference(int length)
|
|
{
|
|
var data = GetBuffer(length);
|
|
var crc = new SharpCrc32();
|
|
crc.Update(data);
|
|
|
|
long expected = crc.Value;
|
|
long actual = Crc32.Calculate(data);
|
|
|
|
Assert.Equal(expected, actual);
|
|
}
|
|
|
|
private static byte[] GetBuffer(int length)
|
|
{
|
|
var data = new byte[length];
|
|
new Random(1).NextBytes(data);
|
|
|
|
return data;
|
|
}
|
|
}
|
|
}
|
|
|