From 1e74316f63804b69be628401f3bb1d050ecd61cf Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 19 May 2020 20:31:45 +0200 Subject: [PATCH] Add unit test for `UseLayoutRounding`. --- .../LayoutableTests.cs | 32 +++++++++++++++++++ tests/Avalonia.UnitTests/TestRoot.cs | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/Avalonia.Layout.UnitTests/LayoutableTests.cs b/tests/Avalonia.Layout.UnitTests/LayoutableTests.cs index 31310f7d42..a1c1e62f58 100644 --- a/tests/Avalonia.Layout.UnitTests/LayoutableTests.cs +++ b/tests/Avalonia.Layout.UnitTests/LayoutableTests.cs @@ -1,5 +1,6 @@ using System; using Avalonia.Controls; +using Avalonia.UnitTests; using Moq; using Xunit; @@ -171,6 +172,37 @@ namespace Avalonia.Layout.UnitTests target.Verify(x => x.InvalidateMeasure(root), Times.Once()); } + [Theory] + [InlineData(16, 6, 5.333333333333333)] + [InlineData(18, 10, 4)] + public void UseLayoutRounding_Arranges_Center_Alignment_Correctly_With_Fractional_Scaling( + double containerWidth, + double childWidth, + double expectedX) + { + Border target; + var root = new TestRoot + { + LayoutScaling = 1.5, + UseLayoutRounding = true, + Child = new Decorator + { + Width = containerWidth, + Height = 100, + Child = target = new Border + { + Width = childWidth, + HorizontalAlignment = HorizontalAlignment.Center, + } + } + }; + + root.Measure(new Size(100, 100)); + root.Arrange(new Rect(target.DesiredSize)); + + Assert.Equal(new Rect(expectedX, 0, childWidth, 100), target.Bounds); + } + private class TestLayoutable : Layoutable { public Size ArrangeSize { get; private set; } diff --git a/tests/Avalonia.UnitTests/TestRoot.cs b/tests/Avalonia.UnitTests/TestRoot.cs index 56a1a6c245..f291d386aa 100644 --- a/tests/Avalonia.UnitTests/TestRoot.cs +++ b/tests/Avalonia.UnitTests/TestRoot.cs @@ -42,7 +42,7 @@ namespace Avalonia.UnitTests public Size MaxClientSize { get; set; } = Size.Infinity; - public double LayoutScaling => 1; + public double LayoutScaling { get; set; } = 1; public ILayoutManager LayoutManager { get; set; } = new LayoutManager();