Browse Source

Don't leak IPlatformRenderInterface.

pull/10860/head
Steven Kirk 4 years ago
parent
commit
668fa942b7
  1. 19
      tests/Avalonia.Base.UnitTests/Media/GlyphRunTests.cs

19
tests/Avalonia.Base.UnitTests/Media/GlyphRunTests.cs

@ -1,22 +1,13 @@
using System; using System;
using System.Linq;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Media.TextFormatting; using Avalonia.Media.TextFormatting;
using Avalonia.Platform;
using Avalonia.UnitTests; using Avalonia.UnitTests;
using Avalonia.Utilities;
using Xunit; using Xunit;
namespace Avalonia.Base.UnitTests.Media namespace Avalonia.Base.UnitTests.Media
{ {
public class GlyphRunTests : TestWithServicesBase public class GlyphRunTests : TestWithServicesBase
{ {
public GlyphRunTests()
{
AvaloniaLocator.CurrentMutable
.Bind<IPlatformRenderInterface>().ToSingleton<MockPlatformRenderInterface>();
}
[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, 0, 0)]
[InlineData(new double[] { 30, 0, 0 }, new int[] { 0, 0, 0 }, 0, 3, 30)] [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)] [InlineData(new double[] { 10, 10, 10 }, new int[] { 0, 1, 2 }, 1, 0, 10)]
@ -25,7 +16,7 @@ namespace Avalonia.Base.UnitTests.Media
[Theory] [Theory]
public void Should_Get_Distance_From_CharacterHit(double[] advances, int[] clusters, int start, int trailingLength, double expectedDistance) 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)) using (var glyphRun = CreateGlyphRun(advances, clusters))
{ {
var characterHit = new CharacterHit(start, trailingLength); 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, public void Should_Get_CharacterHit_FromDistance(double[] advances, int[] clusters, double distance, int start,
int trailingLengthExpected, bool isInsideExpected) int trailingLengthExpected, bool isInsideExpected)
{ {
using(UnitTestApplication.Start(TestServices.StyledWindow)) using (Start())
using (var glyphRun = CreateGlyphRun(advances, clusters)) using (var glyphRun = CreateGlyphRun(advances, clusters))
{ {
var textBounds = glyphRun.GetCharacterHitFromDistance(distance, out var isInside); 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); 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()));
}
} }
} }

Loading…
Cancel
Save