From 668fa942b70bd36279e980bd58c094c848a316d1 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 30 Mar 2023 22:28:55 +0200 Subject: [PATCH 1/2] Don't leak IPlatformRenderInterface. --- .../Media/GlyphRunTests.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/Avalonia.Base.UnitTests/Media/GlyphRunTests.cs b/tests/Avalonia.Base.UnitTests/Media/GlyphRunTests.cs index 43feb75c08..84ce341e98 100644 --- a/tests/Avalonia.Base.UnitTests/Media/GlyphRunTests.cs +++ b/tests/Avalonia.Base.UnitTests/Media/GlyphRunTests.cs @@ -1,22 +1,13 @@ using System; -using System.Linq; using Avalonia.Media; using Avalonia.Media.TextFormatting; -using Avalonia.Platform; using Avalonia.UnitTests; -using Avalonia.Utilities; using Xunit; namespace Avalonia.Base.UnitTests.Media { public class GlyphRunTests : TestWithServicesBase { - public GlyphRunTests() - { - AvaloniaLocator.CurrentMutable - .Bind().ToSingleton(); - } - [InlineData(new double[] { 30, 0, 0 }, new int[] { 0, 0, 0 }, 0, 0, 0)] [InlineData(new double[] { 30, 0, 0 }, new int[] { 0, 0, 0 }, 0, 3, 30)] [InlineData(new double[] { 10, 10, 10 }, new int[] { 0, 1, 2 }, 1, 0, 10)] @@ -25,7 +16,7 @@ namespace Avalonia.Base.UnitTests.Media [Theory] public void Should_Get_Distance_From_CharacterHit(double[] advances, int[] clusters, int start, int trailingLength, double expectedDistance) { - using(UnitTestApplication.Start(TestServices.StyledWindow)) + using (Start()) using (var glyphRun = CreateGlyphRun(advances, clusters)) { var characterHit = new CharacterHit(start, trailingLength); @@ -44,7 +35,7 @@ namespace Avalonia.Base.UnitTests.Media public void Should_Get_CharacterHit_FromDistance(double[] advances, int[] clusters, double distance, int start, int trailingLengthExpected, bool isInsideExpected) { - using(UnitTestApplication.Start(TestServices.StyledWindow)) + using (Start()) using (var glyphRun = CreateGlyphRun(advances, clusters)) { var textBounds = glyphRun.GetCharacterHitFromDistance(distance, out var isInside); @@ -190,5 +181,11 @@ namespace Avalonia.Base.UnitTests.Media return new GlyphRun(new MockGlyphTypeface(), 10, new string('a', count).AsMemory(), glyphInfos, biDiLevel: bidiLevel); } + + private static IDisposable Start() + { + return UnitTestApplication.Start(TestServices.StyledWindow.With( + renderInterface: new MockPlatformRenderInterface())); + } } } From a28483252b9039d5e9c921eb054c3aa034963d33 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 30 Mar 2023 22:29:48 +0200 Subject: [PATCH 2/2] Make MaskedTextBox tests pass again. They need a registered `IPlatformRenderInterface` and were only passing because `GlyphRunTests` was leaking one. --- tests/Avalonia.Controls.UnitTests/MaskedTextBoxTests.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/Avalonia.Controls.UnitTests/MaskedTextBoxTests.cs b/tests/Avalonia.Controls.UnitTests/MaskedTextBoxTests.cs index 19009416ef..a51abdb9af 100644 --- a/tests/Avalonia.Controls.UnitTests/MaskedTextBoxTests.cs +++ b/tests/Avalonia.Controls.UnitTests/MaskedTextBoxTests.cs @@ -109,7 +109,7 @@ namespace Avalonia.Controls.UnitTests [Fact] public void CaretIndex_Can_Moved_To_Position_After_The_End_Of_Text_With_Arrow_Key() { - using (Start(TestServices.StyledWindow)) + using (Start()) { var target = new MaskedTextBox { @@ -184,7 +184,7 @@ namespace Avalonia.Controls.UnitTests [Fact] public void Control_Backspace_Should_Remove_The_Word_Before_The_Caret_If_There_Is_No_Selection() { - using (Start(TestServices.StyledWindow)) + using (Start()) { MaskedTextBox textBox = new MaskedTextBox { @@ -226,7 +226,7 @@ namespace Avalonia.Controls.UnitTests [Fact] public void Control_Delete_Should_Remove_The_Word_After_The_Caret_If_There_Is_No_Selection() { - using (Start(TestServices.StyledWindow)) + using (Start()) { var textBox = new MaskedTextBox { @@ -812,7 +812,7 @@ namespace Avalonia.Controls.UnitTests bool fromClipboard, string expected) { - using (Start(TestServices.StyledWindow)) + using (Start()) { var target = new MaskedTextBox { @@ -898,6 +898,7 @@ namespace Avalonia.Controls.UnitTests standardCursorFactory: Mock.Of()); private static TestServices Services => TestServices.MockThreadingInterface.With( + renderInterface: new MockPlatformRenderInterface(), standardCursorFactory: Mock.Of(), textShaperImpl: new MockTextShaperImpl(), fontManagerImpl: new MockFontManagerImpl());