Skip to content

Commit

Permalink
chore: Fix access modifiers and file exclusions
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Oct 16, 2023
1 parent 283e312 commit 3ae53a6
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Uno.UI.RuntimeTests;


#if !UNO_RUNTIMETESTS_DISABLE_UI || !UNO_RUNTIMETESTS_DISABLE_RC
#if !UNO_RUNTIMETESTS_DISABLE_UI || !UNO_RUNTIMETESTS_DISABLE_EMBEDDEDRUNNER

public record UnitTestEngineConfig
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !UNO_RUNTIMETESTS_DISABLE_UI || !UNO_RUNTIMETESTS_DISABLE_RC
#if !UNO_RUNTIMETESTS_DISABLE_UI || !UNO_RUNTIMETESTS_DISABLE_EMBEDDEDRUNNER
using System;
using System.Linq;
using System.Reflection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#if !UNO_RUNTIMETESTS_DISABLE_LIBRARY
// *********************************************************************************************************************
// *********************************************************************************************************************
// Be aware that this file is referenced only if the package Uno.[Win]UI.DevServer is referenced.
// *********************************************************************************************************************
// *********************************************************************************************************************

#if !UNO_RUNTIMETESTS_DISABLE_LIBRARY
#nullable enable

#if !IS_UNO_RUNTIMETEST_PROJECT
Expand Down Expand Up @@ -28,12 +34,23 @@

namespace Uno.UI.RuntimeTests;

public static class HotReloadHelper
public static partial class HotReloadHelper
{
public static async ValueTask<IAsyncDisposable?> UpdateServerFile(string filPathRelativeToProject, string originalText, string replacementText, CancellationToken ct)
=> await UpdateServerFile(filPathRelativeToProject, originalText, replacementText, true, ct);

public static async ValueTask<IAsyncDisposable?> UpdateServerFile(string filPathRelativeToProject, string originalText, string replacementText, bool waitForMetadataUpdate, CancellationToken ct)
public static async ValueTask<IAsyncDisposable?> UpdateServerFile<T>(string filPathRelativeToProject, string originalText, string replacementText, CancellationToken ct)
=> await UpdateServerFile<T>(filPathRelativeToProject, originalText, replacementText, true, ct);

/// <summary>
/// Update the
/// </summary>
/// <typeparam name="T">The type that is expected to be altered</typeparam>
/// <param name="filPathRelativeToProject"></param>
/// <param name="originalText"></param>
/// <param name="replacementText"></param>
/// <param name="waitForMetadataUpdate"></param>
/// <param name="ct"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public static async ValueTask<IAsyncDisposable?> UpdateServerFile<T>(string filPathRelativeToProject, string originalText, string replacementText, bool waitForMetadataUpdate, CancellationToken ct)
{
var projectFile = typeof(HotReloadHelper).Assembly.GetCustomAttribute<RuntimeTestsSourceProjectAttribute>()?.ProjectFullPath;
if (projectFile is null or { Length: 0 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
using Windows.UI;

#if HAS_UNO_WINUI || WINDOWS_WINUI
using Microsoft.UI;
using Microsoft.UI.Xaml.Markup;
#else
using Windows.UI.Xaml.Markup;
#endif

namespace Uno.UI.RuntimeTests;

internal record struct ExpectedPixels
public record struct ExpectedPixels
{
#region Fluent declaration
public static ExpectedPixels At(string name, float x, float y)
Expand Down Expand Up @@ -193,7 +194,7 @@ private static Color GetColorFromString(string colorCode) =>
: (Color)XamlBindingHelper.ConvertValue(typeof(Color), colorCode);
}

internal struct PixelTolerance
public struct PixelTolerance
{
#region Fluent declaration
public static PixelTolerance None => default;
Expand Down Expand Up @@ -247,7 +248,7 @@ public override string ToString() =>
: "No color tolerance";
}

internal enum ColorToleranceKind
public enum ColorToleranceKind
{
/// <summary>
/// Each component of the pixel (i.e. a, r, g and b) might differ by the provided color tolerance
Expand All @@ -260,7 +261,7 @@ internal enum ColorToleranceKind
Cumulative
}

internal enum LocationToleranceKind
public enum LocationToleranceKind
{
/// <summary>
/// The offset applies to all pixel in <see cref="ExpectedPixels.Values"/> at once
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
using Windows.UI;
using Windows.Foundation;

#if HAS_UNO_WINUI || WINDOWS_WINUI
using Microsoft.UI;
#endif

namespace Uno.UI.RuntimeTests;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Uno.UI.RuntimeTests;
/// <summary>
/// Screen shot based assertions, to validate individual colors of an image
/// </summary>
internal static partial class ImageAssert
public static partial class ImageAssert
{
#region HasColorAt
public static void HasColorAt(TestBitmap screenshot, Windows.Foundation.Point location, string expectedColorCode, byte tolerance = 0, [CallerLineNumber] int line = 0)
Expand Down Expand Up @@ -144,7 +144,7 @@ private static void DoesNotHaveColorAtImpl(TestBitmap screenshot, int x, int y,
{
Assert.Fail(WithContext(builder: builder => builder
.AppendLine($"Color at ({x},{y}) is not expected")
.AppendLine($"excluded: {ToArgbCode(excludedColor)} {ColorHelper.ToDisplayName(excludedColor)}")
.AppendLine($"excluded: {ToArgbCode(excludedColor)}")
.AppendLine($"actual : {ToArgbCode(pixel)} {pixel}")
.AppendLine($"tolerance: {tolerance}")
.AppendLine($"difference: {difference}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@
using Windows.Graphics.Display;
using Windows.Storage.Streams;
using Windows.UI;

#if HAS_UNO_WINUI || WINDOWS_WINUI
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Imaging;
#else
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
#endif

namespace Uno.UI.RuntimeTests;

/// <summary>
/// Represents a <see cref="RenderTargetBitmap"/> to be tested against.
/// </summary>
internal partial class TestBitmap
public partial class TestBitmap
{
private readonly RenderTargetBitmap _bitmap;
private readonly UIElement _renderedElement; // Allow access through partial implementation
Expand All @@ -42,7 +50,7 @@ private TestBitmap(RenderTargetBitmap bitmap, UIElement renderedElement, double
/// <summary>
/// Prefer using UIHelper.Screenshot() instead.
/// </summary>
public static async Task<TestBitmap> From(RenderTargetBitmap bitmap, UIElement renderedElement, double? implicitScaling = null)
internal static async Task<TestBitmap> From(RenderTargetBitmap bitmap, UIElement renderedElement, double? implicitScaling = null)
{
implicitScaling ??= DisplayInformation.GetForCurrentView()?.RawPixelsPerViewPixel ?? 1;
var raw = new TestBitmap(bitmap, renderedElement, implicitScaling.Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Graphics.Display;
using Windows.UI;
using Windows.System;

#if HAS_UNO_WINUI || WINDOWS_WINUI
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
Expand All @@ -33,7 +35,7 @@ namespace Uno.UI.RuntimeTests;
/// <summary>
/// Set of helpers to interact with the UI during tests.
/// </summary>
internal static class UIHelper
public static partial class UIHelper
{
/// <summary>
/// Gets or sets the content of the current test area.
Expand Down Expand Up @@ -216,9 +218,9 @@ public static async ValueTask Show(TestBitmap bitmap)
{
new Border
{
BorderBrush = new SolidColorBrush(Windows.UI.Colors.Black),
BorderBrush = new SolidColorBrush(Colors.Black),
BorderThickness = new Thickness(1),
Background = new SolidColorBrush(Windows.UI.Colors.Gray),
Background = new SolidColorBrush(Colors.Gray),
Width = bitmap.Width * bitmap.ImplicitScaling + 2,
Height = bitmap.Height * bitmap.ImplicitScaling + 2,
Child = img = new Image
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
<Project>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)/../src/**/*.cs"
Link="Uno.UI.RuntimeTests.Engine/%(RecursiveDir)%(FileName)%(Extension)"
Visible="False" />
<Page Include="$(MSBuildThisFileDirectory)/../src/**/*.xaml"
Link="Uno.UI.RuntimeTests.Engine/%(RecursiveDir)%(FileName)%(Extension)"
Visible="False"
XamlRuntime="WinUI" />
<AssemblyAttribute Include="Uno.UI.RuntimeTests.Engine.RuntimeTestsSourceProjectAttribute" Condition="!$(DefineConstants.Contains('UNO_RUNTIMETESTS_DISABLE_EMBEDDEDRUNNER'))">
<_Parameter1>$(MSBuildProjectFullPath)</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<Compile
Include="$(MSBuildThisFileDirectory)/../src/**/*.cs"
Link="Uno.UI.RuntimeTests.Engine/%(RecursiveDir)%(FileName)%(Extension)"
Visible="False" />
<Page
Include="$(MSBuildThisFileDirectory)/../src/**/*.xaml"
Link="Uno.UI.RuntimeTests.Engine/%(RecursiveDir)%(FileName)%(Extension)"
Visible="False"
XamlRuntime="WinUI" />

<Compile
Condition="$(DefineConstants.Contains('UNO_RUNTIMETESTS_DISABLE_UI'))"
Remove="$(MSBuildThisFileDirectory)/../src/Engine/UI/**/*.cs" />
<Page
Condition="$(DefineConstants.Contains('UNO_RUNTIMETESTS_DISABLE_UI'))"
Remove="$(MSBuildThisFileDirectory)/../src/Engine/UI/**/*.cs" />

<Compile Condition="$(DefineConstants.Contains('UNO_RUNTIMETESTS_DISABLE_UI'))"
Remove="$(MSBuildThisFileDirectory)/../src/UI/**/*.cs" />
<Page Condition="$(DefineConstants.Contains('UNO_RUNTIMETESTS_DISABLE_UI'))"
Remove="$(MSBuildThisFileDirectory)/../src/UI/**/*.cs" />
<Compile
Condition="$(DefineConstants.Contains('UNO_RUNTIMETESTS_DISABLE_LIBRARY'))"
Remove="$(MSBuildThisFileDirectory)/../src/Library/**/*.cs" />

<Compile Condition="$(DefineConstants.Contains('UNO_RUNTIMETESTS_DISABLE_LIBRARY'))"
Remove="$(MSBuildThisFileDirectory)/../src/Library/**/*.cs" />
<Compile
Condition="'$(PkgUno_UI_DevServer)' == '' AND '$(PkgUno_WinUI_DevServer)' == ''"
Remove="$(MSBuildThisFileDirectory)/../src/Library/Helpers/HotReloadHelper.cs" />
</ItemGroup>
</Project>

0 comments on commit 3ae53a6

Please sign in to comment.