Skip to content

Commit

Permalink
Rework of variant tests split
Browse files Browse the repository at this point in the history
  • Loading branch information
kant2002 committed May 21, 2021
1 parent 6854225 commit 6fa61f1
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 93 deletions.
37 changes: 37 additions & 0 deletions src/tests/Interop/PInvoke/Variant/VariantTest.BuiltInCom.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.InteropServices;
using TestLibrary;
using static VariantNative;

#pragma warning disable CS0612, CS0618
partial class Test
{
public static int Main()
{
bool builtInComDisabled=false;
var comConfig = AppContext.GetData("System.Runtime.InteropServices.BuiltInComInterop.IsSupported");
if(comConfig != null && !bool.Parse(comConfig.ToString()))
{
builtInComDisabled=true;
}

Console.WriteLine($"Built-in COM Disabled?: {builtInComDisabled}");
try
{
TestByValue(builtInComDisabled);
TestByRef(builtInComDisabled);
TestOut();
TestFieldByValue(builtInComDisabled);
TestFieldByRef(builtInComDisabled);
}
catch (Exception e)
{
Console.WriteLine($"Test failed: {e}");
return 101;
}
return 100;
}
}
112 changes: 112 additions & 0 deletions src/tests/Interop/PInvoke/Variant/VariantTest.ComWrappers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using TestLibrary;
using static VariantNative;
using ComTypes = System.Runtime.InteropServices.ComTypes;

#pragma warning disable CS0612, CS0618
partial class Test
{
public static int Main()
{
bool testComMarshal=true;
ComWrappers.RegisterForMarshalling(new ComWrappersImpl());
try
{
TestByValue(testComMarshal);
TestByRef(testComMarshal);
TestOut();
TestFieldByValue(testComMarshal);
TestFieldByRef(testComMarshal);
}
catch (Exception e)
{
Console.WriteLine($"Test failed: {e}");
return 101;
}
return 100;
}
}

internal unsafe class ComWrappersImpl : ComWrappers
{
private static readonly ComInterfaceEntry* wrapperEntry;

static ComWrappersImpl()
{
var vtblRaw = (IntPtr*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IDispatchVtbl), sizeof(IntPtr) * 7);
GetIUnknownImpl(out vtblRaw[0], out vtblRaw[1], out vtblRaw[2]);

vtblRaw[3] = (IntPtr)(delegate* unmanaged<IntPtr, IntPtr, int>)&IDispatchVtbl.GetTypeInfoCountInternal;
vtblRaw[4] = (IntPtr)(delegate* unmanaged<IntPtr, int, int, IntPtr, int>)&IDispatchVtbl.GetTypeInfoInternal;
vtblRaw[5] = (IntPtr)(delegate* unmanaged<IntPtr, IntPtr, IntPtr, int, int, IntPtr, int>)&IDispatchVtbl.GetIDsOfNamesInternal;
vtblRaw[6] = (IntPtr)(delegate* unmanaged<IntPtr, int, IntPtr, int, ComTypes.INVOKEKIND, IntPtr, IntPtr, IntPtr, IntPtr, int>)&IDispatchVtbl.InvokeInternal;

wrapperEntry = (ComInterfaceEntry*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IDispatchVtbl), sizeof(ComInterfaceEntry));
wrapperEntry->IID = new Guid("00020400-0000-0000-C000-000000000046");
wrapperEntry->Vtable = (IntPtr)vtblRaw;
}

protected override unsafe ComInterfaceEntry* ComputeVtables(object obj, CreateComInterfaceFlags flags, out int count)
{
// Always return the same table mappings.
count = 1;
return wrapperEntry;
}

protected override object CreateObject(IntPtr externalComObject, CreateObjectFlags flags)
{
throw new NotImplementedException();
}

protected override void ReleaseObjects(IEnumerable objects)
{
throw new NotImplementedException();
}
}
public struct IDispatchVtbl
{
[UnmanagedCallersOnly]
public static int GetTypeInfoCountInternal(IntPtr thisPtr, IntPtr i)
{
return 0; // S_OK;
}

[UnmanagedCallersOnly]
public static int GetTypeInfoInternal(IntPtr thisPtr, int itinfo, int lcid, IntPtr i)
{
return 0; // S_OK;
}

[UnmanagedCallersOnly]
public static int GetIDsOfNamesInternal(
IntPtr thisPtr,
IntPtr iid,
IntPtr names,
int namesCount,
int lcid,
IntPtr dispIds)
{
return 0; // S_OK;
}

[UnmanagedCallersOnly]
public static int InvokeInternal(
IntPtr thisPtr,
int dispIdMember,
IntPtr riid,
int lcid,
ComTypes.INVOKEKIND wFlags,
IntPtr pDispParams,
IntPtr VarResult,
IntPtr pExcepInfo,
IntPtr puArgErr)
{
return 0; // S_OK;
}
}
Loading

0 comments on commit 6fa61f1

Please sign in to comment.