-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
GenericsTest.Point2C.cs
54 lines (40 loc) · 1.99 KB
/
GenericsTest.Point2C.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
47
48
49
50
51
52
53
54
// 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))]
public static extern Point2<char> GetPoint2C(char e00, char e01);
[DllImport(nameof(GenericsNative))]
public static extern void GetPoint2COut(char e00, char e01, out Point2<char> value);
[DllImport(nameof(GenericsNative), EntryPoint = "GetPoint2CPtr")]
public static extern ref readonly Point2<char> GetPoint2CRef(char e00, char e01);
[DllImport(nameof(GenericsNative))]
public static extern Point2<char> AddPoint2C(Point2<char> lhs, Point2<char> rhs);
[DllImport(nameof(GenericsNative))]
public static extern Point2<char> AddPoint2Cs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point2<char>[] pValues, int count);
[DllImport(nameof(GenericsNative))]
public static extern Point2<char> AddPoint2Cs(in Point2<char> pValues, int count);
}
public unsafe partial class GenericsTest
{
[Fact]
public static void TestPoint2C()
{
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetPoint2C('1', '2'));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetPoint2COut('1', '2', out GenericsNative.Point2<char> value3));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetPoint2CRef('1', '2'));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddPoint2C(default, default));
GenericsNative.Point2<char>[] values = new GenericsNative.Point2<char>[] {
default,
default,
default,
default,
default
};
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddPoint2Cs(values, values.Length));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddPoint2Cs(in values[0], values.Length));
}
}