Permalink
Browse files

2010-07-12 Rodrigo Kumpera <rkumpera@novell.com>

	* bug-389886-3.cs: New regression test.

svn path=/trunk/mono/; revision=160259
  • Loading branch information...
1 parent d229e91 commit c0da3aa336c288adf2a2bc33eea0879856006f00 @kumpera kumpera committed Jul 12, 2010
Showing with 116 additions and 1 deletion.
  1. +4 −0 mono/tests/ChangeLog
  2. +2 −1 mono/tests/Makefile.am
  3. +110 −0 mono/tests/bug-389886-3.cs
View
@@ -1,3 +1,7 @@
+2010-07-12 Rodrigo Kumpera <rkumpera@novell.com>
+
+ * bug-389886-3.cs: New regression test.
+
2010-07-10 Jonathan Pryor <jpryor@novell.com>
* Makfile.am (test-process-exit): Expected output is in $srcdir.
View
@@ -368,7 +368,8 @@ BASE_TEST_CS_SRC= \
bug-561239.cs \
bug-562150.cs \
bug-575941.cs \
- bug-599469.cs
+ bug-599469.cs \
+ bug-389886-3.cs
TEST_CS_SRC_DIST= \
$(BASE_TEST_CS_SRC) \
View
@@ -0,0 +1,110 @@
+using System;
+using System.Threading;
+using System.Reflection;
+using System.Reflection.Emit;
+
+namespace TestApp
+{
+ class Program
+ {
+ static AssemblyBuilder assembly;
+ static ModuleBuilder module;
+ static Type[] args;
+ static ConstructorBuilder delegate_ctor;
+ static MethodBuilder invoke_mb;
+ static string ASSEMBLY_NAME = "MonoTests.System.Reflection.Emit.TypeBuilderTest";
+
+ static void SetUp ()
+ {
+ AssemblyName assemblyName = new AssemblyName ();
+ assemblyName.Name = ASSEMBLY_NAME;
+
+ assembly =
+ Thread.GetDomain ().DefineDynamicAssembly (
+ assemblyName, AssemblyBuilderAccess.RunAndSave, ".");
+
+ module = assembly.DefineDynamicModule ("module1", "bla.exe");
+ }
+
+ static TypeBuilder DefineDelegate () {
+ TypeBuilder typeBuilder = module.DefineType( "MyDelegate",
+ TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Sealed,
+ typeof (object) );
+ args = typeBuilder.DefineGenericParameters ("TIn", "TOut");
+
+ delegate_ctor = typeBuilder.DefineConstructor(
+ MethodAttributes.Public | MethodAttributes.HideBySig |
+ MethodAttributes.RTSpecialName | MethodAttributes.SpecialName,
+ CallingConventions.Standard,
+ new Type[] { typeof(Object), typeof (IntPtr) } );
+
+ delegate_ctor.SetImplementationFlags( MethodImplAttributes.Runtime | MethodImplAttributes.Managed );
+
+ invoke_mb = typeBuilder.DefineMethod(
+ "Invoke",
+ MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig,
+ args [1],
+ new Type[] { args [0] } );
+
+ invoke_mb.SetImplementationFlags( MethodImplAttributes.Runtime | MethodImplAttributes.Managed );
+
+ MethodBuilder mb = typeBuilder.DefineMethod(
+ "BeginInvoke",
+ MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig,
+ typeof (IAsyncResult),
+ new Type[] { args [0], typeof (AsyncCallback), typeof (object) } );
+
+ mb.SetImplementationFlags( MethodImplAttributes.Runtime | MethodImplAttributes.Managed );
+
+ mb = typeBuilder.DefineMethod(
+ "EndInvoke",
+ MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig,
+ args [1],
+ new Type[] { typeof (IAsyncResult) } );
+
+ mb.SetImplementationFlags( MethodImplAttributes.Runtime | MethodImplAttributes.Managed );
+
+ return typeBuilder;
+ }
+
+ static int Main()
+ {
+ SetUp ();
+
+ TypeBuilder tb = DefineDelegate ();
+ TypeBuilder main = module.DefineType ("Main", TypeAttributes.Public);
+ /* >>>move this to after the SetParent call and things will work<<< */
+ Type inst = tb.MakeGenericType (new Type[] {typeof (double), typeof(int)});
+
+ tb.SetParent (typeof( System.MulticastDelegate));
+
+ ConstructorBuilder ctor = main.DefineDefaultConstructor (MethodAttributes.Public);
+
+ MethodBuilder foo_mb = main.DefineMethod("Foo", MethodAttributes.Public, typeof (int), new Type[] { typeof (double) } );
+ ILGenerator ig = foo_mb.GetILGenerator ();
+ ig.Emit (OpCodes.Ldc_I4_0);
+ ig.Emit (OpCodes.Ret);
+
+
+ MethodBuilder main_mb = main.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static, typeof (int), Type.EmptyTypes);
+ ig = main_mb.GetILGenerator ();
+
+ ig.Emit (OpCodes.Newobj, ctor);
+ ig.Emit (OpCodes.Ldftn, foo_mb);
+ ig.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (inst, delegate_ctor));
+ ig.Emit (OpCodes.Ldc_R8, 2.2);
+ ig.Emit (OpCodes.Callvirt, TypeBuilder.GetMethod (inst, invoke_mb));
+
+ ig.Emit (OpCodes.Ret);
+
+ tb.CreateType ();
+
+ Type t = main.CreateType ();
+
+ MethodInfo method = t.GetMethod ("Main");
+ method.Invoke (null, null);
+
+ return 0;
+ }
+ }
+}

0 comments on commit c0da3aa

Please sign in to comment.