Browse Source

Add unit test for `UseLayoutRounding`.

pull/3960/head
Steven Kirk 6 years ago
parent
commit
1e74316f63
  1. 32
      tests/Avalonia.Layout.UnitTests/LayoutableTests.cs
  2. 2
      tests/Avalonia.UnitTests/TestRoot.cs

32
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; }

2
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();

Loading…
Cancel
Save