Add assert when dllmap is disabled and fix support build in netcore mode
[mono-project.git] / mono / tests / pinvoke_ppcf.cs
bloba7f519e557cef0ab9011a5487120becb5a64aba2
1 // pinvoke_ppcf.cs - Test cases for passing structures to and and returning
2 // structures from functions. This particular test is for
3 // structures consisting wholy of 4 byte fields.
4 //
5 // The Power ABI version 2 allows for special parameter
6 // passing and returning optimizations for certain
7 // structures of homogenous composition (like all ints).
8 // This set of tests checks all the possible combinations
9 // that use the special parm/return rules and one beyond.
11 // Bill Seurer (seurer@linux.vnet.ibm.com)
13 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
16 using System;
17 using System.Runtime.InteropServices;
20 public class Test_float {
22 [DllImport ("libtest", EntryPoint="mono_return_float1")]
23 public static extern float1 mono_return_float1 (float1 s, int addend);
24 [StructLayout(LayoutKind.Sequential)]
25 public struct float1 {
26 public float f1;
28 [DllImport ("libtest", EntryPoint="mono_return_float2")]
29 public static extern float2 mono_return_float2 (float2 s, int addend);
30 [StructLayout(LayoutKind.Sequential)]
31 public struct float2 {
32 public float f1,f2;
34 [DllImport ("libtest", EntryPoint="mono_return_float3")]
35 public static extern float3 mono_return_float3 (float3 s, int addend);
36 [StructLayout(LayoutKind.Sequential)]
37 public struct float3 {
38 public float f1,f2,f3;
40 [DllImport ("libtest", EntryPoint="mono_return_float4")]
41 public static extern float4 mono_return_float4 (float4 s, int addend);
42 [StructLayout(LayoutKind.Sequential)]
43 public struct float4 {
44 public float f1,f2,f3,f4;
46 // This structure is 1 element too large to use the special return
47 // rules.
48 [DllImport ("libtest", EntryPoint="mono_return_float5")]
49 public static extern float5 mono_return_float5 (float5 s, int addend);
50 [StructLayout(LayoutKind.Sequential)]
51 public struct float5 {
52 public float f1,f2,f3,f4,f5;
54 [DllImport ("libtest", EntryPoint="mono_return_float6")]
55 public static extern float6 mono_return_float6 (float6 s, int addend);
56 [StructLayout(LayoutKind.Sequential)]
57 public struct float6 {
58 public float f1,f2,f3,f4,f5,f6;
60 [DllImport ("libtest", EntryPoint="mono_return_float7")]
61 public static extern float7 mono_return_float7 (float7 s, int addend);
62 [StructLayout(LayoutKind.Sequential)]
63 public struct float7 {
64 public float f1,f2,f3,f4,f5,f6,f7;
66 [DllImport ("libtest", EntryPoint="mono_return_float8")]
67 public static extern float8 mono_return_float8 (float8 s, int addend);
68 [StructLayout(LayoutKind.Sequential)]
69 public struct float8 {
70 public float f1,f2,f3,f4,f5,f6,f7,f8;
72 // This structure is 1 element too large to use the special parameter
73 // passing rules.
74 [DllImport ("libtest", EntryPoint="mono_return_float9")]
75 public static extern float9 mono_return_float9 (float9 s, int addend);
76 [StructLayout(LayoutKind.Sequential)]
77 public struct float9 {
78 public float f1,f2,f3,f4,f5,f6,f7,f8,f9;
81 // This structure has nested structures within it but they are
82 // homogenous and thus should still use the special rules.
83 public struct float4_nested1 {
84 public float f1;
86 public struct float4_nested2 {
87 public float f4;
89 [DllImport ("libtest", EntryPoint="mono_return_float4_nested")]
90 public static extern float4_nested mono_return_float4_nested (float4_nested s, int addend);
91 [StructLayout(LayoutKind.Sequential)]
92 public struct float4_nested {
93 public float4_nested1 nested1;
94 public float f2,f3;
95 public float4_nested2 nested2;
98 public static int Main (string[] args) {
100 float1 s1;
101 s1.f1 = 1;
102 s1 = mono_return_float1(s1, 906);
103 if (s1.f1 != 1+906) {
104 Console.WriteLine(" float1 s1.f1: got {0} but expected {1}", s1.f1, 1+906);
105 return 1;
108 float2 s2;
109 s2.f1 = 1;
110 s2.f2 = 2;
111 s2 = mono_return_float2(s2, 906);
112 if (s2.f1 != 1+906) {
113 Console.WriteLine(" float2 s2.f1: got {0} but expected {1}", s2.f1, 1+906);
114 return 1;
116 if (s2.f2 != 2+906) {
117 Console.WriteLine(" float2 s2.f2: got {0} but expected {1}", s2.f2, 2+906);
118 return 2;
121 float3 s3;
122 s3.f1 = 1;
123 s3.f2 = 2;
124 s3.f3 = 3;
125 s3 = mono_return_float3(s3, 906);
126 if (s3.f1 != 1+906) {
127 Console.WriteLine(" float3 s3.f1: got {0} but expected {1}", s3.f1, 1+906);
128 return 1;
130 if (s3.f2 != 2+906) {
131 Console.WriteLine(" float3 s3.f2: got {0} but expected {1}", s3.f2, 2+906);
132 return 2;
134 if (s3.f3 != 3+906) {
135 Console.WriteLine(" float3 s3.f3: got {0} but expected {1}", s3.f3, 3+906);
136 return 3;
139 float4 s4;
140 s4.f1 = 1;
141 s4.f2 = 2;
142 s4.f3 = 3;
143 s4.f4 = 4;
144 s4 = mono_return_float4(s4, 906);
145 if (s4.f1 != 1+906) {
146 Console.WriteLine(" float4 s4.f1: got {0} but expected {1}", s4.f1, 1+906);
147 return 1;
149 if (s4.f2 != 2+906) {
150 Console.WriteLine(" float4 s4.f2: got {0} but expected {1}", s4.f2, 2+906);
151 return 2;
153 if (s4.f3 != 3+906) {
154 Console.WriteLine(" float4 s4.f3: got {0} but expected {1}", s4.f3, 3+906);
155 return 3;
157 if (s4.f4 != 4+906) {
158 Console.WriteLine(" float4 s4.f4: got {0} but expected {1}", s4.f4, 4+906);
159 return 4;
162 float5 s5;
163 s5.f1 = 1;
164 s5.f2 = 2;
165 s5.f3 = 3;
166 s5.f4 = 4;
167 s5.f5 = 5;
168 s5 = mono_return_float5(s5, 906);
169 if (s5.f1 != 1+906) {
170 Console.WriteLine(" float5 s5.f1: got {0} but expected {1}", s5.f1, 1+906);
171 return 1;
173 if (s5.f2 != 2+906) {
174 Console.WriteLine(" float5 s5.f2: got {0} but expected {1}", s5.f2, 2+906);
175 return 2;
177 if (s5.f3 != 3+906) {
178 Console.WriteLine(" float5 s5.f3: got {0} but expected {1}", s5.f3, 3+906);
179 return 3;
181 if (s5.f4 != 4+906) {
182 Console.WriteLine(" float5 s5.f4: got {0} but expected {1}", s5.f4, 4+906);
183 return 4;
185 if (s5.f5 != 5+906) {
186 Console.WriteLine(" float5 s5.f5: got {0} but expected {1}", s5.f5, 5+906);
187 return 5;
190 float6 s6;
191 s6.f1 = 1;
192 s6.f2 = 2;
193 s6.f3 = 3;
194 s6.f4 = 4;
195 s6.f5 = 5;
196 s6.f6 = 6;
197 s6 = mono_return_float6(s6, 906);
198 if (s6.f1 != 1+906) {
199 Console.WriteLine(" float6 s6.f1: got {0} but expected {1}", s6.f1, 1+906);
200 return 1;
202 if (s6.f2 != 2+906) {
203 Console.WriteLine(" float6 s6.f2: got {0} but expected {1}", s6.f2, 2+906);
204 return 2;
206 if (s6.f3 != 3+906) {
207 Console.WriteLine(" float6 s6.f3: got {0} but expected {1}", s6.f3, 3+906);
208 return 3;
210 if (s6.f4 != 4+906) {
211 Console.WriteLine(" float6 s6.f4: got {0} but expected {1}", s6.f4, 4+906);
212 return 4;
214 if (s6.f5 != 5+906) {
215 Console.WriteLine(" float6 s6.f5: got {0} but expected {1}", s6.f5, 5+906);
216 return 5;
218 if (s6.f6 != 6+906) {
219 Console.WriteLine(" float6 s6.f6: got {0} but expected {1}", s6.f6, 6+906);
220 return 6;
223 float7 s7;
224 s7.f1 = 1;
225 s7.f2 = 2;
226 s7.f3 = 3;
227 s7.f4 = 4;
228 s7.f5 = 5;
229 s7.f6 = 6;
230 s7.f7 = 7;
231 s7 = mono_return_float7(s7, 906);
232 if (s7.f1 != 1+906) {
233 Console.WriteLine(" float7 s7.f1: got {0} but expected {1}", s7.f1, 1+906);
234 return 1;
236 if (s7.f2 != 2+906) {
237 Console.WriteLine(" float7 s7.f2: got {0} but expected {1}", s7.f2, 2+906);
238 return 2;
240 if (s7.f3 != 3+906) {
241 Console.WriteLine(" float7 s7.f3: got {0} but expected {1}", s7.f3, 3+906);
242 return 3;
244 if (s7.f4 != 4+906) {
245 Console.WriteLine(" float7 s7.f4: got {0} but expected {1}", s7.f4, 4+906);
246 return 4;
248 if (s7.f5 != 5+906) {
249 Console.WriteLine(" float7 s7.f5: got {0} but expected {1}", s7.f5, 5+906);
250 return 5;
252 if (s7.f6 != 6+906) {
253 Console.WriteLine(" float7 s7.f6: got {0} but expected {1}", s7.f6, 6+906);
254 return 6;
256 if (s7.f7 != 7+906) {
257 Console.WriteLine(" float7 s7.f7: got {0} but expected {1}", s7.f7, 7+906);
258 return 7;
261 float8 s8;
262 s8.f1 = 1;
263 s8.f2 = 2;
264 s8.f3 = 3;
265 s8.f4 = 4;
266 s8.f5 = 5;
267 s8.f6 = 6;
268 s8.f7 = 7;
269 s8.f8 = 8;
270 s8 = mono_return_float8(s8, 906);
271 if (s8.f1 != 1+906) {
272 Console.WriteLine(" float8 s8.f1: got {0} but expected {1}", s8.f1, 1+906);
273 return 1;
275 if (s8.f2 != 2+906) {
276 Console.WriteLine(" float8 s8.f2: got {0} but expected {1}", s8.f2, 2+906);
277 return 2;
279 if (s8.f3 != 3+906) {
280 Console.WriteLine(" float8 s8.f3: got {0} but expected {1}", s8.f3, 3+906);
281 return 3;
283 if (s8.f4 != 4+906) {
284 Console.WriteLine(" float8 s8.f4: got {0} but expected {1}", s8.f4, 4+906);
285 return 4;
287 if (s8.f5 != 5+906) {
288 Console.WriteLine(" float8 s8.f5: got {0} but expected {1}", s8.f5, 5+906);
289 return 5;
291 if (s8.f6 != 6+906) {
292 Console.WriteLine(" float8 s8.f6: got {0} but expected {1}", s8.f6, 6+906);
293 return 6;
295 if (s8.f7 != 7+906) {
296 Console.WriteLine(" float8 s8.f7: got {0} but expected {1}", s8.f7, 7+906);
297 return 7;
299 if (s8.f8 != 8+906) {
300 Console.WriteLine(" float8 s8.f8: got {0} but expected {1}", s8.f8, 8+906);
301 return 8;
304 float9 s9;
305 s9.f1 = 1;
306 s9.f2 = 2;
307 s9.f3 = 3;
308 s9.f4 = 4;
309 s9.f5 = 5;
310 s9.f6 = 6;
311 s9.f7 = 7;
312 s9.f8 = 8;
313 s9.f9 = 9;
314 s9 = mono_return_float9(s9, 906);
315 if (s9.f1 != 1+906) {
316 Console.WriteLine(" float9 s9.f1: got {0} but expected {1}", s9.f1, 1+906);
317 return 1;
319 if (s9.f2 != 2+906) {
320 Console.WriteLine(" float9 s9.f2: got {0} but expected {1}", s9.f2, 2+906);
321 return 2;
323 if (s9.f3 != 3+906) {
324 Console.WriteLine(" float9 s9.f3: got {0} but expected {1}", s9.f3, 3+906);
325 return 3;
327 if (s9.f4 != 4+906) {
328 Console.WriteLine(" float9 s9.f4: got {0} but expected {1}", s9.f4, 4+906);
329 return 4;
331 if (s9.f5 != 5+906) {
332 Console.WriteLine(" float9 s9.f5: got {0} but expected {1}", s9.f5, 5+906);
333 return 5;
335 if (s9.f6 != 6+906) {
336 Console.WriteLine(" float9 s9.f6: got {0} but expected {1}", s9.f6, 6+906);
337 return 6;
339 if (s9.f7 != 7+906) {
340 Console.WriteLine(" float9 s9.f7: got {0} but expected {1}", s9.f7, 7+906);
341 return 7;
343 if (s9.f8 != 8+906) {
344 Console.WriteLine(" float9 s9.f8: got {0} but expected {1}", s9.f8, 8+906);
345 return 8;
347 if (s9.f9 != 9+906) {
348 Console.WriteLine(" float9 s9.f9: got {0} but expected {1}", s9.f9, 9+906);
349 return 9;
353 float4_nested sn4;
354 sn4.nested1.f1 = 1;
355 sn4.f2 = 2;
356 sn4.f3 = 3;
357 sn4.nested2.f4 = 4;
358 sn4 = mono_return_float4_nested(sn4, 906);
359 if (sn4.nested1.f1 != 1+906) {
360 Console.WriteLine(" float4_nested sn4.nested1.f1: got {0} but expected {1}", sn4.nested1.f1, 1+906);
361 return 1;
363 if (sn4.f2 != 2+906) {
364 Console.WriteLine(" float4_nested sn4.f2: got {0} but expected {1}", sn4.f2, 2+906);
365 return 2;
367 if (sn4.f3 != 3+906) {
368 Console.WriteLine(" float4_nested sn4.f3: got {0} but expected {1}", sn4.f3, 3+906);
369 return 3;
371 if (sn4.nested2.f4 != 4+906) {
372 Console.WriteLine(" float4_nested sn4.nested2.f4: got {0} but expected {1}", sn4.nested2.f4, 4+906);
373 return 4;
376 return 0;
377 } // end Main
378 } // end class Test_float