Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAhson Ahmed Khan <ahsonkhan@users.noreply.github.com>2017-09-06 23:28:04 +0300
committerGitHub <noreply@github.com>2017-09-06 23:28:04 +0300
commitf10dc060613fe2a3a4e6181673de934781ed7e8c (patch)
treedd36e359e9ba5223a73834f0906445199c5b272c /src/System.Memory/tests/Memory/Span.cs
parent68aa52ff5387d6bfc8f15fad45945376a8d70b72 (diff)
Adding Memory, OwnedMemory, MemoryHandle, and IRetainable & Tests (#23701)
* Adding Memory, OwnedMemory, MemoryHandle, and IRetainable * Adding initial tests and fixing Memory.Empty property * Adding {RO}Memory tests and fixing XML comments based on feedback. * Removing netstandard1.0 build configuration and adding netstandard1.1. * Fixing errors in the upgrade from netstandard1.0 to netstandard1.1. * Removing Windows Phone 8 as a supported framework for System.Memory package.
Diffstat (limited to 'src/System.Memory/tests/Memory/Span.cs')
-rw-r--r--src/System.Memory/tests/Memory/Span.cs98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/System.Memory/tests/Memory/Span.cs b/src/System.Memory/tests/Memory/Span.cs
new file mode 100644
index 0000000000..881abe2d36
--- /dev/null
+++ b/src/System.Memory/tests/Memory/Span.cs
@@ -0,0 +1,98 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Buffers;
+using Xunit;
+
+namespace System.MemoryTests
+{
+ public static partial class MemoryTests
+ {
+ [Fact]
+ public static void SpanFromCtorArrayInt()
+ {
+ int[] a = { 91, 92, -93, 94 };
+ Memory<int> memory;
+
+ memory = new Memory<int>(a);
+ memory.Span.Validate(91, 92, -93, 94);
+
+ memory = new Memory<int>(a, 0, a.Length);
+ memory.Span.Validate(91, 92, -93, 94);
+
+ OwnedMemory<int> owner = new CustomMemoryForTest<int>(a);
+ owner.AsMemory.Span.Validate(91, 92, -93, 94);
+ }
+
+ [Fact]
+ public static void SpanFromCtorArrayLong()
+ {
+ long[] a = { 91, -92, 93, 94, -95 };
+ Memory<long> memory;
+
+ memory = new Memory<long>(a);
+ memory.Span.Validate(91, -92, 93, 94, -95);
+
+ memory = new Memory<long>(a, 0, a.Length);
+ memory.Span.Validate(91, -92, 93, 94, -95);
+
+ OwnedMemory<long> owner = new CustomMemoryForTest<long>(a);
+ owner.AsMemory.Span.Validate(91, -92, 93, 94, -95);
+ }
+
+ [Fact]
+ public static void SpanFromCtorArrayObject()
+ {
+ object o1 = new object();
+ object o2 = new object();
+ object[] a = { o1, o2 };
+ Memory<object> memory;
+
+ memory = new Memory<object>(a);
+ memory.Span.ValidateReferenceType(o1, o2);
+
+ memory = new Memory<object>(a, 0, a.Length);
+ memory.Span.ValidateReferenceType(o1, o2);
+
+ OwnedMemory<object> owner = new CustomMemoryForTest<object>(a);
+ owner.AsMemory.Span.ValidateReferenceType(o1, o2);
+ }
+
+ [Fact]
+ public static void SpanFromCtorArrayZeroLength()
+ {
+ int[] empty = Array.Empty<int>();
+ Memory<int> memory;
+
+ memory = new Memory<int>(empty);
+ memory.Span.Validate();
+
+ memory = new Memory<int>(empty, 0, empty.Length);
+ memory.Span.Validate();
+
+ OwnedMemory<int> owner = new CustomMemoryForTest<int>(empty);
+ owner.AsMemory.Span.Validate();
+ }
+
+ [Fact]
+ public static void SpanFromCtorArrayWrongValueType()
+ {
+ // Can pass variant array, if array type is a valuetype.
+
+ uint[] a = { 42u, 0xffffffffu };
+ int[] aAsIntArray = (int[])(object)a;
+ Memory<int> memory;
+
+ memory = new Memory<int>(aAsIntArray);
+ memory.Span.Validate(42, -1);
+
+ memory = new Memory<int>(aAsIntArray, 0, aAsIntArray.Length);
+ memory.Span.Validate(42, -1);
+
+ OwnedMemory<int> owner = new CustomMemoryForTest<int>(aAsIntArray);
+ owner.AsMemory.Span.Validate(42, -1);
+ }
+
+ }
+}