Files
plist-cil/plist-cil.test/UIDTests.cs

104 lines
2.9 KiB
C#
Raw Normal View History

2018-06-19 17:16:08 +02:00
using Claunia.PropertyList;
using System.IO;
using Xunit;
namespace plistcil.test
{
public class UIDTests
{
[Fact]
public void ByteUidTest()
{
2018-06-19 22:54:05 +02:00
var uid = new UID((byte)0xAB);
2018-06-19 17:16:08 +02:00
Assert.Equal(new byte[] { 0xAB }, uid.Bytes);
}
[Fact]
public void SByteUidTest()
{
2018-06-19 22:54:05 +02:00
var uid = new UID("test", unchecked((sbyte)0x0F));
Assert.Equal(new byte[] { 0x0F }, uid.Bytes);
2018-06-19 17:16:08 +02:00
}
[Fact]
public void ShortUidTest()
{
2018-06-19 22:54:05 +02:00
var uid = new UID("test", unchecked((short)0x0F0F));
Assert.Equal(new byte[] { 0x0F, 0x0F }, uid.Bytes);
2018-06-19 17:16:08 +02:00
}
[Fact]
public void UShortUidTest()
{
2018-06-19 22:54:05 +02:00
var uid = new UID(0xABCDu);
2018-06-19 17:16:08 +02:00
Assert.Equal(new byte[] { 0xAB, 0xCD }, uid.Bytes);
}
[Fact]
public void UIntUidTest()
{
2018-06-19 22:54:05 +02:00
var uid = new UID(0xABCDEF00u);
2018-06-19 17:16:08 +02:00
Assert.Equal(new byte[] { 0xAB, 0xCD, 0xEF, 0x00 }, uid.Bytes);
}
[Fact]
public void IntUidTest()
{
2018-06-19 22:54:05 +02:00
var uid = new UID(0xABCDEF00);
2018-06-19 17:16:08 +02:00
Assert.Equal(new byte[] { 0xAB, 0xCD, 0xEF, 0x00 }, uid.Bytes);
}
[Fact]
public void ULongUidTest()
{
2018-06-19 22:54:05 +02:00
var uid = new UID(0xABCDEF0000EFCDABu);
2018-06-19 17:16:08 +02:00
Assert.Equal(new byte[] { 0xAB, 0xCD, 0xEF, 0x00, 0x00, 0xEF, 0xCD, 0xAB }, uid.Bytes);
}
[Fact]
public void LongUidTest()
{
2018-06-19 22:54:05 +02:00
var uid = new UID(0xABCDEF0000EFCDAB);
2018-06-19 17:16:08 +02:00
Assert.Equal(new byte[] { 0xAB, 0xCD, 0xEF, 0x00, 0x00, 0xEF, 0xCD, 0xAB }, uid.Bytes);
}
[Theory]
[InlineData(new byte[] { 0xAB })]
[InlineData(new byte[] { 0xAB, 0xCD })]
[InlineData(new byte[] { 0xAB, 0xCD, 0xEF, 0xFE })]
[InlineData(new byte[] { 0xAB, 0xCD, 0xEF, 0xFE, 0xFE, 0xEF, 0xCD, 0xAB })]
public void UidFromArrayTest(byte[] array)
{
2018-06-19 22:54:05 +02:00
var uid = new UID(array);
2018-06-19 17:16:08 +02:00
Assert.Equal(array, uid.Bytes);
}
[Fact]
public void BinaryRoundTripTest()
{
2018-06-19 22:54:05 +02:00
var original = new UID(0xabcd);
2018-06-19 17:16:08 +02:00
using (MemoryStream stream = new MemoryStream())
{
BinaryPropertyListWriter.Write(stream, original);
stream.Position = 0;
var roundtrip = BinaryPropertyListParser.Parse(stream) as UID;
2018-06-19 17:23:57 +02:00
Assert.Equal(original.Bytes, roundtrip.Bytes);
2018-06-19 17:16:08 +02:00
}
}
[Fact]
public void XmlRoundTripTest()
{
2018-06-19 22:54:05 +02:00
var original = new UID(0xabcd);
2018-06-19 17:16:08 +02:00
var plist = original.ToXmlPropertyList();
// UIDs don't exist in XML property lists, but they are represented as strings
// for compability purposes
var roundtrip = XmlPropertyListParser.ParseString(plist) as NSString;
2018-06-19 22:54:05 +02:00
Assert.Equal("abcd", roundtrip.ToObject());
2018-06-19 17:16:08 +02:00
}
}
}