2007-03-12 Zoltan Varga <vargaz@gmail.com>
authorZoltan Varga <vargaz@gmail.com>
Mon, 12 Mar 2007 12:58:31 +0000 (12:58 -0000)
committerZoltan Varga <vargaz@gmail.com>
Mon, 12 Mar 2007 12:58:31 +0000 (12:58 -0000)
* DynamicMethodTest.cs: Add a test for circular references.

svn path=/trunk/mcs/; revision=74122

mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog
mcs/class/corlib/Test/System.Reflection.Emit/DynamicMethodTest.cs

index cfda32928897ea6a1113e0eee9a430f5a481b0e8..ee92c906e629bf101999904799765a89c5f0329e 100644 (file)
@@ -1,3 +1,7 @@
+2007-03-12  Zoltan Varga  <vargaz@gmail.com>
+
+       * DynamicMethodTest.cs: Add a test for circular references.
+
 2007-03-07  Gert Driesen  <drieseng@users.sourceforge.net>
 
        * EnumBuilderTest.cs: Enabled test that failed due to bug #81037.
index b5f172cb7d469398da7f4a7051a336b492fe44ee..d4fa680ad31589cdc27c47aff31b3b8579a9213a 100644 (file)
@@ -260,6 +260,38 @@ namespace MonoTests.System.Reflection.Emit
                        object objRet = hello.Invoke (null, invokeArgs);
                        Assert.AreEqual (2, objRet, "#3");
                }
+
+               [Test]
+               public void Circular_Refs () {
+                       DynamicMethod m1 = new DynamicMethod("f1", typeof(int), new Type[] { typeof (int) },
+                                                                                                typeof(object));
+                       DynamicMethod m2 = new DynamicMethod("f2", typeof(int), new Type[] { typeof (int) },
+                                                                                                typeof(object));
+
+                       ILGenerator il1 = m1.GetILGenerator();
+                       ILGenerator il2 = m2.GetILGenerator();
+
+                       Label l = il1.DefineLabel ();
+                       //il1.EmitWriteLine ("f1");
+                       il1.Emit (OpCodes.Ldarg_0);
+                       il1.Emit (OpCodes.Ldc_I4_0);
+                       il1.Emit (OpCodes.Bne_Un, l);
+                       il1.Emit (OpCodes.Ldarg_0);
+                       il1.Emit (OpCodes.Ret);
+                       il1.MarkLabel (l);
+                       il1.Emit (OpCodes.Ldarg_0);
+                       il1.Emit (OpCodes.Ldc_I4_1);
+                       il1.Emit (OpCodes.Sub);
+                       il1.Emit (OpCodes.Call, m2);
+                       il1.Emit (OpCodes.Ret);
+
+                       //il2.EmitWriteLine("f2");
+                       il2.Emit(OpCodes.Ldarg_0);
+                       il2.Emit(OpCodes.Call, m1);
+                       il2.Emit(OpCodes.Ret);
+
+                       m1.Invoke(null, new object[] { 5 });
+               }
        }
 }