1 // pinvoke_ppcs.cs - Test cases for passing structures to and and returning
2 // structures from functions. This particular test is for
3 // structures consisting wholy of 2 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_short
{
22 [DllImport ("libtest", EntryPoint
="mono_return_short1")]
23 public static extern short1
mono_return_short1 (short1 s
, int addend
);
24 [StructLayout(LayoutKind
.Sequential
)]
25 public struct short1
{
28 [DllImport ("libtest", EntryPoint
="mono_return_short2")]
29 public static extern short2
mono_return_short2 (short2 s
, int addend
);
30 [StructLayout(LayoutKind
.Sequential
)]
31 public struct short2
{
34 [DllImport ("libtest", EntryPoint
="mono_return_short3")]
35 public static extern short3
mono_return_short3 (short3 s
, int addend
);
36 [StructLayout(LayoutKind
.Sequential
)]
37 public struct short3
{
38 public short f1
,f2
,f3
;
40 [DllImport ("libtest", EntryPoint
="mono_return_short4")]
41 public static extern short4
mono_return_short4 (short4 s
, int addend
);
42 [StructLayout(LayoutKind
.Sequential
)]
43 public struct short4
{
44 public short f1
,f2
,f3
,f4
;
46 [DllImport ("libtest", EntryPoint
="mono_return_short5")]
47 public static extern short5
mono_return_short5 (short5 s
, int addend
);
48 [StructLayout(LayoutKind
.Sequential
)]
49 public struct short5
{
50 public short f1
,f2
,f3
,f4
,f5
;
52 [DllImport ("libtest", EntryPoint
="mono_return_short6")]
53 public static extern short6
mono_return_short6 (short6 s
, int addend
);
54 [StructLayout(LayoutKind
.Sequential
)]
55 public struct short6
{
56 public short f1
,f2
,f3
,f4
,f5
,f6
;
58 [DllImport ("libtest", EntryPoint
="mono_return_short7")]
59 public static extern short7
mono_return_short7 (short7 s
, int addend
);
60 [StructLayout(LayoutKind
.Sequential
)]
61 public struct short7
{
62 public short f1
,f2
,f3
,f4
,f5
,f6
,f7
;
64 [DllImport ("libtest", EntryPoint
="mono_return_short8")]
65 public static extern short8
mono_return_short8 (short8 s
, int addend
);
66 [StructLayout(LayoutKind
.Sequential
)]
67 public struct short8
{
68 public short f1
,f2
,f3
,f4
,f5
,f6
,f7
,f8
;
70 // This structure is 1 element too large to use the special return
72 [DllImport ("libtest", EntryPoint
="mono_return_short9")]
73 public static extern short9
mono_return_short9 (short9 s
, int addend
);
74 [StructLayout(LayoutKind
.Sequential
)]
75 public struct short9
{
76 public short f1
,f2
,f3
,f4
,f5
,f6
,f7
,f8
,f9
;
79 // This structure has nested structures within it but they are
80 // homogenous and thus should still use the special rules.
81 public struct short8_nested1
{
84 public struct short8_nested2
{
87 [DllImport ("libtest", EntryPoint
="mono_return_short8_nested")]
88 public static extern short8_nested
mono_return_short8_nested (short8_nested s
, int addend
);
89 [StructLayout(LayoutKind
.Sequential
)]
90 public struct short8_nested
{
91 public short8_nested1 nested1
;
92 public short f2
,f3
,f4
,f5
,f6
,f7
;
93 public short8_nested2 nested2
;
96 public static int Main (string[] args
) {
100 s1
= mono_return_short1(s1
, 90);
102 Console
.WriteLine(" short1 s1.f1: got {0} but expected {1}", s1
.f1
, 1+90);
109 s2
= mono_return_short2(s2
, 90);
111 Console
.WriteLine(" short2 s2.f1: got {0} but expected {1}", s2
.f1
, 1+90);
115 Console
.WriteLine(" short2 s2.f2: got {0} but expected {1}", s2
.f2
, 2+90);
123 s3
= mono_return_short3(s3
, 90);
125 Console
.WriteLine(" short3 s3.f1: got {0} but expected {1}", s3
.f1
, 1+90);
129 Console
.WriteLine(" short3 s3.f2: got {0} but expected {1}", s3
.f2
, 2+90);
133 Console
.WriteLine(" short3 s3.f3: got {0} but expected {1}", s3
.f3
, 3+90);
142 s4
= mono_return_short4(s4
, 90);
144 Console
.WriteLine(" short4 s4.f1: got {0} but expected {1}", s4
.f1
, 1+90);
148 Console
.WriteLine(" short4 s4.f2: got {0} but expected {1}", s4
.f2
, 2+90);
152 Console
.WriteLine(" short4 s4.f3: got {0} but expected {1}", s4
.f3
, 3+90);
156 Console
.WriteLine(" short4 s4.f4: got {0} but expected {1}", s4
.f4
, 4+90);
166 s5
= mono_return_short5(s5
, 90);
168 Console
.WriteLine(" short5 s5.f1: got {0} but expected {1}", s5
.f1
, 1+90);
172 Console
.WriteLine(" short5 s5.f2: got {0} but expected {1}", s5
.f2
, 2+90);
176 Console
.WriteLine(" short5 s5.f3: got {0} but expected {1}", s5
.f3
, 3+90);
180 Console
.WriteLine(" short5 s5.f4: got {0} but expected {1}", s5
.f4
, 4+90);
184 Console
.WriteLine(" short5 s5.f5: got {0} but expected {1}", s5
.f5
, 5+90);
195 s6
= mono_return_short6(s6
, 90);
197 Console
.WriteLine(" short6 s6.f1: got {0} but expected {1}", s6
.f1
, 1+90);
201 Console
.WriteLine(" short6 s6.f2: got {0} but expected {1}", s6
.f2
, 2+90);
205 Console
.WriteLine(" short6 s6.f3: got {0} but expected {1}", s6
.f3
, 3+90);
209 Console
.WriteLine(" short6 s6.f4: got {0} but expected {1}", s6
.f4
, 4+90);
213 Console
.WriteLine(" short6 s6.f5: got {0} but expected {1}", s6
.f5
, 5+90);
217 Console
.WriteLine(" short6 s6.f6: got {0} but expected {1}", s6
.f6
, 6+90);
229 s7
= mono_return_short7(s7
, 90);
231 Console
.WriteLine(" short7 s7.f1: got {0} but expected {1}", s7
.f1
, 1+90);
235 Console
.WriteLine(" short7 s7.f2: got {0} but expected {1}", s7
.f2
, 2+90);
239 Console
.WriteLine(" short7 s7.f3: got {0} but expected {1}", s7
.f3
, 3+90);
243 Console
.WriteLine(" short7 s7.f4: got {0} but expected {1}", s7
.f4
, 4+90);
247 Console
.WriteLine(" short7 s7.f5: got {0} but expected {1}", s7
.f5
, 5+90);
251 Console
.WriteLine(" short7 s7.f6: got {0} but expected {1}", s7
.f6
, 6+90);
255 Console
.WriteLine(" short7 s7.f7: got {0} but expected {1}", s7
.f7
, 7+90);
268 s8
= mono_return_short8(s8
, 90);
270 Console
.WriteLine(" short8 s8.f1: got {0} but expected {1}", s8
.f1
, 1+90);
274 Console
.WriteLine(" short8 s8.f2: got {0} but expected {1}", s8
.f2
, 2+90);
278 Console
.WriteLine(" short8 s8.f3: got {0} but expected {1}", s8
.f3
, 3+90);
282 Console
.WriteLine(" short8 s8.f4: got {0} but expected {1}", s8
.f4
, 4+90);
286 Console
.WriteLine(" short8 s8.f5: got {0} but expected {1}", s8
.f5
, 5+90);
290 Console
.WriteLine(" short8 s8.f6: got {0} but expected {1}", s8
.f6
, 6+90);
294 Console
.WriteLine(" short8 s8.f7: got {0} but expected {1}", s8
.f7
, 7+90);
298 Console
.WriteLine(" short8 s8.f8: got {0} but expected {1}", s8
.f8
, 8+90);
312 s9
= mono_return_short9(s9
, 90);
314 Console
.WriteLine(" short9 s9.f1: got {0} but expected {1}", s9
.f1
, 1+90);
318 Console
.WriteLine(" short9 s9.f2: got {0} but expected {1}", s9
.f2
, 2+90);
322 Console
.WriteLine(" short9 s9.f3: got {0} but expected {1}", s9
.f3
, 3+90);
326 Console
.WriteLine(" short9 s9.f4: got {0} but expected {1}", s9
.f4
, 4+90);
330 Console
.WriteLine(" short9 s9.f5: got {0} but expected {1}", s9
.f5
, 5+90);
334 Console
.WriteLine(" short9 s9.f6: got {0} but expected {1}", s9
.f6
, 6+90);
338 Console
.WriteLine(" short9 s9.f7: got {0} but expected {1}", s9
.f7
, 7+90);
342 Console
.WriteLine(" short9 s9.f8: got {0} but expected {1}", s9
.f8
, 8+90);
346 Console
.WriteLine(" short9 s9.f9: got {0} but expected {1}", s9
.f9
, 9+90);
360 sn8
= mono_return_short8_nested(sn8
, 90);
361 if (sn8
.nested1
.f1
!= 1+90) {
362 Console
.WriteLine(" short8_nested sn8.nested1.f1: got {0} but expected {1}", sn8
.nested1
.f1
, 1+90);
365 if (sn8
.f2
!= 2+90) {
366 Console
.WriteLine(" short8_nested sn8.f2: got {0} but expected {1}", sn8
.f2
, 2+90);
369 if (sn8
.f3
!= 3+90) {
370 Console
.WriteLine(" short8_nested sn8.f3: got {0} but expected {1}", sn8
.f3
, 3+90);
373 if (sn8
.f4
!= 4+90) {
374 Console
.WriteLine(" short8_nested sn8.f4: got {0} but expected {1}", sn8
.f4
, 4+90);
377 if (sn8
.f5
!= 5+90) {
378 Console
.WriteLine(" short8_nested sn8.f5: got {0} but expected {1}", sn8
.f5
, 5+90);
381 if (sn8
.f6
!= 6+90) {
382 Console
.WriteLine(" short8_nested sn8.f6: got {0} but expected {1}", sn8
.f6
, 6+90);
385 if (sn8
.f7
!= 7+90) {
386 Console
.WriteLine(" short8_nested sn8.f7: got {0} but expected {1}", sn8
.f7
, 7+90);
389 if (sn8
.nested2
.f8
!= 8+90) {
390 Console
.WriteLine(" short8_nested sn8.nested2.f8: got {0} but expected {1}", sn8
.nested2
.f8
, 8+90);
396 } // end class Test_short