* test-driver: Clean up.
[mono.git] / mono / tests / pinvoke2.cs
1 using System;
2 using System.Text;
3 using System.Runtime.InteropServices;
4
5 public class Tests {
6
7         public static int delegate_test (int a)
8         {
9                 if (a == 2)
10                         return 0;
11
12                 return 1;
13         }
14         
15         [StructLayout (LayoutKind.Sequential)]
16         public struct SimpleStruct {
17                 public bool a;
18                 public bool b;
19                 public bool c;
20                 public string d;
21         }
22
23         [StructLayout (LayoutKind.Sequential)]
24         public struct SimpleStruct2 {
25                 public bool a;
26                 public bool b;
27                 public bool c;
28                 public string d;
29                 public byte e;
30                 public double f;
31                 public byte g;
32                 public long h;
33         }
34
35         [StructLayout (LayoutKind.Sequential, Size=0)]
36         public struct EmptyStruct {
37         }
38
39         [StructLayout (LayoutKind.Sequential)]
40         public struct DelegateStruct {
41                 public int a;
42                 public SimpleDelegate del;
43                 [MarshalAs(UnmanagedType.FunctionPtr)] 
44                 public SimpleDelegate del2;
45         }
46
47         /* sparcv9 has complex conventions when passing structs with doubles in them 
48            by value, some simple tests for them */
49         [StructLayout (LayoutKind.Sequential)]
50         public struct Point {
51                 public double x;
52                 public double y;
53         }
54
55         [StructLayout (LayoutKind.Sequential)]
56         public struct MixedPoint {
57                 public int x;
58                 public double y;
59         }
60
61         [StructLayout (LayoutKind.Sequential)]
62         public class SimpleClass {
63                 public bool a;
64                 public bool b;
65                 public bool c;
66                 public string d;
67                 public byte e;
68                 public double f;
69                 public byte g;
70                 public long h;
71         }
72
73         [StructLayout (LayoutKind.Sequential)]
74         public class EmptyClass {
75         }
76
77         [StructLayout (LayoutKind.Sequential)]
78         public struct LongAlignStruct {
79                 public int a;
80                 public long b;
81                 public long c;
82         }
83
84         [StructLayout(LayoutKind.Sequential)]
85         public class VectorList
86         {
87                 public int a = 1;
88                 public int b = 2;
89         }
90
91         [StructLayout (LayoutKind.Sequential)]
92         class SimpleObj
93         {
94                 public string str;
95                 public int i;
96         }
97
98         [DllImport ("libnot-found", EntryPoint="not_found")]
99         public static extern int mono_library_not_found ();
100
101         [DllImport ("libtest", EntryPoint="not_found")]
102         public static extern int mono_entry_point_not_found ();
103
104         [DllImport ("libtest.dll", EntryPoint="mono_test_marshal_char")]
105         public static extern int mono_test_marshal_char_2 (char a1);
106
107         [DllImport ("test", EntryPoint="mono_test_marshal_char")]
108         public static extern int mono_test_marshal_char_3 (char a1);
109
110         [DllImport ("libtest", EntryPoint="mono_test_marshal_char")]
111         public static extern int mono_test_marshal_char (char a1);
112
113         [DllImport ("libtest", EntryPoint="mono_test_marshal_char_array")]
114         public static extern int mono_test_marshal_char_array (char[] a1);
115
116         [DllImport ("libtest", EntryPoint="mono_test_marshal_bool_byref")]
117         public static extern int mono_test_marshal_bool_byref (int a, ref bool b, int c);
118
119         [DllImport ("libtest", EntryPoint="mono_test_marshal_array")]
120         public static extern int mono_test_marshal_array (int [] a1);
121
122         [DllImport ("libtest", EntryPoint="mono_test_marshal_empty_string_array")]
123         public static extern int mono_test_marshal_empty_string_array (string [] a1);
124
125         [DllImport ("libtest", EntryPoint="mono_test_marshal_string_array")]
126         public static extern int mono_test_marshal_string_array (string [] a1);
127
128         [DllImport ("libtest", EntryPoint="mono_test_marshal_unicode_string_array", CharSet=CharSet.Unicode)]
129         public static extern int mono_test_marshal_unicode_string_array (string [] a1, [MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr)]string [] a2);
130
131         [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_array")]
132         public static extern int mono_test_marshal_stringbuilder_array (StringBuilder [] a1);   
133
134         [DllImport ("libtest", EntryPoint="mono_test_marshal_inout_array")]
135         public static extern int mono_test_marshal_inout_array ([In, Out] int [] a1);
136
137         [DllImport ("libtest", EntryPoint="mono_test_marshal_inout_nonblittable_array", CharSet = CharSet.Unicode)]
138         public static extern int mono_test_marshal_inout_nonblittable_array ([In, Out] char [] a1);
139         
140         [DllImport ("libtest", EntryPoint="mono_test_marshal_struct")]
141         public static extern int mono_test_marshal_struct (SimpleStruct ss);
142
143         [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2")]
144         public static extern int mono_test_marshal_struct2 (SimpleStruct2 ss);
145
146         [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2_2")]
147         public static extern int mono_test_marshal_struct2_2 (int i, int j, int k, SimpleStruct2 ss);
148
149         [DllImport ("libtest", EntryPoint="mono_test_marshal_point")]
150         public static extern int mono_test_marshal_point (Point p);
151
152         [DllImport ("libtest", EntryPoint="mono_test_marshal_mixed_point")]
153         public static extern int mono_test_marshal_mixed_point (MixedPoint p);
154
155         [DllImport ("libtest", EntryPoint="mono_test_empty_struct")]
156         public static extern int mono_test_empty_struct (int a, EmptyStruct es, int b);
157
158         [DllImport ("libtest", EntryPoint="mono_test_marshal_struct_array")]
159         public static extern int mono_test_marshal_struct_array (SimpleStruct2[] ss);
160
161         [DllImport ("libtest", EntryPoint="mono_test_marshal_long_align_struct_array")]
162         public static extern int mono_test_marshal_long_align_struct_array (LongAlignStruct[] ss);
163
164         [DllImport ("libtest", EntryPoint="mono_test_marshal_class")]
165         public static extern SimpleClass mono_test_marshal_class (int i, int j, int k, SimpleClass ss, int l);
166
167         [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_class")]
168         public static extern int mono_test_marshal_byref_class (ref SimpleClass ss);
169
170         [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate")]
171         public static extern int mono_test_marshal_delegate (SimpleDelegate d);
172
173         [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate_struct")]
174         public static extern int mono_test_marshal_delegate_struct (DelegateStruct d);
175
176         [DllImport ("libtest", EntryPoint="mono_test_marshal_return_delegate")]
177         public static extern SimpleDelegate mono_test_marshal_return_delegate (SimpleDelegate d);
178
179         [DllImport ("libtest", EntryPoint="mono_test_return_vtype")]
180         public static extern SimpleStruct mono_test_return_vtype (IntPtr i);
181
182         [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder")]
183         public static extern void mono_test_marshal_stringbuilder (StringBuilder sb, int len);
184
185         [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_unicode", CharSet=CharSet.Unicode)]
186         public static extern void mono_test_marshal_stringbuilder_unicode (StringBuilder sb, int len);
187
188         [DllImport ("libtest", EntryPoint="mono_test_last_error", SetLastError=true)]
189         public static extern void mono_test_last_error (int err);
190
191         [DllImport ("libtest", EntryPoint="mono_test_asany")]
192         public static extern int mono_test_asany ([MarshalAs (UnmanagedType.AsAny)] object o, int what);
193
194         [DllImport ("libtest", EntryPoint="mono_test_asany", CharSet=CharSet.Unicode)]
195         public static extern int mono_test_asany_unicode ([MarshalAs (UnmanagedType.AsAny)] object o, int what);
196
197         [DllImport ("libtest")]
198         static extern int class_marshal_test0 (SimpleObj obj);
199
200         [DllImport ("libtest")]
201         static extern void class_marshal_test1 (out SimpleObj obj);
202         
203         [DllImport ("libtest")]
204         static extern int class_marshal_test2 (ref SimpleObj obj);
205
206         [DllImport ("libtest")]
207         static extern int class_marshal_test4 (SimpleObj obj);
208
209         public delegate int SimpleDelegate (int a);
210
211         public static int Main (string[] args) {
212                 return TestDriver.RunTests (typeof (Tests), args);
213         }
214
215         static int test_0_marshal_char () {
216                 return mono_test_marshal_char ('a');
217         }
218
219         static int test_0_marshal_char_array () {
220                 // char[] is implicitly marshalled as [Out]
221                 char[] buf = new char [32];
222                 mono_test_marshal_char_array (buf);
223                 string s = new string (buf);
224                 if (s.StartsWith ("abcdef"))
225                         return 0;
226                 else
227                         return 1;
228         }
229
230         static int test_1225_marshal_array () {
231                 int [] a1 = new int [50];
232                 for (int i = 0; i < 50; i++)
233                         a1 [i] = i;
234
235                 return mono_test_marshal_array (a1);
236         }
237
238         static int test_1225_marshal_inout_array () {
239                 int [] a1 = new int [50];
240                 for (int i = 0; i < 50; i++)
241                         a1 [i] = i;
242
243                 int res = mono_test_marshal_inout_array (a1);
244
245                 for (int i = 0; i < 50; i++)
246                         if (a1 [i] != 50 - i) {
247                                 Console.WriteLine ("X: " + i + " " + a1 [i]);
248                                 return 2;
249                         }
250
251                 return res;
252         }
253
254         static int test_0_marshal_inout_nonblittable_array () {
255                 char [] a1 = new char [10];
256                 for (int i = 0; i < 10; i++)
257                         a1 [i] = "Hello, World" [i];
258
259                 int res = mono_test_marshal_inout_nonblittable_array (a1);
260
261                 for (int i = 0; i < 10; i++)
262                         if (a1 [i] != 'F')
263                                 return 2;
264
265                 return res;
266         }
267
268         static int test_0_marshal_struct () {
269                 SimpleStruct ss = new  SimpleStruct ();
270                 ss.b = true;
271                 ss.d = "TEST";
272                 
273                 return mono_test_marshal_struct (ss);
274         }
275
276         static int test_0_marshal_struct2 () {
277                 SimpleStruct2 ss2 = new  SimpleStruct2 ();
278                 ss2.b = true;
279                 ss2.d = "TEST";
280                 ss2.e = 99;
281                 ss2.f = 1.5;
282                 ss2.g = 42;
283                 ss2.h = 123L;
284
285                 return mono_test_marshal_struct2 (ss2);
286         }
287
288         static int test_0_marshal_struct3 () {
289                 SimpleStruct2 ss2 = new  SimpleStruct2 ();
290                 ss2.b = true;
291                 ss2.d = "TEST";
292                 ss2.e = 99;
293                 ss2.f = 1.5;
294                 ss2.g = 42;
295                 ss2.h = 123L;
296
297                 return mono_test_marshal_struct2_2 (10, 11, 12, ss2);
298         }
299
300         static int test_0_marshal_empty_struct () {
301                 EmptyStruct es = new EmptyStruct ();
302
303                 if (mono_test_empty_struct (1, es, 2) != 0)
304                         return 1;
305                 
306                 return 0;
307         }
308
309         static int test_0_marshal_struct_array () {
310                 SimpleStruct2[] ss_arr = new SimpleStruct2 [2];
311
312                 SimpleStruct2 ss2 = new SimpleStruct2 ();
313                 ss2.b = true;
314                 ss2.d = "TEST";
315                 ss2.e = 99;
316                 ss2.f = 1.5;
317                 ss2.g = 42;
318                 ss2.h = 123L;
319
320                 ss_arr [0] = ss2;
321
322                 ss2.b = false;
323                 ss2.d = "TEST2";
324                 ss2.e = 100;
325                 ss2.f = 2.5;
326                 ss2.g = 43;
327                 ss2.h = 124L;
328
329                 ss_arr [1] = ss2;
330
331                 return mono_test_marshal_struct_array (ss_arr);
332         }
333
334         static int test_105_marshal_long_align_struct_array () {
335                 LongAlignStruct[] ss_arr = new LongAlignStruct [2];
336
337                 LongAlignStruct ss = new LongAlignStruct ();
338                 ss.a = 5;
339                 ss.b = 10;
340                 ss.c = 15;
341
342                 ss_arr [0] = ss;
343
344                 ss.a = 20;
345                 ss.b = 25;
346                 ss.c = 30;
347
348                 ss_arr [1] = ss;
349
350                 return mono_test_marshal_long_align_struct_array (ss_arr);
351         }
352
353         /* Test classes as arguments and return values */
354         static int test_0_marshal_class () {
355                 SimpleClass ss = new  SimpleClass ();
356                 ss.b = true;
357                 ss.d = "TEST";
358                 ss.e = 99;
359                 ss.f = 1.5;
360                 ss.g = 42;
361                 ss.h = 123L;
362
363                 SimpleClass res = mono_test_marshal_class (10, 11, 12, ss, 14);
364                 if (res == null)
365                         return 1;
366                 if  (! (res.a == ss.a && res.b == ss.b && res.c == ss.c && 
367                                 res.d == ss.d && res.e == ss.e && res.f == ss.f &&
368                                 res.g == ss.g && res.h == ss.h))
369                         return 2;
370
371                 /* Test null arguments and results */
372                 res = mono_test_marshal_class (10, 11, 12, null, 14);
373                 if (res != null)
374                         return 3;
375
376                 return 0;
377         }
378
379         static int test_0_marshal_byref_class () {
380                 SimpleClass ss = new  SimpleClass ();
381                 ss.b = true;
382                 ss.d = "TEST";
383                 ss.e = 99;
384                 ss.f = 1.5;
385                 ss.g = 42;
386                 ss.h = 123L;
387
388                 int res = mono_test_marshal_byref_class (ref ss);
389                 if (ss.d != "TEST-RES")
390                         return 1;
391
392                 return 0;
393         }
394
395         static int test_0_marshal_delegate () {
396                 SimpleDelegate d = new SimpleDelegate (delegate_test);
397
398                 return mono_test_marshal_delegate (d);
399         }
400
401         static int test_0_marshal_return_delegate () {
402                 SimpleDelegate d = new SimpleDelegate (delegate_test);
403
404                 SimpleDelegate d2 = mono_test_marshal_return_delegate (d);
405
406                 return d2 (2);
407         }
408
409         static int test_0_marshal_delegate_struct () {
410                 DelegateStruct s = new DelegateStruct ();
411
412                 s.a = 2;
413                 s.del = new SimpleDelegate (delegate_test);
414                 s.del2 = new SimpleDelegate (delegate_test);
415
416                 return mono_test_marshal_delegate_struct (s);
417         }
418
419         static int test_0_marshal_point () {
420                 Point pt = new Point();
421                 pt.x = 1.25;
422                 pt.y = 3.5;
423                 
424                 return mono_test_marshal_point(pt);
425         }
426
427         static int test_0_marshal_mixed_point () {
428                 MixedPoint mpt = new MixedPoint();
429                 mpt.x = 5;
430                 mpt.y = 6.75;
431                 
432                 return mono_test_marshal_mixed_point(mpt);
433         }
434
435         static int test_0_marshal_bool_byref () {
436                 bool b = true;
437                 if (mono_test_marshal_bool_byref (99, ref b, 100) != 1)
438                         return 1;
439                 b = false;
440                 if (mono_test_marshal_bool_byref (99, ref b, 100) != 0)
441                         return 12;
442                 if (b != true)
443                         return 13;
444
445                 return 0;
446         }
447
448         static int test_0_return_vtype () {
449                 SimpleStruct ss = mono_test_return_vtype (new IntPtr (5));
450
451                 if (!ss.a && ss.b && !ss.c && ss.d == "TEST")
452                         return 0;
453                 
454                 return 1;
455         }
456
457         static int test_0_marshal_stringbuilder () {
458                 StringBuilder sb = new StringBuilder(255);
459                 sb.Append ("ABCD");
460                 mono_test_marshal_stringbuilder (sb, sb.Capacity);
461                 String res = sb.ToString();
462
463                 if (res != "This is my message.  Isn't it nice?")
464                         return 1;  
465                 
466                 return 0;
467         }
468
469         static int test_0_marshal_stringbuilder_unicode () {
470                 StringBuilder sb = new StringBuilder(255);
471                 mono_test_marshal_stringbuilder_unicode (sb, sb.Capacity);
472                 String res = sb.ToString();
473
474                 if (res != "This is my message.  Isn't it nice?")
475                         return 1;  
476                 
477                 return 0;
478         }
479
480         static int test_0_marshal_empty_string_array () {
481                 return mono_test_marshal_empty_string_array (null);
482         }
483
484         static int test_0_marshal_string_array () {
485                 return mono_test_marshal_string_array (new String [] { "ABC", "DEF" });
486         }
487
488         static int test_0_marshal_unicode_string_array () {
489                 return mono_test_marshal_unicode_string_array (new String [] { "ABC", "DEF" }, new String [] { "ABC", "DEF" });
490         }
491
492         static int test_0_marshal_stringbuilder_array () {
493                 StringBuilder sb1 = new StringBuilder ("ABC");
494                 StringBuilder sb2 = new StringBuilder ("DEF");
495
496                 int res = mono_test_marshal_stringbuilder_array (new StringBuilder [] { sb1, sb2 });
497                 if (res != 0)
498                         return res;
499                 if (sb1.ToString () != "DEF")
500                         return 5;
501                 if (sb2.ToString () != "ABC")
502                         return 6;
503                 return 0;
504         }
505
506         static int test_0_last_error () {
507                 mono_test_last_error (5);
508                 if (Marshal.GetLastWin32Error () == 5)
509                         return 0;
510                 else
511                         return 1;
512         }
513
514         static int test_0_library_not_found () {
515
516                 try {
517                         mono_entry_point_not_found ();
518                         return 1;
519                 }
520                 catch (EntryPointNotFoundException) {
521                 }
522
523                 return 0;
524         }
525
526         static int test_0_entry_point_not_found () {
527
528                 try {
529                         mono_library_not_found ();
530                         return 1;
531                 }
532                 catch (DllNotFoundException) {
533                 }
534
535                 return 0;
536         }
537
538         /* Check that the runtime trims .dll from the library name */
539         static int test_0_trim_dll_from_name () {
540
541                 mono_test_marshal_char_2 ('A');
542
543                 return 0;
544         }
545
546         /* Check that the runtime adds lib to to the library name */
547         static int test_0_add_lib_to_name () {
548
549                 mono_test_marshal_char_3 ('A');
550
551                 return 0;
552         }
553
554         class C {
555                 public int i;
556         }
557
558         static int test_0_asany () {
559                 if (mono_test_asany (5, 1) != 0)
560                         return 1;
561
562                 if (mono_test_asany ("ABC", 2) != 0)
563                         return 2;
564
565                 SimpleStruct2 ss2 = new  SimpleStruct2 ();
566                 ss2.b = true;
567                 ss2.d = "TEST";
568                 ss2.e = 99;
569                 ss2.f = 1.5;
570                 ss2.g = 42;
571                 ss2.h = 123L;
572
573                 if (mono_test_asany (ss2, 3) != 0)
574                         return 3;
575
576                 if (mono_test_asany_unicode ("ABC", 4) != 0)
577                         return 4;
578
579                 try {
580                         C c = new C ();
581                         c.i = 5;
582                         mono_test_asany (c, 0);
583                         return 5;
584                 }
585                 catch (ArgumentException) {
586                 }
587
588                 try {
589                         mono_test_asany (new Object (), 0);
590                         return 6;
591                 }
592                 catch (ArgumentException) {
593                 }
594
595                 return 0;
596         }
597
598         /* Byref String Array */
599
600         [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_string_array")]
601         public static extern int mono_test_marshal_byref_string_array (ref string[] data);
602
603         public static int test_0_byref_string_array () {
604
605                 string[] arr = null;
606
607                 if (mono_test_marshal_byref_string_array (ref arr) != 0)
608                         return 1;
609
610                 arr = new string[] { "Alpha", "Beta", "Gamma" };
611
612                 if (mono_test_marshal_byref_string_array (ref arr) != 1)
613                         return 2;
614
615                 /* FIXME: Test returned array and out case */
616
617                 return 0;
618         }
619
620         /*
621          * AMD64 small structs-by-value tests.
622          */
623
624         /* TEST 1: 16 byte long INTEGER struct */
625
626         [StructLayout(LayoutKind.Sequential)]
627         public struct Amd64Struct1 {
628                 public int i;
629                 public int j;
630                 public int k;
631                 public int l;
632         }
633         
634         [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct1")]
635         public static extern Amd64Struct1 mono_test_marshal_amd64_pass_return_struct1 (Amd64Struct1 s);
636
637         public static int test_0_amd64_struct1 () {
638                 Amd64Struct1 s = new Amd64Struct1 ();
639                 s.i = 5;
640                 s.j = -5;
641                 s.k = 0xffffff;
642                 s.l = 0xfffffff;
643
644                 Amd64Struct1 s2 = mono_test_marshal_amd64_pass_return_struct1 (s);
645
646                 return ((s2.i == 6) && (s2.j == -4) && (s2.k == 0x1000000) && (s2.l == 0x10000000)) ? 0 : 1;
647         }
648
649         /* TEST 2: 8 byte long INTEGER struct */
650
651         [StructLayout(LayoutKind.Sequential)]
652         public struct Amd64Struct2 {
653                 public int i;
654                 public int j;
655         }
656         
657         [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct2")]
658         public static extern Amd64Struct2 mono_test_marshal_amd64_pass_return_struct2 (Amd64Struct2 s);
659
660         public static int test_0_amd64_struct2 () {
661                 Amd64Struct2 s = new Amd64Struct2 ();
662                 s.i = 5;
663                 s.j = -5;
664
665                 Amd64Struct2 s2 = mono_test_marshal_amd64_pass_return_struct2 (s);
666
667                 return ((s2.i == 6) && (s2.j == -4)) ? 0 : 1;
668         }
669
670         /* TEST 3: 4 byte long INTEGER struct */
671
672         [StructLayout(LayoutKind.Sequential)]
673         public struct Amd64Struct3 {
674                 public int i;
675         }
676         
677         [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct3")]
678         public static extern Amd64Struct3 mono_test_marshal_amd64_pass_return_struct3 (Amd64Struct3 s);
679
680         public static int test_0_amd64_struct3 () {
681                 Amd64Struct3 s = new Amd64Struct3 ();
682                 s.i = -5;
683
684                 Amd64Struct3 s2 = mono_test_marshal_amd64_pass_return_struct3 (s);
685
686                 return (s2.i == -4) ? 0 : 1;
687         }
688
689         /* Test 4: 16 byte long FLOAT struct */
690
691         [StructLayout(LayoutKind.Sequential)]
692         public struct Amd64Struct4 {
693                 public double d1, d2;
694         }
695         
696         [DllImport ("libtest", EntryPoint="mono_test_marshal_amd64_pass_return_struct4")]
697         public static extern Amd64Struct4 mono_test_marshal_amd64_pass_return_struct4 (Amd64Struct4 s);
698
699         public static int test_0_amd64_struct4 () {
700                 Amd64Struct4 s = new Amd64Struct4 ();
701                 s.d1 = 5.0;
702                 s.d2 = -5.0;
703
704                 Amd64Struct4 s2 = mono_test_marshal_amd64_pass_return_struct4 (s);
705
706                 return (s2.d1 == 6.0 && s2.d2 == -4.0) ? 0 : 1;
707         }
708
709         /* Blittable class */
710         [DllImport("libtest")]
711         private static extern VectorList TestVectorList (VectorList vl);
712
713         public static int test_0_marshal_blittable_class () {
714                 VectorList v1 = new VectorList ();
715
716                 /* Since it is blittable, it looks like it is passed as in/out */
717                 VectorList v2 = TestVectorList (v1);
718
719                 if (v1.a != 2 || v1.b != 3)
720                         return 1;
721                 
722                 if (v2.a != 2 || v2.b != 3)
723                         return 2;
724                 
725                 return 0;
726         }
727
728         static int test_0_marshal_byval_class () {
729                 SimpleObj obj0 = new SimpleObj ();
730                 obj0.str = "T1";
731                 obj0.i = 4;
732                 
733                 if (class_marshal_test0 (obj0) != 0)
734                         return 1;
735
736                 return 0;
737         }
738
739         static int test_0_marshal_byval_class_null () {
740                 if (class_marshal_test4 (null) != 0)
741                         return 1;
742
743                 return 0;
744         }
745
746         static int test_0_marshal_out_class () {
747                 SimpleObj obj1;
748
749                 class_marshal_test1 (out obj1);
750
751                 if (obj1.str != "ABC")
752                         return 1;
753
754                 if (obj1.i != 5)
755                         return 2;
756
757                 return 0;
758         }
759
760         [DllImport ("libtest", EntryPoint="mono_test_stdcall_name_mangling", CallingConvention=CallingConvention.StdCall)]
761         public static extern int mono_test_stdcall_name_mangling (int a, int b, int c);
762
763         static int test_0_stdcall_name_mangling () {
764                 return mono_test_stdcall_name_mangling (0, 1, 2) == 3 ? 0 : 1;
765         }
766 }
767