📷 A modern, cross-platform, 2D Graphics library for .NET
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.
 
 

88 lines
2.7 KiB

// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.MetaData.Profiles.Icc;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Icc
{
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);
}
}
}