diff options
Diffstat (limited to 'src/System.Collections.Specialized/tests/HybridDictionary/HybridDictionary.ValuesTests.cs')
-rw-r--r-- | src/System.Collections.Specialized/tests/HybridDictionary/HybridDictionary.ValuesTests.cs | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/src/System.Collections.Specialized/tests/HybridDictionary/HybridDictionary.ValuesTests.cs b/src/System.Collections.Specialized/tests/HybridDictionary/HybridDictionary.ValuesTests.cs index 4176995088..9141fdeb55 100644 --- a/src/System.Collections.Specialized/tests/HybridDictionary/HybridDictionary.ValuesTests.cs +++ b/src/System.Collections.Specialized/tests/HybridDictionary/HybridDictionary.ValuesTests.cs @@ -51,17 +51,54 @@ namespace System.Collections.Specialized.Tests Array arr = Array.CreateInstance(typeof(object), new int[] { count }, new int[] { 2 }); Assert.Equal(1, arr.Rank); Assert.Equal(2, arr.GetLowerBound(0)); - - // A bug in Hashtable.Values.CopyTo (the underlying collection) means we don't check - // the lower bounds of the destination array for count > 10 - if (count < 10) + if (count == 0) { - Assert.Throws<ArgumentException>("array", () => collection.CopyTo(arr, 0)); + collection.CopyTo(arr, count); + Assert.Equal(0, arr.Length); + return; } + + Assert.Throws(count < 10 ? typeof(IndexOutOfRangeException) : typeof(ArgumentException), () => collection.CopyTo(arr, count)); + } + + [Theory] + [MemberData(nameof(ValidCollectionSizes))] + public override void ICollection_NonGeneric_CopyTo_IndexEqualToArrayCount_ThrowsArgumentException(int count) + { + ICollection collection = NonGenericICollectionFactory(count); + object[] array = new object[count]; + if (count > 0) + Assert.Throws(count < 10 ? typeof(IndexOutOfRangeException) : typeof(ArgumentException), () => collection.CopyTo(array, count)); else + collection.CopyTo(array, count); // does nothing since the array is empty + } + + [Theory] + [MemberData(nameof(ValidCollectionSizes))] + public override void ICollection_NonGeneric_CopyTo_NotEnoughSpaceInOffsettedArray_ThrowsArgumentException(int count) + { + if (count > 0) // Want the T array to have at least 1 element { - Assert.Throws<IndexOutOfRangeException>(() => collection.CopyTo(arr, 0)); + ICollection collection = NonGenericICollectionFactory(count); + object[] array = new object[count]; + Assert.Throws(count < 10 ? typeof(IndexOutOfRangeException) : typeof(ArgumentException), () => collection.CopyTo(array, 1)); } } + + [Theory] + [MemberData(nameof(ValidCollectionSizes))] + public override void ICollection_NonGeneric_CopyTo_IndexLargerThanArrayCount_ThrowsAnyArgumentException(int count) + { + ICollection collection = NonGenericICollectionFactory(count); + object[] array = new object[count]; + if (count == 0) + { + collection.CopyTo(array, count + 1); + Assert.Equal(count, array.Length); + return; + } + + Assert.Throws(count < 10 ? typeof(IndexOutOfRangeException) : typeof(ArgumentException), () => collection.CopyTo(array, count + 1)); + } } } |