Merge pull request #901 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / corlib / Test / System / TypeTest.cs
index 2a2e54f3ac2e7b9a2baf664985e498787186b656..6d5431e082d30b8533e4c1a318ee66c3d2d66236 100644 (file)
@@ -141,6 +141,8 @@ namespace MonoTests.System
                        get { return 1; }
                        set { }
                }
+
+               public event EventHandler E;
        }
 
        class Derived1 : Base1
@@ -156,6 +158,8 @@ namespace MonoTests.System
                        get { return 1; }
                        set { }
                }
+
+               public event Action E;
        }
 
        public class Foo<T>
@@ -399,6 +403,14 @@ namespace MonoTests.System
                        Assert.AreEqual (1, typeof (Derived1).GetProperties ().Length, "#03");
                }
 
+               [Test]
+               public void GetEvents ()
+               {
+                       // Test hide-by-name
+                       Assert.AreEqual (1, typeof (Derived2).GetEvents ().Length);
+                       Assert.AreEqual (typeof (Derived2), typeof (Derived2).GetEvents ()[0].DeclaringType);
+               }
+
                [Test]
                public void GetProperties ()
                {
@@ -1701,6 +1713,45 @@ PublicKeyToken=b77a5c561934e089"));
                        Type t = Type.GetType ("System.String[*]");
                        Assert.AreEqual ("System.String[*]", t.ToString ());
                }
+
+#if MONOTOUCH
+               // feature not available when compiled under FULL_AOT_RUNTIME
+               [ExpectedException (typeof (NotImplementedException))]
+#endif
+               [Test]
+               public void TypeFromCLSID ()
+               {
+                       Guid CLSID_ShellDesktop = new Guid("00021400-0000-0000-c000-000000000046");
+                       Guid CLSID_Bogus = new Guid("1ea9d7a9-f7ab-443b-b486-30d285b21f1b");
+
+                       Type t1 = Type.GetTypeFromCLSID (CLSID_ShellDesktop);
+
+                       Type t2 = Type.GetTypeFromCLSID (CLSID_Bogus);
+
+                       Assert.AreEqual (t1.FullName, "System.__ComObject");
+
+                       if (Environment.OSVersion.Platform == PlatformID.Win32Windows ||
+                               Environment.OSVersion.Platform == PlatformID.Win32NT)
+                               Activator.CreateInstance(t1);
+
+                       Assert.AreEqual (t2.FullName, "System.__ComObject");
+
+                       Assert.AreNotEqual (t1, t2);
+               }
+
+               [Test]
+               [Category("NotWorking")] // Mono throws TargetInvokationException
+               [ExpectedException("System.Runtime.InteropServices.COMException")]
+               public void TypeFromCLSIDBogus ()
+               {
+                       Guid CLSID_Bogus = new Guid("1ea9d7a9-f7ab-443b-b486-30d285b21f1b");
+                       Type t = Type.GetTypeFromCLSID (CLSID_Bogus);
+                       if (Environment.OSVersion.Platform == PlatformID.Win32Windows ||
+                               Environment.OSVersion.Platform == PlatformID.Win32NT)
+                               Activator.CreateInstance(t);
+                       else
+                               throw new COMException ();
+               }
                
                [Test]
                public void ExerciseFilterName ()
@@ -1760,6 +1811,13 @@ PublicKeyToken=b77a5c561934e089"));
                        Assert.AreEqual (0, mi.Length);
                }
 
+               [Test]
+               [ExpectedException (typeof (InvalidFilterCriteriaException))]
+               public void FilterAttribute_Invalid ()
+               {
+                       Type.FilterAttribute (MethodBase.GetCurrentMethod (), (byte) 1);
+               }
+
                [Test]
                public void GenericParameterMemberType ()
                {
@@ -2466,6 +2524,47 @@ PublicKeyToken=b77a5c561934e089"));
                        Assert.IsFalse (typeof (bug82431B4).IsDefined (typeof (NotInheritAttribute), true), "#K4");
                }
 
+               class Bug13767Attribute : Attribute
+               {
+                       public object[] field;
+
+                       public Bug13767Attribute (params object[] args)
+                       {
+                               field = args;
+                       }
+               }
+
+               public enum Bug13767Enum
+               {
+                       Value0,
+                       Value1,
+               }
+
+               [Bug13767("Demo", new[] { Bug13767Enum.Value1, Bug13767Enum.Value0 })]
+               public void Bug13767Method(string attributeName, Bug13767Enum[]options)
+               {
+
+               }
+
+               [Test] //Bug 13767
+               public void CustomAttributeWithNestedArrayOfEnum ()
+               {
+                       var m = GetType ().GetMethod ("Bug13767Method");
+
+                       var attr = m.GetCustomAttributes (false);
+                       Assert.AreEqual (1, attr.Length, "#1");
+
+                       var tc = (Bug13767Attribute)attr[0];
+                       Assert.AreEqual (2, tc.field.Length, "#2");
+                       Assert.AreEqual ("Demo", tc.field[0], "#3");
+                       Assert.IsNotNull (tc.field[1], "#4");
+
+                       var arr = (Bug13767Enum[])tc.field [1];
+                       Assert.AreEqual (2, arr.Length, "#5");
+                       Assert.AreEqual (Bug13767Enum.Value1, arr [0], "#6");
+                       Assert.AreEqual (Bug13767Enum.Value0, arr [1], "#7");
+               }
+
                [Test] // GetType (String)
                public void GetType1_TypeName_Null ()
                {
@@ -3937,6 +4036,25 @@ PublicKeyToken=b77a5c561934e089"));
                }
 #endif
 
+               [Test]
+               public void GetTypeParseGenericCorrectly () { //Bug #15124
+                       Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1"), typeof (Foo<>), "#1");
+                       Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[System.Int32]"), typeof (Foo<int>), "#2");
+                       Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[[System.Int32]]"), typeof (Foo<int>), "#3");
+                       Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[System.Int32][]"), typeof (Foo<int>[]), "#4");
+                       Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[][System.Int32]"), null, "#5");
+                       Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[System.Int32][,]"), typeof (Foo<int>[,]), "#6");
+                       Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[]"), typeof (Foo<>).MakeArrayType(), "#7");
+                       Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[,]"), typeof (Foo<>).MakeArrayType (2), "#8");
+                       Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[][]"), typeof (Foo<>).MakeArrayType ().MakeArrayType (), "#9");
+                       Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1["), null, "#10");
+                       Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[["), null, "#11");
+                       Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[[]"), null, "#12");
+                       Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[,"), null, "#13");
+                       Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[*"), null, "#14");
+                       Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[System.Int32"), null, "#15");
+               }
+
                public abstract class Stream : IDisposable
                {
                        public void Dispose ()