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 ("libnot-found", EntryPoint="not_found")]
70 public static extern int mono_library_not_found ();
72 [DllImport ("libtest", EntryPoint="not_found")]
73 public static extern int mono_entry_point_not_found ();
75 [DllImport ("libtest.dll", EntryPoint="mono_test_marshal_char")]
76 public static extern int mono_test_marshal_char_2 (char a1);
78 [DllImport ("libtest", EntryPoint="mono_test_marshal_char")]
79 public static extern int mono_test_marshal_char (char a1);
81 [DllImport ("libtest", EntryPoint="mono_test_marshal_bool_byref")]
82 public static extern int mono_test_marshal_bool_byref (int a, ref bool b, int c);
84 [DllImport ("libtest", EntryPoint="mono_test_marshal_array")]
85 public static extern int mono_test_marshal_array (int [] a1);
87 [DllImport ("libtest", EntryPoint="mono_test_marshal_inout_array")]
88 public static extern int mono_test_marshal_inout_array ([In, Out] int [] a1);
90 [DllImport ("libtest", EntryPoint="mono_test_marshal_inout_nonblittable_array", CharSet = CharSet.Unicode)]
91 public static extern int mono_test_marshal_inout_nonblittable_array ([In, Out] char [] a1);
93 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct")]
94 public static extern int mono_test_marshal_struct (SimpleStruct ss);
96 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2")]
97 public static extern int mono_test_marshal_struct2 (SimpleStruct2 ss);
99 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2_2")]
100 public static extern int mono_test_marshal_struct2_2 (int i, int j, int k, SimpleStruct2 ss);
102 [DllImport ("libtest", EntryPoint="mono_test_marshal_point")]
103 public static extern int mono_test_marshal_point (Point p);
105 [DllImport ("libtest", EntryPoint="mono_test_marshal_mixed_point")]
106 public static extern int mono_test_marshal_mixed_point (MixedPoint p);
108 [DllImport ("libtest", EntryPoint="mono_test_empty_struct")]
109 public static extern int mono_test_empty_struct (int a, EmptyStruct es, int b);
111 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct_array")]
112 public static extern int mono_test_marshal_struct_array (SimpleStruct2[] ss);
114 [DllImport ("libtest", EntryPoint="mono_test_marshal_class")]
115 public static extern SimpleClass mono_test_marshal_class (int i, int j, int k, SimpleClass ss, int l);
117 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_class")]
118 public static extern int mono_test_marshal_byref_class (ref SimpleClass ss);
120 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate")]
121 public static extern int mono_test_marshal_delegate (SimpleDelegate d);
123 [DllImport ("libtest", EntryPoint="mono_test_return_vtype")]
124 public static extern SimpleStruct mono_test_return_vtype (IntPtr i);
126 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder")]
127 public static extern void mono_test_marshal_stringbuilder (StringBuilder sb, int len);
129 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_unicode", CharSet=CharSet.Unicode)]
130 public static extern void mono_test_marshal_stringbuilder_unicode (StringBuilder sb, int len);
132 [DllImport ("libtest", EntryPoint="mono_test_last_error", SetLastError=true)]
133 public static extern void mono_test_last_error (int err);
135 public delegate int SimpleDelegate (int a);
137 public static int Main () {
138 return TestDriver.RunTests (typeof (Tests));
141 static int test_0_marshal_char () {
142 return mono_test_marshal_char ('a');
145 static int test_1225_marshal_array () {
146 int [] a1 = new int [50];
147 for (int i = 0; i < 50; i++)
150 return mono_test_marshal_array (a1);
153 static int test_1225_marshal_inout_array () {
154 int [] a1 = new int [50];
155 for (int i = 0; i < 50; i++)
158 int res = mono_test_marshal_inout_array (a1);
160 for (int i = 0; i < 50; i++)
161 if (a1 [i] != 50 - i) {
162 Console.WriteLine ("X: " + i + " " + a1 [i]);
169 static int test_0_marshal_inout_nonblittable_array () {
170 char [] a1 = new char [10];
171 for (int i = 0; i < 10; i++)
172 a1 [i] = "Hello, World" [i];
174 int res = mono_test_marshal_inout_nonblittable_array (a1);
176 for (int i = 0; i < 10; i++)
183 static int test_0_marshal_struct () {
184 SimpleStruct ss = new SimpleStruct ();
188 return mono_test_marshal_struct (ss);
191 static int test_0_marshal_struct2 () {
192 SimpleStruct2 ss2 = new SimpleStruct2 ();
200 return mono_test_marshal_struct2 (ss2);
203 static int test_0_marshal_struct3 () {
204 SimpleStruct2 ss2 = new SimpleStruct2 ();
212 return mono_test_marshal_struct2_2 (10, 11, 12, ss2);
215 static int test_0_marshal_empty_struct () {
216 EmptyStruct es = new EmptyStruct ();
218 if (mono_test_empty_struct (1, es, 2) != 0)
224 static int test_0_marshal_struct_array () {
225 SimpleStruct2[] ss_arr = new SimpleStruct2 [2];
227 SimpleStruct2 ss2 = new SimpleStruct2 ();
246 return mono_test_marshal_struct_array (ss_arr);
249 /* Test classes as arguments and return values */
250 static int test_0_marshal_class () {
251 SimpleClass ss = new SimpleClass ();
259 SimpleClass res = mono_test_marshal_class (10, 11, 12, ss, 14);
262 if (! (res.a == ss.a && res.b == ss.b && res.c == ss.c &&
263 res.d == ss.d && res.e == ss.e && res.f == ss.f &&
264 res.g == ss.g && res.h == ss.h))
267 /* Test null arguments and results */
268 res = mono_test_marshal_class (10, 11, 12, null, 14);
275 static int test_0_marshal_byref_class () {
276 SimpleClass ss = new SimpleClass ();
284 int res = mono_test_marshal_byref_class (ref ss);
285 if (ss.d != "TEST-RES")
291 static int test_0_marshal_delegate () {
292 SimpleDelegate d = new SimpleDelegate (delegate_test);
294 return mono_test_marshal_delegate (d);
297 static int test_0_marshal_point () {
298 Point pt = new Point();
302 return mono_test_marshal_point(pt);
305 static int test_0_marshal_mixed_point () {
306 MixedPoint mpt = new MixedPoint();
310 return mono_test_marshal_mixed_point(mpt);
313 static int test_0_marshal_bool_byref () {
315 if (mono_test_marshal_bool_byref (99, ref b, 100) != 1)
318 if (mono_test_marshal_bool_byref (99, ref b, 100) != 0)
326 static int test_0_return_vtype () {
327 SimpleStruct ss = mono_test_return_vtype (new IntPtr (5));
329 if (!ss.a && ss.b && !ss.c && ss.d == "TEST")
335 static int test_0_marshal_stringbuilder () {
336 StringBuilder sb = new StringBuilder(255);
337 mono_test_marshal_stringbuilder (sb, sb.Capacity);
338 String res = sb.ToString();
340 if (res != "This is my message. Isn't it nice?")
346 static int test_0_marshal_stringbuilder_unicode () {
347 StringBuilder sb = new StringBuilder(255);
348 mono_test_marshal_stringbuilder_unicode (sb, sb.Capacity);
349 String res = sb.ToString();
351 if (res != "This is my message. Isn't it nice?")
357 static int test_0_last_error () {
358 mono_test_last_error (5);
359 if (Marshal.GetLastWin32Error () == 5)
365 static int test_0_library_not_found () {
368 mono_entry_point_not_found ();
371 catch (EntryPointNotFoundException) {
377 static int test_0_entry_point_not_found () {
380 mono_library_not_found ();
383 catch (DllNotFoundException) {
389 /* Check that the runtime trims .dll from the library name */
390 static int test_0_trim_dll_from_name () {
392 mono_test_marshal_char_2 ('A');