diff options
author | Jose Perez Rodriguez <joperezr@microsoft.com> | 2016-08-18 00:52:33 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-18 00:52:33 +0300 |
commit | 56ddab3bc5e4d1d3487ebdb3ce60aea8ba9d8598 (patch) | |
tree | 0a64f56cc4bcdeefe9e140fc8b5b7b4c8819a801 /src/System.Runtime.CompilerServices.Unsafe/tests | |
parent | 5ef30c10f91dd356ff553f3529278f4427cf9252 (diff) | |
parent | fdc7fee28235a57411590d9d79183a3b0e6b6b88 (diff) |
Merge pull request #10929 from joperezr/MergeMaster
Merge branch master -> dev/api
Diffstat (limited to 'src/System.Runtime.CompilerServices.Unsafe/tests')
-rw-r--r-- | src/System.Runtime.CompilerServices.Unsafe/tests/UnsafeTests.cs | 69 | ||||
-rw-r--r-- | src/System.Runtime.CompilerServices.Unsafe/tests/project.json | 4 |
2 files changed, 71 insertions, 2 deletions
diff --git a/src/System.Runtime.CompilerServices.Unsafe/tests/UnsafeTests.cs b/src/System.Runtime.CompilerServices.Unsafe/tests/UnsafeTests.cs index 4f4f4af979..2cca63b8d6 100644 --- a/src/System.Runtime.CompilerServices.Unsafe/tests/UnsafeTests.cs +++ b/src/System.Runtime.CompilerServices.Unsafe/tests/UnsafeTests.cs @@ -235,6 +235,75 @@ namespace System.Runtime.CompilerServices object o = new Object(); Assert.IsType(typeof(Object), Unsafe.As<string>(o)); } + + // Active Issue: https://github.com/dotnet/coreclr/issues/6505 + // These tests require C# compiler with support for ref returns and locals +#if false + [Fact] + public unsafe static void AsRef() + { + byte[] b = new byte[4] { 0x42, 0x42, 0x42, 0x42 }; + fixed (byte * p = b) + { + ref int r = ref Unsafe.AsRef<int>(p); + Assert.Equal(0x42424242, r); + + r = 0x0EF00EF0; + Assert.Equal(0xFE, b[0] | b[1] | b[2] | b[3]); + } + } + + [Fact] + public static void RefAs() + { + byte[] b = new byte[4] { 0x42, 0x42, 0x42, 0x42 }; + + ref int r = ref Unsafe.As<byte, int>(ref b[0]); + Assert.Equal(0x42424242, r); + + r = 0x0EF00EF0; + Assert.Equal(0xFE, b[0] | b[1] | b[2] | b[3]); + } + + [Fact] + public static void RefAdd() + { + int[] a = new int[] { 0x123, 0x234, 0x345, 0x456 }; + + ref int r1 = ref Unsafe.Add(ref a[0], 1); + Assert.Equal(0x234, r1); + + ref int r2 = ref Unsafe.Add(ref r1, 2); + Assert.Equal(0x456, r2); + + ref int r3 = ref Unsafe.Add(ref r2, -3); + Assert.Equal(0x123, r3); + } + + [Fact] + public static void RefSubtract() + { + string[] a = new string[] { "abc", "def", "ghi", "jkl" }; + + ref string r1 = ref Unsafe.Subtract(ref a[0], -2); + Assert.Equal("ghi", r1); + + ref string r2 = ref Unsafe.Subtract(ref r1, -1); + Assert.Equal("jkl", r2); + + ref string r3 = ref Unsafe.Subtract(ref r2, 3); + Assert.Equal("abc", r3); + } + + [Fact] + public static void RefAreSame() + { + long[] a = new long[2]; + + Assert.True(Unsafe.AreSame(ref a[0], ref a[0])); + Assert.False(Unsafe.AreSame(ref a[0], ref a[1])); + } +#endif } [StructLayout(LayoutKind.Explicit)] diff --git a/src/System.Runtime.CompilerServices.Unsafe/tests/project.json b/src/System.Runtime.CompilerServices.Unsafe/tests/project.json index 7af373cd7f..d2bdc69e72 100644 --- a/src/System.Runtime.CompilerServices.Unsafe/tests/project.json +++ b/src/System.Runtime.CompilerServices.Unsafe/tests/project.json @@ -6,8 +6,8 @@ "target": "project", "exclude": "compile" }, - "Microsoft.xunit.netcore.extensions": "1.0.0-prerelease-00508-01", - "Microsoft.DotNet.BuildTools.TestSuite": "1.0.0-prerelease-00520-02" + "Microsoft.xunit.netcore.extensions": "1.0.0-prerelease-00704-03", + "Microsoft.DotNet.BuildTools.TestSuite": "1.0.0-prerelease-00704-03" }, "frameworks": { "netstandard1.3": {} |