[interp] Remove unreachable code (#12411)
[mono-project.git] / mono / tests / thunks.cs
blobcd59ad8bb721e1ed335680575b09866a38d44fcc
1 using System;
2 using System.Reflection;
3 using System.Runtime.InteropServices;
5 public class Test
7 [DllImport ("libtest")]
8 public static extern int test_method_thunk (int test_id, IntPtr testMethodHandle,
9 IntPtr createObjectHandle);
11 static void RunTests(int series, Type type)
13 const string Prefix = "Test";
14 MethodInfo createObjectMethod = type.GetMethod ("CreateObject");
16 foreach (MethodInfo mi in type.GetMethods ()) {
17 string name = mi.Name;
18 if (!name.StartsWith (Prefix))
19 continue;
21 int id = Convert.ToInt32 (name.Substring (Prefix.Length));
23 int res = test_method_thunk (series + id, mi.MethodHandle.Value, createObjectMethod.MethodHandle.Value);
25 if (res != 0) {
26 Console.WriteLine ("{0} returned {1}", mi, res);
27 Environment.Exit ((id << 3) + res);
32 public static int Main ()
34 RunTests (0, typeof (Test));
35 RunTests (100, typeof (TestStruct));
36 return 0;
39 public static object CreateObject ()
41 return new Test ();
44 public static void Test0 ()
48 public static int Test1 ()
50 return 42;
53 public static string Test2 (string s)
55 return s;
58 public string Test3 (string a)
60 return a;
63 public int Test4 (string a, int i)
65 return i;
68 public int Test5 (string a, int i)
70 throw new NotImplementedException ();
73 public bool Test6 (byte a1, short a2, int a3, long a4, float a5, double a6, string a7)
75 return a1 == 254 &&
76 a2 == 32700 &&
77 a3 == -245378 &&
78 a4 == 6789600 &&
79 (Math.Abs (a5 - 3.1415) < 0.001) &&
80 (Math.Abs (a6 - 3.1415) < 0.001) &&
81 a7 == "Test6";
84 public static long Test7 ()
86 return Int64.MaxValue;
89 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)
91 a1 = 254;
92 a2 = 32700;
93 a3 = -245378;
94 a4 = 6789600;
95 a5 = 3.1415f;
96 a6 = 3.1415;
97 a7 = "Test8";
100 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)
102 throw new NotImplementedException ();
105 public static void Test10 (ref Test obj)
107 obj = new Test ();
112 public struct TestStruct
114 public int A;
115 public double B;
117 public static object CreateObject ()
119 return new TestStruct ();
122 public static bool Test0 (TestStruct s)
124 bool res = s.A == 42 && Math.Abs (s.B - 3.1415) < 0.001;
126 /* these changes must not be visible in unmanaged code */
127 s.A = 12;
128 s.B = 13;
130 return res;
133 public static void Test1 (ref TestStruct s)
135 s.A = 42;
136 s.B = 3.1415;
139 public static TestStruct Test2 ()
141 TestStruct s = new TestStruct ();
142 s.A = 42;
143 s.B = 3.1415;
144 return s;
147 public void Test3 ()
149 A = 1;
150 B = 17;