-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathComInteropTests.cs
173 lines (154 loc) · 6.98 KB
/
ComInteropTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using System;
using System.Runtime.InteropServices;
using Windows.ApplicationModel.DataTransfer;
using Windows.ApplicationModel.DataTransfer.DragDrop.Core;
using Windows.Graphics.Display;
using Windows.Graphics.Printing;
using Windows.Media;
using Windows.Media.PlayTo;
using Windows.Security.Authentication.Web.Core;
using Windows.Security.Credentials;
using Windows.Security.Credentials.UI;
using Windows.UI.ApplicationSettings;
using Windows.UI.Input;
using Windows.UI.Input.Core;
using Windows.UI.Input.Spatial;
using Windows.UI.ViewManagement;
using Xunit;
using WinRT;
using TestComponentCSharp;
namespace UnitTest
{
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("15651B9F-6C6B-4CC0-944C-C7D7B0F36F81")]
internal interface IComInterop
{
Int64 ReturnWindowHandle(IntPtr hwnd, Guid iid);
}
// Note: Many of the COM interop APIs cannot be easily tested without significant test setup.
// These cases either expect a runtime exception, or are compile-time only (skipped to validate types).
public class ComInteropTests
{
[Fact]
public void TestHWND()
{
var comInterop = Class.ComInterop.As<IComInterop>();
if (System.Environment.Is64BitProcess)
{
var hwnd = new IntPtr(0x0123456789ABCDEF);
var value = comInterop.ReturnWindowHandle(hwnd, typeof(IComInterop).GUID);
var hwndValue = hwnd.ToInt64();
Assert.Equal(hwndValue, value);
}
else
{
var hwnd = new IntPtr(0x01234567);
var value = comInterop.ReturnWindowHandle(hwnd, typeof(IComInterop).GUID);
var hwndValue = hwnd.ToInt32();
Assert.Equal(hwndValue, value);
}
}
[Fact]
public void TestMockDragDropManager()
{
var interop = Class.ComInterop.As<WinRT.Interop.IDragDropManagerInterop>();
Guid iid = GuidGenerator.CreateIID(typeof(ICoreDragDropManager));
var manager = interop.GetForWindow(new IntPtr(0), iid);
Assert.NotNull(manager);
}
[Fact]
public void TestAccountsSettingsPane()
{
Assert.Throws<COMException>(() => AccountsSettingsPaneInterop.GetForWindow(new IntPtr(0)));
Assert.Throws<COMException>(() => AccountsSettingsPaneInterop.ShowAddAccountForWindowAsync(new IntPtr(0)));
Assert.Throws<COMException>(() => AccountsSettingsPaneInterop.ShowManageAccountsForWindowAsync(new IntPtr(0)));
}
[Fact]
public void TestDragDropManager()
{
Assert.Throws<COMException>(() => DragDropManagerInterop.GetForWindow(new IntPtr(0)));
}
[Fact]
public void TestInputPane()
{
Assert.Throws<TypeInitializationException>(() => InputPaneInterop.GetForWindow(new IntPtr(0)));
}
[Fact]
public void TestPlayToManager()
{
Assert.Throws<COMException>(() => PlayToManagerInterop.GetForWindow(new IntPtr(0)));
PlayToManagerInterop.ShowPlayToUIForWindow(new IntPtr(0));
}
[Fact]
public void TestPrintManager()
{
Assert.Throws<COMException>(() => PrintManagerInterop.GetForWindow(new IntPtr(0)));
Assert.Throws<COMException>(() => PrintManagerInterop.ShowPrintUIForWindowAsync(new IntPtr(0)));
}
[Fact]
public void TestRadialControllerConfiguration()
{
Assert.Throws<COMException>(() => RadialControllerConfigurationInterop.GetForWindow(new IntPtr(0)));
}
// Skipping this test as it causes a hang
[Fact(Skip = "Compile-time only interop test")]
public void TestRadialControllerIndependentInputSource()
{
var radialControllerIndependentInputSource = RadialControllerIndependentInputSourceInterop.CreateForWindow(new IntPtr(0));
Assert.IsType<Windows.UI.Input.Core.RadialControllerIndependentInputSource>(radialControllerIndependentInputSource);
}
// Skipping this test as it causes a hang
[Fact(Skip = "Compile-time only interop test")]
public void TestRadialControllerInterop()
{
var radialController = RadialControllerInterop.CreateForWindow(new IntPtr(0));
Assert.IsType<Windows.UI.Input.RadialController>(radialController);
}
// Skipping this test as it raises non-catchable 'System.AccessViolationException' occurred in Windows.dll
[Fact(Skip = "Compile-time only interop test")]
public void TestSpatialInteractionManager()
{
Assert.Throws<COMException>(() => SpatialInteractionManagerInterop.GetForWindow(new IntPtr(0)));
}
// Skipping this test as it raises non-catchable 'System.AccessViolationException' occurred in Windows.dll
[Fact(Skip = "Compile-time only interop test")]
public void TestSystemMediaTransportControls()
{
Assert.Throws<COMException>(() => SystemMediaTransportControlsInterop.GetForWindow(new IntPtr(0)));
}
[Fact]
public void TestUIViewSettings()
{
Assert.Throws<COMException>(() => UIViewSettingsInterop.GetForWindow(new IntPtr(0)));
}
[Fact]
public void TestUserConsentVerifier()
{
var operation = UserConsentVerifierInterop.RequestVerificationForWindowAsync(new IntPtr(0), "message");
Assert.NotNull(operation);
}
[Fact]
public void TestWebAuthenticationCoreManager()
{
WebAccountProvider provider = new WebAccountProvider("id", "name", null);
WebTokenRequest webTokenRequest = new WebTokenRequest(provider);
Assert.Throws<ArgumentException>(() => WebAuthenticationCoreManagerInterop.RequestTokenForWindowAsync(new IntPtr(0), webTokenRequest));
var webAccount = new WebAccount(provider, "user name", 0);
Assert.Throws<ArgumentException>(() => WebAuthenticationCoreManagerInterop.RequestTokenWithWebAccountForWindowAsync(new IntPtr(0), webTokenRequest, webAccount));
}
// Skipping as API isn't available in pipeline yet.
[Fact(Skip = "Compile-time only interop test")]
public void TestDisplayInformation()
{
Assert.Throws<COMException>(() => DisplayInformationInterop.GetForWindow(new IntPtr(0)));
Assert.Throws<COMException>(() => DisplayInformationInterop.GetForMonitor(new IntPtr(0)));
}
[Fact]
public void TestDataTransferManager()
{
Assert.Throws<COMException>(() => DataTransferManagerInterop.GetForWindow(new IntPtr(0)));
Assert.Throws<COMException>(() => DataTransferManagerInterop.ShowShareUIForWindow(new IntPtr(0)));
}
}
}