Browse Source

Added some more tests for Shape.

Can't get all the new tests to pass... need to take a break AAARGH ;)
Need to be more tests added to test different stretch values etc.
pull/58/head
Steven Kirk 11 years ago
parent
commit
56968707de
  1. 7
      Perspex.sln
  2. 72
      Tests/Perspex.Direct2D1.UnitTests/Controls/Shapes/PathTests.cs
  3. 43
      Tests/Perspex.Direct2D1.UnitTests/Media/GeometryTests.cs
  4. 124
      Tests/Perspex.Direct2D1.UnitTests/Perspex.Direct2D1.UnitTests.csproj
  5. 36
      Tests/Perspex.Direct2D1.UnitTests/Properties/AssemblyInfo.cs
  6. 24
      Tests/Perspex.Direct2D1.UnitTests/RectComparer.cs
  7. 10
      Tests/Perspex.Direct2D1.UnitTests/packages.config
  8. 24
      Tests/Perspex.RenderTests/Shapes/PathTests.cs
  9. 2
      Tests/Perspex.RenderTests/TestBase.cs

7
Perspex.sln

@ -55,6 +55,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Perspex.Direct2D1.RenderTes
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Perspex.Input.UnitTests", "Tests\Perspex.Input.UnitTests\Perspex.Input.UnitTests.csproj", "{AC18926A-E784-40FE-B09D-BB0FE2B599F0}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Perspex.Input.UnitTests", "Tests\Perspex.Input.UnitTests\Perspex.Input.UnitTests.csproj", "{AC18926A-E784-40FE-B09D-BB0FE2B599F0}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Perspex.Direct2D1.UnitTests", "Tests\Perspex.Direct2D1.UnitTests\Perspex.Direct2D1.UnitTests.csproj", "{EFB11458-9CDF-41C0-BE4F-44AF45A4CAB8}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -153,6 +155,10 @@ Global
{AC18926A-E784-40FE-B09D-BB0FE2B599F0}.Debug|Any CPU.Build.0 = Debug|Any CPU {AC18926A-E784-40FE-B09D-BB0FE2B599F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC18926A-E784-40FE-B09D-BB0FE2B599F0}.Release|Any CPU.ActiveCfg = Release|Any CPU {AC18926A-E784-40FE-B09D-BB0FE2B599F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC18926A-E784-40FE-B09D-BB0FE2B599F0}.Release|Any CPU.Build.0 = Release|Any CPU {AC18926A-E784-40FE-B09D-BB0FE2B599F0}.Release|Any CPU.Build.0 = Release|Any CPU
{EFB11458-9CDF-41C0-BE4F-44AF45A4CAB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EFB11458-9CDF-41C0-BE4F-44AF45A4CAB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EFB11458-9CDF-41C0-BE4F-44AF45A4CAB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EFB11458-9CDF-41C0-BE4F-44AF45A4CAB8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -169,5 +175,6 @@ Global
{08478EF5-44E8-42E9-92D6-15E00EC038D8} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B} {08478EF5-44E8-42E9-92D6-15E00EC038D8} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B}
{DABFD304-D6A4-4752-8123-C2CCF7AC7831} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B} {DABFD304-D6A4-4752-8123-C2CCF7AC7831} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B}
{AC18926A-E784-40FE-B09D-BB0FE2B599F0} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B} {AC18926A-E784-40FE-B09D-BB0FE2B599F0} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B}
{EFB11458-9CDF-41C0-BE4F-44AF45A4CAB8} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

72
Tests/Perspex.Direct2D1.UnitTests/Controls/Shapes/PathTests.cs

@ -0,0 +1,72 @@
// -----------------------------------------------------------------------
// <copyright file="GeometryTests.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Direct2D1.UnitTests.Controls.Shapes
{
using Perspex.Controls.Shapes;
using Perspex.Layout;
using Perspex.Media;
using Splat;
using Xunit;
public class PathTests
{
private static readonly RectComparer compare = new RectComparer();
[Fact]
void Should_Measure_Expander_Triangle_Correctly()
{
using (Locator.CurrentMutable.WithResolver())
{
Direct2D1Platform.Initialize();
var target = new Path
{
Data = StreamGeometry.Parse("M 0 2 L 4 6 L 0 10 Z"),
StrokeThickness = 0,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
UseLayoutRounding = false,
};
target.Measure(new Size(100, 100));
target.Arrange(new Rect(0, 0, 100, 100));
Assert.Equal(new Rect(0, 0, 4, 10), target.Bounds, compare);
}
}
[Fact]
void Should_Measure_Expander_Triangle_With_Stroke_Correctly()
{
using (Locator.CurrentMutable.WithResolver())
{
Direct2D1Platform.Initialize();
var target = new Path
{
Data = StreamGeometry.Parse("M 0 2 L 4 6 L 0 10 Z"),
Stroke = Brushes.Black,
StrokeThickness = 2,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
UseLayoutRounding = false,
};
target.Measure(new Size(100, 100));
target.Arrange(new Rect(0, 0, 100, 100));
// Measured geometry with stroke of 2px is:
// {-1, -0.414, 6.414, 12.828} (see GeometryTests)
// With origin at 0,0 the bounds equal:
Assert.Equal(new Rect(0, 0, 5.414, 12.414), target.Bounds, compare);
}
}
}
}
//{-0.5,0.79289323091507,5.207106590271,10.4142133593559}
//{-1,-0.414213567972183,6.41421365737915,12.8284267485142}

43
Tests/Perspex.Direct2D1.UnitTests/Media/GeometryTests.cs

@ -0,0 +1,43 @@
// -----------------------------------------------------------------------
// <copyright file="GeometryTests.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Direct2D1.UnitTests.Media
{
using Perspex.Media;
using Splat;
using Xunit;
public class GeometryTests
{
private static readonly RectComparer compare = new RectComparer();
[Fact]
void Should_Measure_Expander_Triangle_Correctly()
{
using (Locator.CurrentMutable.WithResolver())
{
Direct2D1Platform.Initialize();
var target = StreamGeometry.Parse("M 0 2 L 4 6 L 0 10 Z");
Assert.Equal(new Rect(0, 2, 4, 8), target.Bounds, compare);
}
}
[Fact]
void Should_Measure_Expander_Triangle_With_Stroke_Correctly()
{
using (Locator.CurrentMutable.WithResolver())
{
Direct2D1Platform.Initialize();
var target = StreamGeometry.Parse("M 0 2 L 4 6 L 0 10 Z");
Assert.Equal(new Rect(-1, -0.414, 6.414, 12.828), target.GetRenderBounds(2), compare);
}
}
}
}

124
Tests/Perspex.Direct2D1.UnitTests/Perspex.Direct2D1.UnitTests.csproj

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="..\..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props" Condition="Exists('..\..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{EFB11458-9CDF-41C0-BE4F-44AF45A4CAB8}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Perspex.Direct2D1.UnitTests</RootNamespace>
<AssemblyName>Perspex.Direct2D1.UnitTests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Splat, Version=1.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Splat.1.6.2\lib\Net45\Splat.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.assert, Version=2.0.0.2929, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.assert.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.core, Version=2.0.0.2929, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.extensibility.core.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Controls\Shapes\PathTests.cs" />
<Compile Include="Media\GeometryTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RectComparer.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Perspex.Animation\Perspex.Animation.csproj">
<Project>{d211e587-d8bc-45b9-95a4-f297c8fa5200}</Project>
<Name>Perspex.Animation</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Base\Perspex.Base.csproj">
<Project>{b09b78d8-9b26-48b0-9149-d64a2f120f3f}</Project>
<Name>Perspex.Base</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Controls\Perspex.Controls.csproj">
<Project>{d2221c82-4a25-4583-9b43-d791e3f6820c}</Project>
<Name>Perspex.Controls</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Input\Perspex.Input.csproj">
<Project>{62024b2d-53eb-4638-b26b-85eeaa54866e}</Project>
<Name>Perspex.Input</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Interactivity\Perspex.Interactivity.csproj">
<Project>{6b0ed19d-a08b-461c-a9d9-a9ee40b0c06b}</Project>
<Name>Perspex.Interactivity</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Layout\Perspex.Layout.csproj">
<Project>{42472427-4774-4c81-8aff-9f27b8e31721}</Project>
<Name>Perspex.Layout</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.SceneGraph\Perspex.SceneGraph.csproj">
<Project>{eb582467-6abb-43a1-b052-e981ba910e3a}</Project>
<Name>Perspex.SceneGraph</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Styling\Perspex.Styling.csproj">
<Project>{f1baa01a-f176-4c6a-b39d-5b40bb1b148f}</Project>
<Name>Perspex.Styling</Name>
</ProjectReference>
<ProjectReference Include="..\..\Windows\Perspex.Direct2D1\Perspex.Direct2D1.csproj">
<Project>{3e908f67-5543-4879-a1dc-08eace79b3cd}</Project>
<Name>Perspex.Direct2D1</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props'))" />
<Error Condition="!Exists('..\..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

36
Tests/Perspex.Direct2D1.UnitTests/Properties/AssemblyInfo.cs

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Perspex.Direct2D1.UnitTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Perspex.Direct2D1.UnitTests")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("efb11458-9cdf-41c0-be4f-44af45a4cab8")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

24
Tests/Perspex.Direct2D1.UnitTests/RectComparer.cs

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Perspex.Direct2D1.UnitTests
{
public class RectComparer : IEqualityComparer<Rect>
{
public bool Equals(Rect a, Rect b)
{
return Math.Round(a.X, 3) == Math.Round(b.X, 3) &&
Math.Round(a.Y, 3) == Math.Round(b.Y, 3) &&
Math.Round(a.Width, 3) == Math.Round(b.Width, 3) &&
Math.Round(a.Height, 3) == Math.Round(b.Height, 3);
}
public int GetHashCode(Rect obj)
{
throw new NotImplementedException();
}
}
}

10
Tests/Perspex.Direct2D1.UnitTests/packages.config

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Splat" version="1.6.2" targetFramework="net45" userInstalled="true" />
<package id="xunit" version="2.0.0" targetFramework="net45" userInstalled="true" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" userInstalled="true" />
<package id="xunit.assert" version="2.0.0" targetFramework="net45" userInstalled="true" />
<package id="xunit.core" version="2.0.0" targetFramework="net45" userInstalled="true" />
<package id="xunit.extensibility.core" version="2.0.0" targetFramework="net45" userInstalled="true" />
<package id="xunit.runner.visualstudio" version="2.0.0" targetFramework="net45" userInstalled="true" />
</packages>

24
Tests/Perspex.RenderTests/Shapes/PathTests.cs

@ -41,7 +41,6 @@ namespace Perspex.Direct2D1.RenderTests.Shapes
this.CompareImages(); this.CompareImages();
} }
[Fact] [Fact]
public void Path_Tick_Scaled() public void Path_Tick_Scaled()
{ {
@ -65,6 +64,29 @@ namespace Perspex.Direct2D1.RenderTests.Shapes
this.CompareImages(); this.CompareImages();
} }
[Fact]
public void Path_Tick_Scaled_Stroke_8px()
{
Decorator target = new Decorator
{
Width = 200,
Height = 200,
Content = new Path
{
Fill = Brushes.Gray,
Stroke = Brushes.Red,
StrokeThickness = 8,
Stretch = Stretch.Uniform,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Data = StreamGeometry.Parse("M 1145.607177734375,430 C1145.607177734375,430 1141.449951171875,435.0772705078125 1141.449951171875,435.0772705078125 1141.449951171875,435.0772705078125 1139.232177734375,433.0999755859375 1139.232177734375,433.0999755859375 1139.232177734375,433.0999755859375 1138,434.5538330078125 1138,434.5538330078125 1138,434.5538330078125 1141.482177734375,438 1141.482177734375,438 1141.482177734375,438 1141.96875,437.9375 1141.96875,437.9375 1141.96875,437.9375 1147,431.34619140625 1147,431.34619140625 1147,431.34619140625 1145.607177734375,430 1145.607177734375,430 z"),
}
};
this.RenderToFile(target);
this.CompareImages();
}
[Fact] [Fact]
public void Path_Expander_With_Border() public void Path_Expander_With_Border()
{ {

2
Tests/Perspex.RenderTests/TestBase.cs

@ -70,7 +70,7 @@ namespace Perspex.Direct2D1.RenderTests
if (error > 0.02) if (error > 0.02)
{ {
Assert.True(false, "Error = " + error); Assert.True(false, actualPath + ": Error = " + error);
} }
} }
} }

Loading…
Cancel
Save