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

qa: Add C++/CLI Acceptance tests #299

Merged
merged 13 commits into from
Nov 20, 2024
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
4 changes: 4 additions & 0 deletions .github/workflows/example-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
path: outproc
- name: 32 Bit
path: 32bit
- name: C++/CLI
path: cppcli

steps:
- uses: actions/checkout@v3
Expand All @@ -37,6 +39,8 @@ jobs:
- name: Build
run: dotnet build -c Release

- uses: ilammy/msvc-dev-cmd@v1

- name: Run ${{ matrix.test_suite.Name }} Acceptance test
run: .\msbuild-acceptance-test.cmd
working-directory: .\examples\${{ matrix.test_suite.path }}\scripts
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ Depending on whether you want to process 32bit or 64bit assemblies, you need to
> To prevent this it is **recommended that the assembly is compiled as a 32 bit assembly** and not as an AnyCPU assembly.
> see: <https://github.com/dotnet/runtime/issues/32493>

> Warning!
> In order to use 32 bit support with the build targets, the x86 version of .NET must be installed, as dscom requests the hostfxr.dll to be loaded.

## Migration notes (mscorelib vs System.Private.CoreLib)

Both assemblies are **ComVisible=false** but lot of .NET Framework types are **ComVisible=true**.
Expand Down
2 changes: 2 additions & 0 deletions examples/32bit/scripts/msbuild-acceptance-test.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ dotnet pack src\dscom.build\dscom.build.csproj -p:Configuration=Release

IF NOT EXIST %root%\_packages MKDIR _packages

XCOPY /Y /I /C /F .\src\dscom\bin\x64\Release\*.nupkg _packages\
XCOPY /Y /I /C /F .\src\dscom.build\bin\x64\Release\*.nupkg _packages\
XCOPY /Y /I /C /F .\src\dscom\bin\Release\*.nupkg _packages\
XCOPY /Y /I /C /F .\src\dscom.build\bin\Release\*.nupkg _packages\

Expand Down
48 changes: 48 additions & 0 deletions examples/cppcli/CppCli.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35506.116 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CppLibrary", "CppLibrary\CppLibrary.vcxproj", "{4E2EE544-4FD0-4790-A6D7-D6A75F84F902}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsLibrary", "CsLibrary\CsLibrary.csproj", "{87C7349D-418E-47D7-9BBC-C995D008F333}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4E2EE544-4FD0-4790-A6D7-D6A75F84F902}.Debug|Any CPU.ActiveCfg = Debug|x64
{4E2EE544-4FD0-4790-A6D7-D6A75F84F902}.Debug|Any CPU.Build.0 = Debug|x64
{4E2EE544-4FD0-4790-A6D7-D6A75F84F902}.Debug|x64.ActiveCfg = Debug|x64
{4E2EE544-4FD0-4790-A6D7-D6A75F84F902}.Debug|x64.Build.0 = Debug|x64
{4E2EE544-4FD0-4790-A6D7-D6A75F84F902}.Debug|x86.ActiveCfg = Debug|Win32
{4E2EE544-4FD0-4790-A6D7-D6A75F84F902}.Debug|x86.Build.0 = Debug|Win32
{4E2EE544-4FD0-4790-A6D7-D6A75F84F902}.Release|Any CPU.ActiveCfg = Release|x64
{4E2EE544-4FD0-4790-A6D7-D6A75F84F902}.Release|Any CPU.Build.0 = Release|x64
{4E2EE544-4FD0-4790-A6D7-D6A75F84F902}.Release|x64.ActiveCfg = Release|x64
{4E2EE544-4FD0-4790-A6D7-D6A75F84F902}.Release|x64.Build.0 = Release|x64
{4E2EE544-4FD0-4790-A6D7-D6A75F84F902}.Release|x86.ActiveCfg = Release|Win32
{4E2EE544-4FD0-4790-A6D7-D6A75F84F902}.Release|x86.Build.0 = Release|Win32
{87C7349D-418E-47D7-9BBC-C995D008F333}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{87C7349D-418E-47D7-9BBC-C995D008F333}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87C7349D-418E-47D7-9BBC-C995D008F333}.Debug|x64.ActiveCfg = Debug|Any CPU
{87C7349D-418E-47D7-9BBC-C995D008F333}.Debug|x64.Build.0 = Debug|Any CPU
{87C7349D-418E-47D7-9BBC-C995D008F333}.Debug|x86.ActiveCfg = Debug|Any CPU
{87C7349D-418E-47D7-9BBC-C995D008F333}.Debug|x86.Build.0 = Debug|Any CPU
{87C7349D-418E-47D7-9BBC-C995D008F333}.Release|Any CPU.ActiveCfg = Release|Any CPU
{87C7349D-418E-47D7-9BBC-C995D008F333}.Release|Any CPU.Build.0 = Release|Any CPU
{87C7349D-418E-47D7-9BBC-C995D008F333}.Release|x64.ActiveCfg = Release|Any CPU
{87C7349D-418E-47D7-9BBC-C995D008F333}.Release|x64.Build.0 = Release|Any CPU
{87C7349D-418E-47D7-9BBC-C995D008F333}.Release|x86.ActiveCfg = Release|Any CPU
{87C7349D-418E-47D7-9BBC-C995D008F333}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
123 changes: 123 additions & 0 deletions examples/cppcli/CppLibrary/CppLibrary.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<EnableManagedPackageReferenceSupport>true</EnableManagedPackageReferenceSupport>
<ProjectGuid>{4E2EE544-4FD0-4790-A6D7-D6A75F84F902}</ProjectGuid>
<Keyword>NetCoreCProj</Keyword>
<RootNamespace>CppLibrary</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CLRSupport>NetCore</CLRSupport>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CLRSupport>NetCore</CLRSupport>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CLRSupport>NetCore</CLRSupport>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CLRSupport>NetCore</CLRSupport>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies />
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies />
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies />
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies />
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="MyCppClass.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="MyCppClass.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
27 changes: 27 additions & 0 deletions examples/cppcli/CppLibrary/CppLibrary.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="MyCppClass.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="MyCppClass.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions examples/cppcli/CppLibrary/MyCppClass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "MyCppClass.h"
namespace CppNs {
int MyCppClass::Add(int a, int b)
{
return a + b;
}
}
8 changes: 8 additions & 0 deletions examples/cppcli/CppLibrary/MyCppClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once
namespace CppNs {
public ref class MyCppClass
{
public:
int Add(int a, int b);
};
}
2 changes: 2 additions & 0 deletions examples/cppcli/CppLibrary/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<packages />
15 changes: 15 additions & 0 deletions examples/cppcli/CsLibrary/CsLibrary.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0-windows</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableComHosting>True</EnableComHosting>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>

<ItemGroup Condition="'$(PerformAcceptanceTest)' == 'Runtime'">
<ProjectReference Include="..\CppLibrary\CppLibrary.vcxproj" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions examples/cppcli/CsLibrary/MyCsClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Runtime.InteropServices;

namespace CsNs
{
[ComVisible(true)]
[Guid("4468308A-1E42-4CE2-8BC0-4F6AFA1951E0")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IComClass
{
int Add(int a, int b);
};

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[Guid("6610DBEC-DD26-416B-BF94-A5D0C7192F6C")]
public class MyCsClass : CppNs.MyCppClass, IComClass
{
}
}
75 changes: 75 additions & 0 deletions examples/cppcli/scripts/msbuild-acceptance-test.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
@ECHO off

REM Run this script from VsDevCmd

SET root=%~dp0\..\..\..\

PUSHD %root%
dotnet build-server shutdown

dotnet pack src\dscom.build\dscom.build.csproj -p:Configuration=Release

IF NOT EXIST %root%\_packages MKDIR _packages

XCOPY /Y /I /C /F .\src\dscom\bin\x64\Release\*.nupkg _packages\
XCOPY /Y /I /C /F .\src\dscom.build\bin\x64\Release\*.nupkg _packages\
XCOPY /Y /I /C /F .\src\dscom\bin\Release\*.nupkg _packages\
XCOPY /Y /I /C /F .\src\dscom.build\bin\Release\*.nupkg _packages\

dotnet build-server shutdown

dotnet nuget locals global-packages --clear

POPD

PUSHD %~dp0\..\CppLibrary

msbuild -nodeReuse:False -t:Clean -p:Configuration=Release -p:PerformAcceptanceTest=Runtime
nuget restore -SolutionDirectory ..

POPD

PUSHD %~dp0\..\CsLibrary

msbuild -nodeReuse:False -t:Clean -p:Configuration=Release -p:PerformAcceptanceTest=Runtime -p:SkipResolvePackageAssets=true

dotnet build-server shutdown

dotnet add CsLibrary.csproj package --prerelease -s %root%\_packages dSPACE.Runtime.InteropServices.BuildTasks

dotnet build-server shutdown

msbuild -nodeReuse:False -t:Restore -p:Configuration=Release -p:Platform=x64 -p:TargetPlatform=net8.0-windows -p:PerformAcceptanceTest=Runtime -p:SkipResolvePackageAssets=true

dotnet build-server shutdown

msbuild -nodeReuse:False -t:Build -p:Configuration=Release -p:Platform=x64 -p:TargetPlatform=net8.0-windows -p:PerformAcceptanceTest=Runtime -bl:%~dp0\net80x86.binlog
SET ERRUNTIMEX64_NET80=%ERRORLEVEL%

msbuild -nodeReuse:False -t:Clean -p:Configuration=Release -p:Platform=x64 -p:TargetPlatform=net8.0-windows -p:PerformAcceptanceTest=Runtime ..\CppLibrary\CppLibrary.vcxproj

dotnet build-server shutdown

dotnet remove CsLibrary.csproj package dSPACE.Runtime.InteropServices.BuildTasks

POPD

SetLocal EnableDelayedExpansion

SET EXITCODE=0

IF NOT "%ERRUNTIMEX64_NET80%" == "0" (
SET EXITCODE=1
ECHO "::warning::Runtime specific acceptance test for platform x64 using .NET 8.0 failed."
)

IF NOT EXIST %~dp0\..\CsLibrary\bin\x64\Release\net8.0-windows\CsLibrary.tlb (
::SET EXITCODE=1
ECHO "::warning::Could not find exported TLB file for .NET 8 (x64)"
)

IF "%EXITCODE%" == "0" (
ECHO "Acceptance test completed successfully."
)

EXIT /B %EXITCODE%
2 changes: 2 additions & 0 deletions examples/outproc/scripts/msbuild-acceptance-test.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ dotnet pack -p:Configuration=Release

IF NOT EXIST %root%\_packages MKDIR _packages

XCOPY /Y /I /C /F .\src\dscom\bin\x64\Release\*.nupkg _packages\
XCOPY /Y /I /C /F .\src\dscom.build\bin\x64\Release\*.nupkg _packages\
XCOPY /Y /I /C /F .\src\dscom\bin\Release\*.nupkg _packages\
XCOPY /Y /I /C /F .\src\dscom.build\bin\Release\*.nupkg _packages\

Expand Down
Loading