Runtime invoke tests.
authorPaolo Molaro <lupus@oddwiz.org>
Tue, 10 Sep 2002 13:57:49 +0000 (13:57 -0000)
committerPaolo Molaro <lupus@oddwiz.org>
Tue, 10 Sep 2002 13:57:49 +0000 (13:57 -0000)
svn path=/trunk/mono/; revision=7351

mono/tests/Makefile.am
mono/tests/invoke2.cs [new file with mode: 0644]
mono/tests/reinit.cs [new file with mode: 0644]

index 0afd1578be049c586a9a0022d7ec7aef2a5ab2f6..be799f0fbe71d148f44be76457de8ea1112a62ab 100644 (file)
@@ -50,6 +50,8 @@ TEST_CS_SRC=                  \
        pinvoke8.cs             \
        pinvoke9.cs             \
        invoke.cs               \
+       invoke2.cs              \
+       reinit.cs               \
        box.cs                  \
        array.cs                \
        enum.cs                 \
diff --git a/mono/tests/invoke2.cs b/mono/tests/invoke2.cs
new file mode 100644 (file)
index 0000000..3dbf927
--- /dev/null
@@ -0,0 +1,68 @@
+using System;
+using System.Reflection;
+
+class B {
+       public virtual int vmethod () {
+               return 0;
+       }
+}
+
+class T : B {
+
+       public override int vmethod () {
+               return 1;
+       }
+       static int stuff (int a) {
+               return 0;
+       }
+       static int stuff (char a) {
+               return 1;
+       }
+       static int Main () {
+               Type t = typeof (T);
+               Type b = typeof (B);
+               T obj = new T ();
+               Type[] char_types = new Type[1] {typeof(char)};
+               Type[] int_types = new Type[1] {typeof(int)};
+               object[] int_args = new object[1] {1};
+               object[] char_args = new object[1] {(char)1};
+               MethodBase m1, m2;
+               bool ok = false;
+               try {
+                       m1 = t.GetMethod ("stuff", BindingFlags.Static|BindingFlags.NonPublic);
+               } catch (AmbiguousMatchException) {
+                       ok = true;
+               }
+               if (!ok)
+                       return 1;
+
+               m1 = t.GetMethod ("stuff", BindingFlags.Static|BindingFlags.NonPublic,
+                       null, char_types, null);
+               Console.WriteLine ("m1: {0}", m1);
+               if (m1 == null)
+                       return 2;
+
+               object m1res = m1.Invoke (null, char_args);
+               Console.WriteLine ("m1 invoke: {0}", m1res);
+               if ((int)m1res != 1)
+                       return 3;
+               
+               ok = false;
+               try {
+                       m1res = m1.Invoke (null, int_args);
+               } catch (ArgumentException) {
+                       ok = true;
+               }
+               if (!ok)
+                       return 4;
+               
+               m2 = b.GetMethod ("vmethod");
+               Console.WriteLine ("m2: {0}, declaring: {1}, reflected: {2}", m2, m2.DeclaringType, m2.ReflectedType);
+               object m2res = m2.Invoke (obj, null);
+               if ((int)m1res != 1)
+                       return 5;
+
+               return 0;
+       }
+}
+
diff --git a/mono/tests/reinit.cs b/mono/tests/reinit.cs
new file mode 100644 (file)
index 0000000..8c5bde0
--- /dev/null
@@ -0,0 +1,36 @@
+using System;
+using System.Reflection;
+
+class T {
+       int v;
+       int a;
+       public T () {
+               v = 1;
+               // note: a not modified
+       }
+       static int Main () {
+               Type t = typeof (T);
+               T obj = new T ();
+               MethodBase m1;
+               Console.WriteLine ("after ctor a is {0}", obj.a);
+               Console.WriteLine ("after ctor v is {0}", obj.v);
+               obj.a = 2;
+               obj.v = 5;
+               Console.WriteLine ("a is {0}", obj.a);
+               Console.WriteLine ("v is {0}", obj.v);
+
+               m1 = t.GetConstructor (Type.EmptyTypes);
+               m1.Invoke (obj, null);
+               Console.WriteLine ("after reinit a is {0}", obj.a);
+               Console.WriteLine ("after reinit v is {0}", obj.v);
+               /* value not preserved */
+               if (obj.a != 2)
+                       return 1;
+               /* value not reinitialized */
+               if (obj.v != 1)
+                       return 2;
+
+               return 0;
+       }
+}
+