Skip to content

Commit

Permalink
Consolidate .netcoreapp.cs test files in System.Runtime.* (dotnet#999)
Browse files Browse the repository at this point in the history
* Consolidate .netcoreapp.cs files because System.Runtime.* projects is no longer cross-compiled
  • Loading branch information
Marusyk authored and jkotas committed Dec 19, 2019
1 parent 385121f commit 752a8d2
Show file tree
Hide file tree
Showing 16 changed files with 301 additions and 391 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace System.Runtime.InteropServices.RuntimeInformationTests
{
public partial class CheckPlatformTests
public class CheckPlatformTests
{
[Fact, PlatformSpecific(TestPlatforms.Linux)] // Tests RuntimeInformation OS platform
public void CheckLinux()
Expand All @@ -25,15 +25,16 @@ public void CheckLinux()
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("UNIX")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD));
}

[Fact, PlatformSpecific(TestPlatforms.NetBSD)] // Tests RuntimeInformation OS platform
public void CheckNetBSD()
{
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD")));

Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NetBSD")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("netbsd")));

Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("DARWIN")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("LINUX")));
Expand All @@ -43,6 +44,7 @@ public void CheckNetBSD()
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD));
}

[Fact, PlatformSpecific(TestPlatforms.OSX)] // Tests RuntimeInformation OS platform
Expand All @@ -55,27 +57,47 @@ public void CheckOSX()
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NetBSD")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("netbsd")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("osx")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("mac")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("DARWIN")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("MACOSX")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD));
}

[Fact, PlatformSpecific(TestPlatforms.Windows)] // Tests RuntimeInformation OS platform
public void CheckWindows()
{
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("WINDOWS")));

Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NetBSD")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("netbsd")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("windows")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("Windows NT")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD));
}

[Fact, PlatformSpecific(TestPlatforms.FreeBSD)] // Tests RuntimeInformation OS platform
public void CheckFreeBSD()
{
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD));
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")));

Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("DARWIN")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("LINUX")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("linux")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NetBSD")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("ubuntu")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("UNIX")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
}

[Fact]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<ItemGroup>
<Compile Include="CheckArchitectureTests.cs" />
<Compile Include="CheckPlatformTests.cs" />
<Compile Include="CheckPlatformTests.netcoreapp.cs" Condition="'$(TargetsNetCoreApp)' == 'true'" />
<Compile Include="DescriptionNameTests.cs" />
<Compile Include="$(CommonPath)Interop\Linux\cgroups\Interop.cgroups.cs">
<Link>Common\Interop\Linux\Interop.cgroups.cs</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace System.Numerics.Tests
{
public partial class ToStringTest
public class ToStringTest
{
private static bool s_noZeroOut = true;

Expand Down Expand Up @@ -1460,7 +1460,29 @@ private static void VerifyExpectedStringResult(string expectedResult, string res
}
}

static partial void VerifyTryFormat(string test, string format, IFormatProvider provider, bool expectError, string expectedResult);
static void VerifyTryFormat(string test, string format, IFormatProvider provider, bool expectError, string expectedResult)
{
try
{
BigInteger bi = BigInteger.Parse(test, provider);

char[] destination = expectedResult != null ? new char[expectedResult.Length] : Array.Empty<char>();
Assert.True(bi.TryFormat(destination, out int charsWritten, format, provider));
Assert.False(expectError);

VerifyExpectedStringResult(expectedResult, new string(destination, 0, charsWritten));

if (expectedResult.Length > 0)
{
Assert.False(bi.TryFormat(new char[expectedResult.Length - 1], out charsWritten, format, provider));
Assert.Equal(0, charsWritten);
}
}
catch (FormatException)
{
Assert.True(expectError);
}
}

private static string GetDigitSequence(int min, int max, Random random)
{
Expand Down

This file was deleted.

109 changes: 109 additions & 0 deletions src/libraries/System.Runtime.Numerics/tests/BigInteger/ToByteArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,114 @@ public void ToByteArray_FromStringTests(string str, byte[] expectedBytes)
BigInteger bi2 = new BigInteger(bytes);
Assert.Equal(bi, bi2);
}

public static IEnumerable<object[]> FromIntTests_MemberData() =>
MatrixGenerator(FromIntTests_MemberDataSeed(), false);

[Theory]
[MemberData(nameof(FromIntTests_MemberData))]
public void ToByteArray_FromIntTests(int i, bool isUnsigned, bool isBigEndian, byte[] expectedBytes)
{
BigInteger bi = new BigInteger(i);

if (i < 0 && isUnsigned)
{
Assert.Throws<OverflowException>(() => bi.ToByteArray(isUnsigned, isBigEndian));
return;
}

byte[] bytes = bi.ToByteArray(isUnsigned, isBigEndian);
Assert.Equal(expectedBytes, bytes);
BigInteger bi2 = new BigInteger(bytes, isUnsigned, isBigEndian);
Assert.Equal(bi, bi2);
}

public static IEnumerable<object[]> FromLongTests_MemberData() =>
MatrixGenerator(FromLongTests_MemberDataSeed(), false);

[Theory]
[MemberData(nameof(FromLongTests_MemberData))]
public void ToByteArray_FromLongTests(long l, bool isUnsigned, bool isBigEndian, byte[] expectedBytes)
{
BigInteger bi = new BigInteger(l);

if (l < 0 && isUnsigned)
{
Assert.Throws<OverflowException>(() => bi.ToByteArray(isUnsigned, isBigEndian));
return;
}

byte[] bytes = bi.ToByteArray(isUnsigned, isBigEndian);
Assert.Equal(expectedBytes, bytes);
BigInteger bi2 = new BigInteger(bytes, isUnsigned, isBigEndian);
Assert.Equal(bi, bi2);
}

public static IEnumerable<object[]> FromStringTests_MemberData() =>
MatrixGenerator(FromStringTests_MemberDataSeed(), true);

[Theory]
[MemberData(nameof(FromStringTests_MemberData))]
public void ToByteArray_FromStringTests(string str, bool isUnsigned, bool isBigEndian, byte[] expectedBytes)
{
BigInteger bi = BigInteger.Parse(str);

if (str[0] == '-' && isUnsigned)
{
Assert.Throws<OverflowException>(() => bi.ToByteArray(isUnsigned, isBigEndian));
return;
}

byte[] bytes = bi.ToByteArray(isUnsigned, isBigEndian);
Assert.Equal(expectedBytes, bytes);
BigInteger bi2 = new BigInteger(bytes, isUnsigned, isBigEndian);
Assert.Equal(bi, bi2);
}

private static IEnumerable<object[]> MatrixGenerator(IEnumerable<object[]> seedData, bool dataIsBigEndian)
{
foreach (object[] seed in seedData)
{
object value = seed[0];
byte[] leSignedBytes = (byte[])seed[1];
byte[] beSignedBytes = (byte[])leSignedBytes.Clone();
Array.Reverse(beSignedBytes);

if (dataIsBigEndian)
{
var tmp = leSignedBytes;
leSignedBytes = beSignedBytes;
beSignedBytes = tmp;
}

// Signed Little Endian
yield return new object[] { value, false, false, leSignedBytes };

// Signed Big Endian
yield return new object[] { value, false, true, beSignedBytes };

byte[] leUnsignedBytes;
byte[] beUnsignedBytes;

if (beSignedBytes.Length > 1 &&
beSignedBytes[0] == 0)
{
leUnsignedBytes = new Span<byte>(leSignedBytes, 0, leSignedBytes.Length - 1).ToArray();
beUnsignedBytes = new Span<byte>(beSignedBytes, 1, beSignedBytes.Length - 1).ToArray();
}
else
{
// No padding was required, the unsigned data is the same as the signed data.
leUnsignedBytes = leSignedBytes;
beUnsignedBytes = beSignedBytes;
}

// Unsigned Big Endian
yield return new object[] { value, true, true, beUnsignedBytes };

// Unsigned Little Endian
yield return new object[] { value, true, false, leUnsignedBytes };
}
}
}
}
Loading

0 comments on commit 752a8d2

Please sign in to comment.