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 [DllImport ("libnot-found", EntryPoint="not_found")]
102 public static extern int mono_library_not_found ();
104 [DllImport ("libtest", EntryPoint="not_found")]
105 public static extern int mono_entry_point_not_found ();
107 [DllImport ("libtest.dll", EntryPoint="mono_test_marshal_char")]
108 public static extern int mono_test_marshal_char_2 (char a1);
110 [DllImport ("test", EntryPoint="mono_test_marshal_char")]
111 public static extern int mono_test_marshal_char_3 (char a1);
113 [DllImport ("libtest", EntryPoint="mono_test_marshal_char")]
114 public static extern int mono_test_marshal_char (char a1);
116 [DllImport ("libtest", EntryPoint="mono_test_marshal_char_array", CharSet=CharSet.Unicode)]
117 public static extern int mono_test_marshal_char_array (char[] a1);
119 [DllImport ("libtest", EntryPoint="mono_test_marshal_bool_byref")]
120 public static extern int mono_test_marshal_bool_byref (int a, ref bool b, int c);
122 [DllImport ("libtest", EntryPoint="mono_test_marshal_array")]
123 public static extern int mono_test_marshal_array (int [] a1);
125 [DllImport ("libtest", EntryPoint="mono_test_marshal_empty_string_array")]
126 public static extern int mono_test_marshal_empty_string_array (string [] a1);
128 [DllImport ("libtest", EntryPoint="mono_test_marshal_string_array")]
129 public static extern int mono_test_marshal_string_array (string [] a1);
131 [DllImport ("libtest", EntryPoint="mono_test_marshal_unicode_string_array", CharSet=CharSet.Unicode)]
132 public static extern int mono_test_marshal_unicode_string_array (string [] a1, [MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr)]string [] a2);
134 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_array")]
135 public static extern int mono_test_marshal_stringbuilder_array (StringBuilder [] a1);
137 [DllImport ("libtest", EntryPoint="mono_test_marshal_inout_array")]
138 public static extern int mono_test_marshal_inout_array ([In, Out] int [] a1);
140 [DllImport ("libtest", EntryPoint="mono_test_marshal_out_array")]
141 public static extern int mono_test_marshal_out_array ([Out] [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int [] a1, int n);
143 [DllImport ("libtest", EntryPoint="mono_test_marshal_inout_nonblittable_array", CharSet = CharSet.Unicode)]
144 public static extern int mono_test_marshal_inout_nonblittable_array ([In, Out] char [] a1);
146 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct")]
147 public static extern int mono_test_marshal_struct (SimpleStruct ss);
149 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2")]
150 public static extern int mono_test_marshal_struct2 (SimpleStruct2 ss);
152 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2_2")]
153 public static extern int mono_test_marshal_struct2_2 (int i, int j, int k, SimpleStruct2 ss);
155 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_struct")]
156 public static extern int mono_test_marshal_byref_struct (ref SimpleStruct ss, bool a, bool b, bool c, String d);
158 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_struct")]
159 public static extern int mono_test_marshal_byref_struct_in ([In] ref SimpleStruct ss, bool a, bool b, bool c, String d);
161 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_struct")]
162 public static extern int mono_test_marshal_byref_struct_inout ([In, Out] ref SimpleStruct ss, bool a, bool b, bool c, String d);
164 [DllImport ("libtest", EntryPoint="mono_test_marshal_point")]
165 public static extern int mono_test_marshal_point (Point p);
167 [DllImport ("libtest", EntryPoint="mono_test_marshal_mixed_point")]
168 public static extern int mono_test_marshal_mixed_point (MixedPoint p);
170 [DllImport ("libtest", EntryPoint="mono_test_empty_struct")]
171 public static extern int mono_test_empty_struct (int a, EmptyStruct es, int b);
173 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct_array")]
174 public static extern int mono_test_marshal_struct_array (SimpleStruct2[] ss);
176 [DllImport ("libtest", EntryPoint="mono_test_marshal_long_align_struct_array")]
177 public static extern int mono_test_marshal_long_align_struct_array (LongAlignStruct[] ss);
179 [DllImport ("libtest", EntryPoint="mono_test_marshal_class")]
180 public static extern SimpleClass mono_test_marshal_class (int i, int j, int k, SimpleClass ss, int l);
182 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_class")]
183 public static extern int mono_test_marshal_byref_class (ref SimpleClass ss);
185 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate")]
186 public static extern int mono_test_marshal_delegate (SimpleDelegate d);
188 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate_struct")]
189 public static extern DelegateStruct mono_test_marshal_delegate_struct (DelegateStruct d);
191 [DllImport ("libtest", EntryPoint="mono_test_marshal_return_delegate")]
192 public static extern SimpleDelegate mono_test_marshal_return_delegate (SimpleDelegate d);
194 [DllImport ("libtest", EntryPoint="mono_test_return_vtype")]
195 public static extern SimpleStruct mono_test_return_vtype (IntPtr i);
197 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder")]
198 public static extern void mono_test_marshal_stringbuilder (StringBuilder sb, int len);
200 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_unicode", CharSet=CharSet.Unicode)]
201 public static extern void mono_test_marshal_stringbuilder_unicode (StringBuilder sb, int len);
203 [DllImport ("libtest", EntryPoint="mono_test_last_error", SetLastError=true)]
204 public static extern void mono_test_last_error (int err);
206 [DllImport ("libtest", EntryPoint="mono_test_asany")]
207 public static extern int mono_test_asany ([MarshalAs (UnmanagedType.AsAny)] object o, int what);
209 [DllImport ("libtest", EntryPoint="mono_test_asany", CharSet=CharSet.Unicode)]
210 public static extern int mono_test_asany_unicode ([MarshalAs (UnmanagedType.AsAny)] object o, int what);
212 [DllImport ("libtest")]
213 static extern int class_marshal_test0 (SimpleObj obj);
215 [DllImport ("libtest")]
216 static extern void class_marshal_test1 (out SimpleObj obj);
218 [DllImport ("libtest")]
219 static extern int class_marshal_test4 (SimpleObj obj);
221 [DllImport ("libtest")]
222 static extern int string_marshal_test0 (string str);
224 [DllImport ("libtest")]
225 static extern void string_marshal_test1 (out string str);
227 [DllImport ("libtest")]
228 static extern int string_marshal_test2 (ref string str);
230 [DllImport ("libtest")]
231 static extern int string_marshal_test3 (string str);
233 public delegate int SimpleDelegate (int a);
235 public static int Main (string[] args) {
236 return TestDriver.RunTests (typeof (Tests), args);
239 public static int test_0_marshal_char () {
240 return mono_test_marshal_char ('a');
243 public static int test_0_marshal_char_array () {
244 // a unicode char[] is implicitly marshalled as [Out]
245 char[] buf = new char [32];
246 mono_test_marshal_char_array (buf);
247 string s = new string (buf);
248 if (s.StartsWith ("abcdef"))
254 public static int test_1225_marshal_array () {
255 int [] a1 = new int [50];
256 for (int i = 0; i < 50; i++)
259 return mono_test_marshal_array (a1);
262 public static int test_1225_marshal_inout_array () {
263 int [] a1 = new int [50];
264 for (int i = 0; i < 50; i++)
267 int res = mono_test_marshal_inout_array (a1);
269 for (int i = 0; i < 50; i++)
270 if (a1 [i] != 50 - i) {
271 Console.WriteLine ("X: " + i + " " + a1 [i]);
278 public static int test_0_marshal_out_array () {
279 int [] a1 = new int [50];
281 int res = mono_test_marshal_out_array (a1, 0);
283 for (int i = 0; i < 50; i++)
285 Console.WriteLine ("X: " + i + " " + a1 [i]);
292 public static int test_0_marshal_inout_nonblittable_array () {
293 char [] a1 = new char [10];
294 for (int i = 0; i < 10; i++)
295 a1 [i] = "Hello, World" [i];
297 int res = mono_test_marshal_inout_nonblittable_array (a1);
299 for (int i = 0; i < 10; i++)
306 public static int test_0_marshal_struct () {
307 SimpleStruct ss = new SimpleStruct ();
311 return mono_test_marshal_struct (ss);
314 public static int test_0_marshal_struct2 () {
315 SimpleStruct2 ss2 = new SimpleStruct2 ();
323 return mono_test_marshal_struct2 (ss2);
326 public static int test_0_marshal_struct3 () {
327 SimpleStruct2 ss2 = new SimpleStruct2 ();
335 return mono_test_marshal_struct2_2 (10, 11, 12, ss2);
338 public static int test_0_marshal_empty_struct () {
339 EmptyStruct es = new EmptyStruct ();
341 if (mono_test_empty_struct (1, es, 2) != 0)
347 public static int test_0_marshal_struct_array () {
348 SimpleStruct2[] ss_arr = new SimpleStruct2 [2];
350 SimpleStruct2 ss2 = new SimpleStruct2 ();
369 return mono_test_marshal_struct_array (ss_arr);
372 public static int test_105_marshal_long_align_struct_array () {
373 LongAlignStruct[] ss_arr = new LongAlignStruct [2];
375 LongAlignStruct ss = new LongAlignStruct ();
388 return mono_test_marshal_long_align_struct_array (ss_arr);
391 /* Test classes as arguments and return values */
392 public static int test_0_marshal_class () {
393 SimpleClass ss = new SimpleClass ();
401 SimpleClass res = mono_test_marshal_class (10, 11, 12, ss, 14);
404 if (! (res.a == ss.a && res.b == ss.b && res.c == ss.c &&
405 res.d == ss.d && res.e == ss.e && res.f == ss.f &&
406 res.g == ss.g && res.h == ss.h))
409 /* Test null arguments and results */
410 res = mono_test_marshal_class (10, 11, 12, null, 14);
417 public static int test_0_marshal_byref_class () {
418 SimpleClass ss = new SimpleClass ();
426 int res = mono_test_marshal_byref_class (ref ss);
427 if (ss.d != "TEST-RES")
433 public static int test_0_marshal_delegate () {
434 SimpleDelegate d = new SimpleDelegate (delegate_test);
436 return mono_test_marshal_delegate (d);
439 public static int test_0_marshal_return_delegate () {
440 SimpleDelegate d = new SimpleDelegate (delegate_test);
442 SimpleDelegate d2 = mono_test_marshal_return_delegate (d);
447 public static int test_0_marshal_delegate_struct () {
448 DelegateStruct s = new DelegateStruct ();
451 s.del = new SimpleDelegate (delegate_test);
452 s.del2 = new SimpleDelegate (delegate_test);
454 DelegateStruct res = mono_test_marshal_delegate_struct (s);
458 if (res.del (2) != 0)
460 if (res.del2 (2) != 0)
466 public static int test_0_marshal_byref_struct () {
467 SimpleStruct s = new SimpleStruct ();
474 int res = mono_test_marshal_byref_struct (ref s, true, false, true, "ABC");
477 if (s.a != false || s.b != true || s.c != false || s.d != "DEF")
482 public static int test_0_marshal_byref_struct_in () {
483 SimpleStruct s = new SimpleStruct ();
490 int res = mono_test_marshal_byref_struct_in (ref s, true, false, true, "ABC");
493 if (s.a != true || s.b != false || s.c != true || s.d != "ABC")
498 public static int test_0_marshal_byref_struct_inout () {
499 SimpleStruct s = new SimpleStruct ();
506 int res = mono_test_marshal_byref_struct_inout (ref s, true, false, true, "ABC");
509 if (s.a != false || s.b != true || s.c != false || s.d != "DEF")
514 public static int test_0_marshal_point () {
515 Point pt = new Point();
519 return mono_test_marshal_point(pt);
522 public static int test_0_marshal_mixed_point () {
523 MixedPoint mpt = new MixedPoint();
527 return mono_test_marshal_mixed_point(mpt);
530 public static int test_0_marshal_bool_byref () {
532 if (mono_test_marshal_bool_byref (99, ref b, 100) != 1)
535 if (mono_test_marshal_bool_byref (99, ref b, 100) != 0)
543 public static int test_0_return_vtype () {
544 SimpleStruct ss = mono_test_return_vtype (new IntPtr (5));
546 if (!ss.a && ss.b && !ss.c && ss.d == "TEST" && ss.d2 == "TEST2")
552 public static int test_0_marshal_stringbuilder () {
553 StringBuilder sb = new StringBuilder(255);
555 mono_test_marshal_stringbuilder (sb, sb.Capacity);
556 String res = sb.ToString();
558 if (res != "This is my message. Isn't it nice?")
564 public static int test_0_marshal_stringbuilder_unicode () {
565 StringBuilder sb = new StringBuilder(255);
566 mono_test_marshal_stringbuilder_unicode (sb, sb.Capacity);
567 String res = sb.ToString();
569 if (res != "This is my message. Isn't it nice?")
575 public static int test_0_marshal_empty_string_array () {
576 return mono_test_marshal_empty_string_array (null);
579 public static int test_0_marshal_string_array () {
580 return mono_test_marshal_string_array (new String [] { "ABC", "DEF" });
583 public static int test_0_marshal_unicode_string_array () {
584 return mono_test_marshal_unicode_string_array (new String [] { "ABC", "DEF" }, new String [] { "ABC", "DEF" });
587 public static int test_0_marshal_stringbuilder_array () {
588 StringBuilder sb1 = new StringBuilder ("ABC");
589 StringBuilder sb2 = new StringBuilder ("DEF");
591 int res = mono_test_marshal_stringbuilder_array (new StringBuilder [] { sb1, sb2 });
594 if (sb1.ToString () != "DEF")
596 if (sb2.ToString () != "ABC")
601 public static int test_0_last_error () {
602 mono_test_last_error (5);
603 if (Marshal.GetLastWin32Error () == 5)
609 public static int test_0_library_not_found () {
612 mono_entry_point_not_found ();
615 catch (EntryPointNotFoundException) {
621 public static int test_0_entry_point_not_found () {
624 mono_library_not_found ();
627 catch (DllNotFoundException) {
633 /* Check that the runtime trims .dll from the library name */
634 public static int test_0_trim_dll_from_name () {
636 mono_test_marshal_char_2 ('A');
641 /* Check that the runtime adds lib to to the library name */
642 public static int test_0_add_lib_to_name () {
644 mono_test_marshal_char_3 ('A');
653 public static int test_0_asany () {
654 if (mono_test_asany (5, 1) != 0)
657 if (mono_test_asany ("ABC", 2) != 0)
660 SimpleStruct2 ss2 = new SimpleStruct2 ();
668 if (mono_test_asany (ss2, 3) != 0)
671 if (mono_test_asany_unicode ("ABC", 4) != 0)
677 mono_test_asany (c, 0);
680 catch (ArgumentException) {
684 mono_test_asany (new Object (), 0);
687 catch (ArgumentException) {
693 /* Byref String Array */
695 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_string_array")]
696 public static extern int mono_test_marshal_byref_string_array (ref string[] data);
698 public static int test_0_byref_string_array () {
702 if (mono_test_marshal_byref_string_array (ref arr) != 0)
705 arr = new string[] { "Alpha", "Beta", "Gamma" };
707 if (mono_test_marshal_byref_string_array (ref arr) != 1)
710 /* FIXME: Test returned array and out case */
716 * AMD64 small structs-by-value tests.
719 /* TEST 1: 16 byte long INTEGER struct */
721 [StructLayout(LayoutKind.Sequential)]
722 public struct Amd64Struct1 {
729 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct1")]
730 public static extern Amd64Struct1 mono_test_marshal_amd64_pass_return_struct1 (Amd64Struct1 s);
732 public static int test_0_amd64_struct1 () {
733 Amd64Struct1 s = new Amd64Struct1 ();
739 Amd64Struct1 s2 = mono_test_marshal_amd64_pass_return_struct1 (s);
741 return ((s2.i == 6) && (s2.j == -4) && (s2.k == 0x1000000) && (s2.l == 0x10000000)) ? 0 : 1;
744 /* TEST 2: 8 byte long INTEGER struct */
746 [StructLayout(LayoutKind.Sequential)]
747 public struct Amd64Struct2 {
752 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct2")]
753 public static extern Amd64Struct2 mono_test_marshal_amd64_pass_return_struct2 (Amd64Struct2 s);
755 public static int test_0_amd64_struct2 () {
756 Amd64Struct2 s = new Amd64Struct2 ();
760 Amd64Struct2 s2 = mono_test_marshal_amd64_pass_return_struct2 (s);
762 return ((s2.i == 6) && (s2.j == -4)) ? 0 : 1;
765 /* TEST 3: 4 byte long INTEGER struct */
767 [StructLayout(LayoutKind.Sequential)]
768 public struct Amd64Struct3 {
772 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct3")]
773 public static extern Amd64Struct3 mono_test_marshal_amd64_pass_return_struct3 (Amd64Struct3 s);
775 public static int test_0_amd64_struct3 () {
776 Amd64Struct3 s = new Amd64Struct3 ();
779 Amd64Struct3 s2 = mono_test_marshal_amd64_pass_return_struct3 (s);
781 return (s2.i == -4) ? 0 : 1;
784 /* Test 4: 16 byte long FLOAT struct */
786 [StructLayout(LayoutKind.Sequential)]
787 public struct Amd64Struct4 {
788 public double d1, d2;
791 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct4")]
792 public static extern Amd64Struct4 mono_test_marshal_amd64_pass_return_struct4 (Amd64Struct4 s);
794 public static int test_0_amd64_struct4 () {
795 Amd64Struct4 s = new Amd64Struct4 ();
799 Amd64Struct4 s2 = mono_test_marshal_amd64_pass_return_struct4 (s);
801 return (s2.d1 == 6.0 && s2.d2 == -4.0) ? 0 : 1;
808 /* Test 5: Float HFA */
810 [StructLayout(LayoutKind.Sequential)]
811 public struct TestStruct5 {
815 [DllImport ("libtest", EntryPoint="mono_test_marshal_ia64_pass_return_struct5")]
816 public static extern TestStruct5 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, TestStruct5 s, double f3, double f4);
818 public static int test_0_ia64_struct5 () {
819 TestStruct5 s = new TestStruct5 ();
823 TestStruct5 s2 = mono_test_marshal_ia64_pass_return_struct5 (1.0, 2.0, s, 3.0, 4.0);
825 return (s2.d1 == 8.0 && s2.d2 == 2.0) ? 0 : 1;
828 /* Test 6: Double HFA */
830 [StructLayout(LayoutKind.Sequential)]
831 public struct TestStruct6 {
832 public double d1, d2;
835 [DllImport ("libtest", EntryPoint="mono_test_marshal_ia64_pass_return_struct6")]
836 public static extern TestStruct6 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, TestStruct6 s, double f3, double f4);
838 public static int test_0_ia64_struct6 () {
839 TestStruct6 s = new TestStruct6 ();
843 TestStruct6 s2 = mono_test_marshal_ia64_pass_return_struct6 (1.0, 2.0, s, 3.0, 4.0);
845 return (s2.d1 == 9.0 && s2.d2 == 1.0) ? 0 : 1;
848 /* Blittable class */
849 [DllImport("libtest")]
850 private static extern VectorList TestVectorList (VectorList vl);
852 public static int test_0_marshal_blittable_class () {
853 VectorList v1 = new VectorList ();
855 /* Since it is blittable, it looks like it is passed as in/out */
856 VectorList v2 = TestVectorList (v1);
858 if (v1.a != 2 || v1.b != 3)
861 if (v2.a != 2 || v2.b != 3)
867 public static int test_0_marshal_byval_class () {
868 SimpleObj obj0 = new SimpleObj ();
872 if (class_marshal_test0 (obj0) != 0)
878 public static int test_0_marshal_byval_class_null () {
879 if (class_marshal_test4 (null) != 0)
885 public static int test_0_marshal_out_class () {
888 class_marshal_test1 (out obj1);
890 if (obj1.str != "ABC")
899 public static int test_0_marshal_string () {
900 return string_marshal_test0 ("TEST0");
903 public static int test_0_marshal_out_string () {
906 string_marshal_test1 (out res);
914 public static int test_0_marshal_byref_string () {
915 string res = "TEST1";
917 return string_marshal_test2 (ref res);
920 public static int test_0_marshal_null_string () {
921 return string_marshal_test3 (null);
924 [DllImport ("libtest", EntryPoint="mono_test_stdcall_name_mangling", CallingConvention=CallingConvention.StdCall)]
925 public static extern int mono_test_stdcall_name_mangling (int a, int b, int c);
927 public static int test_0_stdcall_name_mangling () {
928 return mono_test_stdcall_name_mangling (0, 1, 2) == 3 ? 0 : 1;
932 * Pointers to structures can not be passed
935 public struct CharInfo {
936 public char Character;
937 public short Attributes;
940 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct")]
941 public static unsafe extern int mono_test_marshal_ptr_to_struct (CharInfo *ptr);
943 public static unsafe int test_0_marshal_ptr_to_struct () {
944 CharInfo [] buffer = new CharInfo [1];
945 fixed (CharInfo *ptr = &buffer [0]) {
947 mono_test_marshal_ptr_to_struct (ptr);
950 catch (MarshalDirectiveException) {
961 [DllImport("libtest", EntryPoint="test_lpwstr_marshal")]
962 [return: MarshalAs(UnmanagedType.LPWStr)]
963 private static extern string mono_test_marshal_lpwstr_marshal(
964 [MarshalAs(UnmanagedType.LPWStr)] string s,
967 [DllImport("libtest", EntryPoint="test_lpwstr_marshal", CharSet=CharSet.Unicode)]
968 private static extern string mono_test_marshal_lpwstr_marshal2(
972 public static int test_0_pass_return_lwpstr () {
975 string res = mono_test_marshal_lpwstr_marshal (s, s.Length);
980 string res2 = mono_test_marshal_lpwstr_marshal2 (s, s.Length);
989 * Byref bool marshalling
992 [DllImport("libtest")]
993 extern static int marshal_test_ref_bool
996 [MarshalAs(UnmanagedType.I1)] ref bool b1,
997 [MarshalAs(UnmanagedType.VariantBool)] ref bool b2,
1001 public static int test_0_pass_byref_bool () {
1002 for (int i = 0; i < 8; i++)
1004 bool b1 = (i & 4) != 0;
1005 bool b2 = (i & 2) != 0;
1006 bool b3 = (i & 1) != 0;
1007 bool orig_b1 = b1, orig_b2 = b2, orig_b3 = b3;
1008 if (marshal_test_ref_bool(i, ref b1, ref b2, ref b3) != 0)
1022 * Bool struct field marshalling
1028 [MarshalAs(UnmanagedType.I1)] public bool b1;
1029 [MarshalAs(UnmanagedType.VariantBool)] public bool b2;
1033 [DllImport("libtest")]
1034 extern static int marshal_test_bool_struct(ref BoolStruct s);
1036 public static int test_0_pass_bool_in_struct () {
1037 for (int i = 0; i < 8; i++)
1039 BoolStruct s = new BoolStruct();
1041 s.b1 = (i & 4) != 0;
1042 s.b2 = (i & 2) != 0;
1043 s.b3 = (i & 1) != 0;
1044 BoolStruct orig = s;
1045 if (marshal_test_bool_struct(ref s) != 0)
1047 if (s.b1 != !orig.b1)
1049 if (s.b2 != !orig.b2)
1051 if (s.b3 != !orig.b3)
1059 * Invoking pinvoke methods through delegates
1062 delegate int MyDelegate (string name);
1064 [DllImport ("libtest", EntryPoint="mono_test_puts_static")]
1065 public static extern int puts_static (string name);
1067 public static int test_0_invoke_pinvoke_through_delegate () {
1068 puts_static ("A simple Test for PInvoke 1");
1070 MyDelegate d = new MyDelegate (puts_static);
1071 d ("A simple Test for PInvoke 2");
1073 object [] args = {"A simple Test for PInvoke 3"};
1074 d.DynamicInvoke (args);
1080 * Missing virtual pinvoke methods
1085 public virtual object MyClone ()
1091 public class T2 : T {
1092 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1093 public override extern object MyClone ();
1096 public static int test_0_missing_virtual_pinvoke_method () {
1101 } catch (Exception ex) {