[test] Regression test for #58950
[mono.git] / mono / tests / invoke.cs
1 using System;
2 using System.Reflection;
3
4 class Tests {
5         
6         public struct SimpleStruct {
7                 public bool a;
8                 public bool b;
9
10                 public SimpleStruct (bool arg) {
11                         a = arg;
12                         b = false;
13                 }
14         }
15
16         public static void Foo(ref int x, ref int y)
17         {
18                 x = 20;
19                 y = 30;
20         }
21         
22         public static int Main (string[] args) {
23                 return TestDriver.RunTests (typeof (Tests), args);
24         }
25
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");
30                 
31                 var args = new object[2];
32                 
33                 m3.Invoke(null, args);
34
35                 if ((((int)(args [0])) != 20) || (((int)(args [1])) != 30))
36                         return 2;
37
38                 return 0;
39         }
40
41         public static int test_0_ctor_vtype () {
42                 // Test the return value from  ConstructorInfo.Invoke when a precreated
43                 // valuetype is used.
44
45                 SimpleStruct ss = new SimpleStruct ();
46                 ss.a = true;
47                 ss.b = false;
48
49                 ConstructorInfo ci = typeof (SimpleStruct).GetConstructor (new Type [] { typeof (bool) });
50                 ci.Invoke (ss, new object [] { false });
51
52                 return 0;
53         }
54
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];
58
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;
63
64                 return 0;
65         }
66
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' } });
70
71                 typeof (Assembly).GetMethod ("GetType", new Type [] { typeof (string), }).Invoke (typeof (int).Assembly, new object [] { "A" });
72         
73                 return 0;
74         }
75 }