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.
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.
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
{
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
{
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
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
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
{
86 public struct float4_nested2
{
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
;
95 public float4_nested2 nested2
;
98 public static int Main (string[] args
) {
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);
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);
116 if (s2
.f2
!= 2+906) {
117 Console
.WriteLine(" float2 s2.f2: got {0} but expected {1}", s2
.f2
, 2+906);
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);
130 if (s3
.f2
!= 2+906) {
131 Console
.WriteLine(" float3 s3.f2: got {0} but expected {1}", s3
.f2
, 2+906);
134 if (s3
.f3
!= 3+906) {
135 Console
.WriteLine(" float3 s3.f3: got {0} but expected {1}", s3
.f3
, 3+906);
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);
149 if (s4
.f2
!= 2+906) {
150 Console
.WriteLine(" float4 s4.f2: got {0} but expected {1}", s4
.f2
, 2+906);
153 if (s4
.f3
!= 3+906) {
154 Console
.WriteLine(" float4 s4.f3: got {0} but expected {1}", s4
.f3
, 3+906);
157 if (s4
.f4
!= 4+906) {
158 Console
.WriteLine(" float4 s4.f4: got {0} but expected {1}", s4
.f4
, 4+906);
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);
173 if (s5
.f2
!= 2+906) {
174 Console
.WriteLine(" float5 s5.f2: got {0} but expected {1}", s5
.f2
, 2+906);
177 if (s5
.f3
!= 3+906) {
178 Console
.WriteLine(" float5 s5.f3: got {0} but expected {1}", s5
.f3
, 3+906);
181 if (s5
.f4
!= 4+906) {
182 Console
.WriteLine(" float5 s5.f4: got {0} but expected {1}", s5
.f4
, 4+906);
185 if (s5
.f5
!= 5+906) {
186 Console
.WriteLine(" float5 s5.f5: got {0} but expected {1}", s5
.f5
, 5+906);
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);
202 if (s6
.f2
!= 2+906) {
203 Console
.WriteLine(" float6 s6.f2: got {0} but expected {1}", s6
.f2
, 2+906);
206 if (s6
.f3
!= 3+906) {
207 Console
.WriteLine(" float6 s6.f3: got {0} but expected {1}", s6
.f3
, 3+906);
210 if (s6
.f4
!= 4+906) {
211 Console
.WriteLine(" float6 s6.f4: got {0} but expected {1}", s6
.f4
, 4+906);
214 if (s6
.f5
!= 5+906) {
215 Console
.WriteLine(" float6 s6.f5: got {0} but expected {1}", s6
.f5
, 5+906);
218 if (s6
.f6
!= 6+906) {
219 Console
.WriteLine(" float6 s6.f6: got {0} but expected {1}", s6
.f6
, 6+906);
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);
236 if (s7
.f2
!= 2+906) {
237 Console
.WriteLine(" float7 s7.f2: got {0} but expected {1}", s7
.f2
, 2+906);
240 if (s7
.f3
!= 3+906) {
241 Console
.WriteLine(" float7 s7.f3: got {0} but expected {1}", s7
.f3
, 3+906);
244 if (s7
.f4
!= 4+906) {
245 Console
.WriteLine(" float7 s7.f4: got {0} but expected {1}", s7
.f4
, 4+906);
248 if (s7
.f5
!= 5+906) {
249 Console
.WriteLine(" float7 s7.f5: got {0} but expected {1}", s7
.f5
, 5+906);
252 if (s7
.f6
!= 6+906) {
253 Console
.WriteLine(" float7 s7.f6: got {0} but expected {1}", s7
.f6
, 6+906);
256 if (s7
.f7
!= 7+906) {
257 Console
.WriteLine(" float7 s7.f7: got {0} but expected {1}", s7
.f7
, 7+906);
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);
275 if (s8
.f2
!= 2+906) {
276 Console
.WriteLine(" float8 s8.f2: got {0} but expected {1}", s8
.f2
, 2+906);
279 if (s8
.f3
!= 3+906) {
280 Console
.WriteLine(" float8 s8.f3: got {0} but expected {1}", s8
.f3
, 3+906);
283 if (s8
.f4
!= 4+906) {
284 Console
.WriteLine(" float8 s8.f4: got {0} but expected {1}", s8
.f4
, 4+906);
287 if (s8
.f5
!= 5+906) {
288 Console
.WriteLine(" float8 s8.f5: got {0} but expected {1}", s8
.f5
, 5+906);
291 if (s8
.f6
!= 6+906) {
292 Console
.WriteLine(" float8 s8.f6: got {0} but expected {1}", s8
.f6
, 6+906);
295 if (s8
.f7
!= 7+906) {
296 Console
.WriteLine(" float8 s8.f7: got {0} but expected {1}", s8
.f7
, 7+906);
299 if (s8
.f8
!= 8+906) {
300 Console
.WriteLine(" float8 s8.f8: got {0} but expected {1}", s8
.f8
, 8+906);
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);
319 if (s9
.f2
!= 2+906) {
320 Console
.WriteLine(" float9 s9.f2: got {0} but expected {1}", s9
.f2
, 2+906);
323 if (s9
.f3
!= 3+906) {
324 Console
.WriteLine(" float9 s9.f3: got {0} but expected {1}", s9
.f3
, 3+906);
327 if (s9
.f4
!= 4+906) {
328 Console
.WriteLine(" float9 s9.f4: got {0} but expected {1}", s9
.f4
, 4+906);
331 if (s9
.f5
!= 5+906) {
332 Console
.WriteLine(" float9 s9.f5: got {0} but expected {1}", s9
.f5
, 5+906);
335 if (s9
.f6
!= 6+906) {
336 Console
.WriteLine(" float9 s9.f6: got {0} but expected {1}", s9
.f6
, 6+906);
339 if (s9
.f7
!= 7+906) {
340 Console
.WriteLine(" float9 s9.f7: got {0} but expected {1}", s9
.f7
, 7+906);
343 if (s9
.f8
!= 8+906) {
344 Console
.WriteLine(" float9 s9.f8: got {0} but expected {1}", s9
.f8
, 8+906);
347 if (s9
.f9
!= 9+906) {
348 Console
.WriteLine(" float9 s9.f9: got {0} but expected {1}", s9
.f9
, 9+906);
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);
363 if (sn4
.f2
!= 2+906) {
364 Console
.WriteLine(" float4_nested sn4.f2: got {0} but expected {1}", sn4
.f2
, 2+906);
367 if (sn4
.f3
!= 3+906) {
368 Console
.WriteLine(" float4_nested sn4.f3: got {0} but expected {1}", sn4
.f3
, 3+906);
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);
378 } // end class Test_float