Merge pull request #217 from QuickJack/master
[mono.git] / mono / tests / runtime-invoke.cs
index 7ffaf16ee4f01fba386ae5a13dc067466b336edc..d0244a26c1c4b16fba42442e99f898d3fdebbcda 100644 (file)
@@ -17,11 +17,43 @@ public class D
        }
 }
 
-class X
+enum Enum1
 {
-       static void Main ()
+       A,
+       B
+}
+
+enum Enum2
+{
+       C,
+       D
+}
+
+class Tests
+{
+       public static Enum1 return_enum1 () {
+               return Enum1.A;
+       }
+
+       public static Enum2 return_enum2 () {
+               return Enum2.C;
+       }
+
+       public static long return_long () {
+               return 1234;
+       }
+
+       public static ulong return_ulong () {
+               return UInt64.MaxValue - 5;
+       }
+
+       static int Main (string[] args)
        {
-               Assembly ass = Assembly.GetCallingAssembly ();
+               return TestDriver.RunTests (typeof (Tests), args);
+       }
+
+       public static int test_0_base () {
+               Assembly ass = typeof (Tests).Assembly;
                Type a_type = ass.GetType ("A");
                MethodInfo a_method = a_type.GetMethod ("ToString");
 
@@ -38,5 +70,112 @@ class X
 
                object d_ret = d_method.Invoke (d, null);
                Console.WriteLine (d_ret);
+
+               return 0;
+       }
+
+       public static int test_0_enum_sharing () {
+               /* Check sharing of wrappers returning enums */
+               if (typeof (Tests).GetMethod ("return_enum1").Invoke (null, null).GetType () != typeof (Enum1))
+                       return 1;
+               if (typeof (Tests).GetMethod ("return_enum2").Invoke (null, null).GetType () != typeof (Enum2))
+                       return 2;
+               return 0;
+       }
+
+       public static int test_0_primitive_sharing () {
+               /* Check sharing of wrappers returning primitive types */
+               if (typeof (Tests).GetMethod ("return_long").Invoke (null, null).GetType () != typeof (long))
+                       return 3;
+               if (typeof (Tests).GetMethod ("return_ulong").Invoke (null, null).GetType () != typeof (ulong))
+                       return 4;
+
+               return 0;
+       }
+
+       public struct Foo
+       {
+               public string ToString2 () {
+                       return "FOO";
+               }
        }
+
+       public static object GetNSObject (IntPtr i) {
+               return i;
+       }
+
+       public static int test_0_vtype_method_sharing () {
+               /* Check sharing of wrappers of vtype methods with static methods having an IntPtr argument */
+               if ((string)(typeof (Foo).GetMethod ("ToString2").Invoke (new Foo (), null)) != "FOO")
+                       return 3;
+               object o = typeof (Tests).GetMethod ("GetNSObject").Invoke (null, new object [] { new IntPtr (42) });
+               if (!(o is IntPtr) || ((IntPtr)o != new IntPtr (42)))
+                       return 4;
+
+               return 0;
+       }
+
+       public static unsafe int test_0_ptr () {
+               int[] arr = new int [10];
+               fixed (void *p = &arr [5]) {
+                       object o = typeof (Tests).GetMethod ("data_types_ptr").Invoke (null, new object [1] { new IntPtr (p) });
+                       void *p2 = Pointer.Unbox (o);
+                       if (new IntPtr (p) != new IntPtr (p2))
+                               return 1;
+
+                       o = typeof (Tests).GetMethod ("data_types_ptr").Invoke (null, new object [1] { null });
+                       p2 = Pointer.Unbox (o);
+                       if (new IntPtr (p2) != IntPtr.Zero)
+                               return 1;
+               }
+
+               return 0;
+       }
+
+       public static int test_0_string_ctor () {
+               string res = (string)typeof (String).GetConstructor (new Type [] { typeof (char[]) }).Invoke (null, new object [] { new char [] { 'A', 'B', 'C' } });
+               if (res == "ABC")
+                       return 0;
+               else
+                       return 1;
+       }
+
+       public class Foo<T> {
+               public T t;
+       }
+
+       public static int test_0_ginst_ref () {
+               Foo<string> f = new Foo<string> { t = "A" };
+               Foo<string> f2 = (Foo<string>)typeof (Tests).GetMethod ("data_types_ginst_ref").MakeGenericMethod (new Type [] { typeof (string) }).Invoke (null, new object [] { f });
+               if (f2.t != "A")
+                       return 1;
+               else
+                       return 0;
+       }
+
+       public static int test_0_ginst_vtype () {
+               FooStruct<string> f = new FooStruct<string> { t = "A" };
+               FooStruct<string> f2 = (FooStruct<string>)typeof (Tests).GetMethod ("data_types_ginst_vtype").MakeGenericMethod (new Type [] { typeof (string) }).Invoke (null, new object [] { f });
+               if (f2.t != "A")
+                       return 1;
+               else
+                       return 0;
+       }
+
+       public static Foo<T> data_types_ginst_ref<T> (Foo<T> f) {
+               return f;
+       }
+
+       public struct FooStruct<T> {
+               public T t;
+       }
+
+       public static FooStruct<T> data_types_ginst_vtype<T> (FooStruct<T> f) {
+               return f;
+       }
+
+    public static unsafe int* data_types_ptr (int *val) {
+               //Console.WriteLine (new IntPtr (val));
+        return val;
+    }
 }