Updates and fixes, mostly from Bernie Solomon <bernard@ugsolutions.com>.
[mono.git] / mono / tests / pinvoke11.cs
1 using System;
2 using System.Runtime.InteropServices;
3
4 [StructLayout(LayoutKind.Sequential)]
5 public struct ss
6 {
7         public int i1;
8 }
9
10 [StructLayout(LayoutKind.Explicit)]
11 public struct su
12 {
13         [FieldOffset(0)] public int i1;
14         [FieldOffset(0)] public int i2;
15 }
16
17 [StructLayout(LayoutKind.Sequential)]
18 public struct cs
19 {
20         public bool b1;
21         public int i1;
22         public su u1;
23 }
24
25 public class Test
26 {
27         [DllImport ("libtest.so")]
28         public static extern int mono_union_test_1 (cs a);
29
30         [DllImport ("libtest.so")]
31         public static extern int mono_return_int (int a);
32
33         [DllImport ("libtest.so", EntryPoint="mono_return_int_ss")]
34         public static extern int mono_return_int_ss (ss a);
35
36         [DllImport ("libtest.so", EntryPoint="mono_return_int_su")]
37         public static extern int mono_return_int_su (su a);
38
39         static int Main()
40         {
41                 if (mono_return_int (5) != 5)
42                         return 1;
43
44                 ss s1;
45                 s1.i1 = 4;
46                 if (mono_return_int_ss (s1) != 4)
47                         return 2;
48                 
49                 su s2;
50                 s2.i1 = 2;
51                 s2.i2 = 3;
52                 if (mono_return_int_su (s2) != 3)
53                         return 3;
54                 
55                 s2.i1 = 2;
56                 if (mono_return_int_su (s2) != 2)
57                         return 4;
58
59
60                 cs s3;
61                 s3.b1 = false;
62                 s3.i1 = 12;
63                 s3.u1.i1 = 2;
64                 s3.u1.i2 = 1;
65                 
66                 if (mono_union_test_1 (s3) != 13)
67                         return 5;
68
69                 s3.u1.i1 = 2;
70                 if (mono_union_test_1 (s3) != 14)
71                         return 6;
72
73                 s3.b1 = true;
74                 if (mono_union_test_1 (s3) != 15)
75                         return 7;
76                 
77                 return 0;
78         }
79 }
80