Merge pull request #1659 from alexanderkyte/stringbuilder-referencesource
[mono.git] / mcs / class / corlib / Test / System / AttributeTest.cs
index 5aa8205e3584b7ad4a0f0c72651f974b5f9f8b1b..160b9b98df29899dc9d770d6ade3b7142c759963 100644 (file)
@@ -88,6 +88,13 @@ namespace MonoTests.System
                class MyDerivedClassNoAttribute : MyClass
                {
                }
+
+               internal class AttributeWithTypeId : Attribute
+               {
+                       public override object TypeId {
+                               get { return this; }
+                       }
+               }
        }
 
        [TestFixture]
@@ -813,6 +820,14 @@ namespace MonoTests.System
                        Assert.IsTrue (type.lastInherit, "#7");
                        Assert.AreEqual (typeof (TestFixtureAttribute), type.lastAttrType, "#8");
                }
+
+               [Test]
+               public void IsDefinedForPseudoAttribute ()
+               {                       
+                       Assert.IsTrue (Attribute.IsDefined (typeof (object), typeof(SerializableAttribute), true), "#1");
+                       Assert.IsFalse (Attribute.IsDefined (typeof (AttributeTest), typeof(SerializableAttribute), true), "#2");
+               }
+
 #if !MONOTOUCH
                [Test]
                public void GetCustomAttributeOnNewSreTypes ()
@@ -990,6 +1005,33 @@ namespace MonoTests.System
                        MyOwnCustomAttribute b1 = new MyOwnCustomAttribute (null);
                        Assert.AreNotEqual (a1.GetHashCode (), b1.GetHashCode (), "non-identical-types");
                }
+
+               [Test]
+               public void GetHashCodeWithOverriddenTypeId ()
+               {
+                       //check for not throwing stack overflow exception
+                       AttributeWithTypeId a = new AttributeWithTypeId ();
+                       a.GetHashCode ();
+               }
+
+               class ArrayAttribute : Attribute
+               {
+#pragma warning disable 414
+                       int[] array;
+#pragma warning restore
+
+                       public ArrayAttribute (int[] array)
+                       {
+                               this.array = array;
+                       }
+               }
+
+               [Test]
+               public void ArrayFieldsEquality ()
+               {
+                       Assert.IsTrue (new ArrayAttribute (new int[] { 1, 2 }).Equals (new ArrayAttribute (new int[] { 1, 2 })));
+                       Assert.IsFalse (new ArrayAttribute (new int[] { 1, 2 }).Equals (new ArrayAttribute (new int[] { 1, 1 })));
+               }
        }
 
        namespace ParamNamespace {
@@ -1027,6 +1069,12 @@ namespace MonoTests.System
                        {
                        }
                }
+
+               class Multiple {
+                       public void Bar ([Foo] [Bar] string multiple, [Bar] string bar)
+                       {
+                       }
+               }
        }
 
        [TestFixture]
@@ -1119,6 +1167,24 @@ namespace MonoTests.System
                        Assert.AreEqual ("Derived.baz", attributes [0].Data);
                }
 
+               [Test]
+               public void MultipleParameterAttributes ()
+               {
+                       var parameter = GetParameter (typeof(ParamNamespace.Multiple), "Bar", "multiple");
+                       var foo = parameter.GetCustomAttribute<ParamNamespace.FooAttribute> ();
+                       Assert.AreEqual (typeof(ParamNamespace.FooAttribute), foo.GetType ());
+                       var bar = parameter.GetCustomAttribute<ParamNamespace.BarAttribute> ();
+                       Assert.AreEqual (typeof(ParamNamespace.BarAttribute), bar.GetType ());
+               }
+
+               [Test]
+               public void MultipleParameterAttributes2 ()
+               {
+                       var parameter = GetParameter (typeof(ParamNamespace.Multiple), "Bar", "bar");
+                       var foo = parameter.GetCustomAttribute<ParamNamespace.FooAttribute> ();
+                       Assert.IsNull (foo);
+               }
+
                [AttributeUsage(AttributeTargets.Event | AttributeTargets.Method | AttributeTargets.Class)]
                public class MyCAttr : Attribute {}