forked from dotnet/coreclr
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Managed->Native tests for our WinRT primitives (dotnet#23529)
* First pass generating the contracts for the WinRT tests. Managed ones are manually written, Native are generated via C++/WinRT. * Don't overwrite the public implementation files when we run cppwinrt * Don't output a MIDL-processed header. * Add default constructor for BindingViewModel. * Partial implementation of most of the native winrt component. * Finish implementation of native winrt component. * Get native component building correctly (cppwinrt doesn't include wrappers for the "Windows::UI::Xaml::Interop::IBindable*" collection types. * Add WinRT primitive marshalling tests. * Add testing for projected types used for binding. * Add license headers to native files. * Disable WinRT tests on non-WinRT platforms (detection copied from CoreFX). * Use WINDOWS_SDK_VERSION variable in all locations. * Use Windows SDK version determined by CMake in WinRT build. * Resolve WinMDs via globs so the build can roll between different Windows SDK versions that have required APIs seamlessly. * Add logging of cppwinrt version. * Try to construct path to cppwinrt when finding it * Just directly construct the cppwinrt path. * Remove -prefix flag from cppwinrt invocation * PR feedback. * Fix syntax in BindableVectorWrapper. * Disable winrt binding test on Nano Server. * Add enum testing. Clean up WinRT tests to hopefully build on CI (or at least fail at a later point). * Add some more logging to try to determine why an older SDK version is being picked. * Try to define CMAKE_SYSTEM_VERSION and see if that selects the correct SDK version (it seems to work on the build.cmd script) * Clean up WinRT CMake now that it builds on AzDO CI. * Disable WinRT binding test on pre-Win10V1809 systems.
- Loading branch information
1 parent
b4c2b14
commit 6a2c6a4
Showing
47 changed files
with
1,505 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
tests/src/Interop/WinRT/Contracts/Component.Contracts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Specialized; | ||
using System.ComponentModel; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
|
||
namespace Component.Contracts | ||
{ | ||
[ComImport] | ||
[Guid("971AF13A-9793-4AF7-B2F2-72D829195592")] | ||
[WindowsRuntimeImport] | ||
public interface IBooleanTesting | ||
{ | ||
bool And(bool left, bool right); | ||
} | ||
|
||
[ComImport] | ||
[Guid("C6F1F632-47B6-4A52-86D2-A89807ED2677")] | ||
[WindowsRuntimeImport] | ||
public interface IStringTesting | ||
{ | ||
string ConcatStrings(string left, string right); | ||
} | ||
|
||
[ComImport] | ||
[Guid("939D4EE5-8D41-4C4B-8948-86017CEB9244")] | ||
[WindowsRuntimeImport] | ||
public interface INullableTesting | ||
{ | ||
bool IsNull(int? value); | ||
int GetIntValue(int? value); | ||
} | ||
|
||
[ComImport] | ||
[Guid("BB545A14-9AE7-491A-874D-1C03D239FB70")] | ||
[WindowsRuntimeImport] | ||
public interface ITypeTesting | ||
{ | ||
string GetTypeName(Type type); | ||
} | ||
|
||
[ComImport] | ||
[Guid("9162201d-b591-4f30-8f41-f0f79f6ecea3")] | ||
[WindowsRuntimeImport] | ||
public interface IExceptionTesting | ||
{ | ||
void ThrowException(Exception ex); | ||
Exception GetException(int hResultToReturn); | ||
} | ||
|
||
[ComImport] | ||
[Guid("ccd10099-3a45-4382-970d-b76f52780bcd")] | ||
[WindowsRuntimeImport] | ||
public interface IKeyValuePairTesting | ||
{ | ||
KeyValuePair<int, int> MakeSimplePair(int key, int value); | ||
KeyValuePair<string, string> MakeMarshaledPair(string key, string value); | ||
KeyValuePair<int, IEnumerable<int>> MakeProjectedPair(int key, int[] values); | ||
} | ||
|
||
[ComImport] | ||
[Guid("e0af24b3-e6c6-4e89-b8d1-a332979ef398")] | ||
[WindowsRuntimeImport] | ||
public interface IUriTesting | ||
{ | ||
string GetFromUri(Uri uri); | ||
Uri CreateUriFromString(string uri); | ||
} | ||
|
||
[ComImport] | ||
[Guid("821B532D-CC5E-4218-90AB-A8361AC92794")] | ||
[WindowsRuntimeImport] | ||
public interface IArrayTesting | ||
{ | ||
int Sum(int[] array); | ||
bool Xor(bool[] array); | ||
} | ||
|
||
[ComImport] | ||
[Guid("4bb923ae-986a-4aad-9bfb-13e0b5ecffa4")] | ||
[WindowsRuntimeImport] | ||
public interface IBindingViewModel | ||
{ | ||
INotifyCollectionChanged Collection { get; } | ||
void AddElement(int i); | ||
string Name { get; set; } | ||
} | ||
|
||
[ComImport] | ||
[Guid("857e28e1-3e7f-4f6f-8554-efc73feba286")] | ||
[WindowsRuntimeImport] | ||
public interface IBindingProjectionsTesting | ||
{ | ||
IBindingViewModel CreateViewModel(); | ||
IDisposable InitializeXamlFrameworkForCurrentThread(); | ||
} | ||
|
||
public enum TestEnum | ||
{ | ||
A = 1, | ||
B = 2, | ||
C = 3 | ||
} | ||
|
||
[ComImport] | ||
[Guid("d89d71b2-2671-444d-8576-536d206dea49")] | ||
[WindowsRuntimeImport] | ||
public interface IEnumTesting | ||
{ | ||
TestEnum GetA(); | ||
Boolean IsB(TestEnum val); | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
tests/src/Interop/WinRT/Contracts/Component.Contracts.idl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace Component.Contracts | ||
{ | ||
[interface_name("Component.Contracts.IBooleanTesting", 971AF13A-9793-4AF7-B2F2-72D829195592)] | ||
runtimeclass BooleanTesting | ||
{ | ||
BooleanTesting(); | ||
Boolean And(Boolean left, Boolean right); | ||
} | ||
|
||
[interface_name("Component.Contracts.IStringTesting", C6F1F632-47B6-4A52-86D2-A89807ED2677)] | ||
runtimeclass StringTesting | ||
{ | ||
StringTesting(); | ||
String ConcatStrings(String left, String right); | ||
} | ||
|
||
[interface_name("Component.Contracts.INullableTesting", 939D4EE5-8D41-4C4B-8948-86017CEB9244)] | ||
runtimeclass NullableTesting | ||
{ | ||
NullableTesting(); | ||
Boolean IsNull(Windows.Foundation.IReference<Int32> value); | ||
Int32 GetIntValue(Windows.Foundation.IReference<Int32> value); | ||
} | ||
|
||
[interface_name("Component.Contracts.ITypeTesting", BB545A14-9AE7-491A-874D-1C03D239FB70)] | ||
runtimeclass TypeTesting | ||
{ | ||
TypeTesting(); | ||
String GetTypeName(Windows.UI.Xaml.Interop.TypeName typeName); | ||
} | ||
|
||
[interface_name("Component.Contracts.IExceptionTesting", 9162201d-b591-4f30-8f41-f0f79f6ecea3)] | ||
runtimeclass ExceptionTesting | ||
{ | ||
ExceptionTesting(); | ||
void ThrowException(Windows.Foundation.HResult hr); | ||
Windows.Foundation.HResult GetException(Int32 hr); | ||
} | ||
|
||
[interface_name("Component.Contracts.IKeyValuePairTesting", ccd10099-3a45-4382-970d-b76f52780bcd)] | ||
runtimeclass KeyValuePairTesting | ||
{ | ||
KeyValuePairTesting(); | ||
Windows.Foundation.Collections.IKeyValuePair<Int32, Int32> MakeSimplePair(Int32 key, Int32 value); | ||
Windows.Foundation.Collections.IKeyValuePair<String, String> MakeMarshaledPair(String key, String value); | ||
Windows.Foundation.Collections.IKeyValuePair<Int32, Windows.Foundation.Collections.IIterable<Int32> > MakeProjectedPair(Int32 key, Int32[] values); | ||
} | ||
|
||
[interface_name("Component.Contracts.IUriTesting", e0af24b3-e6c6-4e89-b8d1-a332979ef398)] | ||
runtimeclass UriTesting | ||
{ | ||
UriTesting(); | ||
String GetFromUri(Windows.Foundation.Uri uri); | ||
Windows.Foundation.Uri CreateUriFromString(String uri); | ||
} | ||
|
||
[interface_name("Component.Contracts.IArrayTesting", 821B532D-CC5E-4218-90AB-A8361AC92794)] | ||
runtimeclass ArrayTesting | ||
{ | ||
ArrayTesting(); | ||
Int32 Sum(Int32[] array); | ||
Boolean Xor(Boolean[] array); | ||
} | ||
|
||
[uuid(4bb923ae-986a-4aad-9bfb-13e0b5ecffa4)] | ||
interface IBindingViewModel | ||
{ | ||
Windows.UI.Xaml.Interop.INotifyCollectionChanged Collection { get; }; | ||
void AddElement(Int32 i); | ||
String Name { get; set; }; | ||
} | ||
|
||
runtimeclass BindingViewModel : [default] IBindingViewModel, Windows.UI.Xaml.Data.INotifyPropertyChanged | ||
{ | ||
BindingViewModel(); | ||
} | ||
|
||
[interface_name("Component.Contracts.IBindingProjectionsTesting", 857e28e1-3e7f-4f6f-8554-efc73feba286)] | ||
runtimeclass BindingProjectionsTesting | ||
{ | ||
BindingProjectionsTesting(); | ||
IBindingViewModel CreateViewModel(); | ||
Windows.Foundation.IClosable InitializeXamlFrameworkForCurrentThread(); | ||
} | ||
|
||
enum TestEnum | ||
{ | ||
A = 1, | ||
B = 2, | ||
C = 3 | ||
}; | ||
|
||
[interface_name("Component.Contracts.IEnumTesting", d89d71b2-2671-444d-8576-536d206dea49)] | ||
runtimeclass EnumTesting | ||
{ | ||
EnumTesting(); | ||
TestEnum GetA(); | ||
Boolean IsB(TestEnum val); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
|
||
public static class WinRTNativeComponent | ||
{ | ||
[DllImport(nameof(WinRTNativeComponent), PreserveSig = false)] | ||
private static extern IActivationFactory DllGetActivationFactory([MarshalAs(UnmanagedType.HString)] string typeName); | ||
|
||
public static object GetObjectFromNativeComponent(string typeName) | ||
{ | ||
return DllGetActivationFactory(typeName).ActivateInstance(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/src/Interop/WinRT/Contracts/WindowsRuntimeImportAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace System.Runtime.InteropServices.WindowsRuntime | ||
{ | ||
// Types decorated with this attribute are treated specially by the compiler. A "windowsruntime" bit is set in their metadata. | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Enum | AttributeTargets.Struct | AttributeTargets.Delegate, Inherited = false)] | ||
internal sealed class WindowsRuntimeImportAttribute : Attribute | ||
{ | ||
public WindowsRuntimeImportAttribute() { } | ||
} | ||
} |
Oops, something went wrong.