Files
plist-cil/plist-cil.test/BinaryPropertyListParserTests.cs
Frederik Carlier 46d56b5cc2 Add unit tests
2018-06-19 17:16:08 +02:00

37 lines
1.5 KiB
C#

using Claunia.PropertyList;
using Xunit;
namespace plistcil.test
{
public class BinaryPropertyListParserTests
{
[Theory]
[InlineData(new byte[] { 0x08 }, 0x08)]
[InlineData(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07 }, 7)]
[InlineData(new byte[] { 0x00, 0x0e, 0x47, 0x7b }, 0x00000000000e477b)]
public void ParseUnsignedIntTest(byte[] binaryValue, int expectedValue)
{
Assert.Equal(expectedValue, BinaryPropertyListParser.ParseUnsignedInt(binaryValue));
}
[Theory]
[InlineData(new byte[] { 0x57 }, 0x57)]
[InlineData(new byte[] { 0x40, 0x2d, 0xf8, 0x4d }, 0x402df84d)]
[InlineData(new byte[] { 0x41, 0xb4, 0x83, 0x98, 0x2a, 0x00, 0x00, 0x00 }, 0x41b483982a000000)]
[InlineData(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x19 }, unchecked((long)0xfffffffffffffc19))]
public void ParseLongTest(byte[] binaryValue, long expectedValue)
{
Assert.Equal(expectedValue, BinaryPropertyListParser.ParseLong(binaryValue));
}
[Theory]
[InlineData(new byte[] { 0x41, 0xb4, 0x83, 0x98, 0x2a, 0x00, 0x00, 0x00 }, 344168490)]
[InlineData(new byte[] { 0x40, 0x09, 0x21, 0xf9, 0xf0, 0x1b, 0x86, 0x6e }, 3.14159)]
[InlineData(new byte[] { 0x40, 0x2d, 0xf8, 0x4d }, 2.71828007698059)]
public void ParseDoubleTest(byte[] binaryValue, double expectedValue)
{
Assert.Equal(expectedValue, BinaryPropertyListParser.ParseDouble(binaryValue), 14);
}
}
}