2 // marshal.cs: tests for the System.Runtime.InteropServices.Marshal class
6 using System
.Reflection
;
7 using System
.Runtime
.InteropServices
;
11 public static int Main (string[] args
) {
12 return TestDriver
.RunTests (typeof (Tests
), args
);
15 public delegate int SimpleDelegate (int a
);
17 public static int delegate_test (int a
)
22 [DllImport ("libtest", EntryPoint
="mono_test_marshal_delegate")]
23 public static extern int mono_test_marshal_delegate (IntPtr ptr
);
25 [DllImport ("libtest", EntryPoint
="mono_test_marshal_return_delegate")]
26 public static extern IntPtr
mono_test_marshal_return_delegate (SimpleDelegate d
);
28 [DllImport ("libtest", EntryPoint
="mono_test_marshal_return_delegate_2")]
29 public static extern IntPtr
mono_test_marshal_return_delegate_2 ();
31 static int test_0_get_function_pointer_for_delegate () {
32 // This is a 2.0 feature
33 MethodInfo mi
= typeof (Marshal
).GetMethod ("GetFunctionPointerForDelegate");
37 IntPtr fnPtr
= (IntPtr
)mi
.Invoke (null, new object [] { new SimpleDelegate (delegate_test)}
);
39 if (mono_test_marshal_delegate (fnPtr
) != 3)
45 static int test_0_get_delegate_for_function_pointer () {
46 // This is a 2.0 feature
47 MethodInfo mi
= typeof (Marshal
).GetMethod ("GetDelegateForFunctionPointer");
51 IntPtr ptr
= mono_test_marshal_return_delegate (new SimpleDelegate (delegate_test
));
53 SimpleDelegate d
= (SimpleDelegate
)mi
.Invoke (null, new object [] { ptr, typeof (SimpleDelegate) }
);
55 return d (5) == 6 ? 0 : 1;
58 /* Obtain a delegate from a native function pointer */
59 static int test_0_get_delegate_for_ftnptr_native () {
60 // This is a 2.0 feature
61 MethodInfo mi
= typeof (Marshal
).GetMethod ("GetDelegateForFunctionPointer");
65 IntPtr ptr
= mono_test_marshal_return_delegate_2 ();
67 SimpleDelegate d
= (SimpleDelegate
)mi
.Invoke (null, new object [] { ptr, typeof (SimpleDelegate) }
);
69 return d (5) == 6 ? 0 : 1;