2 using System.Reflection;
6 public override string ToString ()
34 public static Enum1 return_enum1 () {
38 public static Enum2 return_enum2 () {
42 public static long return_long () {
46 public static ulong return_ulong () {
47 return UInt64.MaxValue - 5;
50 static int Main (string[] args)
52 return TestDriver.RunTests (typeof (Tests), args);
55 public static int test_0_base () {
56 Assembly ass = typeof (Tests).Assembly;
57 Type a_type = ass.GetType ("A");
58 MethodInfo a_method = a_type.GetMethod ("ToString");
60 Type d_type = ass.GetType ("D");
61 MethodInfo d_method = d_type.GetMethod ("Test");
63 Console.WriteLine ("TEST: {0} {1}", a_method, d_method);
68 object a_ret = a_method.Invoke (a, null);
69 Console.WriteLine (a_ret);
71 object d_ret = d_method.Invoke (d, null);
72 Console.WriteLine (d_ret);
77 public static int test_0_enum_sharing () {
78 /* Check sharing of wrappers returning enums */
79 if (typeof (Tests).GetMethod ("return_enum1").Invoke (null, null).GetType () != typeof (Enum1))
81 if (typeof (Tests).GetMethod ("return_enum2").Invoke (null, null).GetType () != typeof (Enum2))
86 public static int test_0_primitive_sharing () {
87 /* Check sharing of wrappers returning primitive types */
88 if (typeof (Tests).GetMethod ("return_long").Invoke (null, null).GetType () != typeof (long))
90 if (typeof (Tests).GetMethod ("return_ulong").Invoke (null, null).GetType () != typeof (ulong))
98 public string ToString2 () {
103 public static object GetNSObject (IntPtr i) {
107 public static int test_0_vtype_method_sharing () {
108 /* Check sharing of wrappers of vtype methods with static methods having an IntPtr argument */
109 if ((string)(typeof (Foo).GetMethod ("ToString2").Invoke (new Foo (), null)) != "FOO")
111 object o = typeof (Tests).GetMethod ("GetNSObject").Invoke (null, new object [] { new IntPtr (42) });
112 if (!(o is IntPtr) || ((IntPtr)o != new IntPtr (42)))
118 public static unsafe int test_0_ptr () {
119 int[] arr = new int [10];
120 fixed (void *p = &arr [5]) {
121 object o = typeof (Tests).GetMethod ("data_types_ptr").Invoke (null, new object [1] { new IntPtr (p) });
122 void *p2 = Pointer.Unbox (o);
123 if (new IntPtr (p) != new IntPtr (p2))
126 o = typeof (Tests).GetMethod ("data_types_ptr").Invoke (null, new object [1] { null });
127 p2 = Pointer.Unbox (o);
128 if (new IntPtr (p2) != IntPtr.Zero)
135 public static int test_0_string_ctor () {
136 string res = (string)typeof (String).GetConstructor (new Type [] { typeof (char[]) }).Invoke (new object [] { new char [] { 'A', 'B', 'C' } });
143 public class Foo<T> {
147 public static int test_0_ginst_ref () {
148 Foo<string> f = new Foo<string> { t = "A" };
149 Foo<string> f2 = (Foo<string>)typeof (Tests).GetMethod ("data_types_ginst_ref").MakeGenericMethod (new Type [] { typeof (string) }).Invoke (null, new object [] { f });
156 public static int test_0_ginst_vtype () {
157 FooStruct<string> f = new FooStruct<string> { t = "A" };
158 FooStruct<string> f2 = (FooStruct<string>)typeof (Tests).GetMethod ("data_types_ginst_vtype").MakeGenericMethod (new Type [] { typeof (string) }).Invoke (null, new object [] { f });
165 public static Foo<T> data_types_ginst_ref<T> (Foo<T> f) {
169 public struct FooStruct<T> {
173 public static FooStruct<T> data_types_ginst_vtype<T> (FooStruct<T> f) {
177 public static unsafe int* data_types_ptr (int *val) {
178 //Console.WriteLine (new IntPtr (val));
182 public static bool pack_u2 (ushort us) {
186 public static bool pack_i2 (short value) {
188 // Force 'value' to be register allocated
189 for (int i = 0; i < value; ++i)
195 public static int test_0_i2_u2 () {
196 typeof (Tests).GetMethod ("pack_u2").Invoke (null, new object [] { (ushort)0 });
197 var res = typeof (Tests).GetMethod ("pack_i2").Invoke (null, new object [] { (short)-1 });
198 return (bool)res ? 0 : 1;
201 public static bool pack_bool (bool b) {
205 public static bool pack_i1 (sbyte value) {
207 // Force 'value' to be register allocated
208 for (int i = 0; i < value; ++i)
213 public static int test_0_i1_bool () {
214 typeof (Tests).GetMethod ("pack_bool").Invoke (null, new object [] { true });
215 var res = typeof (Tests).GetMethod ("pack_i1").Invoke (null, new object [] { (sbyte)-0x40 });
216 return (bool)res ? 0 : 1;
224 public Point Location {
226 return new Point () { x = 10, y = 20 };
231 public static int test_0_vtype_method_vtype_ret () {
233 var p = (Point)typeof (Foo2).GetMethod ("get_Location").Invoke (f, null);
234 if (p.x != 10 || p.y != 20)
239 public static int test_0_array_get_set () {
240 int[,,] arr = new int [10, 10, 10];
242 var gm = arr.GetType ().GetMethod ("Get");
243 int i = (int) gm.Invoke (arr, new object [] { 0, 1, 2 });
246 var sm = arr.GetType ().GetMethod ("Set");
247 sm.Invoke (arr, new object [] { 0, 1, 2, 33 });
248 if (arr [0, 1, 2] != 33)
253 public static int test_0_multi_dim_array_ctor () {
254 var type1 = Type.GetType ("System.Char[,]").GetTypeInfo ();
256 ConstructorInfo ci = null;
257 foreach (var c in type1.DeclaredConstructors) {
258 if (c.GetParameters ().Length == 4)
261 var res = ci.Invoke (new object[] { 1, 5, -10, 7 });
263 if (a.GetLength (0) != 5 || a.GetLowerBound (0) != 1 || a.GetLength (1) != 7 || a.GetLowerBound (1) != -10)