2 // Copyright 2011 Xamarin Inc (http://www.xamarin.com).
7 using System.Runtime.InteropServices;
8 using System.Runtime.CompilerServices;
9 using System.Reflection.Emit;
15 public static int delegate_test (int a)
23 public int delegate_test_instance (int a)
28 [StructLayout (LayoutKind.Sequential)]
29 public struct SimpleStruct {
34 [MarshalAs(UnmanagedType.LPWStr)]
38 [StructLayout (LayoutKind.Sequential)]
39 public struct SimpleStructGen<T> {
44 [MarshalAs(UnmanagedType.LPWStr)]
48 [StructLayout (LayoutKind.Sequential)]
49 public struct SimpleStruct2 {
60 [StructLayout (LayoutKind.Sequential, Size=0)]
61 public struct EmptyStruct {
64 [StructLayout (LayoutKind.Sequential, Size=1)]
65 public struct EmptyStructCpp {
68 [StructLayout (LayoutKind.Sequential)]
69 public struct DelegateStruct {
71 public SimpleDelegate del;
72 [MarshalAs(UnmanagedType.FunctionPtr)]
73 public SimpleDelegate del2;
74 [MarshalAs(UnmanagedType.FunctionPtr)]
75 public SimpleDelegate del3;
78 [StructLayout (LayoutKind.Sequential)]
79 public struct SingleDoubleStruct {
83 /* sparcv9 has complex conventions when passing structs with doubles in them
84 by value, some simple tests for them */
85 [StructLayout (LayoutKind.Sequential)]
91 [StructLayout (LayoutKind.Sequential)]
92 public struct MixedPoint {
97 [StructLayout (LayoutKind.Sequential)]
98 public struct TinyStruct {
99 public TinyStruct (int i)
106 [StructLayout (LayoutKind.Sequential)]
107 public class SimpleClass {
118 [StructLayout (LayoutKind.Sequential)]
119 public class EmptyClass {
122 [StructLayout (LayoutKind.Sequential)]
123 public struct LongAlignStruct {
129 [StructLayout(LayoutKind.Sequential)]
130 public class BlittableClass
136 [StructLayout (LayoutKind.Sequential)]
143 [StructLayout(LayoutKind.Sequential)]
151 public AsAnyStruct(int i, int j, int k, String s) {
159 [StructLayout(LayoutKind.Sequential)]
167 public AsAnyClass(int i, int j, int k, String s) {
174 [DllImport ("libnot-found", EntryPoint="not_found")]
175 public static extern int mono_library_not_found ();
177 [DllImport ("libtest", EntryPoint="not_found")]
178 public static extern int mono_entry_point_not_found ();
180 [DllImport ("libtest.dll", EntryPoint="mono_test_marshal_char")]
181 public static extern int mono_test_marshal_char_2 (char a1);
183 [DllImport ("test", EntryPoint="mono_test_marshal_char")]
184 public static extern int mono_test_marshal_char_3 (char a1);
186 [DllImport ("libtest", EntryPoint="mono_test_marshal_char")]
187 public static extern int mono_test_marshal_char (char a1);
189 [DllImport ("libtest", EntryPoint="mono_test_marshal_char_array", CharSet=CharSet.Unicode)]
190 public static extern int mono_test_marshal_char_array (char[] a1);
192 [DllImport ("libtest", EntryPoint="mono_test_marshal_bool_byref")]
193 public static extern int mono_test_marshal_bool_byref (int a, ref bool b, int c);
195 [DllImport ("libtest", EntryPoint="mono_test_marshal_bool_in_as_I1_U1")]
196 public static extern int mono_test_marshal_bool_in_as_I1 ([MarshalAs (UnmanagedType.I1)] bool bTrue, [MarshalAs (UnmanagedType.I1)] bool bFalse);
198 [DllImport ("libtest", EntryPoint="mono_test_marshal_bool_in_as_I1_U1")]
199 public static extern int mono_test_marshal_bool_in_as_U1 ([MarshalAs (UnmanagedType.U1)] bool bTrue, [MarshalAs (UnmanagedType.U1)] bool bFalse);
201 [DllImport ("libtest", EntryPoint="mono_test_marshal_bool_out_as_I1_U1")]
202 public static extern int mono_test_marshal_bool_out_as_I1 ([MarshalAs (UnmanagedType.I1)] out bool bTrue, [MarshalAs (UnmanagedType.I1)] out bool bFalse);
204 [DllImport ("libtest", EntryPoint="mono_test_marshal_bool_out_as_I1_U1")]
205 public static extern int mono_test_marshal_bool_out_as_U1 ([MarshalAs (UnmanagedType.U1)] out bool bTrue, [MarshalAs (UnmanagedType.U1)] out bool bFalse);
207 [DllImport ("libtest", EntryPoint="mono_test_marshal_bool_ref_as_I1_U1")]
208 public static extern int mono_test_marshal_bool_ref_as_I1 ([MarshalAs (UnmanagedType.I1)] ref bool bTrue, [MarshalAs (UnmanagedType.I1)] ref bool bFalse);
210 [DllImport ("libtest", EntryPoint="mono_test_marshal_bool_ref_as_I1_U1")]
211 public static extern int mono_test_marshal_bool_ref_as_U1 ([MarshalAs (UnmanagedType.U1)] ref bool bTrue, [MarshalAs (UnmanagedType.U1)] ref bool bFalse);
213 [DllImport ("libtest", EntryPoint="mono_test_marshal_array")]
214 public static extern int mono_test_marshal_array (int [] a1);
216 [DllImport ("libtest", EntryPoint="mono_test_marshal_empty_string_array")]
217 public static extern int mono_test_marshal_empty_string_array (string [] a1);
219 [DllImport ("libtest", EntryPoint="mono_test_marshal_string_array")]
220 public static extern int mono_test_marshal_string_array (string [] a1);
222 [DllImport ("libtest", EntryPoint="mono_test_marshal_unicode_string_array", CharSet=CharSet.Unicode)]
223 public static extern int mono_test_marshal_unicode_string_array (string [] a1, [MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr)]string [] a2);
225 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_array")]
226 public static extern int mono_test_marshal_stringbuilder_array (StringBuilder [] a1);
228 [DllImport ("libtest", EntryPoint="mono_test_marshal_inout_array")]
229 public static extern int mono_test_marshal_inout_array ([In, Out] int [] a1);
231 [DllImport ("libtest", EntryPoint="mono_test_marshal_out_array")]
232 public static extern int mono_test_marshal_out_array ([Out] [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int [] a1, int n);
234 [DllImport ("libtest", EntryPoint="mono_test_marshal_out_byref_array_out_size_param")]
235 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);
237 [DllImport ("libtest", EntryPoint="mono_test_marshal_out_lparray_out_size_param")]
238 public static extern int mono_test_marshal_out_lparray_out_size_param ([Out] [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int [] a1, out int n);
240 [DllImport ("libtest", EntryPoint="mono_test_marshal_inout_nonblittable_array", CharSet = CharSet.Unicode)]
241 public static extern int mono_test_marshal_inout_nonblittable_array ([In, Out] char [] a1);
243 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct")]
244 public static extern int mono_test_marshal_struct (SimpleStruct ss);
246 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct")]
247 public static extern int mono_test_marshal_struct_gen (SimpleStructGen<string> ss);
249 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2")]
250 public static extern int mono_test_marshal_struct2 (SimpleStruct2 ss);
252 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2_2")]
253 public static extern int mono_test_marshal_struct2_2 (int i, int j, int k, SimpleStruct2 ss);
255 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_struct")]
256 public static extern int mono_test_marshal_byref_struct (ref SimpleStruct ss, bool a, bool b, bool c, String d);
258 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_struct")]
259 public static extern int mono_test_marshal_byref_struct_in ([In] ref SimpleStruct ss, bool a, bool b, bool c, String d);
261 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_struct")]
262 public static extern int mono_test_marshal_byref_struct_inout ([In, Out] ref SimpleStruct ss, bool a, bool b, bool c, String d);
264 [DllImport ("libtest", EntryPoint="mono_test_marshal_point")]
265 public static extern int mono_test_marshal_point (Point p);
267 [DllImport ("libtest", EntryPoint="mono_test_marshal_mixed_point")]
268 public static extern int mono_test_marshal_mixed_point (MixedPoint p);
270 [DllImport ("libtest", EntryPoint="mono_test_empty_struct")]
271 public static extern int mono_test_empty_struct (int a, EmptyStruct es, int b);
273 [DllImport ("libtest", EntryPoint="mono_test_return_empty_struct")]
274 public static extern EmptyStruct mono_test_return_empty_struct (int a);
276 [DllImport ("libtest", EntryPoint="mono_test_return_empty_struct")]
277 public static extern EmptyStructCpp mono_test_return_empty_struct_cpp (int a);
279 [DllImport ("libtest", EntryPoint="mono_test_marshal_lpstruct")]
280 public static extern int mono_test_marshal_lpstruct ([In, MarshalAs(UnmanagedType.LPStruct)] SimpleStruct ss);
282 [DllImport ("libtest", EntryPoint="mono_test_marshal_lpstruct_blittable")]
283 public static extern int mono_test_marshal_lpstruct_blittable ([In, MarshalAs(UnmanagedType.LPStruct)] Point p);
285 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct_array")]
286 public static extern int mono_test_marshal_struct_array (SimpleStruct2[] ss);
288 [DllImport ("libtest", EntryPoint="mono_test_marshal_long_align_struct_array")]
289 public static extern int mono_test_marshal_long_align_struct_array (LongAlignStruct[] ss);
291 [DllImport ("libtest", EntryPoint="mono_test_marshal_class")]
292 public static extern SimpleClass mono_test_marshal_class (int i, int j, int k, SimpleClass ss, int l);
294 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_class")]
295 public static extern int mono_test_marshal_byref_class (ref SimpleClass ss);
297 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate")]
298 public static extern int mono_test_marshal_delegate (SimpleDelegate d);
300 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate_struct")]
301 public static extern DelegateStruct mono_test_marshal_delegate_struct (DelegateStruct d);
303 [DllImport ("libtest", EntryPoint="mono_test_marshal_return_delegate")]
304 public static extern SimpleDelegate mono_test_marshal_return_delegate (SimpleDelegate d);
306 [DllImport ("libtest", EntryPoint="mono_test_return_vtype")]
307 public static extern SimpleStruct mono_test_return_vtype (IntPtr i);
309 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder")]
310 public static extern void mono_test_marshal_stringbuilder (StringBuilder sb, int len);
312 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_default")]
313 public static extern void mono_test_marshal_stringbuilder_default (StringBuilder sb, int len);
315 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_append")]
316 public static extern void mono_test_marshal_stringbuilder_append (StringBuilder sb, int len);
318 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_unicode", CharSet=CharSet.Unicode)]
319 public static extern void mono_test_marshal_stringbuilder_unicode (StringBuilder sb, int len);
321 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_out")]
322 public static extern void mono_test_marshal_stringbuilder_out (out StringBuilder sb);
324 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_ref")]
325 public static extern int mono_test_marshal_stringbuilder_ref (ref StringBuilder sb);
327 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_out_unicode", CharSet=CharSet.Unicode)]
328 public static extern void mono_test_marshal_stringbuilder_out_unicode (out StringBuilder sb);
330 [DllImport ("libtest", EntryPoint="mono_test_last_error", SetLastError=true)]
331 public static extern void mono_test_last_error (int err);
333 [DllImport ("libtest", EntryPoint="mono_test_asany")]
334 public static extern int mono_test_asany ([MarshalAs (UnmanagedType.AsAny)] object o, int what);
336 [DllImport ("libtest", EntryPoint="mono_test_asany", CharSet=CharSet.Unicode)]
337 public static extern int mono_test_asany_unicode ([MarshalAs (UnmanagedType.AsAny)] object o, int what);
339 [DllImport("libtest", EntryPoint="mono_test_marshal_asany_in")]
340 static extern void mono_test_asany_in ([MarshalAs(UnmanagedType.AsAny)][In] object obj);
342 [DllImport("libtest", EntryPoint="mono_test_marshal_asany_out")]
343 static extern void mono_test_asany_out ([MarshalAs(UnmanagedType.AsAny)][Out] object obj);
344 [DllImport("libtest", EntryPoint="mono_test_marshal_asany_inout")]
345 static extern void mono_test_asany_inout ([MarshalAs(UnmanagedType.AsAny)][In, Out] object obj);
347 [DllImport ("libtest")]
348 static extern int class_marshal_test0 (SimpleObj obj);
350 [DllImport ("libtest")]
351 static extern void class_marshal_test1 (out SimpleObj obj);
353 [DllImport ("libtest")]
354 static extern int class_marshal_test4 (SimpleObj obj);
356 [DllImport ("libtest")]
357 static extern int string_marshal_test0 (string str);
359 [DllImport ("libtest")]
360 static extern void string_marshal_test1 (out string str);
362 [DllImport ("libtest")]
363 static extern int string_marshal_test2 (ref string str);
365 [DllImport ("libtest")]
366 static extern int string_marshal_test3 (string str);
368 public delegate int SimpleDelegate (int a);
370 public static int Main (string[] args) {
371 return TestDriver.RunTests (typeof (Tests), args);
374 public static int test_0_marshal_char () {
375 return mono_test_marshal_char ('a');
378 public static int test_0_marshal_char_array () {
379 // a unicode char[] is implicitly marshalled as [Out]
380 char[] buf = new char [32];
381 mono_test_marshal_char_array (buf);
382 string s = new string (buf);
383 if (s.StartsWith ("abcdef"))
389 public static int test_1225_marshal_array () {
390 int [] a1 = new int [50];
391 for (int i = 0; i < 50; i++)
394 return mono_test_marshal_array (a1);
397 public static int test_1225_marshal_inout_array () {
398 int [] a1 = new int [50];
399 for (int i = 0; i < 50; i++)
402 int res = mono_test_marshal_inout_array (a1);
404 for (int i = 0; i < 50; i++)
405 if (a1 [i] != 50 - i) {
406 Console.WriteLine ("X: " + i + " " + a1 [i]);
413 public static int test_0_marshal_out_array () {
414 int [] a1 = new int [50];
416 int res = mono_test_marshal_out_array (a1, 0);
418 for (int i = 0; i < 50; i++)
420 Console.WriteLine ("X: " + i + " " + a1 [i]);
427 public static int test_0_marshal_out_byref_array_out_size_param () {
431 int res = mono_test_marshal_out_byref_array_out_size_param (out a1, out len);
434 for (int i = 0; i < len; i++)
440 public static int test_0_marshal_out_lparray_out_size_param () {
445 int res = mono_test_marshal_out_lparray_out_size_param (a1, out len);
446 // Check that a1 was not overwritten
450 for (int i = 0; i < len; i++)
456 public static int test_0_marshal_inout_nonblittable_array () {
457 char [] a1 = new char [10];
458 for (int i = 0; i < 10; i++)
459 a1 [i] = "Hello, World" [i];
461 int res = mono_test_marshal_inout_nonblittable_array (a1);
463 for (int i = 0; i < 10; i++)
470 public static int test_0_marshal_struct () {
471 SimpleStruct ss = new SimpleStruct ();
475 return mono_test_marshal_struct (ss);
478 public static int test_0_marshal_struct_gen () {
479 SimpleStructGen<string> ss = new SimpleStructGen<string> ();
483 return mono_test_marshal_struct_gen (ss);
486 public static int test_0_marshal_struct2 () {
487 SimpleStruct2 ss2 = new SimpleStruct2 ();
495 return mono_test_marshal_struct2 (ss2);
498 public static int test_0_marshal_struct3 () {
499 SimpleStruct2 ss2 = new SimpleStruct2 ();
507 return mono_test_marshal_struct2_2 (10, 11, 12, ss2);
510 public static int test_0_marshal_empty_struct () {
511 EmptyStruct es = new EmptyStruct ();
513 if (mono_test_empty_struct (1, es, 2) != 0)
516 mono_test_return_empty_struct (42);
521 /* FIXME: This doesn't work on all platforms */
523 public static int test_0_marshal_empty_struct_cpp () {
524 EmptyStructCpp es = new EmptyStructCpp ();
526 mono_test_return_empty_struct_cpp (42);
532 public static int test_0_marshal_lpstruct () {
533 SimpleStruct ss = new SimpleStruct ();
537 return mono_test_marshal_lpstruct (ss);
540 public static int test_0_marshal_lpstruct_blittable () {
541 Point p = new Point ();
545 return mono_test_marshal_lpstruct_blittable (p);
548 public static int test_0_marshal_struct_array () {
549 SimpleStruct2[] ss_arr = new SimpleStruct2 [2];
551 SimpleStruct2 ss2 = new SimpleStruct2 ();
570 return mono_test_marshal_struct_array (ss_arr);
573 public static int test_105_marshal_long_align_struct_array () {
574 LongAlignStruct[] ss_arr = new LongAlignStruct [2];
576 LongAlignStruct ss = new LongAlignStruct ();
589 return mono_test_marshal_long_align_struct_array (ss_arr);
592 /* Test classes as arguments and return values */
593 public static int test_0_marshal_class () {
594 SimpleClass ss = new SimpleClass ();
602 SimpleClass res = mono_test_marshal_class (10, 11, 12, ss, 14);
605 if (! (res.a == ss.a && res.b == ss.b && res.c == ss.c &&
606 res.d == ss.d && res.e == ss.e && res.f == ss.f &&
607 res.g == ss.g && res.h == ss.h))
610 /* Test null arguments and results */
611 res = mono_test_marshal_class (10, 11, 12, null, 14);
618 public static int test_0_marshal_byref_class () {
619 SimpleClass ss = new SimpleClass ();
627 int res = mono_test_marshal_byref_class (ref ss);
628 if (ss.d != "TEST-RES")
634 public static int test_0_marshal_delegate () {
635 SimpleDelegate d = new SimpleDelegate (delegate_test);
637 return mono_test_marshal_delegate (d);
640 public static int test_34_marshal_instance_delegate () {
641 Tests t = new Tests ();
643 SimpleDelegate d = new SimpleDelegate (t.delegate_test_instance);
645 return mono_test_marshal_delegate (d);
648 /* Static delegates closed over their first argument */
649 public static int closed_delegate (Tests t, int a) {
650 return t.int_field + a;
653 public static int test_34_marshal_closed_static_delegate () {
654 Tests t = new Tests ();
656 SimpleDelegate d = (SimpleDelegate)Delegate.CreateDelegate (typeof (SimpleDelegate), t, typeof (Tests).GetMethod ("closed_delegate"));
658 return mono_test_marshal_delegate (d);
661 public static int test_0_marshal_return_delegate () {
662 SimpleDelegate d = new SimpleDelegate (delegate_test);
664 SimpleDelegate d2 = mono_test_marshal_return_delegate (d);
669 public static int test_0_marshal_delegate_struct () {
670 DelegateStruct s = new DelegateStruct ();
673 s.del = new SimpleDelegate (delegate_test);
674 s.del2 = new SimpleDelegate (delegate_test);
677 DelegateStruct res = mono_test_marshal_delegate_struct (s);
681 if (res.del (2) != 0)
683 if (res.del2 (2) != 0)
685 if (res.del3 != null)
691 [DllImport ("libtest", EntryPoint="mono_test_marshal_out_delegate")]
692 public static extern int mono_test_marshal_out_delegate (out SimpleDelegate d);
694 public static int test_3_marshal_out_delegate () {
695 SimpleDelegate d = null;
697 mono_test_marshal_out_delegate (out d);
702 public static int test_0_marshal_byref_struct () {
703 SimpleStruct s = new SimpleStruct ();
710 int res = mono_test_marshal_byref_struct (ref s, true, false, true, "ABC");
713 if (s.a != false || s.b != true || s.c != false || s.d != "DEF")
718 public static int test_0_marshal_byref_struct_in () {
719 SimpleStruct s = new SimpleStruct ();
726 int res = mono_test_marshal_byref_struct_in (ref s, true, false, true, "ABC");
729 if (s.a != true || s.b != false || s.c != true || s.d != "ABC")
734 public static int test_0_marshal_byref_struct_inout () {
735 SimpleStruct s = new SimpleStruct ();
742 int res = mono_test_marshal_byref_struct_inout (ref s, true, false, true, "ABC");
745 if (s.a != false || s.b != true || s.c != false || s.d != "DEF")
750 public static int test_0_marshal_point () {
751 Point pt = new Point();
755 return mono_test_marshal_point(pt);
758 public static int test_0_marshal_mixed_point () {
759 MixedPoint mpt = new MixedPoint();
763 return mono_test_marshal_mixed_point(mpt);
766 public static int test_0_marshal_bool_byref () {
768 if (mono_test_marshal_bool_byref (99, ref b, 100) != 1)
771 if (mono_test_marshal_bool_byref (99, ref b, 100) != 0)
779 public static int test_0_marshal_bool_as_I1 () {
783 if ((ret = mono_test_marshal_bool_in_as_I1 (true, false)) != 0)
786 if ((ret = mono_test_marshal_bool_out_as_I1 (out bTrue, out bFalse)) != 0)
795 if ((ret = mono_test_marshal_bool_ref_as_I1 (ref bTrue, ref bFalse)) != 0)
807 public static int test_0_marshal_bool_as_U1 () {
811 if ((ret = mono_test_marshal_bool_in_as_U1 (true, false)) != 0)
814 if ((ret = mono_test_marshal_bool_out_as_U1 (out bTrue, out bFalse)) != 0)
823 if ((ret = mono_test_marshal_bool_ref_as_U1 (ref bTrue, ref bFalse)) != 0)
835 public static int test_0_return_vtype () {
836 SimpleStruct ss = mono_test_return_vtype (new IntPtr (5));
838 if (!ss.a && ss.b && !ss.c && ss.d == "TEST" && ss.d2 == "TEST2")
844 public static int test_0_marshal_stringbuilder () {
845 StringBuilder sb = new StringBuilder(255);
847 mono_test_marshal_stringbuilder (sb, sb.Capacity);
848 String res = sb.ToString();
850 if (res != "This is my message. Isn't it nice?")
853 // Test StringBuilder with default capacity (16)
854 StringBuilder sb2 = new StringBuilder();
855 mono_test_marshal_stringbuilder_default (sb2, sb2.Capacity);
856 if (sb2.ToString () != "This is my messa")
862 public static int test_0_marshal_stringbuilder_append () {
863 const String in_sentinel = "MONO_";
864 const String out_sentinel = "CSHARP_";
865 const int iterations = 100;
866 StringBuilder sb = new StringBuilder(255);
867 StringBuilder check = new StringBuilder(255);
869 for (int i = 0; i < iterations; i++) {
870 sb.Append (in_sentinel[i % in_sentinel.Length]);
871 check.Append (out_sentinel[i % out_sentinel.Length]);
873 mono_test_marshal_stringbuilder_append (sb, sb.Length);
875 String res = sb.ToString();
876 String checkRev = check.ToString();
881 // Test StringBuilder with default capacity (16)
882 StringBuilder sb2 = new StringBuilder();
883 mono_test_marshal_stringbuilder_default (sb2, sb2.Capacity);
884 if (sb2.ToString () != "This is my messa")
890 public static int test_0_marshal_stringbuilder_unicode () {
891 StringBuilder sb = new StringBuilder(255);
892 mono_test_marshal_stringbuilder_unicode (sb, sb.Capacity);
893 String res = sb.ToString();
895 if (res != "This is my message. Isn't it nice?")
898 // Test StringBuilder with default capacity (16)
899 StringBuilder sb2 = new StringBuilder();
900 mono_test_marshal_stringbuilder_unicode (sb2, sb2.Capacity);
901 if (sb2.ToString () != "This is my messa")
907 public static int test_0_marshal_stringbuilder_out () {
909 mono_test_marshal_stringbuilder_out (out sb);
911 if (sb.ToString () != "This is my message. Isn't it nice?")
916 public static int test_0_marshal_stringbuilder_out_unicode () {
918 mono_test_marshal_stringbuilder_out_unicode (out sb);
920 if (sb.ToString () != "This is my message. Isn't it nice?")
925 public static int test_0_marshal_stringbuilder_ref () {
926 StringBuilder sb = new StringBuilder ();
928 int res = mono_test_marshal_stringbuilder_ref (ref sb);
932 if (sb.ToString () != "This is my message. Isn't it nice?")
937 public static int test_0_marshal_empty_string_array () {
938 return mono_test_marshal_empty_string_array (null);
941 public static int test_0_marshal_string_array () {
942 return mono_test_marshal_string_array (new String [] { "ABC", "DEF" });
945 public static int test_0_marshal_unicode_string_array () {
946 return mono_test_marshal_unicode_string_array (new String [] { "ABC", "DEF" }, new String [] { "ABC", "DEF" });
949 public static int test_0_marshal_stringbuilder_array () {
950 StringBuilder sb1 = new StringBuilder ("ABC");
951 StringBuilder sb2 = new StringBuilder ("DEF");
953 int res = mono_test_marshal_stringbuilder_array (new StringBuilder [] { sb1, sb2 });
956 if (sb1.ToString () != "DEF")
958 if (sb2.ToString () != "ABC")
963 public static int test_0_last_error () {
964 mono_test_last_error (5);
965 if (Marshal.GetLastWin32Error () == 5)
971 public static int test_0_entry_point_not_found () {
974 mono_entry_point_not_found ();
977 catch (EntryPointNotFoundException) {
983 public static int test_0_library_not_found () {
986 mono_library_not_found ();
989 catch (DllNotFoundException) {
995 /* Check that the runtime trims .dll from the library name */
996 public static int test_0_trim_dll_from_name () {
998 mono_test_marshal_char_2 ('A');
1003 /* Check that the runtime adds lib to to the library name */
1004 public static int test_0_add_lib_to_name () {
1006 mono_test_marshal_char_3 ('A');
1015 public static int test_0_asany () {
1016 if (mono_test_asany (5, 1) != 0)
1019 if (mono_test_asany ("ABC", 2) != 0)
1022 SimpleStruct2 ss2 = new SimpleStruct2 ();
1030 if (mono_test_asany (ss2, 3) != 0)
1033 if (mono_test_asany_unicode ("ABC", 4) != 0)
1039 mono_test_asany (c, 0);
1042 catch (ArgumentException) {
1046 mono_test_asany (new Object (), 0);
1049 catch (ArgumentException) {
1055 /* AsAny marshalling + [In, Out] */
1057 public static int test_0_asany_in () {
1059 AsAnyStruct str = new AsAnyStruct(1,2,3, "ABC");
1060 mono_test_asany_in (str);
1063 AsAnyClass cls = new AsAnyClass(1,2,3, "ABC");
1064 mono_test_asany_in (cls);
1065 if ((cls.i != 1) || (cls.j != 2) || (cls.k != 3))
1069 object obj = new AsAnyStruct(1,2,3, "ABC");
1070 mono_test_asany_in (obj);
1071 str = (AsAnyStruct)obj;
1072 if ((str.i != 1) || (str.j != 2) || (str.k != 3))
1078 public static int test_0_asany_out () {
1080 AsAnyStruct str = new AsAnyStruct(1,2,3, "ABC");
1081 mono_test_asany_out (str);
1084 AsAnyClass cls = new AsAnyClass(1,2,3, "ABC");
1085 mono_test_asany_out (cls);
1086 if ((cls.i != 10) || (cls.j != 20) || (cls.k != 30))
1090 object obj = new AsAnyStruct(1,2,3, "ABC");
1091 mono_test_asany_out (obj);
1092 str = (AsAnyStruct)obj;
1093 if ((str.i != 10) || (str.j != 20) || (str.k != 30))
1099 public static int test_0_asany_inout () {
1101 AsAnyStruct str = new AsAnyStruct(1,2,3, "ABC");
1102 mono_test_asany_inout (str);
1105 AsAnyClass cls = new AsAnyClass(1,2,3, "ABC");
1106 mono_test_asany_inout (cls);
1107 if ((cls.i != 10) || (cls.j != 20) || (cls.k != 30))
1111 object obj = new AsAnyStruct(1,2,3, "ABC");
1112 mono_test_asany_inout (obj);
1113 str = (AsAnyStruct)obj;
1114 if ((str.i != 10) || (str.j != 20) || (str.k != 30))
1120 /* Byref String Array */
1122 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_string_array")]
1123 public static extern int mono_test_marshal_byref_string_array (ref string[] data);
1125 public static int test_0_byref_string_array () {
1127 string[] arr = null;
1129 if (mono_test_marshal_byref_string_array (ref arr) != 0)
1132 arr = new string[] { "Alpha", "Beta", "Gamma" };
1134 if (mono_test_marshal_byref_string_array (ref arr) != 1)
1137 /* FIXME: Test returned array and out case */
1143 * AMD64 small structs-by-value tests.
1146 /* TEST 1: 16 byte long INTEGER struct */
1148 [StructLayout(LayoutKind.Sequential)]
1149 public struct Amd64Struct1 {
1156 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct1")]
1157 public static extern Amd64Struct1 mono_test_marshal_amd64_pass_return_struct1 (Amd64Struct1 s);
1159 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct1_many_args")]
1160 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);
1162 public static int test_0_amd64_struct1 () {
1163 Amd64Struct1 s = new Amd64Struct1 ();
1169 Amd64Struct1 s2 = mono_test_marshal_amd64_pass_return_struct1 (s);
1171 return ((s2.i == 6) && (s2.j == -4) && (s2.k == 0x1000000) && (s2.l == 0x10000000)) ? 0 : 1;
1174 public static int test_0_amd64_struct1_many_args () {
1175 Amd64Struct1 s = new Amd64Struct1 ();
1181 Amd64Struct1 s2 = mono_test_marshal_amd64_pass_return_struct1_many_args (s, 1, 2, 3, 4, 5, 6, 7, 8);
1183 return ((s2.i == 6) && (s2.j == -4) && (s2.k == 0x1000000) && (s2.l == 0x10000000 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8)) ? 0 : 1;
1186 /* TEST 2: 8 byte long INTEGER struct */
1188 [StructLayout(LayoutKind.Sequential)]
1189 public struct Amd64Struct2 {
1194 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct2")]
1195 public static extern Amd64Struct2 mono_test_marshal_amd64_pass_return_struct2 (Amd64Struct2 s);
1197 public static int test_0_amd64_struct2 () {
1198 Amd64Struct2 s = new Amd64Struct2 ();
1202 Amd64Struct2 s2 = mono_test_marshal_amd64_pass_return_struct2 (s);
1204 return ((s2.i == 6) && (s2.j == -4)) ? 0 : 1;
1207 /* TEST 3: 4 byte long INTEGER struct */
1209 [StructLayout(LayoutKind.Sequential)]
1210 public struct Amd64Struct3 {
1214 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct3")]
1215 public static extern Amd64Struct3 mono_test_marshal_amd64_pass_return_struct3 (Amd64Struct3 s);
1217 public static int test_0_amd64_struct3 () {
1218 Amd64Struct3 s = new Amd64Struct3 ();
1221 Amd64Struct3 s2 = mono_test_marshal_amd64_pass_return_struct3 (s);
1223 return (s2.i == -4) ? 0 : 1;
1226 /* Test 4: 16 byte long FLOAT struct */
1228 [StructLayout(LayoutKind.Sequential)]
1229 public struct Amd64Struct4 {
1230 public double d1, d2;
1233 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct4")]
1234 public static extern Amd64Struct4 mono_test_marshal_amd64_pass_return_struct4 (Amd64Struct4 s);
1236 public static int test_0_amd64_struct4 () {
1237 Amd64Struct4 s = new Amd64Struct4 ();
1241 Amd64Struct4 s2 = mono_test_marshal_amd64_pass_return_struct4 (s);
1243 return (s2.d1 == 6.0 && s2.d2 == -4.0) ? 0 : 1;
1250 /* Test 5: Float HFA */
1252 [StructLayout(LayoutKind.Sequential)]
1253 public struct TestStruct5 {
1254 public float d1, d2;
1257 [DllImport ("libtest", EntryPoint="mono_test_marshal_ia64_pass_return_struct5")]
1258 public static extern TestStruct5 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, TestStruct5 s, int i, double f3, double f4);
1260 public static int test_0_ia64_struct5 () {
1261 TestStruct5 s = new TestStruct5 ();
1265 TestStruct5 s2 = mono_test_marshal_ia64_pass_return_struct5 (1.0, 2.0, s, 5, 3.0, 4.0);
1267 return (s2.d1 == 13.0 && s2.d2 == 7.0) ? 0 : 1;
1270 /* Test 6: Double HFA */
1272 [StructLayout(LayoutKind.Sequential)]
1273 public struct TestStruct6 {
1274 public double d1, d2;
1277 [DllImport ("libtest", EntryPoint="mono_test_marshal_ia64_pass_return_struct6")]
1278 public static extern TestStruct6 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, TestStruct6 s, int i, double f3, double f4);
1280 public static int test_0_ia64_struct6 () {
1281 TestStruct6 s = new TestStruct6 ();
1285 TestStruct6 s2 = mono_test_marshal_ia64_pass_return_struct6 (1.0, 2.0, s, 3, 4.0, 5.0);
1287 return (s2.d1 == 12.0 && s2.d2 == 3.0) ? 0 : 1;
1290 /* Blittable class */
1291 [DllImport("libtest")]
1292 private static extern BlittableClass TestBlittableClass (BlittableClass vl);
1294 public static int test_0_marshal_blittable_class () {
1295 BlittableClass v1 = new BlittableClass ();
1297 /* Since it is blittable, it looks like it is passed as in/out */
1298 BlittableClass v2 = TestBlittableClass (v1);
1300 if (v1.a != 2 || v1.b != 3)
1303 if (v2.a != 2 || v2.b != 3)
1307 BlittableClass v3 = TestBlittableClass (null);
1309 if (v3.a != 42 || v3.b != 43)
1316 * Generic structures
1319 [StructLayout(LayoutKind.Sequential)]
1320 public struct Amd64Struct1Gen<T> {
1327 [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct1")]
1328 public static extern Amd64Struct1Gen<int> mono_test_marshal_amd64_pass_return_struct1_gen (Amd64Struct1Gen<int> s);
1330 public static int test_0_amd64_struct1_gen () {
1331 Amd64Struct1Gen<int> s = new Amd64Struct1Gen<int> ();
1337 Amd64Struct1Gen<int> s2 = mono_test_marshal_amd64_pass_return_struct1_gen (s);
1339 return ((s2.i == 6) && (s2.j == -4) && (s2.k == 0x1000000) && (s2.l == 0x10000000)) ? 0 : 1;
1346 public static int test_0_marshal_byval_class () {
1347 SimpleObj obj0 = new SimpleObj ();
1351 if (class_marshal_test0 (obj0) != 0)
1357 public static int test_0_marshal_byval_class_null () {
1358 if (class_marshal_test4 (null) != 0)
1364 public static int test_0_marshal_out_class () {
1367 class_marshal_test1 (out obj1);
1369 if (obj1.str != "ABC")
1378 public static int test_0_marshal_string () {
1379 return string_marshal_test0 ("TEST0");
1382 public static int test_0_marshal_out_string () {
1385 string_marshal_test1 (out res);
1393 public static int test_0_marshal_byref_string () {
1394 string res = "TEST1";
1396 int r = string_marshal_test2 (ref res);
1404 public static int test_0_marshal_null_string () {
1405 return string_marshal_test3 (null);
1409 [DllImport ("libtest", EntryPoint="mono_test_stdcall_mismatch_1", CallingConvention=CallingConvention.StdCall)]
1410 public static extern int mono_test_stdcall_mismatch_1 (int a, int b, int c);
1412 /* Test mismatched called conventions, the native function is cdecl */
1413 public static int test_0_stdcall_mismatch_1 () {
1414 mono_test_stdcall_mismatch_1 (0, 1, 2);
1418 [DllImport ("libtest", EntryPoint="mono_test_stdcall_mismatch_2", CallingConvention=CallingConvention.Cdecl)]
1419 public static extern int mono_test_stdcall_mismatch_2 (int a, int b, int c);
1421 /* Test mismatched called conventions, the native function is stdcall */
1422 public static int test_0_stdcall_mismatch_2 () {
1423 mono_test_stdcall_mismatch_2 (0, 1, 2);
1428 [DllImport ("libtest", EntryPoint="mono_test_stdcall_name_mangling", CallingConvention=CallingConvention.StdCall)]
1429 public static extern int mono_test_stdcall_name_mangling (int a, int b, int c);
1431 public static int test_0_stdcall_name_mangling () {
1432 return mono_test_stdcall_name_mangling (0, 1, 2) == 3 ? 0 : 1;
1437 [DllImport ("libtest", EntryPoint="mono_test_marshal_pass_return_float")]
1438 public static extern float mono_test_marshal_pass_return_float (float f);
1440 public static int test_0_pass_return_float () {
1441 float f = mono_test_marshal_pass_return_float (1.5f);
1443 return (f == 2.5f) ? 0 : 1;
1447 * Pointers to structures can not be passed
1450 /* This seems to be allowed by MS in some cases */
1452 public struct CharInfo {
1453 public char Character;
1454 public short Attributes;
1457 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct")]
1458 public static unsafe extern int mono_test_marshal_ptr_to_struct (CharInfo *ptr);
1460 public static unsafe int test_0_marshal_ptr_to_struct () {
1461 CharInfo [] buffer = new CharInfo [1];
1462 fixed (CharInfo *ptr = &buffer [0]) {
1464 mono_test_marshal_ptr_to_struct (ptr);
1467 catch (MarshalDirectiveException) {
1476 * LPWStr marshalling
1479 [DllImport("libtest", EntryPoint="test_lpwstr_marshal")]
1480 [return: MarshalAs(UnmanagedType.LPWStr)]
1481 private static extern string mono_test_marshal_lpwstr_marshal(
1482 [MarshalAs(UnmanagedType.LPWStr)] string s,
1485 [DllImport("libtest", EntryPoint="test_lpwstr_marshal", CharSet=CharSet.Unicode)]
1486 private static extern string mono_test_marshal_lpwstr_marshal2(
1490 [DllImport("libtest", EntryPoint="test_lpwstr_marshal_out")]
1491 private static extern void mono_test_marshal_lpwstr_out_marshal(
1492 [MarshalAs(UnmanagedType.LPWStr)] out string s);
1494 [DllImport("libtest", EntryPoint="test_lpwstr_marshal_out", CharSet=CharSet.Unicode)]
1495 private static extern void mono_test_marshal_lpwstr_out_marshal2(
1498 public static int test_0_pass_return_lwpstr () {
1501 mono_test_marshal_lpwstr_out_marshal (out s);
1507 mono_test_marshal_lpwstr_out_marshal2 (out s);
1515 public static int test_0_out_lwpstr () {
1518 string res = mono_test_marshal_lpwstr_marshal (s, s.Length);
1523 string res2 = mono_test_marshal_lpwstr_marshal2 (s, s.Length);
1532 * Byref bool marshalling
1535 [DllImport("libtest")]
1536 extern static int marshal_test_ref_bool
1539 [MarshalAs(UnmanagedType.I1)] ref bool b1,
1540 [MarshalAs(UnmanagedType.VariantBool)] ref bool b2,
1544 public static int test_0_pass_byref_bool () {
1545 for (int i = 0; i < 8; i++)
1547 bool b1 = (i & 4) != 0;
1548 bool b2 = (i & 2) != 0;
1549 bool b3 = (i & 1) != 0;
1550 bool orig_b1 = b1, orig_b2 = b2, orig_b3 = b3;
1551 if (marshal_test_ref_bool(i, ref b1, ref b2, ref b3) != 0)
1565 * Bool struct field marshalling
1571 [MarshalAs(UnmanagedType.I1)] public bool b1;
1572 [MarshalAs(UnmanagedType.VariantBool)] public bool b2;
1576 [DllImport("libtest")]
1577 extern static int marshal_test_bool_struct(ref BoolStruct s);
1579 public static int test_0_pass_bool_in_struct () {
1580 for (int i = 0; i < 8; i++)
1582 BoolStruct s = new BoolStruct();
1584 s.b1 = (i & 4) != 0;
1585 s.b2 = (i & 2) != 0;
1586 s.b3 = (i & 1) != 0;
1587 BoolStruct orig = s;
1588 if (marshal_test_bool_struct(ref s) != 0)
1590 if (s.b1 != !orig.b1)
1592 if (s.b2 != !orig.b2)
1594 if (s.b3 != !orig.b3)
1602 * Alignment of structs containing longs
1605 struct LongStruct2 {
1611 public LongStruct2 l;
1614 [DllImport("libtest")]
1615 extern static int mono_test_marshal_long_struct (ref LongStruct s);
1617 public static int test_47_pass_long_struct () {
1618 LongStruct s = new LongStruct ();
1620 s.l = new LongStruct2 ();
1623 return mono_test_marshal_long_struct (ref s);
1627 * Invoking pinvoke methods through delegates
1630 delegate int MyDelegate (string name);
1632 [DllImport ("libtest", EntryPoint="mono_test_puts_static")]
1633 public static extern int puts_static (string name);
1635 public static int test_0_invoke_pinvoke_through_delegate () {
1636 puts_static ("A simple Test for PInvoke 1");
1638 MyDelegate d = new MyDelegate (puts_static);
1639 d ("A simple Test for PInvoke 2");
1641 object [] args = {"A simple Test for PInvoke 3"};
1642 d.DynamicInvoke (args);
1648 * Missing virtual pinvoke methods
1653 public virtual object MyClone ()
1659 public class T2 : T {
1660 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1661 public override extern object MyClone ();
1664 public static int test_0_missing_virtual_pinvoke_method () {
1669 } catch (Exception ex) {
1677 * Marshalling of type 'object'
1680 [DllImport ("libtest", EntryPoint="mono_test_marshal_class")]
1681 public static extern SimpleClass mono_test_marshal_object (int i, int j, int k, object ss, int l);
1683 public static int test_0_marshal_object () {
1685 mono_test_marshal_object (0, 0, 0, null, 0);
1687 } catch (Exception) {
1693 * Marshalling of DateTime to OLE DATE (double)
1695 [DllImport ("libtest", EntryPoint="mono_test_marshal_date_time")]
1696 public static extern double mono_test_marshal_date_time (DateTime d, out DateTime d2);
1698 public static int test_0_marshal_date_time () {
1699 DateTime d = new DateTime (2009, 12, 6);
1701 double d3 = mono_test_marshal_date_time (d, out d2);
1710 * Calling pinvoke functions dynamically using calli
1713 [DllImport("libtest")]
1714 private static extern IntPtr mono_test_marshal_lookup_symbol (string fileName);
1716 delegate void CalliDel (IntPtr a, int[] f);
1718 public static int test_0_calli_dynamic () {
1719 /* we need the cdecl version because the icall convention demands it under Windows */
1720 IntPtr func = mono_test_marshal_lookup_symbol ("mono_test_marshal_inout_array_cdecl");
1722 DynamicMethod dm = new DynamicMethod ("calli", typeof (void), new Type [] { typeof (IntPtr), typeof (int[]) });
1724 var il = dm.GetILGenerator ();
1725 var signature = SignatureHelper.GetMethodSigHelper (CallingConvention.Cdecl, typeof (void));
1727 il.Emit (OpCodes.Ldarg, 1);
1728 signature.AddArgument (typeof (byte[]));
1730 il.Emit (OpCodes.Ldarg_0);
1732 il.Emit (OpCodes.Calli, signature);
1733 il.Emit (OpCodes.Ret);
1735 var f = (CalliDel)dm.CreateDelegate (typeof (CalliDel));
1737 int[] arr = new int [1000];
1738 for (int i = 0; i < 50; ++i)
1741 if (arr.Length != 1000)
1743 for (int i = 0; i < 50; ++i)
1744 if (arr [i] != 50 - i)
1751 /*char array marshaling */
1752 [DllImport ("libtest", EntryPoint="mono_test_marshal_ansi_char_array", CharSet=CharSet.Ansi)]
1753 public static extern int mono_test_marshal_ansi_char_array (char[] a1);
1755 public static int test_0_marshal_ansi_char_array () {
1756 char[] buf = new char [32];
1762 if (mono_test_marshal_ansi_char_array (buf) != 0)
1765 string s = new string (buf);
1766 if (s.StartsWith ("qwer"))
1772 /*char array marshaling */
1773 [DllImport ("libtest", EntryPoint="mono_test_marshal_unicode_char_array", CharSet=CharSet.Unicode)]
1774 public static extern int mono_test_marshal_unicode_char_array (char[] a1);
1776 public static int test_0_marshal_unicode_char_array () {
1777 char[] buf = new char [32];
1783 if (mono_test_marshal_unicode_char_array (buf) != 0)
1786 string s = new string (buf);
1787 if (s.StartsWith ("abcdef"))
1793 [DllImport ("libtest", EntryPoint="mono_test_marshal_lpstr")]
1794 public static extern int mono_test_marshal_lpstr ([MarshalAs(UnmanagedType.LPStr)] string str);
1796 public static int test_0_mono_test_marshal_lpstr () {
1799 if (mono_test_marshal_lpstr (str) != 0)
1805 [DllImport ("libtest", EntryPoint="mono_test_marshal_lpwstr")]
1806 public static extern int mono_test_marshal_lpwstr ([MarshalAs(UnmanagedType.LPWStr)] string str);
1808 public static int test_0_mono_test_marshal_lpwstr () {
1811 if (mono_test_marshal_lpwstr (str) != 0)
1818 [method: DllImport ("libtest", EntryPoint="mono_test_marshal_return_lpstr")]
1819 [return: MarshalAs(UnmanagedType.LPStr)]
1820 public static extern string mono_test_marshal_return_lpstr ();
1822 public static int test_0_mono_test_marshal_return_lpstr () {
1823 string str = mono_test_marshal_return_lpstr ();
1830 [method: DllImport ("libtest", EntryPoint="mono_test_marshal_return_lpwstr")]
1831 [return: MarshalAs(UnmanagedType.LPWStr)]
1832 public static extern string mono_test_marshal_return_lpwstr ();
1834 public static int test_0_mono_test_marshal_return_lpwstr () {
1835 string str = mono_test_marshal_return_lpwstr ();
1842 [DllImport ("libtest", EntryPoint="mono_test_has_thiscall")]
1843 public static extern int mono_test_has_thiscall ();
1845 [DllImport ("libtest", EntryPoint = "_mono_test_native_thiscall1", CallingConvention=CallingConvention.ThisCall)]
1846 public static extern int mono_test_native_thiscall (int a);
1848 [DllImport ("libtest", EntryPoint = "_mono_test_native_thiscall2", CallingConvention=CallingConvention.ThisCall)]
1849 public static extern int mono_test_native_thiscall (int a, int b);
1851 [DllImport ("libtest", EntryPoint = "_mono_test_native_thiscall3", CallingConvention=CallingConvention.ThisCall)]
1852 public static extern int mono_test_native_thiscall (int a, int b, int c);
1854 [DllImport ("libtest", EntryPoint = "_mono_test_native_thiscall1", CallingConvention=CallingConvention.ThisCall)]
1855 public static extern int mono_test_native_thiscall (TinyStruct a);
1857 [DllImport ("libtest", EntryPoint = "_mono_test_native_thiscall2", CallingConvention=CallingConvention.ThisCall)]
1858 public static extern int mono_test_native_thiscall (TinyStruct a, int b);
1860 [DllImport ("libtest", EntryPoint = "_mono_test_native_thiscall3", CallingConvention=CallingConvention.ThisCall)]
1861 public static extern int mono_test_native_thiscall (TinyStruct a, int b, int c);
1863 public static int test_0_native_thiscall ()
1865 if (mono_test_has_thiscall () == 0)
1868 if (mono_test_native_thiscall (1968329802) != 1968329802)
1871 if (mono_test_native_thiscall (268894549, 1212675791) != 1481570339)
1874 if (mono_test_native_thiscall (1288082683, -421187449, -1733670329) != -866775098)
1877 if (mono_test_native_thiscall (new TinyStruct(1968329802)) != 1968329802)
1880 if (mono_test_native_thiscall (new TinyStruct(268894549), 1212675791) != 1481570339)
1883 if (mono_test_native_thiscall (new TinyStruct(1288082683), -421187449, -1733670329) != -866775098)
1889 [DllImport ("libtest", EntryPoint = "mono_test_marshal_return_single_double_struct")]
1890 public static extern SingleDoubleStruct mono_test_marshal_return_single_double_struct ();
1892 public static int test_0_x86_single_double_struct_ret () {
1893 double d = mono_test_marshal_return_single_double_struct ().d;