diff options
author | nietras <nietras@users.noreply.github.com> | 2016-10-22 04:39:59 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2016-10-22 04:39:59 +0300 |
commit | b1937cb6f0bc01f11be2fc363643a8af558d8dcb (patch) | |
tree | b88ddb07b42740efc6e87e27881adbbd288d477a /src/System.Runtime.CompilerServices.Unsafe/tests | |
parent | 0a1ca15ee8d854b88aefb89393162432cca3443a (diff) |
S.R.CS.Unsafe: Add 'IntPtr ByteOffset<T>(ref T origin, ref T target)' (#12895)
Diffstat (limited to 'src/System.Runtime.CompilerServices.Unsafe/tests')
-rw-r--r-- | src/System.Runtime.CompilerServices.Unsafe/tests/UnsafeTests.cs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/System.Runtime.CompilerServices.Unsafe/tests/UnsafeTests.cs b/src/System.Runtime.CompilerServices.Unsafe/tests/UnsafeTests.cs index 2a90b63525..1385fbe442 100644 --- a/src/System.Runtime.CompilerServices.Unsafe/tests/UnsafeTests.cs +++ b/src/System.Runtime.CompilerServices.Unsafe/tests/UnsafeTests.cs @@ -387,6 +387,37 @@ namespace System.Runtime.CompilerServices Assert.IsType(typeof(Object), Unsafe.As<string>(o)); } + [Fact] + public static void ByteOffsetArray() + { + var a = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }; + + Assert.Equal(new IntPtr(0), Unsafe.ByteOffset(ref a[0], ref a[0])); + Assert.Equal(new IntPtr(1), Unsafe.ByteOffset(ref a[0], ref a[1])); + Assert.Equal(new IntPtr(-1), Unsafe.ByteOffset(ref a[1], ref a[0])); + Assert.Equal(new IntPtr(2), Unsafe.ByteOffset(ref a[0], ref a[2])); + Assert.Equal(new IntPtr(-2), Unsafe.ByteOffset(ref a[2], ref a[0])); + Assert.Equal(new IntPtr(3), Unsafe.ByteOffset(ref a[0], ref a[3])); + Assert.Equal(new IntPtr(4), Unsafe.ByteOffset(ref a[0], ref a[4])); + Assert.Equal(new IntPtr(5), Unsafe.ByteOffset(ref a[0], ref a[5])); + Assert.Equal(new IntPtr(6), Unsafe.ByteOffset(ref a[0], ref a[6])); + Assert.Equal(new IntPtr(7), Unsafe.ByteOffset(ref a[0], ref a[7])); + } + + [Fact] + public static void ByteOffsetStackByte4() + { + var byte4 = new Byte4(); + + Assert.Equal(new IntPtr(0), Unsafe.ByteOffset(ref byte4.B0, ref byte4.B0)); + Assert.Equal(new IntPtr(1), Unsafe.ByteOffset(ref byte4.B0, ref byte4.B1)); + Assert.Equal(new IntPtr(-1), Unsafe.ByteOffset(ref byte4.B1, ref byte4.B0)); + Assert.Equal(new IntPtr(2), Unsafe.ByteOffset(ref byte4.B0, ref byte4.B2)); + Assert.Equal(new IntPtr(-2), Unsafe.ByteOffset(ref byte4.B2, ref byte4.B0)); + Assert.Equal(new IntPtr(3), Unsafe.ByteOffset(ref byte4.B0, ref byte4.B3)); + Assert.Equal(new IntPtr(-3), Unsafe.ByteOffset(ref byte4.B3, ref byte4.B0)); + } + // Active Issue: https://github.com/dotnet/coreclr/issues/6505 // These tests require C# compiler with support for ref returns and locals #if false |