AssertEquals("#F13(" + i + ")", src[i], array.GetValue(i+5));
}
+ // Test that a 1 dimensional array with 0 lower bound is the
+ // same as an szarray
+ Type szarrayType = new int [10].GetType ();
+ Assert (szarrayType == (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0})).GetType ());
+ Assert (szarrayType != (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {1})).GetType ());
}
[Test]
Array a = Array.CreateInstance (typeof (Int32), (int[])null);
}
-#if NET_1_1
[Test]
- [ExpectedException (typeof (NullReferenceException))]
+#if NET_2_0
+ [ExpectedException (typeof (ArgumentNullException))]
+#else
+ [ExpectedException (typeof (NullReferenceException))]
+#endif
public void TestCreateInstance2b ()
{
Array a = Array.CreateInstance (typeof (Int32), (long[])null);
}
-#endif
[Test]
public void TestGetEnumerator() {
}
}
-#if NET_1_1
[Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void TestGetValueLongArray() {
+#if NET_2_0
+ [ExpectedException (typeof (ArgumentNullException))]
+#else
+ [ExpectedException (typeof (NullReferenceException))]
+#endif
+ public void TestGetValueLongArray ()
+ {
char[] c = new Char[2];
c.GetValue((long [])null);
}
-#endif
[Test]
public void TestGetValueN() {
}
}
-#if NET_1_1
[Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void TestSetValueLongArray() {
+#if NET_2_0
+ [ExpectedException (typeof (ArgumentNullException))]
+#else
+ [ExpectedException (typeof (NullReferenceException))]
+#endif
+ public void TestSetValueLongArray ()
+ {
char[] c = new Char[2];
c.SetValue("buh", (long [])null);
}
-#endif
-
[Test]
public void TestSetValueN() {
AssertEquals (1, Array.BinarySearch (x, 'b'));
}
-#if NET_2_0
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void AsReadOnly_NullArray ()
- {
- Array.AsReadOnly <int> (null);
- }
+ class Comparer: IComparer {
- [Test]
- [ExpectedException (typeof (NotSupportedException))]
- public void ReadOnly_Add ()
- {
- Array.AsReadOnly (new int [10]).Add (5);
- }
+ private bool called = false;
+ public bool Called {
+ get {
+ bool result = called;
+ called = false;
+ return called;
+ }
+ }
+
+ public int Compare (object x, object y)
+ {
+ called = true;
+ return 0;
+ }
+ }
[Test]
- [ExpectedException (typeof (NotSupportedException))]
- public void ReadOnly_Remove ()
+ public void BinarySearch1_EmptyList ()
{
- Array.AsReadOnly (new int [10]).Remove (5);
+ int[] array = new int[0];
+ AssertEquals ("BinarySearch", - 1, Array.BinarySearch (array, 0));
}
[Test]
- [ExpectedException (typeof (NotSupportedException))]
- public void ReadOnly_Clear ()
+ public void BinarySearch2_EmptyList ()
{
- Array.AsReadOnly (new int [10]).Clear ();
+ int[] array = new int[0];
+ AssertEquals ("BinarySearch", -1, Array.BinarySearch (array, 0, 0, 0));
}
[Test]
- [ExpectedException (typeof (NotSupportedException))]
- public void ReadOnly_Insert ()
+ public void BinarySearch3_EmptyList ()
{
- Array.AsReadOnly (new int [10]).Insert (0, 5);
+ Comparer comparer = new Comparer ();
+ int[] array = new int[0];
+ AssertEquals ("BinarySearch", -1, Array.BinarySearch (array, 0, comparer));
+ // bug 77030 - the comparer isn't called for an empty array/list
+ Assert ("Called", !comparer.Called);
}
[Test]
- [ExpectedException (typeof (NotSupportedException))]
- public void ReadOnly_RemoveAt ()
+ public void BinarySearch4_EmptyList ()
{
- Array.AsReadOnly (new int [10]).RemoveAt (5);
+ Comparer comparer = new Comparer ();
+ int[] array = new int[0];
+ AssertEquals ("BinarySearch", -1, Array.BinarySearch (array, 0, 0, comparer));
+ // bug 77030 - the comparer isn't called for an empty array/list
+ Assert ("Called", !comparer.Called);
}
+#if NET_2_0
[Test]
- public void ReadOnly_IsReadOnly ()
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void AsReadOnly_NullArray ()
{
- Assert (Array.AsReadOnly (new int [10]).IsReadOnly);
+ Array.AsReadOnly <int> (null);
}
[Test]
Array.Resize (ref arr, 10);
AssertEquals (arr.Length, 10);
}
+
+ [Test]
+ public void Test_ContainsAndIndexOf_EquatableItem ()
+ {
+ EquatableClass[] list = new EquatableClass[] {new EquatableClass (0), new EquatableClass (1), new EquatableClass (0)};
+
+ AssertEquals ("#0", 0, Array.IndexOf<EquatableClass> (list, list[0]));
+ AssertEquals ("#1", 0, Array.IndexOf<EquatableClass> (list, new EquatableClass (0)));
+ AssertEquals ("#2", 2, Array.LastIndexOf<EquatableClass> (list, list[0]));
+ AssertEquals ("#3", 2, Array.LastIndexOf<EquatableClass> (list, new EquatableClass (0)));
+ }
+
+ public class EquatableClass : IEquatable<EquatableClass>
+ {
+ int _x;
+ public EquatableClass (int x)
+ {
+ _x = x;
+ }
+
+ public bool Equals (EquatableClass other)
+ {
+ return this._x == other._x;
+ }
+
+ }
+
+ [Test]
+ // From bug #80563
+ public void ICollectionNull ()
+ {
+ ICollection<object> test;
+
+ test = new List<object>();
+ AssertEquals ("list<o>", test.Contains (null), false);
+
+ test = new object[] {};
+ AssertEquals ("empty array", test.Contains (null), false);
+
+ test = new object[] {null};
+ AssertEquals ("array with null", test.Contains (null), true);
+
+ test = new List<object>(test);
+ AssertEquals ("List<object> with test", test.Contains (null), true);
+
+ test = new object[] {new object()};
+ AssertEquals ("array with object", test.Contains (null), false);
+
+ test = new List<object>(test);
+ AssertEquals ("array with test", test.Contains (null), false);
+ }
#endif
+
+ #region Bug 80299
+
+ enum ByteEnum : byte {}
+ enum IntEnum : int {}
+
+ [Test]
+ public void TestByteEnumArrayToByteArray ()
+ {
+ ByteEnum[] a = new ByteEnum[] {(ByteEnum) 1, (ByteEnum) 2};
+ byte[] b = new byte[a.Length];
+ a.CopyTo (b, 0);
+ }
+
+ [Test]
+ public void TestByteEnumArrayToIntArray ()
+ {
+ ByteEnum[] a = new ByteEnum[] {(ByteEnum) 1, (ByteEnum) 2};
+ int[] b = new int[a.Length];
+ a.CopyTo (b, 0);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArrayTypeMismatchException))]
+ public void TestIntEnumArrayToByteArray ()
+ {
+ IntEnum[] a = new IntEnum[] {(IntEnum) 1, (IntEnum) 2};
+ byte[] b = new byte[a.Length];
+ a.CopyTo (b, 0);
+ }
+
+ [Test]
+ public void TestIntEnumArrayToIntArray ()
+ {
+ IntEnum[] a = new IntEnum[] {(IntEnum) 1, (IntEnum) 2};
+ int[] b = new int[a.Length];
+ a.CopyTo (b, 0);
+ }
+
+ #endregion
}
}