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

132 lines
3.1 KiB
C#
Raw Normal View History

2018-07-09 19:57:08 +01:00
using System.IO;
using Claunia.PropertyList;
2018-06-19 17:16:08 +02:00
using Xunit;
namespace plistcil.test
{
public class UIDTests
{
[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
})]
2018-07-09 19:57:08 +01:00
public void UidFromArrayTest(byte[] array)
2018-06-19 17:16:08 +02:00
{
var uid = new UID(array);
2018-07-09 19:57:08 +01:00
Assert.Equal(array, uid.Bytes);
2018-06-19 17:16:08 +02:00
}
[Fact]
2018-07-09 19:57:08 +01:00
public void BinaryRoundTripTest()
2018-06-19 17:16:08 +02:00
{
var original = new UID(0xabcd);
2018-07-09 19:57:08 +01:00
using var stream = new MemoryStream();
BinaryPropertyListWriter.Write(stream, original);
stream.Position = 0;
var roundtrip = BinaryPropertyListParser.Parse(stream) as UID;
Assert.Equal(original.Bytes, roundtrip.Bytes);
2018-06-19 17:16:08 +02:00
}
[Fact]
2018-07-09 19:57:08 +01:00
public void ByteUidTest()
2018-06-19 17:16:08 +02:00
{
var uid = new UID(0xAB);
Assert.Equal(new byte[]
{
0xAB
}, uid.Bytes);
2019-06-12 14:51:29 +02:00
Assert.Equal(0xABu, uid.ToUInt64());
2018-06-19 17:16:08 +02:00
}
[Fact]
2018-07-09 19:57:08 +01:00
public void IntUidTest()
2018-06-19 17:16:08 +02:00
{
var uid = new UID(0xABCDEF00);
Assert.Equal(new byte[]
{
0xAB, 0xCD, 0xEF, 0x00
}, uid.Bytes);
2019-06-12 14:51:29 +02:00
Assert.Equal(0xABCDEF00, uid.ToUInt64());
2018-06-19 17:16:08 +02:00
}
[Fact]
2018-07-09 19:57:08 +01:00
public void LongUidTest()
2018-06-19 17:16:08 +02:00
{
var uid = new UID(0xABCDEF0000EFCDAB);
Assert.Equal(new byte[]
{
0xAB, 0xCD, 0xEF, 0x00, 0x00, 0xEF, 0xCD, 0xAB
}, uid.Bytes);
2019-06-12 14:51:29 +02:00
Assert.Equal(0xABCDEF0000EFCDAB, uid.ToUInt64());
2018-06-19 17:16:08 +02:00
}
[Fact]
2018-07-09 19:57:08 +01:00
public void UIntUidTest()
2018-06-19 17:16:08 +02:00
{
var uid = new UID(0xABCDEF00u);
Assert.Equal(new byte[]
{
0xAB, 0xCD, 0xEF, 0x00
}, uid.Bytes);
2019-06-12 14:51:29 +02:00
Assert.Equal(0xABCDEF00u, uid.ToUInt64());
2018-06-19 17:16:08 +02:00
}
2018-07-09 19:57:08 +01:00
[Fact]
public void ULongUidTest()
2018-06-19 17:16:08 +02:00
{
var uid = new UID(0xABCDEF0000EFCDABu);
Assert.Equal(new byte[]
{
0xAB, 0xCD, 0xEF, 0x00, 0x00, 0xEF, 0xCD, 0xAB
}, uid.Bytes);
2019-06-12 14:51:29 +02:00
Assert.Equal(0xABCDEF0000EFCDABu, uid.ToUInt64());
2018-06-19 17:16:08 +02:00
}
[Fact]
2018-07-09 19:57:08 +01:00
public void UShortUidTest()
2018-06-19 17:16:08 +02:00
{
var uid = new UID(0xABCDu);
Assert.Equal(new byte[]
{
0xAB, 0xCD
}, uid.Bytes);
2019-06-12 14:51:29 +02:00
Assert.Equal(0xABCDu, uid.ToUInt64());
2018-06-19 17:16:08 +02:00
}
[Fact]
public void XmlRoundTripTest()
{
var original = new UID(0xabcd);
2018-06-19 17:16:08 +02:00
2018-07-09 19:57:08 +01:00
string plist = original.ToXmlPropertyList();
2018-06-19 17:16:08 +02:00
2020-04-23 00:01:27 +02:00
// UIDs don't exist in XML property lists, but they are represented as dictionaries
2018-06-19 17:16:08 +02:00
// for compability purposes
var roundtrip = XmlPropertyListParser.ParseString(plist) as UID;
Assert.Equal(0xabcdUL, roundtrip.ToUInt64());
2018-06-19 17:16:08 +02:00
}
}
2018-07-09 19:57:08 +01:00
}