Browse Source

Use PngChunkType enum in TestData

af/merge-core
Jason Nelson 8 years ago
parent
commit
b460b14006
  1. 30
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

30
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

@ -11,6 +11,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests namespace SixLabors.ImageSharp.Tests
{ {
using System.Buffers.Binary;
using System.Linq; using System.Linq;
using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.Formats.Png;
@ -242,12 +243,14 @@ namespace SixLabors.ImageSharp.Tests
} }
[Theory] [Theory]
[InlineData("IHDR")] // Header [InlineData((uint)PngChunkType.Header)] // IHDR
[InlineData("PLTE")] // Palette [InlineData((uint)PngChunkType.Palette)] // PLTE
// [InlineData(PngChunkTypes.Data)] //TODO: Figure out how to test this // [InlineData(PngChunkTypes.Data)] //TODO: Figure out how to test this
[InlineData("IEND")] // End [InlineData((uint)PngChunkType.End)] // IEND
public void Decode_IncorrectCRCForCriticalChunk_ExceptionIsThrown(string chunkName) public void Decode_IncorrectCRCForCriticalChunk_ExceptionIsThrown(uint chunkType)
{ {
string chunkName = GetChunkTypeName(chunkType);
using (var memStream = new MemoryStream()) using (var memStream = new MemoryStream())
{ {
WriteHeaderChunk(memStream); WriteHeaderChunk(memStream);
@ -266,12 +269,14 @@ namespace SixLabors.ImageSharp.Tests
} }
[Theory] [Theory]
[InlineData("gAMA")] // Gamma [InlineData((uint)PngChunkType.Gamma)] // gAMA
[InlineData("tRNS")] // PaletteAlpha [InlineData((uint)PngChunkType.PaletteAlpha)] // tRNS
[InlineData("pHYs")] // Pysical: It's ok to test physical as we don't throw for duplicate chunks. [InlineData((uint)PngChunkType.Physical)] // pHYs: It's ok to test physical as we don't throw for duplicate chunks.
//[InlineData(PngChunkTypes.Text)] //TODO: Figure out how to test this //[InlineData(PngChunkTypes.Text)] //TODO: Figure out how to test this
public void Decode_IncorrectCRCForNonCriticalChunk_ExceptionIsThrown(string chunkName) public void Decode_IncorrectCRCForNonCriticalChunk_ExceptionIsThrown(uint chunkType)
{ {
string chunkName = GetChunkTypeName(chunkType);
using (var memStream = new MemoryStream()) using (var memStream = new MemoryStream())
{ {
WriteHeaderChunk(memStream); WriteHeaderChunk(memStream);
@ -283,6 +288,15 @@ namespace SixLabors.ImageSharp.Tests
} }
} }
private static string GetChunkTypeName(uint value)
{
byte[] data = new byte[4];
BinaryPrimitives.WriteUInt32BigEndian(data, value);
return Encoding.ASCII.GetString(data);
}
private static void WriteHeaderChunk(MemoryStream memStream) private static void WriteHeaderChunk(MemoryStream memStream)
{ {
// Writes a 1x1 32bit png header chunk containing a single black pixel // Writes a 1x1 32bit png header chunk containing a single black pixel

Loading…
Cancel
Save