Skip to content

Commit 6fa61f1

Browse files
committed
Rework of variant tests split
1 parent 6854225 commit 6fa61f1

File tree

6 files changed

+274
-93
lines changed

6 files changed

+274
-93
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
using System;
5+
using System.Runtime.InteropServices;
6+
using TestLibrary;
7+
using static VariantNative;
8+
9+
#pragma warning disable CS0612, CS0618
10+
partial class Test
11+
{
12+
public static int Main()
13+
{
14+
bool builtInComDisabled=false;
15+
var comConfig = AppContext.GetData("System.Runtime.InteropServices.BuiltInComInterop.IsSupported");
16+
if(comConfig != null && !bool.Parse(comConfig.ToString()))
17+
{
18+
builtInComDisabled=true;
19+
}
20+
21+
Console.WriteLine($"Built-in COM Disabled?: {builtInComDisabled}");
22+
try
23+
{
24+
TestByValue(builtInComDisabled);
25+
TestByRef(builtInComDisabled);
26+
TestOut();
27+
TestFieldByValue(builtInComDisabled);
28+
TestFieldByRef(builtInComDisabled);
29+
}
30+
catch (Exception e)
31+
{
32+
Console.WriteLine($"Test failed: {e}");
33+
return 101;
34+
}
35+
return 100;
36+
}
37+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
using System;
5+
using System.Collections;
6+
using System.Runtime.CompilerServices;
7+
using System.Runtime.InteropServices;
8+
using TestLibrary;
9+
using static VariantNative;
10+
using ComTypes = System.Runtime.InteropServices.ComTypes;
11+
12+
#pragma warning disable CS0612, CS0618
13+
partial class Test
14+
{
15+
public static int Main()
16+
{
17+
bool testComMarshal=true;
18+
ComWrappers.RegisterForMarshalling(new ComWrappersImpl());
19+
try
20+
{
21+
TestByValue(testComMarshal);
22+
TestByRef(testComMarshal);
23+
TestOut();
24+
TestFieldByValue(testComMarshal);
25+
TestFieldByRef(testComMarshal);
26+
}
27+
catch (Exception e)
28+
{
29+
Console.WriteLine($"Test failed: {e}");
30+
return 101;
31+
}
32+
return 100;
33+
}
34+
}
35+
36+
internal unsafe class ComWrappersImpl : ComWrappers
37+
{
38+
private static readonly ComInterfaceEntry* wrapperEntry;
39+
40+
static ComWrappersImpl()
41+
{
42+
var vtblRaw = (IntPtr*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IDispatchVtbl), sizeof(IntPtr) * 7);
43+
GetIUnknownImpl(out vtblRaw[0], out vtblRaw[1], out vtblRaw[2]);
44+
45+
vtblRaw[3] = (IntPtr)(delegate* unmanaged<IntPtr, IntPtr, int>)&IDispatchVtbl.GetTypeInfoCountInternal;
46+
vtblRaw[4] = (IntPtr)(delegate* unmanaged<IntPtr, int, int, IntPtr, int>)&IDispatchVtbl.GetTypeInfoInternal;
47+
vtblRaw[5] = (IntPtr)(delegate* unmanaged<IntPtr, IntPtr, IntPtr, int, int, IntPtr, int>)&IDispatchVtbl.GetIDsOfNamesInternal;
48+
vtblRaw[6] = (IntPtr)(delegate* unmanaged<IntPtr, int, IntPtr, int, ComTypes.INVOKEKIND, IntPtr, IntPtr, IntPtr, IntPtr, int>)&IDispatchVtbl.InvokeInternal;
49+
50+
wrapperEntry = (ComInterfaceEntry*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IDispatchVtbl), sizeof(ComInterfaceEntry));
51+
wrapperEntry->IID = new Guid("00020400-0000-0000-C000-000000000046");
52+
wrapperEntry->Vtable = (IntPtr)vtblRaw;
53+
}
54+
55+
protected override unsafe ComInterfaceEntry* ComputeVtables(object obj, CreateComInterfaceFlags flags, out int count)
56+
{
57+
// Always return the same table mappings.
58+
count = 1;
59+
return wrapperEntry;
60+
}
61+
62+
protected override object CreateObject(IntPtr externalComObject, CreateObjectFlags flags)
63+
{
64+
throw new NotImplementedException();
65+
}
66+
67+
protected override void ReleaseObjects(IEnumerable objects)
68+
{
69+
throw new NotImplementedException();
70+
}
71+
}
72+
public struct IDispatchVtbl
73+
{
74+
[UnmanagedCallersOnly]
75+
public static int GetTypeInfoCountInternal(IntPtr thisPtr, IntPtr i)
76+
{
77+
return 0; // S_OK;
78+
}
79+
80+
[UnmanagedCallersOnly]
81+
public static int GetTypeInfoInternal(IntPtr thisPtr, int itinfo, int lcid, IntPtr i)
82+
{
83+
return 0; // S_OK;
84+
}
85+
86+
[UnmanagedCallersOnly]
87+
public static int GetIDsOfNamesInternal(
88+
IntPtr thisPtr,
89+
IntPtr iid,
90+
IntPtr names,
91+
int namesCount,
92+
int lcid,
93+
IntPtr dispIds)
94+
{
95+
return 0; // S_OK;
96+
}
97+
98+
[UnmanagedCallersOnly]
99+
public static int InvokeInternal(
100+
IntPtr thisPtr,
101+
int dispIdMember,
102+
IntPtr riid,
103+
int lcid,
104+
ComTypes.INVOKEKIND wFlags,
105+
IntPtr pDispParams,
106+
IntPtr VarResult,
107+
IntPtr pExcepInfo,
108+
IntPtr puArgErr)
109+
{
110+
return 0; // S_OK;
111+
}
112+
}

0 commit comments

Comments
 (0)