1 // pinvoke_ppci.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_int
{
22 [DllImport ("libtest", EntryPoint
="mono_return_int1")]
23 public static extern int1
mono_return_int1 (int1 s
, int addend
);
24 [StructLayout(LayoutKind
.Sequential
)]
28 [DllImport ("libtest", EntryPoint
="mono_return_int2")]
29 public static extern int2
mono_return_int2 (int2 s
, int addend
);
30 [StructLayout(LayoutKind
.Sequential
)]
34 [DllImport ("libtest", EntryPoint
="mono_return_int3")]
35 public static extern int3
mono_return_int3 (int3 s
, int addend
);
36 [StructLayout(LayoutKind
.Sequential
)]
40 [DllImport ("libtest", EntryPoint
="mono_return_int4")]
41 public static extern int4
mono_return_int4 (int4 s
, int addend
);
42 [StructLayout(LayoutKind
.Sequential
)]
44 public int f1
,f2
,f3
,f4
;
46 // This structure is 1 element too large to use the special return
48 [DllImport ("libtest", EntryPoint
="mono_return_int5")]
49 public static extern int5
mono_return_int5 (int5 s
, int addend
);
50 [StructLayout(LayoutKind
.Sequential
)]
52 public int f1
,f2
,f3
,f4
,f5
;
55 // This structure has nested structures within it but they are
56 // homogenous and thus should still use the special rules.
57 public struct int4_nested1
{
60 public struct int4_nested2
{
63 [DllImport ("libtest", EntryPoint
="mono_return_int4_nested")]
64 public static extern int4_nested
mono_return_int4_nested (int4_nested s
, int addend
);
65 [StructLayout(LayoutKind
.Sequential
)]
66 public struct int4_nested
{
67 public int4_nested1 nested1
;
69 public int4_nested2 nested2
;
72 public static int Main (string[] args
) {
76 s1
= mono_return_int1(s1
, 906);
78 Console
.WriteLine(" int1 s1.f1: got {0} but expected {1}", s1
.f1
, 1+906);
85 s2
= mono_return_int2(s2
, 906);
87 Console
.WriteLine(" int2 s2.f1: got {0} but expected {1}", s2
.f1
, 1+906);
91 Console
.WriteLine(" int2 s2.f2: got {0} but expected {1}", s2
.f2
, 2+906);
99 s3
= mono_return_int3(s3
, 906);
100 if (s3
.f1
!= 1+906) {
101 Console
.WriteLine(" int3 s3.f1: got {0} but expected {1}", s3
.f1
, 1+906);
104 if (s3
.f2
!= 2+906) {
105 Console
.WriteLine(" int3 s3.f2: got {0} but expected {1}", s3
.f2
, 2+906);
108 if (s3
.f3
!= 3+906) {
109 Console
.WriteLine(" int3 s3.f3: got {0} but expected {1}", s3
.f3
, 3+906);
118 s4
= mono_return_int4(s4
, 906);
119 if (s4
.f1
!= 1+906) {
120 Console
.WriteLine(" int4 s4.f1: got {0} but expected {1}", s4
.f1
, 1+906);
123 if (s4
.f2
!= 2+906) {
124 Console
.WriteLine(" int4 s4.f2: got {0} but expected {1}", s4
.f2
, 2+906);
127 if (s4
.f3
!= 3+906) {
128 Console
.WriteLine(" int4 s4.f3: got {0} but expected {1}", s4
.f3
, 3+906);
131 if (s4
.f4
!= 4+906) {
132 Console
.WriteLine(" int4 s4.f4: got {0} but expected {1}", s4
.f4
, 4+906);
142 s5
= mono_return_int5(s5
, 906);
143 if (s5
.f1
!= 1+906) {
144 Console
.WriteLine(" int5 s5.f1: got {0} but expected {1}", s5
.f1
, 1+906);
147 if (s5
.f2
!= 2+906) {
148 Console
.WriteLine(" int5 s5.f2: got {0} but expected {1}", s5
.f2
, 2+906);
151 if (s5
.f3
!= 3+906) {
152 Console
.WriteLine(" int5 s5.f3: got {0} but expected {1}", s5
.f3
, 3+906);
155 if (s5
.f4
!= 4+906) {
156 Console
.WriteLine(" int5 s5.f4: got {0} but expected {1}", s5
.f4
, 4+906);
159 if (s5
.f5
!= 5+906) {
160 Console
.WriteLine(" int5 s5.f5: got {0} but expected {1}", s5
.f5
, 5+906);
170 sn4
= mono_return_int4_nested(sn4
, 906);
171 if (sn4
.nested1
.f1
!= 1+906) {
172 Console
.WriteLine(" int4_nested sn4.nested1.f1: got {0} but expected {1}", sn4
.nested1
.f1
, 1+906);
175 if (sn4
.f2
!= 2+906) {
176 Console
.WriteLine(" int4_nested sn4.f2: got {0} but expected {1}", sn4
.f2
, 2+906);
179 if (sn4
.f3
!= 3+906) {
180 Console
.WriteLine(" int4_nested sn4.f3: got {0} but expected {1}", sn4
.f3
, 3+906);
183 if (sn4
.nested2
.f4
!= 4+906) {
184 Console
.WriteLine(" int4_nested sn4.nested2.f4: got {0} but expected {1}", sn4
.nested2
.f4
, 4+906);
190 } // end class Test_int