-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Split Variant marshalling tests #53035
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
Merged
AaronRobinsonMSFT
merged 9 commits into
dotnet:main
from
kant2002:kant/split-variant-test
May 30, 2021
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6fa61f1
Rework of variant tests split
kant2002 3306160
Add missing file
kant2002 39d52a5
Fix testing of disabled built-in COM
kant2002 0961092
Address PR feedback
kant2002 c5e050f
Return fetched type
kant2002 8d25983
Fix compilation errors
kant2002 23ca8fa
Fix compilation error
kant2002 05fbfc7
Address PR feedback
kant2002 3409bc5
Fixes to logic
kant2002 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/tests/Interop/PInvoke/Variant/VariantTest.BuiltInCom.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
114 changes: 114 additions & 0 deletions
114
src/tests/Interop/PInvoke/Variant/VariantTest.ComWrappers.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| // 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 = IDispatchVtbl.IID_IDispatch; | ||
| 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 | ||
| { | ||
| internal static readonly Guid IID_IDispatch = new Guid("00020400-0000-0000-C000-000000000046"); | ||
|
|
||
| [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; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.