Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / winx64structs.cs
index c9a479cbc6775df092cbb357d326647f206ced00..0148fb4a4df0bf5cb1ba89b3b0f06b52f931dd64 100644 (file)
@@ -1,6 +1,11 @@
 using System;
 using System.Runtime.InteropServices;
 
+[AttributeUsage (AttributeTargets.Method)]
+sealed class MonoPInvokeCallbackAttribute : Attribute {
+       public MonoPInvokeCallbackAttribute (Type t) {}
+}
+
 [StructLayout (LayoutKind.Sequential)]
 struct winx64_struct1
 {
@@ -171,6 +176,14 @@ class winx64structs
        [return: MarshalAs (UnmanagedType.Struct)]
        static extern winx64_struct5 mono_test_Winx64_struct5_ret ();
 
+       [DllImport ("libtest")]
+       [return: MarshalAs (UnmanagedType.Struct)]
+       static extern winx64_struct1 mono_test_Winx64_struct1_ret_5_args (byte a, byte b, byte c, byte d, byte e);
+
+       [DllImport ("libtest")]
+       [return: MarshalAs (UnmanagedType.Struct)]
+       static extern winx64_struct5 mono_test_Winx64_struct5_ret6_args (byte a, byte b, byte c, byte d, byte e ); 
+
        [DllImport ("libtest")]
        static extern int mono_test_Winx64_floatStruct ([MarshalAs (UnmanagedType.Struct)] winx64_floatStruct var);
 
@@ -182,6 +195,31 @@ class winx64structs
        [DllImport ("libtest")]
        static extern int mono_test_managed_Winx64_struct1_in (managed_struct1_delegate func);
 
+       public delegate int managed_struct5_delegate ([MarshalAs (UnmanagedType.Struct)] winx64_struct5 var);
+
+       [DllImport ("libtest")]
+       static extern int mono_test_managed_Winx64_struct5_in (managed_struct5_delegate func);
+
+       public delegate int managed_struct1_struct5_delegate (winx64_struct1 var1, winx64_struct5 var2,
+                                                             winx64_struct1 var3, winx64_struct5 var4,
+                                                             winx64_struct1 var5, winx64_struct5 var6);
+
+       [DllImport ("libtest")]
+       static extern int mono_test_managed_Winx64_struct1_struct5_in (managed_struct1_struct5_delegate func);
+
+       [return:MarshalAs (UnmanagedType.Struct)]
+       public delegate winx64_struct1 mono_test_Winx64_struct1_ret_delegate ();
+
+       [DllImport ("libtest")]
+       static extern int mono_test_Winx64_struct1_ret_managed (mono_test_Winx64_struct1_ret_delegate func);
+
+       [return: MarshalAs (UnmanagedType.Struct)]
+       public delegate winx64_struct5 mono_test_Winx64_struct5_ret_delegate ();
+
+       [DllImport ("libtest")]
+       static extern int mono_test_Winx64_struct5_ret_managed (mono_test_Winx64_struct5_ret_delegate func);
+       
+
        private static bool enableBroken = false;
        
        static int Main (string[] args)
@@ -273,6 +311,10 @@ class winx64structs
                if (t_winx64_struct4.d != 0x87654321)
                        return 404;
 
+               t_winx64_struct1 = mono_test_Winx64_struct1_ret_5_args (0x1, 0x0, 0x4, 0x10, 0x40);
+               if (t_winx64_struct1.a != 0x55)
+                       return 501;
+
                return 0;
        }
 
@@ -286,6 +328,14 @@ class winx64structs
                if (t_winx64_struct5.c != 6)
                        return 103;
 
+               t_winx64_struct5 = mono_test_Winx64_struct5_ret6_args (0x1, 0x4, 0x2, 0x8, 0x30);
+               if (t_winx64_struct5.a != 0x5)
+                       return 201;
+               if (t_winx64_struct5.b != 0xa)
+                       return 202;
+               if (t_winx64_struct5.c != 0x30)
+                       return 203;
+
                return 0;
        }
 
@@ -354,6 +404,58 @@ class winx64structs
                return 0;
        }
 
+       public static int test_0_In_Args_Value_On_Stack_ADDR_In_RCX_Managed ()
+       {
+               int retCode;
+
+               managed_struct5_delegate s1Del = new managed_struct5_delegate (managed_struct5_test);
+
+               if ((retCode = mono_test_managed_Winx64_struct5_in (s1Del)) != 0)
+                       return 100 + retCode;
+
+               return 0;
+       }
+
+       public static int test_0_In_Args_Values_In_Registers_with_Stack_and_On_Stack_Managed ()
+       {
+               int retCode;
+
+               managed_struct1_struct5_delegate s1Del = 
+                       new managed_struct1_struct5_delegate (managed_struct1_struct5_test);
+
+               if ((retCode = mono_test_managed_Winx64_struct1_struct5_in (s1Del)) != 0)
+                       return 100 + retCode;
+
+               return 0;
+       }
+
+       public static int test_0_Ret_In_RAX_managed ()
+       {
+               int retCode;
+
+               mono_test_Winx64_struct1_ret_delegate s1Del =
+                       new mono_test_Winx64_struct1_ret_delegate (mono_test_Winx64_struct1_ret_test);
+
+               if ((retCode = mono_test_Winx64_struct1_ret_managed (s1Del)) != 0)
+                       return 100 + retCode;
+
+               return 0;
+       }
+
+       public static int test_0_Ret_In_Address_managed ()
+       {
+               int retCode;
+
+               mono_test_Winx64_struct5_ret_delegate s1Del =
+                       new mono_test_Winx64_struct5_ret_delegate (mono_test_Winx64_struct5_ret_test);
+
+               if ((retCode = mono_test_Winx64_struct5_ret_managed (s1Del)) != 0)
+                       return 100 + retCode;
+
+               return 0;
+       }
+
+       [MonoPInvokeCallback (typeof (managed_struct1_delegate))]
        public static int managed_struct1_test (winx64_struct1 var)
        {
                if (var.a != 5)
@@ -361,4 +463,48 @@ class winx64structs
 
                return 0;
        }
+
+       [MonoPInvokeCallback (typeof (managed_struct5_delegate))]
+       public static int managed_struct5_test (winx64_struct5 var)
+       {
+               if (var.a != 5)
+                       return 1;
+               if (var.b != 0x10)
+                       return 2;
+               if (var.c != 0x99)
+                       return 3;
+
+               return 0;
+       }
+
+       [MonoPInvokeCallback (typeof (managed_struct1_struct5_delegate))]
+       public static int managed_struct1_struct5_test (winx64_struct1 var1, winx64_struct5 var2,
+                                                       winx64_struct1 var3, winx64_struct5 var4,
+                                                       winx64_struct1 var5, winx64_struct5 var6)
+       {
+               if (var1.a != 1 || var3.a != 5)
+                       return 1;
+               if (var2.a != 2 || var2.b != 3 || var2.c != 4 ||
+                   var4.a != 6 || var4.b != 7 || var4.c != 8)
+                       return 2;
+               if (var5.a != 9)
+                       return 3;
+               if (var6.a != 10 || var6.b != 11 || var6.c != 12)
+                       return 4;
+
+               return 0;
+       }
+
+       [MonoPInvokeCallback (typeof (mono_test_Winx64_struct1_ret_delegate))]
+       public static winx64_struct1 mono_test_Winx64_struct1_ret_test ()
+       {
+               return new winx64_struct1 (0x45);
+       }
+
+       [MonoPInvokeCallback (typeof (mono_test_Winx64_struct5_ret_delegate))]
+       public static winx64_struct5 mono_test_Winx64_struct5_ret_test ()
+       {
+               return new winx64_struct5 (0x12, 0x34, 0x56);
+       }
+       
 }