Skip to content

Commit

Permalink
Add some tests to the plist readers
Browse files Browse the repository at this point in the history
  • Loading branch information
artehe committed Jan 11, 2024
1 parent bf81219 commit 3448b7d
Show file tree
Hide file tree
Showing 15 changed files with 66,020 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Netimobiledevice.Exceptions
namespace Netimobiledevice.Plist
{
public class PlistException : Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Netimobiledevice.Exceptions
namespace Netimobiledevice.Plist
{
/// <summary>
/// Property list format exception.
Expand Down
4 changes: 4 additions & 0 deletions NetimobiledeviceTest/NetimobiledeviceTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="TestFiles\*.plist" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Netimobiledevice\Netimobiledevice.csproj" />
Expand Down
68 changes: 68 additions & 0 deletions NetimobiledeviceTest/Plist/BinaryFormatReaderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Netimobiledevice.Plist;
using NetimobiledeviceTest.TestFiles;

namespace NetimobiledeviceTest.Plist;

[TestClass]
public class BinaryFormatReaderTests
{
[TestMethod]
public void ParseBinaryPlistWithSingleDictionary()
{
using (Stream stream = TestFileHelper.GetTestFileStream("TestFiles/GenericBinary.plist")) {
PropertyNode node = PropertyList.Load(stream);
Assert.IsNotNull(node);
DictionaryNode dictionary = node.AsDictionaryNode();
Assert.IsNotNull(dictionary);
Assert.AreEqual(14, dictionary.Count);
}
}

[TestMethod]
public void ReadFileWithUID()
{
using (Stream stream = TestFileHelper.GetTestFileStream("TestFiles/UidBinary.plist")) {
DictionaryNode root = PropertyList.Load(stream).AsDictionaryNode();

Assert.IsNotNull(root);
Assert.AreEqual(4, root.Count);

DictionaryNode dict = root["$top"].AsDictionaryNode();
Assert.IsNotNull(dict);

UidNode uid = dict["data"].AsUidNode();
Assert.IsNotNull(uid);

Assert.AreEqual<ulong>(1, uid.Value);
}
}

[TestMethod]
public void ReadingFileWith16bitIntegers()
{
using (Stream stream = TestFileHelper.GetTestFileStream("TestFiles/UnityBinary.plist")) {
try {
PropertyNode node = PropertyList.Load(stream);
}
catch (PlistFormatException ex) {
Assert.Fail(ex.Message);
}
}
}

[TestMethod]
public void ReadingFileWithLargeDictionary()
{
using (Stream stream = TestFileHelper.GetTestFileStream("TestFiles/LargeDictionaryBinary.plist")) {
try {
PropertyNode node = PropertyList.Load(stream);
DictionaryNode dictNode = node.AsDictionaryNode();
Assert.IsNotNull(dictNode);
Assert.AreEqual(32768, dictNode.Keys.Count);
}
catch (PlistFormatException ex) {
Assert.Fail(ex.Message);
}
}
}
}
87 changes: 87 additions & 0 deletions NetimobiledeviceTest/Plist/XmlReaderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using Netimobiledevice.Plist;
using NetimobiledeviceTest.TestFiles;

namespace NetimobiledeviceTest.Plist;

[TestClass]
public class XmlReaderTests
{
[TestMethod]
public void ParseXmlPlistWithSingleDictionary()
{
using (Stream stream = TestFileHelper.GetTestFileStream("TestFiles/GenericXml.plist")) {
PropertyNode node = PropertyList.Load(stream);
DictionaryNode dictionary = node.AsDictionaryNode();
Assert.IsNotNull(dictionary);
Assert.AreEqual(14, dictionary.Count);
}
}

[TestMethod]
public void DocumentContainingNestedCollections()
{
using (Stream stream = TestFileHelper.GetTestFileStream("TestFiles/DictInsideArrayXml.plist")) {
PropertyNode node = PropertyList.Load(stream);

Assert.IsNotNull(node);
Assert.IsInstanceOfType<DictionaryNode>(node);

ArrayNode array = node.AsDictionaryNode().Values.First().AsArrayNode();
Assert.IsNotNull(array);
Assert.AreEqual(1, array.Count);

DictionaryNode dictionary = array[0].AsDictionaryNode();
Assert.IsNotNull(dictionary);

Assert.AreEqual(4, dictionary.Count);
}
}

[TestMethod]
public void DocumentContainingEmptyArray()
{
using (Stream stream = TestFileHelper.GetTestFileStream("TestFiles/EmptyArrayXml.plist")) {
DictionaryNode root = PropertyList.Load(stream).AsDictionaryNode();

Assert.IsNotNull(root);
Assert.AreEqual(1, root.Count);

Assert.IsInstanceOfType<DictionaryNode>(root["Entitlements"]);
DictionaryNode dict = root["Entitlements"].AsDictionaryNode();

ArrayNode array = dict["com.apple.developer.icloud-container-identifiers"].AsArrayNode();
Assert.IsNotNull(array);
Assert.AreEqual(0, array.Count);
}
}

[TestMethod]
public void ReadingFileWith16bitIntegers()
{
using (Stream stream = TestFileHelper.GetTestFileStream("TestFiles/UnityXml.plist")) {
try {
PropertyNode node = PropertyList.Load(stream);
}
catch (PlistFormatException ex) {
Assert.Fail(ex.Message);
}
}
}

[TestMethod]
public void ReadingFileWithLargeDictionary()
{
using (Stream stream = TestFileHelper.GetTestFileStream("TestFiles/LargeDictionaryXml.plist")) {
try {
PropertyNode node = PropertyList.Load(stream);
DictionaryNode dictNode = node.AsDictionaryNode();
Assert.IsNotNull(dictNode);
Assert.AreEqual(32768, dictNode.Keys.Count);
}
catch (PlistFormatException ex) {
Assert.Fail(ex.Message);
}
}
}
}

19 changes: 19 additions & 0 deletions NetimobiledeviceTest/TestFiles/DictInsideArrayXml.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UILaunchImages</key>
<array>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>7.0</string>
<key>UILaunchImageName</key>
<string>LaunchImage-700-568h</string>
<key>UILaunchImageOrientation</key>
<string>Portrait</string>
<key>UILaunchImageSize</key>
<string>{320, 568}</string>
</dict>
</array>
</dict>
</plist>
85 changes: 85 additions & 0 deletions NetimobiledeviceTest/TestFiles/EmptyArrayXml.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Entitlements</key>
<dict>
<key>com.apple.developer.pass-type-identifiers</key>
<array>
<string>S25XN959HW.*</string>
</array>
<key>com.apple.developer.networking.networkextension</key>
<array>
<string>app-proxy-provider</string>
<string>content-filter-provider</string>
<string>packet-tunnel-provider</string>
<string>dns-proxy</string>
</array>
<key>com.apple.developer.networking.HotspotConfiguration</key>
<true/>
<key>com.apple.developer.networking.multipath</key>
<true/>
<key>com.apple.developer.nfc.readersession.formats</key>
<array>
<string>NDEF</string>
</array>
<key>com.apple.developer.ClassKit-environment</key>
<array>
<string>development</string>
<string>production</string>
</array>
<key>com.apple.developer.authentication-services.autofill-credential-provider</key>
<true/>
<key>com.apple.developer.networking.wifi-info</key>
<true/>
<key>keychain-access-groups</key>
<array>
<string>S25XN959HW.*</string>
</array>
<key>inter-app-audio</key>
<true/>
<key>get-task-allow</key>
<true/>
<key>application-identifier</key>
<string>S25XN959HW.com.os.os04</string>
<key>com.apple.developer.healthkit</key>
<true/>
<key>com.apple.developer.healthkit.access</key>
<array>
<string>health-records</string>
</array>
<key>com.apple.developer.ubiquity-kvstore-identifier</key>
<string>S25XN959HW.*</string>
<key>com.apple.developer.icloud-services</key>
<string>*</string>
<key>com.apple.developer.icloud-container-identifiers</key>
<array> </array>
<key>com.apple.developer.icloud-container-development-container-identifiers</key>
<array> </array>
<key>com.apple.developer.ubiquity-container-identifiers</key>
<array> </array>
<key>com.apple.developer.associated-domains</key>
<string>*</string>
<key>com.apple.security.application-groups</key>
<array> </array>
<key>com.apple.developer.homekit</key>
<true/>
<key>com.apple.developer.team-identifier</key>
<string>S25XN959HW</string>
<key>com.apple.external-accessory.wireless-configuration</key>
<true/>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.developer.in-app-payments</key>
<array> </array>
<key>com.apple.developer.default-data-protection</key>
<string>NSFileProtectionComplete</string>
<key>com.apple.developer.networking.vpn.api</key>
<array>
<string>allow-vpn</string>
</array>
<key>com.apple.developer.siri</key>
<true/>
</dict>
</dict>
</plist>
Binary file added NetimobiledeviceTest/TestFiles/GenericBinary.plist
Binary file not shown.
34 changes: 34 additions & 0 deletions NetimobiledeviceTest/TestFiles/GenericXml.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.test.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2014 Test. All rights reserved.</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
Binary file not shown.
Loading

0 comments on commit 3448b7d

Please sign in to comment.