From 105b73b81769436ed78f7ea4c29be865e2930f9f Mon Sep 17 00:00:00 2001 From: Rodrigo Kumpera Date: Thu, 11 Mar 2010 15:01:00 +0000 Subject: [PATCH] 2010-03-11 Rodrigo Kumpera * TypeBuilderTest.cs: New tests for GetMethod, GetConstructor * and GetField. svn path=/trunk/mcs/; revision=153469 --- .../corlib/Test/System.Reflection.Emit/ChangeLog | 4 ++ .../Test/System.Reflection.Emit/TypeBuilderTest.cs | 45 +++++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog b/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog index 5f876da0b04..b2e7ad4f204 100644 --- a/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog +++ b/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog @@ -1,3 +1,7 @@ +2010-03-11 Rodrigo Kumpera + + * TypeBuilderTest.cs: New tests for GetMethod, GetConstructor and GetField. + 2010-02-02 Zoltan Varga * DynamicMethodTest.cs: Add a test for #575955. diff --git a/mcs/class/corlib/Test/System.Reflection.Emit/TypeBuilderTest.cs b/mcs/class/corlib/Test/System.Reflection.Emit/TypeBuilderTest.cs index 5d4849ce9d9..8f75a5e34f1 100644 --- a/mcs/class/corlib/Test/System.Reflection.Emit/TypeBuilderTest.cs +++ b/mcs/class/corlib/Test/System.Reflection.Emit/TypeBuilderTest.cs @@ -2060,7 +2060,49 @@ namespace MonoTests.System.Reflection.Emit tb.DefineProperty ("A", 0, null, Type.EmptyTypes); } -#if NET_2_0 + [Test] + public void GetMethod_WorksWithTypeBuilderParameter () { + TypeBuilder tb = module.DefineType (genTypeName ()); + var garg = tb.DefineGenericParameters ("T") [0]; + MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes); + + var mi = TypeBuilder.GetMethod (tb, mb); + var decl = mi.DeclaringType; + + Assert.IsTrue (decl.IsGenericType, "#1"); + Assert.IsFalse (decl.IsGenericTypeDefinition, "#2"); + Assert.AreEqual (tb, decl.GetGenericTypeDefinition (), "#3"); + Assert.AreEqual (garg, decl.GetGenericArguments () [0], "#4"); + } + + [Test] + public void GetConstructor_FailWithTypeBuilderParameter () { + TypeBuilder tb = module.DefineType (genTypeName ()); + var garg = tb.DefineGenericParameters ("T") [0]; + var cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes); + + try { + TypeBuilder.GetConstructor (tb, cb); + Assert.Fail ("#1"); + } catch (ArgumentException ex) { + Assert.AreEqual ("type", ex.ParamName, "#2"); + } + } + + [Test] + public void GetField_FailWithTypeBuilderParameter () { + TypeBuilder tb = module.DefineType (genTypeName ()); + var garg = tb.DefineGenericParameters ("T") [0]; + var fb = tb.DefineField ("TestField", typeof (int), FieldAttributes.Public); + + try { + TypeBuilder.GetField (tb, fb); + Assert.Fail ("#1"); + } catch (ArgumentException ex) { + Assert.AreEqual ("type", ex.ParamName, "#2"); + } + } + [Test] public void GetMethod_RejectMethodFromInflatedTypeBuilder () { TypeBuilder tb = module.DefineType (genTypeName ()); @@ -2218,7 +2260,6 @@ namespace MonoTests.System.Reflection.Emit catch (NullReferenceException) { } } -#endif [Test] //#536243 public void CreateTypeThrowsForMethodsWithBadLabels () -- 2.11.4.GIT