Merge pull request #1659 from alexanderkyte/stringbuilder-referencesource
[mono.git] / mcs / class / corlib / Test / System / AttributeTest.cs
index f8fe8cd7a001f294a54e2f7bdd0b0aec37e917d0..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]
@@ -998,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 {
@@ -1035,6 +1069,12 @@ namespace MonoTests.System
                        {
                        }
                }
+
+               class Multiple {
+                       public void Bar ([Foo] [Bar] string multiple, [Bar] string bar)
+                       {
+                       }
+               }
        }
 
        [TestFixture]
@@ -1127,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 {}