Skip to content

Commit

Permalink
feat: Added runtime tests to check platform detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcNets committed Dec 5, 2024
1 parent e304301 commit ff8e2bd
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 5 deletions.
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
}
}
19 changes: 14 additions & 5 deletions src/Uno.UI/Helpers/Xaml/UnoRuntimePlatformExtensions.cs
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;
}

0 comments on commit ff8e2bd

Please sign in to comment.