Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial interop testing framework #1932

Merged
merged 1 commit into from
Jul 28, 2020
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
15 changes: 15 additions & 0 deletions Winforms.sln
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.TestUt
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiToolStripTests", "src\System.Windows.Forms\tests\IntegrationTests\MauiTests\MauiToolStripTests\MauiToolStripTests.csproj", "{83634671-CF3A-43B0-B729-42CCBA62DF2C}"
EndProject
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -277,6 +279,18 @@ Global
{83634671-CF3A-43B0-B729-42CCBA62DF2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83634671-CF3A-43B0-B729-42CCBA62DF2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83634671-CF3A-43B0-B729-42CCBA62DF2C}.Release|Any CPU.Build.0 = Release|Any CPU
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Debug|Any CPU.ActiveCfg = Debug|x86
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Debug|Any CPU.Build.0 = Debug|x86
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Release|Any CPU.ActiveCfg = Release|x86
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Release|Any CPU.Build.0 = Release|x86
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm honest, I have no clue if this is the right thing to do

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use "Any CPU"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If your project needs an architecture specific build, then one way to map [[solution configuration]] -> [[project configuration]] is like this.

You'll necessarily need to map x64 somehow, which means that the [[solution configuration]] would need to support x64.

Take a look at Solution and Project Configuration WPF documentation for how I did this there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our solutions is "Any CPU", we don't current have explicit x86/x64 configurations. The tests are then run in x86 and x64 processes.

Copy link
Contributor Author

@hughbe hughbe Jun 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use "Any CPU"?

Yeah we can't do this because we get errors in the cmake build. I did comment earlier for suggestions - I think the thing to do is as @vatsan-madhavan suggested

Would this be as simple as adding

		{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Debug|x86.ActiveCfg = Debug|x86
		{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Debug|x86.Build.0 = Debug|x86
		{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Release|x86.ActiveCfg = Release|x86
		{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Release|x86.Build.0 = Release|x86
		{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Debug|x64.ActiveCfg = Debug|x64
		{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Debug|x64.Build.0 = Debug|x64
		{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Release|x64.ActiveCfg = Release|x64
		{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Release|x64.Build.0 = Release|x64

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't try to edit solution files by hand. Use the configuration editor in Visual Studio to do this for you.

{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Debug|x86.ActiveCfg = Debug|x86
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Debug|x86.Build.0 = Debug|x86
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Release|x86.ActiveCfg = Release|x86
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Release|x86.Build.0 = Release|x86
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Debug|x64.ActiveCfg = Debug|x64
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Debug|x64.Build.0 = Debug|x64
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Release|x64.ActiveCfg = Release|x64
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -321,6 +335,7 @@ Global
{73B0857A-966B-4E7D-8A83-FECFE0281AB9} = {DF68A171-D27B-4E6A-8A7E-63A651622355}
{86418F0B-39DC-4B5A-8145-6D607E6150AC} = {DF68A171-D27B-4E6A-8A7E-63A651622355}
{83634671-CF3A-43B0-B729-42CCBA62DF2C} = {8F20A905-BD37-4D80-B8DF-FA45276FC23F}
{C272DA06-B98D-4BB7-B1C4-ECF58F54B224} = {583F1292-AE8D-4511-B8D8-A81FE4642DDC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7B1B0433-F612-4E5A-BE7E-FCF5B9F6E136}
Expand Down
3 changes: 3 additions & 0 deletions eng/configure-toolset.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
$script:DoNotAbortNativeToolsInstallationOnFailure = $true
$script:DoNotDisplayNativeToolsInstallationWarnings = $true

# Add CMake to path.
$env:PATH = "$PSScriptRoot\..\.tools\bin;$env:PATH"
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"Microsoft.NET.Sdk.IL": "5.0.0-rc.1.20371.13"
},
"native-tools": {
"cmake": "3.14.2",
"cmake": "3.17.3",
"dotnet-api-docs_netcoreapp3.0": "0.0.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ HRESULT GetMoniker(
Ole32.OLEWHICHMK dwWhichMoniker,
IntPtr* ppmk);

[PreserveSig]
HRESULT GetContainer(
out IOleContainer container);
IOleContainer GetContainer();

[PreserveSig]
HRESULT ShowObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ HRESULT LockInPlaceActive(

[PreserveSig]
HRESULT GetExtendedControl(
[MarshalAs(UnmanagedType.IDispatch)] out object ppDisp);
IntPtr* ppDisp);

[PreserveSig]
HRESULT TransformCoords(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,21 @@ HRESULT IOleControlSite.LockInPlaceActive(BOOL fLock)
return HRESULT.E_NOTIMPL;
}

HRESULT IOleControlSite.GetExtendedControl(out object ppDisp)
unsafe HRESULT IOleControlSite.GetExtendedControl(IntPtr* ppDisp)
{
Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "in GetExtendedControl " + host.ToString());
ppDisp = host.GetParentContainer().GetProxyForControl(host);
if (ppDisp == null)
{
return HRESULT.E_POINTER;
}

object proxy = host.GetParentContainer().GetProxyForControl(host);
if (proxy == null)
{
return HRESULT.E_NOTIMPL;
}

*ppDisp = Marshal.GetIDispatchForObject(proxy);
return HRESULT.S_OK;
}

Expand Down Expand Up @@ -374,11 +380,10 @@ unsafe HRESULT IOleClientSite.GetMoniker(OLEGETMONIKER dwAssign, OLEWHICHMK dwWh
return HRESULT.E_NOTIMPL;
}

HRESULT IOleClientSite.GetContainer(out IOleContainer container)
IOleContainer IOleClientSite.GetContainer()
{
Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "in getContainer");
container = host.GetParentContainer();
return HRESULT.S_OK;
return host.GetParentContainer();
}

unsafe HRESULT IOleClientSite.ShowObject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ public object GetService(Type service)
{
if (service == typeof(HtmlDocument))
{
HRESULT hr = _clientSite.GetContainer(out Ole32.IOleContainer iOlecontainer);
if (hr.Succeeded() && iOlecontainer is Mshtml.IHTMLDocument)
if (_clientSite.GetContainer() is Mshtml.IHTMLDocument document)
{
_shimManager ??= new HtmlShimManager();
return new HtmlDocument(_shimManager, iOlecontainer as Mshtml.IHTMLDocument);
return new HtmlDocument(_shimManager, document);
}
}
else if (_clientSite.GetType().IsAssignableFrom(service))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,22 @@ HRESULT IOleControlSite.LockInPlaceActive(BOOL fLock)
return HRESULT.E_NOTIMPL;
}

HRESULT IOleControlSite.GetExtendedControl(out object ppDisp)
unsafe HRESULT IOleControlSite.GetExtendedControl(IntPtr* ppDisp)
{
ppDisp = null;
if (ppDisp == null)
{
return HRESULT.E_POINTER;
}

*ppDisp = IntPtr.Zero;
return HRESULT.E_NOTIMPL;
}

unsafe HRESULT IOleControlSite.TransformCoords(Point *pPtlHimetric, PointF *pPtfContainer, XFORMCOORDS dwFlags)
{
if (pPtlHimetric == null || pPtfContainer == null)
{
return HRESULT.E_INVALIDARG;
return HRESULT.E_POINTER;
}

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

HRESULT IOleClientSite.GetContainer(out IOleContainer container)
IOleContainer IOleClientSite.GetContainer()
{
container = Host.GetParentContainer();
return HRESULT.S_OK;
return Host.GetParentContainer();
}

unsafe HRESULT IOleClientSite.ShowObject()
Expand Down
22 changes: 22 additions & 0 deletions src/System.Windows.Forms/tests/InteropTests/InteropTestBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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 Xunit.Sdk;

namespace System.Windows.Forms.InteropTests
{
public abstract class InteropTestBase
{
public const string NativeTests = "NativeTests";
public const string Success = "Success";

protected static void AssertSuccess(string result)
{
if (result != Success)
{
throw new XunitException(result);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required (VERSION 2.6)
project (NativeTests)
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_library(NativeTests SHARED
WebBrowserSiteBaseInteropTests.cpp
)
install(TARGETS NativeTests)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.DotNet.CMake.Sdk">
<PropertyGroup>
<CMakeLists>CMakeLists.txt</CMakeLists>
</PropertyGroup>
</Project>
Loading