Add Array.Copy test for very large arrays (dotnet/corefx#42373)
authorJan Kotas <jkotas@microsoft.com>
Mon, 4 Nov 2019 23:05:27 +0000 (15:05 -0800)
committerStephen Toub <stoub@microsoft.com>
Mon, 4 Nov 2019 23:05:27 +0000 (18:05 -0500)
Commit migrated from https://github.com/dotnet/corefx/commit/83a1672fd01f1191d8dd159163b1c0291a34560d

src/libraries/System.Runtime/tests/System/ArrayTests.cs

index bf0ef632697fa5a92e4451503f2b9e6079cd0007..a22635b314c75f7040752a8de62d7839227157d9 100644 (file)
@@ -1319,6 +1319,25 @@ namespace System.Tests
             Assert.Equal(expected, destinationArrayClone);
         }
 
+        [OuterLoop] // Allocates large array
+        [Fact]
+        public static void Copy_LargeMultiDimensionalArray()
+        {
+            // If this test is run in a 32-bit process, the large allocation will fail.
+            if (IntPtr.Size != sizeof(long))
+            {
+                return;
+            }
+
+            short[,] a = new short[2, 2_000_000_000];
+            a[1, 1] = 42;
+            Array.Copy(a, 1, a, Int32.MaxValue, 2);
+            Assert.Equal(42, a[1, Int32.MaxValue - 2_000_000_000]);
+
+            Array.Clear(a, Int32.MaxValue - 1, 3);
+            Assert.Equal(0, a[1, Int32.MaxValue - 2_000_000_000]);
+        }
+
         [Fact]
         public static void Copy_NullSourceArray_ThrowsArgumentNullException()
         {