-
Notifications
You must be signed in to change notification settings - Fork 743
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added runtime tests to check platform detection.
- Loading branch information
Showing
2 changed files
with
97 additions
and
5 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
src/Uno.UI.RuntimeTests/Tests/Uno_UI_Toolkit/Given_RuntimePlatformDetected.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Private.Infrastructure; | ||
using Uno.Disposables; | ||
using Uno.UI.RuntimeTests.Extensions; | ||
using Uno.UI.RuntimeTests.Helpers; | ||
using Uno.UI.Toolkit; | ||
using Uno.UI.Helpers; | ||
using Windows.UI; | ||
using Windows.UI.ViewManagement; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Media; | ||
using Microsoft.UI.Xaml.Shapes; | ||
using static Private.Infrastructure.TestServices; | ||
using FluentAssertions; | ||
|
||
namespace Uno.UI.RuntimeTests.Tests.Uno_UI_Toolkit | ||
{ | ||
[TestClass] | ||
[RunsOnUIThread] | ||
public class Given_RuntimePlatformDetected | ||
{ | ||
#if __SKIA__ | ||
[TestMethod] | ||
public void When_IsSkia() | ||
{ | ||
Uno.UI.Helpers.PlatformRuntimeHelper.Current.IsSkia().Should().BeTrue(); | ||
} | ||
#endif | ||
|
||
#if __IOS__ | ||
[TestMethod] | ||
public void When_IsIOS() | ||
{ | ||
Uno.UI.Helpers.PlatformRuntimeHelper.Current.IsIOS().Should().BeTrue(); | ||
} | ||
#endif | ||
|
||
#if __ANDROID__ | ||
[TestMethod] | ||
public void When_IsAndroid() | ||
{ | ||
Uno.UI.Helpers.PlatformRuntimeHelper.Current.IsAndroid().Should().BeTrue(); | ||
} | ||
#endif | ||
|
||
#if __MACCATALYST__ | ||
[TestMethod] | ||
public void When_IsMacCatalyst() | ||
{ | ||
Uno.UI.Helpers.PlatformRuntimeHelper.Current.IsMacCatalyst().Should().BeTrue(); | ||
} | ||
#endif | ||
|
||
#if __MACOS__ | ||
[TestMethod] | ||
public void When_IsMacOS() | ||
{ | ||
Uno.UI.Helpers.PlatformRuntimeHelper.Current.IsMacOS().Should().BeTrue(); | ||
} | ||
#endif | ||
|
||
#if __WASM__ | ||
[TestMethod] | ||
public void When_IsWebAssembly() | ||
{ | ||
Uno.UI.Helpers.PlatformRuntimeHelper.Current.IsWebAssembly().Should().BeTrue(); | ||
} | ||
#endif | ||
|
||
#if !HAS_UNO | ||
[TestMethod] | ||
public void When_IsWindows() | ||
{ | ||
Uno.UI.Toolkit.PlatformRuntimeHelper.Current.Should().Be(Uno.UI.Toolkit.UnoRuntimePlatform.Windows); | ||
} | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
namespace Uno.UI.Helpers; | ||
|
||
internal static class UnoRuntimePlatformExtensions | ||
public static class UnoRuntimePlatformExtensions | ||
{ | ||
public static bool IsSkia(UnoRuntimePlatform platform) | ||
{ | ||
return platform == UnoRuntimePlatform.SkiaFrameBuffer | ||
public static bool IsSkia(this UnoRuntimePlatform platform) => platform == UnoRuntimePlatform.SkiaFrameBuffer | ||
|| platform == UnoRuntimePlatform.SkiaGtk | ||
|| platform == UnoRuntimePlatform.SkiaMacOS | ||
|| platform == UnoRuntimePlatform.SkiaWpfIslands | ||
|| platform == UnoRuntimePlatform.SkiaX11; | ||
} | ||
|
||
public static bool IsIOS(this UnoRuntimePlatform platform) => platform == UnoRuntimePlatform.iOS; | ||
|
||
public static bool IsMacCatalyst(this UnoRuntimePlatform platform) => platform == UnoRuntimePlatform.MacCatalyst; | ||
|
||
public static bool IsMacOS(this UnoRuntimePlatform platform) => platform == UnoRuntimePlatform.MacOSX; | ||
|
||
public static bool IsWebAssembly(this UnoRuntimePlatform platform) => platform == UnoRuntimePlatform.WebAssembly; | ||
|
||
public static bool IsWindows(this UnoRuntimePlatform platform) => platform == UnoRuntimePlatform.Windows; | ||
|
||
public static bool IsAndroid(this UnoRuntimePlatform platform) => platform == UnoRuntimePlatform.Android; | ||
} |