[System] Tweak socket test
[mono-project.git] / mono / tests / winx64structs.cs
blob0148fb4a4df0bf5cb1ba89b3b0f06b52f931dd64
1 using System;
2 using System.Runtime.InteropServices;
4 [AttributeUsage (AttributeTargets.Method)]
5 sealed class MonoPInvokeCallbackAttribute : Attribute {
6 public MonoPInvokeCallbackAttribute (Type t) {}
9 [StructLayout (LayoutKind.Sequential)]
10 struct winx64_struct1
12 public winx64_struct1 (byte ia)
14 a = ia;
16 public byte a;
19 [StructLayout (LayoutKind.Sequential)]
20 struct winx64_struct2
22 public winx64_struct2 (byte ia, byte ib)
24 a = ia;
25 b = ib;
28 public byte a;
29 public byte b;
32 [StructLayout (LayoutKind.Sequential)]
33 struct winx64_struct3
35 public winx64_struct3 (byte ia, byte ib, short ic)
37 a = ia;
38 b = ib;
39 c = ic;
42 public byte a;
43 public byte b;
44 public short c;
47 [StructLayout (LayoutKind.Sequential)]
48 struct winx64_struct4
50 public winx64_struct4 (byte ia, byte ib, short ic, uint id)
52 a = ia;
53 b = ib;
54 c = ic;
55 d = id;
58 public byte a;
59 public byte b;
60 public short c;
61 public uint d;
64 [StructLayout (LayoutKind.Sequential)]
65 struct winx64_struct5
67 public winx64_struct5 (byte ia, byte ib, byte ic)
69 a = ia;
70 b = ib;
71 c = ic;
74 public byte a;
75 public byte b;
76 public byte c;
79 [StructLayout (LayoutKind.Sequential)]
80 struct winx64_struct6
82 public winx64_struct6 (winx64_struct1 ia, short ib, byte ic)
84 a = ia;
85 b = ib;
86 c = ic;
89 public winx64_struct1 a;
90 public short b;
91 public byte c;
94 [StructLayout (LayoutKind.Sequential)]
95 struct winx64_floatStruct
97 public winx64_floatStruct (float ia, float ib)
99 a = ia;
100 b = ib;
103 public float a;
104 public float b;
107 [StructLayout (LayoutKind.Sequential)]
108 struct winx64_doubleStruct
110 public winx64_doubleStruct (double ia)
112 a = ia;
115 public double a;
118 class winx64structs
120 [DllImport ("libtest")]
121 static extern int mono_test_Winx64_struct1_in ([MarshalAs (UnmanagedType.Struct)] winx64_struct1 var);
123 [DllImport ("libtest")]
124 static extern int mono_test_Winx64_struct2_in ([MarshalAs (UnmanagedType.Struct)] winx64_struct2 var);
126 [DllImport ("libtest")]
127 static extern int mono_test_Winx64_struct3_in ([MarshalAs (UnmanagedType.Struct)] winx64_struct3 var);
129 [DllImport ("libtest")]
130 static extern int mono_test_Winx64_struct4_in ([MarshalAs (UnmanagedType.Struct)] winx64_struct4 var);
132 [DllImport ("libtest")]
133 static extern int mono_test_Winx64_struct5_in ([MarshalAs (UnmanagedType.Struct)] winx64_struct5 var);
135 [DllImport ("libtest")]
136 static extern int mono_test_Winx64_struct6_in ([MarshalAs (UnmanagedType.Struct)] winx64_struct6 var);
138 [DllImport ("libtest")]
139 static extern int mono_test_Winx64_structs_in1 ([MarshalAs (UnmanagedType.Struct)] winx64_struct1 var1,
140 [MarshalAs (UnmanagedType.Struct)] winx64_struct2 var2,
141 [MarshalAs (UnmanagedType.Struct)] winx64_struct3 var3,
142 [MarshalAs (UnmanagedType.Struct)] winx64_struct4 var4);
144 [DllImport ("libtest")]
145 static extern int mono_test_Winx64_structs_in2 ([MarshalAs (UnmanagedType.Struct)] winx64_struct1 var1,
146 [MarshalAs (UnmanagedType.Struct)] winx64_struct1 var2,
147 [MarshalAs (UnmanagedType.Struct)] winx64_struct1 var3,
148 [MarshalAs (UnmanagedType.Struct)] winx64_struct1 var4,
149 [MarshalAs (UnmanagedType.Struct)] winx64_struct1 var5);
151 [DllImport ("libtest")]
152 static extern int mono_test_Winx64_structs_in3 ([MarshalAs (UnmanagedType.Struct)] winx64_struct1 var1,
153 [MarshalAs (UnmanagedType.Struct)] winx64_struct5 var2,
154 [MarshalAs (UnmanagedType.Struct)] winx64_struct1 var3,
155 [MarshalAs (UnmanagedType.Struct)] winx64_struct5 var4,
156 [MarshalAs (UnmanagedType.Struct)] winx64_struct1 var5,
157 [MarshalAs (UnmanagedType.Struct)] winx64_struct5 var6);
159 [DllImport ("libtest")]
160 [return:MarshalAs (UnmanagedType.Struct)]
161 static extern winx64_struct1 mono_test_Winx64_struct1_ret ();
163 [DllImport ("libtest")]
164 [return: MarshalAs (UnmanagedType.Struct)]
165 static extern winx64_struct2 mono_test_Winx64_struct2_ret ();
167 [DllImport ("libtest")]
168 [return: MarshalAs (UnmanagedType.Struct)]
169 static extern winx64_struct3 mono_test_Winx64_struct3_ret ();
171 [DllImport ("libtest")]
172 [return: MarshalAs (UnmanagedType.Struct)]
173 static extern winx64_struct4 mono_test_Winx64_struct4_ret ();
175 [DllImport ("libtest")]
176 [return: MarshalAs (UnmanagedType.Struct)]
177 static extern winx64_struct5 mono_test_Winx64_struct5_ret ();
179 [DllImport ("libtest")]
180 [return: MarshalAs (UnmanagedType.Struct)]
181 static extern winx64_struct1 mono_test_Winx64_struct1_ret_5_args (byte a, byte b, byte c, byte d, byte e);
183 [DllImport ("libtest")]
184 [return: MarshalAs (UnmanagedType.Struct)]
185 static extern winx64_struct5 mono_test_Winx64_struct5_ret6_args (byte a, byte b, byte c, byte d, byte e );
187 [DllImport ("libtest")]
188 static extern int mono_test_Winx64_floatStruct ([MarshalAs (UnmanagedType.Struct)] winx64_floatStruct var);
190 [DllImport ("libtest")]
191 static extern int mono_test_Winx64_doubleStruct ([MarshalAs (UnmanagedType.Struct)] winx64_doubleStruct var);
193 public delegate int managed_struct1_delegate ([MarshalAs (UnmanagedType.Struct)] winx64_struct1 var);
195 [DllImport ("libtest")]
196 static extern int mono_test_managed_Winx64_struct1_in (managed_struct1_delegate func);
198 public delegate int managed_struct5_delegate ([MarshalAs (UnmanagedType.Struct)] winx64_struct5 var);
200 [DllImport ("libtest")]
201 static extern int mono_test_managed_Winx64_struct5_in (managed_struct5_delegate func);
203 public delegate int managed_struct1_struct5_delegate (winx64_struct1 var1, winx64_struct5 var2,
204 winx64_struct1 var3, winx64_struct5 var4,
205 winx64_struct1 var5, winx64_struct5 var6);
207 [DllImport ("libtest")]
208 static extern int mono_test_managed_Winx64_struct1_struct5_in (managed_struct1_struct5_delegate func);
210 [return:MarshalAs (UnmanagedType.Struct)]
211 public delegate winx64_struct1 mono_test_Winx64_struct1_ret_delegate ();
213 [DllImport ("libtest")]
214 static extern int mono_test_Winx64_struct1_ret_managed (mono_test_Winx64_struct1_ret_delegate func);
216 [return: MarshalAs (UnmanagedType.Struct)]
217 public delegate winx64_struct5 mono_test_Winx64_struct5_ret_delegate ();
219 [DllImport ("libtest")]
220 static extern int mono_test_Winx64_struct5_ret_managed (mono_test_Winx64_struct5_ret_delegate func);
223 private static bool enableBroken = false;
225 static int Main (string[] args)
227 return TestDriver.RunTests (typeof (winx64structs), args);
230 public static int test_0_In_Args_Value_In_RCX ()
232 int retCode;
234 winx64_struct1 t_winx64_struct1 = new winx64_struct1 (123);
236 if ((retCode = mono_test_Winx64_struct1_in (t_winx64_struct1)) != 0)
237 return 100 + retCode;
239 winx64_struct2 t_winx64_struct2 = new winx64_struct2 (4, 5);
241 if ((retCode = mono_test_Winx64_struct2_in (t_winx64_struct2)) != 0)
242 return 200 + retCode;
244 winx64_struct3 t_winx64_struct3 = new winx64_struct3 (4, 5, 0x1234);
246 if ((retCode = mono_test_Winx64_struct3_in (t_winx64_struct3)) != 0)
247 return 300 + retCode;
249 winx64_struct4 t_winx64_struct4 = new winx64_struct4 (4, 5, 0x1234, 0x87654321);
251 if ((retCode = mono_test_Winx64_struct4_in (t_winx64_struct4)) != 0)
252 return 400 + retCode;
254 winx64_floatStruct t_winx64_floatStruct = new winx64_floatStruct (5.5F, 9.5F);
256 if ((retCode = mono_test_Winx64_floatStruct (t_winx64_floatStruct)) != 0)
257 return 500 + retCode;
259 winx64_doubleStruct t_winx64_doubleStruct = new winx64_doubleStruct (5.5F);
261 if ((retCode = mono_test_Winx64_doubleStruct (t_winx64_doubleStruct)) != 0)
262 return 600 + retCode;
264 return 0;
267 public static int test_0_In_Args_Values_In_Multiple_Registers ()
269 int retCode;
271 winx64_struct1 t_winx64_struct1 = new winx64_struct1 (123);
272 winx64_struct2 t_winx64_struct2 = new winx64_struct2 (4, 5);
273 winx64_struct3 t_winx64_struct3 = new winx64_struct3 (4, 5, 0x1234);
274 winx64_struct4 t_winx64_struct4 = new winx64_struct4 (4, 5, 0x1234, 0x87654321);
276 if ((retCode = mono_test_Winx64_structs_in1 (t_winx64_struct1, t_winx64_struct2,
277 t_winx64_struct3, t_winx64_struct4)) != 0)
278 return 100 + retCode;
281 return 0;
284 public static int test_0_Ret_In_RAX ()
286 winx64_struct1 t_winx64_struct1 = mono_test_Winx64_struct1_ret ();
287 if (t_winx64_struct1.a != 123)
288 return 101;
290 winx64_struct2 t_winx64_struct2 = mono_test_Winx64_struct2_ret ();
291 if (t_winx64_struct2.a != 4)
292 return 201;
293 if (t_winx64_struct2.b != 5)
294 return 202;
296 winx64_struct3 t_winx64_struct3 = mono_test_Winx64_struct3_ret ();
297 if (t_winx64_struct3.a != 4)
298 return 301;
299 if (t_winx64_struct3.b != 5)
300 return 302;
301 if (t_winx64_struct3.c != 0x1234)
302 return 303;
304 winx64_struct4 t_winx64_struct4 = mono_test_Winx64_struct4_ret ();
305 if (t_winx64_struct4.a != 4)
306 return 401;
307 if (t_winx64_struct4.b != 5)
308 return 402;
309 if (t_winx64_struct4.c != 0x1234)
310 return 403;
311 if (t_winx64_struct4.d != 0x87654321)
312 return 404;
314 t_winx64_struct1 = mono_test_Winx64_struct1_ret_5_args (0x1, 0x0, 0x4, 0x10, 0x40);
315 if (t_winx64_struct1.a != 0x55)
316 return 501;
318 return 0;
321 public static int test_0_Ret_In_Address ()
323 winx64_struct5 t_winx64_struct5 = mono_test_Winx64_struct5_ret ();
324 if (t_winx64_struct5.a != 4)
325 return 101;
326 if (t_winx64_struct5.b != 5)
327 return 102;
328 if (t_winx64_struct5.c != 6)
329 return 103;
331 t_winx64_struct5 = mono_test_Winx64_struct5_ret6_args (0x1, 0x4, 0x2, 0x8, 0x30);
332 if (t_winx64_struct5.a != 0x5)
333 return 201;
334 if (t_winx64_struct5.b != 0xa)
335 return 202;
336 if (t_winx64_struct5.c != 0x30)
337 return 203;
339 return 0;
342 public static int test_0_In_Args_Values_In_Registers_and_Stack ()
344 int retCode;
346 winx64_struct1 var1 = new winx64_struct1 (1);
347 winx64_struct1 var2 = new winx64_struct1 (2);
348 winx64_struct1 var3 = new winx64_struct1 (3);
349 winx64_struct1 var4 = new winx64_struct1 (4);
350 winx64_struct1 var5 = new winx64_struct1 (5);
352 if ((retCode = mono_test_Winx64_structs_in2 (var1, var2, var3, var4, var5)) != 0)
353 return 100 + retCode;
355 return 0;
358 public static int test_0_In_Args_Values_In_Registers_with_Stack_and_On_Stack ()
360 int retCode;
362 winx64_struct1 var1 = new winx64_struct1 (1);
363 winx64_struct5 var2 = new winx64_struct5 (2, 3, 4);
364 winx64_struct1 var3 = new winx64_struct1 (5);
365 winx64_struct5 var4 = new winx64_struct5 (6, 7, 8);
366 winx64_struct1 var5 = new winx64_struct1 (9);
367 winx64_struct5 var6 = new winx64_struct5 (10, 11, 12);
369 if ((retCode = mono_test_Winx64_structs_in3 (var1, var2, var3, var4, var5, var6)) != 0)
370 return 100 + retCode;
372 return 0;
375 public static int test_0_In_Args_Value_On_Stack_ADDR_In_RCX ()
377 int retCode;
379 winx64_struct5 t_winx64_struct5 = new winx64_struct5 (4, 5, 6);
380 t_winx64_struct5.a = 4;
381 t_winx64_struct5.b = 5;
382 t_winx64_struct5.c = 6;
384 if ((retCode = mono_test_Winx64_struct5_in (t_winx64_struct5)) != 0)
385 return 100 + retCode;
387 winx64_struct6 t_winx64_struct6 = new winx64_struct6 (new winx64_struct1 (4), 5, 6);
389 if ((retCode = mono_test_Winx64_struct6_in (t_winx64_struct6)) != 0)
390 return 200 + retCode;
392 return 0;
395 public static int test_0_In_Args_Value_In_RCX_Managed ()
397 int retCode;
399 managed_struct1_delegate s1Del = new managed_struct1_delegate (managed_struct1_test);
401 if ((retCode = mono_test_managed_Winx64_struct1_in (s1Del)) != 0)
402 return 100 + retCode;
404 return 0;
407 public static int test_0_In_Args_Value_On_Stack_ADDR_In_RCX_Managed ()
409 int retCode;
411 managed_struct5_delegate s1Del = new managed_struct5_delegate (managed_struct5_test);
413 if ((retCode = mono_test_managed_Winx64_struct5_in (s1Del)) != 0)
414 return 100 + retCode;
416 return 0;
419 public static int test_0_In_Args_Values_In_Registers_with_Stack_and_On_Stack_Managed ()
421 int retCode;
423 managed_struct1_struct5_delegate s1Del =
424 new managed_struct1_struct5_delegate (managed_struct1_struct5_test);
426 if ((retCode = mono_test_managed_Winx64_struct1_struct5_in (s1Del)) != 0)
427 return 100 + retCode;
429 return 0;
432 public static int test_0_Ret_In_RAX_managed ()
434 int retCode;
436 mono_test_Winx64_struct1_ret_delegate s1Del =
437 new mono_test_Winx64_struct1_ret_delegate (mono_test_Winx64_struct1_ret_test);
439 if ((retCode = mono_test_Winx64_struct1_ret_managed (s1Del)) != 0)
440 return 100 + retCode;
442 return 0;
445 public static int test_0_Ret_In_Address_managed ()
447 int retCode;
449 mono_test_Winx64_struct5_ret_delegate s1Del =
450 new mono_test_Winx64_struct5_ret_delegate (mono_test_Winx64_struct5_ret_test);
452 if ((retCode = mono_test_Winx64_struct5_ret_managed (s1Del)) != 0)
453 return 100 + retCode;
455 return 0;
458 [MonoPInvokeCallback (typeof (managed_struct1_delegate))]
459 public static int managed_struct1_test (winx64_struct1 var)
461 if (var.a != 5)
462 return 1;
464 return 0;
467 [MonoPInvokeCallback (typeof (managed_struct5_delegate))]
468 public static int managed_struct5_test (winx64_struct5 var)
470 if (var.a != 5)
471 return 1;
472 if (var.b != 0x10)
473 return 2;
474 if (var.c != 0x99)
475 return 3;
477 return 0;
480 [MonoPInvokeCallback (typeof (managed_struct1_struct5_delegate))]
481 public static int managed_struct1_struct5_test (winx64_struct1 var1, winx64_struct5 var2,
482 winx64_struct1 var3, winx64_struct5 var4,
483 winx64_struct1 var5, winx64_struct5 var6)
485 if (var1.a != 1 || var3.a != 5)
486 return 1;
487 if (var2.a != 2 || var2.b != 3 || var2.c != 4 ||
488 var4.a != 6 || var4.b != 7 || var4.c != 8)
489 return 2;
490 if (var5.a != 9)
491 return 3;
492 if (var6.a != 10 || var6.b != 11 || var6.c != 12)
493 return 4;
495 return 0;
498 [MonoPInvokeCallback (typeof (mono_test_Winx64_struct1_ret_delegate))]
499 public static winx64_struct1 mono_test_Winx64_struct1_ret_test ()
501 return new winx64_struct1 (0x45);
504 [MonoPInvokeCallback (typeof (mono_test_Winx64_struct5_ret_delegate))]
505 public static winx64_struct5 mono_test_Winx64_struct5_ret_test ()
507 return new winx64_struct5 (0x12, 0x34, 0x56);