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.
89 lines
2.8 KiB
89 lines
2.8 KiB
// <copyright file="IccDataReader.PrimitivesTests.cs" company="James Jackson-South">
|
|
// Copyright (c) James Jackson-South and contributors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
// </copyright>
|
|
|
|
namespace ImageSharp.Tests.Icc
|
|
{
|
|
using System;
|
|
using Xunit;
|
|
|
|
public class IccDataReaderPrimitivesTests
|
|
{
|
|
[Theory]
|
|
[MemberData(nameof(IccTestDataPrimitives.AsciiTestData), MemberType = typeof(IccTestDataPrimitives))]
|
|
public void ReadAsciiString(byte[] textBytes, int length, string expected)
|
|
{
|
|
IccDataReader reader = CreateReader(textBytes);
|
|
|
|
string output = reader.ReadAsciiString(length);
|
|
|
|
Assert.Equal(expected, output);
|
|
}
|
|
|
|
[Fact]
|
|
public void ReadAsciiStringWithNegativeLenghtThrowsArgumentException()
|
|
{
|
|
IccDataReader reader = CreateReader(new byte[4]);
|
|
|
|
Assert.Throws<ArgumentOutOfRangeException>(() => reader.ReadAsciiString(-1));
|
|
}
|
|
|
|
[Fact]
|
|
public void ReadUnicodeStringWithNegativeLenghtThrowsArgumentException()
|
|
{
|
|
IccDataReader reader = CreateReader(new byte[4]);
|
|
|
|
Assert.Throws<ArgumentOutOfRangeException>(() => reader.ReadUnicodeString(-1));
|
|
}
|
|
|
|
[Theory]
|
|
[MemberData(nameof(IccTestDataPrimitives.Fix16TestData), MemberType = typeof(IccTestDataPrimitives))]
|
|
public void ReadFix16(byte[] data, float expected)
|
|
{
|
|
IccDataReader reader = CreateReader(data);
|
|
|
|
float output = reader.ReadFix16();
|
|
|
|
Assert.Equal(expected, output);
|
|
}
|
|
|
|
[Theory]
|
|
[MemberData(nameof(IccTestDataPrimitives.UFix16TestData), MemberType = typeof(IccTestDataPrimitives))]
|
|
public void ReadUFix16(byte[] data, float expected)
|
|
{
|
|
IccDataReader reader = CreateReader(data);
|
|
|
|
float output = reader.ReadUFix16();
|
|
|
|
Assert.Equal(expected, output);
|
|
}
|
|
|
|
[Theory]
|
|
[MemberData(nameof(IccTestDataPrimitives.U1Fix15TestData), MemberType = typeof(IccTestDataPrimitives))]
|
|
public void ReadU1Fix15(byte[] data, float expected)
|
|
{
|
|
IccDataReader reader = CreateReader(data);
|
|
|
|
float output = reader.ReadU1Fix15();
|
|
|
|
Assert.Equal(expected, output);
|
|
}
|
|
|
|
[Theory]
|
|
[MemberData(nameof(IccTestDataPrimitives.UFix8TestData), MemberType = typeof(IccTestDataPrimitives))]
|
|
public void ReadUFix8(byte[] data, float expected)
|
|
{
|
|
IccDataReader reader = CreateReader(data);
|
|
|
|
float output = reader.ReadUFix8();
|
|
|
|
Assert.Equal(expected, output);
|
|
}
|
|
|
|
private IccDataReader CreateReader(byte[] data)
|
|
{
|
|
return new IccDataReader(data);
|
|
}
|
|
}
|
|
}
|
|
|