Add OSPlatform entries for iOS/tvOS/watchOS/Android (#36704)
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Fri, 10 Jul 2020 09:26:54 +0000 (11:26 +0200)
committerGitHub <noreply@github.com>
Fri, 10 Jul 2020 09:26:54 +0000 (11:26 +0200)
* Add OSPlatform entries for iOS/tvOS/watchOS/Android

Implements the non-controversial new OSPlatform members from https://github.com/dotnet/runtime/issues/33331

* Add tests for new OSPlatform entries

src/libraries/System.Runtime.InteropServices.RuntimeInformation/ref/System.Runtime.InteropServices.RuntimeInformation.cs
src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/OSPlatform.cs
src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs

index aae34f0..92264d9 100644 (file)
@@ -18,10 +18,14 @@ namespace System.Runtime.InteropServices
     {
         private readonly object _dummy;
         private readonly int _dummyPrimitive;
+        public static System.Runtime.InteropServices.OSPlatform Android { get { throw null; } }
         public static System.Runtime.InteropServices.OSPlatform Browser { get { throw null; } }
         public static System.Runtime.InteropServices.OSPlatform FreeBSD { get { throw null; } }
+        public static System.Runtime.InteropServices.OSPlatform iOS { get { throw null; } }
         public static System.Runtime.InteropServices.OSPlatform Linux { get { throw null; } }
         public static System.Runtime.InteropServices.OSPlatform OSX { get { throw null; } }
+        public static System.Runtime.InteropServices.OSPlatform tvOS { get { throw null; } }
+        public static System.Runtime.InteropServices.OSPlatform watchOS { get { throw null; } }
         public static System.Runtime.InteropServices.OSPlatform Windows { get { throw null; } }
         public static System.Runtime.InteropServices.OSPlatform Create(string osPlatform) { throw null; }
         public override bool Equals(object? obj) { throw null; }
@@ -33,11 +37,11 @@ namespace System.Runtime.InteropServices
     }
     public static partial class RuntimeInformation
     {
-        public static string RuntimeIdentifier { get { throw null; } }
         public static string FrameworkDescription { get { throw null; } }
         public static System.Runtime.InteropServices.Architecture OSArchitecture { get { throw null; } }
         public static string OSDescription { get { throw null; } }
         public static System.Runtime.InteropServices.Architecture ProcessArchitecture { get { throw null; } }
+        public static string RuntimeIdentifier { get { throw null; } }
         public static bool IsOSPlatform(System.Runtime.InteropServices.OSPlatform osPlatform) { throw null; }
     }
 }
index b4e860d..39f956e 100644 (file)
@@ -7,6 +7,8 @@ namespace System.Runtime.InteropServices
     {
         private readonly string _osPlatform;
 
+        public static OSPlatform Android { get; } = new OSPlatform("ANDROID");
+
         public static OSPlatform Browser { get; } = new OSPlatform("BROWSER");
 
         public static OSPlatform FreeBSD { get; } = new OSPlatform("FREEBSD");
@@ -15,6 +17,12 @@ namespace System.Runtime.InteropServices
 
         public static OSPlatform OSX { get; } = new OSPlatform("OSX");
 
+        public static OSPlatform iOS { get; } = new OSPlatform("IOS");
+
+        public static OSPlatform tvOS { get; } = new OSPlatform("TVOS");
+
+        public static OSPlatform watchOS { get; } = new OSPlatform("WATCHOS");
+
         public static OSPlatform Windows { get; } = new OSPlatform("WINDOWS");
 
         private OSPlatform(string osPlatform)
index 936b58e..1264c5c 100644 (file)
@@ -65,6 +65,82 @@ namespace System.Runtime.InteropServices.RuntimeInformationTests
             Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD));
         }
 
+        [Fact, PlatformSpecific(TestPlatforms.iOS)]  // Tests RuntimeInformation OS platform
+        public void CheckiOS()
+        {
+            Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.iOS));
+            Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")));
+
+            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.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.tvOS)]  // Tests RuntimeInformation OS platform
+        public void ChecktvOS()
+        {
+            Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.tvOS));
+            Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS")));
+
+            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.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.Android)]  // Tests RuntimeInformation OS platform
+        public void CheckAndroid()
+        {
+            Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Android));
+            Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID")));
+
+            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.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.Browser)]  // Tests RuntimeInformation OS platform
+        public void CheckBrowser()
+        {
+            Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Browser));
+            Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")));
+
+            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.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()
         {