Skip to content

Commit 059fad6

Browse files
committed
Add test for dynamic keyword with managed COM server
1 parent 344204e commit 059fad6

File tree

5 files changed

+83
-2
lines changed

5 files changed

+83
-2
lines changed

src/tests/Interop/COM/Dynamic/App.manifest

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
33
<assemblyIdentity
4-
type="win32"
4+
type="win32"
55
name="COMDynamicTest"
66
version="1.0.0.0" />
77

88
<dependency>
99
<dependentAssembly>
10-
<!-- RegFree COM -->
10+
<!-- RegFree COM to activate managed server -->
11+
<assemblyIdentity
12+
type="win32"
13+
name="CoreShim.X"
14+
version="1.0.0.0"/>
15+
</dependentAssembly>
16+
</dependency>
17+
<dependency>
18+
<dependentAssembly>
19+
<!-- RegFree COM to activate native server-->
1120
<assemblyIdentity
1221
type="win32"
1322
name="DynamicTestServer.X"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
3+
4+
<assemblyIdentity
5+
type="win32"
6+
name="CoreShim.X"
7+
version="1.0.0.0" />
8+
9+
<file name="CoreShim.dll">
10+
<!-- ConsumeNETServerTesting -->
11+
<comClass
12+
clsid="{DE4ACF53-5957-4D31-8BE2-EA6C80683246}"
13+
threadingModel="Both" />
14+
</file>
15+
16+
</assembly>

src/tests/Interop/COM/Dynamic/Dynamic.csproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<OutputType>Exe</OutputType>
44
<ApplicationManifest>App.manifest</ApplicationManifest>
55
<IsManagedCOMClient>true</IsManagedCOMClient>
6+
<UseManagedCOMServer>true</UseManagedCOMServer>
67
<!-- This test is very slow under some GCStress variations, especially with COMPlus_HeapVerify=1, so disable it under GCStress to avoid test timeouts in the CI.
78
Issue: https://github.com/dotnet/runtime/issues/39584
89
-->
@@ -13,11 +14,23 @@
1314
<Compile Include="CollectionTest.cs" />
1415
<Compile Include="EventTest.cs" />
1516
<Compile Include="ParametersTest.cs" />
17+
<Compile Include="NETServerTest.cs" />
1618
<Compile Include="Program.cs" />
1719
<Compile Include="ServerGuids.cs" />
20+
<Compile Include="../ServerContracts/ServerGuids.cs" />
21+
</ItemGroup>
22+
<ItemGroup>
23+
<None Include="CoreShim.X.manifest">
24+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
25+
</None>
1826
</ItemGroup>
1927
<ItemGroup>
2028
<ProjectReference Include="Server/CMakeLists.txt" />
2129
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
30+
<ProjectReference Include="../NETServer/NETServer.csproj">
31+
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
32+
<OutputItemType>Content</OutputItemType>
33+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
34+
</ProjectReference>
2235
</ItemGroup>
2336
</Project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
4+
namespace Dynamic
5+
{
6+
using System;
7+
using System.Runtime.InteropServices;
8+
using TestLibrary;
9+
10+
internal class NETServerTest
11+
{
12+
public void Run()
13+
{
14+
Console.WriteLine($"Running {nameof(NETServerTest)}");
15+
16+
// Initialize CoreShim and hostpolicymock
17+
HostPolicyMock.Initialize(Environment.CurrentDirectory, null);
18+
Environment.SetEnvironmentVariable("CORESHIM_COMACT_ASSEMBLYNAME", "NETServer");
19+
Environment.SetEnvironmentVariable("CORESHIM_COMACT_TYPENAME", "ConsumeNETServerTesting");
20+
21+
using (HostPolicyMock.Mock_corehost_resolve_component_dependencies(
22+
0,
23+
string.Empty,
24+
string.Empty,
25+
string.Empty))
26+
{
27+
Type t = Type.GetTypeFromCLSID(Guid.Parse(Server.Contract.Guids.ConsumeNETServerTesting));
28+
dynamic obj = Activator.CreateInstance(t);
29+
30+
try
31+
{
32+
Assert.IsTrue(obj.EqualByCCW(obj));
33+
Assert.IsTrue(obj.NotEqualByRCW(obj));
34+
}
35+
finally
36+
{
37+
obj.ReleaseResources();
38+
}
39+
}
40+
}
41+
}
42+
}

src/tests/Interop/COM/Dynamic/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ static int Main(string[] doNotUse)
2222
new CollectionTest().Run();
2323
new EventTest().Run();
2424
new ParametersTest().Run();
25+
new NETServerTest().Run();
2526
}
2627
catch (Exception e)
2728
{

0 commit comments

Comments
 (0)