3 using System.Runtime.InteropServices;
7 public static int delegate_test (int a)
15 [StructLayout (LayoutKind.Sequential)]
16 public struct SimpleStruct {
23 [StructLayout (LayoutKind.Sequential)]
24 public struct SimpleStruct2 {
35 [StructLayout (LayoutKind.Sequential, Size=0)]
36 public struct EmptyStruct {
39 /* sparcv9 has complex conventions when passing structs with doubles in them
40 by value, some simple tests for them */
41 [StructLayout (LayoutKind.Sequential)]
47 [StructLayout (LayoutKind.Sequential)]
48 public struct MixedPoint {
53 [StructLayout (LayoutKind.Sequential)]
54 public class SimpleClass {
65 [StructLayout (LayoutKind.Sequential)]
66 public class EmptyClass {
69 [DllImport ("libtest", EntryPoint="mono_test_marshal_char")]
70 public static extern int mono_test_marshal_char (char a1);
72 [DllImport ("libtest", EntryPoint="mono_test_marshal_bool_byref")]
73 public static extern int mono_test_marshal_bool_byref (int a, ref bool b, int c);
75 [DllImport ("libtest", EntryPoint="mono_test_marshal_array")]
76 public static extern int mono_test_marshal_array (int [] a1);
78 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct")]
79 public static extern int mono_test_marshal_struct (SimpleStruct ss);
81 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2")]
82 public static extern int mono_test_marshal_struct2 (SimpleStruct2 ss);
84 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2_2")]
85 public static extern int mono_test_marshal_struct2_2 (int i, int j, int k, SimpleStruct2 ss);
87 [DllImport ("libtest", EntryPoint="mono_test_marshal_point")]
88 public static extern int mono_test_marshal_point (Point p);
90 [DllImport ("libtest", EntryPoint="mono_test_marshal_mixed_point")]
91 public static extern int mono_test_marshal_mixed_point (MixedPoint p);
93 [DllImport ("libtest", EntryPoint="mono_test_empty_struct")]
94 public static extern int mono_test_empty_struct (int a, EmptyStruct es, int b);
96 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct_array")]
97 public static extern int mono_test_marshal_struct_array (SimpleStruct2[] ss);
99 [DllImport ("libtest", EntryPoint="mono_test_marshal_class")]
100 public static extern SimpleClass mono_test_marshal_class (int i, int j, int k, SimpleClass ss, int l);
102 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_class")]
103 public static extern int mono_test_marshal_byref_class (ref SimpleClass ss);
105 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate")]
106 public static extern int mono_test_marshal_delegate (SimpleDelegate d);
108 [DllImport ("libtest", EntryPoint="mono_test_return_vtype")]
109 public static extern SimpleStruct mono_test_return_vtype (IntPtr i);
111 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder")]
112 public static extern void mono_test_marshal_stringbuilder (StringBuilder sb, int len);
114 public delegate int SimpleDelegate (int a);
116 public static int Main () {
117 return TestDriver.RunTests (typeof (Tests));
120 static int test_0_marshal_char () {
121 return mono_test_marshal_char ('a');
124 static int test_1225_marshal_array () {
125 int [] a1 = new int [50];
126 for (int i = 0; i < 50; i++)
129 return mono_test_marshal_array (a1);
132 static int test_0_marshal_struct () {
133 SimpleStruct ss = new SimpleStruct ();
137 return mono_test_marshal_struct (ss);
140 static int test_0_marshal_struct2 () {
141 SimpleStruct2 ss2 = new SimpleStruct2 ();
149 return mono_test_marshal_struct2 (ss2);
152 static int test_0_marshal_struct3 () {
153 SimpleStruct2 ss2 = new SimpleStruct2 ();
161 return mono_test_marshal_struct2_2 (10, 11, 12, ss2);
164 static int test_0_marshal_empty_struct () {
165 EmptyStruct es = new EmptyStruct ();
167 if (mono_test_empty_struct (1, es, 2) != 0)
173 static int test_0_marshal_struct_array () {
174 SimpleStruct2[] ss_arr = new SimpleStruct2 [2];
176 SimpleStruct2 ss2 = new SimpleStruct2 ();
195 return mono_test_marshal_struct_array (ss_arr);
198 /* Test classes as arguments and return values */
199 static int test_0_marshal_class () {
200 SimpleClass ss = new SimpleClass ();
208 SimpleClass res = mono_test_marshal_class (10, 11, 12, ss, 14);
211 if (! (res.a == ss.a && res.b == ss.b && res.c == ss.c &&
212 res.d == ss.d && res.e == ss.e && res.f == ss.f &&
213 res.g == ss.g && res.h == ss.h))
216 /* Test null arguments and results */
217 res = mono_test_marshal_class (10, 11, 12, null, 14);
224 static int test_0_marshal_byref_class () {
225 SimpleClass ss = new SimpleClass ();
233 int res = mono_test_marshal_byref_class (ref ss);
234 if (ss.d != "TEST-RES")
240 static int test_0_marshal_delegate () {
241 SimpleDelegate d = new SimpleDelegate (delegate_test);
243 return mono_test_marshal_delegate (d);
246 static int test_0_marshal_point () {
247 Point pt = new Point();
251 return mono_test_marshal_point(pt);
254 static int test_0_marshal_mixed_point () {
255 MixedPoint mpt = new MixedPoint();
259 return mono_test_marshal_mixed_point(mpt);
262 static int test_0_marshal_bool_byref () {
264 if (mono_test_marshal_bool_byref (99, ref b, 100) != 1)
267 if (mono_test_marshal_bool_byref (99, ref b, 100) != 0)
275 static int test_0_return_vtype () {
276 SimpleStruct ss = mono_test_return_vtype (new IntPtr (5));
278 if (!ss.a && ss.b && !ss.c && ss.d == "TEST")
284 static int test_0_marshal_stringbuilder () {
285 StringBuilder sb = new StringBuilder(255);
286 mono_test_marshal_stringbuilder (sb, sb.Capacity);
287 String res = sb.ToString();
289 if (res != "This is my message. Isn't it nice?")