X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FTest%2FSystem%2FArrayTest.cs;h=36db33d6352b9ac3efc47122a7897ed4289ea21d;hb=410bb8a57e23a901ea47d8a74f88a20972de423d;hp=eab4c40e1434ad47d8c4fb335497cb760a647a24;hpb=90d6059c5475419ddf6e0fc4b49098158010cab0;p=mono.git diff --git a/mcs/class/corlib/Test/System/ArrayTest.cs b/mcs/class/corlib/Test/System/ArrayTest.cs index eab4c40e143..36db33d6352 100644 --- a/mcs/class/corlib/Test/System/ArrayTest.cs +++ b/mcs/class/corlib/Test/System/ArrayTest.cs @@ -543,11 +543,6 @@ public class ArrayTest } catch (ArgumentException) { errorThrown = true; } -#if TARGET_JVM // This is really implementation dependent behaviour. - catch (RankException) { - errorThrown = true; - } -#endif // TARGET_JVM Assert.IsTrue (errorThrown, "#E62"); } { @@ -707,7 +702,6 @@ public class ArrayTest } Assert.IsTrue (errorThrown, "#F03b"); } -#if !TARGET_JVM // Arrays lower bounds are not supported for TARGET_JVM { bool errorThrown = false; try { @@ -717,7 +711,6 @@ public class ArrayTest } Assert.IsTrue (errorThrown, "#F04"); } -#endif // TARGET_JVM { bool errorThrown = false; try { @@ -728,7 +721,6 @@ public class ArrayTest } Assert.IsTrue (errorThrown, "#F05"); } -#if !TARGET_JVM // CreateInstance with lower bounds not supported for TARGET_JVM { bool errorThrown = false; try { @@ -771,7 +763,6 @@ public class ArrayTest Type szarrayType = new int [10].GetType (); Assert.IsTrue (szarrayType == (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0})).GetType ()); Assert.IsTrue (szarrayType != (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {1})).GetType ()); -#endif // TARGET_JVM } [Test] @@ -788,6 +779,14 @@ public class ArrayTest Array.CreateInstance (typeof (Int32), (long[])null); } + [Test] + public void CreateInstanceVoid () + { + Assert.Throws (delegate () { + Array.CreateInstance (typeof (void), 1); + }); + } + [Test] public void TestGetEnumerator() { String[] s1 = {"this", "is", "a", "test"}; @@ -842,7 +841,6 @@ public class ArrayTest } [Test] - [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM public void TestGetEnumeratorNonZeroLowerBounds() { int[] myLengthsArray = new int[2] { 3, 5 }; int[] myBoundsArray = new int[2] { 2, 3 }; @@ -871,7 +869,6 @@ public class ArrayTest } [Test] - [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM public void TestIList_Add () { int[] myLengthsArray = new int[2] { 3, 5 }; int[] myBoundsArray = new int[2] { 2, 3 }; @@ -892,7 +889,6 @@ public class ArrayTest } [Test] - [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM public void TestIList_Insert () { int[] myLengthsArray = new int[2] { 3, 5 }; int[] myBoundsArray = new int[2] { 2, 3 }; @@ -913,7 +909,6 @@ public class ArrayTest } [Test] - [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM public void TestIList_Remove () { int[] myLengthsArray = new int[2] { 3, 5 }; int[] myBoundsArray = new int[2] { 2, 3 }; @@ -934,7 +929,6 @@ public class ArrayTest } [Test] - [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM public void TestIList_RemoveAt () { int[] myLengthsArray = new int[2] { 3, 5 }; int[] myBoundsArray = new int[2] { 2, 3 }; @@ -955,7 +949,6 @@ public class ArrayTest } [Test] - [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM public void TestIList_Contains () { int[] myLengthsArray = new int[2] { 3, 5 }; int[] myBoundsArray = new int[2] { 2, 3 }; @@ -981,7 +974,6 @@ public class ArrayTest } [Test] - [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM public void TestIList_IndexOf () { int[] myLengthsArray = new int[2] { 3, 5 }; int[] myBoundsArray = new int[2] { 2, 3 }; @@ -1011,7 +1003,6 @@ public class ArrayTest int[] myBoundArray = new int[1] { Int32.MinValue }; Array myExtremeArray=Array.CreateInstance ( typeof(String), myLengthArray, myBoundArray ); Assert.AreEqual (Int32.MaxValue, ((IList)myExtremeArray).IndexOf (42), "AD04"); - } [Test] @@ -2564,6 +2555,53 @@ public class ArrayTest Assert.AreEqual (4, indices [0]); } + [Test] + public void TestSortComparable() + { + int[] source = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + int[] expected = { 6, 5, 4, 3, 2, 1, 7, 8, 9 }; + Comp[] c = { new Comp (100), new Comp (16), new Comp (11), new Comp (9), new Comp (0), new Comp (-100) }; + IComparer comp = null; + Array.Sort (c, source, comp); + + Assert.AreEqual (expected, source); + } + + class Comp : IComparable + { + readonly int val; + + public Comp (int a) + { + val = a; + } + + int IComparable.CompareTo (object obj) + { + return val.CompareTo ((obj as Comp).val); + } + } + + [Test] + public void TestSortComparableMixed() + { + var m = new TestSortComparableMixed_Comparer (); + var arr = new object [] { 1, 2, m, 4, 5, 6, 7, 8, 9, 10 }; + + Array.Sort (arr); + + var expected = new object [] { m, 1, 2, 4, 5, 6, 7, 8, 9, 10 }; + Assert.AreEqual (expected, arr); + } + + class TestSortComparableMixed_Comparer : IComparable + { + public int CompareTo (object other) + { + return -1; + } + } + [Test] public void TestInitializeEmpty() { @@ -3178,7 +3216,6 @@ public class ArrayTest public int i, j; } -#if !TARGET_JVM // BugBUG: T[] is not yet ICollection under TARGET_JVM [Test] // From bug #80563 public void ICollectionNull () @@ -3234,7 +3271,6 @@ public class ArrayTest Assert.AreEqual (-1, test.IndexOf (null), "array with test"); } -#endif // TARGET_JVM #region Bug 80299 @@ -3349,6 +3385,30 @@ public class ArrayTest } } + [Test] + public void IEnumerator_Dispose () + { + IEnumerable e = new int[] { 1 }; + var en = e.GetEnumerator (); + Assert.IsTrue (en.MoveNext (), "#1"); + Assert.IsFalse (en.MoveNext (), "#2"); + en.Dispose (); + Assert.IsFalse (en.MoveNext (), "#3"); + } + + [Test] + public void IEnumerator_ZeroSize () + { + IEnumerable e = Array.Empty (); + var en = e.GetEnumerator (); + Assert.IsFalse (en.MoveNext (), "#1"); + + e = Array.Empty (); + en = e.GetEnumerator (); + Assert.IsFalse (en.MoveNext (), "#2"); + } + + [Test] public void ICollection_IsReadOnly() { ICollection arr = new string [10]; @@ -3467,7 +3527,6 @@ public class ArrayTest Assert.AreEqual (input, expected); } -#if NET_4_0 [Test] [ExpectedException (typeof (ArgumentException))] public void CompareToWithJaggedArray () { @@ -3634,7 +3693,49 @@ public class ArrayTest Assert.AreEqual (3, c.Counter); } -#endif + [Test] + public void EnumeratorsEquality () + { + int [] normalBase = new int [0]; + IEnumerable specialBase = new int [0]; + + var firstSpecial = specialBase.GetEnumerator (); + var secondSpecial = specialBase.GetEnumerator (); + var firstNormal = normalBase.GetEnumerator (); + var secondNormal = normalBase.GetEnumerator (); + Assert.IsFalse (object.ReferenceEquals (firstNormal, secondNormal)); + Assert.IsTrue (object.ReferenceEquals (firstSpecial, secondSpecial)); + } + + [Test] + public void JaggedArrayCtor () + { + var type = Type.GetType ("System.Object[][]"); + + ConstructorInfo ctor = null; + foreach (var c in type.GetConstructors ()) { + if (c.GetParameters ().Length == 2) + ctor = c; + } + Assert.IsNotNull (ctor); + var arr = (object[])ctor.Invoke (new object [] { 4, 10 }); + for (int i = 0; i < 4; ++i) { + Assert.IsNotNull (arr [i]); + Assert.AreEqual (10, ((object[])arr [i]).Length); + } + } + + [Test] + public unsafe void PointerArraysBoxing () + { + var x = new int*[10]; + var e = x.GetEnumerator (); + e.MoveNext (); + + Assert.Throws (() => { var _ = e.Current; }, "#1"); + Assert.Throws (() => { var _ = x.GetValue (0); }, "#2"); + Assert.Throws (() => { x.SetValue (0, 0); }, "#3"); + } } }