Permalink
Browse files

2005-02-15 Zoltan Varga <vargaz@freemail.hu>

	* marshal.cs libtest.c: Add new test for GetDelegateForFunctionPointer.

svn path=/trunk/mono/; revision=40701
  • Loading branch information...
1 parent b42871b commit 268b3e64050e3c6467227944dfc1161847459571 @vargaz vargaz committed Feb 15, 2005
Showing with 33 additions and 0 deletions.
  1. +4 −0 mono/tests/ChangeLog
  2. +12 −0 mono/tests/libtest.c
  3. +17 −0 mono/tests/marshal.cs
View
4 mono/tests/ChangeLog
@@ -1,3 +1,7 @@
+2005-02-15 Zoltan Varga <vargaz@freemail.hu>
+
+ * marshal.cs libtest.c: Add new test for GetDelegateForFunctionPointer.
+
2005-02-13 Zoltan Varga <vargaz@freemail.hu>
* libtest.c (NameManglingAuto): Fix test. Fixes #72559.
View
12 mono/tests/libtest.c
@@ -540,6 +540,18 @@ mono_test_marshal_return_delegate (SimpleDelegate delegate)
return delegate;
}
+static STDCALL int
+return_plus_one (int i)
+{
+ return i + 1;
+}
+
+STDCALL SimpleDelegate
+mono_test_marshal_return_delegate_2 ()
+{
+ return return_plus_one;
+}
+
typedef simplestruct (STDCALL *SimpleDelegate2) (simplestruct ss);
static gboolean
View
17 mono/tests/marshal.cs
@@ -25,6 +25,9 @@ public static int delegate_test (int a)
[DllImport ("libtest", EntryPoint="mono_test_marshal_return_delegate")]
public static extern IntPtr mono_test_marshal_return_delegate (SimpleDelegate d);
+ [DllImport ("libtest", EntryPoint="mono_test_marshal_return_delegate_2")]
+ public static extern IntPtr mono_test_marshal_return_delegate_2 ();
+
static int test_0_get_function_pointer_for_delegate () {
// This is a 2.0 feature
MethodInfo mi = typeof (Marshal).GetMethod ("GetFunctionPointerForDelegate");
@@ -51,4 +54,18 @@ public static int delegate_test (int a)
return d (5) == 6 ? 0 : 1;
}
+
+ /* Obtain a delegate from a native function pointer */
+ static int test_0_get_delegate_for_ftnptr_native () {
+ // This is a 2.0 feature
+ MethodInfo mi = typeof (Marshal).GetMethod ("GetDelegateForFunctionPointer");
+ if (mi == null)
+ return 0;
+
+ IntPtr ptr = mono_test_marshal_return_delegate_2 ();
+
+ SimpleDelegate d = (SimpleDelegate)mi.Invoke (null, new object [] { ptr, typeof (SimpleDelegate) });
+
+ return d (5) == 6 ? 0 : 1;
+ }
}

0 comments on commit 268b3e6

Please sign in to comment.