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_string_array")]
88 public static extern int mono_test_marshal_string_array (string [] a1);
90 [DllImport ("libtest", EntryPoint="mono_test_marshal_inout_array")]
91 public static extern int mono_test_marshal_inout_array ([In, Out] int [] a1);
93 [DllImport ("libtest", EntryPoint="mono_test_marshal_inout_nonblittable_array", CharSet = CharSet.Unicode)]
94 public static extern int mono_test_marshal_inout_nonblittable_array ([In, Out] char [] a1);
96 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct")]
97 public static extern int mono_test_marshal_struct (SimpleStruct ss);
99 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2")]
100 public static extern int mono_test_marshal_struct2 (SimpleStruct2 ss);
102 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2_2")]
103 public static extern int mono_test_marshal_struct2_2 (int i, int j, int k, SimpleStruct2 ss);
105 [DllImport ("libtest", EntryPoint="mono_test_marshal_point")]
106 public static extern int mono_test_marshal_point (Point p);
108 [DllImport ("libtest", EntryPoint="mono_test_marshal_mixed_point")]
109 public static extern int mono_test_marshal_mixed_point (MixedPoint p);
111 [DllImport ("libtest", EntryPoint="mono_test_empty_struct")]
112 public static extern int mono_test_empty_struct (int a, EmptyStruct es, int b);
114 [DllImport ("libtest", EntryPoint="mono_test_marshal_struct_array")]
115 public static extern int mono_test_marshal_struct_array (SimpleStruct2[] ss);
117 [DllImport ("libtest", EntryPoint="mono_test_marshal_class")]
118 public static extern SimpleClass mono_test_marshal_class (int i, int j, int k, SimpleClass ss, int l);
120 [DllImport ("libtest", EntryPoint="mono_test_marshal_byref_class")]
121 public static extern int mono_test_marshal_byref_class (ref SimpleClass ss);
123 [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate")]
124 public static extern int mono_test_marshal_delegate (SimpleDelegate d);
126 [DllImport ("libtest", EntryPoint="mono_test_return_vtype")]
127 public static extern SimpleStruct mono_test_return_vtype (IntPtr i);
129 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder")]
130 public static extern void mono_test_marshal_stringbuilder (StringBuilder sb, int len);
132 [DllImport ("libtest", EntryPoint="mono_test_marshal_stringbuilder_unicode", CharSet=CharSet.Unicode)]
133 public static extern void mono_test_marshal_stringbuilder_unicode (StringBuilder sb, int len);
135 [DllImport ("libtest", EntryPoint="mono_test_last_error", SetLastError=true)]
136 public static extern void mono_test_last_error (int err);
138 public delegate int SimpleDelegate (int a);
140 public static int Main () {
141 return TestDriver.RunTests (typeof (Tests));
144 static int test_0_marshal_char () {
145 return mono_test_marshal_char ('a');
148 static int test_1225_marshal_array () {
149 int [] a1 = new int [50];
150 for (int i = 0; i < 50; i++)
153 return mono_test_marshal_array (a1);
156 static int test_1225_marshal_inout_array () {
157 int [] a1 = new int [50];
158 for (int i = 0; i < 50; i++)
161 int res = mono_test_marshal_inout_array (a1);
163 for (int i = 0; i < 50; i++)
164 if (a1 [i] != 50 - i) {
165 Console.WriteLine ("X: " + i + " " + a1 [i]);
172 static int test_0_marshal_inout_nonblittable_array () {
173 char [] a1 = new char [10];
174 for (int i = 0; i < 10; i++)
175 a1 [i] = "Hello, World" [i];
177 int res = mono_test_marshal_inout_nonblittable_array (a1);
179 for (int i = 0; i < 10; i++)
186 static int test_0_marshal_struct () {
187 SimpleStruct ss = new SimpleStruct ();
191 return mono_test_marshal_struct (ss);
194 static int test_0_marshal_struct2 () {
195 SimpleStruct2 ss2 = new SimpleStruct2 ();
203 return mono_test_marshal_struct2 (ss2);
206 static int test_0_marshal_struct3 () {
207 SimpleStruct2 ss2 = new SimpleStruct2 ();
215 return mono_test_marshal_struct2_2 (10, 11, 12, ss2);
218 static int test_0_marshal_empty_struct () {
219 EmptyStruct es = new EmptyStruct ();
221 if (mono_test_empty_struct (1, es, 2) != 0)
227 static int test_0_marshal_struct_array () {
228 SimpleStruct2[] ss_arr = new SimpleStruct2 [2];
230 SimpleStruct2 ss2 = new SimpleStruct2 ();
249 return mono_test_marshal_struct_array (ss_arr);
252 /* Test classes as arguments and return values */
253 static int test_0_marshal_class () {
254 SimpleClass ss = new SimpleClass ();
262 SimpleClass res = mono_test_marshal_class (10, 11, 12, ss, 14);
265 if (! (res.a == ss.a && res.b == ss.b && res.c == ss.c &&
266 res.d == ss.d && res.e == ss.e && res.f == ss.f &&
267 res.g == ss.g && res.h == ss.h))
270 /* Test null arguments and results */
271 res = mono_test_marshal_class (10, 11, 12, null, 14);
278 static int test_0_marshal_byref_class () {
279 SimpleClass ss = new SimpleClass ();
287 int res = mono_test_marshal_byref_class (ref ss);
288 if (ss.d != "TEST-RES")
294 static int test_0_marshal_delegate () {
295 SimpleDelegate d = new SimpleDelegate (delegate_test);
297 return mono_test_marshal_delegate (d);
300 static int test_0_marshal_point () {
301 Point pt = new Point();
305 return mono_test_marshal_point(pt);
308 static int test_0_marshal_mixed_point () {
309 MixedPoint mpt = new MixedPoint();
313 return mono_test_marshal_mixed_point(mpt);
316 static int test_0_marshal_bool_byref () {
318 if (mono_test_marshal_bool_byref (99, ref b, 100) != 1)
321 if (mono_test_marshal_bool_byref (99, ref b, 100) != 0)
329 static int test_0_return_vtype () {
330 SimpleStruct ss = mono_test_return_vtype (new IntPtr (5));
332 if (!ss.a && ss.b && !ss.c && ss.d == "TEST")
338 static int test_0_marshal_stringbuilder () {
339 StringBuilder sb = new StringBuilder(255);
340 mono_test_marshal_stringbuilder (sb, sb.Capacity);
341 String res = sb.ToString();
343 if (res != "This is my message. Isn't it nice?")
349 static int test_0_marshal_stringbuilder_unicode () {
350 StringBuilder sb = new StringBuilder(255);
351 mono_test_marshal_stringbuilder_unicode (sb, sb.Capacity);
352 String res = sb.ToString();
354 if (res != "This is my message. Isn't it nice?")
360 static int test_0_marshal_empty_string_array () {
361 mono_test_marshal_string_array (null);
365 static int test_0_last_error () {
366 mono_test_last_error (5);
367 if (Marshal.GetLastWin32Error () == 5)
373 static int test_0_library_not_found () {
376 mono_entry_point_not_found ();
379 catch (EntryPointNotFoundException) {
385 static int test_0_entry_point_not_found () {
388 mono_library_not_found ();
391 catch (DllNotFoundException) {
397 /* Check that the runtime trims .dll from the library name */
398 static int test_0_trim_dll_from_name () {
400 mono_test_marshal_char_2 ('A');