-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
GenericsTest.IComInterfaceB.cs
46 lines (34 loc) · 2.17 KB
/
GenericsTest.IComInterfaceB.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// 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 Xunit;
unsafe partial class GenericsNative
{
[DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterface")]
[return: MarshalAs(UnmanagedType.Interface)]
public static extern IComInterface<bool> GetIComInterfaceB();
[DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaceOut")]
public static extern void GetIComInterfaceBOut([MarshalAs(UnmanagedType.Interface)] out IComInterface<bool> value);
[DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfacePtr")]
[return: MarshalAs(UnmanagedType.Interface)]
public static extern ref readonly IComInterface<bool> GetIComInterfaceBRef();
[DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaces")]
public static extern void GetIComInterfaceBs([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Interface, SizeParamIndex = 1)] IComInterface<bool>[] pValues, int count);
[DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaces")]
public static extern void GetIComInterfaceBs([MarshalAs(UnmanagedType.Interface)] ref IComInterface<bool> pValues, int count);
}
public unsafe partial class GenericsTest
{
[Fact]
[ActiveIssue("https://github.com/dotnet/runtimelab/issues/177", typeof(TestLibrary.Utilities), nameof(TestLibrary.Utilities.IsNativeAot))]
public static void TestIComInterfaceB()
{
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetIComInterfaceB());
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetIComInterfaceBOut(out GenericsNative.IComInterface<bool> value2));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetIComInterfaceBRef());
GenericsNative.IComInterface<bool>[] values = new GenericsNative.IComInterface<bool>[3];
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetIComInterfaceBs(values, values.Length));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetIComInterfaceBs(ref values[0], values.Length));
}
}