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 // (C) {Copyright holder}
17 using System.Runtime.InteropServices;
20 public class Test_int {
22 [DllImport ("libtest", EntryPoint="mono_return_int1")]
23 public static extern int mono_return_int1 (int1 s, int addend);
24 [StructLayout(LayoutKind.Sequential)]
28 [DllImport ("libtest", EntryPoint="mono_return_int2")]
29 public static extern int mono_return_int2 (int2 s, int addend);
30 [StructLayout(LayoutKind.Sequential)]
34 [DllImport ("libtest", EntryPoint="mono_return_int3")]
35 public static extern int mono_return_int3 (int3 s, int addend);
36 [StructLayout(LayoutKind.Sequential)]
40 [DllImport ("libtest", EntryPoint="mono_return_int4")]
41 public static extern int 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 int 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 int retval1 = mono_return_int1(s1, 906);
77 if (retval1 != 2*906) {
78 Console.WriteLine(" int1 retval1: got {0} but expected {1}", retval1, 2*906);
85 int retval2 = mono_return_int2(s2, 906);
86 if (retval2 != 2*906) {
87 Console.WriteLine(" int2 retval2: got {0} but expected {1}", retval2, 2*906);
95 int retval3 = mono_return_int3(s3, 906);
96 if (retval3 != 2*906) {
97 Console.WriteLine(" int3 retval3: got {0} but expected {1}", retval3, 2*906);
106 int retval4 = mono_return_int4(s4, 906);
107 if (retval4 != 2*906) {
108 Console.WriteLine(" int4 retval4: got {0} but expected {1}", retval4, 2*906);
118 int retval5 = mono_return_int5(s5, 906);
119 if (retval5 != 2*906) {
120 Console.WriteLine(" int5 retval5: got {0} but expected {1}", retval5, 2*906);
127 } // end class Test_int