X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Ftests%2Finvoke.cs;h=a57d96d9e489e1c0a8ce5d9787ddd48f8039e7d7;hb=e343ad0cfd404c92761cd6e0f683ccd46402897b;hp=387f0ecb95ec18b4f9de2261dd6b8de7570ba5f3;hpb=881f83658281916d8f0784df7c726ecb7cc289db;p=mono.git diff --git a/mono/tests/invoke.cs b/mono/tests/invoke.cs index 387f0ecb95e..a57d96d9e48 100644 --- a/mono/tests/invoke.cs +++ b/mono/tests/invoke.cs @@ -1,7 +1,7 @@ using System; using System.Reflection; -class Test { +class Tests { public struct SimpleStruct { public bool a; @@ -12,18 +12,6 @@ class Test { b = false; } } - - static void Test2 () { - Console.WriteLine ("Test2 called"); - } - - public static SimpleStruct Test1 (SimpleStruct ss) { - Console.WriteLine ("Test1 called " + ss.a + " " + ss.b); - SimpleStruct res = new SimpleStruct (); - res.a = !ss.a; - res.b = !ss.b; - return res; - } public static void Foo(ref int x, ref int y) { @@ -31,45 +19,56 @@ class Test { y = 30; } - static int Main () { - Type t = typeof (Test); - - MethodInfo m2 = t.GetMethod ("Test2"); - if (m2 != null) - return 1; - - MethodInfo m1 = t.GetMethod ("Test1"); - if (m1 == null) - return 1; - - object [] args = new object [1]; - SimpleStruct ss = new SimpleStruct (); - ss.a = true; - ss.b = false; - args [0] = ss; - - SimpleStruct res = (SimpleStruct)m1.Invoke (null, args); - - if (res.a == true) - return 1; - if (res.b == false) - return 1; + public static int Main (string[] args) { + return TestDriver.RunTests (typeof (Tests), args); + } + public static int test_0_byref_null () { // Test that the objects for byref valuetype arguments are // automatically created - MethodInfo m3 = typeof(Test).GetMethod("Foo"); + MethodInfo m3 = typeof(Tests).GetMethod("Foo"); - args = new object[2]; + var args = new object[2]; m3.Invoke(null, args); if ((((int)(args [0])) != 20) || (((int)(args [1])) != 30)) return 2; + return 0; + } + + public static int test_0_ctor_vtype () { // Test the return value from ConstructorInfo.Invoke when a precreated // valuetype is used. + + SimpleStruct ss = new SimpleStruct (); + ss.a = true; + ss.b = false; + ConstructorInfo ci = typeof (SimpleStruct).GetConstructor (new Type [] { typeof (bool) }); - SimpleStruct res2 = (SimpleStruct)ci.Invoke (ss, new object [] { false }); + ci.Invoke (ss, new object [] { false }); + + return 0; + } + + public static int test_0_array_get_set () { + // Test invoking of the array Get/Set methods + string[,] arr = new string [10, 10]; + + arr.GetType ().GetMethod ("Set").Invoke (arr, new object [] { 1, 1, "FOO" }); + string s = (string)arr.GetType ().GetMethod ("Get").Invoke (arr, new object [] { 1, 1 }); + if (s != "FOO") + return 3; + + return 0; + } + + public static int test_0_string_ctor_sharing () { + // Test the sharing of runtime invoke wrappers for string ctors + typeof (string).GetConstructor (new Type [] { typeof (char[]) }).Invoke (new object [] { new char [] { 'a', 'b', 'c' } }); + + typeof (Assembly).GetMethod ("GetType", new Type [] { typeof (string), }).Invoke (typeof (int).Assembly, new object [] { "A" }); return 0; }