X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FTest%2FSystem%2FTypeTest.cs;h=9cc8ca79a413f707d27ad210899583c3fdb03456;hb=3e6c4f526499a339783cbe427e9916bbd99d7a0e;hp=d70e5fdde709fd20dcbcf54bf9fa7e338d5483bb;hpb=a5fc1343a36f9609a5bb2d7aa9142398f6887bbc;p=mono.git diff --git a/mcs/class/corlib/Test/System/TypeTest.cs b/mcs/class/corlib/Test/System/TypeTest.cs index d70e5fdde70..9cc8ca79a41 100644 --- a/mcs/class/corlib/Test/System/TypeTest.cs +++ b/mcs/class/corlib/Test/System/TypeTest.cs @@ -16,7 +16,7 @@ using System.Collections; using System.Collections.Generic; using System.IO; using System.Reflection; -#if !MONOTOUCH && !MOBILE_STATIC +#if !MONOTOUCH && !FULL_AOT_RUNTIME using System.Reflection.Emit; #endif using System.Runtime.InteropServices; @@ -261,7 +261,7 @@ namespace MonoTests.System [TestFixture] public class TypeTest { -#if !MONOTOUCH && !MOBILE_STATIC +#if !MONOTOUCH && !FULL_AOT_RUNTIME private ModuleBuilder module; #endif const string ASSEMBLY_NAME = "MonoTests.System.TypeTest"; @@ -273,7 +273,7 @@ namespace MonoTests.System { AssemblyName assemblyName = new AssemblyName (); assemblyName.Name = ASSEMBLY_NAME; -#if !MONOTOUCH && !MOBILE_STATIC +#if !MONOTOUCH && !FULL_AOT_RUNTIME var assembly = AppDomain.CurrentDomain.DefineDynamicAssembly ( assemblyName, AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ()); module = assembly.DefineDynamicModule ("module1"); @@ -3068,6 +3068,14 @@ namespace MonoTests.System object o = Array.CreateInstance (typeof (global::System.TypedReference), 1); } + [Test] + public void MakeArrayTypeLargeRank () + { + Assert.Throws (delegate () { + typeof (int).MakeArrayType (33); + }); + } + [ComVisible (true)] public class ComFoo { } @@ -3157,7 +3165,7 @@ namespace MonoTests.System } [Test] -#if MONOTOUCH || MOBILE_STATIC +#if MONOTOUCH || FULL_AOT_RUNTIME [ExpectedException (typeof (NotSupportedException))] #endif public void MakeGenericType_UserDefinedType () @@ -3174,7 +3182,7 @@ namespace MonoTests.System } [Test] -#if MONOTOUCH || MOBILE_STATIC +#if MONOTOUCH || FULL_AOT_RUNTIME [ExpectedException (typeof (NotSupportedException))] #endif public void MakeGenericType_NestedUserDefinedType () @@ -3191,7 +3199,7 @@ namespace MonoTests.System } [Test] -#if MONOTOUCH || MOBILE_STATIC +#if MONOTOUCH || FULL_AOT_RUNTIME [ExpectedException (typeof (NotSupportedException))] #endif public void TestMakeGenericType_UserDefinedType_DotNet20SP1 () @@ -3204,7 +3212,7 @@ namespace MonoTests.System } [Test] -#if MONOTOUCH || MOBILE_STATIC +#if MONOTOUCH || FULL_AOT_RUNTIME [ExpectedException (typeof (NotSupportedException))] #endif public void MakeGenericType_BadUserType () @@ -3263,6 +3271,38 @@ namespace MonoTests.System Assert.AreSame (expectedType, r, "#2"); } + public class BConstrained where Y : BConstrained { + } + + public class AConstrained : BConstrained> { + } + + [Test] // Bug https://bugzilla.xamarin.com/show_bug.cgi?id=54485 + public void MakeGenericType_GTD_Constraint () + { + // This is pretty weird, but match .NET behavior (note + // that typeof(BConstrained>) is a + // compile-time error with roslyn, but it's apparently + // an ok thing to make with reflection. + var tb = typeof (BConstrained<>); + var ta = typeof (AConstrained<>); + var result = tb.MakeGenericType (ta); + Assert.IsNotNull (result, "#1"); + // lock down the answer to match what .NET makes + Assert.IsTrue (result.IsGenericType, "#2"); + Assert.AreEqual (tb, result.GetGenericTypeDefinition (), "#3"); + var bargs = result.GetGenericArguments (); + Assert.AreEqual (1, bargs.Length, "#4"); + var arg = bargs [0]; + Assert.IsTrue (arg.IsGenericType, "#5"); + // N.B. evidently AConstrained`1 and AConstrained`1 are the same type + Assert.IsTrue (arg.IsGenericTypeDefinition, "#6"); + Assert.AreEqual (ta, arg.GetGenericTypeDefinition (), "#7"); + var aargs = arg.GetGenericArguments (); + Assert.AreEqual (1, aargs.Length, "#8"); + Assert.AreEqual (ta.GetGenericArguments () [0], aargs [0], "#9"); + } + [Test] public void EqualsUserType () { UserType2 t1 = new UserType2(null); @@ -3340,7 +3380,7 @@ namespace MonoTests.System Assert.AreEqual (t1, t2); } -#if !MONOTOUCH && !MOBILE_STATIC +#if !MONOTOUCH && !FULL_AOT_RUNTIME [Test] public void SpaceAfterComma () { string strType = "System.Collections.Generic.Dictionary`2[[System.Int32,mscorlib], [System.String,mscorlib]],mscorlib"; @@ -3348,7 +3388,7 @@ namespace MonoTests.System } #endif -#if !MONOTOUCH && !MOBILE_STATIC +#if !MONOTOUCH && !FULL_AOT_RUNTIME [Test] public void Bug506757 () { @@ -4197,6 +4237,17 @@ namespace MonoTests.System MustTLE (string.Format ("{0}ZZZZ,{1}", typeof (MyRealEnum).FullName, aqn)); } + [Test] + public void GetTypeExceptionMsg () { + string typeName = "system.int32, foo"; + try { + Type.GetType(typeName, true, false); + } catch (TypeLoadException ex) { + Assert.IsTrue (ex.Message.Contains ("system.int32")); + Assert.IsTrue (ex.Message.Contains ("foo")); + } + } + delegate void MyAction(T ag); [Test] //bug #668506 @@ -4278,7 +4329,7 @@ namespace MonoTests.System } -#if !MONOTOUCH && !MOBILE_STATIC +#if !MONOTOUCH && !FULL_AOT_RUNTIME && !MONOMAC [Test] [Category ("AndroidNotWorking")] // requires symbol writer public void FullNameGetTypeParseEscapeRoundtrip () // bug #26384 @@ -4286,7 +4337,7 @@ namespace MonoTests.System var nm = new AssemblyName ("asm"); var ab = AssemblyBuilder.DefineDynamicAssembly (nm, AssemblyBuilderAccess.Run); - var mb = ab.DefineDynamicModule("m", true); + var mb = ab.DefineDynamicModule("m", false); var tb = mb.DefineType ("NameSpace,+*&[]\\.Type,+*&[]\\", TypeAttributes.Class | TypeAttributes.Public); @@ -4324,6 +4375,24 @@ namespace MonoTests.System } #endif + + [Test] + public void GetTypeBadArity() + { + // Regression test for #46250 + try { + Type.GetType ("System.Collections.Generic.Dictionary`2[System.String]", true); + Assert.Fail ("Did not throw an exception (#1)"); + } catch (ArgumentException) { + } + + try { + Type.GetType ("System.Collections.Generic.Dictionary`2[System.String,System.Int32,System.Int64]", true); + Assert.Fail ("Did not throw an exception (#2)"); + } catch (ArgumentException) { + } + } + public abstract class Stream : IDisposable { public void Dispose ()