Merge pull request #3749 from BrzVlad/fix-mips-fix
[mono.git] / mcs / class / corlib / Test / System.Reflection.Emit / TypeBuilderTest.cs
index b52e42369260330e1b5e71a86c19ea5f4e604068..ac3b1f149fa3d8e587cb8cf5a691fcc62eef46a5 100644 (file)
@@ -112,7 +112,7 @@ namespace MonoTests.System.Reflection.Emit
                                Thread.GetDomain ().DefineDynamicAssembly (
                                        assemblyName, AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
 
-                       module = assembly.DefineDynamicModule ("module1");
+                       module = assembly.DefineDynamicModule (ASSEMBLY_NAME, ASSEMBLY_NAME + ".dll");
                }
 
                static int typeIndexer = 0;
@@ -1182,6 +1182,7 @@ namespace MonoTests.System.Reflection.Emit
                }
 
                [Test]
+               [Category ("AndroidNotWorking")] // Fails with System.MethodAccessException : Method `t17:.ctor ()' is inaccessible from method `t18:.ctor ()'
                public void DefineDefaultConstructor_Parent_DefaultCtorInaccessible ()
                {
                        TypeBuilder tb;
@@ -1826,6 +1827,23 @@ namespace MonoTests.System.Reflection.Emit
                        // TODO:
                }
 
+               [Test]
+               public void NestedTypeSave () {
+                       var tb = module.DefineType (genTypeName ());
+
+                       var tbuilder = tb.DefineNestedType ("Test.CodeGen", TypeAttributes.Public | TypeAttributes.Class);
+                       var entryp = tbuilder.DefineMethod("Main", MethodAttributes.Public | MethodAttributes.Static, typeof (void), null);
+                       var ilg = entryp.GetILGenerator (128);
+                       ilg.Emit (OpCodes.Ldtoken, tb);
+                       ilg.Emit (OpCodes.Pop);
+                       ilg.Emit (OpCodes.Ret);
+
+                       tbuilder.CreateType ();
+                       tb.CreateType ();
+
+                       assembly.Save (ASSEMBLY_NAME + ".dll");
+               }
+
                [Test]
                public void DefinePInvokeMethod_Name_NullChar ()
                {
@@ -8434,6 +8452,7 @@ namespace MonoTests.System.Reflection.Emit
                }
 
                [Test]
+               [Category ("MobileNotWorking")] // Not available in the 2.1 profile
                public void TestAddDeclarativeSecurityAlreadyCreated ()
                {
                        TypeBuilder tb = module.DefineType (genTypeName ());
@@ -8452,6 +8471,7 @@ namespace MonoTests.System.Reflection.Emit
                }
 
                [Test]
+               [Category ("MobileNotWorking")] // Not available in the 2.1 profile
                public void TestAddDeclarativeSecurityNullPermissionSet ()
                {
                        TypeBuilder tb = module.DefineType (genTypeName ());
@@ -8468,6 +8488,7 @@ namespace MonoTests.System.Reflection.Emit
                }
 
                [Test]
+               [Category ("MobileNotWorking")] // Not available in the 2.1 profile
                public void TestAddDeclarativeSecurityInvalidAction ()
                {
                        TypeBuilder tb = module.DefineType (genTypeName ());
@@ -8488,6 +8509,7 @@ namespace MonoTests.System.Reflection.Emit
                }
 
                [Test]
+               [Category ("MobileNotWorking")] // Not available in the 2.1 profile
                public void TestAddDeclarativeSecurityDuplicateAction ()
                {
                        TypeBuilder tb = module.DefineType (genTypeName ());
@@ -9089,6 +9111,8 @@ namespace MonoTests.System.Reflection.Emit
 
 
                [Test]
+               // Casts don't work with unfinished types
+               [Category ("NotWorking")]
                [Category ("NotDotNet")]
                public void IsAssignableFrom_NotCreated_Array ()
                {
@@ -9741,6 +9765,33 @@ namespace MonoTests.System.Reflection.Emit
                        //Console.WriteLine (res[0]);
                }
 
+               [Test]
+               public void FieldWithInitializedDataWorksWithCompilerRuntimeHelpers2 ()
+               {
+                       TypeBuilder tb = module.DefineType ("Type1", TypeAttributes.Public);
+                       var garg = tb.DefineGenericParameters ("T") [0];
+                       FieldBuilder fb = tb.DefineInitializedData ("Foo", new byte [] {1,2,3,4}, FieldAttributes.Static|FieldAttributes.Public);
+                       tb.CreateType ();
+
+                       assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME+"2"), AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
+                       module = assembly.DefineDynamicModule ("Instance.exe");
+
+                       TypeBuilder tb2 = module.DefineType ("Type2", TypeAttributes.Public);
+                       MethodBuilder mb = tb2.DefineMethod ("Test", MethodAttributes.Public | MethodAttributes.Static, typeof (object), new Type [0]);
+                       ILGenerator il = mb.GetILGenerator ();
+
+                       il.Emit (OpCodes.Ldc_I4_1);
+                       il.Emit (OpCodes.Newarr, typeof (int));
+                       il.Emit (OpCodes.Dup);
+                       il.Emit (OpCodes.Ldtoken, fb);
+                       il.Emit (OpCodes.Call, typeof (RuntimeHelpers).GetMethod ("InitializeArray"));
+                       il.Emit (OpCodes.Ret);
+
+                       Type t = tb2.CreateType ();
+                       int[] res = (int[])t.GetMethod ("Test").Invoke (null, new object[0]);
+                       //Console.WriteLine (res[0]);
+               }
+
                public interface IDelegateFactory
                {
                        Delegate Create (Delegate del);
@@ -10878,6 +10929,7 @@ namespace MonoTests.System.Reflection.Emit
 
                //Test for #572660
         [Test]
+        [Category ("MobileNotWorking")] // Mono.CompilerServices.SymbolWriter not available in XA
         public void CircularArrayType()
         {
                        var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("Test"), AssemblyBuilderAccess.RunAndSave);
@@ -11025,6 +11077,10 @@ namespace MonoTests.System.Reflection.Emit
                }
 
                [Test]
+               [Category ("AndroidNotWorking")]
+               // It's not possible to save the assembly in the current directory on Android and AssemblyBuilder.DefineDynamicModule will not
+               // allow a full path to the assembly to be passed to it. Trying to change the current directory before saving will not work either as
+               // FileStream will then prepend / to the file name (perhaps it's another bug) and write access to the filesystem root is, obviously, denied
                public void Ldfld_Encoding_10122 () {
                        Build2<Example<int>> ();
                }