-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
GenericsTest.Point3L.cs
99 lines (79 loc) · 3.69 KB
/
GenericsTest.Point3L.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// 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 Point3<long> GetPoint3L(long e00, long e01, long e02);
[DllImport(nameof(GenericsNative))]
public static extern void GetPoint3LOut(long e00, long e01, long e02, Point3<long>* value);
[DllImport(nameof(GenericsNative))]
public static extern void GetPoint3LOut(long e00, long e01, long e02, out Point3<long> value);
[DllImport(nameof(GenericsNative))]
public static extern Point3<long>* GetPoint3LPtr(long e00, long e01, long e02);
[DllImport(nameof(GenericsNative), EntryPoint = "GetPoint3LPtr")]
public static extern ref readonly Point3<long> GetPoint3LRef(long e00, long e01, long e02);
[DllImport(nameof(GenericsNative))]
public static extern Point3<long> AddPoint3L(Point3<long> lhs, Point3<long> rhs);
[DllImport(nameof(GenericsNative))]
public static extern Point3<long> AddPoint3Ls(Point3<long>* pValues, int count);
[DllImport(nameof(GenericsNative))]
public static extern Point3<long> AddPoint3Ls([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point3<long>[] pValues, int count);
[DllImport(nameof(GenericsNative))]
public static extern Point3<long> AddPoint3Ls(in Point3<long> pValues, int count);
}
unsafe partial class GenericsTest
{
private static void TestPoint3L()
{
GenericsNative.Point3<long> value = GenericsNative.GetPoint3L(1L, 2L, 3L);
Assert.Equal(value.e00, 1L);
Assert.Equal(value.e01, 2L);
Assert.Equal(value.e02, 3L);
GenericsNative.Point3<long> value2;
GenericsNative.GetPoint3LOut(1L, 2L, 3L, &value2);
Assert.Equal(value2.e00, 1L);
Assert.Equal(value2.e01, 2L);
Assert.Equal(value2.e02, 3L);
GenericsNative.GetPoint3LOut(1L, 2L, 3L, out GenericsNative.Point3<long> value3);
Assert.Equal(value3.e00, 1L);
Assert.Equal(value3.e01, 2L);
Assert.Equal(value3.e02, 3L);
GenericsNative.Point3<long>* value4 = GenericsNative.GetPoint3LPtr(1L, 2L, 3L);
Assert.Equal(value4->e00, 1L);
Assert.Equal(value4->e01, 2L);
Assert.Equal(value4->e02, 3L);
ref readonly GenericsNative.Point3<long> value5 = ref GenericsNative.GetPoint3LRef(1L, 2L, 3L);
Assert.Equal(value5.e00, 1L);
Assert.Equal(value5.e01, 2L);
Assert.Equal(value5.e02, 3L);
GenericsNative.Point3<long> result = GenericsNative.AddPoint3L(value, value);
Assert.Equal(result.e00, 2L);
Assert.Equal(result.e01, 4L);
Assert.Equal(result.e02, 6l);
GenericsNative.Point3<long>[] values = new GenericsNative.Point3<long>[] {
value,
value2,
value3,
*value4,
value5
};
fixed (GenericsNative.Point3<long>* pValues = &values[0])
{
GenericsNative.Point3<long> result2 = GenericsNative.AddPoint3Ls(pValues, values.Length);
Assert.Equal(result2.e00, 5l);
Assert.Equal(result2.e01, 10l);
Assert.Equal(result2.e02, 15l);
}
GenericsNative.Point3<long> result3 = GenericsNative.AddPoint3Ls(values, values.Length);
Assert.Equal(result3.e00, 5l);
Assert.Equal(result3.e01, 10l);
Assert.Equal(result3.e02, 15l);
GenericsNative.Point3<long> result4 = GenericsNative.AddPoint3Ls(in values[0], values.Length);
Assert.Equal(result4.e00, 5l);
Assert.Equal(result4.e01, 10l);
Assert.Equal(result4.e02, 15l);
}
}