Imported Upstream version 5.8.0.22

Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-10-19 20:04:20 +00:00
parent 5f4a27cc8a
commit 7d05485754
5020 changed files with 114082 additions and 186061 deletions

View File

@@ -2,6 +2,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.WindowsRuntime.UI.Xaml.Tests", "tests\System.Runtime.WindowsRuntime.UI.Xaml.Tests.csproj", "{69FC7EB5-64FD-4464-88B1-B8ADD3870640}"
ProjectSection(ProjectDependencies) = postProject
{263DA4F1-C3BC-4B43-98E7-9F38B419A131} = {263DA4F1-C3BC-4B43-98E7-9F38B419A131}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.WindowsRuntime.UI.Xaml", "src\System.Runtime.WindowsRuntime.UI.Xaml.csproj", "{263DA4F1-C3BC-4B43-98E7-9F38B419A131}"
ProjectSection(ProjectDependencies) = postProject
{AA1600B8-C4D3-42A9-A28A-04D0C8282566} = {AA1600B8-C4D3-42A9-A28A-04D0C8282566}
@@ -9,6 +14,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.WindowsRunti
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.WindowsRuntime.UI.Xaml", "ref\System.Runtime.WindowsRuntime.UI.Xaml.csproj", "{AA1600B8-C4D3-42A9-A28A-04D0C8282566}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{1A2F9F4A-A032-433E-B914-ADD5992BB178}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E107E9C1-E893-4E87-987E-04EF0DCEAEFD}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{2E666815-2EDB-464B-9DF6-380BF4789AD4}"
@@ -19,6 +26,10 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{69FC7EB5-64FD-4464-88B1-B8ADD3870640}.Debug|Any CPU.ActiveCfg = uap-Windows_NT-Debug|Any CPU
{69FC7EB5-64FD-4464-88B1-B8ADD3870640}.Debug|Any CPU.Build.0 = uap-Windows_NT-Debug|Any CPU
{69FC7EB5-64FD-4464-88B1-B8ADD3870640}.Release|Any CPU.ActiveCfg = uap-Windows_NT-Release|Any CPU
{69FC7EB5-64FD-4464-88B1-B8ADD3870640}.Release|Any CPU.Build.0 = uap-Windows_NT-Release|Any CPU
{263DA4F1-C3BC-4B43-98E7-9F38B419A131}.Debug|Any CPU.ActiveCfg = uap-Windows_NT-Debug|Any CPU
{263DA4F1-C3BC-4B43-98E7-9F38B419A131}.Debug|Any CPU.Build.0 = uap-Windows_NT-Debug|Any CPU
{263DA4F1-C3BC-4B43-98E7-9F38B419A131}.Release|Any CPU.ActiveCfg = uap-Windows_NT-Release|Any CPU
@@ -32,6 +43,7 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{69FC7EB5-64FD-4464-88B1-B8ADD3870640} = {1A2F9F4A-A032-433E-B914-ADD5992BB178}
{263DA4F1-C3BC-4B43-98E7-9F38B419A131} = {E107E9C1-E893-4E87-987E-04EF0DCEAEFD}
{AA1600B8-C4D3-42A9-A28A-04D0C8282566} = {2E666815-2EDB-464B-9DF6-380BF4789AD4}
EndGlobalSection

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
uap-Windows_NT;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<ProjectGuid>{69FC7EB5-64FD-4464-88B1-B8ADD3870640}</ProjectGuid>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Windows_NT-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="Windows\UI\Xaml\CornerRadiusTests.cs" />
<Compile Include="Windows\UI\Xaml\DurationTests.cs" />
<Compile Include="Windows\UI\Xaml\GridLengthTests.cs" />
<Compile Include="Windows\UI\Xaml\LayoutCycleExceptionTests.cs" />
<Compile Include="Windows\UI\Xaml\ThicknessTests.cs" />
<Compile Include="Windows\UI\Xaml\Automation\ElementNotEnabledExceptionTests.cs" />
<Compile Include="Windows\UI\Xaml\Automation\ElementNotAvailableExceptionTests.cs" />
<Compile Include="Windows\UI\Xaml\Controls\Primitives\GeneratorPositionTests.cs" />
<Compile Include="Windows\UI\Xaml\Markup\XamlParseExceptionTests.cs" />
<Compile Include="Windows\UI\Xaml\Media\MatrixTests.cs" />
<Compile Include="Windows\UI\Xaml\Media\Animation\KeyTimeTests.cs" />
<Compile Include="Windows\UI\Xaml\Media\Animation\RepeatBehaviorTests.cs" />
<Compile Include="Windows\UI\Xaml\Media3D\Matrix3DTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\System.Runtime.WindowsRuntime.UI.Xaml.csproj">
<Project>{263DA4F1-C3BC-4B43-98E7-9F38B419A131}</Project>
<Name>System.Runtime.WindowsRuntime.UI.Xaml</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@@ -0,0 +1,42 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using Xunit;
namespace Windows.UI.Xaml.Automation.Tests
{
public class ElementNotAvailableExceptionTests
{
private const int E_ELEMENTNOTAVAILABLE = unchecked((int)0x802B001F);
[Fact]
public void Ctor_Default()
{
var exception = new ElementNotAvailableException();
Assert.NotEmpty(exception.Message);
Assert.Null(exception.InnerException);
Assert.Equal(E_ELEMENTNOTAVAILABLE, exception.HResult);
}
[Fact]
public void Ctor_Message()
{
var exception = new ElementNotAvailableException("Message");
Assert.Equal("Message", exception.Message);
Assert.Null(exception.InnerException);
Assert.Equal(E_ELEMENTNOTAVAILABLE, exception.HResult);
}
[Fact]
public void Ctor_Message_InnerException()
{
var innerException = new Exception();
var exception = new ElementNotAvailableException("Message", innerException);
Assert.Equal("Message", exception.Message);
Assert.Same(innerException, exception.InnerException);
Assert.Equal(E_ELEMENTNOTAVAILABLE, exception.HResult);
}
}
}

View File

@@ -0,0 +1,42 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using Xunit;
namespace Windows.UI.Xaml.Automation.Tests
{
public class ElementNotEnabledExceptionTests
{
private const int E_ELEMENTNOTENABLED = unchecked((int)0x802B001E);
[Fact]
public void Ctor_Default()
{
var exception = new ElementNotEnabledException();
Assert.NotEmpty(exception.Message);
Assert.Null(exception.InnerException);
Assert.Equal(E_ELEMENTNOTENABLED, exception.HResult);
}
[Fact]
public void Ctor_Message()
{
var exception = new ElementNotEnabledException("Message");
Assert.Equal("Message", exception.Message);
Assert.Null(exception.InnerException);
Assert.Equal(E_ELEMENTNOTENABLED, exception.HResult);
}
[Fact]
public void Ctor_Message_InnerException()
{
var innerException = new Exception();
var exception = new ElementNotEnabledException("Message", innerException);
Assert.Equal("Message", exception.Message);
Assert.Same(innerException, exception.InnerException);
Assert.Equal(E_ELEMENTNOTENABLED, exception.HResult);
}
}
}

View File

@@ -0,0 +1,83 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Xunit;
namespace Windows.UI.Xaml.Controls.Primitives.Tests
{
public class GeneratorPositionTests
{
[Fact]
public void Ctor_Default()
{
var position = new GeneratorPosition();
Assert.Equal(0, position.Index);
Assert.Equal(0, position.Offset);
}
[Theory]
[InlineData(-1, -2)]
[InlineData(0, 0)]
[InlineData(1, 2)]
public void Ctor_Index_Offset(int index, int offset)
{
var position = new GeneratorPosition(index, offset);
Assert.Equal(index, position.Index);
Assert.Equal(offset, position.Offset);
}
[Theory]
[InlineData(-1)]
[InlineData(0)]
[InlineData(1)]
public void Index_Set_GetReturnsExpected(int value)
{
var thickness = new GeneratorPosition { Index = value };
Assert.Equal(value, thickness.Index);
}
[Theory]
[InlineData(-1)]
[InlineData(0)]
[InlineData(1)]
public void Offset_Set_GetReturnsExpected(int value)
{
var thickness = new GeneratorPosition { Offset = value };
Assert.Equal(value, thickness.Offset);
}
public static IEnumerable<object[]> Equals_TestData()
{
yield return new object[] { new GeneratorPosition(1, 2), new GeneratorPosition(1, 2), true };
yield return new object[] { new GeneratorPosition(1, 2), new GeneratorPosition(2, 2), false };
yield return new object[] { new GeneratorPosition(1, 2), new GeneratorPosition(1, 3), false };
yield return new object[] { new GeneratorPosition(1, 2), new object(), false };
yield return new object[] { new GeneratorPosition(1, 2), null, false };
}
[Theory]
[MemberData(nameof(Equals_TestData))]
public void Equals_Object_ReturnsExpected(GeneratorPosition position, object other, bool expected)
{
Assert.Equal(expected, position.Equals(other));
if (other is GeneratorPosition otherPosition)
{
Assert.Equal(expected, position.Equals(otherPosition));
Assert.Equal(expected, position == otherPosition);
Assert.Equal(!expected, position != otherPosition);
Assert.Equal(expected, position.GetHashCode().Equals(otherPosition.GetHashCode()));
}
}
[Fact]
public void ToString_Invoke_ReturnsExpected()
{
var position = new GeneratorPosition(1, 2);
Assert.Equal("GeneratorPosition (1,2)", position.ToString());
}
}
}

View File

@@ -0,0 +1,219 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using Xunit;
namespace Windows.UI.Xaml.Tests
{
public class CornerRadiusTests
{
[Fact]
public void Ctor_Default()
{
var cornerRadius = new CornerRadius();
Assert.Equal(0, cornerRadius.TopLeft);
Assert.Equal(0, cornerRadius.TopRight);
Assert.Equal(0, cornerRadius.BottomRight);
Assert.Equal(0, cornerRadius.BottomLeft);
}
public static IEnumerable<object[]> ValidDoubles_TestData()
{
yield return new object[] { 0 };
yield return new object[] { 1 };
yield return new object[] { double.MaxValue };
yield return new object[] { double.PositiveInfinity };
}
[Theory]
[MemberData(nameof(ValidDoubles_TestData))]
public void Ctor_UniformRadius(double uniformRadius)
{
var cornerRadius = new CornerRadius(uniformRadius);
Assert.Equal(uniformRadius, cornerRadius.TopLeft);
Assert.Equal(uniformRadius, cornerRadius.TopRight);
Assert.Equal(uniformRadius, cornerRadius.BottomRight);
Assert.Equal(uniformRadius, cornerRadius.BottomLeft);
}
private static List<double> InvalidDoubles { get; } = new List<double> { -1, double.NaN, double.NegativeInfinity };
public static IEnumerable<object[]> InvalidDoubles_TestData() => InvalidDoubles.Select(f => new object[] { f });
[Theory]
[MemberData(nameof(InvalidDoubles_TestData))]
public void Ctor_InvalidUniformRadius_ThrowsArgumentException(double uniformRadius)
{
AssertExtensions.Throws<ArgumentException>(null, () => new CornerRadius(uniformRadius));
}
[Theory]
[InlineData(0, 0, 0, 0)]
[InlineData(1, 2, 3, 4)]
[InlineData(double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity)]
[InlineData(double.MaxValue, double.MaxValue, double.MaxValue, double.MaxValue)]
public void Ctor_TopLeft_TopRight_BottomRight_BottomLeft(double topLeft, double topRight, double bottomRight, double bottomLeft)
{
var cornerRadius = new CornerRadius(topLeft, topRight, bottomRight, bottomLeft);
Assert.Equal(topLeft, cornerRadius.TopLeft);
Assert.Equal(topRight, cornerRadius.TopRight);
Assert.Equal(bottomRight, cornerRadius.BottomRight);
Assert.Equal(bottomLeft, cornerRadius.BottomLeft);
}
public static IEnumerable<object[]> Ctor_InvalidValues_TestData()
{
foreach (double invalidValue in InvalidDoubles)
{
yield return new object[] { invalidValue, 0, 0, 0 };
yield return new object[] { 0, invalidValue, 0, 0 };
yield return new object[] { 0, 0, invalidValue, 0 };
yield return new object[] { 0, 0, 0, invalidValue };
}
}
[Theory]
[MemberData(nameof(Ctor_InvalidValues_TestData))]
public void Ctor_InvalidValues_ThrowsArgumentException(double topLeft, double topRight, double bottomRight, double bottomLeft)
{
AssertExtensions.Throws<ArgumentException>(null, () => new CornerRadius(topLeft, topRight, bottomRight, bottomLeft));
}
[Theory]
[MemberData(nameof(ValidDoubles_TestData))]
public void TopLeft_SetValid_GetReturnsExpected(double value)
{
var cornerRadius = new CornerRadius { TopLeft = value };
Assert.Equal(value, cornerRadius.TopLeft);
}
[Theory]
[MemberData(nameof(InvalidDoubles_TestData))]
public void TopLeft_SetInvalid_ThrowsArgumentException(double value)
{
var cornerRadius = new CornerRadius();
AssertExtensions.Throws<ArgumentException>(null, () => cornerRadius.TopLeft = value);
}
[Theory]
[MemberData(nameof(ValidDoubles_TestData))]
public void TopRight_SetValid_GetReturnsExpected(double value)
{
var cornerRadius = new CornerRadius { TopRight = value };
Assert.Equal(value, cornerRadius.TopRight);
}
[Theory]
[MemberData(nameof(InvalidDoubles_TestData))]
public void TopRight_SetInvalid_ThrowsArgumentException(double value)
{
var cornerRadius = new CornerRadius();
AssertExtensions.Throws<ArgumentException>(null, () => cornerRadius.TopRight = value);
}
[Theory]
[MemberData(nameof(ValidDoubles_TestData))]
public void BottomRight_SetValid_GetReturnsExpected(double value)
{
var cornerRadius = new CornerRadius { BottomRight = value };
Assert.Equal(value, cornerRadius.BottomRight);
}
[Theory]
[MemberData(nameof(InvalidDoubles_TestData))]
public void BottomRight_SetInvalid_ThrowsArgumentException(double value)
{
var cornerRadius = new CornerRadius();
AssertExtensions.Throws<ArgumentException>(null, () => cornerRadius.BottomRight = value);
}
[Theory]
[MemberData(nameof(ValidDoubles_TestData))]
public void BottomLeft_SetValid_GetReturnsExpected(double value)
{
var cornerRadius = new CornerRadius { BottomLeft = value };
Assert.Equal(value, cornerRadius.BottomLeft);
}
[Theory]
[MemberData(nameof(InvalidDoubles_TestData))]
public void BottomLeft_SetInvalid_ThrowsArgumentException(double value)
{
var cornerRadius = new CornerRadius();
AssertExtensions.Throws<ArgumentException>(null, () => cornerRadius.BottomLeft = value);
}
public static IEnumerable<object[]> Equals_TestData()
{
yield return new object[] { new CornerRadius(1, 2, 3, 4), new CornerRadius(1, 2, 3, 4), true };
yield return new object[] { new CornerRadius(1, 2, 3, 4), new CornerRadius(2, 2, 3, 4), false };
yield return new object[] { new CornerRadius(1, 2, 3, 4), new CornerRadius(1, 3, 3, 4), false };
yield return new object[] { new CornerRadius(1, 2, 3, 4), new CornerRadius(1, 2, 4, 4), false };
yield return new object[] { new CornerRadius(1, 2, 3, 4), new CornerRadius(1, 2, 3, 5), false };
yield return new object[] { new CornerRadius(1, 2, 3, 4), new object(), false };
yield return new object[] { new CornerRadius(1, 2, 3, 4), null, false };
}
[Theory]
[MemberData(nameof(Equals_TestData))]
public void Equals_Object_ReturnsExpected(CornerRadius cornerRadius, object other, bool expected)
{
Assert.Equal(expected, cornerRadius.Equals(other));
if (other is CornerRadius otherCornerRadius)
{
Assert.Equal(expected, cornerRadius.Equals(otherCornerRadius));
Assert.Equal(expected, cornerRadius == otherCornerRadius);
Assert.Equal(!expected, cornerRadius != otherCornerRadius);
Assert.Equal(expected, cornerRadius.GetHashCode().Equals(otherCornerRadius.GetHashCode()));
}
}
[Fact]
public void ToString_Invoke_ReturnsExpected()
{
var cornerRadius = new CornerRadius(1, 2.2, 3, 4);
Assert.Equal("1,2.2,3,4", cornerRadius.ToString());
}
[Fact]
public void ToString_NaN_ReturnsAuto()
{
CornerRadius cornerRadius = new FakeCornerRadius
{
TopLeft = double.NaN,
TopRight = double.NaN,
BottomRight = double.NaN,
BottomLeft = double.NaN
}.ToActual();
Assert.Equal("Auto,Auto,Auto,Auto", cornerRadius.ToString());
}
public struct FakeCornerRadius
{
public double TopRight;
public double TopLeft;
public double BottomRight;
public double BottomLeft;
public CornerRadius ToActual()
{
CornerRadiusWrapper wrapper = default(CornerRadiusWrapper);
wrapper.Fake = this;
return wrapper.Actual;
}
}
[StructLayout(LayoutKind.Explicit)]
public struct CornerRadiusWrapper
{
[FieldOffset(0)] public CornerRadius Actual;
[FieldOffset(0)] public FakeCornerRadius Fake;
}
}
}

View File

@@ -0,0 +1,173 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using Xunit;
namespace Windows.UI.Xaml.Tests
{
public class DurationTests
{
[Fact]
public void Ctor_Default()
{
var duration = new Duration();
Assert.False(duration.HasTimeSpan);
Assert.Throws<InvalidOperationException>(() => duration.TimeSpan);
}
[Fact]
public void Ctor_TimeSpan()
{
var duration = new Duration(TimeSpan.FromSeconds(2));
Assert.True(duration.HasTimeSpan);
Assert.Equal(TimeSpan.FromSeconds(2), duration.TimeSpan);
}
[Fact]
public void Operator_Duration_ReturnsExpected()
{
Duration duration = TimeSpan.FromSeconds(2);
Assert.True(duration.HasTimeSpan);
Assert.Equal(TimeSpan.FromSeconds(2), duration.TimeSpan);
}
[Fact]
public void Operator_UnaryPlus_ReturnsExpected()
{
Duration duration = +new Duration(TimeSpan.FromSeconds(2));
Assert.True(duration.HasTimeSpan);
Assert.Equal(TimeSpan.FromSeconds(2), duration.TimeSpan);
}
[Fact]
public void Automatic_Get_ReturnsExpected()
{
Duration duration = Duration.Automatic;
Assert.False(duration.HasTimeSpan);
Assert.Throws<InvalidOperationException>(() => duration.TimeSpan);
}
[Fact]
public void Forever_Get_ReturnsExpected()
{
Duration duration = Duration.Forever;
Assert.False(duration.HasTimeSpan);
Assert.Throws<InvalidOperationException>(() => duration.TimeSpan);
}
public static IEnumerable<object[]> Add_TestData()
{
yield return new object[] { Duration.Automatic, Duration.Automatic, Duration.Automatic };
yield return new object[] { Duration.Automatic, Duration.Forever, Duration.Automatic };
yield return new object[] { Duration.Forever, Duration.Forever, Duration.Forever };
yield return new object[] { Duration.Automatic, new Duration(TimeSpan.FromSeconds(2)), Duration.Automatic };
yield return new object[] { Duration.Forever, new Duration(TimeSpan.FromSeconds(2)), Duration.Forever };
yield return new object[] { new Duration(TimeSpan.FromSeconds(1)), new Duration(TimeSpan.FromSeconds(2)), new Duration(TimeSpan.FromSeconds(3)) };
}
[Theory]
[MemberData(nameof(Add_TestData))]
public void Add_Durations_ReturnsExpected(Duration duration1, Duration duration2, Duration expected)
{
Assert.Equal(expected, duration1.Add(duration2));
Assert.Equal(expected, duration1 + duration2);
Assert.Equal(expected, duration2.Add(duration1));
Assert.Equal(expected, duration2 + duration1);
}
public static IEnumerable<object[]> Subtract_TestData()
{
yield return new object[] { Duration.Automatic, Duration.Automatic, Duration.Automatic };
yield return new object[] { Duration.Automatic, Duration.Forever, Duration.Automatic };
yield return new object[] { Duration.Forever, Duration.Automatic, Duration.Automatic };
yield return new object[] { Duration.Forever, Duration.Forever, Duration.Automatic };
yield return new object[] { Duration.Automatic, new Duration(TimeSpan.FromSeconds(2)), Duration.Automatic };
yield return new object[] { Duration.Forever, new Duration(TimeSpan.FromSeconds(2)), Duration.Forever };
yield return new object[] { new Duration(TimeSpan.FromSeconds(3)), new Duration(TimeSpan.FromSeconds(2)), new Duration(TimeSpan.FromSeconds(1)) };
}
[Theory]
[MemberData(nameof(Subtract_TestData))]
public void Subtract_Durations_ReturnsExpected(Duration duration1, Duration duration2, Duration expected)
{
Assert.Equal(expected, duration1.Subtract(duration2));
Assert.Equal(expected, duration1 - duration2);
}
public static IEnumerable<object[]> Compare_TestData()
{
yield return new object[] { new Duration(TimeSpan.FromSeconds(1)), new Duration(TimeSpan.FromSeconds(2)), -1 };
yield return new object[] { new Duration(TimeSpan.FromSeconds(2)), new Duration(TimeSpan.FromSeconds(1)), 1 };
yield return new object[] { new Duration(TimeSpan.FromSeconds(1)), new Duration(TimeSpan.FromSeconds(1)), 0 };
yield return new object[] { new Duration(TimeSpan.FromSeconds(1)), Duration.Automatic, 1 };
yield return new object[] { new Duration(TimeSpan.FromSeconds(2)), Duration.Forever, -1 };
yield return new object[] { Duration.Forever, Duration.Forever, 0 };
yield return new object[] { Duration.Forever, new Duration(TimeSpan.FromSeconds(2)), 1 };
yield return new object[] { Duration.Forever, Duration.Automatic, 1 };
yield return new object[] { Duration.Automatic, Duration.Automatic, 0 };
yield return new object[] { Duration.Automatic, new Duration(TimeSpan.FromSeconds(2)), -1 };
yield return new object[] { Duration.Automatic, Duration.Forever, -1 };
}
[Theory]
[MemberData(nameof(Compare_TestData))]
public void Compare_TestData(Duration duration1, Duration duration2, int expected)
{
bool bothOrNoneAutomatic = (duration1 == Duration.Automatic) == (duration2 == Duration.Automatic);
Assert.Equal(expected, Duration.Compare(duration1, duration2));
Assert.Equal(expected <= 0 && bothOrNoneAutomatic, duration1 <= duration2);
Assert.Equal(expected < 0 && bothOrNoneAutomatic, duration1 < duration2);
Assert.Equal(expected == 0 && bothOrNoneAutomatic, duration1 == duration2);
Assert.Equal(expected != 0, duration1 != duration2);
Assert.Equal(expected >= 0 && bothOrNoneAutomatic, duration1 >= duration2);
Assert.Equal(expected > 0 && bothOrNoneAutomatic, duration1 > duration2);
}
public static IEnumerable<object[]> Equals_TestData()
{
yield return new object[] { new Duration(), new object(), -1 };
yield return new object[] { new Duration(), null, -1 };
}
[Theory]
[MemberData(nameof(Equals_TestData))]
[MemberData(nameof(Compare_TestData))]
public void Equals_Object_ReturnsExpected(Duration duration, object other, int expected)
{
Assert.Equal(expected == 0, duration.Equals(other));
if (other is Duration otherDuration)
{
Assert.Equal(expected == 0, Duration.Equals(duration, otherDuration));
Assert.Equal(expected == 0, duration.Equals(otherDuration));
Assert.Equal(expected == 0, duration.GetHashCode().Equals(otherDuration.GetHashCode()));
}
}
public static IEnumerable<object[]> ToString_TestData()
{
yield return new object[] { Duration.Automatic, "Automatic" };
yield return new object[] { Duration.Forever, "Forever" };
yield return new object[] { new Duration(TimeSpan.FromSeconds(2)), TimeSpan.FromSeconds(2).ToString() };
}
[Theory]
[MemberData(nameof(ToString_TestData))]
public void ToString_Invoke_ReturnsExpected(Duration duration, string expected)
{
Assert.Equal(expected, duration.ToString());
}
}
}

View File

@@ -0,0 +1,124 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using Xunit;
namespace Windows.UI.Xaml.Tests
{
public class GridLengthTests
{
[Fact]
public void Ctor_Default()
{
var gridLength = new GridLength();
Assert.Equal(GridUnitType.Auto, gridLength.GridUnitType);
Assert.False(gridLength.IsAbsolute);
Assert.True(gridLength.IsAuto);
Assert.False(gridLength.IsStar);
Assert.Equal(1, gridLength.Value);
}
[Theory]
[InlineData(0)]
[InlineData(10)]
[InlineData(float.MaxValue)]
public void Ctor_Pixels(double pixels)
{
var gridLength = new GridLength(pixels);
Assert.Equal(GridUnitType.Pixel, gridLength.GridUnitType);
Assert.True(gridLength.IsAbsolute);
Assert.False(gridLength.IsAuto);
Assert.False(gridLength.IsStar);
Assert.Equal(pixels, gridLength.Value);
}
[Theory]
[InlineData(0, GridUnitType.Auto, 1)]
[InlineData(0, GridUnitType.Pixel, 0)]
[InlineData(0, GridUnitType.Star, 0)]
[InlineData(10, GridUnitType.Pixel, 10)]
[InlineData(float.MaxValue, GridUnitType.Star, float.MaxValue)]
public void Ctor_Value_UnitType(double value, GridUnitType unitType, double expectedValue)
{
var gridLength = new GridLength(value, unitType);
Assert.Equal(unitType, gridLength.GridUnitType);
Assert.Equal(unitType == GridUnitType.Pixel, gridLength.IsAbsolute);
Assert.Equal(unitType == GridUnitType.Auto, gridLength.IsAuto);
Assert.Equal(unitType == GridUnitType.Star, gridLength.IsStar);
Assert.Equal(expectedValue, gridLength.Value);
}
[Theory]
[InlineData(-1)]
[InlineData(double.NaN)]
[InlineData(double.PositiveInfinity)]
[InlineData(double.NegativeInfinity)]
public void Ctor_InvalidValue_ThrowsArgumentException(double value)
{
AssertExtensions.Throws<ArgumentException>("value", () => new GridLength(value));
AssertExtensions.Throws<ArgumentException>("value", () => new GridLength(value, GridUnitType.Pixel));
}
[Theory]
[InlineData(GridUnitType.Auto - 1)]
[InlineData(GridUnitType.Star + 1)]
public void Ctor_InvalidUnitType_ThrowsArgumentException(GridUnitType unitType)
{
AssertExtensions.Throws<ArgumentException>("type", () => new GridLength(1, unitType));
}
[Fact]
public void Auto_Get_ReturnsExpected()
{
GridLength gridLength = GridLength.Auto;
Assert.Equal(GridUnitType.Auto, gridLength.GridUnitType);
Assert.False(gridLength.IsAbsolute);
Assert.True(gridLength.IsAuto);
Assert.False(gridLength.IsStar);
Assert.Equal(1, gridLength.Value);
}
public static IEnumerable<object[]> Equals_TestData()
{
yield return new object[] { new GridLength(10, GridUnitType.Pixel), new GridLength(10, GridUnitType.Pixel), true };
yield return new object[] { new GridLength(10, GridUnitType.Pixel), new GridLength(11, GridUnitType.Pixel), false };
yield return new object[] { new GridLength(10, GridUnitType.Pixel), new GridLength(10, GridUnitType.Auto), false };
yield return new object[] { new GridLength(10, GridUnitType.Pixel), new GridLength(10, GridUnitType.Star), false };
yield return new object[] { new GridLength(10, GridUnitType.Auto), GridLength.Auto, true };
yield return new object[] { new GridLength(10, GridUnitType.Pixel), new object(), false };
yield return new object[] { new GridLength(10, GridUnitType.Pixel), null, false };
}
[Theory]
[MemberData(nameof(Equals_TestData))]
public void Equals_Object_ReturnsExpected(GridLength gridLength, object other, bool expected)
{
Assert.Equal(expected, gridLength.Equals(other));
if (other is GridLength otherGridLength)
{
Assert.Equal(expected, gridLength.Equals(otherGridLength));
Assert.Equal(expected, gridLength == otherGridLength);
Assert.Equal(!expected, gridLength != otherGridLength);
Assert.Equal(expected, gridLength.GetHashCode().Equals(otherGridLength.GetHashCode()));
}
}
public static IEnumerable<object[]> ToString_TestData()
{
yield return new object[] { GridLength.Auto, "Auto" };
yield return new object[] { new GridLength(10, GridUnitType.Pixel), "10" };
yield return new object[] { new GridLength(10, GridUnitType.Star), "10*" };
}
[Theory]
[MemberData(nameof(ToString_TestData))]
public void ToString_Invoke_ReturnsExpected(GridLength gridLength, string expected)
{
Assert.Equal(expected, gridLength.ToString());
}
}
}

View File

@@ -0,0 +1,42 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using Xunit;
namespace Windows.UI.Xaml.Tests
{
public class LayoutCycleExceptionTests
{
private const int E_LAYOUTCYCLE = unchecked((int)0x802B0014);
[Fact]
public void Ctor_Default()
{
var exception = new LayoutCycleException();
Assert.NotEmpty(exception.Message);
Assert.Null(exception.InnerException);
Assert.Equal(E_LAYOUTCYCLE, exception.HResult);
}
[Fact]
public void Ctor_Message()
{
var exception = new LayoutCycleException("Message");
Assert.Equal("Message", exception.Message);
Assert.Null(exception.InnerException);
Assert.Equal(E_LAYOUTCYCLE, exception.HResult);
}
[Fact]
public void Ctor_Message_InnerException()
{
var innerException = new Exception();
var exception = new LayoutCycleException("Message", innerException);
Assert.Equal("Message", exception.Message);
Assert.Same(innerException, exception.InnerException);
Assert.Equal(E_LAYOUTCYCLE, exception.HResult);
}
}
}

View File

@@ -0,0 +1,42 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using Xunit;
namespace Windows.UI.Xaml.Markup.Tests
{
public class XamlParseExceptionTests
{
private const int E_XAMLPARSEFAILED = unchecked((int)0x802B000A);
[Fact]
public void Ctor_Default()
{
var exception = new XamlParseException();
Assert.NotEmpty(exception.Message);
Assert.Null(exception.InnerException);
Assert.Equal(E_XAMLPARSEFAILED, exception.HResult);
}
[Fact]
public void Ctor_Message()
{
var exception = new XamlParseException("Message");
Assert.Equal("Message", exception.Message);
Assert.Null(exception.InnerException);
Assert.Equal(E_XAMLPARSEFAILED, exception.HResult);
}
[Fact]
public void Ctor_Message_InnerException()
{
var innerException = new Exception();
var exception = new XamlParseException("Message", innerException);
Assert.Equal("Message", exception.Message);
Assert.Same(innerException, exception.InnerException);
Assert.Equal(E_XAMLPARSEFAILED, exception.HResult);
}
}
}

View File

@@ -0,0 +1,85 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using Xunit;
namespace Windows.UI.Xaml.Media.Animation.Tests
{
public class KeyTimeTests
{
[Fact]
public void Ctor_Default()
{
var keyTime = new KeyTime();
Assert.Equal(TimeSpan.Zero, keyTime.TimeSpan);
}
[Theory]
[InlineData(0)]
[InlineData(1)]
public void FromTimeSpan_ValidTimeSpan_ReturnsExpected(int seconds)
{
KeyTime keyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(seconds));
Assert.Equal(TimeSpan.FromSeconds(seconds), keyTime.TimeSpan);
}
[Fact]
public void FromTimeSpan_NegativeTimeSpan_ThrowsArgumentOutOfRangeException()
{
AssertExtensions.Throws<ArgumentOutOfRangeException>("timeSpan", () => KeyTime.FromTimeSpan(TimeSpan.FromTicks(-1)));
}
[Fact]
public void Operator_ValidTimeSpan_ReturnsExpected()
{
KeyTime keyTime = TimeSpan.FromSeconds(2);
Assert.Equal(TimeSpan.FromSeconds(2), keyTime);
}
[Fact]
public void Operator_NegativeTimeSpan_ThrowsArgumentOutOfRangeException()
{
TimeSpan timeSpan = TimeSpan.FromTicks(-1);
AssertExtensions.Throws<ArgumentOutOfRangeException>("timeSpan", () => (KeyTime)timeSpan);
}
public static IEnumerable<object[]> Equals_TestData()
{
yield return new object[] { KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2)), KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2)), true };
yield return new object[] { KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2)), KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)), false };
yield return new object[] { KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2)), new object(), false };
yield return new object[] { KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2)), null, false };
}
[Theory]
[MemberData(nameof(Equals_TestData))]
public void Equals_Object_ReturnsExpected(KeyTime keyTime, object other, bool expected)
{
Assert.Equal(expected, keyTime.Equals(other));
if (other is KeyTime otherKeyTime)
{
Assert.Equal(expected, keyTime.Equals(otherKeyTime));
Assert.Equal(expected, keyTime == otherKeyTime);
Assert.Equal(!expected, keyTime != otherKeyTime);
Assert.Equal(expected, keyTime.GetHashCode().Equals(otherKeyTime.GetHashCode()));
}
}
public static IEnumerable<object[]> ToString_TestData()
{
yield return new object[] { new KeyTime(), TimeSpan.Zero.ToString() };
yield return new object[] { KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2)), TimeSpan.FromSeconds(2).ToString() };
}
[Theory]
[MemberData(nameof(ToString_TestData))]
public void ToString_Invoke_ReturnsExpected(KeyTime keyTime, string expected)
{
Assert.Equal(expected, keyTime.ToString());
}
}
}

View File

@@ -0,0 +1,215 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Globalization;
using Xunit;
namespace Windows.UI.Xaml.Media.Animation.Tests
{
public class RepeatBehaviorTests
{
[Fact]
public void Ctor_Default()
{
var repeatBehaviour = new RepeatBehavior();
Assert.True(repeatBehaviour.HasCount);
Assert.Equal(0, repeatBehaviour.Count);
Assert.False(repeatBehaviour.HasDuration);
Assert.Equal(TimeSpan.Zero, repeatBehaviour.Duration);
Assert.Equal(RepeatBehaviorType.Count, repeatBehaviour.Type);
}
[Theory]
[InlineData(0)]
[InlineData(10)]
[InlineData(double.MaxValue)]
public void Ctor_Count(double count)
{
var repeatBehaviour = new RepeatBehavior(count);
Assert.True(repeatBehaviour.HasCount);
Assert.Equal(count, repeatBehaviour.Count);
Assert.False(repeatBehaviour.HasDuration);
Assert.Equal(TimeSpan.Zero, repeatBehaviour.Duration);
Assert.Equal(RepeatBehaviorType.Count, repeatBehaviour.Type);
Assert.Equal(count.GetHashCode(), repeatBehaviour.GetHashCode());
}
[Theory]
[InlineData(-1)]
[InlineData(double.NaN)]
[InlineData(double.PositiveInfinity)]
[InlineData(double.NegativeInfinity)]
public void Ctor_InvalidCount_ThrowsArgumentOutOfRangeException(double count)
{
AssertExtensions.Throws<ArgumentOutOfRangeException>("count", () => new RepeatBehavior(count));
}
[Theory]
[InlineData(0)]
[InlineData(1)]
public void Ctor_TimeSpan(int seconds)
{
var repeatBehaviour = new RepeatBehavior(TimeSpan.FromSeconds(seconds));
Assert.False(repeatBehaviour.HasCount);
Assert.Equal(0, repeatBehaviour.Count);
Assert.True(repeatBehaviour.HasDuration);
Assert.Equal(TimeSpan.FromSeconds(seconds), repeatBehaviour.Duration);
Assert.Equal(RepeatBehaviorType.Duration, repeatBehaviour.Type);
Assert.Equal(TimeSpan.FromSeconds(seconds).GetHashCode(), repeatBehaviour.GetHashCode());
}
[Fact]
public void Ctor_NegativeTimeSpan_ThrowsArgumentOutOfRangeException()
{
AssertExtensions.Throws<ArgumentOutOfRangeException>("duration", () => new RepeatBehavior(TimeSpan.FromTicks(-1)));
}
[Fact]
public void Forever_Get_ReturnsExpected()
{
RepeatBehavior forever = RepeatBehavior.Forever;
Assert.False(forever.HasCount);
Assert.Equal(0, forever.Count);
Assert.False(forever.HasDuration);
Assert.Equal(TimeSpan.Zero, forever.Duration);
Assert.Equal(RepeatBehaviorType.Forever, forever.Type);
Assert.Equal(int.MaxValue - 42, forever.GetHashCode());
}
[Theory]
[InlineData(-1)]
[InlineData(0)]
[InlineData(10)]
[InlineData(double.MaxValue)]
[InlineData(double.NaN)]
[InlineData(double.PositiveInfinity)]
[InlineData(double.NegativeInfinity)]
public void Count_Set_GetReturnsExpected(double value)
{
var repeatBehaviour = new RepeatBehavior(TimeSpan.MaxValue) { Count = value };
Assert.False(repeatBehaviour.HasCount);
Assert.Equal(value, repeatBehaviour.Count);
// Although we set a count, the type is unchanged.
Assert.Equal(RepeatBehaviorType.Duration, repeatBehaviour.Type);
}
[Theory]
[InlineData(0)]
[InlineData(1)]
[InlineData(-1)]
public void Duration_Set_GetReturnsExpected(int seconds)
{
var repeatBehaviour = new RepeatBehavior(1) { Duration = TimeSpan.FromSeconds(seconds) };
Assert.False(repeatBehaviour.HasDuration);
Assert.Equal(TimeSpan.FromSeconds(seconds), repeatBehaviour.Duration);
// Although we set a duration, the type is unchanged.
Assert.Equal(RepeatBehaviorType.Count, repeatBehaviour.Type);
}
[Theory]
[InlineData(RepeatBehaviorType.Count - 1)]
[InlineData(RepeatBehaviorType.Count)]
[InlineData(RepeatBehaviorType.Duration)]
[InlineData(RepeatBehaviorType.Forever)]
[InlineData(RepeatBehaviorType.Forever + 1)]
public void Type_Set_GetReturnsExpected(RepeatBehaviorType type)
{
var repeatBehaviour = new RepeatBehavior(1) { Type = type };
Assert.Equal(type == RepeatBehaviorType.Count, repeatBehaviour.HasCount);
Assert.Equal(type == RepeatBehaviorType.Duration, repeatBehaviour.HasDuration);
}
public static IEnumerable<object[]> Equals_TestData()
{
yield return new object[] { new RepeatBehavior(2), new RepeatBehavior(2), true };
yield return new object[] { new RepeatBehavior(2), new RepeatBehavior(1), false };
yield return new object[] { new RepeatBehavior(2), RepeatBehavior.Forever, false };
yield return new object[] { new RepeatBehavior(2), new RepeatBehavior(TimeSpan.FromSeconds(2)), false };
yield return new object[] { new RepeatBehavior(TimeSpan.FromSeconds(2)), new RepeatBehavior(TimeSpan.FromSeconds(2)), true };
yield return new object[] { new RepeatBehavior(TimeSpan.FromSeconds(2)), new RepeatBehavior(TimeSpan.FromSeconds(1)), false };
yield return new object[] { new RepeatBehavior(TimeSpan.FromSeconds(2)), RepeatBehavior.Forever, false };
yield return new object[] { new RepeatBehavior(TimeSpan.FromSeconds(2)), new RepeatBehavior(2), false };
yield return new object[] { RepeatBehavior.Forever, RepeatBehavior.Forever, true };
yield return new object[] { RepeatBehavior.Forever, new RepeatBehavior(TimeSpan.FromSeconds(2)), false };
yield return new object[] { RepeatBehavior.Forever, new RepeatBehavior(2), false };
yield return new object[] { new RepeatBehavior { Type = RepeatBehaviorType.Count - 1 }, new RepeatBehavior { Type = RepeatBehaviorType.Count - 1 }, false };
yield return new object[] { new RepeatBehavior { Type = RepeatBehaviorType.Forever + 1 }, new RepeatBehavior { Type = RepeatBehaviorType.Count + 1 }, false };
yield return new object[] { new RepeatBehavior(TimeSpan.FromSeconds(2)), new object(), false };
yield return new object[] { new RepeatBehavior(TimeSpan.FromSeconds(2)), null, false };
}
[Theory]
[MemberData(nameof(Equals_TestData))]
public void Equals_Object_ReturnsExpected(RepeatBehavior repeatBehaviour, object other, bool expected)
{
Assert.Equal(expected, repeatBehaviour.Equals(other));
if (other is RepeatBehavior otherRepeatBehaviour)
{
Assert.Equal(expected, RepeatBehavior.Equals(repeatBehaviour, otherRepeatBehaviour));
Assert.Equal(expected, repeatBehaviour.Equals(otherRepeatBehaviour));
Assert.Equal(expected, repeatBehaviour == otherRepeatBehaviour);
Assert.Equal(!expected, repeatBehaviour != otherRepeatBehaviour);
if (repeatBehaviour.Type >= RepeatBehaviorType.Count && repeatBehaviour.Type <= RepeatBehaviorType.Forever)
{
Assert.Equal(expected, repeatBehaviour.GetHashCode().Equals(otherRepeatBehaviour.GetHashCode()));
}
else if (repeatBehaviour.Type == otherRepeatBehaviour.Type)
{
Assert.Equal(repeatBehaviour.GetHashCode(), otherRepeatBehaviour.GetHashCode());
}
}
}
public static IEnumerable<object[]> ToString_TestData()
{
yield return new object[] { RepeatBehavior.Forever, null, null, "Forever" };
yield return new object[] { RepeatBehavior.Forever, "InvalidFormat", CultureInfo.CurrentCulture, "Forever" };
yield return new object[] { new RepeatBehavior(TimeSpan.FromSeconds(2)), null, null, TimeSpan.FromSeconds(2).ToString() };
yield return new object[] { new RepeatBehavior(TimeSpan.FromSeconds(2)), "InvalidFormat", CultureInfo.CurrentCulture, TimeSpan.FromSeconds(2).ToString() };
var culture = new CultureInfo("en-US");
culture.NumberFormat.NumberDecimalSeparator = "|";
yield return new object[] { new RepeatBehavior(2.2), "abc", culture, "abcx" };
yield return new object[] { new RepeatBehavior(2.2), "N4", culture, "2|2000x" };
yield return new object[] { new RepeatBehavior(2.2), null, culture, "2|2x" };
yield return new object[] { new RepeatBehavior(2.2), null, null, $"{2.2.ToString()}x" };
}
[Theory]
[MemberData(nameof(ToString_TestData))]
public void ToString_Invoke_ReturnsExpected(RepeatBehavior keyTime, string format, IFormatProvider formatProvider, string expected)
{
if (format == null)
{
if (formatProvider == null)
{
Assert.Equal(expected, keyTime.ToString());
}
Assert.Equal(expected, keyTime.ToString(formatProvider));
}
Assert.Equal(expected, ((IFormattable)keyTime).ToString(format, formatProvider));
}
}
}

View File

@@ -0,0 +1,368 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Globalization;
using Windows.Foundation;
using Xunit;
namespace Windows.UI.Xaml.Media.Media3D.Tests
{
public class Matrix3DTests
{
[Fact]
public void Ctor_Default()
{
var matrix = new Matrix3D();
Assert.Equal(0, matrix.M11);
Assert.Equal(0, matrix.M12);
Assert.Equal(0, matrix.M13);
Assert.Equal(0, matrix.M14);
Assert.Equal(0, matrix.M21);
Assert.Equal(0, matrix.M22);
Assert.Equal(0, matrix.M23);
Assert.Equal(0, matrix.M24);
Assert.Equal(0, matrix.M31);
Assert.Equal(0, matrix.M32);
Assert.Equal(0, matrix.M33);
Assert.Equal(0, matrix.M34);
Assert.Equal(0, matrix.OffsetX);
Assert.Equal(0, matrix.OffsetY);
Assert.Equal(0, matrix.OffsetZ);
Assert.Equal(0, matrix.M44);
Assert.False(matrix.IsIdentity);
}
[Theory]
[InlineData(-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, false, false)]
[InlineData(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false, false)]
[InlineData(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, false, false)]
[InlineData(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, true, true)]
[InlineData(1, 2, 0, 0, 0, 1, 2, 0, 4, 0, 1, 2, 0, 4, 0, 1, false, true)]
[InlineData(double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, false, true)]
[InlineData(double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, false, true)]
[InlineData(double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, false, true)]
public void Ctor_Values(double m11, double m12, double m13, double m14,
double m21, double m22, double m23, double m24,
double m31, double m32, double m33, double m34,
double offsetX, double offsetY, double offsetZ, double m44, bool expectedIsIdentity, bool expectedHasInverse)
{
var matrix = new Matrix3D(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, offsetX, offsetY, offsetZ, m44);
Assert.Equal(m11, matrix.M11);
Assert.Equal(m12, matrix.M12);
Assert.Equal(m13, matrix.M13);
Assert.Equal(m14, matrix.M14);
Assert.Equal(m21, matrix.M21);
Assert.Equal(m22, matrix.M22);
Assert.Equal(m23, matrix.M23);
Assert.Equal(m24, matrix.M24);
Assert.Equal(m31, matrix.M31);
Assert.Equal(m32, matrix.M32);
Assert.Equal(m33, matrix.M33);
Assert.Equal(m34, matrix.M34);
Assert.Equal(offsetX, matrix.OffsetX);
Assert.Equal(offsetY, matrix.OffsetY);
Assert.Equal(offsetZ, matrix.OffsetZ);
Assert.Equal(m44, matrix.M44);
Assert.Equal(expectedIsIdentity, matrix.IsIdentity);
Assert.Equal(expectedHasInverse, matrix.HasInverse);
}
[Fact]
public void Identity_Get_ReturnsExpected()
{
Matrix3D matrix = Matrix3D.Identity;
Assert.Equal(1, matrix.M11);
Assert.Equal(0, matrix.M12);
Assert.Equal(0, matrix.M13);
Assert.Equal(0, matrix.M14);
Assert.Equal(0, matrix.M21);
Assert.Equal(1, matrix.M22);
Assert.Equal(0, matrix.M23);
Assert.Equal(0, matrix.M24);
Assert.Equal(0, matrix.M31);
Assert.Equal(0, matrix.M32);
Assert.Equal(1, matrix.M33);
Assert.Equal(0, matrix.M34);
Assert.Equal(0, matrix.OffsetX);
Assert.Equal(0, matrix.OffsetY);
Assert.Equal(0, matrix.OffsetZ);
Assert.Equal(1, matrix.M44);
Assert.True(matrix.IsIdentity);
Assert.True(matrix.HasInverse);
}
public static IEnumerable<object[]> Values_TestData()
{
yield return new object[] { -1 };
yield return new object[] { 0 };
yield return new object[] { 1 };
yield return new object[] { float.NaN };
yield return new object[] { float.PositiveInfinity };
yield return new object[] { float.NegativeInfinity };
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void M11_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix3D { M11 = value };
Assert.Equal(value, matrix.M11);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void M12_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix3D { M12 = value };
Assert.Equal(value, matrix.M12);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void M13_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix3D { M13 = value };
Assert.Equal(value, matrix.M13);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void M14_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix3D { M14 = value };
Assert.Equal(value, matrix.M14);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void M21_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix3D { M21 = value };
Assert.Equal(value, matrix.M21);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void M22_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix3D { M22 = value };
Assert.Equal(value, matrix.M22);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void M23_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix3D { M23 = value };
Assert.Equal(value, matrix.M23);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void M24_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix3D { M24 = value };
Assert.Equal(value, matrix.M24);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void M31_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix3D { M31 = value };
Assert.Equal(value, matrix.M31);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void M32_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix3D { M32 = value };
Assert.Equal(value, matrix.M32);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void M33_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix3D { M33 = value };
Assert.Equal(value, matrix.M33);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void M34_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix3D { M34 = value };
Assert.Equal(value, matrix.M34);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void OffsetX_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix3D { OffsetX = value };
Assert.Equal(value, matrix.OffsetX);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void OffsetY_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix3D { OffsetY = value };
Assert.Equal(value, matrix.OffsetY);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void OffsetZ_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix3D { OffsetZ = value };
Assert.Equal(value, matrix.OffsetZ);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void M44_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix3D { M44 = value };
Assert.Equal(value, matrix.M44);
}
public static IEnumerable<object[]> Equals_TestData()
{
var matrix = new Matrix3D(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
yield return new object[] { matrix, new Matrix3D(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), true };
yield return new object[] { matrix, new Matrix3D(2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), false };
yield return new object[] { matrix, new Matrix3D(1, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), false };
yield return new object[] { matrix, new Matrix3D(1, 2, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), false };
yield return new object[] { matrix, new Matrix3D(1, 2, 3, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), false };
yield return new object[] { matrix, new Matrix3D(1, 2, 3, 4, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), false };
yield return new object[] { matrix, new Matrix3D(1, 2, 3, 4, 5, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), false };
yield return new object[] { matrix, new Matrix3D(1, 2, 3, 4, 5, 6, 8, 8, 9, 10, 11, 12, 13, 14, 15, 16), false };
yield return new object[] { matrix, new Matrix3D(1, 2, 3, 4, 5, 6, 7, 9, 9, 10, 11, 12, 13, 14, 15, 16), false };
yield return new object[] { matrix, new Matrix3D(1, 2, 3, 4, 5, 6, 7, 8, 10, 10, 11, 12, 13, 14, 15, 16), false };
yield return new object[] { matrix, new Matrix3D(1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 11, 12, 13, 14, 15, 16), false };
yield return new object[] { matrix, new Matrix3D(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 12, 13, 14, 15, 16), false };
yield return new object[] { matrix, new Matrix3D(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 13, 14, 15, 16), false };
yield return new object[] { matrix, new Matrix3D(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 14, 15, 16), false };
yield return new object[] { matrix, new Matrix3D(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 15, 16), false };
yield return new object[] { matrix, new Matrix3D(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 16), false };
yield return new object[] { matrix, new Matrix3D(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17), false };
yield return new object[] { Matrix3D.Identity, Matrix3D.Identity, true };
yield return new object[] { Matrix3D.Identity, new Matrix3D(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1), true };
yield return new object[] { Matrix3D.Identity, new Matrix3D(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1), false };
yield return new object[] { Matrix3D.Identity, new object(), false };
yield return new object[] { Matrix3D.Identity, null, false };
}
[Theory]
[MemberData(nameof(Equals_TestData))]
public void Equals_Object_ReturnsExpected(Matrix3D matrix, object other, bool expected)
{
Assert.Equal(expected, matrix.Equals(other));
if (other is Matrix3D otherMatrix)
{
Assert.Equal(expected, matrix.Equals(otherMatrix));
Assert.Equal(expected, matrix == otherMatrix);
Assert.Equal(!expected, matrix != otherMatrix);
Assert.Equal(expected, matrix.GetHashCode().Equals(otherMatrix.GetHashCode()));
}
}
[Fact]
public void Multiply_Matrices_ReturnsExpected()
{
var matrix1 = new Matrix3D(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
var matrix2 = new Matrix3D(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
Matrix3D result = matrix1 * matrix2;
Assert.Equal(new Matrix3D(90, 100, 110, 120, 202, 228, 254, 280, 314, 356, 398, 440, 426, 484, 542, 600), result);
Assert.False(result.IsIdentity);
Assert.False(result.HasInverse);
}
[Fact]
public void Invert_Affine_ReturnsExpected()
{
var matrix = new Matrix3D(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
matrix.Invert();
Assert.Equal(new Matrix3D(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1), matrix);
}
[Fact]
public void Invert_NonAffine_ReturnsExpected()
{
var matrix = new Matrix3D(1, 2, 0, 0, 0, 1, 2, 0, 4, 0, 1, 2, 0, 4, 0, 1);
matrix.Invert();
string expected = ((IFormattable)new Matrix3D(0.515151515151515, -0.0606060606060606, 0.121212121212121, -0.242424242424242, 0.242424242424242, 0.0303030303030303, -0.0606060606060606, 0.121212121212121, -0.121212121212121, 0.484848484848485, 0.0303030303030303, -0.0606060606060606, -0.96969696969697, -0.121212121212121, 0.242424242424242, 0.515151515151515)).ToString("N2", null);
Assert.Equal(expected, ((IFormattable)matrix).ToString("N2", null));
}
[Fact]
public void Invert_NotInvertible_ThrowsInvalidOperationException()
{
var matrix = new Matrix3D(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
Assert.Throws<InvalidOperationException>(() => matrix.Invert());
}
[Fact]
public void Invert_AffineNotInvertible_ThrowsInvalidOperationException()
{
var matrix = new Matrix3D(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
Assert.Throws<InvalidOperationException>(() => matrix.Invert());
}
public static IEnumerable<object[]> ToString_TestData()
{
string cultureSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
char decimalSeparator = cultureSeparator.Length > 0 && cultureSeparator[0] == ',' ? ';' : ',';
yield return new object[] { Matrix3D.Identity, null, null, "Identity" };
yield return new object[] { Matrix3D.Identity, "InvalidFormat", CultureInfo.CurrentCulture, "Identity" };
yield return new object[] { new Matrix3D(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), null, null, $"1{decimalSeparator}2{decimalSeparator}3{decimalSeparator}4{decimalSeparator}5{decimalSeparator}6{decimalSeparator}7{decimalSeparator}8{decimalSeparator}9{decimalSeparator}10{decimalSeparator}11{decimalSeparator}12{decimalSeparator}13{decimalSeparator}14{decimalSeparator}15{decimalSeparator}16" };
var matrix = new Matrix3D(2.2, 2.2, 2.2, 2.2, 2.2, 2.2, 2.2, 2.2, 2.2, 2.2, 2.2, 2.2, 2.2, 2.2, 2.2, 2.2);
var culture = new CultureInfo("en-US");
culture.NumberFormat.NumberDecimalSeparator = "|";
yield return new object[] { matrix, "abc", culture, "abc,abc,abc,abc,abc,abc,abc,abc,abc,abc,abc,abc,abc,abc,abc,abc" };
yield return new object[] { matrix, "N4", culture, "2|2000,2|2000,2|2000,2|2000,2|2000,2|2000,2|2000,2|2000,2|2000,2|2000,2|2000,2|2000,2|2000,2|2000,2|2000,2|2000" };
yield return new object[] { matrix, null, culture, "2|2,2|2,2|2,2|2,2|2,2|2,2|2,2|2,2|2,2|2,2|2,2|2,2|2,2|2,2|2,2|2" };
var commaCulture = new CultureInfo("en-US");
commaCulture.NumberFormat.NumberDecimalSeparator = ",";
yield return new object[] { matrix, null, commaCulture, "2,2;2,2;2,2;2,2;2,2;2,2;2,2;2,2;2,2;2,2;2,2;2,2;2,2;2,2;2,2;2,2" };
yield return new object[] { matrix, null, null, $"{2.2.ToString()}{decimalSeparator}{2.2.ToString()}{decimalSeparator}{2.2.ToString()}{decimalSeparator}{2.2.ToString()}{decimalSeparator}{2.2.ToString()}{decimalSeparator}{2.2.ToString()}{decimalSeparator}{2.2.ToString()}{decimalSeparator}{2.2.ToString()}{decimalSeparator}{2.2.ToString()}{decimalSeparator}{2.2.ToString()}{decimalSeparator}{2.2.ToString()}{decimalSeparator}{2.2.ToString()}{decimalSeparator}{2.2.ToString()}{decimalSeparator}{2.2.ToString()}{decimalSeparator}{2.2.ToString()}{decimalSeparator}{2.2.ToString()}" };
}
[Theory]
[MemberData(nameof(ToString_TestData))]
public void ToString_Invoke_ReturnsExpected(Matrix3D matrix, string format, IFormatProvider formatProvider, string expected)
{
if (format == null)
{
if (formatProvider == null)
{
Assert.Equal(expected, matrix.ToString());
}
Assert.Equal(expected, matrix.ToString(formatProvider));
}
Assert.Equal(expected, ((IFormattable)matrix).ToString(format, formatProvider));
}
}
}

View File

@@ -0,0 +1,211 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using Windows.Foundation;
using Xunit;
namespace Windows.UI.Xaml.Media.Tests
{
public class MatrixTests
{
[Fact]
public void Ctor_Default()
{
var matrix = new Matrix();
Assert.Equal(0, matrix.M11);
Assert.Equal(0, matrix.M12);
Assert.Equal(0, matrix.M21);
Assert.Equal(0, matrix.M22);
Assert.Equal(0, matrix.OffsetX);
Assert.Equal(0, matrix.OffsetY);
Assert.False(matrix.IsIdentity);
}
[Theory]
[InlineData(-1, -2, -3, -4, -5, -6, false)]
[InlineData(0, 0, 0, 0, 0, 0, false)]
[InlineData(1, 1, 1, 1, 1, 1, false)]
[InlineData(1, 0, 0, 1, 0, 0, true)]
[InlineData(double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, false)]
[InlineData(double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, false)]
[InlineData(double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, false)]
public void Ctor_Values(double m11, double m12, double m21, double m22, double offsetX, double offsetY, bool expectedIsIdentity)
{
var matrix = new Matrix(m11, m12, m21, m22, offsetX, offsetY);
Assert.Equal(m11, matrix.M11);
Assert.Equal(m12, matrix.M12);
Assert.Equal(m21, matrix.M21);
Assert.Equal(m22, matrix.M22);
Assert.Equal(offsetX, matrix.OffsetX);
Assert.Equal(offsetY, matrix.OffsetY);
Assert.Equal(expectedIsIdentity, matrix.IsIdentity);
}
[Fact]
public void Identity_Get_ReturnsExpected()
{
Matrix matrix = Matrix.Identity;
Assert.Equal(1, matrix.M11);
Assert.Equal(0, matrix.M12);
Assert.Equal(0, matrix.M21);
Assert.Equal(1, matrix.M22);
Assert.Equal(0, matrix.OffsetX);
Assert.Equal(0, matrix.OffsetY);
Assert.True(matrix.IsIdentity);
}
public static IEnumerable<object[]> Values_TestData()
{
yield return new object[] { -1 };
yield return new object[] { 0 };
yield return new object[] { 1 };
yield return new object[] { float.NaN };
yield return new object[] { float.PositiveInfinity };
yield return new object[] { float.NegativeInfinity };
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void M11_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix { M11 = value };
Assert.Equal(value, matrix.M11);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void M12_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix { M12 = value };
Assert.Equal(value, matrix.M12);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void M21_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix { M21 = value };
Assert.Equal(value, matrix.M21);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void M22_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix { M22 = value };
Assert.Equal(value, matrix.M22);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void OffsetX_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix { OffsetX = value };
Assert.Equal(value, matrix.OffsetX);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void OffsetY_Set_GetReturnsExpected(double value)
{
var matrix = new Matrix { OffsetY = value };
Assert.Equal(value, matrix.OffsetY);
}
[Fact]
public void Transform_Identity_ReturnsPoint()
{
Point transformedPoint = Matrix.Identity.Transform(new Point(1, 2));
Assert.Equal(new Point(1, 2), transformedPoint);
}
[Fact]
public void Transform_Point_ReturnsExpected()
{
var matrix = new Matrix(1, 2, 3, 4, 5, 6);
var point = new Point(1, 2);
Point transformedPoint = matrix.Transform(point);
Assert.Equal(new Point(12, 16), transformedPoint);
}
public static IEnumerable<object[]> Equals_TestData()
{
yield return new object[] { new Matrix(1, 2, 3, 4, 5, 6), new Matrix(1, 2, 3, 4, 5, 6), true };
yield return new object[] { new Matrix(1, 2, 3, 4, 5, 6), new Matrix(2, 2, 3, 4, 5, 6), false };
yield return new object[] { new Matrix(1, 2, 3, 4, 5, 6), new Matrix(1, 3, 3, 4, 5, 6), false };
yield return new object[] { new Matrix(1, 2, 3, 4, 5, 6), new Matrix(1, 2, 4, 4, 5, 6), false };
yield return new object[] { new Matrix(1, 2, 3, 4, 5, 6), new Matrix(1, 2, 3, 5, 5, 6), false };
yield return new object[] { new Matrix(1, 2, 3, 4, 5, 6), new Matrix(1, 2, 3, 4, 6, 6), false };
yield return new object[] { new Matrix(1, 2, 3, 4, 5, 6), new Matrix(1, 2, 3, 4, 5, 7), false };
yield return new object[] { Matrix.Identity, Matrix.Identity, true };
yield return new object[] { Matrix.Identity, new Matrix(1, 0, 0, 1, 0, 0), true };
yield return new object[] { Matrix.Identity, new Matrix(1, 0, 0, 0, 0, 0), false };
yield return new object[] { new Matrix(1, 2, 3, 4, 5, 6), new object(), false };
yield return new object[] { new Matrix(1, 2, 3, 4, 5, 6), null, false };
}
[Theory]
[MemberData(nameof(Equals_TestData))]
public void Equals_Object_ReturnsExpected(Matrix matrix, object other, bool expected)
{
Assert.Equal(expected, matrix.Equals(other));
if (other is Matrix otherMatrix)
{
Assert.Equal(expected, matrix.Equals(otherMatrix));
Assert.Equal(expected, matrix == otherMatrix);
Assert.Equal(!expected, matrix != otherMatrix);
Assert.Equal(expected, matrix.GetHashCode().Equals(otherMatrix.GetHashCode()));
}
}
public static IEnumerable<object[]> ToString_TestData()
{
string cultureSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
char decimalSeparator = cultureSeparator.Length > 0 && cultureSeparator[0] == ',' ? ';' : ',';
yield return new object[] { Matrix.Identity, null, null, "Identity" };
yield return new object[] { Matrix.Identity, "InvalidFormat", CultureInfo.CurrentCulture, "Identity" };
yield return new object[] { new Matrix(1, 2, 3, 4, 5, 6), null, null, $"1{decimalSeparator}2{decimalSeparator}3{decimalSeparator}4{decimalSeparator}5{decimalSeparator}6" };
var culture = new CultureInfo("en-US");
culture.NumberFormat.NumberDecimalSeparator = "|";
yield return new object[] { new Matrix(2.2, 2.2, 2.2, 2.2, 2.2, 2.2), "abc", culture, "abc,abc,abc,abc,abc,abc" };
yield return new object[] { new Matrix(2.2, 2.2, 2.2, 2.2, 2.2, 2.2), "N4", culture, "2|2000,2|2000,2|2000,2|2000,2|2000,2|2000" };
yield return new object[] { new Matrix(2.2, 2.2, 2.2, 2.2, 2.2, 2.2), null, culture, "2|2,2|2,2|2,2|2,2|2,2|2" };
var commaCulture = new CultureInfo("en-US");
commaCulture.NumberFormat.NumberDecimalSeparator = ",";
yield return new object[] { new Matrix(2.2, 2.2, 2.2, 2.2, 2.2, 2.2), null, commaCulture, "2,2;2,2;2,2;2,2;2,2;2,2" };
yield return new object[] { new Matrix(2.2, 2.2, 2.2, 2.2, 2.2, 2.2), null, null, $"{2.2.ToString()}{decimalSeparator}{2.2.ToString()}{decimalSeparator}{2.2.ToString()}{decimalSeparator}{2.2.ToString()}{decimalSeparator}{2.2.ToString()}{decimalSeparator}{2.2.ToString()}" };
}
[Theory]
[MemberData(nameof(ToString_TestData))]
public void ToString_Invoke_ReturnsExpected(Matrix matrix, string format, IFormatProvider formatProvider, string expected)
{
if (format == null)
{
if (formatProvider == null)
{
Assert.Equal(expected, matrix.ToString());
}
Assert.Equal(expected, matrix.ToString(formatProvider));
}
Assert.Equal(expected, ((IFormattable)matrix).ToString(format, formatProvider));
}
}
}

View File

@@ -0,0 +1,161 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Xunit;
namespace Windows.UI.Xaml.Tests
{
public class ThicknessTests
{
[Fact]
public void Ctor_Default()
{
var thickness = new Thickness();
Assert.Equal(0, thickness.Left);
Assert.Equal(0, thickness.Top);
Assert.Equal(0, thickness.Right);
Assert.Equal(0, thickness.Bottom);
}
public static IEnumerable<object[]> Values_TestData()
{
yield return new object[] { -1 };
yield return new object[] { 0 };
yield return new object[] { 1 };
yield return new object[] { double.MaxValue };
yield return new object[] { double.NaN };
yield return new object[] { double.PositiveInfinity };
yield return new object[] { double.NegativeInfinity };
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void Ctor_Default(double uniformLength)
{
var thickness = new Thickness(uniformLength);
Assert.Equal(uniformLength, thickness.Left);
Assert.Equal(uniformLength, thickness.Top);
Assert.Equal(uniformLength, thickness.Right);
Assert.Equal(uniformLength, thickness.Bottom);
}
[Theory]
[InlineData(-1, -2, -3, -4)]
[InlineData(0, 0, 0, 0)]
[InlineData(1, 2, 3, 4)]
[InlineData(double.NaN, double.NaN, double.NaN, double.NaN)]
[InlineData(double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity)]
[InlineData(double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity)]
public void Ctor_Left_Top_Right_Bottom(double left, double top, double right, double bottom)
{
var thickness = new Thickness(left, top, right, bottom);
Assert.Equal(left, thickness.Left);
Assert.Equal(top, thickness.Top);
Assert.Equal(right, thickness.Right);
Assert.Equal(bottom, thickness.Bottom);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void Left_Set_GetReturnsExpected(double value)
{
var thickness = new Thickness { Left = value };
Assert.Equal(value, thickness.Left);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void Top_Set_GetReturnsExpected(double value)
{
var thickness = new Thickness { Top = value };
Assert.Equal(value, thickness.Top);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void Right_Set_GetReturnsExpected(double value)
{
var thickness = new Thickness { Right = value };
Assert.Equal(value, thickness.Right);
}
[Theory]
[MemberData(nameof(Values_TestData))]
public void Bottom_Set_GetReturnsExpected(double value)
{
var cornerRadius = new Thickness { Bottom = value };
Assert.Equal(value, cornerRadius.Bottom);
}
public static IEnumerable<object[]> Equals_TestData()
{
yield return new object[] { new Thickness(1, 2, 3, 4), new Thickness(1, 2, 3, 4), true };
yield return new object[] { new Thickness(1, 2, 3, 4), new Thickness(2, 2, 3, 4), false };
yield return new object[] { new Thickness(1, 2, 3, 4), new Thickness(1, 3, 3, 4), false };
yield return new object[] { new Thickness(1, 2, 3, 4), new Thickness(1, 2, 4, 4), false };
yield return new object[] { new Thickness(1, 2, 3, 4), new Thickness(1, 2, 3, 5), false };
yield return new object[] { new Thickness(1, 2, 3, 4), new object(), false };
yield return new object[] { new Thickness(1, 2, 3, 4), null, false };
}
[Theory]
[MemberData(nameof(Equals_TestData))]
public void Equals_Object_ReturnsExpected(Thickness thickness, object other, bool expected)
{
Assert.Equal(expected, thickness.Equals(other));
if (other is Thickness otherThickness)
{
Assert.Equal(expected, thickness.Equals(otherThickness));
Assert.Equal(expected, thickness == otherThickness);
Assert.Equal(!expected, thickness != otherThickness);
Assert.Equal(expected, thickness.GetHashCode().Equals(otherThickness.GetHashCode()));
}
}
[Fact]
public void ToString_Invoke_ReturnsExpected()
{
var thickness = new Thickness(1, 2.2, 3, 4);
Assert.Equal("1,2.2,3,4", thickness.ToString());
}
[Fact]
public void ToString_NaN_ReturnsAuto()
{
Thickness thickness = new FakeThickness
{
Left = double.NaN,
Top = double.NaN,
Right = double.NaN,
Bottom = double.NaN
}.ToActual();
Assert.Equal("Auto,Auto,Auto,Auto", thickness.ToString());
}
public struct FakeThickness
{
public double Left;
public double Top;
public double Right;
public double Bottom;
public Thickness ToActual()
{
ThicknessWrapper wrapper = default(ThicknessWrapper);
wrapper.Fake = this;
return wrapper.Actual;
}
}
[StructLayout(LayoutKind.Explicit)]
public struct ThicknessWrapper
{
[FieldOffset(0)] public Thickness Actual;
[FieldOffset(0)] public FakeThickness Fake;
}
}
}