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

96 lines
2.9 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
{
2018-07-09 19:57:08 +01:00
[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 17:16:08 +02:00
{
2018-07-09 19:57:08 +01:00
UID uid = new UID(array);
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
{
2018-07-09 19:57:08 +01:00
UID original = new UID(0xabcd);
using(MemoryStream stream = new MemoryStream())
{
BinaryPropertyListWriter.Write(stream, original);
stream.Position = 0;
UID 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
{
2018-07-09 19:57:08 +01:00
UID 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
{
2018-07-09 19:57:08 +01:00
UID 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
{
2018-07-09 19:57:08 +01:00
UID 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
{
2018-07-09 19:57:08 +01:00
UID 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
{
2018-07-09 19:57:08 +01:00
UID 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
{
2018-07-09 19:57:08 +01:00
UID 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()
{
2018-07-09 19:57:08 +01:00
UID 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
2020-04-23 00:01:27 +02:00
var roundtrip = XmlPropertyListParser.ParseString(plist) as NSDictionary;
Assert.Single(roundtrip.Keys, "CF$UID");
Assert.Single(roundtrip.Values, new NSNumber(0xabcd));
2018-06-19 17:16:08 +02:00
}
}
2018-07-09 19:57:08 +01:00
}