Merge pull request #1909 from esdrubal/reflection
[mono.git] / mcs / class / corlib / Test / System.Reflection.Emit / ModuleBuilderTest.cs
index 33d320e72999283562f76682554f94090d29c0b4..aa6f1ba35833bdb3b1c4bf28e54fedd5b0a83718 100644 (file)
@@ -136,6 +136,7 @@ namespace MonoTests.System.Reflection.Emit
                }
 
                [Test]
+               [Category ("AndroidNotWorking")] // Missing Mono.CompilerServices.SymbolWriter assembly
                public void DefineType_Name_Null ()
                {
                        AssemblyBuilder ab = genAssembly ();
@@ -152,6 +153,7 @@ namespace MonoTests.System.Reflection.Emit
                }
 
                [Test]
+               [Category ("AndroidNotWorking")] // Missing Mono.CompilerServices.SymbolWriter assembly
                public void DefineType_Name_Empty ()
                {
                        AssemblyBuilder ab = genAssembly ();
@@ -169,6 +171,7 @@ namespace MonoTests.System.Reflection.Emit
                }
 
                [Test]
+               [Category ("AndroidNotWorking")] // Missing Mono.CompilerServices.SymbolWriter assembly
                public void DefineType_Name_NullChar ()
                {
                        AssemblyBuilder ab = genAssembly ();
@@ -188,6 +191,7 @@ namespace MonoTests.System.Reflection.Emit
                }
 
                [Test]
+               [Category ("AndroidNotWorking")] // Missing Mono.CompilerServices.SymbolWriter assembly
                public void DefineType_InterfaceNotAbstract ()
                {
                        AssemblyBuilder ab = genAssembly ();
@@ -224,9 +228,7 @@ namespace MonoTests.System.Reflection.Emit
                }
 
                [Test]
-#if ONLY_1_1
-               [Category ("NotDotNet")] // Parent type was not extensible by the given type
-#endif
+               [Category ("AndroidNotWorking")] // Missing Mono.CompilerServices.SymbolWriter assembly
                public void DefineType_Parent_Interface ()
                {
                        TypeBuilder tb;
@@ -244,6 +246,19 @@ namespace MonoTests.System.Reflection.Emit
                }
 
                [Test]
+               [Category ("AndroidNotWorking")] // Missing Mono.CompilerServices.SymbolWriter assembly
+               public void DefineType_TypeSize ()
+               {
+                       AssemblyBuilder ab = genAssembly ();
+                       ModuleBuilder mb = ab.DefineDynamicModule ("foo.dll", "foo.dll", true);
+
+                       TypeBuilder tb = mb.DefineType ("Foo", TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.SequentialLayout,
+                               typeof (ValueType), 1);
+                       Assert.AreEqual (1, tb.Size);
+               }
+
+               [Test]
+               [Category ("AndroidNotWorking")] // Missing Mono.CompilerServices.SymbolWriter assembly
                [ExpectedException (typeof (ArgumentException))]
                public void DuplicateTypeName () {
                        AssemblyBuilder ab = genAssembly ();
@@ -259,6 +274,7 @@ namespace MonoTests.System.Reflection.Emit
                }
 
                [Test]
+               [Category ("AndroidNotWorking")] // Missing Mono.CompilerServices.SymbolWriter assembly
                public void DuplicateSymbolDocument ()
                {
                        AssemblyBuilder ab = genAssembly ();
@@ -363,6 +379,32 @@ namespace MonoTests.System.Reflection.Emit
                        Assert.AreEqual ("Frub", mi.Name);
                }
 
+               [Test]
+               public void GetMethodTokenCrossMethodBuilders ()
+               {
+                       AssemblyBuilder ab = genAssembly ();
+                       ModuleBuilder moduleb = ab.DefineDynamicModule ("foo.dll", "foo.dll");
+
+                       TypeBuilder tb = moduleb.DefineType ("foo");
+                       MethodBuilder mb = tb.DefineMethod("Frub", MethodAttributes.Static, null, new Type[] { typeof(IntPtr) });
+                       int tok = mb.GetToken().Token;
+                       mb.SetImplementationFlags(MethodImplAttributes.NoInlining);
+                       ILGenerator ilgen = mb.GetILGenerator();
+                       ilgen.Emit(OpCodes.Ret);
+
+                       tb.CreateType ();
+
+                       var mi = (MethodInfo) moduleb.ResolveMember (tok);
+                       Assert.IsNotNull (mi);
+
+                       ModuleBuilder moduleb2 = ab.DefineDynamicModule ("foo2.dll", "foo2.dll");
+                       var tok2 = moduleb2.GetMethodToken (mi).Token;
+
+                       MethodBase mi2 = moduleb.ResolveMethod (tok2);
+                       Assert.IsNotNull (mi2);
+                       Assert.AreEqual ("Frub", mi.Name);
+               }
+
                [Test]
                public void ResolveMemberField ()
                {
@@ -686,5 +728,31 @@ namespace MonoTests.System.Reflection.Emit
                        catch (ArgumentException) {
                        }
                }
+
+               [Test]
+               public void GetMethodTokenNullParam ()
+               {
+                       AssemblyName an = genAssemblyName ();
+                       AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (an, AssemblyBuilderAccess.Run);
+                       ModuleBuilder module = ab.DefineDynamicModule ("mod");
+
+                       var method = typeof (object).GetMethod ("GetType");
+
+                       // ArgumentNullException should not occur.
+                       module.GetMethodToken (method, null);
+               }
+
+               [Test]
+               public void GetConstructorTokenNullParam ()
+               {
+                       AssemblyName an = genAssemblyName ();
+                       AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (an, AssemblyBuilderAccess.Run);
+                       ModuleBuilder module = ab.DefineDynamicModule ("mod");
+
+                       var method = typeof (object).GetConstructor (Type.EmptyTypes);
+
+                       // ArgumentNullException should not occur.
+                       module.GetConstructorToken (method, null);
+               }
        }
 }