Skip to content

Commit 3bae4e6

Browse files
authored
Add initial interop testing framework (#1932)
1 parent 8061136 commit 3bae4e6

File tree

15 files changed

+925
-19
lines changed

15 files changed

+925
-19
lines changed

Winforms.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.TestUt
135135
EndProject
136136
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiToolStripTests", "src\System.Windows.Forms\tests\IntegrationTests\MauiTests\MauiToolStripTests\MauiToolStripTests.csproj", "{83634671-CF3A-43B0-B729-42CCBA62DF2C}"
137137
EndProject
138+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.Interop.Tests", "src\System.Windows.Forms\tests\InteropTests\System.Windows.Forms.Interop.Tests.csproj", "{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}"
139+
EndProject
138140
Global
139141
GlobalSection(SolutionConfigurationPlatforms) = preSolution
140142
Debug|Any CPU = Debug|Any CPU
@@ -277,6 +279,18 @@ Global
277279
{83634671-CF3A-43B0-B729-42CCBA62DF2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
278280
{83634671-CF3A-43B0-B729-42CCBA62DF2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
279281
{83634671-CF3A-43B0-B729-42CCBA62DF2C}.Release|Any CPU.Build.0 = Release|Any CPU
282+
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Debug|Any CPU.ActiveCfg = Debug|x86
283+
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Debug|Any CPU.Build.0 = Debug|x86
284+
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Release|Any CPU.ActiveCfg = Release|x86
285+
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Release|Any CPU.Build.0 = Release|x86
286+
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Debug|x86.ActiveCfg = Debug|x86
287+
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Debug|x86.Build.0 = Debug|x86
288+
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Release|x86.ActiveCfg = Release|x86
289+
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Release|x86.Build.0 = Release|x86
290+
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Debug|x64.ActiveCfg = Debug|x64
291+
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Debug|x64.Build.0 = Debug|x64
292+
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Release|x64.ActiveCfg = Release|x64
293+
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Release|x64.Build.0 = Release|x64
280294
EndGlobalSection
281295
GlobalSection(SolutionProperties) = preSolution
282296
HideSolutionNode = FALSE
@@ -321,6 +335,7 @@ Global
321335
{73B0857A-966B-4E7D-8A83-FECFE0281AB9} = {DF68A171-D27B-4E6A-8A7E-63A651622355}
322336
{86418F0B-39DC-4B5A-8145-6D607E6150AC} = {DF68A171-D27B-4E6A-8A7E-63A651622355}
323337
{83634671-CF3A-43B0-B729-42CCBA62DF2C} = {8F20A905-BD37-4D80-B8DF-FA45276FC23F}
338+
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224} = {583F1292-AE8D-4511-B8D8-A81FE4642DDC}
324339
EndGlobalSection
325340
GlobalSection(ExtensibilityGlobals) = postSolution
326341
SolutionGuid = {7B1B0433-F612-4E5A-BE7E-FCF5B9F6E136}

eng/configure-toolset.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
$script:DoNotAbortNativeToolsInstallationOnFailure = $true
22
$script:DoNotDisplayNativeToolsInstallationWarnings = $true
3+
4+
# Add CMake to path.
5+
$env:PATH = "$PSScriptRoot\..\.tools\bin;$env:PATH"

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"Microsoft.NET.Sdk.IL": "5.0.0-rc.1.20371.13"
2222
},
2323
"native-tools": {
24-
"cmake": "3.14.2",
24+
"cmake": "3.17.3",
2525
"dotnet-api-docs_netcoreapp3.0": "0.0.0.1"
2626
}
2727
}

src/System.Windows.Forms.Primitives/src/Interop/Ole32/Interop.IOleClientSite.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ HRESULT GetMoniker(
2323
Ole32.OLEWHICHMK dwWhichMoniker,
2424
IntPtr* ppmk);
2525

26-
[PreserveSig]
27-
HRESULT GetContainer(
28-
out IOleContainer container);
26+
IOleContainer GetContainer();
2927

3028
[PreserveSig]
3129
HRESULT ShowObject();

src/System.Windows.Forms.Primitives/src/Interop/Ole32/Interop.IOleControlSite.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ HRESULT LockInPlaceActive(
2424

2525
[PreserveSig]
2626
HRESULT GetExtendedControl(
27-
[MarshalAs(UnmanagedType.IDispatch)] out object ppDisp);
27+
IntPtr* ppDisp);
2828

2929
[PreserveSig]
3030
HRESULT TransformCoords(

src/System.Windows.Forms/src/System/Windows/Forms/AxHost.OleInterfaces.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,21 @@ HRESULT IOleControlSite.LockInPlaceActive(BOOL fLock)
250250
return HRESULT.E_NOTIMPL;
251251
}
252252

253-
HRESULT IOleControlSite.GetExtendedControl(out object ppDisp)
253+
unsafe HRESULT IOleControlSite.GetExtendedControl(IntPtr* ppDisp)
254254
{
255255
Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "in GetExtendedControl " + host.ToString());
256-
ppDisp = host.GetParentContainer().GetProxyForControl(host);
257256
if (ppDisp == null)
257+
{
258+
return HRESULT.E_POINTER;
259+
}
260+
261+
object proxy = host.GetParentContainer().GetProxyForControl(host);
262+
if (proxy == null)
258263
{
259264
return HRESULT.E_NOTIMPL;
260265
}
261266

267+
*ppDisp = Marshal.GetIDispatchForObject(proxy);
262268
return HRESULT.S_OK;
263269
}
264270

@@ -374,11 +380,10 @@ unsafe HRESULT IOleClientSite.GetMoniker(OLEGETMONIKER dwAssign, OLEWHICHMK dwWh
374380
return HRESULT.E_NOTIMPL;
375381
}
376382

377-
HRESULT IOleClientSite.GetContainer(out IOleContainer container)
383+
IOleContainer IOleClientSite.GetContainer()
378384
{
379385
Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "in getContainer");
380-
container = host.GetParentContainer();
381-
return HRESULT.S_OK;
386+
return host.GetParentContainer();
382387
}
383388

384389
unsafe HRESULT IOleClientSite.ShowObject()

src/System.Windows.Forms/src/System/Windows/Forms/Control.AxSourcingSite.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ public object GetService(Type service)
3838
{
3939
if (service == typeof(HtmlDocument))
4040
{
41-
HRESULT hr = _clientSite.GetContainer(out Ole32.IOleContainer iOlecontainer);
42-
if (hr.Succeeded() && iOlecontainer is Mshtml.IHTMLDocument)
41+
if (_clientSite.GetContainer() is Mshtml.IHTMLDocument document)
4342
{
4443
_shimManager ??= new HtmlShimManager();
45-
return new HtmlDocument(_shimManager, iOlecontainer as Mshtml.IHTMLDocument);
44+
return new HtmlDocument(_shimManager, document);
4645
}
4746
}
4847
else if (_clientSite.GetType().IsAssignableFrom(service))

src/System.Windows.Forms/src/System/Windows/Forms/WebBrowserSiteBase.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,22 @@ HRESULT IOleControlSite.LockInPlaceActive(BOOL fLock)
8888
return HRESULT.E_NOTIMPL;
8989
}
9090

91-
HRESULT IOleControlSite.GetExtendedControl(out object ppDisp)
91+
unsafe HRESULT IOleControlSite.GetExtendedControl(IntPtr* ppDisp)
9292
{
93-
ppDisp = null;
93+
if (ppDisp == null)
94+
{
95+
return HRESULT.E_POINTER;
96+
}
97+
98+
*ppDisp = IntPtr.Zero;
9499
return HRESULT.E_NOTIMPL;
95100
}
96101

97102
unsafe HRESULT IOleControlSite.TransformCoords(Point *pPtlHimetric, PointF *pPtfContainer, XFORMCOORDS dwFlags)
98103
{
99104
if (pPtlHimetric == null || pPtfContainer == null)
100105
{
101-
return HRESULT.E_INVALIDARG;
106+
return HRESULT.E_POINTER;
102107
}
103108

104109
if ((dwFlags & XFORMCOORDS.HIMETRICTOCONTAINER) != 0)
@@ -183,10 +188,9 @@ unsafe HRESULT IOleClientSite.GetMoniker(OLEGETMONIKER dwAssign, OLEWHICHMK dwWh
183188
return HRESULT.E_NOTIMPL;
184189
}
185190

186-
HRESULT IOleClientSite.GetContainer(out IOleContainer container)
191+
IOleContainer IOleClientSite.GetContainer()
187192
{
188-
container = Host.GetParentContainer();
189-
return HRESULT.S_OK;
193+
return Host.GetParentContainer();
190194
}
191195

192196
unsafe HRESULT IOleClientSite.ShowObject()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Xunit.Sdk;
6+
7+
namespace System.Windows.Forms.InteropTests
8+
{
9+
public abstract class InteropTestBase
10+
{
11+
public const string NativeTests = "NativeTests";
12+
public const string Success = "Success";
13+
14+
protected static void AssertSuccess(string result)
15+
{
16+
if (result != Success)
17+
{
18+
throw new XunitException(result);
19+
}
20+
}
21+
}
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmake_minimum_required (VERSION 2.6)
2+
project (NativeTests)
3+
set(CMAKE_MACOSX_RPATH 1)
4+
set(CMAKE_CXX_STANDARD 11)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
add_library(NativeTests SHARED
8+
WebBrowserSiteBaseInteropTests.cpp
9+
)
10+
install(TARGETS NativeTests)

0 commit comments

Comments
 (0)