Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/Simple/PInvoke/PInvoke.cs')
-rw-r--r--tests/src/Simple/PInvoke/PInvoke.cs20
1 files changed, 17 insertions, 3 deletions
diff --git a/tests/src/Simple/PInvoke/PInvoke.cs b/tests/src/Simple/PInvoke/PInvoke.cs
index 1e7a6fa99..2804cd614 100644
--- a/tests/src/Simple/PInvoke/PInvoke.cs
+++ b/tests/src/Simple/PInvoke/PInvoke.cs
@@ -8,7 +8,7 @@ using System.Text;
// Name of namespace matches the name of the assembly on purpose to
// ensure that we can handle this (mostly an issue for C++ code generation).
-namespace PInvoke
+namespace PInvokeTests
{
internal class Program
{
@@ -36,6 +36,9 @@ namespace PInvoke
[DllImport("*", CallingConvention = CallingConvention.StdCall)]
public static extern bool SafeHandleTest(SafeMemoryHandle sh1, Int64 sh1Value);
+ [DllImport("*", CallingConvention = CallingConvention.StdCall)]
+ public static extern int SafeHandleOutTest(out SafeMemoryHandle sh1);
+
[DllImport("*", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
public static extern bool LastErrorTest();
@@ -51,9 +54,9 @@ namespace PInvoke
return 100;
}
- public static void ThrowIfNotEquals<T>(T expected, T actual, string message)
+ public static void ThrowIfNotEquals(int expected, int actual, string message)
{
- if (!Object.Equals(expected, actual))
+ if (expected != actual)
{
message += "\nExpected: " + expected + "\n";
message += "Actual: " + actual + "\n";
@@ -61,6 +64,11 @@ namespace PInvoke
}
}
+ public static void ThrowIfNotEquals(bool expected, bool actual, string message)
+ {
+ ThrowIfNotEquals(expected ? 1 : 0, actual ? 1 : 0, message);
+ }
+
private static void TestBlittableType()
{
Console.WriteLine("Testing marshalling blittable types");
@@ -117,6 +125,12 @@ namespace PInvoke
long val = hndIntPtr.ToInt64(); //return the 64-bit value associated with hnd
ThrowIfNotEquals(true, SafeHandleTest(hnd, val), "SafeHandle marshalling failed.");
+
+ Console.WriteLine("Testing marshalling out SafeHandle");
+ SafeMemoryHandle hnd2;
+ int actual = SafeHandleOutTest(out hnd2);
+ int expected = unchecked((int)hnd2.DangerousGetHandle().ToInt64());
+ ThrowIfNotEquals(actual, expected, "SafeHandle out marshalling failed");
}
}