2010-06-21 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / tests / winx64structs.cs
blob527c29be754e5e0820e6c70bb76ab465e0eed486
1 using System;
2 using System.Runtime.InteropServices;
4 [StructLayout (LayoutKind.Sequential)]
5 struct winx64_struct1
7 public winx64_struct1 (byte ia)
9 a = ia;
11 public byte a;
14 [StructLayout (LayoutKind.Sequential)]
15 struct winx64_struct2
17 public winx64_struct2 (byte ia, byte ib)
19 a = ia;
20 b = ib;
23 public byte a;
24 public byte b;
27 [StructLayout (LayoutKind.Sequential)]
28 struct winx64_struct3
30 public winx64_struct3 (byte ia, byte ib, short ic)
32 a = ia;
33 b = ib;
34 c = ic;
37 public byte a;
38 public byte b;
39 public short c;
42 [StructLayout (LayoutKind.Sequential)]
43 struct winx64_struct4
45 public winx64_struct4 (byte ia, byte ib, short ic, uint id)
47 a = ia;
48 b = ib;
49 c = ic;
50 d = id;
53 public byte a;
54 public byte b;
55 public short c;
56 public uint d;
59 [StructLayout (LayoutKind.Sequential)]
60 struct winx64_struct5
62 public winx64_struct5 (byte ia, byte ib, byte ic)
64 a = ia;
65 b = ib;
66 c = ic;
69 public byte a;
70 public byte b;
71 public byte c;
74 [StructLayout (LayoutKind.Sequential)]
75 struct winx64_struct6
77 public winx64_struct6 (winx64_struct1 ia, short ib, byte ic)
79 a = ia;
80 b = ib;
81 c = ic;
84 public winx64_struct1 a;
85 public short b;
86 public byte c;
89 [StructLayout (LayoutKind.Sequential)]
90 struct winx64_floatStruct
92 public winx64_floatStruct (float ia, float ib)
94 a = ia;
95 b = ib;
98 public float a;
99 public float b;
102 [StructLayout (LayoutKind.Sequential)]
103 struct winx64_doubleStruct
105 public winx64_doubleStruct (double ia)
107 a = ia;
110 public double a;
113 class winx64structs
115 [DllImport ("libtest")]
116 static extern int mono_test_Winx64_struct1_in ([MarshalAs (UnmanagedType.Struct)] winx64_struct1 var);
118 [DllImport ("libtest")]
119 static extern int mono_test_Winx64_struct2_in ([MarshalAs (UnmanagedType.Struct)] winx64_struct2 var);
121 [DllImport ("libtest")]
122 static extern int mono_test_Winx64_struct3_in ([MarshalAs (UnmanagedType.Struct)] winx64_struct3 var);
124 [DllImport ("libtest")]
125 static extern int mono_test_Winx64_struct4_in ([MarshalAs (UnmanagedType.Struct)] winx64_struct4 var);
127 [DllImport ("libtest")]
128 static extern int mono_test_Winx64_struct5_in ([MarshalAs (UnmanagedType.Struct)] winx64_struct5 var);
130 [DllImport ("libtest")]
131 static extern int mono_test_Winx64_struct6_in ([MarshalAs (UnmanagedType.Struct)] winx64_struct6 var);
133 [DllImport ("libtest")]
134 static extern int mono_test_Winx64_structs_in1 ([MarshalAs (UnmanagedType.Struct)] winx64_struct1 var1,
135 [MarshalAs (UnmanagedType.Struct)] winx64_struct2 var2,
136 [MarshalAs (UnmanagedType.Struct)] winx64_struct3 var3,
137 [MarshalAs (UnmanagedType.Struct)] winx64_struct4 var4);
139 [DllImport ("libtest")]
140 static extern int mono_test_Winx64_structs_in2 ([MarshalAs (UnmanagedType.Struct)] winx64_struct1 var1,
141 [MarshalAs (UnmanagedType.Struct)] winx64_struct1 var2,
142 [MarshalAs (UnmanagedType.Struct)] winx64_struct1 var3,
143 [MarshalAs (UnmanagedType.Struct)] winx64_struct1 var4,
144 [MarshalAs (UnmanagedType.Struct)] winx64_struct1 var5);
146 [DllImport ("libtest")]
147 static extern int mono_test_Winx64_structs_in3 ([MarshalAs (UnmanagedType.Struct)] winx64_struct1 var1,
148 [MarshalAs (UnmanagedType.Struct)] winx64_struct5 var2,
149 [MarshalAs (UnmanagedType.Struct)] winx64_struct1 var3,
150 [MarshalAs (UnmanagedType.Struct)] winx64_struct5 var4,
151 [MarshalAs (UnmanagedType.Struct)] winx64_struct1 var5,
152 [MarshalAs (UnmanagedType.Struct)] winx64_struct5 var6);
154 [DllImport ("libtest")]
155 [return:MarshalAs (UnmanagedType.Struct)]
156 static extern winx64_struct1 mono_test_Winx64_struct1_ret ();
158 [DllImport ("libtest")]
159 [return: MarshalAs (UnmanagedType.Struct)]
160 static extern winx64_struct2 mono_test_Winx64_struct2_ret ();
162 [DllImport ("libtest")]
163 [return: MarshalAs (UnmanagedType.Struct)]
164 static extern winx64_struct3 mono_test_Winx64_struct3_ret ();
166 [DllImport ("libtest")]
167 [return: MarshalAs (UnmanagedType.Struct)]
168 static extern winx64_struct4 mono_test_Winx64_struct4_ret ();
170 [DllImport ("libtest")]
171 [return: MarshalAs (UnmanagedType.Struct)]
172 static extern winx64_struct5 mono_test_Winx64_struct5_ret ();
174 [DllImport ("libtest")]
175 [return: MarshalAs (UnmanagedType.Struct)]
176 static extern winx64_struct1 mono_test_Winx64_struct1_ret_5_args (byte a, byte b, byte c, byte d, byte e);
178 [DllImport ("libtest")]
179 [return: MarshalAs (UnmanagedType.Struct)]
180 static extern winx64_struct5 mono_test_Winx64_struct5_ret6_args (byte a, byte b, byte c, byte d, byte e );
182 [DllImport ("libtest")]
183 static extern int mono_test_Winx64_floatStruct ([MarshalAs (UnmanagedType.Struct)] winx64_floatStruct var);
185 [DllImport ("libtest")]
186 static extern int mono_test_Winx64_doubleStruct ([MarshalAs (UnmanagedType.Struct)] winx64_doubleStruct var);
188 public delegate int managed_struct1_delegate ([MarshalAs (UnmanagedType.Struct)] winx64_struct1 var);
190 [DllImport ("libtest")]
191 static extern int mono_test_managed_Winx64_struct1_in (managed_struct1_delegate func);
193 public delegate int managed_struct5_delegate ([MarshalAs (UnmanagedType.Struct)] winx64_struct5 var);
195 [DllImport ("libtest")]
196 static extern int mono_test_managed_Winx64_struct5_in (managed_struct5_delegate func);
198 public delegate int managed_struct1_struct5_delegate (winx64_struct1 var1, winx64_struct5 var2,
199 winx64_struct1 var3, winx64_struct5 var4,
200 winx64_struct1 var5, winx64_struct5 var6);
202 [DllImport ("libtest")]
203 static extern int mono_test_managed_Winx64_struct1_struct5_in (managed_struct1_struct5_delegate func);
205 [return:MarshalAs (UnmanagedType.Struct)]
206 public delegate winx64_struct1 mono_test_Winx64_struct1_ret_delegate ();
208 [DllImport ("libtest")]
209 static extern int mono_test_Winx64_struct1_ret_managed (mono_test_Winx64_struct1_ret_delegate func);
211 [return: MarshalAs (UnmanagedType.Struct)]
212 public delegate winx64_struct5 mono_test_Winx64_struct5_ret_delegate ();
214 [DllImport ("libtest")]
215 static extern int mono_test_Winx64_struct5_ret_managed (mono_test_Winx64_struct5_ret_delegate func);
218 private static bool enableBroken = false;
220 static int Main (string[] args)
222 return TestDriver.RunTests (typeof (winx64structs), args);
225 public static int test_0_In_Args_Value_In_RCX ()
227 int retCode;
229 winx64_struct1 t_winx64_struct1 = new winx64_struct1 (123);
231 if ((retCode = mono_test_Winx64_struct1_in (t_winx64_struct1)) != 0)
232 return 100 + retCode;
234 winx64_struct2 t_winx64_struct2 = new winx64_struct2 (4, 5);
236 if ((retCode = mono_test_Winx64_struct2_in (t_winx64_struct2)) != 0)
237 return 200 + retCode;
239 winx64_struct3 t_winx64_struct3 = new winx64_struct3 (4, 5, 0x1234);
241 if ((retCode = mono_test_Winx64_struct3_in (t_winx64_struct3)) != 0)
242 return 300 + retCode;
244 winx64_struct4 t_winx64_struct4 = new winx64_struct4 (4, 5, 0x1234, 0x87654321);
246 if ((retCode = mono_test_Winx64_struct4_in (t_winx64_struct4)) != 0)
247 return 400 + retCode;
249 winx64_floatStruct t_winx64_floatStruct = new winx64_floatStruct (5.5F, 9.5F);
251 if ((retCode = mono_test_Winx64_floatStruct (t_winx64_floatStruct)) != 0)
252 return 500 + retCode;
254 winx64_doubleStruct t_winx64_doubleStruct = new winx64_doubleStruct (5.5F);
256 if ((retCode = mono_test_Winx64_doubleStruct (t_winx64_doubleStruct)) != 0)
257 return 600 + retCode;
259 return 0;
262 public static int test_0_In_Args_Values_In_Multiple_Registers ()
264 int retCode;
266 winx64_struct1 t_winx64_struct1 = new winx64_struct1 (123);
267 winx64_struct2 t_winx64_struct2 = new winx64_struct2 (4, 5);
268 winx64_struct3 t_winx64_struct3 = new winx64_struct3 (4, 5, 0x1234);
269 winx64_struct4 t_winx64_struct4 = new winx64_struct4 (4, 5, 0x1234, 0x87654321);
271 if ((retCode = mono_test_Winx64_structs_in1 (t_winx64_struct1, t_winx64_struct2,
272 t_winx64_struct3, t_winx64_struct4)) != 0)
273 return 100 + retCode;
276 return 0;
279 public static int test_0_Ret_In_RAX ()
281 winx64_struct1 t_winx64_struct1 = mono_test_Winx64_struct1_ret ();
282 if (t_winx64_struct1.a != 123)
283 return 101;
285 winx64_struct2 t_winx64_struct2 = mono_test_Winx64_struct2_ret ();
286 if (t_winx64_struct2.a != 4)
287 return 201;
288 if (t_winx64_struct2.b != 5)
289 return 202;
291 winx64_struct3 t_winx64_struct3 = mono_test_Winx64_struct3_ret ();
292 if (t_winx64_struct3.a != 4)
293 return 301;
294 if (t_winx64_struct3.b != 5)
295 return 302;
296 if (t_winx64_struct3.c != 0x1234)
297 return 303;
299 winx64_struct4 t_winx64_struct4 = mono_test_Winx64_struct4_ret ();
300 if (t_winx64_struct4.a != 4)
301 return 401;
302 if (t_winx64_struct4.b != 5)
303 return 402;
304 if (t_winx64_struct4.c != 0x1234)
305 return 403;
306 if (t_winx64_struct4.d != 0x87654321)
307 return 404;
309 t_winx64_struct1 = mono_test_Winx64_struct1_ret_5_args (0x1, 0x0, 0x4, 0x10, 0x40);
310 if (t_winx64_struct1.a != 0x55)
311 return 501;
313 return 0;
316 public static int test_0_Ret_In_Address ()
318 winx64_struct5 t_winx64_struct5 = mono_test_Winx64_struct5_ret ();
319 if (t_winx64_struct5.a != 4)
320 return 101;
321 if (t_winx64_struct5.b != 5)
322 return 102;
323 if (t_winx64_struct5.c != 6)
324 return 103;
326 t_winx64_struct5 = mono_test_Winx64_struct5_ret6_args (0x1, 0x4, 0x2, 0x8, 0x30);
327 if (t_winx64_struct5.a != 0x5)
328 return 201;
329 if (t_winx64_struct5.b != 0xa)
330 return 202;
331 if (t_winx64_struct5.c != 0x30)
332 return 203;
334 return 0;
337 public static int test_0_In_Args_Values_In_Registers_and_Stack ()
339 int retCode;
341 winx64_struct1 var1 = new winx64_struct1 (1);
342 winx64_struct1 var2 = new winx64_struct1 (2);
343 winx64_struct1 var3 = new winx64_struct1 (3);
344 winx64_struct1 var4 = new winx64_struct1 (4);
345 winx64_struct1 var5 = new winx64_struct1 (5);
347 if ((retCode = mono_test_Winx64_structs_in2 (var1, var2, var3, var4, var5)) != 0)
348 return 100 + retCode;
350 return 0;
353 public static int test_0_In_Args_Values_In_Registers_with_Stack_and_On_Stack ()
355 int retCode;
357 winx64_struct1 var1 = new winx64_struct1 (1);
358 winx64_struct5 var2 = new winx64_struct5 (2, 3, 4);
359 winx64_struct1 var3 = new winx64_struct1 (5);
360 winx64_struct5 var4 = new winx64_struct5 (6, 7, 8);
361 winx64_struct1 var5 = new winx64_struct1 (9);
362 winx64_struct5 var6 = new winx64_struct5 (10, 11, 12);
364 if ((retCode = mono_test_Winx64_structs_in3 (var1, var2, var3, var4, var5, var6)) != 0)
365 return 100 + retCode;
367 return 0;
370 public static int test_0_In_Args_Value_On_Stack_ADDR_In_RCX ()
372 int retCode;
374 winx64_struct5 t_winx64_struct5 = new winx64_struct5 (4, 5, 6);
375 t_winx64_struct5.a = 4;
376 t_winx64_struct5.b = 5;
377 t_winx64_struct5.c = 6;
379 if ((retCode = mono_test_Winx64_struct5_in (t_winx64_struct5)) != 0)
380 return 100 + retCode;
382 winx64_struct6 t_winx64_struct6 = new winx64_struct6 (new winx64_struct1 (4), 5, 6);
384 if ((retCode = mono_test_Winx64_struct6_in (t_winx64_struct6)) != 0)
385 return 200 + retCode;
387 return 0;
390 public static int test_0_In_Args_Value_In_RCX_Managed ()
392 int retCode;
394 managed_struct1_delegate s1Del = new managed_struct1_delegate (managed_struct1_test);
396 if ((retCode = mono_test_managed_Winx64_struct1_in (s1Del)) != 0)
397 return 100 + retCode;
399 return 0;
402 public static int test_0_In_Args_Value_On_Stack_ADDR_In_RCX_Managed ()
404 int retCode;
406 managed_struct5_delegate s1Del = new managed_struct5_delegate (managed_struct5_test);
408 if ((retCode = mono_test_managed_Winx64_struct5_in (s1Del)) != 0)
409 return 100 + retCode;
411 return 0;
414 public static int test_0_In_Args_Values_In_Registers_with_Stack_and_On_Stack_Managed ()
416 int retCode;
418 managed_struct1_struct5_delegate s1Del =
419 new managed_struct1_struct5_delegate (managed_struct1_struct5_test);
421 if ((retCode = mono_test_managed_Winx64_struct1_struct5_in (s1Del)) != 0)
422 return 100 + retCode;
424 return 0;
427 public static int test_0_Ret_In_RAX_managed ()
429 int retCode;
431 mono_test_Winx64_struct1_ret_delegate s1Del =
432 new mono_test_Winx64_struct1_ret_delegate (mono_test_Winx64_struct1_ret_test);
434 if ((retCode = mono_test_Winx64_struct1_ret_managed (s1Del)) != 0)
435 return 100 + retCode;
437 return 0;
440 public static int test_0_Ret_In_Address_managed ()
442 int retCode;
444 mono_test_Winx64_struct5_ret_delegate s1Del =
445 new mono_test_Winx64_struct5_ret_delegate (mono_test_Winx64_struct5_ret_test);
447 if ((retCode = mono_test_Winx64_struct5_ret_managed (s1Del)) != 0)
448 return 100 + retCode;
450 return 0;
453 public static int managed_struct1_test (winx64_struct1 var)
455 if (var.a != 5)
456 return 1;
458 return 0;
461 public static int managed_struct5_test (winx64_struct5 var)
463 if (var.a != 5)
464 return 1;
465 if (var.b != 0x10)
466 return 2;
467 if (var.c != 0x99)
468 return 3;
470 return 0;
473 public static int managed_struct1_struct5_test (winx64_struct1 var1, winx64_struct5 var2,
474 winx64_struct1 var3, winx64_struct5 var4,
475 winx64_struct1 var5, winx64_struct5 var6)
477 if (var1.a != 1 || var3.a != 5)
478 return 1;
479 if (var2.a != 2 || var2.b != 3 || var2.c != 4 ||
480 var4.a != 6 || var4.b != 7 || var4.c != 8)
481 return 2;
482 if (var5.a != 9)
483 return 3;
484 if (var6.a != 10 || var6.b != 11 || var6.c != 12)
485 return 4;
487 return 0;
490 public static winx64_struct1 mono_test_Winx64_struct1_ret_test ()
492 return new winx64_struct1 (0x45);
495 public static winx64_struct5 mono_test_Winx64_struct5_ret_test ()
497 return new winx64_struct5 (0x12, 0x34, 0x56);