//
using System;
+using System.Text;
using System.Runtime.InteropServices;
public class Tests {
return s == "ABC" ? 0 : 1;
}
+ public static int delegate_test_string_builder_marshalling (StringBuilder s)
+ {
+ if (s == null)
+ return 2;
+ else
+ return s.ToString () == "ABC" ? 0 : 1;
+ }
+
[DllImport ("libtest", EntryPoint="mono_test_ref_vtype")]
public static extern int mono_test_ref_vtype (int a, ref SimpleStruct ss, int b, TestDelegate d);
[DllImport ("libtest", EntryPoint="mono_test_marshal_delegate10")]
public static extern int mono_test_marshal_delegate10 (SimpleDelegate9 d);
+ [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate8")]
+ public static extern int mono_test_marshal_delegate11 (SimpleDelegate11 d, string s);
+
[DllImport ("libtest", EntryPoint="mono_test_marshal_primitive_byref_delegate")]
public static extern int mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate d);
public delegate int SimpleDelegate9 (return_int_delegate del);
+ public delegate int SimpleDelegate11 (StringBuilder s1);
+
public delegate int PrimitiveByrefDelegate (ref int i);
public delegate return_int_delegate ReturnDelegateDelegate ();
return mono_test_marshal_delegate8 (d, "ABC");
}
+ /* Test string builder marshalling with delegates */
+ public static int test_0_marshal_string_builder_delegate () {
+ SimpleDelegate11 d = new SimpleDelegate11 (delegate_test_string_builder_marshalling);
+
+ if (mono_test_marshal_delegate11 (d, null) != 2)
+ return 2;
+
+ return mono_test_marshal_delegate11 (d, "ABC");
+ }
+
/* Test that the delegate wrapper correctly catches null byref arguments */
public static int test_0_marshal_byref_class_delegate_null () {
SimpleDelegate5 d = new SimpleDelegate5 (delegate_test_class_byref);
}
}
+ public delegate int ArrayDelegate4_2 (int i,
+ string j,
+ string[] arr);
+
+ [DllImport ("libtest", EntryPoint="mono_test_marshal_array_delegate")]
+ public static extern int mono_test_marshal_array_delegate4_2 (string[] arr, int len, ArrayDelegate4_2 d);
+
+ public static int array_delegate4_2 (int i, string j, string[] arr) {
+ return (arr == null) ? 0 : 1;
+ }
+
+ public static int test_0_marshal_array_delegate_no_marshal_directive () {
+ try {
+ mono_test_marshal_array_delegate4_2 (null, 0, new ArrayDelegate4_2 (array_delegate4_2));
+ return 1;
+ }
+ catch (MarshalDirectiveException) {
+ return 0;
+ }
+ }
+
+ public delegate int ArrayDelegate4_3 (int i,
+ string j,
+ string[] arr);
+
+ [DllImport ("libtest", EntryPoint="mono_test_marshal_array_delegate")]
+ public static extern int mono_test_marshal_array_delegate4_3 (string[] arr, int len, ArrayDelegate4_3 d);
+
+ public int array_delegate4_3 (int i, string j, string[] arr) {
+ return (arr == null) ? 0 : 1;
+ }
+
+ public static int test_0_marshal_array_delegate_no_marshal_directive_instance () {
+ try {
+ Tests t = new Tests ();
+ mono_test_marshal_array_delegate4_3 (null, 0, new ArrayDelegate4_3 (t.array_delegate4_3));
+ return 1;
+ }
+ catch (MarshalDirectiveException) {
+ return 0;
+ }
+ }
+
public delegate int ArrayDelegate5 (int i,
string j,
[In, MarshalAs(UnmanagedType.LPArray,
return mono_test_marshal_out_string_array_delegate (arr, 2, new ArrayDelegate10 (array_delegate10));
}
+ /*
+ * [In, Out] classes
+ */
+
+ public delegate int InOutByvalClassDelegate ([In, Out] SimpleClass ss);
+
+ [DllImport ("libtest", EntryPoint="mono_test_marshal_inout_byval_class_delegate")]
+ public static extern int mono_test_marshal_inout_byval_class_delegate (InOutByvalClassDelegate d);
+
+ public static int delegate_test_byval_class_inout (SimpleClass ss) {
+ if ((ss.a != false) || (ss.b != true) || (ss.c != false) || (ss.d != "FOO"))
+ return 1;
+
+ ss.a = true;
+ ss.b = false;
+ ss.c = true;
+ ss.d = "RES";
+
+ return 0;
+ }
+
+ public static int test_0_marshal_inout_byval_class_delegate () {
+ return mono_test_marshal_inout_byval_class_delegate (new InOutByvalClassDelegate (delegate_test_byval_class_inout));
+ }
+
+ /*
+ * Returning unicode strings
+ */
+ [return: MarshalAs(UnmanagedType.LPWStr)]
+ public delegate string ReturnUnicodeStringDelegate([MarshalAs(UnmanagedType.LPWStr)] string message);
+
+ [DllImport ("libtest", EntryPoint="mono_test_marshal_return_unicode_string_delegate")]
+ public static extern int mono_test_marshal_return_unicode_string_delegate (ReturnUnicodeStringDelegate d);
+
+ public static String return_unicode_string_delegate (string message) {
+ return message;
+ }
+
+ public static int test_0_marshal_return_unicode_string_delegate () {
+ return mono_test_marshal_return_unicode_string_delegate (new ReturnUnicodeStringDelegate (return_unicode_string_delegate));
+ }
+
/*
* Returning string arrays
*/
return mono_test_marshal_return_string_array_delegate (new ReturnArrayDelegate (return_array_delegate_null));
}
+ /*
+ * Byref string marshalling
+ */
+ public delegate int ByrefStringDelegate (ref string s);
+
+ [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_string_delegate")]
+ public static extern int mono_test_marshal_byref_string_delegate (ByrefStringDelegate d);
+
+ public static int byref_string_delegate (ref string s) {
+ if (s != "ABC")
+ return 1;
+
+ s = "DEF";
+
+ return 0;
+ }
+
+ public static int test_0_marshal_byref_string_delegate () {
+ return mono_test_marshal_byref_string_delegate (new ByrefStringDelegate (byref_string_delegate));
+ }
}