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 // (C) {Copyright holder}
17 using System.Runtime.InteropServices;
20 public class Test_short {
22 [DllImport ("libtest", EntryPoint="mono_return_short1")]
23 public static extern short 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 short 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 short 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 short 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 short 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 short 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 short 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 short 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 short 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 short retval1 = mono_return_short1(s1, 90);
101 if (retval1 != 2*90) {
102 Console.WriteLine(" short1 retval1: got {0} but expected {1}", retval1, 2*90);
109 short retval2 = mono_return_short2(s2, 90);
110 if (retval2 != 2*90) {
111 Console.WriteLine(" short2 retval2: got {0} but expected {1}", retval2, 2*90);
119 short retval3 = mono_return_short3(s3, 90);
120 if (retval3 != 2*90) {
121 Console.WriteLine(" short3 retval3: got {0} but expected {1}", retval3, 2*90);
130 short retval4 = mono_return_short4(s4, 90);
131 if (retval4 != 2*90) {
132 Console.WriteLine(" short4 retval4: got {0} but expected {1}", retval4, 2*90);
142 short retval5 = mono_return_short5(s5, 90);
143 if (retval5 != 2*90) {
144 Console.WriteLine(" short5 retval5: got {0} but expected {1}", retval5, 2*90);
155 short retval6 = mono_return_short6(s6, 90);
156 if (retval6 != 2*90) {
157 Console.WriteLine(" short6 retval6: got {0} but expected {1}", retval6, 2*90);
169 short retval7 = mono_return_short7(s7, 90);
170 if (retval7 != 2*90) {
171 Console.WriteLine(" short7 retval7: got {0} but expected {1}", retval7, 2*90);
184 short retval8 = mono_return_short8(s8, 90);
185 if (retval8 != 2*90) {
186 Console.WriteLine(" short8 retval8: got {0} but expected {1}", retval8, 2*90);
200 short retval9 = mono_return_short9(s9, 90);
201 if (retval9 != 2*90) {
202 Console.WriteLine(" short9 retval9: got {0} but expected {1}", retval9, 2*90);
209 } // end class Test_short