Skip to content
Open
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
78 changes: 78 additions & 0 deletions src/Tests/FunctionalTests/Collections/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,84 @@
}
}

// Test 'Keys'/'Values' on a directly constructed runtime class that's projected via
// cswinrt's static_abi_methods path (uses the interop generator's '{Map}Methods.Keys/Values'
// statically resolved via 'UnsafeAccessor'). 'Windows.Foundation.Collections.StringMap' is a
// runtime class projected as 'IDictionary<string, string>'; this exercises the trim/AOT path
// for both the cswinrt-generated 'Keys'/'Values' property and the interop-emitted static method.
var stringMapForKeysValues = new Windows.Foundation.Collections.StringMap
{
["one"] = "1",
["two"] = "2",
["three"] = "3"
};

System.Collections.Generic.ICollection<string> stringMapKeys = stringMapForKeysValues.Keys;
System.Collections.Generic.ICollection<string> stringMapValues = stringMapForKeysValues.Values;
if (stringMapKeys.Count != 3 || stringMapValues.Count != 3)
{
return 101;
}
if (!stringMapKeys.Contains("one") || !stringMapKeys.Contains("two") || !stringMapKeys.Contains("three"))
{
return 101;
}
if (!stringMapValues.Contains("1") || !stringMapValues.Contains("2") || !stringMapValues.Contains("3"))
{
return 101;
}

// Same scenario for 'PropertySet'/'ValueSet': different generic instantiation
// ('IDictionary<string, object>') and so a different generated 'Methods' type.
var newPropertySet = new Windows.Foundation.Collections.PropertySet
{
["alpha"] = 1,
["beta"] = "two"
};

System.Collections.Generic.ICollection<string> newPropertySetKeys = newPropertySet.Keys;
System.Collections.Generic.ICollection<object> newPropertySetValues = newPropertySet.Values;
if (newPropertySetKeys.Count != 2 || newPropertySetValues.Count != 2)
{
return 101;
}
if (!newPropertySetKeys.Contains("alpha") || !newPropertySetKeys.Contains("beta"))
{
return 101;
}

var newValueSet = new Windows.Foundation.Collections.ValueSet
{
["x"] = 1.0,
["y"] = 2.0
};

if (newValueSet.Keys.Count != 2 || newValueSet.Values.Count != 2)
{
return 101;
}

// Test the parallel 'IReadOnlyDictionary' path through a runtime class that's projected
// as 'IReadOnlyDictionary<string, string>'. This exercises the cswinrt-emitted projection
// (with the corrected 'IEnumerable<T>' UnsafeAccessor return type) bound to the interop-
// emitted 'IReadOnlyDictionary'2<string|string>Methods.Keys'/'Values' static methods,
// under trimming/AOT.
var customReadOnlyDictionary = new TestComponentCSharp.CustomReadOnlyDictionaryTest();
System.Collections.Generic.IEnumerable<string> customDictionaryKeys = customReadOnlyDictionary.Keys;
System.Collections.Generic.IEnumerable<string> customDictionaryValues = customReadOnlyDictionary.Values;
if (customDictionaryKeys.Count() != 3 || customDictionaryValues.Count() != 3)
{
return 101;
}
if (!customDictionaryKeys.Contains("apples") || !customDictionaryKeys.Contains("oranges") || !customDictionaryKeys.Contains("pears"))
{
return 101;
}
if (!customDictionaryValues.Contains("1") || !customDictionaryValues.Contains("2") || !customDictionaryValues.Contains("3"))
{
return 101;
}

var propertySet = Class.PropertySet;
if (propertySet["beta"] is not string str || str != "second")
{
Expand Down
49 changes: 49 additions & 0 deletions src/Tests/TestComponentCSharp/CustomReadOnlyDictionaryTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "pch.h"
#include "CustomReadOnlyDictionaryTest.h"
#include "CustomReadOnlyDictionaryTest.g.cpp"

namespace winrt::TestComponentCSharp::implementation
{
CustomReadOnlyDictionaryTest::CustomReadOnlyDictionaryTest()
{
// Default contents: a small set of string -> string entries suitable for 'Keys'/'Values' tests.
std::map<winrt::hstring, winrt::hstring> initial{
{ L"apples", L"1" },
{ L"oranges", L"2" },
{ L"pears", L"3" }
};
_mapView = winrt::single_threaded_map_view<winrt::hstring, winrt::hstring>(std::move(initial));
}

CustomReadOnlyDictionaryTest::CustomReadOnlyDictionaryTest(winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, winrt::hstring> const& mapView)
{
_mapView = mapView;
}

winrt::hstring CustomReadOnlyDictionaryTest::Lookup(winrt::hstring const& key)
{
return _mapView.Lookup(key);
}

uint32_t CustomReadOnlyDictionaryTest::Size()
{
return _mapView.Size();
}

bool CustomReadOnlyDictionaryTest::HasKey(winrt::hstring const& key)
{
return _mapView.HasKey(key);
}

void CustomReadOnlyDictionaryTest::Split(
winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, winrt::hstring>& first,
winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, winrt::hstring>& second)
{
_mapView.Split(first, second);
}

winrt::Windows::Foundation::Collections::IIterator<winrt::Windows::Foundation::Collections::IKeyValuePair<winrt::hstring, winrt::hstring>> CustomReadOnlyDictionaryTest::First()
{
return _mapView.First();
}
}
28 changes: 28 additions & 0 deletions src/Tests/TestComponentCSharp/CustomReadOnlyDictionaryTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once
#include "CustomReadOnlyDictionaryTest.g.h"

namespace winrt::TestComponentCSharp::implementation
{
struct CustomReadOnlyDictionaryTest : CustomReadOnlyDictionaryTestT<CustomReadOnlyDictionaryTest>
{
CustomReadOnlyDictionaryTest();
CustomReadOnlyDictionaryTest(winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, winrt::hstring> const& mapView);

winrt::hstring Lookup(winrt::hstring const& key);
uint32_t Size();
bool HasKey(winrt::hstring const& key);
void Split(
winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, winrt::hstring>& first,
winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, winrt::hstring>& second);
winrt::Windows::Foundation::Collections::IIterator<winrt::Windows::Foundation::Collections::IKeyValuePair<winrt::hstring, winrt::hstring>> First();

winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, winrt::hstring> _mapView;
};
}

namespace winrt::TestComponentCSharp::factory_implementation
{
struct CustomReadOnlyDictionaryTest : CustomReadOnlyDictionaryTestT<CustomReadOnlyDictionaryTest, implementation::CustomReadOnlyDictionaryTest>
{
};
}
7 changes: 7 additions & 0 deletions src/Tests/TestComponentCSharp/TestComponentCSharp.idl
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,13 @@ namespace TestComponentCSharp
static CustomIterableTest CreateWithCustomIterator();
}

[default_interface]
runtimeclass CustomReadOnlyDictionaryTest : Windows.Foundation.Collections.IMapView<String, String>
{
CustomReadOnlyDictionaryTest();
CustomReadOnlyDictionaryTest(Windows.Foundation.Collections.IMapView<String, String> mapView);
}

// SupportedOSPlatform warning tests
[contract(Windows.Foundation.UniversalApiContract, 10)]
[attributeusage(target_all)]
Expand Down
2 changes: 2 additions & 0 deletions src/Tests/TestComponentCSharp/TestComponentCSharp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<ClInclude Include="CustomExperimentClass.h" />
<ClInclude Include="CustomEquals.h" />
<ClInclude Include="CustomIterableTest.h" />
<ClInclude Include="CustomReadOnlyDictionaryTest.h" />
<ClInclude Include="ManualProjectionTestClasses.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="Class.h">
Expand All @@ -111,6 +112,7 @@
<ClCompile Include="CustomExperimentClass.cpp" />
<ClCompile Include="CustomEquals.cpp" />
<ClCompile Include="CustomIterableTest.cpp" />
<ClCompile Include="CustomReadOnlyDictionaryTest.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
Expand Down
110 changes: 56 additions & 54 deletions src/Tests/TestComponentCSharp/TestComponentCSharp.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -1,55 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Resources">
<UniqueIdentifier>accd3aa8-1ba0-4223-9bbe-0c431709210b</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp" />
<ClCompile Include="Class.cpp" />
<ClCompile Include="NonAgileClass.cpp" />
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
<ClCompile Include="ComImports.cpp" />
<ClCompile Include="ManualProjectionTestClasses.cpp" />
<ClCompile Include="WarningClass.cpp" />
<ClCompile Include="WarningStatic.cpp" />
<ClCompile Include="Singleton.cpp" />
<ClCompile Include="Windows.Class.cpp" />
<ClCompile Include="ABCDEFGHIJKLMNOPQRSTUVQXYZabcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVQXYZabcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.cpp" />
<ClCompile Include="AnotherAssembly.SetPropertyClass.cpp" />
<ClCompile Include="CustomEquals.cpp" />
<ClCompile Include="CustomExperimentClass.cpp" />
<ClCompile Include="WinRT.Class.cpp" />
<ClCompile Include="ClassWithExplicitIUnknown.cpp" />
<ClCompile Include="NonUniqueClass.cpp" />
<ClCompile Include="CustomIterableTest.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="NonAgileClass.h" />
<ClInclude Include="ComImports.h" />
<ClInclude Include="ManualProjectionTestClasses.h" />
<ClInclude Include="WarningStatic.h" />
<ClInclude Include="WarningClass.h" />
<ClInclude Include="Singleton.h" />
<ClInclude Include="Windows.Class.h" />
<ClInclude Include="ABCDEFGHIJKLMNOPQRSTUVQXYZabcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVQXYZabcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.h" />
<ClInclude Include="AnotherAssembly.SetPropertyClass.h" />
<ClInclude Include="CustomEquals.h" />
<ClInclude Include="CustomExperimentClass.h" />
<ClInclude Include="WinRT.Class.h" />
<ClInclude Include="ClassWithExplicitIUnknown.h" />
<ClInclude Include="NonUniqueClass.h" />
<ClInclude Include="CustomIterableTest.h" />
</ItemGroup>
<ItemGroup>
<Midl Include="TestComponentCSharp.idl" />
</ItemGroup>
<ItemGroup>
<None Include="TestComponentCSharp.def" />
<None Include="packages.config" />
<None Include="Directory.Build.props" />
</ItemGroup>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Resources">
<UniqueIdentifier>accd3aa8-1ba0-4223-9bbe-0c431709210b</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp" />
<ClCompile Include="Class.cpp" />
<ClCompile Include="NonAgileClass.cpp" />
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
<ClCompile Include="ComImports.cpp" />
<ClCompile Include="ManualProjectionTestClasses.cpp" />
<ClCompile Include="WarningClass.cpp" />
<ClCompile Include="WarningStatic.cpp" />
<ClCompile Include="Singleton.cpp" />
<ClCompile Include="Windows.Class.cpp" />
<ClCompile Include="ABCDEFGHIJKLMNOPQRSTUVQXYZabcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVQXYZabcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.cpp" />
<ClCompile Include="AnotherAssembly.SetPropertyClass.cpp" />
<ClCompile Include="CustomEquals.cpp" />
<ClCompile Include="CustomExperimentClass.cpp" />
<ClCompile Include="WinRT.Class.cpp" />
<ClCompile Include="ClassWithExplicitIUnknown.cpp" />
<ClCompile Include="NonUniqueClass.cpp" />
<ClCompile Include="CustomIterableTest.cpp" />
<ClCompile Include="CustomReadOnlyDictionaryTest.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="NonAgileClass.h" />
<ClInclude Include="ComImports.h" />
<ClInclude Include="ManualProjectionTestClasses.h" />
<ClInclude Include="WarningStatic.h" />
<ClInclude Include="WarningClass.h" />
<ClInclude Include="Singleton.h" />
<ClInclude Include="Windows.Class.h" />
<ClInclude Include="ABCDEFGHIJKLMNOPQRSTUVQXYZabcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVQXYZabcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.h" />
<ClInclude Include="AnotherAssembly.SetPropertyClass.h" />
<ClInclude Include="CustomEquals.h" />
<ClInclude Include="CustomExperimentClass.h" />
<ClInclude Include="WinRT.Class.h" />
<ClInclude Include="ClassWithExplicitIUnknown.h" />
<ClInclude Include="NonUniqueClass.h" />
<ClInclude Include="CustomIterableTest.h" />
<ClInclude Include="CustomReadOnlyDictionaryTest.h" />
</ItemGroup>
<ItemGroup>
<Midl Include="TestComponentCSharp.idl" />
</ItemGroup>
<ItemGroup>
<None Include="TestComponentCSharp.def" />
<None Include="packages.config" />
<None Include="Directory.Build.props" />
</ItemGroup>
</Project>
Loading