[runtime] Fix "make distcheck"
[mono-project.git] / mono / tests / invoke.cs
bloba57d96d9e489e1c0a8ce5d9787ddd48f8039e7d7
1 using System;
2 using System.Reflection;
4 class Tests {
6 public struct SimpleStruct {
7 public bool a;
8 public bool b;
10 public SimpleStruct (bool arg) {
11 a = arg;
12 b = false;
16 public static void Foo(ref int x, ref int y)
18 x = 20;
19 y = 30;
22 public static int Main (string[] args) {
23 return TestDriver.RunTests (typeof (Tests), args);
26 public static int test_0_byref_null () {
27 // Test that the objects for byref valuetype arguments are
28 // automatically created
29 MethodInfo m3 = typeof(Tests).GetMethod("Foo");
31 var args = new object[2];
33 m3.Invoke(null, args);
35 if ((((int)(args [0])) != 20) || (((int)(args [1])) != 30))
36 return 2;
38 return 0;
41 public static int test_0_ctor_vtype () {
42 // Test the return value from ConstructorInfo.Invoke when a precreated
43 // valuetype is used.
45 SimpleStruct ss = new SimpleStruct ();
46 ss.a = true;
47 ss.b = false;
49 ConstructorInfo ci = typeof (SimpleStruct).GetConstructor (new Type [] { typeof (bool) });
50 ci.Invoke (ss, new object [] { false });
52 return 0;
55 public static int test_0_array_get_set () {
56 // Test invoking of the array Get/Set methods
57 string[,] arr = new string [10, 10];
59 arr.GetType ().GetMethod ("Set").Invoke (arr, new object [] { 1, 1, "FOO" });
60 string s = (string)arr.GetType ().GetMethod ("Get").Invoke (arr, new object [] { 1, 1 });
61 if (s != "FOO")
62 return 3;
64 return 0;
67 public static int test_0_string_ctor_sharing () {
68 // Test the sharing of runtime invoke wrappers for string ctors
69 typeof (string).GetConstructor (new Type [] { typeof (char[]) }).Invoke (new object [] { new char [] { 'a', 'b', 'c' } });
71 typeof (Assembly).GetMethod ("GetType", new Type [] { typeof (string), }).Invoke (typeof (int).Assembly, new object [] { "A" });
73 return 0;