Merge pull request #5636 from BrzVlad/fix-xmm-scan
[mono.git] / mono / tests / runtime-invoke.cs
index 70532e404a4384993c0eaf676e99938a5caf3516..2c34478f83d63d1931908c51f24d1384fbc2f1db 100644 (file)
@@ -29,6 +29,11 @@ enum Enum2
        D
 }
 
+struct AStruct {
+       public int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;
+       public int a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
+}
+
 class Tests
 {
        public static Enum1 return_enum1 () {
@@ -47,6 +52,10 @@ class Tests
                return UInt64.MaxValue - 5;
        }
 
+       public static object return_t<T> (T t) {
+               return (object)t;
+       }
+
        static int Main (string[] args)
        {
                return TestDriver.RunTests (typeof (Tests), args);
@@ -132,42 +141,9 @@ class Tests
                return 0;
        }
 
-       public static int test_42_int () {
-               return (int)typeof (Tests).GetMethod ("data_types_int").Invoke (null, new object [] { Int32.MinValue, UInt32.MaxValue });
-       }
-
-       public static int test_42_short () {
-               return (short)typeof (Tests).GetMethod ("data_types_short").Invoke (null, new object [] { short.MinValue, ushort.MaxValue });
-       }
-
-       public static int test_0_bool_char () {
-               if ((int)typeof (Tests).GetMethod ("data_types_bool_char").Invoke (null, new object [] { true, false, 'A' }) != 0)
-                       return 1;
-               return 0;
-       }
-
-       public static int test_0_byref_int () {
-               if ((int)typeof (Tests).GetMethod ("data_types_byref_int").Invoke (null, new object [] { 42 }) != 0)
-                       return 1;
-               return 0;
-       }
-
-       public static int test_0_long () {
-               if ((long)typeof (Tests).GetMethod ("data_types_long").Invoke (null, new object [] { 0x123456789L, (ulong)0x123456789L }) == 0x12345678AL)
-                       return 0;
-               else
-                       return 1;
-       }
-
-       public static int test_0_float_ret () {
-               if ((float)typeof (Tests).GetMethod ("data_types_float_ret").Invoke (null, new object [] { }) == 0.123f)
-                       return 0;
-               else
-                       return 1;
-       }
-
-       public static int test_0_double_ret () {
-               if ((double)typeof (Tests).GetMethod ("data_types_double_ret").Invoke (null, new object [] { }) == 0.123f)
+       public static int test_0_string_ctor () {
+               string res = (string)typeof (String).GetConstructor (new Type [] { typeof (char[]) }).Invoke (new object [] { new char [] { 'A', 'B', 'C' } });
+               if (res == "ABC")
                        return 0;
                else
                        return 1;
@@ -207,51 +183,124 @@ class Tests
                return f;
        }
 
-       public static int data_types_int (int i, uint ui) {
-               if (i == Int32.MinValue && ui == UInt32.MaxValue)
-                       return 42;
-               else
-                       return 1;
+    public static unsafe int* data_types_ptr (int *val) {
+               //Console.WriteLine (new IntPtr (val));
+        return val;
+    }
+
+       public static bool pack_u2 (ushort us) {
+               return true;
        }
 
-       public static short data_types_short (short i, ushort ui) {
-               if (i == short.MinValue && ui == ushort.MaxValue)
-                       return 42;
-               else
-                       return 1;
+       public static bool pack_i2 (short value) {
+               int c = 0;
+               // Force 'value' to be register allocated
+               for (int i = 0; i < value; ++i)
+                       c += value;
+         return value < 0x80;
        }
 
-       public static int data_types_bool_char (bool b1, bool b2, char c) {
-               if (b1 == true && b2 == false && c == 'A')
-                       return 0;
-               else
-                       return 1;
+       // #11750
+       public static int test_0_i2_u2 () {
+               typeof (Tests).GetMethod ("pack_u2").Invoke (null, new object [] { (ushort)0 });
+               var res = typeof (Tests).GetMethod ("pack_i2").Invoke (null, new object [] { (short)-1 });
+               return (bool)res ? 0 : 1;
        }
 
-       public static int data_types_byref_int (ref int i) {
-               if (i == 42)
-                       return 0;
-               else
-                       return 1;
+       public static bool pack_bool (bool b) {
+               return true;
        }
 
-       public static long data_types_long (long i, ulong ui) {
-               if (i == 0x123456789L && ui == 0x123456789L)
-                       return 0x12345678AL;
-               else
+       public static bool pack_i1 (sbyte value) {
+               int c = 0;
+               // Force 'value' to be register allocated
+               for (int i = 0; i < value; ++i)
+                       c += value;
+               return value < -1;
+       }
+
+       public static int test_0_i1_bool () {
+               typeof (Tests).GetMethod ("pack_bool").Invoke (null, new object [] { true });
+               var res = typeof (Tests).GetMethod ("pack_i1").Invoke (null, new object [] { (sbyte)-0x40 });
+               return (bool)res ? 0 : 1;
+       }
+
+       struct Point {
+               public int x, y;
+       }
+
+       struct Foo2 {
+               public Point Location {
+                       get {
+                               return new Point () { x = 10, y = 20 };
+                       }
+               }
+       }
+
+       public static int test_0_vtype_method_vtype_ret () {
+               var f = new Foo2 ();
+               var p = (Point)typeof (Foo2).GetMethod ("get_Location").Invoke (f, null);
+               if (p.x != 10 || p.y != 20)
                        return 1;
+               return 0;
        }
 
-       public static float data_types_float_ret () {
-               return 0.123f;
+       public static int test_0_array_get_set () {
+               int[,,] arr = new int [10, 10, 10];
+               arr [0, 1, 2] = 42;
+               var gm = arr.GetType ().GetMethod ("Get");
+               int i = (int) gm.Invoke (arr, new object [] { 0, 1, 2 });
+               if (i != 42)
+                       return 1;
+               var sm = arr.GetType ().GetMethod ("Set");
+               sm.Invoke (arr, new object [] { 0, 1, 2, 33 });
+               if (arr [0, 1, 2] != 33)
+                       return 2;
+               return 0;
        }
 
-       public static double data_types_double_ret () {
-               return 0.123f;
+       public static int test_0_multi_dim_array_ctor () {
+        var type1 = Type.GetType ("System.Char[,]").GetTypeInfo ();
+
+               ConstructorInfo ci = null;
+               foreach (var c in type1.DeclaredConstructors) {
+                       if (c.GetParameters ().Length == 4)
+                               ci = c;
+               }
+        var res = ci.Invoke (new object[] { 1, 5, -10, 7 });
+               var a = (Array)res;
+               if (a.GetLength (0) != 5 || a.GetLowerBound (0) != 1 || a.GetLength (1) != 7 || a.GetLowerBound (1) != -10)
+                       return 1;
+               return 0;
        }
 
-    public static unsafe int* data_types_ptr (int *val) {
-               //Console.WriteLine (new IntPtr (val));
-        return val;
+       private static void method_invoke_no_modify_by_value_arg_helper (int dummy)
+    {
     }
+
+    public static int test_0_method_invoke_no_modify_by_value_arg ()
+    {
+        var args = new object[] { null };
+        var method = typeof (Tests).GetMethod ("method_invoke_no_modify_by_value_arg_helper", BindingFlags.NonPublic | BindingFlags.Static);
+        method.Invoke (null, args);
+        if (args[0] == null)
+            return 0;
+        else
+            return 1;
+    }
+
+       public static int test_0_large_arg ()
+       {
+               var arg = new AStruct ();
+               arg.a1 = 1;
+               arg.a2 = 2;
+               arg.a3 = 3;
+               arg.a20 = 20;
+               var res = typeof (Tests).GetMethod ("return_t").MakeGenericMethod (new Type [] { typeof (AStruct) }).Invoke (null, new object [] { arg });
+               var arg2 = (AStruct)res;
+               if (arg2.a20 == 20)
+                       return 0;
+               else
+                       return 1;
+       }
 }