Merge pull request #2014 from BillSeurer/master
[mono.git] / mono / tests / pinvoke_ppcf.cs
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.
10 //
11 // Bill Seurer (seurer@linux.vnet.ibm.com)
12 //
13 // (C) {Copyright holder}
14 //
15
16 using System;
17 using System.Runtime.InteropServices;
18
19
20 public class Test_float {
21
22         [DllImport ("libtest", EntryPoint="mono_return_float1")]
23         public static extern float mono_return_float1 (float1 s, int addend);
24         [StructLayout(LayoutKind.Sequential)]
25         public struct float1 {
26                 public float f1;
27         }
28         [DllImport ("libtest", EntryPoint="mono_return_float2")]
29         public static extern float mono_return_float2 (float2 s, int addend);
30         [StructLayout(LayoutKind.Sequential)]
31         public struct float2 {
32                 public float f1,f2;
33         }
34         [DllImport ("libtest", EntryPoint="mono_return_float3")]
35         public static extern float mono_return_float3 (float3 s, int addend);
36         [StructLayout(LayoutKind.Sequential)]
37         public struct float3 {
38                 public float f1,f2,f3;
39         }
40         [DllImport ("libtest", EntryPoint="mono_return_float4")]
41         public static extern float mono_return_float4 (float4 s, int addend);
42         [StructLayout(LayoutKind.Sequential)]
43         public struct float4 {
44                 public float f1,f2,f3,f4;
45         }
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 float mono_return_float5 (float5 s, int addend);
50         [StructLayout(LayoutKind.Sequential)]
51         public struct float5 {
52                 public float f1,f2,f3,f4,f5;
53         }
54         [DllImport ("libtest", EntryPoint="mono_return_float6")]
55         public static extern float mono_return_float6 (float6 s, int addend);
56         [StructLayout(LayoutKind.Sequential)]
57         public struct float6 {
58                 public float f1,f2,f3,f4,f5,f6;
59         }
60         [DllImport ("libtest", EntryPoint="mono_return_float7")]
61         public static extern float 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;
65         }
66         [DllImport ("libtest", EntryPoint="mono_return_float8")]
67         public static extern float 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;
71         }
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 float 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;
79         }
80
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;
85         };
86         public struct float4_nested2 {
87                 public float f4;
88         };
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;
96         }
97
98         public static int Main (string[] args) {
99
100                 float1 s1;
101                 s1.f1 = 1;
102                 float retval1 = mono_return_float1(s1, 906);
103                 if (retval1 != 2*906) {
104                         Console.WriteLine("   float1 retval1: got {0} but expected {1}", retval1, 2*906);
105                         return 1;
106                 }
107
108                 float2 s2;
109                 s2.f1 = 1;
110                 s2.f2 = 2;
111                 float retval2 = mono_return_float2(s2, 906);
112                 if (retval2 != 2*906) {
113                         Console.WriteLine("   float2 retval2: got {0} but expected {1}", retval2, 2*906);
114                         return 1;
115                 }
116
117                 float3 s3;
118                 s3.f1 = 1;
119                 s3.f2 = 2;
120                 s3.f3 = 3;
121                 float retval3 = mono_return_float3(s3, 906);
122                 if (retval3 != 2*906) {
123                         Console.WriteLine("   float3 retval3: got {0} but expected {1}", retval3, 2*906);
124                         return 1;
125                 }
126
127                 float4 s4;
128                 s4.f1 = 1;
129                 s4.f2 = 2;
130                 s4.f3 = 3;
131                 s4.f4 = 4;
132                 float retval4 = mono_return_float4(s4, 906);
133                 if (retval4 != 2*906) {
134                         Console.WriteLine("   float4 retval4: got {0} but expected {1}", retval4, 2*906);
135                         return 1;
136                 }
137
138                 float5 s5;
139                 s5.f1 = 1;
140                 s5.f2 = 2;
141                 s5.f3 = 3;
142                 s5.f4 = 4;
143                 s5.f5 = 5;
144                 float retval5 = mono_return_float5(s5, 906);
145                 if (retval5 != 2*906) {
146                         Console.WriteLine("   float5 retval5: got {0} but expected {1}", retval5, 2*906);
147                         return 1;
148                 }
149
150                 float6 s6;
151                 s6.f1 = 1;
152                 s6.f2 = 2;
153                 s6.f3 = 3;
154                 s6.f4 = 4;
155                 s6.f5 = 5;
156                 s6.f6 = 6;
157                 float retval6 = mono_return_float6(s6, 906);
158                 if (retval6 != 2*906) {
159                         Console.WriteLine("   float6 retval6: got {0} but expected {1}", retval6, 2*906);
160                         return 1;
161                 }
162
163                 float7 s7;
164                 s7.f1 = 1;
165                 s7.f2 = 2;
166                 s7.f3 = 3;
167                 s7.f4 = 4;
168                 s7.f5 = 5;
169                 s7.f6 = 6;
170                 s7.f7 = 7;
171                 float retval7 = mono_return_float7(s7, 906);
172                 if (retval7 != 2*906) {
173                         Console.WriteLine("   float7 retval7: got {0} but expected {1}", retval7, 2*906);
174                         return 1;
175                 }
176
177                 float8 s8;
178                 s8.f1 = 1;
179                 s8.f2 = 2;
180                 s8.f3 = 3;
181                 s8.f4 = 4;
182                 s8.f5 = 5;
183                 s8.f6 = 6;
184                 s8.f7 = 7;
185                 s8.f8 = 8;
186                 float retval8 = mono_return_float8(s8, 906);
187                 if (retval8 != 2*906) {
188                         Console.WriteLine("   float8 retval8: got {0} but expected {1}", retval8, 2*906);
189                         return 1;
190                 }
191
192                 float9 s9;
193                 s9.f1 = 1;
194                 s9.f2 = 2;
195                 s9.f3 = 3;
196                 s9.f4 = 4;
197                 s9.f5 = 5;
198                 s9.f6 = 6;
199                 s9.f7 = 7;
200                 s9.f8 = 8;
201                 s9.f9 = 9;
202                 float retval9 = mono_return_float9(s9, 906);
203                 if (retval9 != 2*906) {
204                         Console.WriteLine("   float9 retval9: got {0} but expected {1}", retval9, 2*906);
205                         return 1;
206                 }
207
208
209                 return 0;
210         } // end Main
211 } // end class Test_float
212
213
214
215
216