Browse Source
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
9 changed files with 340 additions and 2 deletions
@ -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}
|
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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> |
||||
@ -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")] |
||||
@ -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(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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> |
||||
Loading…
Reference in new issue