Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions UnitTests/PListObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ public void TestIntegerXmlSerialization ()

using (var stream = GetType ().Assembly.GetManifestResourceStream ("UnitTests.TestData.PropertyLists.xml-integers.plist")) {
var buffer = new byte [stream.Length];
#if NET7_0_OR_GREATER
stream.ReadExactly (buffer, 0, buffer.Length);
#else
stream.Read (buffer, 0, buffer.Length);
#endif

expected = Encoding.UTF8.GetString (buffer);
}
Expand Down Expand Up @@ -117,6 +121,25 @@ public void TestIntegerBinarySerialization ()
Assert.That (integer.Value, Is.EqualTo (kvp.Value));
}
}

[Test]
public void TestStrings ()
{
PDictionary plist;

using (var stream = GetType ().Assembly.GetManifestResourceStream ($"UnitTests.TestData.PropertyLists.strings.plist"))
plist = (PDictionary) PObject.FromStream (stream);

Assert.That (plist.Count, Is.EqualTo (2));

Assert.That (plist.TryGetValue<PString> ("KeyA", out var valueA), Is.True);
Assert.That (valueA.Value, Is.EqualTo ("ValueA"));
Assert.That (plist.TryGetStringValue ("KeyA", out var valueAString));
Assert.That (valueAString, Is.EqualTo ("ValueA"));

Assert.That (plist.TryGetStringValue ("✅", out var emojiValue), Is.True);
Assert.That (emojiValue, Is.EqualTo ("❌"));
}
}
}

10 changes: 10 additions & 0 deletions UnitTests/TestData/PropertyLists/strings.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?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>KeyA</key>
<string>ValueA</string>
<key>✅</key>
<string>❌</string>
</dict>
</plist>
5 changes: 4 additions & 1 deletion UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<TargetFrameworks>net472;net10.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="4.1.0" />
Expand All @@ -10,6 +10,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit.ConsoleRunner" Version="3.18.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<None Remove="TestData\PropertyLists\" />
Expand All @@ -29,5 +31,6 @@
<ItemGroup>
<EmbeddedResource Include="TestData\PropertyLists\binary-integers.plist" />
<EmbeddedResource Include="TestData\PropertyLists\xml-integers.plist" />
<EmbeddedResource Include="TestData\PropertyLists\strings.plist" />
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions Xamarin.MacDev/PListObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,17 @@ public bool TryGetValue<T> (string key, [NotNullWhen (true)] out T? value) where
return false;
}

public bool TryGetStringValue (string key, [NotNullWhen (true)] out string? value)
{
if (TryGetValue<PString> (key, out var obj)) {
value = obj.Value;
return true;
}

value = null;
return false;
}

#if POBJECT_MONOMAC
public override NSObject Convert ()
{
Expand Down