-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
GenericsTest.ReadOnlySpanD.cs
43 lines (32 loc) · 1.73 KB
/
GenericsTest.ReadOnlySpanD.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
// 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 = "GetSpanD")]
public static extern ReadOnlySpan<double> GetReadOnlySpanD(double e00);
[DllImport(nameof(GenericsNative), EntryPoint = "GetSpanDOut")]
public static extern void GetReadOnlySpanDOut(double e00, out ReadOnlySpan<double> value);
[DllImport(nameof(GenericsNative), EntryPoint = "GetSpanDPtr")]
public static extern ref readonly ReadOnlySpan<double> GetReadOnlySpanDRef(double e00);
[DllImport(nameof(GenericsNative), EntryPoint = "AddSpanD")]
public static extern ReadOnlySpan<double> AddReadOnlySpanD(ReadOnlySpan<double> lhs, ReadOnlySpan<double> rhs);
[DllImport(nameof(GenericsNative), EntryPoint = "AddSpanDs")]
public static extern ReadOnlySpan<double> AddReadOnlySpanDs(in ReadOnlySpan<double> pValues, int count);
}
unsafe partial class GenericsTest
{
private static void TestReadOnlySpanD()
{
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetReadOnlySpanD(1.0));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetReadOnlySpanDOut(1.0, out ReadOnlySpan<double> value3));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetReadOnlySpanDRef(1.0));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddReadOnlySpanD(default, default));
Assert.Throws<MarshalDirectiveException>(() => {
ReadOnlySpan<double> value = default;
GenericsNative.AddReadOnlySpanDs(in value, 1);
});
}
}