2 // Copyright 2011 Xamarin Inc (http://www.xamarin.com).
3 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
8 using System.Runtime.InteropServices;
9 using System.Runtime.CompilerServices;
10 using System.Reflection.Emit;
12 public unsafe class Tests {
16 public static int delegate_test (int a)
24 public int delegate_test_instance (int a)
29 [StructLayout (LayoutKind.Sequential)]
30 public struct SimpleStruct {
35 [MarshalAs(UnmanagedType.LPWStr)]
39 [StructLayout (LayoutKind.Sequential)]
40 public struct SimpleStructGen<T> {
45 [MarshalAs(UnmanagedType.LPWStr)]
49 [StructLayout (LayoutKind.Sequential)]
50 public struct SimpleStruct2 {
61 [StructLayout (LayoutKind.Sequential, Size=0)]
62 public struct EmptyStruct {
65 [StructLayout (LayoutKind.Sequential, Size=1)]
66 public struct EmptyStructCpp {
69 [StructLayout (LayoutKind.Sequential)]
70 public struct DelegateStruct {
72 public SimpleDelegate del;
73 [MarshalAs(UnmanagedType.FunctionPtr)]
74 public SimpleDelegate del2;
75 [MarshalAs(UnmanagedType.FunctionPtr)]
76 public SimpleDelegate del3;
79 [StructLayout (LayoutKind.Sequential)]
80 public struct SingleDoubleStruct {
84 /* sparcv9 has complex conventions when passing structs with doubles in them
85 by value, some simple tests for them */
86 [StructLayout (LayoutKind.Sequential)]
92 [StructLayout (LayoutKind.Sequential)]
93 public struct MixedPoint {
98 [StructLayout (LayoutKind.Sequential)]
99 public struct TinyStruct {
100 public TinyStruct (int i)
107 [StructLayout (LayoutKind.Sequential)]
108 public class SimpleClass {
119 [StructLayout (LayoutKind.Sequential)]
120 public class EmptyClass {
123 [StructLayout (LayoutKind.Sequential)]
124 public struct LongAlignStruct {
130 [StructLayout(LayoutKind.Sequential)]
131 public class BlittableClass
137 [StructLayout (LayoutKind.Sequential)]
144 [StructLayout(LayoutKind.Sequential)]
152 public AsAnyStruct(int i, int j, int k, String s) {
160 [StructLayout(LayoutKind.Sequential)]
168 public AsAnyClass(int i, int j, int k, String s) {
175 [DllImport ("libnot-found", EntryPoint="not_found")]
176 public static extern int mono_library_not_found ();
178 [DllImport ("libtest", EntryPoint="not_found")]
179 public static extern int mono_entry_point_not_found ();
181 [DllImport ("libtest.dll", EntryPoint="mono_test_marshal_char")]
182 public static extern int mono_test_marshal_char_2 (char a1);
184 [DllImport ("test", EntryPoint="mono_test_marshal_char")]
185 public static extern int mono_test_marshal_char_3 (char a1);
187 [DllImport ("libtest", EntryPoint="mono_test_marshal_char")]
188 public static extern int mono_test_marshal_char (char a1);
190 [DllImport ("libtest", EntryPoint="mono_test_marshal_char_array", CharSet=CharSet.Unicode)]
191 public static extern int mono_test_marshal_char_array (char[] a1);
193 [DllImport ("libtest", EntryPoint="mono_test_marshal_bool_byref")]
194 public static extern int mono_test_marshal_bool_byref (int a, ref bool b, int c);
196 [DllImport ("libtest", EntryPoint="mono_test_marshal_bool_in_as_I1_U1")]
197 public static extern int mono_test_marshal_bool_in_as_I1 ([MarshalAs (UnmanagedType.I1)] bool bTrue, [MarshalAs (UnmanagedType.I1)] bool bFalse);
199 [DllImport ("libtest", EntryPoint="mono_test_marshal_bool_in_as_I1_U1")]
200 public static extern int mono_test_marshal_bool_in_as_U1 ([MarshalAs (UnmanagedType.U1)] bool bTrue, [MarshalAs (UnmanagedType.U1)] bool bFalse);
202 [DllImport ("libtest", EntryPoint="mono_test_marshal_bool_out_as_I1_U1")]
203 public static extern int mono_test_marshal_bool_out_as_I1 ([MarshalAs (UnmanagedType.I1)] out bool bTrue, [MarshalAs (UnmanagedType.I1)] out bool bFalse);
205 [DllImport ("libtest", EntryPoint="mono_test_marshal_bool_out_as_I1_U1")]
206 public static extern int mono_test_marshal_bool_out_as_U1 ([MarshalAs (UnmanagedType.U1)] out bool bTrue, [MarshalAs (UnmanagedType.U1)] out bool bFalse);
208 [DllImport ("libtest", EntryPoint="mono_test_marshal_bool_ref_as_I1_U1")]
209 public static extern int mono_test_marshal_bool_ref_as_I1 ([MarshalAs (UnmanagedType.I1)] ref bool bTrue, [MarshalAs (UnmanagedType.I1)] ref bool bFalse);
211 [DllImport ("libtest", EntryPoint="mono_test_marshal_bool_ref_as_I1_U1")]
212 public static extern int mono_test_marshal_bool_ref_as_U1 ([MarshalAs (UnmanagedType.U1)] ref bool bTrue, [MarshalAs (UnmanagedType.U1)] ref bool bFalse);
214 [DllImport ("libtest", EntryPoint="mono_test_marshal_array")]
215 public static extern int mono_test_marshal_array (int [] a1);
217 [DllImport ("libtest", EntryPoint="mono_test_marshal_empty_string_array")]
218 public static extern int mono_test_marshal_empty_string_array (string [] a1);
220 [DllImport ("libtest", EntryPoint="mono_test_marshal_string_array")]
221 public static extern int mono_test_marshal_string_array (string [] a1);
223 [DllImport ("libtest", EntryPoint="mono_test_marshal_unicode_string_array", CharSet=CharSet.Unicode)]
224 public static extern int mono_test_marshal_unicode_string_array (string [] a1, [MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr)]string [] a2);
226 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_array")]
227 public static extern int mono_test_marshal_stringbuilder_array (StringBuilder [] a1);
229 [DllImport ("libtest", EntryPoint="mono_test_marshal_inout_array")]
230 public static extern int mono_test_marshal_inout_array ([In, Out] int [] a1);
232 [DllImport ("libtest", EntryPoint="mono_test_marshal_out_array")]
233 public static extern int mono_test_marshal_out_array ([Out] [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int [] a1, int n);
235 [DllImport ("libtest", EntryPoint="mono_test_marshal_out_byref_array_out_size_param")]
236 public static extern int mono_test_marshal_out_byref_array_out_size_param ([Out] [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] out int [] a1, out int n);
238 [DllImport ("libtest", EntryPoint="mono_test_marshal_out_lparray_out_size_param")]
239 public static extern int mono_test_marshal_out_lparray_out_size_param ([Out] [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int [] a1, out int n);
241 [DllImport ("libtest", EntryPoint="mono_test_marshal_inout_nonblittable_array", CharSet = CharSet.Unicode)]
242 public static extern int mono_test_marshal_inout_nonblittable_array ([In, Out] char [] a1);
244 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct")]
245 public static extern int mono_test_marshal_struct (SimpleStruct ss);
247 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct")]
248 public static extern int mono_test_marshal_struct_gen (SimpleStructGen<string> ss);
250 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2")]
251 public static extern int mono_test_marshal_struct2 (SimpleStruct2 ss);
253 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2_2")]
254 public static extern int mono_test_marshal_struct2_2 (int i, int j, int k, SimpleStruct2 ss);
256 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_struct")]
257 public static extern int mono_test_marshal_byref_struct (ref SimpleStruct ss, bool a, bool b, bool c, String d);
259 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_struct")]
260 public static extern int mono_test_marshal_byref_struct_in ([In] ref SimpleStruct ss, bool a, bool b, bool c, String d);
262 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_struct")]
263 public static extern int mono_test_marshal_byref_struct_inout ([In, Out] ref SimpleStruct ss, bool a, bool b, bool c, String d);
265 [DllImport ("libtest", EntryPoint="mono_test_marshal_point")]
266 public static extern int mono_test_marshal_point (Point p);
268 [DllImport ("libtest", EntryPoint="mono_test_marshal_mixed_point")]
269 public static extern int mono_test_marshal_mixed_point (MixedPoint p);
271 [DllImport ("libtest", EntryPoint="mono_test_empty_struct")]
272 public static extern int mono_test_empty_struct (int a, EmptyStruct es, int b);
274 [DllImport ("libtest", EntryPoint="mono_test_return_empty_struct")]
275 public static extern EmptyStruct mono_test_return_empty_struct (int a);
277 [DllImport ("libtest", EntryPoint="mono_test_return_empty_struct")]
278 public static extern EmptyStructCpp mono_test_return_empty_struct_cpp (int a);
280 [DllImport ("libtest", EntryPoint="mono_test_marshal_lpstruct")]
281 public static extern int mono_test_marshal_lpstruct ([In, MarshalAs(UnmanagedType.LPStruct)] SimpleStruct ss);
283 [DllImport ("libtest", EntryPoint="mono_test_marshal_lpstruct_blittable")]
284 public static extern int mono_test_marshal_lpstruct_blittable ([In, MarshalAs(UnmanagedType.LPStruct)] Point p);
286 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct_array")]
287 public static extern int mono_test_marshal_struct_array (SimpleStruct2[] ss);
289 [DllImport ("libtest", EntryPoint="mono_test_marshal_long_align_struct_array")]
290 public static extern int mono_test_marshal_long_align_struct_array (LongAlignStruct[] ss);
292 [DllImport ("libtest", EntryPoint="mono_test_marshal_class")]
293 public static extern SimpleClass mono_test_marshal_class (int i, int j, int k, SimpleClass ss, int l);
295 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_class")]
296 public static extern int mono_test_marshal_byref_class (ref SimpleClass ss);
298 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate")]
299 public static extern int mono_test_marshal_delegate (SimpleDelegate d);
301 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate_struct")]
302 public static extern DelegateStruct mono_test_marshal_delegate_struct (DelegateStruct d);
304 [DllImport ("libtest", EntryPoint="mono_test_marshal_return_delegate")]
305 public static extern SimpleDelegate mono_test_marshal_return_delegate (SimpleDelegate d);
307 [DllImport ("libtest", EntryPoint="mono_test_return_vtype")]
308 public static extern SimpleStruct mono_test_return_vtype (IntPtr i);
310 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder")]
311 public static extern void mono_test_marshal_stringbuilder (StringBuilder sb, int len);
313 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_default")]
314 public static extern void mono_test_marshal_stringbuilder_default (StringBuilder sb, int len);
316 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_append")]
317 public static extern void mono_test_marshal_stringbuilder_append (StringBuilder sb, int len);
319 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_unicode", CharSet=CharSet.Unicode)]
320 public static extern void mono_test_marshal_stringbuilder_unicode (StringBuilder sb, int len);
322 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_out")]
323 public static extern void mono_test_marshal_stringbuilder_out (out StringBuilder sb);
325 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_ref")]
326 public static extern int mono_test_marshal_stringbuilder_ref (ref StringBuilder sb);
328 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_out_unicode", CharSet=CharSet.Unicode)]
329 public static extern void mono_test_marshal_stringbuilder_out_unicode (out StringBuilder sb);
331 [DllImport ("libtest", EntryPoint="mono_test_last_error", SetLastError=true)]
332 public static extern void mono_test_last_error (int err);
334 [DllImport ("libtest", EntryPoint="mono_test_asany")]
335 public static extern int mono_test_asany ([MarshalAs (UnmanagedType.AsAny)] object o, int what);
337 [DllImport ("libtest", EntryPoint="mono_test_asany", CharSet=CharSet.Unicode)]
338 public static extern int mono_test_asany_unicode ([MarshalAs (UnmanagedType.AsAny)] object o, int what);
340 [DllImport("libtest", EntryPoint="mono_test_marshal_asany_in")]
341 static extern void mono_test_asany_in ([MarshalAs(UnmanagedType.AsAny)][In] object obj);
343 [DllImport("libtest", EntryPoint="mono_test_marshal_asany_out")]
344 static extern void mono_test_asany_out ([MarshalAs(UnmanagedType.AsAny)][Out] object obj);
345 [DllImport("libtest", EntryPoint="mono_test_marshal_asany_inout")]
346 static extern void mono_test_asany_inout ([MarshalAs(UnmanagedType.AsAny)][In, Out] object obj);
348 [DllImport ("libtest")]
349 static extern int class_marshal_test0 (SimpleObj obj);
351 [DllImport ("libtest")]
352 static extern void class_marshal_test1 (out SimpleObj obj);
354 [DllImport ("libtest")]
355 static extern int class_marshal_test4 (SimpleObj obj);
357 [DllImport ("libtest")]
358 static extern int string_marshal_test0 (string str);
360 [DllImport ("libtest")]
361 static extern void string_marshal_test1 (out string str);
363 [DllImport ("libtest")]
364 static extern int string_marshal_test2 (ref string str);
366 [DllImport ("libtest")]
367 static extern int string_marshal_test3 (string str);
369 public delegate int SimpleDelegate (int a);
371 public static int Main (string[] args) {
372 return TestDriver.RunTests (typeof (Tests), args);
375 public static int test_0_marshal_char () {
376 return mono_test_marshal_char ('a');
379 public static int test_0_marshal_char_array () {
380 // a unicode char[] is implicitly marshalled as [Out]
381 char[] buf = new char [32];
382 mono_test_marshal_char_array (buf);
383 string s = new string (buf);
384 if (s.StartsWith ("abcdef"))
390 public static int test_1225_marshal_array () {
391 int [] a1 = new int [50];
392 for (int i = 0; i < 50; i++)
395 return mono_test_marshal_array (a1);
398 public static int test_1225_marshal_inout_array () {
399 int [] a1 = new int [50];
400 for (int i = 0; i < 50; i++)
403 int res = mono_test_marshal_inout_array (a1);
405 for (int i = 0; i < 50; i++)
406 if (a1 [i] != 50 - i) {
407 Console.WriteLine ("X: " + i + " " + a1 [i]);
414 public static int test_0_marshal_out_array () {
415 int [] a1 = new int [50];
417 int res = mono_test_marshal_out_array (a1, 0);
419 for (int i = 0; i < 50; i++)
421 Console.WriteLine ("X: " + i + " " + a1 [i]);
428 public static int test_0_marshal_out_byref_array_out_size_param () {
432 int res = mono_test_marshal_out_byref_array_out_size_param (out a1, out len);
435 for (int i = 0; i < len; i++)
441 public static int test_0_marshal_out_lparray_out_size_param () {
446 int res = mono_test_marshal_out_lparray_out_size_param (a1, out len);
447 // Check that a1 was not overwritten
451 for (int i = 0; i < len; i++)
457 public static int test_0_marshal_inout_nonblittable_array () {
458 char [] a1 = new char [10];
459 for (int i = 0; i < 10; i++)
460 a1 [i] = "Hello, World" [i];
462 int res = mono_test_marshal_inout_nonblittable_array (a1);
464 for (int i = 0; i < 10; i++)
471 public static int test_0_marshal_struct () {
472 SimpleStruct ss = new SimpleStruct ();
476 return mono_test_marshal_struct (ss);
479 public static int test_0_marshal_struct_gen () {
480 SimpleStructGen<string> ss = new SimpleStructGen<string> ();
484 return mono_test_marshal_struct_gen (ss);
487 public static int test_0_marshal_struct2 () {
488 SimpleStruct2 ss2 = new SimpleStruct2 ();
496 return mono_test_marshal_struct2 (ss2);
499 public static int test_0_marshal_struct3 () {
500 SimpleStruct2 ss2 = new SimpleStruct2 ();
508 return mono_test_marshal_struct2_2 (10, 11, 12, ss2);
511 public static int test_0_marshal_empty_struct () {
512 EmptyStruct es = new EmptyStruct ();
514 if (mono_test_empty_struct (1, es, 2) != 0)
517 mono_test_return_empty_struct (42);
522 /* FIXME: This doesn't work on all platforms */
524 public static int test_0_marshal_empty_struct_cpp () {
525 EmptyStructCpp es = new EmptyStructCpp ();
527 mono_test_return_empty_struct_cpp (42);
533 public static int test_0_marshal_lpstruct () {
534 SimpleStruct ss = new SimpleStruct ();
538 return mono_test_marshal_lpstruct (ss);
541 public static int test_0_marshal_lpstruct_blittable () {
542 Point p = new Point ();
546 return mono_test_marshal_lpstruct_blittable (p);
549 public static int test_0_marshal_struct_array () {
550 SimpleStruct2[] ss_arr = new SimpleStruct2 [2];
552 SimpleStruct2 ss2 = new SimpleStruct2 ();
571 return mono_test_marshal_struct_array (ss_arr);
574 public static int test_105_marshal_long_align_struct_array () {
575 LongAlignStruct[] ss_arr = new LongAlignStruct [2];
577 LongAlignStruct ss = new LongAlignStruct ();
590 return mono_test_marshal_long_align_struct_array (ss_arr);
593 /* Test classes as arguments and return values */
594 public static int test_0_marshal_class () {
595 SimpleClass ss = new SimpleClass ();
603 SimpleClass res = mono_test_marshal_class (10, 11, 12, ss, 14);
606 if (! (res.a == ss.a && res.b == ss.b && res.c == ss.c &&
607 res.d == ss.d && res.e == ss.e && res.f == ss.f &&
608 res.g == ss.g && res.h == ss.h))
611 /* Test null arguments and results */
612 res = mono_test_marshal_class (10, 11, 12, null, 14);
619 public static int test_0_marshal_byref_class () {
620 SimpleClass ss = new SimpleClass ();
628 int res = mono_test_marshal_byref_class (ref ss);
629 if (ss.d != "TEST-RES")
635 public static int test_0_marshal_delegate () {
636 SimpleDelegate d = new SimpleDelegate (delegate_test);
638 return mono_test_marshal_delegate (d);
641 public static int test_34_marshal_instance_delegate () {
642 Tests t = new Tests ();
644 SimpleDelegate d = new SimpleDelegate (t.delegate_test_instance);
646 return mono_test_marshal_delegate (d);
649 /* Static delegates closed over their first argument */
650 public static int closed_delegate (Tests t, int a) {
651 return t.int_field + a;
654 public static int test_34_marshal_closed_static_delegate () {
655 Tests t = new Tests ();
657 SimpleDelegate d = (SimpleDelegate)Delegate.CreateDelegate (typeof (SimpleDelegate), t, typeof (Tests).GetMethod ("closed_delegate"));
659 return mono_test_marshal_delegate (d);
662 public static int test_0_marshal_return_delegate () {
663 SimpleDelegate d = new SimpleDelegate (delegate_test);
665 SimpleDelegate d2 = mono_test_marshal_return_delegate (d);
670 public static int test_0_marshal_delegate_struct () {
671 DelegateStruct s = new DelegateStruct ();
674 s.del = new SimpleDelegate (delegate_test);
675 s.del2 = new SimpleDelegate (delegate_test);
678 DelegateStruct res = mono_test_marshal_delegate_struct (s);
682 if (res.del (2) != 0)
684 if (res.del2 (2) != 0)
686 if (res.del3 != null)
692 [DllImport ("libtest", EntryPoint="mono_test_marshal_out_delegate")]
693 public static extern int mono_test_marshal_out_delegate (out SimpleDelegate d);
695 public static int test_3_marshal_out_delegate () {
696 SimpleDelegate d = null;
698 mono_test_marshal_out_delegate (out d);
703 public static int test_0_marshal_byref_struct () {
704 SimpleStruct s = new SimpleStruct ();
711 int res = mono_test_marshal_byref_struct (ref s, true, false, true, "ABC");
714 if (s.a != false || s.b != true || s.c != false || s.d != "DEF")
719 public static int test_0_marshal_byref_struct_in () {
720 SimpleStruct s = new SimpleStruct ();
727 int res = mono_test_marshal_byref_struct_in (ref s, true, false, true, "ABC");
730 if (s.a != true || s.b != false || s.c != true || s.d != "ABC")
735 public static int test_0_marshal_byref_struct_inout () {
736 SimpleStruct s = new SimpleStruct ();
743 int res = mono_test_marshal_byref_struct_inout (ref s, true, false, true, "ABC");
746 if (s.a != false || s.b != true || s.c != false || s.d != "DEF")
751 public static int test_0_marshal_point () {
752 Point pt = new Point();
756 return mono_test_marshal_point(pt);
759 public static int test_0_marshal_mixed_point () {
760 MixedPoint mpt = new MixedPoint();
764 return mono_test_marshal_mixed_point(mpt);
767 public static int test_0_marshal_bool_byref () {
769 if (mono_test_marshal_bool_byref (99, ref b, 100) != 1)
772 if (mono_test_marshal_bool_byref (99, ref b, 100) != 0)
780 public static int test_0_marshal_bool_as_I1 () {
784 if ((ret = mono_test_marshal_bool_in_as_I1 (true, false)) != 0)
787 if ((ret = mono_test_marshal_bool_out_as_I1 (out bTrue, out bFalse)) != 0)
796 if ((ret = mono_test_marshal_bool_ref_as_I1 (ref bTrue, ref bFalse)) != 0)
808 public static int test_0_marshal_bool_as_U1 () {
812 if ((ret = mono_test_marshal_bool_in_as_U1 (true, false)) != 0)
815 if ((ret = mono_test_marshal_bool_out_as_U1 (out bTrue, out bFalse)) != 0)
824 if ((ret = mono_test_marshal_bool_ref_as_U1 (ref bTrue, ref bFalse)) != 0)
836 public static int test_0_return_vtype () {
837 SimpleStruct ss = mono_test_return_vtype (new IntPtr (5));
839 if (!ss.a && ss.b && !ss.c && ss.d == "TEST" && ss.d2 == "TEST2")
845 public static int test_0_marshal_stringbuilder () {
846 StringBuilder sb = new StringBuilder(255);
848 mono_test_marshal_stringbuilder (sb, sb.Capacity);
849 String res = sb.ToString();
851 if (res != "This is my message. Isn't it nice?")
854 // Test StringBuilder with default capacity (16)
855 StringBuilder sb2 = new StringBuilder();
856 mono_test_marshal_stringbuilder_default (sb2, sb2.Capacity);
857 if (sb2.ToString () != "This is my messa")
863 public static int test_0_marshal_stringbuilder_append () {
864 const String in_sentinel = "MONO_";
865 const String out_sentinel = "CSHARP_";
866 const int iterations = 100;
867 StringBuilder sb = new StringBuilder(255);
868 StringBuilder check = new StringBuilder(255);
870 for (int i = 0; i < iterations; i++) {
871 sb.Append (in_sentinel[i % in_sentinel.Length]);
872 check.Append (out_sentinel[i % out_sentinel.Length]);
874 mono_test_marshal_stringbuilder_append (sb, sb.Length);
876 String res = sb.ToString();
877 String checkRev = check.ToString();
882 // Test StringBuilder with default capacity (16)
883 StringBuilder sb2 = new StringBuilder();
884 mono_test_marshal_stringbuilder_default (sb2, sb2.Capacity);
885 if (sb2.ToString () != "This is my messa")
891 public static int test_0_marshal_stringbuilder_unicode () {
892 StringBuilder sb = new StringBuilder(255);
893 mono_test_marshal_stringbuilder_unicode (sb, sb.Capacity);
894 String res = sb.ToString();
896 if (res != "This is my message. Isn't it nice?")
899 // Test StringBuilder with default capacity (16)
900 StringBuilder sb2 = new StringBuilder();
901 mono_test_marshal_stringbuilder_unicode (sb2, sb2.Capacity);
902 if (sb2.ToString () != "This is my messa")
908 public static int test_0_marshal_stringbuilder_out () {
910 mono_test_marshal_stringbuilder_out (out sb);
912 if (sb.ToString () != "This is my message. Isn't it nice?")
917 public static int test_0_marshal_stringbuilder_out_unicode () {
919 mono_test_marshal_stringbuilder_out_unicode (out sb);
921 if (sb.ToString () != "This is my message. Isn't it nice?")
926 public static int test_0_marshal_stringbuilder_ref () {
927 StringBuilder sb = new StringBuilder ();
929 int res = mono_test_marshal_stringbuilder_ref (ref sb);
933 if (sb.ToString () != "This is my message. Isn't it nice?")
938 public static int test_0_marshal_empty_string_array () {
939 return mono_test_marshal_empty_string_array (null);
942 public static int test_0_marshal_string_array () {
943 return mono_test_marshal_string_array (new String [] { "ABC", "DEF" });
946 public static int test_0_marshal_unicode_string_array () {
947 return mono_test_marshal_unicode_string_array (new String [] { "ABC", "DEF" }, new String [] { "ABC", "DEF" });
950 public static int test_0_marshal_stringbuilder_array () {
951 StringBuilder sb1 = new StringBuilder ("ABC");
952 StringBuilder sb2 = new StringBuilder ("DEF");
954 int res = mono_test_marshal_stringbuilder_array (new StringBuilder [] { sb1, sb2 });
957 if (sb1.ToString () != "DEF")
959 if (sb2.ToString () != "ABC")
964 public static int test_0_last_error () {
965 mono_test_last_error (5);
966 if (Marshal.GetLastWin32Error () == 5)
972 public static int test_0_entry_point_not_found () {
975 mono_entry_point_not_found ();
978 catch (EntryPointNotFoundException) {
984 public static int test_0_library_not_found () {
987 mono_library_not_found ();
990 catch (DllNotFoundException) {
996 /* Check that the runtime trims .dll from the library name */
997 public static int test_0_trim_dll_from_name () {
999 mono_test_marshal_char_2 ('A');
1004 /* Check that the runtime adds lib to to the library name */
1005 public static int test_0_add_lib_to_name () {
1007 mono_test_marshal_char_3 ('A');
1016 public static int test_0_asany () {
1017 if (mono_test_asany (5, 1) != 0)
1020 if (mono_test_asany ("ABC", 2) != 0)
1023 SimpleStruct2 ss2 = new SimpleStruct2 ();
1031 if (mono_test_asany (ss2, 3) != 0)
1034 if (mono_test_asany_unicode ("ABC", 4) != 0)
1040 mono_test_asany (c, 0);
1043 catch (ArgumentException) {
1047 mono_test_asany (new Object (), 0);
1050 catch (ArgumentException) {
1056 /* AsAny marshalling + [In, Out] */
1058 public static int test_0_asany_in () {
1060 AsAnyStruct str = new AsAnyStruct(1,2,3, "ABC");
1061 mono_test_asany_in (str);
1064 AsAnyClass cls = new AsAnyClass(1,2,3, "ABC");
1065 mono_test_asany_in (cls);
1066 if ((cls.i != 1) || (cls.j != 2) || (cls.k != 3))
1070 object obj = new AsAnyStruct(1,2,3, "ABC");
1071 mono_test_asany_in (obj);
1072 str = (AsAnyStruct)obj;
1073 if ((str.i != 1) || (str.j != 2) || (str.k != 3))
1079 public static int test_0_asany_out () {
1081 AsAnyStruct str = new AsAnyStruct(1,2,3, "ABC");
1082 mono_test_asany_out (str);
1085 AsAnyClass cls = new AsAnyClass(1,2,3, "ABC");
1086 mono_test_asany_out (cls);
1087 if ((cls.i != 10) || (cls.j != 20) || (cls.k != 30))
1091 object obj = new AsAnyStruct(1,2,3, "ABC");
1092 mono_test_asany_out (obj);
1093 str = (AsAnyStruct)obj;
1094 if ((str.i != 10) || (str.j != 20) || (str.k != 30))
1100 public static int test_0_asany_inout () {
1102 AsAnyStruct str = new AsAnyStruct(1,2,3, "ABC");
1103 mono_test_asany_inout (str);
1106 AsAnyClass cls = new AsAnyClass(1,2,3, "ABC");
1107 mono_test_asany_inout (cls);
1108 if ((cls.i != 10) || (cls.j != 20) || (cls.k != 30))
1112 object obj = new AsAnyStruct(1,2,3, "ABC");
1113 mono_test_asany_inout (obj);
1114 str = (AsAnyStruct)obj;
1115 if ((str.i != 10) || (str.j != 20) || (str.k != 30))
1121 /* Byref String Array */
1123 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_string_array")]
1124 public static extern int mono_test_marshal_byref_string_array (ref string[] data);
1126 public static int test_0_byref_string_array () {
1128 string[] arr = null;
1130 if (mono_test_marshal_byref_string_array (ref arr) != 0)
1133 arr = new string[] { "Alpha", "Beta", "Gamma" };
1135 if (mono_test_marshal_byref_string_array (ref arr) != 1)
1138 /* FIXME: Test returned array and out case */
1144 * AMD64 small structs-by-value tests.
1147 /* TEST 1: 16 byte long INTEGER struct */
1149 [StructLayout(LayoutKind.Sequential)]
1150 public struct Amd64Struct1 {
1157 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct1")]
1158 public static extern Amd64Struct1 mono_test_marshal_amd64_pass_return_struct1 (Amd64Struct1 s);
1160 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct1_many_args")]
1161 public static extern Amd64Struct1 mono_test_marshal_amd64_pass_return_struct1_many_args (Amd64Struct1 s, int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8);
1163 public static int test_0_amd64_struct1 () {
1164 Amd64Struct1 s = new Amd64Struct1 ();
1170 Amd64Struct1 s2 = mono_test_marshal_amd64_pass_return_struct1 (s);
1172 return ((s2.i == 6) && (s2.j == -4) && (s2.k == 0x1000000) && (s2.l == 0x10000000)) ? 0 : 1;
1175 public static int test_0_amd64_struct1_many_args () {
1176 Amd64Struct1 s = new Amd64Struct1 ();
1182 Amd64Struct1 s2 = mono_test_marshal_amd64_pass_return_struct1_many_args (s, 1, 2, 3, 4, 5, 6, 7, 8);
1184 return ((s2.i == 6) && (s2.j == -4) && (s2.k == 0x1000000) && (s2.l == 0x10000000 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8)) ? 0 : 1;
1187 /* TEST 2: 8 byte long INTEGER struct */
1189 [StructLayout(LayoutKind.Sequential)]
1190 public struct Amd64Struct2 {
1195 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct2")]
1196 public static extern Amd64Struct2 mono_test_marshal_amd64_pass_return_struct2 (Amd64Struct2 s);
1198 public static int test_0_amd64_struct2 () {
1199 Amd64Struct2 s = new Amd64Struct2 ();
1203 Amd64Struct2 s2 = mono_test_marshal_amd64_pass_return_struct2 (s);
1205 return ((s2.i == 6) && (s2.j == -4)) ? 0 : 1;
1208 /* TEST 3: 4 byte long INTEGER struct */
1210 [StructLayout(LayoutKind.Sequential)]
1211 public struct Amd64Struct3 {
1215 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct3")]
1216 public static extern Amd64Struct3 mono_test_marshal_amd64_pass_return_struct3 (Amd64Struct3 s);
1218 public static int test_0_amd64_struct3 () {
1219 Amd64Struct3 s = new Amd64Struct3 ();
1222 Amd64Struct3 s2 = mono_test_marshal_amd64_pass_return_struct3 (s);
1224 return (s2.i == -4) ? 0 : 1;
1227 /* Test 4: 16 byte long FLOAT struct */
1229 [StructLayout(LayoutKind.Sequential)]
1230 public struct Amd64Struct4 {
1231 public double d1, d2;
1234 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct4")]
1235 public static extern Amd64Struct4 mono_test_marshal_amd64_pass_return_struct4 (Amd64Struct4 s);
1237 public static int test_0_amd64_struct4 () {
1238 Amd64Struct4 s = new Amd64Struct4 ();
1242 Amd64Struct4 s2 = mono_test_marshal_amd64_pass_return_struct4 (s);
1244 return (s2.d1 == 6.0 && s2.d2 == -4.0) ? 0 : 1;
1251 /* Test 5: Float HFA */
1253 [StructLayout(LayoutKind.Sequential)]
1254 public struct TestStruct5 {
1255 public float d1, d2;
1258 [DllImport ("libtest", EntryPoint="mono_test_marshal_ia64_pass_return_struct5")]
1259 public static extern TestStruct5 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, TestStruct5 s, int i, double f3, double f4);
1261 public static int test_0_ia64_struct5 () {
1262 TestStruct5 s = new TestStruct5 ();
1266 TestStruct5 s2 = mono_test_marshal_ia64_pass_return_struct5 (1.0, 2.0, s, 5, 3.0, 4.0);
1268 return (s2.d1 == 13.0 && s2.d2 == 7.0) ? 0 : 1;
1271 /* Test 6: Double HFA */
1273 [StructLayout(LayoutKind.Sequential)]
1274 public struct TestStruct6 {
1275 public double d1, d2;
1278 [DllImport ("libtest", EntryPoint="mono_test_marshal_ia64_pass_return_struct6")]
1279 public static extern TestStruct6 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, TestStruct6 s, int i, double f3, double f4);
1281 public static int test_0_ia64_struct6 () {
1282 TestStruct6 s = new TestStruct6 ();
1286 TestStruct6 s2 = mono_test_marshal_ia64_pass_return_struct6 (1.0, 2.0, s, 3, 4.0, 5.0);
1288 return (s2.d1 == 12.0 && s2.d2 == 3.0) ? 0 : 1;
1291 /* Blittable class */
1292 [DllImport("libtest")]
1293 private static extern BlittableClass TestBlittableClass (BlittableClass vl);
1295 public static int test_0_marshal_blittable_class () {
1296 BlittableClass v1 = new BlittableClass ();
1298 /* Since it is blittable, it looks like it is passed as in/out */
1299 BlittableClass v2 = TestBlittableClass (v1);
1301 if (v1.a != 2 || v1.b != 3)
1304 if (v2.a != 2 || v2.b != 3)
1308 BlittableClass v3 = TestBlittableClass (null);
1310 if (v3.a != 42 || v3.b != 43)
1317 * Generic structures
1320 [StructLayout(LayoutKind.Sequential)]
1321 public struct Amd64Struct1Gen<T> {
1328 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct1")]
1329 public static extern Amd64Struct1Gen<int> mono_test_marshal_amd64_pass_return_struct1_gen (Amd64Struct1Gen<int> s);
1331 public static int test_0_amd64_struct1_gen () {
1332 Amd64Struct1Gen<int> s = new Amd64Struct1Gen<int> ();
1338 Amd64Struct1Gen<int> s2 = mono_test_marshal_amd64_pass_return_struct1_gen (s);
1340 return ((s2.i == 6) && (s2.j == -4) && (s2.k == 0x1000000) && (s2.l == 0x10000000)) ? 0 : 1;
1347 public static int test_0_marshal_byval_class () {
1348 SimpleObj obj0 = new SimpleObj ();
1352 if (class_marshal_test0 (obj0) != 0)
1358 public static int test_0_marshal_byval_class_null () {
1359 if (class_marshal_test4 (null) != 0)
1365 public static int test_0_marshal_out_class () {
1368 class_marshal_test1 (out obj1);
1370 if (obj1.str != "ABC")
1379 public static int test_0_marshal_string () {
1380 return string_marshal_test0 ("TEST0");
1383 public static int test_0_marshal_out_string () {
1386 string_marshal_test1 (out res);
1394 public static int test_0_marshal_byref_string () {
1395 string res = "TEST1";
1397 int r = string_marshal_test2 (ref res);
1405 public static int test_0_marshal_null_string () {
1406 return string_marshal_test3 (null);
1410 [DllImport ("libtest", EntryPoint="mono_test_stdcall_mismatch_1", CallingConvention=CallingConvention.StdCall)]
1411 public static extern int mono_test_stdcall_mismatch_1 (int a, int b, int c);
1413 /* Test mismatched called conventions, the native function is cdecl */
1414 public static int test_0_stdcall_mismatch_1 () {
1415 mono_test_stdcall_mismatch_1 (0, 1, 2);
1419 [DllImport ("libtest", EntryPoint="mono_test_stdcall_mismatch_2", CallingConvention=CallingConvention.Cdecl)]
1420 public static extern int mono_test_stdcall_mismatch_2 (int a, int b, int c);
1422 /* Test mismatched called conventions, the native function is stdcall */
1423 public static int test_0_stdcall_mismatch_2 () {
1424 mono_test_stdcall_mismatch_2 (0, 1, 2);
1429 [DllImport ("libtest", EntryPoint="mono_test_stdcall_name_mangling", CallingConvention=CallingConvention.StdCall)]
1430 public static extern int mono_test_stdcall_name_mangling (int a, int b, int c);
1432 public static int test_0_stdcall_name_mangling () {
1433 return mono_test_stdcall_name_mangling (0, 1, 2) == 3 ? 0 : 1;
1436 /* Test multiple calls to stdcall wrapper, xamarin bug 30146 */
1437 public static int test_0_stdcall_many_calls () {
1438 for (int i=0; i<256; i++)
1439 mono_test_stdcall_name_mangling (0, 0, 0);
1445 [DllImport ("libtest", EntryPoint="mono_test_marshal_pass_return_float")]
1446 public static extern float mono_test_marshal_pass_return_float (float f);
1448 public static int test_0_pass_return_float () {
1449 float f = mono_test_marshal_pass_return_float (1.5f);
1451 return (f == 2.5f) ? 0 : 1;
1455 * Pointers to structures can not be passed
1458 /* This seems to be allowed by MS in some cases */
1460 public struct CharInfo {
1461 public char Character;
1462 public short Attributes;
1465 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct")]
1466 public static unsafe extern int mono_test_marshal_ptr_to_struct (CharInfo *ptr);
1468 public static unsafe int test_0_marshal_ptr_to_struct () {
1469 CharInfo [] buffer = new CharInfo [1];
1470 fixed (CharInfo *ptr = &buffer [0]) {
1472 mono_test_marshal_ptr_to_struct (ptr);
1475 catch (MarshalDirectiveException) {
1484 * LPWStr marshalling
1487 [DllImport("libtest", EntryPoint="test_lpwstr_marshal")]
1488 [return: MarshalAs(UnmanagedType.LPWStr)]
1489 private static extern string mono_test_marshal_lpwstr_marshal(
1490 [MarshalAs(UnmanagedType.LPWStr)] string s,
1493 [DllImport("libtest", EntryPoint="test_lpwstr_marshal", CharSet=CharSet.Unicode)]
1494 private static extern string mono_test_marshal_lpwstr_marshal2(
1498 [DllImport("libtest", EntryPoint="test_lpwstr_marshal_out")]
1499 private static extern void mono_test_marshal_lpwstr_out_marshal(
1500 [MarshalAs(UnmanagedType.LPWStr)] out string s);
1502 [DllImport("libtest", EntryPoint="test_lpwstr_marshal_out", CharSet=CharSet.Unicode)]
1503 private static extern void mono_test_marshal_lpwstr_out_marshal2(
1506 public static int test_0_pass_return_lwpstr () {
1509 mono_test_marshal_lpwstr_out_marshal (out s);
1515 mono_test_marshal_lpwstr_out_marshal2 (out s);
1523 public static int test_0_out_lwpstr () {
1526 string res = mono_test_marshal_lpwstr_marshal (s, s.Length);
1531 string res2 = mono_test_marshal_lpwstr_marshal2 (s, s.Length);
1540 * Byref bool marshalling
1543 [DllImport("libtest")]
1544 extern static int marshal_test_ref_bool
1547 [MarshalAs(UnmanagedType.I1)] ref bool b1,
1548 [MarshalAs(UnmanagedType.VariantBool)] ref bool b2,
1552 public static int test_0_pass_byref_bool () {
1553 for (int i = 0; i < 8; i++)
1555 bool b1 = (i & 4) != 0;
1556 bool b2 = (i & 2) != 0;
1557 bool b3 = (i & 1) != 0;
1558 bool orig_b1 = b1, orig_b2 = b2, orig_b3 = b3;
1559 if (marshal_test_ref_bool(i, ref b1, ref b2, ref b3) != 0)
1573 * Bool struct field marshalling
1579 [MarshalAs(UnmanagedType.I1)] public bool b1;
1580 [MarshalAs(UnmanagedType.VariantBool)] public bool b2;
1584 [DllImport("libtest")]
1585 extern static int marshal_test_bool_struct(ref BoolStruct s);
1587 public static int test_0_pass_bool_in_struct () {
1588 for (int i = 0; i < 8; i++)
1590 BoolStruct s = new BoolStruct();
1592 s.b1 = (i & 4) != 0;
1593 s.b2 = (i & 2) != 0;
1594 s.b3 = (i & 1) != 0;
1595 BoolStruct orig = s;
1596 if (marshal_test_bool_struct(ref s) != 0)
1598 if (s.b1 != !orig.b1)
1600 if (s.b2 != !orig.b2)
1602 if (s.b3 != !orig.b3)
1610 * Alignment of structs containing longs
1613 struct LongStruct2 {
1619 public LongStruct2 l;
1622 [DllImport("libtest")]
1623 extern static int mono_test_marshal_long_struct (ref LongStruct s);
1625 public static int test_47_pass_long_struct () {
1626 LongStruct s = new LongStruct ();
1628 s.l = new LongStruct2 ();
1631 return mono_test_marshal_long_struct (ref s);
1635 * Invoking pinvoke methods through delegates
1638 delegate int MyDelegate (string name);
1640 [DllImport ("libtest", EntryPoint="mono_test_puts_static")]
1641 public static extern int puts_static (string name);
1643 public static int test_0_invoke_pinvoke_through_delegate () {
1644 puts_static ("A simple Test for PInvoke 1");
1646 MyDelegate d = new MyDelegate (puts_static);
1647 d ("A simple Test for PInvoke 2");
1649 object [] args = {"A simple Test for PInvoke 3"};
1650 d.DynamicInvoke (args);
1656 * Missing virtual pinvoke methods
1661 public virtual object MyClone ()
1667 public class T2 : T {
1668 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1669 public override extern object MyClone ();
1672 public static int test_0_missing_virtual_pinvoke_method () {
1677 } catch (Exception ex) {
1685 * Marshalling of type 'object'
1688 [DllImport ("libtest", EntryPoint="mono_test_marshal_class")]
1689 public static extern SimpleClass mono_test_marshal_object (int i, int j, int k, object ss, int l);
1691 public static int test_0_marshal_object () {
1693 mono_test_marshal_object (0, 0, 0, null, 0);
1695 } catch (Exception) {
1701 * Marshalling of DateTime to OLE DATE (double)
1703 [DllImport ("libtest", EntryPoint="mono_test_marshal_date_time")]
1704 public static extern double mono_test_marshal_date_time (DateTime d, out DateTime d2);
1706 public static int test_0_marshal_date_time () {
1707 DateTime d = new DateTime (2009, 12, 6);
1709 double d3 = mono_test_marshal_date_time (d, out d2);
1718 * Calling pinvoke functions dynamically using calli
1721 [DllImport("libtest")]
1722 private static extern IntPtr mono_test_marshal_lookup_symbol (string fileName);
1724 delegate void CalliDel (IntPtr a, int[] f);
1726 public static int test_0_calli_dynamic () {
1727 /* we need the cdecl version because the icall convention demands it under Windows */
1728 IntPtr func = mono_test_marshal_lookup_symbol ("mono_test_marshal_inout_array_cdecl");
1730 DynamicMethod dm = new DynamicMethod ("calli", typeof (void), new Type [] { typeof (IntPtr), typeof (int[]) });
1732 var il = dm.GetILGenerator ();
1733 var signature = SignatureHelper.GetMethodSigHelper (CallingConvention.Cdecl, typeof (void));
1735 il.Emit (OpCodes.Ldarg, 1);
1736 signature.AddArgument (typeof (byte[]));
1738 il.Emit (OpCodes.Ldarg_0);
1740 il.Emit (OpCodes.Calli, signature);
1741 il.Emit (OpCodes.Ret);
1743 var f = (CalliDel)dm.CreateDelegate (typeof (CalliDel));
1745 int[] arr = new int [1000];
1746 for (int i = 0; i < 50; ++i)
1749 if (arr.Length != 1000)
1751 for (int i = 0; i < 50; ++i)
1752 if (arr [i] != 50 - i)
1759 /*char array marshaling */
1760 [DllImport ("libtest", EntryPoint="mono_test_marshal_ansi_char_array", CharSet=CharSet.Ansi)]
1761 public static extern int mono_test_marshal_ansi_char_array (char[] a1);
1763 public static int test_0_marshal_ansi_char_array () {
1764 char[] buf = new char [32];
1770 if (mono_test_marshal_ansi_char_array (buf) != 0)
1773 string s = new string (buf);
1774 if (s.StartsWith ("qwer"))
1780 /*char array marshaling */
1781 [DllImport ("libtest", EntryPoint="mono_test_marshal_unicode_char_array", CharSet=CharSet.Unicode)]
1782 public static extern int mono_test_marshal_unicode_char_array (char[] a1);
1784 public static int test_0_marshal_unicode_char_array () {
1785 char[] buf = new char [32];
1791 if (mono_test_marshal_unicode_char_array (buf) != 0)
1794 string s = new string (buf);
1795 if (s.StartsWith ("abcdef"))
1801 [DllImport ("libtest", EntryPoint="mono_test_marshal_lpstr")]
1802 public static extern int mono_test_marshal_lpstr ([MarshalAs(UnmanagedType.LPStr)] string str);
1804 public static int test_0_mono_test_marshal_lpstr () {
1807 if (mono_test_marshal_lpstr (str) != 0)
1813 [DllImport ("libtest", EntryPoint="mono_test_marshal_lpwstr")]
1814 public static extern int mono_test_marshal_lpwstr ([MarshalAs(UnmanagedType.LPWStr)] string str);
1816 public static int test_0_mono_test_marshal_lpwstr () {
1819 if (mono_test_marshal_lpwstr (str) != 0)
1826 [method: DllImport ("libtest", EntryPoint="mono_test_marshal_return_lpstr")]
1827 [return: MarshalAs(UnmanagedType.LPStr)]
1828 public static extern string mono_test_marshal_return_lpstr ();
1830 public static int test_0_mono_test_marshal_return_lpstr () {
1831 string str = mono_test_marshal_return_lpstr ();
1838 [method: DllImport ("libtest", EntryPoint="mono_test_marshal_return_lpwstr")]
1839 [return: MarshalAs(UnmanagedType.LPWStr)]
1840 public static extern string mono_test_marshal_return_lpwstr ();
1842 public static int test_0_mono_test_marshal_return_lpwstr () {
1843 string str = mono_test_marshal_return_lpwstr ();
1850 [DllImport ("libtest", EntryPoint="mono_test_has_thiscall")]
1851 public static extern int mono_test_has_thiscall ();
1853 [DllImport ("libtest", EntryPoint = "_mono_test_native_thiscall1", CallingConvention=CallingConvention.ThisCall)]
1854 public static extern int mono_test_native_thiscall (int a);
1856 [DllImport ("libtest", EntryPoint = "_mono_test_native_thiscall2", CallingConvention=CallingConvention.ThisCall)]
1857 public static extern int mono_test_native_thiscall (int a, int b);
1859 [DllImport ("libtest", EntryPoint = "_mono_test_native_thiscall3", CallingConvention=CallingConvention.ThisCall)]
1860 public static extern int mono_test_native_thiscall (int a, int b, int c);
1862 [DllImport ("libtest", EntryPoint = "_mono_test_native_thiscall1", CallingConvention=CallingConvention.ThisCall)]
1863 public static extern int mono_test_native_thiscall (TinyStruct a);
1865 [DllImport ("libtest", EntryPoint = "_mono_test_native_thiscall2", CallingConvention=CallingConvention.ThisCall)]
1866 public static extern int mono_test_native_thiscall (TinyStruct a, int b);
1868 [DllImport ("libtest", EntryPoint = "_mono_test_native_thiscall3", CallingConvention=CallingConvention.ThisCall)]
1869 public static extern int mono_test_native_thiscall (TinyStruct a, int b, int c);
1871 public static int test_0_native_thiscall ()
1873 if (mono_test_has_thiscall () == 0)
1876 if (mono_test_native_thiscall (1968329802) != 1968329802)
1879 if (mono_test_native_thiscall (268894549, 1212675791) != 1481570339)
1882 if (mono_test_native_thiscall (1288082683, -421187449, -1733670329) != -866775098)
1885 if (mono_test_native_thiscall (new TinyStruct(1968329802)) != 1968329802)
1888 if (mono_test_native_thiscall (new TinyStruct(268894549), 1212675791) != 1481570339)
1891 if (mono_test_native_thiscall (new TinyStruct(1288082683), -421187449, -1733670329) != -866775098)
1897 [DllImport ("libtest", EntryPoint = "mono_test_marshal_return_single_double_struct")]
1898 public static extern SingleDoubleStruct mono_test_marshal_return_single_double_struct ();
1900 public static int test_0_x86_single_double_struct_ret () {
1901 double d = mono_test_marshal_return_single_double_struct ().d;
1908 [StructLayout(LayoutKind.Explicit, Size = 12)]
1909 public struct FixedArrayStruct {
1911 public fixed int array[3];
1914 [DllImport ("libtest", EntryPoint="mono_test_marshal_fixed_array")]
1915 public static extern int mono_test_marshal_fixed_array (FixedArrayStruct s);
1917 public static unsafe int test_6_fixed_array_struct () {
1918 var s = new FixedArrayStruct ();
1923 return mono_test_marshal_fixed_array (s);
1926 [DllImport ("libtest", EntryPoint="mono_test_marshal_pointer_array")]
1927 public static extern int mono_test_marshal_pointer_array (int*[] arr);
1929 public static unsafe int test_0_pointer_array () {
1930 var arr = new int [10];
1931 for (int i = 0; i < arr.Length; i++)
1933 var arr2 = new int*[10];
1934 for (int i = 0; i < arr2.Length; i++) {
1935 GCHandle handle = GCHandle.Alloc(arr[i], GCHandleType.Pinned);
1936 fixed (int *ptr = &arr[i]) {
1940 return mono_test_marshal_pointer_array (arr2);
1943 [StructLayout(LayoutKind.Sequential)]
1944 public struct FixedBufferChar {
1945 public fixed char array[16];
1949 [DllImport ("libtest", EntryPoint="mono_test_marshal_fixed_buffer_char")]
1950 public static extern int mono_test_marshal_fixed_buffer_char (ref FixedBufferChar s);
1952 public static unsafe int test_0_fixed_buffer_char () {
1953 var s = new FixedBufferChar ();
1959 int res = mono_test_marshal_fixed_buffer_char (ref s);
1962 if (s.array [0] != 'E' || s.array [1] != 'F' || s.c != 'G')
1967 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
1968 public struct FixedBufferUnicode {
1969 public fixed char array[16];
1973 [DllImport ("libtest", EntryPoint="mono_test_marshal_fixed_buffer_unicode")]
1974 public static extern int mono_test_marshal_fixed_buffer_unicode (ref FixedBufferUnicode s);
1976 public static unsafe int test_0_fixed_buffer_unicode () {
1977 var s = new FixedBufferUnicode ();
1983 int res = mono_test_marshal_fixed_buffer_unicode (ref s);
1986 if (s.array [0] != 'E' || s.array [1] != 'F' || s.c != 'G')