Add tests for InternalArray::GetIndex
authorMarek Safar <marek.safar@gmail.com>
Wed, 30 Nov 2011 14:17:01 +0000 (14:17 +0000)
committerMarek Safar <marek.safar@gmail.com>
Wed, 30 Nov 2011 14:17:01 +0000 (14:17 +0000)
mcs/class/corlib/System/Array.cs
mcs/class/corlib/Test/System/ArrayTest.cs

index 07f38da735f4b648d88740ce951bd789cc1442e7..8231de820386b1f961f767fa033cfa80c7254612 100644 (file)
@@ -160,11 +160,8 @@ namespace System
                                if (item == null){
                                        if (value == null)
                                                return i + this.GetLowerBound (0);
-                                       else {
-                                               unchecked {
-                                                       return this.GetLowerBound (0) - 1;
-                                               }
-                                       }
+
+                                       continue;
                                }
                                if (value.Equals (item))
                                        // array index may not be zero-based.
index 76917b363ed027c74a47534fc245efbe06c5ee22..f53eb6dd25d062f8fed18b780db13b1e027bd2dd 100644 (file)
@@ -12,10 +12,7 @@ using System;
 using System.Collections;
 using System.Globalization;
 using System.Reflection;
-
-#if NET_2_0
 using System.Collections.Generic;
-#endif
 
 namespace MonoTests.System
 {
@@ -746,11 +743,7 @@ public class ArrayTest
        }
 
        [Test]
-#if NET_2_0
        [ExpectedException (typeof (ArgumentNullException))]
-#else
-       [ExpectedException (typeof (NullReferenceException))]
-#endif
        public void TestCreateInstance2b ()
        {
                Array.CreateInstance (typeof (Int32), (long[])null);
@@ -1211,11 +1204,7 @@ public class ArrayTest
        }
 
        [Test]
-#if NET_2_0
        [ExpectedException (typeof (ArgumentNullException))]
-#else
-       [ExpectedException (typeof (NullReferenceException))]
-#endif
        public void TestGetValueLongArray ()
        {
                char[] c = new Char[2];
@@ -1544,12 +1533,10 @@ public class ArrayTest
                        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]
@@ -1868,11 +1855,7 @@ public class ArrayTest
        }
 
        [Test]
-#if NET_2_0
        [ExpectedException (typeof (ArgumentNullException))]
-#else
-       [ExpectedException (typeof (NullReferenceException))]
-#endif
        public void TestSetValueLongArray ()
        {
                char[] c = new Char[2];
@@ -2830,7 +2813,6 @@ public class ArrayTest
                Assert.IsTrue (!comparer.Called, "Called");
        }
 
-#if NET_2_0
        [Test]
        [ExpectedException (typeof (ArgumentNullException))]
        public void AsReadOnly_NullArray ()
@@ -3025,8 +3007,35 @@ public class ArrayTest
                test = new List<object>(test);
                Assert.AreEqual (test.Contains (null), false, "array with test");
        }
+       
+       [Test]
+       public void IListNull ()
+       {
+               IList<object> test;
+               
+               test = new List<object>();
+               Assert.AreEqual (-1, test.IndexOf (null), "list<o>");
+
+               test = new object[] {};
+               Assert.AreEqual (-1, test.IndexOf (null), "empty array");
+
+               test = new object[] {null};
+               Assert.AreEqual (0, test.IndexOf (null), "array with null");
+
+               test = new object[] { 1, null};
+               Assert.AreEqual (1, test.IndexOf (null), "array with last null");
+               
+               test = new List<object>(test);
+               Assert.AreEqual (1, test.IndexOf (null), "List<object> with test");
+               
+               test = new object[] {new object()};
+               Assert.AreEqual (-1, test.IndexOf (null), "array with object");
+
+               test = new List<object>(test);
+               Assert.AreEqual (-1, test.IndexOf (null), "array with test");
+       }
+       
 #endif // TARGET_JVM
-#endif
 
        #region Bug 80299
 
@@ -3068,7 +3077,6 @@ public class ArrayTest
 
        #endregion
 
-#if NET_2_0
        [Test] // bug #322248
        public void IEnumerator_Reset ()
        {
@@ -3147,7 +3155,6 @@ public class ArrayTest
 
                Assert.IsTrue (arr.IsReadOnly);
        }
-#endif
 
        [Test]
        [ExpectedException (typeof (NotSupportedException))]