4 // Tests for native->managed marshalling
9 using System.Runtime.InteropServices;
13 [StructLayout (LayoutKind.Sequential)]
14 public struct SimpleStruct {
19 [MarshalAs(UnmanagedType.LPWStr)]
23 [StructLayout (LayoutKind.Sequential)]
24 public class SimpleClass {
31 public static SimpleStruct delegate_test_struct (SimpleStruct ss)
38 res.d = ss.d + "-RES";
39 res.d2 = ss.d2 + "-RES";
44 public static int delegate_test_struct_byref (int a, ref SimpleStruct ss, int b)
46 if (a == 1 && b == 2 && ss.a && !ss.b && ss.c && ss.d == "TEST2") {
57 public static int delegate_test_struct_out (int a, out SimpleStruct ss, int b)
68 public static SimpleClass delegate_test_class (SimpleClass ss)
73 if (! (!ss.a && ss.b && !ss.c && ss.d == "TEST"))
81 public static int delegate_test_class_byref (ref SimpleClass ss)
86 if (!ss.a && ss.b && !ss.c && ss.d == "TEST") {
98 public static int delegate_test_class_out (out SimpleClass ss)
100 ss = new SimpleClass ();
109 public static int delegate_test_primitive_byref (ref int i)
118 public static int delegate_test_string_marshalling (string s)
120 return s == "ABC" ? 0 : 1;
123 public static int delegate_test_string_builder_marshalling (StringBuilder s)
128 return s.ToString () == "ABC" ? 0 : 1;
131 [DllImport ("libtest", EntryPoint="mono_test_ref_vtype")]
132 public static extern int mono_test_ref_vtype (int a, ref SimpleStruct ss, int b, TestDelegate d);
134 public delegate int OutStructDelegate (int a, out SimpleStruct ss, int b);
136 [DllImport ("libtest", EntryPoint="mono_test_marshal_out_struct")]
137 public static extern int mono_test_marshal_out_struct (int a, out SimpleStruct ss, int b, OutStructDelegate d);
139 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate2")]
140 public static extern int mono_test_marshal_delegate2 (SimpleDelegate2 d);
142 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate4")]
143 public static extern int mono_test_marshal_delegate4 (SimpleDelegate4 d);
145 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate5")]
146 public static extern int mono_test_marshal_delegate5 (SimpleDelegate5 d);
148 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate6")]
149 public static extern int mono_test_marshal_delegate6 (SimpleDelegate5 d);
151 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate7")]
152 public static extern int mono_test_marshal_delegate7 (SimpleDelegate7 d);
154 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate8", CharSet=CharSet.Unicode)]
155 public static extern int mono_test_marshal_delegate8 (SimpleDelegate8 d, string s);
157 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate9")]
158 public static extern int mono_test_marshal_delegate9 (SimpleDelegate9 d, return_int_delegate d2);
160 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate10")]
161 public static extern int mono_test_marshal_delegate10 (SimpleDelegate9 d);
163 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate8")]
164 public static extern int mono_test_marshal_delegate11 (SimpleDelegate11 d, string s);
166 [DllImport ("libtest", EntryPoint="mono_test_marshal_primitive_byref_delegate")]
167 public static extern int mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate d);
169 [DllImport ("libtest", EntryPoint="mono_test_marshal_return_delegate_delegate")]
170 public static extern int mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d);
172 public delegate int TestDelegate (int a, ref SimpleStruct ss, int b);
174 public delegate SimpleStruct SimpleDelegate2 (SimpleStruct ss);
176 public delegate SimpleClass SimpleDelegate4 (SimpleClass ss);
178 public delegate int SimpleDelegate5 (ref SimpleClass ss);
180 public delegate int SimpleDelegate7 (out SimpleClass ss);
182 public delegate int SimpleDelegate8 ([MarshalAs (UnmanagedType.LPWStr)] string s1);
184 public delegate int return_int_delegate (int i);
186 public delegate int SimpleDelegate9 (return_int_delegate del);
188 public delegate int SimpleDelegate11 (StringBuilder s1);
190 public delegate int PrimitiveByrefDelegate (ref int i);
192 public delegate return_int_delegate ReturnDelegateDelegate ();
194 public static int Main () {
195 return TestDriver.RunTests (typeof (Tests));
198 /* Test structures as arguments and return values of delegates */
199 public static int test_0_marshal_struct_delegate () {
200 SimpleDelegate2 d = new SimpleDelegate2 (delegate_test_struct);
202 return mono_test_marshal_delegate2 (d);
205 /* Test structures as byref arguments of delegates */
206 public static int test_0_marshal_byref_struct_delegate () {
207 SimpleStruct ss = new SimpleStruct ();
208 TestDelegate d = new TestDelegate (delegate_test_struct_byref);
213 if (mono_test_ref_vtype (1, ref ss, 2, d) != 0)
216 if (! (ss.a && ss.b && ss.c && ss.d == "TEST3"))
222 /* Test structures as out arguments of delegates */
223 public static int test_0_marshal_out_struct_delegate () {
224 SimpleStruct ss = new SimpleStruct ();
225 OutStructDelegate d = new OutStructDelegate (delegate_test_struct_out);
227 return mono_test_marshal_out_struct (1, out ss, 2, d);
230 /* Test classes as arguments and return values of delegates */
231 public static int test_0_marshal_class_delegate () {
232 SimpleDelegate4 d = new SimpleDelegate4 (delegate_test_class);
234 return mono_test_marshal_delegate4 (d);
237 /* Test classes as byref arguments of delegates */
238 public static int test_0_marshal_byref_class_delegate () {
239 SimpleDelegate5 d = new SimpleDelegate5 (delegate_test_class_byref);
241 return mono_test_marshal_delegate5 (d);
244 /* Test classes as out arguments of delegates */
245 public static int test_0_marshal_out_class_delegate () {
246 SimpleDelegate7 d = new SimpleDelegate7 (delegate_test_class_out);
248 return mono_test_marshal_delegate7 (d);
251 /* Test string marshalling with delegates */
252 public static int test_0_marshal_string_delegate () {
253 SimpleDelegate8 d = new SimpleDelegate8 (delegate_test_string_marshalling);
255 return mono_test_marshal_delegate8 (d, "ABC");
258 /* Test string builder marshalling with delegates */
259 public static int test_0_marshal_string_builder_delegate () {
260 SimpleDelegate11 d = new SimpleDelegate11 (delegate_test_string_builder_marshalling);
262 if (mono_test_marshal_delegate11 (d, null) != 2)
265 return mono_test_marshal_delegate11 (d, "ABC");
268 /* Test that the delegate wrapper correctly catches null byref arguments */
269 public static int test_0_marshal_byref_class_delegate_null () {
270 SimpleDelegate5 d = new SimpleDelegate5 (delegate_test_class_byref);
273 mono_test_marshal_delegate6 (d);
276 catch (ArgumentNullException ex) {
281 static int return_self (int i) {
285 static int call_int_delegate (return_int_delegate d) {
289 public static int test_55_marshal_delegate_delegate () {
290 SimpleDelegate9 d = new SimpleDelegate9 (call_int_delegate);
292 return mono_test_marshal_delegate9 (d, new return_int_delegate (return_self));
295 public static int test_0_marshal_primitive_byref_delegate () {
296 PrimitiveByrefDelegate d = new PrimitiveByrefDelegate (delegate_test_primitive_byref);
298 return mono_test_marshal_primitive_byref_delegate (d);
301 public static return_int_delegate return_delegate () {
302 return new return_int_delegate (return_self);
305 public static int test_55_marshal_return_delegate_delegate () {
306 return mono_test_marshal_return_delegate_delegate (new ReturnDelegateDelegate (return_delegate));
309 /* Passing and returning strings */
311 public delegate String ReturnStringDelegate (String s);
313 [DllImport ("libtest", EntryPoint="mono_test_return_string")]
314 public static extern String mono_test_marshal_return_string_delegate (ReturnStringDelegate d);
316 public static String managed_return_string (String s) {
323 public static int test_0_marshal_return_string_delegate () {
324 ReturnStringDelegate d = new ReturnStringDelegate (managed_return_string);
325 String s = mono_test_marshal_return_string_delegate (d);
327 return (s == "12345") ? 0 : 1;
330 /* Passing and returning enums */
332 public enum FooEnum {
338 public delegate FooEnum ReturnEnumDelegate (FooEnum e);
340 [DllImport ("libtest", EntryPoint="mono_test_marshal_return_enum_delegate")]
341 public static extern int mono_test_marshal_return_enum_delegate (ReturnEnumDelegate d);
343 public static FooEnum managed_return_enum (FooEnum e) {
344 return (FooEnum)((int)e + 1);
347 public static int test_0_marshal_return_enum_delegate () {
348 ReturnEnumDelegate d = new ReturnEnumDelegate (managed_return_enum);
349 FooEnum e = (FooEnum)mono_test_marshal_return_enum_delegate (d);
351 return e == FooEnum.Foo3 ? 0 : 1;
354 /* Passing and returning blittable structs */
356 [StructLayout (LayoutKind.Sequential)]
357 public struct BlittableStruct {
362 public static BlittableStruct delegate_test_blittable_struct (BlittableStruct ss)
374 public delegate BlittableStruct SimpleDelegate10 (BlittableStruct ss);
376 [DllImport ("libtest", EntryPoint="mono_test_marshal_blittable_struct_delegate")]
377 public static extern int mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 d);
379 public static int test_0_marshal_blittable_struct_delegate () {
380 return mono_test_marshal_blittable_struct_delegate (new SimpleDelegate10 (delegate_test_blittable_struct));
384 * Passing and returning small structs
387 /* TEST 1: 4 byte long INTEGER struct */
389 [StructLayout (LayoutKind.Sequential)]
390 public struct SmallStruct1 {
394 public static SmallStruct1 delegate_test_struct (SmallStruct1 ss) {
402 public delegate SmallStruct1 SmallStructDelegate1 (SmallStruct1 ss);
404 [DllImport ("libtest", EntryPoint="mono_test_marshal_small_struct_delegate1")]
405 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate1 d);
407 public static int test_0_marshal_small_struct_delegate1 () {
408 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate1 (delegate_test_struct));
411 /* TEST 2: 2+2 byte long INTEGER struct */
413 [StructLayout (LayoutKind.Sequential)]
414 public struct SmallStruct2 {
418 public static SmallStruct2 delegate_test_struct (SmallStruct2 ss) {
421 res.i = (short)-ss.i;
422 res.j = (short)-ss.j;
427 public delegate SmallStruct2 SmallStructDelegate2 (SmallStruct2 ss);
429 [DllImport ("libtest", EntryPoint="mono_test_marshal_small_struct_delegate2")]
430 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate2 d);
432 public static int test_0_marshal_small_struct_delegate2 () {
433 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate2 (delegate_test_struct));
436 /* TEST 3: 2+1 byte long INTEGER struct */
438 [StructLayout (LayoutKind.Sequential)]
439 public struct SmallStruct3 {
444 public static SmallStruct3 delegate_test_struct (SmallStruct3 ss) {
447 res.i = (short)-ss.i;
453 public delegate SmallStruct3 SmallStructDelegate3 (SmallStruct3 ss);
455 [DllImport ("libtest", EntryPoint="mono_test_marshal_small_struct_delegate3")]
456 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate3 d);
458 public static int test_0_marshal_small_struct_delegate3 () {
459 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate3 (delegate_test_struct));
462 /* TEST 4: 2 byte long INTEGER struct */
464 [StructLayout (LayoutKind.Sequential)]
465 public struct SmallStruct4 {
469 public static SmallStruct4 delegate_test_struct (SmallStruct4 ss) {
472 res.i = (short)-ss.i;
477 public delegate SmallStruct4 SmallStructDelegate4 (SmallStruct4 ss);
479 [DllImport ("libtest", EntryPoint="mono_test_marshal_small_struct_delegate4")]
480 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate4 d);
482 public static int test_0_marshal_small_struct_delegate4 () {
483 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate4 (delegate_test_struct));
486 /* TEST 5: 8 byte long INTEGER struct */
488 [StructLayout (LayoutKind.Sequential)]
489 public struct SmallStruct5 {
493 public static SmallStruct5 delegate_test_struct (SmallStruct5 ss) {
501 public delegate SmallStruct5 SmallStructDelegate5 (SmallStruct5 ss);
503 [DllImport ("libtest", EntryPoint="mono_test_marshal_small_struct_delegate5")]
504 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate5 d);
506 public static int test_0_marshal_small_struct_delegate5 () {
507 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate5 (delegate_test_struct));
510 /* TEST 6: 4+4 byte long INTEGER struct */
512 [StructLayout (LayoutKind.Sequential)]
513 public struct SmallStruct6 {
517 public static SmallStruct6 delegate_test_struct (SmallStruct6 ss) {
526 public delegate SmallStruct6 SmallStructDelegate6 (SmallStruct6 ss);
528 [DllImport ("libtest", EntryPoint="mono_test_marshal_small_struct_delegate6")]
529 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate6 d);
531 public static int test_0_marshal_small_struct_delegate6 () {
532 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate6 (delegate_test_struct));
535 /* TEST 7: 4+2 byte long INTEGER struct */
537 [StructLayout (LayoutKind.Sequential)]
538 public struct SmallStruct7 {
543 public static SmallStruct7 delegate_test_struct (SmallStruct7 ss) {
547 res.j = (short)-ss.j;
552 public delegate SmallStruct7 SmallStructDelegate7 (SmallStruct7 ss);
554 [DllImport ("libtest", EntryPoint="mono_test_marshal_small_struct_delegate7")]
555 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate7 d);
557 public static int test_0_marshal_small_struct_delegate7 () {
558 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate7 (delegate_test_struct));
561 /* TEST 8: 4 byte long FLOAT struct */
563 [StructLayout (LayoutKind.Sequential)]
564 public struct SmallStruct8 {
568 public static SmallStruct8 delegate_test_struct (SmallStruct8 ss) {
576 public delegate SmallStruct8 SmallStructDelegate8 (SmallStruct8 ss);
578 [DllImport ("libtest", EntryPoint="mono_test_marshal_small_struct_delegate8")]
579 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate8 d);
581 public static int test_0_marshal_small_struct_delegate8 () {
582 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate8 (delegate_test_struct));
585 /* TEST 9: 8 byte long FLOAT struct */
587 [StructLayout (LayoutKind.Sequential)]
588 public struct SmallStruct9 {
592 public static SmallStruct9 delegate_test_struct (SmallStruct9 ss) {
600 public delegate SmallStruct9 SmallStructDelegate9 (SmallStruct9 ss);
602 [DllImport ("libtest", EntryPoint="mono_test_marshal_small_struct_delegate9")]
603 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate9 d);
605 public static int test_0_marshal_small_struct_delegate9 () {
606 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate9 (delegate_test_struct));
609 /* TEST 10: 4+4 byte long FLOAT struct */
611 [StructLayout (LayoutKind.Sequential)]
612 public struct SmallStruct10 {
617 public static SmallStruct10 delegate_test_struct (SmallStruct10 ss) {
626 public delegate SmallStruct10 SmallStructDelegate10 (SmallStruct10 ss);
628 [DllImport ("libtest", EntryPoint="mono_test_marshal_small_struct_delegate10")]
629 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate10 d);
631 public static int test_0_marshal_small_struct_delegate10 () {
632 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate10 (delegate_test_struct));
635 /* TEST 11: 4+4 byte long MIXED struct */
637 [StructLayout (LayoutKind.Sequential)]
638 public struct SmallStruct11 {
643 public static SmallStruct11 delegate_test_struct (SmallStruct11 ss) {
652 public delegate SmallStruct11 SmallStructDelegate11 (SmallStruct11 ss);
654 [DllImport ("libtest", EntryPoint="mono_test_marshal_small_struct_delegate11")]
655 public static extern int mono_test_marshal_small_struct_delegate (SmallStructDelegate11 d);
657 public static int test_0_marshal_small_struct_delegate11 () {
658 return mono_test_marshal_small_struct_delegate (new SmallStructDelegate11 (delegate_test_struct));
664 public delegate int ArrayDelegate1 (int i,
666 [In, MarshalAs(UnmanagedType.LPArray,
667 ArraySubType=UnmanagedType.LPStr, SizeParamIndex=0)] string[] arr);
669 [DllImport ("libtest", EntryPoint="mono_test_marshal_array_delegate")]
670 public static extern int mono_test_marshal_array_delegate1 (string[] arr, int len, ArrayDelegate1 d);
672 public static int array_delegate1 (int i, string j, string[] arr) {
675 if ((arr [0] != "ABC") || (arr [1] != "DEF"))
680 public static int test_0_marshal_array_delegate_string () {
681 string[] arr = new string [] { "ABC", "DEF" };
682 return mono_test_marshal_array_delegate1 (arr, arr.Length, new ArrayDelegate1 (array_delegate1));
685 public static int array_delegate2 (int i, string j, string[] arr) {
686 return (arr == null) ? 0 : 1;
689 public static int test_0_marshal_array_delegate_null () {
690 return mono_test_marshal_array_delegate1 (null, 0, new ArrayDelegate1 (array_delegate2));
693 public delegate int ArrayDelegate3 (int i,
695 [In, MarshalAs(UnmanagedType.LPArray,
696 ArraySubType=UnmanagedType.LPStr, SizeParamIndex=3)] string[] arr);
698 [DllImport ("libtest", EntryPoint="mono_test_marshal_array_delegate")]
699 public static extern int mono_test_marshal_array_delegate3 (string[] arr, int len, ArrayDelegate3 d);
701 public static int array_delegate3 (int i, string j, string[] arr) {
702 return (arr == null) ? 0 : 1;
705 public static int test_0_marshal_array_delegate_bad_paramindex () {
707 mono_test_marshal_array_delegate3 (null, 0, new ArrayDelegate3 (array_delegate3));
710 catch (MarshalDirectiveException) {
715 public delegate int ArrayDelegate4 (int i,
717 [In, MarshalAs(UnmanagedType.LPArray,
718 ArraySubType=UnmanagedType.LPStr, SizeParamIndex=1)] string[] arr);
720 [DllImport ("libtest", EntryPoint="mono_test_marshal_array_delegate")]
721 public static extern int mono_test_marshal_array_delegate4 (string[] arr, int len, ArrayDelegate4 d);
723 public static int array_delegate4 (int i, string j, string[] arr) {
724 return (arr == null) ? 0 : 1;
727 public static int test_0_marshal_array_delegate_bad_paramtype () {
729 mono_test_marshal_array_delegate4 (null, 0, new ArrayDelegate4 (array_delegate4));
732 catch (MarshalDirectiveException) {
737 public delegate int ArrayDelegate4_2 (int i,
741 [DllImport ("libtest", EntryPoint="mono_test_marshal_array_delegate")]
742 public static extern int mono_test_marshal_array_delegate4_2 (string[] arr, int len, ArrayDelegate4_2 d);
744 public static int array_delegate4_2 (int i, string j, string[] arr) {
745 return (arr == null) ? 0 : 1;
748 public static int test_0_marshal_array_delegate_no_marshal_directive () {
750 mono_test_marshal_array_delegate4_2 (null, 0, new ArrayDelegate4_2 (array_delegate4_2));
753 catch (MarshalDirectiveException) {
758 public delegate int ArrayDelegate4_3 (int i,
762 [DllImport ("libtest", EntryPoint="mono_test_marshal_array_delegate")]
763 public static extern int mono_test_marshal_array_delegate4_3 (string[] arr, int len, ArrayDelegate4_3 d);
765 public int array_delegate4_3 (int i, string j, string[] arr) {
766 return (arr == null) ? 0 : 1;
769 public static int test_0_marshal_array_delegate_no_marshal_directive_instance () {
771 Tests t = new Tests ();
772 mono_test_marshal_array_delegate4_3 (null, 0, new ArrayDelegate4_3 (t.array_delegate4_3));
775 catch (MarshalDirectiveException) {
780 public delegate int ArrayDelegate5 (int i,
782 [In, MarshalAs(UnmanagedType.LPArray,
783 ArraySubType=UnmanagedType.LPWStr, SizeParamIndex=0)] string[] arr);
785 [DllImport ("libtest", EntryPoint="mono_test_marshal_array_delegate", CharSet=CharSet.Unicode)]
786 public static extern int mono_test_marshal_array_delegate5 (string[] arr, int len, ArrayDelegate5 d);
788 public static int array_delegate5 (int i, string j, string[] arr) {
791 if ((arr [0] != "ABC") || (arr [1] != "DEF"))
796 public static int test_0_marshal_array_delegate_unicode_string () {
797 string[] arr = new string [] { "ABC", "DEF" };
798 return mono_test_marshal_array_delegate5 (arr, arr.Length, new ArrayDelegate5 (array_delegate5));
801 public delegate int ArrayDelegate6 (int i,
803 [In, MarshalAs(UnmanagedType.LPArray,
804 ArraySubType=UnmanagedType.LPStr, SizeConst=2)] string[] arr);
806 [DllImport ("libtest", EntryPoint="mono_test_marshal_array_delegate")]
807 public static extern int mono_test_marshal_array_delegate6 (string[] arr, int len, ArrayDelegate6 d);
809 public static int array_delegate6 (int i, string j, string[] arr) {
812 if ((arr [0] != "ABC") || (arr [1] != "DEF"))
817 public static int test_0_marshal_array_delegate_sizeconst () {
818 string[] arr = new string [] { "ABC", "DEF" };
819 return mono_test_marshal_array_delegate6 (arr, 1024, new ArrayDelegate6 (array_delegate6));
822 public delegate int ArrayDelegate7 (int i,
824 [In, MarshalAs(UnmanagedType.LPArray,
825 ArraySubType=UnmanagedType.LPStr, SizeConst=1, SizeParamIndex=0)] string[] arr);
827 [DllImport ("libtest", EntryPoint="mono_test_marshal_array_delegate")]
828 public static extern int mono_test_marshal_array_delegate7 (string[] arr, int len, ArrayDelegate7 d);
830 public static int array_delegate7 (int i, string j, string[] arr) {
833 if ((arr [0] != "ABC") || (arr [1] != "DEF"))
838 public static int test_0_marshal_array_delegate_sizeconst_paramindex () {
839 string[] arr = new string [] { "ABC", "DEF" };
840 return mono_test_marshal_array_delegate7 (arr, 1, new ArrayDelegate7 (array_delegate7));
843 public delegate int ArrayDelegate8 (int i, string j,
844 [In, MarshalAs(UnmanagedType.LPArray,
848 [DllImport ("libtest", EntryPoint="mono_test_marshal_array_delegate")]
849 public static extern int mono_test_marshal_array_delegate8 (int[] arr, int len, ArrayDelegate8 d);
851 public static int array_delegate8 (int i, string j, int[] arr) {
854 if ((arr [0] != 42) || (arr [1] != 43))
859 public static int test_0_marshal_array_delegate_blittable () {
860 int[] arr = new int [] { 42, 43 };
861 return mono_test_marshal_array_delegate8 (arr, 2, new ArrayDelegate8 (array_delegate8));
864 /* Array with size param of type long */
866 public delegate int ArrayDelegate8_2 (long i,
868 [In, MarshalAs(UnmanagedType.LPArray,
869 ArraySubType=UnmanagedType.LPStr, SizeParamIndex=0)] string[] arr);
871 [DllImport ("libtest", EntryPoint="mono_test_marshal_array_delegate_long")]
872 public static extern int mono_test_marshal_array_delegate8_2 (string[] arr, long len, ArrayDelegate8_2 d);
874 public static int array_delegate8_2 (long i, string j, string[] arr) {
877 if ((arr [0] != "ABC") || (arr [1] != "DEF"))
882 public static int test_0_marshal_array_delegate_long_param () {
883 string[] arr = new string [] { "ABC", "DEF" };
884 return mono_test_marshal_array_delegate8_2 (arr, arr.Length, new ArrayDelegate8_2 (array_delegate8_2));
889 * [Out] blittable arrays
892 public delegate int ArrayDelegate9 (int i, string j,
893 [Out, MarshalAs(UnmanagedType.LPArray,
897 [DllImport ("libtest", EntryPoint="mono_test_marshal_out_array_delegate")]
898 public static extern int mono_test_marshal_out_array_delegate (int[] arr, int len, ArrayDelegate9 d);
900 public static int array_delegate9 (int i, string j, int[] arr) {
910 public static int test_0_marshal_out_array_delegate () {
911 int[] arr = new int [] { 42, 43 };
912 return mono_test_marshal_out_array_delegate (arr, 2, new ArrayDelegate9 (array_delegate9));
916 * [Out] string arrays
919 public delegate int ArrayDelegate10 (int i,
921 [Out, MarshalAs(UnmanagedType.LPArray,
922 ArraySubType=UnmanagedType.LPStr, SizeConst=2)] string[] arr);
924 [DllImport ("libtest", EntryPoint="mono_test_marshal_out_string_array_delegate")]
925 public static extern int mono_test_marshal_out_string_array_delegate (string[] arr, int len, ArrayDelegate10 d);
927 public static int array_delegate10 (int i, string j, string[] arr) {
937 public static int test_0_marshal_out_string_array_delegate () {
938 string[] arr = new string [] { "", "" };
939 return mono_test_marshal_out_string_array_delegate (arr, 2, new ArrayDelegate10 (array_delegate10));
946 public delegate int InOutByvalClassDelegate ([In, Out] SimpleClass ss);
948 [DllImport ("libtest", EntryPoint="mono_test_marshal_inout_byval_class_delegate")]
949 public static extern int mono_test_marshal_inout_byval_class_delegate (InOutByvalClassDelegate d);
951 public static int delegate_test_byval_class_inout (SimpleClass ss) {
952 if ((ss.a != false) || (ss.b != true) || (ss.c != false) || (ss.d != "FOO"))
963 public static int test_0_marshal_inout_byval_class_delegate () {
964 return mono_test_marshal_inout_byval_class_delegate (new InOutByvalClassDelegate (delegate_test_byval_class_inout));
968 * Returning unicode strings
970 [return: MarshalAs(UnmanagedType.LPWStr)]
971 public delegate string ReturnUnicodeStringDelegate([MarshalAs(UnmanagedType.LPWStr)] string message);
973 [DllImport ("libtest", EntryPoint="mono_test_marshal_return_unicode_string_delegate")]
974 public static extern int mono_test_marshal_return_unicode_string_delegate (ReturnUnicodeStringDelegate d);
976 public static String return_unicode_string_delegate (string message) {
980 public static int test_0_marshal_return_unicode_string_delegate () {
981 return mono_test_marshal_return_unicode_string_delegate (new ReturnUnicodeStringDelegate (return_unicode_string_delegate));
985 * Returning string arrays
987 public delegate string[] ReturnArrayDelegate (int i);
989 [DllImport ("libtest", EntryPoint="mono_test_marshal_return_string_array_delegate")]
990 public static extern int mono_test_marshal_return_string_array_delegate (ReturnArrayDelegate d);
992 public static String[] return_array_delegate (int i) {
993 String[] arr = new String [2];
1001 public static String[] return_array_delegate_null (int i) {
1005 public static int test_0_marshal_return_string_array_delegate () {
1006 return mono_test_marshal_return_string_array_delegate (new ReturnArrayDelegate (return_array_delegate));
1009 public static int test_3_marshal_return_string_array_delegate_null () {
1010 return mono_test_marshal_return_string_array_delegate (new ReturnArrayDelegate (return_array_delegate_null));
1014 * Byref string marshalling
1016 public delegate int ByrefStringDelegate (ref string s);
1018 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_string_delegate")]
1019 public static extern int mono_test_marshal_byref_string_delegate (ByrefStringDelegate d);
1021 public static int byref_string_delegate (ref string s) {
1030 public static int test_0_marshal_byref_string_delegate () {
1031 return mono_test_marshal_byref_string_delegate (new ByrefStringDelegate (byref_string_delegate));