2008-09-08 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mcs / class / corlib / Test / System / ArrayTest.cs
index 1a92d87708247a4ace5a76d5da6dcda79bb2232c..a18f160201bb95edc5574edd1cf9b18216c93a61 100644 (file)
@@ -42,6 +42,15 @@ namespace MonoTests.System
                public string s;
                public string a;
        }
+       
+       class DataEqual
+       {
+               public override bool Equals (object obj)
+               {
+                       return true;
+               }
+       }
+               
        //End Auxiliary Things
 
 [TestFixture]
@@ -436,6 +445,17 @@ public class ArrayTest : Assertion
                Assert("#E38", copy[3] != orig[3]);
        }
 
+       [Test]
+       [ExpectedException (typeof (InvalidCastException))]
+       public void Copy_InvalidCast () {
+               object[] arr1 = new object [10];
+               Type[] arr2 = new Type [10];
+
+               arr1 [0] = new object ();
+
+               Array.Copy (arr1, 0, arr2, 0, 10);
+       }
+
        [Test]
        public void TestCopyTo() {
                {
@@ -1356,6 +1376,16 @@ public class ArrayTest : Assertion
                AssertEquals("#J50", 3, Array.IndexOf(s1, "a", 1, 3));
        }
        
+       [Test]
+       public void TestIndexOf_CustomEqual ()
+       {
+               DataEqual[] test = new DataEqual [] { new DataEqual () };
+               AssertEquals (0, Array.IndexOf (test, "asdfas", 0));
+               
+               IList array = (IList)test;
+               AssertEquals (0, array.IndexOf ("asdfas"));
+       }
+       
        [Test]
        public void TestLastIndexOf1() {
                {
@@ -1384,6 +1414,8 @@ public class ArrayTest : Assertion
                AssertEquals("#K05", 0, Array.LastIndexOf(s1, "this"));
                AssertEquals("#K06", 4, Array.LastIndexOf(s1, "test"));
                AssertEquals("#K07", 3, Array.LastIndexOf(s1, "a"));
+
+               AssertEquals (-1, Array.LastIndexOf (new String [0], "foo"));
        }
 
        [Test]
@@ -1478,11 +1510,20 @@ public class ArrayTest : Assertion
        }
 
        [Test]
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]
        public void TestLastIndexOf4 ()
        {
                short [] a = new short [] { 19, 238, 317, 6, 565, 0, -52, 60, -563, 753, 238, 238};
-               Array.LastIndexOf (a, 16, -1);
+               try {
+                       Array.LastIndexOf (a, (object)16, -1);
+                       NUnit.Framework.Assert.Fail ("#1");
+               } catch (ArgumentOutOfRangeException) { }
+               
+#if NET_2_0            
+               try {
+                       Array.LastIndexOf<short> (a, 16, -1);
+                       NUnit.Framework.Assert.Fail ("#2");
+               } catch (ArgumentOutOfRangeException) { }
+#endif         
        }
 
        [Test]