From 0f4e8491658b3560565f1a634ab7c27a5aff2770 Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Thu, 27 Jan 2022 22:53:11 +0100 Subject: [PATCH] test: RenderTargetBitmaps --- .../SamplesApp.UITests.csproj | 7 + .../RenderTargetBitmap_Tests.cs | 78 +++++++++++ .../Border.png | Bin 0 -> 346 bytes .../UITests.Shared/UITests.Shared.projitems | 7 + .../RenderTargetBitmaps.xaml | 25 ++++ .../RenderTargetBitmaps.xaml.cs | 122 ++++++++++++++++++ 6 files changed, 239 insertions(+) create mode 100644 src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml_Media_Imaging/RenderTargetBitmap_Tests.cs create mode 100644 src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml_Media_Imaging/RenderTargetBitmap_Tests_EpectedResults/Border.png create mode 100644 src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Media_Imaging/RenderTargetBitmaps.xaml create mode 100644 src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Media_Imaging/RenderTargetBitmaps.xaml.cs diff --git a/src/SamplesApp/SamplesApp.UITests/SamplesApp.UITests.csproj b/src/SamplesApp/SamplesApp.UITests/SamplesApp.UITests.csproj index ece071d8af28..d581be097012 100644 --- a/src/SamplesApp/SamplesApp.UITests/SamplesApp.UITests.csproj +++ b/src/SamplesApp/SamplesApp.UITests/SamplesApp.UITests.csproj @@ -33,6 +33,7 @@ + @@ -42,4 +43,10 @@ + + + PreserveNewest + + + diff --git a/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml_Media_Imaging/RenderTargetBitmap_Tests.cs b/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml_Media_Imaging/RenderTargetBitmap_Tests.cs new file mode 100644 index 000000000000..143671fb3d70 --- /dev/null +++ b/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml_Media_Imaging/RenderTargetBitmap_Tests.cs @@ -0,0 +1,78 @@ +using System; +using System.IO; +using NUnit.Framework; +using SamplesApp.UITests.Extensions; +using SamplesApp.UITests.TestFramework; +using Uno.UITest.Helpers.Queries; + +namespace SamplesApp.UITests.Windows_UI_Xaml_Media_Imaging +{ + public partial class RenderTargetBitmap_Tests : SampleControlUITestBase + { + private const int TestTimeout = 7 * 60 * 1000; + [Test] + [AutoRetry] + [Timeout(TestTimeout)] + public void When_Border() + => Validate("Border"); + + public void Validate(string controlName, PixelTolerance? tolerance = null) + { + Run("UITests.Windows_UI_Xaml_Media_Imaging.RenderTargetBitmaps", skipInitialScreenshot: true); + + var ctrl = new QueryEx(q => q.Marked("_renderTargetTestRoot")); +; + var expectedDirectory = Path.Combine( + TestContext.CurrentContext.TestDirectory, + nameof(Windows_UI_Xaml_Media_Imaging) + "/RenderTargetBitmap_Tests_EpectedResults"); + var actualDirectory = Path.Combine( + TestContext.CurrentContext.WorkDirectory, + nameof(Windows_UI_Xaml_Media_Imaging), + nameof(RenderTargetBitmap_Tests), + controlName); + + tolerance = tolerance ?? (new PixelTolerance() + .WithColor(132) // We are almost only trying to detect edges + .WithOffset(3, 3, LocationToleranceKind.PerPixel) + .Discrete(2)); + + ctrl.SetDependencyPropertyValue("RunTest", controlName); + _app.WaitFor(() => !string.IsNullOrWhiteSpace(ctrl.GetDependencyPropertyValue("TestResult")) + , timeout: TimeSpan.FromMinutes(1)); + + var testResultsRaw = ctrl.GetDependencyPropertyValue("TestResult"); + + var testResults = testResultsRaw.Split(';'); + Assert.That(testResults.Length, Is.EqualTo(2)); + + var isSuccess = testResults[0] == "SUCCESS"; + var data = Convert.FromBase64String(testResults[1]); + + var target = Path + .Combine(actualDirectory, controlName + (isSuccess ? ".png" : ".txt")) + .GetNormalizedLongPath(); + var targetFile = new FileInfo(target); + + targetFile.Directory.Create(); + File.WriteAllBytes(target, data); + SetOptions(targetFile, new ScreenshotOptions { IgnoreInSnapshotCompare = true }); + TestContext.AddTestAttachment(target, controlName); + + if (!isSuccess) + { + Assert.Fail($"No test result for {controlName}."); + } + + var expected = new FileInfo(Path.Combine(expectedDirectory, $"{controlName}.png")); + if (!expected.Exists) + { + Assert.Fail($"Expected screenshot does not exists ({expected.FullName})"); + } + + var scale = _app.GetDisplayScreenScaling(); + ImageAssert.AreEqual(expected, ImageAssert.FirstQuadrant, + targetFile, ImageAssert.FirstQuadrant, + scale, tolerance.Value); + } + } +} diff --git a/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml_Media_Imaging/RenderTargetBitmap_Tests_EpectedResults/Border.png b/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml_Media_Imaging/RenderTargetBitmap_Tests_EpectedResults/Border.png new file mode 100644 index 0000000000000000000000000000000000000000..fed58f3bad2ded93c790bceb3a0e2e75899f4faf GIT binary patch literal 346 zcmeAS@N?(olHy`uVBq!ia0vp^DImEakt zG3V`NLoQ}V9u~*7JO9^5ic3Bg&tVUp=;Uaeo?dq1$DO){`t#o{+KR58n<>eCQc%Th sf`nrdOXu)m%-C#P{hPB+N97sobvL%7yI!Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -6946,6 +6950,9 @@ SetTargetProperty.xaml + + RenderTargetBitmaps.xaml + Basic_Shapes.xaml diff --git a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Media_Imaging/RenderTargetBitmaps.xaml b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Media_Imaging/RenderTargetBitmaps.xaml new file mode 100644 index 000000000000..cdc6e67539ac --- /dev/null +++ b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Media_Imaging/RenderTargetBitmaps.xaml @@ -0,0 +1,25 @@ + + + + + + + + +