-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
GenericsTest.ReadOnlySpanF.cs
43 lines (32 loc) · 1.72 KB
/
GenericsTest.ReadOnlySpanF.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 = "GetSpanF")]
public static extern ReadOnlySpan<float> GetReadOnlySpanF(float e00);
[DllImport(nameof(GenericsNative), EntryPoint = "GetSpanFOut")]
public static extern void GetReadOnlySpanFOut(float e00, out ReadOnlySpan<float> value);
[DllImport(nameof(GenericsNative), EntryPoint = "GetSpanFPtr")]
public static extern ref readonly ReadOnlySpan<float> GetReadOnlySpanFRef(float e00);
[DllImport(nameof(GenericsNative), EntryPoint = "AddSpanF")]
public static extern ReadOnlySpan<float> AddReadOnlySpanF(ReadOnlySpan<float> lhs, ReadOnlySpan<float> rhs);
[DllImport(nameof(GenericsNative), EntryPoint = "AddSpanFs")]
public static extern ReadOnlySpan<float> AddReadOnlySpanFs(in ReadOnlySpan<float> pValues, int count);
}
unsafe partial class GenericsTest
{
private static void TestReadOnlySpanF()
{
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetReadOnlySpanF(1.0f));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetReadOnlySpanFOut(1.0f, out ReadOnlySpan<float> value3));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetReadOnlySpanFRef(1.0f));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddReadOnlySpanF(default, default));
Assert.Throws<MarshalDirectiveException>(() => {
ReadOnlySpan<float> value = default;
GenericsNative.AddReadOnlySpanFs(in value, 1);
});
}
}