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_inout_array")]
79 public static extern int mono_test_marshal_inout_array ([In, Out] int [] a1);
81 [DllImport ("libtest", EntryPoint="mono_test_marshal_inout_nonblittable_array", CharSet = CharSet.Unicode)]
82 public static extern int mono_test_marshal_inout_nonblittable_array ([In, Out] char [] a1);
84 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct")]
85 public static extern int mono_test_marshal_struct (SimpleStruct ss);
87 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2")]
88 public static extern int mono_test_marshal_struct2 (SimpleStruct2 ss);
90 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2_2")]
91 public static extern int mono_test_marshal_struct2_2 (int i, int j, int k, SimpleStruct2 ss);
93 [DllImport ("libtest", EntryPoint="mono_test_marshal_point")]
94 public static extern int mono_test_marshal_point (Point p);
96 [DllImport ("libtest", EntryPoint="mono_test_marshal_mixed_point")]
97 public static extern int mono_test_marshal_mixed_point (MixedPoint p);
99 [DllImport ("libtest", EntryPoint="mono_test_empty_struct")]
100 public static extern int mono_test_empty_struct (int a, EmptyStruct es, int b);
102 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct_array")]
103 public static extern int mono_test_marshal_struct_array (SimpleStruct2[] ss);
105 [DllImport ("libtest", EntryPoint="mono_test_marshal_class")]
106 public static extern SimpleClass mono_test_marshal_class (int i, int j, int k, SimpleClass ss, int l);
108 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_class")]
109 public static extern int mono_test_marshal_byref_class (ref SimpleClass ss);
111 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate")]
112 public static extern int mono_test_marshal_delegate (SimpleDelegate d);
114 [DllImport ("libtest", EntryPoint="mono_test_return_vtype")]
115 public static extern SimpleStruct mono_test_return_vtype (IntPtr i);
117 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder")]
118 public static extern void mono_test_marshal_stringbuilder (StringBuilder sb, int len);
120 [DllImport ("libtest", EntryPoint="mono_test_last_error", SetLastError=true)]
121 public static extern void mono_test_last_error (int err);
123 public delegate int SimpleDelegate (int a);
125 public static int Main () {
126 return TestDriver.RunTests (typeof (Tests));
129 static int test_0_marshal_char () {
130 return mono_test_marshal_char ('a');
133 static int test_1225_marshal_array () {
134 int [] a1 = new int [50];
135 for (int i = 0; i < 50; i++)
138 return mono_test_marshal_array (a1);
141 static int test_1225_marshal_inout_array () {
142 int [] a1 = new int [50];
143 for (int i = 0; i < 50; i++)
146 int res = mono_test_marshal_inout_array (a1);
148 for (int i = 0; i < 50; i++)
149 if (a1 [i] != 50 - i) {
150 Console.WriteLine ("X: " + i + " " + a1 [i]);
157 static int test_0_marshal_inout_nonblittable_array () {
158 char [] a1 = new char [10];
159 for (int i = 0; i < 10; i++)
160 a1 [i] = "Hello, World" [i];
162 int res = mono_test_marshal_inout_nonblittable_array (a1);
164 for (int i = 0; i < 10; i++)
171 static int test_0_marshal_struct () {
172 SimpleStruct ss = new SimpleStruct ();
176 return mono_test_marshal_struct (ss);
179 static int test_0_marshal_struct2 () {
180 SimpleStruct2 ss2 = new SimpleStruct2 ();
188 return mono_test_marshal_struct2 (ss2);
191 static int test_0_marshal_struct3 () {
192 SimpleStruct2 ss2 = new SimpleStruct2 ();
200 return mono_test_marshal_struct2_2 (10, 11, 12, ss2);
203 static int test_0_marshal_empty_struct () {
204 EmptyStruct es = new EmptyStruct ();
206 if (mono_test_empty_struct (1, es, 2) != 0)
212 static int test_0_marshal_struct_array () {
213 SimpleStruct2[] ss_arr = new SimpleStruct2 [2];
215 SimpleStruct2 ss2 = new SimpleStruct2 ();
234 return mono_test_marshal_struct_array (ss_arr);
237 /* Test classes as arguments and return values */
238 static int test_0_marshal_class () {
239 SimpleClass ss = new SimpleClass ();
247 SimpleClass res = mono_test_marshal_class (10, 11, 12, ss, 14);
250 if (! (res.a == ss.a && res.b == ss.b && res.c == ss.c &&
251 res.d == ss.d && res.e == ss.e && res.f == ss.f &&
252 res.g == ss.g && res.h == ss.h))
255 /* Test null arguments and results */
256 res = mono_test_marshal_class (10, 11, 12, null, 14);
263 static int test_0_marshal_byref_class () {
264 SimpleClass ss = new SimpleClass ();
272 int res = mono_test_marshal_byref_class (ref ss);
273 if (ss.d != "TEST-RES")
279 static int test_0_marshal_delegate () {
280 SimpleDelegate d = new SimpleDelegate (delegate_test);
282 return mono_test_marshal_delegate (d);
285 static int test_0_marshal_point () {
286 Point pt = new Point();
290 return mono_test_marshal_point(pt);
293 static int test_0_marshal_mixed_point () {
294 MixedPoint mpt = new MixedPoint();
298 return mono_test_marshal_mixed_point(mpt);
301 static int test_0_marshal_bool_byref () {
303 if (mono_test_marshal_bool_byref (99, ref b, 100) != 1)
306 if (mono_test_marshal_bool_byref (99, ref b, 100) != 0)
314 static int test_0_return_vtype () {
315 SimpleStruct ss = mono_test_return_vtype (new IntPtr (5));
317 if (!ss.a && ss.b && !ss.c && ss.d == "TEST")
323 static int test_0_marshal_stringbuilder () {
324 StringBuilder sb = new StringBuilder(255);
325 mono_test_marshal_stringbuilder (sb, sb.Capacity);
326 String res = sb.ToString();
328 if (res != "This is my message. Isn't it nice?")
334 static int test_0_last_error () {
335 mono_test_last_error (5);
336 if (Marshal.GetLastWin32Error () == 5)