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 /* various small structs for testing struct-by-value where they are handled specially
26    on some platforms.
27 */
28 [StructLayout(LayoutKind.Sequential)]
29 public struct sc1
30 {
31 	public byte c0;
32 }
33 
34 [StructLayout(LayoutKind.Sequential)]
35 public struct sc3
36 {
37 	public byte c0;
38 	public byte c1;
39 	public byte c2;
40 }
41 
42 [StructLayout(LayoutKind.Sequential)]
43 public struct sc5
44 {
45 	public byte c0;
46 	public byte c1;
47 	public byte c2;
48 	public byte c3;
49 	public byte c4;
50 }
51 
52 public struct FI {
53 	public float f1;
54 	public float f2;
55 	public float f3;
56 }
57 
58 public struct NestedFloat {
59 	public FI fi;
60 	public float f4;
61 }
62 
63 public class Test
64 {
65 	[DllImport ("libtest")]
mono_union_test_1(cs a)66 	public static extern int mono_union_test_1 (cs a);
67 
68 	[DllImport ("libtest")]
mono_return_int(int a)69 	public static extern int mono_return_int (int a);
70 
71 	[DllImport ("libtest", EntryPoint="mono_return_int_ss")]
mono_return_int_ss(ss a)72 	public static extern int mono_return_int_ss (ss a);
73 
74 	[DllImport ("libtest", EntryPoint="mono_return_ss")]
mono_return_ss(ss a)75 	public static extern ss mono_return_ss (ss a);
76 
77 	[DllImport ("libtest", EntryPoint="mono_return_sc1")]
mono_return_sc1(sc1 a)78 	public static extern sc1 mono_return_sc1 (sc1 a);
79 
80 	[DllImport ("libtest", EntryPoint="mono_return_sc3")]
mono_return_sc3(sc3 a)81 	public static extern sc3 mono_return_sc3 (sc3 a);
82 
83 	[DllImport ("libtest", EntryPoint="mono_return_sc5")]
mono_return_sc5(sc5 a)84 	public static extern sc5 mono_return_sc5 (sc5 a);
85 
86 	[DllImport ("libtest", EntryPoint="mono_return_int_su")]
mono_return_int_su(su a)87 	public static extern int mono_return_int_su (su a);
88 
89 	[DllImport ("libtest", EntryPoint="mono_return_nested_float")]
mono_return_nested_float()90 	public static extern NestedFloat mono_return_nested_float ();
91 
Main()92         static int Main()
93         {
94 		if (mono_return_int (5) != 5)
95 			return 1;
96 
97 		ss s1;
98 		s1.i1 = 4;
99 		if (mono_return_int_ss (s1) != 4)
100 			return 2;
101 
102 		s1 = mono_return_ss (s1);
103 		if (s1.i1 != 5)
104 			return 3;
105 
106 		su s2;
107 		s2.i1 = 2;
108 		s2.i2 = 3;
109 		if (mono_return_int_su (s2) != 3)
110 			return 4;
111 
112 		s2.i1 = 2;
113 		if (mono_return_int_su (s2) != 2)
114 			return 5;
115 
116 
117 		cs s3;
118 		s3.b1 = false;
119 		s3.i1 = 12;
120 		s3.u1.i1 = 2;
121 		s3.u1.i2 = 1;
122 
123 		if (mono_union_test_1 (s3) != 13)
124 			return 6;
125 
126 		s3.u1.i1 = 2;
127 		if (mono_union_test_1 (s3) != 14)
128 			return 7;
129 
130 		s3.b1 = true;
131 		if (mono_union_test_1 (s3) != 15)
132 			return 8;
133 
134 		sc1 s4;
135 		s4.c0 = 3;
136 		s4 = mono_return_sc1(s4);
137 		if (s4.c0 != 4)
138 			return 9;
139 
140 		sc3 s5;
141 		s5.c0 = 4;
142 		s5.c1 = 5;
143 		s5.c2 = 6;
144 		s5 = mono_return_sc3(s5);
145 		if (s5.c0 != 5 || s5.c1 != 7 || s5.c2 != 9)
146 			return 10;
147 
148 		sc5 s6;
149 		s6.c0 = 4;
150 		s6.c1 = 5;
151 		s6.c2 = 6;
152 		s6.c3 = 7;
153 		s6.c4 = 8;
154 		s6 = mono_return_sc5(s6);
155 		if (s6.c0 != 5 || s6.c1 != 7 || s6.c2 != 9 || s6.c3 != 11 || s6.c4 != 13)
156 			return 11;
157 
158 		var f = mono_return_nested_float ();
159 		if (f.fi.f1 != 1.0)
160 			return 12;
161 
162 		return 0;
163         }
164 }
165 
166