forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test coverage for unsupported marshal scenarios (dotnet/coreclr#2…
…7393) * Pointers to non-blittable structs are not supported * SizeParamIndex could be bogus Commit migrated from dotnet/coreclr@f1a900d
- Loading branch information
1 parent
0629300
commit 3ffd57e
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/PInvokePointerTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using TestLibrary; | ||
|
||
unsafe class Program | ||
{ | ||
[StructLayout(LayoutKind.Sequential)] | ||
struct NonBlittable | ||
{ | ||
bool _nonBlittable; | ||
} | ||
|
||
// the "string unused" parameter is just so that we don't hit https://github.com/dotnet/coreclr/issues/27408 that | ||
// makes this p/invoke actually work. | ||
[DllImport("Unused")] | ||
private static extern void PointerToNonBlittableType(NonBlittable* pNonBlittable, string unused); | ||
|
||
static int Main() | ||
{ | ||
Assert.Throws<MarshalDirectiveException>(() => PointerToNonBlittableType(null, null)); | ||
|
||
return 100; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/PInvokePointerTest.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<DefineConstants>$(DefineConstants);STATIC</DefineConstants> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="PInvokePointerTest.cs" /> | ||
</ItemGroup> | ||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Interop.settings.targets))\Interop.settings.targets" /> | ||
</Project> |
26 changes: 26 additions & 0 deletions
26
src/coreclr/tests/src/Interop/PInvoke/SizeParamIndex/PInvoke/Invalid/InvalidParamIndex.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using TestLibrary; | ||
|
||
class Program | ||
{ | ||
[DllImport("Unused")] | ||
static extern void SizeParamIndexTooBig( | ||
out byte arrSize, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 20)] out byte[] arrByte); | ||
|
||
[DllImport("Unused")] | ||
public static extern void SizeParamIndexWrongType( | ||
out string arrSize, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] out byte[] arrByte); | ||
|
||
static int Main() | ||
{ | ||
Assert.Throws<MarshalDirectiveException>(() => SizeParamIndexTooBig(out var _, out var _)); | ||
Assert.Throws<MarshalDirectiveException>(() => SizeParamIndexWrongType(out var _, out var _)); | ||
|
||
return 100; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...coreclr/tests/src/Interop/PInvoke/SizeParamIndex/PInvoke/Invalid/InvalidParamIndex.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<DefineConstants>$(DefineConstants);STATIC</DefineConstants> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="InvalidParamIndex.cs" /> | ||
</ItemGroup> | ||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Interop.settings.targets))\Interop.settings.targets" /> | ||
</Project> |