3 using System.Runtime.InteropServices;
4 using System.Runtime.CompilerServices;
8 public static int delegate_test (int a)
16 [StructLayout (LayoutKind.Sequential)]
17 public struct SimpleStruct {
22 [MarshalAs(UnmanagedType.LPWStr)]
26 [StructLayout (LayoutKind.Sequential)]
27 public struct SimpleStruct2 {
38 [StructLayout (LayoutKind.Sequential, Size=0)]
39 public struct EmptyStruct {
42 [StructLayout (LayoutKind.Sequential)]
43 public struct DelegateStruct {
45 public SimpleDelegate del;
46 [MarshalAs(UnmanagedType.FunctionPtr)]
47 public SimpleDelegate del2;
50 /* sparcv9 has complex conventions when passing structs with doubles in them
51 by value, some simple tests for them */
52 [StructLayout (LayoutKind.Sequential)]
58 [StructLayout (LayoutKind.Sequential)]
59 public struct MixedPoint {
64 [StructLayout (LayoutKind.Sequential)]
65 public class SimpleClass {
76 [StructLayout (LayoutKind.Sequential)]
77 public class EmptyClass {
80 [StructLayout (LayoutKind.Sequential)]
81 public struct LongAlignStruct {
87 [StructLayout(LayoutKind.Sequential)]
88 public class VectorList
94 [StructLayout (LayoutKind.Sequential)]
101 [StructLayout(LayoutKind.Sequential)]
109 public AsAnyStruct(int i, int j, int k, String s) {
117 [StructLayout(LayoutKind.Sequential)]
125 public AsAnyClass(int i, int j, int k, String s) {
132 [DllImport ("libnot-found", EntryPoint="not_found")]
133 public static extern int mono_library_not_found ();
135 [DllImport ("libtest", EntryPoint="not_found")]
136 public static extern int mono_entry_point_not_found ();
138 [DllImport ("libtest.dll", EntryPoint="mono_test_marshal_char")]
139 public static extern int mono_test_marshal_char_2 (char a1);
141 [DllImport ("test", EntryPoint="mono_test_marshal_char")]
142 public static extern int mono_test_marshal_char_3 (char a1);
144 [DllImport ("libtest", EntryPoint="mono_test_marshal_char")]
145 public static extern int mono_test_marshal_char (char a1);
147 [DllImport ("libtest", EntryPoint="mono_test_marshal_char_array", CharSet=CharSet.Unicode)]
148 public static extern int mono_test_marshal_char_array (char[] a1);
150 [DllImport ("libtest", EntryPoint="mono_test_marshal_bool_byref")]
151 public static extern int mono_test_marshal_bool_byref (int a, ref bool b, int c);
153 [DllImport ("libtest", EntryPoint="mono_test_marshal_array")]
154 public static extern int mono_test_marshal_array (int [] a1);
156 [DllImport ("libtest", EntryPoint="mono_test_marshal_empty_string_array")]
157 public static extern int mono_test_marshal_empty_string_array (string [] a1);
159 [DllImport ("libtest", EntryPoint="mono_test_marshal_string_array")]
160 public static extern int mono_test_marshal_string_array (string [] a1);
162 [DllImport ("libtest", EntryPoint="mono_test_marshal_unicode_string_array", CharSet=CharSet.Unicode)]
163 public static extern int mono_test_marshal_unicode_string_array (string [] a1, [MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr)]string [] a2);
165 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_array")]
166 public static extern int mono_test_marshal_stringbuilder_array (StringBuilder [] a1);
168 [DllImport ("libtest", EntryPoint="mono_test_marshal_inout_array")]
169 public static extern int mono_test_marshal_inout_array ([In, Out] int [] a1);
171 [DllImport ("libtest", EntryPoint="mono_test_marshal_out_array")]
172 public static extern int mono_test_marshal_out_array ([Out] [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int [] a1, int n);
174 [DllImport ("libtest", EntryPoint="mono_test_marshal_inout_nonblittable_array", CharSet = CharSet.Unicode)]
175 public static extern int mono_test_marshal_inout_nonblittable_array ([In, Out] char [] a1);
177 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct")]
178 public static extern int mono_test_marshal_struct (SimpleStruct ss);
180 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2")]
181 public static extern int mono_test_marshal_struct2 (SimpleStruct2 ss);
183 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2_2")]
184 public static extern int mono_test_marshal_struct2_2 (int i, int j, int k, SimpleStruct2 ss);
186 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_struct")]
187 public static extern int mono_test_marshal_byref_struct (ref SimpleStruct ss, bool a, bool b, bool c, String d);
189 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_struct")]
190 public static extern int mono_test_marshal_byref_struct_in ([In] ref SimpleStruct ss, bool a, bool b, bool c, String d);
192 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_struct")]
193 public static extern int mono_test_marshal_byref_struct_inout ([In, Out] ref SimpleStruct ss, bool a, bool b, bool c, String d);
195 [DllImport ("libtest", EntryPoint="mono_test_marshal_point")]
196 public static extern int mono_test_marshal_point (Point p);
198 [DllImport ("libtest", EntryPoint="mono_test_marshal_mixed_point")]
199 public static extern int mono_test_marshal_mixed_point (MixedPoint p);
201 [DllImport ("libtest", EntryPoint="mono_test_empty_struct")]
202 public static extern int mono_test_empty_struct (int a, EmptyStruct es, int b);
204 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct_array")]
205 public static extern int mono_test_marshal_struct_array (SimpleStruct2[] ss);
207 [DllImport ("libtest", EntryPoint="mono_test_marshal_long_align_struct_array")]
208 public static extern int mono_test_marshal_long_align_struct_array (LongAlignStruct[] ss);
210 [DllImport ("libtest", EntryPoint="mono_test_marshal_class")]
211 public static extern SimpleClass mono_test_marshal_class (int i, int j, int k, SimpleClass ss, int l);
213 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_class")]
214 public static extern int mono_test_marshal_byref_class (ref SimpleClass ss);
216 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate")]
217 public static extern int mono_test_marshal_delegate (SimpleDelegate d);
219 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate_struct")]
220 public static extern DelegateStruct mono_test_marshal_delegate_struct (DelegateStruct d);
222 [DllImport ("libtest", EntryPoint="mono_test_marshal_return_delegate")]
223 public static extern SimpleDelegate mono_test_marshal_return_delegate (SimpleDelegate d);
225 [DllImport ("libtest", EntryPoint="mono_test_return_vtype")]
226 public static extern SimpleStruct mono_test_return_vtype (IntPtr i);
228 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder")]
229 public static extern void mono_test_marshal_stringbuilder (StringBuilder sb, int len);
231 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_unicode", CharSet=CharSet.Unicode)]
232 public static extern void mono_test_marshal_stringbuilder_unicode (StringBuilder sb, int len);
234 [DllImport ("libtest", EntryPoint="mono_test_last_error", SetLastError=true)]
235 public static extern void mono_test_last_error (int err);
237 [DllImport ("libtest", EntryPoint="mono_test_asany")]
238 public static extern int mono_test_asany ([MarshalAs (UnmanagedType.AsAny)] object o, int what);
240 [DllImport ("libtest", EntryPoint="mono_test_asany", CharSet=CharSet.Unicode)]
241 public static extern int mono_test_asany_unicode ([MarshalAs (UnmanagedType.AsAny)] object o, int what);
243 [DllImport("libtest", EntryPoint="mono_test_marshal_asany_inout")]
244 static extern void mono_test_asany_in ([MarshalAs(UnmanagedType.AsAny)][In] object obj);
246 [DllImport("libtest", EntryPoint="mono_test_marshal_asany_inout")]
247 static extern void mono_test_asany_out ([MarshalAs(UnmanagedType.AsAny)][Out] object obj);
248 [DllImport("libtest", EntryPoint="mono_test_marshal_asany_inout")]
249 static extern void mono_test_asany_inout ([MarshalAs(UnmanagedType.AsAny)][In, Out] object obj);
251 [DllImport ("libtest")]
252 static extern int class_marshal_test0 (SimpleObj obj);
254 [DllImport ("libtest")]
255 static extern void class_marshal_test1 (out SimpleObj obj);
257 [DllImport ("libtest")]
258 static extern int class_marshal_test4 (SimpleObj obj);
260 [DllImport ("libtest")]
261 static extern int string_marshal_test0 (string str);
263 [DllImport ("libtest")]
264 static extern void string_marshal_test1 (out string str);
266 [DllImport ("libtest")]
267 static extern int string_marshal_test2 (ref string str);
269 [DllImport ("libtest")]
270 static extern int string_marshal_test3 (string str);
272 public delegate int SimpleDelegate (int a);
274 public static int Main (string[] args) {
275 return TestDriver.RunTests (typeof (Tests), args);
278 public static int test_0_marshal_char () {
279 return mono_test_marshal_char ('a');
282 public static int test_0_marshal_char_array () {
283 // a unicode char[] is implicitly marshalled as [Out]
284 char[] buf = new char [32];
285 mono_test_marshal_char_array (buf);
286 string s = new string (buf);
287 if (s.StartsWith ("abcdef"))
293 public static int test_1225_marshal_array () {
294 int [] a1 = new int [50];
295 for (int i = 0; i < 50; i++)
298 return mono_test_marshal_array (a1);
301 public static int test_1225_marshal_inout_array () {
302 int [] a1 = new int [50];
303 for (int i = 0; i < 50; i++)
306 int res = mono_test_marshal_inout_array (a1);
308 for (int i = 0; i < 50; i++)
309 if (a1 [i] != 50 - i) {
310 Console.WriteLine ("X: " + i + " " + a1 [i]);
317 public static int test_0_marshal_out_array () {
318 int [] a1 = new int [50];
320 int res = mono_test_marshal_out_array (a1, 0);
322 for (int i = 0; i < 50; i++)
324 Console.WriteLine ("X: " + i + " " + a1 [i]);
331 public static int test_0_marshal_inout_nonblittable_array () {
332 char [] a1 = new char [10];
333 for (int i = 0; i < 10; i++)
334 a1 [i] = "Hello, World" [i];
336 int res = mono_test_marshal_inout_nonblittable_array (a1);
338 for (int i = 0; i < 10; i++)
345 public static int test_0_marshal_struct () {
346 SimpleStruct ss = new SimpleStruct ();
350 return mono_test_marshal_struct (ss);
353 public static int test_0_marshal_struct2 () {
354 SimpleStruct2 ss2 = new SimpleStruct2 ();
362 return mono_test_marshal_struct2 (ss2);
365 public static int test_0_marshal_struct3 () {
366 SimpleStruct2 ss2 = new SimpleStruct2 ();
374 return mono_test_marshal_struct2_2 (10, 11, 12, ss2);
377 public static int test_0_marshal_empty_struct () {
378 EmptyStruct es = new EmptyStruct ();
380 if (mono_test_empty_struct (1, es, 2) != 0)
386 public static int test_0_marshal_struct_array () {
387 SimpleStruct2[] ss_arr = new SimpleStruct2 [2];
389 SimpleStruct2 ss2 = new SimpleStruct2 ();
408 return mono_test_marshal_struct_array (ss_arr);
411 public static int test_105_marshal_long_align_struct_array () {
412 LongAlignStruct[] ss_arr = new LongAlignStruct [2];
414 LongAlignStruct ss = new LongAlignStruct ();
427 return mono_test_marshal_long_align_struct_array (ss_arr);
430 /* Test classes as arguments and return values */
431 public static int test_0_marshal_class () {
432 SimpleClass ss = new SimpleClass ();
440 SimpleClass res = mono_test_marshal_class (10, 11, 12, ss, 14);
443 if (! (res.a == ss.a && res.b == ss.b && res.c == ss.c &&
444 res.d == ss.d && res.e == ss.e && res.f == ss.f &&
445 res.g == ss.g && res.h == ss.h))
448 /* Test null arguments and results */
449 res = mono_test_marshal_class (10, 11, 12, null, 14);
456 public static int test_0_marshal_byref_class () {
457 SimpleClass ss = new SimpleClass ();
465 int res = mono_test_marshal_byref_class (ref ss);
466 if (ss.d != "TEST-RES")
472 public static int test_0_marshal_delegate () {
473 SimpleDelegate d = new SimpleDelegate (delegate_test);
475 return mono_test_marshal_delegate (d);
478 public static int test_0_marshal_return_delegate () {
479 SimpleDelegate d = new SimpleDelegate (delegate_test);
481 SimpleDelegate d2 = mono_test_marshal_return_delegate (d);
486 public static int test_0_marshal_delegate_struct () {
487 DelegateStruct s = new DelegateStruct ();
490 s.del = new SimpleDelegate (delegate_test);
491 s.del2 = new SimpleDelegate (delegate_test);
493 DelegateStruct res = mono_test_marshal_delegate_struct (s);
497 if (res.del (2) != 0)
499 if (res.del2 (2) != 0)
505 public static int test_0_marshal_byref_struct () {
506 SimpleStruct s = new SimpleStruct ();
513 int res = mono_test_marshal_byref_struct (ref s, true, false, true, "ABC");
516 if (s.a != false || s.b != true || s.c != false || s.d != "DEF")
521 public static int test_0_marshal_byref_struct_in () {
522 SimpleStruct s = new SimpleStruct ();
529 int res = mono_test_marshal_byref_struct_in (ref s, true, false, true, "ABC");
532 if (s.a != true || s.b != false || s.c != true || s.d != "ABC")
537 public static int test_0_marshal_byref_struct_inout () {
538 SimpleStruct s = new SimpleStruct ();
545 int res = mono_test_marshal_byref_struct_inout (ref s, true, false, true, "ABC");
548 if (s.a != false || s.b != true || s.c != false || s.d != "DEF")
553 public static int test_0_marshal_point () {
554 Point pt = new Point();
558 return mono_test_marshal_point(pt);
561 public static int test_0_marshal_mixed_point () {
562 MixedPoint mpt = new MixedPoint();
566 return mono_test_marshal_mixed_point(mpt);
569 public static int test_0_marshal_bool_byref () {
571 if (mono_test_marshal_bool_byref (99, ref b, 100) != 1)
574 if (mono_test_marshal_bool_byref (99, ref b, 100) != 0)
582 public static int test_0_return_vtype () {
583 SimpleStruct ss = mono_test_return_vtype (new IntPtr (5));
585 if (!ss.a && ss.b && !ss.c && ss.d == "TEST" && ss.d2 == "TEST2")
591 public static int test_0_marshal_stringbuilder () {
592 StringBuilder sb = new StringBuilder(255);
594 mono_test_marshal_stringbuilder (sb, sb.Capacity);
595 String res = sb.ToString();
597 if (res != "This is my message. Isn't it nice?")
603 public static int test_0_marshal_stringbuilder_unicode () {
604 StringBuilder sb = new StringBuilder(255);
605 mono_test_marshal_stringbuilder_unicode (sb, sb.Capacity);
606 String res = sb.ToString();
608 if (res != "This is my message. Isn't it nice?")
614 public static int test_0_marshal_empty_string_array () {
615 return mono_test_marshal_empty_string_array (null);
618 public static int test_0_marshal_string_array () {
619 return mono_test_marshal_string_array (new String [] { "ABC", "DEF" });
622 public static int test_0_marshal_unicode_string_array () {
623 return mono_test_marshal_unicode_string_array (new String [] { "ABC", "DEF" }, new String [] { "ABC", "DEF" });
626 public static int test_0_marshal_stringbuilder_array () {
627 StringBuilder sb1 = new StringBuilder ("ABC");
628 StringBuilder sb2 = new StringBuilder ("DEF");
630 int res = mono_test_marshal_stringbuilder_array (new StringBuilder [] { sb1, sb2 });
633 if (sb1.ToString () != "DEF")
635 if (sb2.ToString () != "ABC")
640 public static int test_0_last_error () {
641 mono_test_last_error (5);
642 if (Marshal.GetLastWin32Error () == 5)
648 public static int test_0_library_not_found () {
651 mono_entry_point_not_found ();
654 catch (EntryPointNotFoundException) {
660 public static int test_0_entry_point_not_found () {
663 mono_library_not_found ();
666 catch (DllNotFoundException) {
672 /* Check that the runtime trims .dll from the library name */
673 public static int test_0_trim_dll_from_name () {
675 mono_test_marshal_char_2 ('A');
680 /* Check that the runtime adds lib to to the library name */
681 public static int test_0_add_lib_to_name () {
683 mono_test_marshal_char_3 ('A');
692 public static int test_0_asany () {
693 if (mono_test_asany (5, 1) != 0)
696 if (mono_test_asany ("ABC", 2) != 0)
699 SimpleStruct2 ss2 = new SimpleStruct2 ();
707 if (mono_test_asany (ss2, 3) != 0)
710 if (mono_test_asany_unicode ("ABC", 4) != 0)
716 mono_test_asany (c, 0);
719 catch (ArgumentException) {
723 mono_test_asany (new Object (), 0);
726 catch (ArgumentException) {
732 /* AsAny marshalling + [In, Out] */
734 public static int test_0_asany_in () {
736 AsAnyStruct str = new AsAnyStruct(1,2,3, "ABC");
737 mono_test_asany_in (str);
740 AsAnyClass cls = new AsAnyClass(1,2,3, "ABC");
741 mono_test_asany_in (cls);
742 if ((cls.i != 1) || (cls.j != 2) || (cls.k != 3))
746 object obj = new AsAnyStruct(1,2,3, "ABC");
747 mono_test_asany_in (obj);
748 str = (AsAnyStruct)obj;
749 if ((str.i != 1) || (str.j != 2) || (str.k != 3))
755 public static int test_0_asany_out () {
757 AsAnyStruct str = new AsAnyStruct(1,2,3, "ABC");
758 mono_test_asany_out (str);
761 AsAnyClass cls = new AsAnyClass(1,2,3, "ABC");
762 mono_test_asany_out (cls);
763 if ((cls.i != 10) || (cls.j != 20) || (cls.k != 30))
767 object obj = new AsAnyStruct(1,2,3, "ABC");
768 mono_test_asany_out (obj);
769 str = (AsAnyStruct)obj;
770 if ((str.i != 10) || (str.j != 20) || (str.k != 30))
776 public static int test_0_asany_inout () {
778 AsAnyStruct str = new AsAnyStruct(1,2,3, "ABC");
779 mono_test_asany_inout (str);
782 AsAnyClass cls = new AsAnyClass(1,2,3, "ABC");
783 mono_test_asany_inout (cls);
784 if ((cls.i != 10) || (cls.j != 20) || (cls.k != 30))
788 object obj = new AsAnyStruct(1,2,3, "ABC");
789 mono_test_asany_inout (obj);
790 str = (AsAnyStruct)obj;
791 if ((str.i != 10) || (str.j != 20) || (str.k != 30))
797 /* Byref String Array */
799 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_string_array")]
800 public static extern int mono_test_marshal_byref_string_array (ref string[] data);
802 public static int test_0_byref_string_array () {
806 if (mono_test_marshal_byref_string_array (ref arr) != 0)
809 arr = new string[] { "Alpha", "Beta", "Gamma" };
811 if (mono_test_marshal_byref_string_array (ref arr) != 1)
814 /* FIXME: Test returned array and out case */
820 * AMD64 small structs-by-value tests.
823 /* TEST 1: 16 byte long INTEGER struct */
825 [StructLayout(LayoutKind.Sequential)]
826 public struct Amd64Struct1 {
833 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct1")]
834 public static extern Amd64Struct1 mono_test_marshal_amd64_pass_return_struct1 (Amd64Struct1 s);
836 public static int test_0_amd64_struct1 () {
837 Amd64Struct1 s = new Amd64Struct1 ();
843 Amd64Struct1 s2 = mono_test_marshal_amd64_pass_return_struct1 (s);
845 return ((s2.i == 6) && (s2.j == -4) && (s2.k == 0x1000000) && (s2.l == 0x10000000)) ? 0 : 1;
848 /* TEST 2: 8 byte long INTEGER struct */
850 [StructLayout(LayoutKind.Sequential)]
851 public struct Amd64Struct2 {
856 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct2")]
857 public static extern Amd64Struct2 mono_test_marshal_amd64_pass_return_struct2 (Amd64Struct2 s);
859 public static int test_0_amd64_struct2 () {
860 Amd64Struct2 s = new Amd64Struct2 ();
864 Amd64Struct2 s2 = mono_test_marshal_amd64_pass_return_struct2 (s);
866 return ((s2.i == 6) && (s2.j == -4)) ? 0 : 1;
869 /* TEST 3: 4 byte long INTEGER struct */
871 [StructLayout(LayoutKind.Sequential)]
872 public struct Amd64Struct3 {
876 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct3")]
877 public static extern Amd64Struct3 mono_test_marshal_amd64_pass_return_struct3 (Amd64Struct3 s);
879 public static int test_0_amd64_struct3 () {
880 Amd64Struct3 s = new Amd64Struct3 ();
883 Amd64Struct3 s2 = mono_test_marshal_amd64_pass_return_struct3 (s);
885 return (s2.i == -4) ? 0 : 1;
888 /* Test 4: 16 byte long FLOAT struct */
890 [StructLayout(LayoutKind.Sequential)]
891 public struct Amd64Struct4 {
892 public double d1, d2;
895 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct4")]
896 public static extern Amd64Struct4 mono_test_marshal_amd64_pass_return_struct4 (Amd64Struct4 s);
898 public static int test_0_amd64_struct4 () {
899 Amd64Struct4 s = new Amd64Struct4 ();
903 Amd64Struct4 s2 = mono_test_marshal_amd64_pass_return_struct4 (s);
905 return (s2.d1 == 6.0 && s2.d2 == -4.0) ? 0 : 1;
912 /* Test 5: Float HFA */
914 [StructLayout(LayoutKind.Sequential)]
915 public struct TestStruct5 {
919 [DllImport ("libtest", EntryPoint="mono_test_marshal_ia64_pass_return_struct5")]
920 public static extern TestStruct5 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, TestStruct5 s, double f3, double f4);
922 public static int test_0_ia64_struct5 () {
923 TestStruct5 s = new TestStruct5 ();
927 TestStruct5 s2 = mono_test_marshal_ia64_pass_return_struct5 (1.0, 2.0, s, 3.0, 4.0);
929 return (s2.d1 == 8.0 && s2.d2 == 2.0) ? 0 : 1;
932 /* Test 6: Double HFA */
934 [StructLayout(LayoutKind.Sequential)]
935 public struct TestStruct6 {
936 public double d1, d2;
939 [DllImport ("libtest", EntryPoint="mono_test_marshal_ia64_pass_return_struct6")]
940 public static extern TestStruct6 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, TestStruct6 s, double f3, double f4);
942 public static int test_0_ia64_struct6 () {
943 TestStruct6 s = new TestStruct6 ();
947 TestStruct6 s2 = mono_test_marshal_ia64_pass_return_struct6 (1.0, 2.0, s, 3.0, 4.0);
949 return (s2.d1 == 9.0 && s2.d2 == 1.0) ? 0 : 1;
952 /* Blittable class */
953 [DllImport("libtest")]
954 private static extern VectorList TestVectorList (VectorList vl);
956 public static int test_0_marshal_blittable_class () {
957 VectorList v1 = new VectorList ();
959 /* Since it is blittable, it looks like it is passed as in/out */
960 VectorList v2 = TestVectorList (v1);
962 if (v1.a != 2 || v1.b != 3)
965 if (v2.a != 2 || v2.b != 3)
971 public static int test_0_marshal_byval_class () {
972 SimpleObj obj0 = new SimpleObj ();
976 if (class_marshal_test0 (obj0) != 0)
982 public static int test_0_marshal_byval_class_null () {
983 if (class_marshal_test4 (null) != 0)
989 public static int test_0_marshal_out_class () {
992 class_marshal_test1 (out obj1);
994 if (obj1.str != "ABC")
1003 public static int test_0_marshal_string () {
1004 return string_marshal_test0 ("TEST0");
1007 public static int test_0_marshal_out_string () {
1010 string_marshal_test1 (out res);
1018 public static int test_0_marshal_byref_string () {
1019 string res = "TEST1";
1021 return string_marshal_test2 (ref res);
1024 public static int test_0_marshal_null_string () {
1025 return string_marshal_test3 (null);
1028 [DllImport ("libtest", EntryPoint="mono_test_stdcall_name_mangling", CallingConvention=CallingConvention.StdCall)]
1029 public static extern int mono_test_stdcall_name_mangling (int a, int b, int c);
1031 public static int test_0_stdcall_name_mangling () {
1032 return mono_test_stdcall_name_mangling (0, 1, 2) == 3 ? 0 : 1;
1036 * Pointers to structures can not be passed
1039 public struct CharInfo {
1040 public char Character;
1041 public short Attributes;
1044 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct")]
1045 public static unsafe extern int mono_test_marshal_ptr_to_struct (CharInfo *ptr);
1047 public static unsafe int test_0_marshal_ptr_to_struct () {
1048 CharInfo [] buffer = new CharInfo [1];
1049 fixed (CharInfo *ptr = &buffer [0]) {
1051 mono_test_marshal_ptr_to_struct (ptr);
1054 catch (MarshalDirectiveException) {
1062 * LPWStr marshalling
1065 [DllImport("libtest", EntryPoint="test_lpwstr_marshal")]
1066 [return: MarshalAs(UnmanagedType.LPWStr)]
1067 private static extern string mono_test_marshal_lpwstr_marshal(
1068 [MarshalAs(UnmanagedType.LPWStr)] string s,
1071 [DllImport("libtest", EntryPoint="test_lpwstr_marshal", CharSet=CharSet.Unicode)]
1072 private static extern string mono_test_marshal_lpwstr_marshal2(
1076 public static int test_0_pass_return_lwpstr () {
1079 string res = mono_test_marshal_lpwstr_marshal (s, s.Length);
1084 string res2 = mono_test_marshal_lpwstr_marshal2 (s, s.Length);
1093 * Byref bool marshalling
1096 [DllImport("libtest")]
1097 extern static int marshal_test_ref_bool
1100 [MarshalAs(UnmanagedType.I1)] ref bool b1,
1101 [MarshalAs(UnmanagedType.VariantBool)] ref bool b2,
1105 public static int test_0_pass_byref_bool () {
1106 for (int i = 0; i < 8; i++)
1108 bool b1 = (i & 4) != 0;
1109 bool b2 = (i & 2) != 0;
1110 bool b3 = (i & 1) != 0;
1111 bool orig_b1 = b1, orig_b2 = b2, orig_b3 = b3;
1112 if (marshal_test_ref_bool(i, ref b1, ref b2, ref b3) != 0)
1126 * Bool struct field marshalling
1132 [MarshalAs(UnmanagedType.I1)] public bool b1;
1133 [MarshalAs(UnmanagedType.VariantBool)] public bool b2;
1137 [DllImport("libtest")]
1138 extern static int marshal_test_bool_struct(ref BoolStruct s);
1140 public static int test_0_pass_bool_in_struct () {
1141 for (int i = 0; i < 8; i++)
1143 BoolStruct s = new BoolStruct();
1145 s.b1 = (i & 4) != 0;
1146 s.b2 = (i & 2) != 0;
1147 s.b3 = (i & 1) != 0;
1148 BoolStruct orig = s;
1149 if (marshal_test_bool_struct(ref s) != 0)
1151 if (s.b1 != !orig.b1)
1153 if (s.b2 != !orig.b2)
1155 if (s.b3 != !orig.b3)
1163 * Invoking pinvoke methods through delegates
1166 delegate int MyDelegate (string name);
1168 [DllImport ("libtest", EntryPoint="mono_test_puts_static")]
1169 public static extern int puts_static (string name);
1171 public static int test_0_invoke_pinvoke_through_delegate () {
1172 puts_static ("A simple Test for PInvoke 1");
1174 MyDelegate d = new MyDelegate (puts_static);
1175 d ("A simple Test for PInvoke 2");
1177 object [] args = {"A simple Test for PInvoke 3"};
1178 d.DynamicInvoke (args);
1184 * Missing virtual pinvoke methods
1189 public virtual object MyClone ()
1195 public class T2 : T {
1196 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1197 public override extern object MyClone ();
1200 public static int test_0_missing_virtual_pinvoke_method () {
1205 } catch (Exception ex) {