Skip to content

Commit

Permalink
Adds FreeBSD support to S.RT.I.RI.
Browse files Browse the repository at this point in the history
System.Runtime.InteropServices.RuntimInformation.

Issue-URL: dotnet/corefx#1626
PR-URL: dotnet/corefx#2068


Commit migrated from dotnet/corefx@64b7f87
  • Loading branch information
Peter Jas committed Jun 16, 2015
1 parent d53d7a3 commit ffb13a5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
FreeBSD_Debug|Any CPU = FreeBSD_Debug|Any CPU
FreeBSD_Release|Any CPU = FreeBSD_Release|Any CPU
Linux_Debug|Any CPU = Linux_Debug|Any CPU
Linux_Release|Any CPU = Linux_Release|Any CPU
OSX_Debug|Any CPU = OSX_Debug|Any CPU
Expand All @@ -19,8 +21,10 @@ Global
Windows_Release|Any CPU = Windows_Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F9DF2357-81B4-4317-908E-512DA9395583}.Debug|Any CPU.ActiveCfg = Windows_Debug|Any CPU
{F9DF2357-81B4-4317-908E-512DA9395583}.Debug|Any CPU.Build.0 = Windows_Debug|Any CPU
{F9DF2357-81B4-4317-908E-512DA9395583}.FreeBSD_Debug|Any CPU.ActiveCfg = FreeBSD_Debug|Any CPU
{F9DF2357-81B4-4317-908E-512DA9395583}.FreeBSD_Debug|Any CPU.Build.0 = FreeBSD_Debug|Any CPU
{F9DF2357-81B4-4317-908E-512DA9395583}.FreeBSD_Release|Any CPU.ActiveCfg = FreeBSD_Release|Any CPU
{F9DF2357-81B4-4317-908E-512DA9395583}.FreeBSD_Release|Any CPU.Build.0 = FreeBSD_Release|Any CPU
{F9DF2357-81B4-4317-908E-512DA9395583}.Linux_Debug|Any CPU.ActiveCfg = Linux_Debug|Any CPU
{F9DF2357-81B4-4317-908E-512DA9395583}.Linux_Debug|Any CPU.Build.0 = Linux_Debug|Any CPU
{F9DF2357-81B4-4317-908E-512DA9395583}.Linux_Release|Any CPU.ActiveCfg = Linux_Release|Any CPU
Expand All @@ -29,14 +33,14 @@ Global
{F9DF2357-81B4-4317-908E-512DA9395583}.OSX_Debug|Any CPU.Build.0 = OSX_Debug|Any CPU
{F9DF2357-81B4-4317-908E-512DA9395583}.OSX_Release|Any CPU.ActiveCfg = OSX_Release|Any CPU
{F9DF2357-81B4-4317-908E-512DA9395583}.OSX_Release|Any CPU.Build.0 = OSX_Release|Any CPU
{F9DF2357-81B4-4317-908E-512DA9395583}.Release|Any CPU.ActiveCfg = Windows_Release|Any CPU
{F9DF2357-81B4-4317-908E-512DA9395583}.Release|Any CPU.Build.0 = Windows_Release|Any CPU
{F9DF2357-81B4-4317-908E-512DA9395583}.Windows_Debug|Any CPU.ActiveCfg = Windows_Debug|Any CPU
{F9DF2357-81B4-4317-908E-512DA9395583}.Windows_Debug|Any CPU.Build.0 = Windows_Debug|Any CPU
{F9DF2357-81B4-4317-908E-512DA9395583}.Windows_Release|Any CPU.ActiveCfg = Windows_Release|Any CPU
{F9DF2357-81B4-4317-908E-512DA9395583}.Windows_Release|Any CPU.Build.0 = Windows_Release|Any CPU
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.FreeBSD_Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.FreeBSD_Debug|Any CPU.Build.0 = Debug|Any CPU
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.FreeBSD_Release|Any CPU.ActiveCfg = Release|Any CPU
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.FreeBSD_Release|Any CPU.Build.0 = Release|Any CPU
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Linux_Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Linux_Debug|Any CPU.Build.0 = Debug|Any CPU
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Linux_Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -45,8 +49,6 @@ Global
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.OSX_Debug|Any CPU.Build.0 = Debug|Any CPU
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.OSX_Release|Any CPU.ActiveCfg = Release|Any CPU
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.OSX_Release|Any CPU.Build.0 = Release|Any CPU
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Release|Any CPU.Build.0 = Release|Any CPU
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Windows_Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Windows_Debug|Any CPU.Build.0 = Debug|Any CPU
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Windows_Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,37 @@ public struct OSPlatform : IEquatable<OSPlatform>
{
private readonly string _osPlatform;

private const string WindowsName = "WINDOWS";
private const string FreeBSDName = "FREEBSD";
private const string LinuxName = "LINUX";
private const string OSXName = "OSX";
private const string WindowsName = "WINDOWS";

private static readonly OSPlatform s_windows = new OSPlatform(WindowsName);
private static readonly OSPlatform s_freebsd = new OSPlatform(FreeBSDName);
private static readonly OSPlatform s_linux = new OSPlatform(LinuxName);
private static readonly OSPlatform s_osx = new OSPlatform(OSXName);
private static readonly OSPlatform s_windows = new OSPlatform(WindowsName);

public static OSPlatform Windows
public static OSPlatform Linux
{
get
{
return s_windows;
return s_linux;
}
}

public static OSPlatform Linux
public static OSPlatform OSX
{
get
{
return s_linux;
return s_osx;
}
}

public static OSPlatform OSX
public static OSPlatform Windows
{
get
{
return s_osx;
return s_windows;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace System.Runtime.InteropServices
{
public static class RuntimeInformation
{
private static OSPlatform s_freeBSD = OSPlatform.Create("FREEBSD");

public static bool IsOSPlatform(OSPlatform osPlatform)
{
return s_freeBSD == osPlatform;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,26 @@
<ProjectGuid>{F9DF2357-81B4-4317-908E-512DA9395583}</ProjectGuid>
</PropertyGroup>
<!-- Help VS understand available configurations -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'FreeBSD_Debug|AnyCPU' " />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'FreeBSD_Release|AnyCPU' " />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Linux_Debug|AnyCPU' " />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Linux_Release|AnyCPU' " />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'OSX_Debug|AnyCPU' " />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'OSX_Release|AnyCPU' " />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Windows_Debug|AnyCPU' " />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Windows_Release|AnyCPU' " />
<ItemGroup Condition=" '$(TargetsWindows)' == 'true' ">
<Compile Include="RuntimeInformation.Windows.cs" />
<ItemGroup Condition=" '$(TargetsFreeBSD)' == 'true' ">
<Compile Include="RuntimeInformation.FreeBSD.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetsLinux)' == 'true' ">
<Compile Include="RuntimeInformation.Linux.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetsOSX)' == 'true' ">
<Compile Include="RuntimeInformation.OSX.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetsWindows)' == 'true' ">
<Compile Include="RuntimeInformation.Windows.cs" />
</ItemGroup>
<ItemGroup>
<None Include="project.json" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using Xunit;

namespace System.Runtime.InteropServices.RuntimeInformationTests
{
public class CheckPlatformTests
{
[Fact, PlatformSpecific(PlatformID.Windows)]
public void CheckWindows()
{
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("WINDOWS")));
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));
}

[Fact, PlatformSpecific(PlatformID.Linux)]
public void CheckLinux()
{
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("LINUX")));

Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("linux")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("UNIX")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("DARWIN")));
Expand All @@ -34,14 +25,29 @@ public void CheckOSX()
{
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("OSX")));

Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")));
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));
}

[Fact, PlatformSpecific(PlatformID.Windows)]
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.Linux));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("windows")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("Windows NT")));
}

[Fact]
public void CheckOSPlatform()
{
Expand All @@ -56,12 +62,14 @@ public void CheckOSPlatform()
Assert.True(winObj == winProp);
Assert.True(winObj != randomObj);
Assert.True(defaultObj == conObj);

Assert.False(winObj == defaultObj);
Assert.False(winObj == randomObj);
Assert.False(winObj != winProp);

Assert.True(winObj.Equals(winProp));
Assert.True(conObj.Equals(defaultObj));

Assert.False(defaultObj.Equals(winProp));
Assert.False(winObj.Equals(null));
Assert.False(winObj.Equals("something"));
Expand Down

0 comments on commit ffb13a5

Please sign in to comment.