In metadata:
[mono.git] / mono / tests / thunks.cs
index 5ee054dadd92cd11c5f4d098b1ecbd4f09db0329..cd59ad8bb721e1ed335680575b09866a38d44fcc 100644 (file)
@@ -1,79 +1,76 @@
 using System;
+using System.Reflection;
 using System.Runtime.InteropServices;
 
 public class Test
 {
        [DllImport ("libtest")]
-       public static extern int test_method_thunk (int id, IntPtr testMethodHandle,
+               public static extern int test_method_thunk (int test_id, IntPtr testMethodHandle,
                IntPtr createObjectHandle);
 
-       static int test_method_thunk (int id, Type type)
+       static void RunTests(int series, Type type)
        {
-               string name = String.Format ("Foo{0}", id);
-               return test_method_thunk (
-                       id,
-                       type.GetMethod (name).MethodHandle.Value,
-                       type.GetMethod ("CreateObject").MethodHandle.Value);
+               const string Prefix = "Test";
+               MethodInfo createObjectMethod = type.GetMethod ("CreateObject");
+               
+               foreach (MethodInfo mi in type.GetMethods ()) {
+                       string name = mi.Name;
+                       if (!name.StartsWith (Prefix))
+                               continue;
+
+                       int id = Convert.ToInt32 (name.Substring (Prefix.Length));
+
+                       int res = test_method_thunk (series + id, mi.MethodHandle.Value, createObjectMethod.MethodHandle.Value);
+
+                       if (res != 0) {
+                               Console.WriteLine ("{0} returned {1}", mi, res);
+                               Environment.Exit ((id << 3) + res);
+                       }
+               }
        }
 
        public static int Main ()
        {
-               const int MaxClassTests = 13;
-               const int MaxStructTests = 1;
-               
-               // tests of class "Test"
-               for (int i = 0; i < MaxClassTests; i++) {
-                       int res = test_method_thunk (i, typeof (Test));
-                       if (res != 0)
-                               return i*10 + res;
-               }
-
-               // tests of struct "TestStruct"
-               for (int i = 0; i < MaxStructTests; i++) {
-                       int res = test_method_thunk (MaxClassTests + i, typeof (TestStruct));
-                       if (res != 0)
-                               return i*10 + res;
-               }
-               
+               RunTests (0, typeof (Test));
+               RunTests (100, typeof (TestStruct));
                return 0;
        }
 
        public static object CreateObject ()
        {
-               Test t = new Test ();
-               return t;
+               return new Test ();
        }
 
-       public static void Foo0 ()
+       public static void Test0 ()
        {
        }
 
-       public static int Foo1 ()
+       public static int Test1 ()
        {
                return 42;
        }
 
-       public static string Foo2 (string s)
+       public static string Test2 (string s)
        {
                return s;
        }
 
-       public string Foo3 (string a)
+       public string Test3 (string a)
        {
                return a;
        }
 
-       public int Foo4 (string a, int i)
+       public int Test4 (string a, int i)
        {
                return i;
        }
 
-       public int Foo5 (string a, int i)
+       public int Test5 (string a, int i)
        {
                throw new NotImplementedException ();
        }
 
-       public bool Foo6 (byte a1, short a2, int a3, long a4, float a5, double a6, string a7)
+       public bool Test6 (byte a1, short a2, int a3, long a4, float a5, double a6, string a7)
        {
                return  a1 == 254 &&
                        a2 == 32700 &&
@@ -81,15 +78,15 @@ public class Test
                        a4 == 6789600 &&
                        (Math.Abs (a5 - 3.1415) < 0.001) &&
                        (Math.Abs (a6 - 3.1415) < 0.001) &&
-                       a7 == "Foo6";
+                       a7 == "Test6";
        }
 
-       public static long Foo7 ()
+       public static long Test7 ()
        {
                return Int64.MaxValue;
        }
 
-       public static void Foo8 (ref byte a1, ref short a2, ref int a3, ref long a4, ref float a5, ref double a6, ref string a7)
+       public static void Test8 (ref byte a1, ref short a2, ref int a3, ref long a4, ref float a5, ref double a6, ref string a7)
        {
                a1 = 254;
                a2 = 32700;
@@ -97,46 +94,57 @@ public class Test
                a4 = 6789600;
                a5 = 3.1415f;
                a6 = 3.1415;
-               a7 = "Foo8";
+               a7 = "Test8";
        }
 
-       public static void Foo9 (ref byte a1, ref short a2, ref int a3, ref long a4, ref float a5, ref double a6, ref string a7)
+       public static void Test9 (ref byte a1, ref short a2, ref int a3, ref long a4, ref float a5, ref double a6, ref string a7)
        {
                throw new NotImplementedException ();
        }
 
-       public static bool Foo10 (TestStruct s)
+       public static void Test10 (ref Test obj)
+       {
+               obj = new Test ();
+       }
+}
+
+
+public struct TestStruct
+{
+       public int A;
+       public double B;
+
+       public static object CreateObject ()
+       {
+               return new TestStruct ();
+       }
+
+       public static bool Test0 (TestStruct s)
        {
-               return s.A == 42 && Math.Abs (s.B - 3.1415) < 0.001;
+               bool res =  s.A == 42 && Math.Abs (s.B - 3.1415) < 0.001;
+
+               /* these changes must not be visible in unmanaged code */
+               s.A = 12;
+               s.B = 13;
+
+               return res;
        }
 
-       public static void Foo11 (ref TestStruct s)
+       public static void Test1 (ref TestStruct s)
        {
                s.A = 42;
                s.B = 3.1415;
        }
 
-       public static TestStruct Foo12 ()
+       public static TestStruct Test2 ()
        {
                TestStruct s = new TestStruct ();
                s.A = 42;
                s.B = 3.1415;
                return s;
        }
-}
-
-
-public struct TestStruct
-{
-       public int A;
-       public double B;
-
-       public static TestStruct CreateObject ()
-       {
-               return new TestStruct ();
-       }
 
-       public void Foo13 ()
+       public void Test3 ()
        {
                A = 1;
                B = 17;