Permalink
Browse files

2008-05-16 Rodrigo Kumpera <rkumpera@novell.com>

	* bug-389886.2.il: Regression test for bug #389886.


svn path=/trunk/mono/; revision=103343
  • Loading branch information...
1 parent 27c4971 commit 6918bcc53c34c55e18908442faa392acf751d46d @kumpera kumpera committed May 16, 2008
Showing with 101 additions and 0 deletions.
  1. +4 −0 mono/tests/ChangeLog
  2. +1 −0 mono/tests/Makefile.am
  3. +96 −0 mono/tests/bug-389886-2.cs
View
@@ -1,3 +1,7 @@
+2008-05-16 Rodrigo Kumpera <rkumpera@novell.com>
+
+ * bug-389886.2.il: Regression test for bug #389886.
+
2008-05-13 Zoltan Varga <vargaz@gmail.com>
* exit-stress.cs: New stress test program for testing Environment.Exit () and
View
@@ -286,6 +286,7 @@ BASE_TEST_CS_SRC= \
bug-348522.2.cs \
bug-340662_bug.cs \
bug-322722_dyn_method_throw.2.cs \
+ bug-389886-2.cs \
thunks.cs
if AMD64
View
@@ -0,0 +1,96 @@
+using System;
+using System.Threading;
+using System.Reflection;
+using System.Reflection.Emit;
+
+/*public delegate void FooDelegate ();*/
+
+public class EmitTest
+{
+ static ConstructorBuilder ctor;
+ static MethodBuilder targetMethod;
+ static MethodBuilder testEvents;
+ static Type fooOpenInst;
+ static Type[] genericArgs;
+
+ static void EmitCtor (TypeBuilder genericFoo) {
+ ConstructorBuilder mb = genericFoo.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, null);
+ ILGenerator il = mb.GetILGenerator ();
+ for (int i = 0; i < 20; ++i)
+ il.Emit (OpCodes.Nop);
+
+ il.Emit (OpCodes.Ldarg_0);
+ il.Emit (OpCodes.Call, typeof (object).GetConstructors()[0]);
+ il.Emit (OpCodes.Ret);
+
+ ctor = mb;
+ }
+
+ static void EmitTestEvents (TypeBuilder genericFoo) {
+ MethodBuilder mb = genericFoo.DefineMethod ("TestEvents", MethodAttributes.Public, typeof (void), null);
+ ILGenerator il = mb.GetILGenerator ();
+ for (int i = 0; i < 20; ++i)
+ il.Emit (OpCodes.Nop);
+
+ il.Emit (OpCodes.Ldarg_0);
+ il.Emit (OpCodes.Ldnull);
+ il.Emit (OpCodes.Callvirt, targetMethod);
+
+ il.Emit (OpCodes.Ret);
+
+ testEvents = mb;
+ }
+
+
+ static void EmitTargetMethod (TypeBuilder genericFoo) {
+ MethodBuilder mb = genericFoo.DefineMethod ("TargetMethod", MethodAttributes.Public, typeof (void), new Type[] {typeof (object) });
+ ILGenerator il = mb.GetILGenerator ();
+
+ for (int i = 0; i < 20; ++i)
+ il.Emit (OpCodes.Nop);
+
+ il.Emit (OpCodes.Ldtoken, genericArgs [0]);
+ il.Emit (OpCodes.Call, typeof (Type).GetMethod ("GetTypeFromHandle"));
+ il.Emit (OpCodes.Call, typeof (Console).GetMethod ("WriteLine", new Type[] { typeof (object) }));
+ il.Emit (OpCodes.Ret);
+
+ targetMethod = mb;
+ }
+
+ public static int Main () {
+ AssemblyName assemblyName = new AssemblyName();
+ assemblyName.Name = "customMod";
+ assemblyName.Version = new Version (1, 2, 3, 4);
+
+ AssemblyBuilder assembly
+ = Thread.GetDomain().DefineDynamicAssembly(
+ assemblyName, AssemblyBuilderAccess.RunAndSave);
+
+ ModuleBuilder module = assembly.DefineDynamicModule("res.exe", "res.exe");
+
+ TypeBuilder genericFoo = module.DefineType ("GenericFoo", TypeAttributes.Public, typeof (object));
+ genericArgs = genericFoo.DefineGenericParameters ("T");
+ fooOpenInst = genericFoo.MakeGenericType (genericArgs);
+
+ EmitCtor (genericFoo);
+ EmitTargetMethod (genericFoo);
+ EmitTestEvents (genericFoo);
+
+ TypeBuilder moduletype = module.DefineType ("ModuleType", TypeAttributes.Public, typeof (object));
+ MethodBuilder main = moduletype.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static, typeof (void), null);
+ ILGenerator il = main.GetILGenerator ();
+
+ Type strInst = genericFoo.MakeGenericType (typeof (string));
+ il.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (strInst, ctor));
+ il.Emit (OpCodes.Callvirt, TypeBuilder.GetMethod (strInst, testEvents));
+ il.Emit (OpCodes.Ret);
+
+ genericFoo.CreateType ();
+ Type res = moduletype.CreateType ();
+
+ res.GetMethod ("Main").Invoke (null, null);
+ return 0;
+ }
+
+}
+

0 comments on commit 6918bcc

Please sign in to comment.