Switched back to NUnit because xUnit had issues with the WGL tests

This commit is contained in:
Matthew Leibowitz 2017-02-16 16:15:35 +02:00
Родитель 1dbb79b2af
Коммит 70eec54cd0
22 изменённых файлов: 371 добавлений и 395 удалений

Просмотреть файл

@ -14,8 +14,7 @@ var NuGetSources = new [] { MakeAbsolute (Directory ("./output")).FullPath, "htt
var NugetToolPath = GetToolPath ("nuget.exe"); var NugetToolPath = GetToolPath ("nuget.exe");
var XamarinComponentToolPath = GetToolPath ("xamarin-component.exe"); var XamarinComponentToolPath = GetToolPath ("xamarin-component.exe");
var CakeToolPath = GetToolPath ("Cake/Cake.exe"); var CakeToolPath = GetToolPath ("Cake/Cake.exe");
var TestConsoleToolPath_x86 = GetToolPath ("xunit.runner.console/tools/xunit.console.x86.exe"); var NUnitConsoleToolPath = GetToolPath ("NUnit.Console/tools/nunit3-console.exe");
var TestConsoleToolPath_x64 = GetToolPath ("xunit.runner.console/tools/xunit.console.exe");
var GenApiToolPath = GetToolPath ("Microsoft.DotNet.BuildTools.GenAPI/tools/GenAPI.exe"); var GenApiToolPath = GetToolPath ("Microsoft.DotNet.BuildTools.GenAPI/tools/GenAPI.exe");
var MDocPath = GetToolPath ("mdoc/mdoc.exe"); var MDocPath = GetToolPath ("mdoc/mdoc.exe");
@ -217,19 +216,19 @@ Task ("tests")
c.Configuration = "Release"; c.Configuration = "Release";
c.Properties ["Platform"] = new [] { "x86" }; c.Properties ["Platform"] = new [] { "x86" };
}); });
RunTests("./tests/SkiaSharp.Desktop.Tests/bin/x86/Release/SkiaSharp.Desktop.Tests.dll", false); RunTests("./tests/SkiaSharp.Desktop.Tests/bin/x86/Release/SkiaSharp.Desktop.Tests.dll");
DotNetBuild ("./tests/SkiaSharp.Desktop.Tests/SkiaSharp.Desktop.Tests.sln", c => { DotNetBuild ("./tests/SkiaSharp.Desktop.Tests/SkiaSharp.Desktop.Tests.sln", c => {
c.Configuration = "Release"; c.Configuration = "Release";
c.Properties ["Platform"] = new [] { "x64" }; c.Properties ["Platform"] = new [] { "x64" };
}); });
RunTests("./tests/SkiaSharp.Desktop.Tests/bin/x64/Release/SkiaSharp.Desktop.Tests.dll", true); RunTests("./tests/SkiaSharp.Desktop.Tests/bin/x64/Release/SkiaSharp.Desktop.Tests.dll");
} }
// Mac OSX (Any CPU) // Mac OSX (Any CPU)
if (IsRunningOnMac ()) { if (IsRunningOnMac ()) {
DotNetBuild ("./tests/SkiaSharp.Desktop.Tests/SkiaSharp.Desktop.Tests.sln", c => { DotNetBuild ("./tests/SkiaSharp.Desktop.Tests/SkiaSharp.Desktop.Tests.sln", c => {
c.Configuration = "Release"; c.Configuration = "Release";
}); });
RunTests("./tests/SkiaSharp.Desktop.Tests/bin/AnyCPU/Release/SkiaSharp.Desktop.Tests.dll", false); RunTests("./tests/SkiaSharp.Desktop.Tests/bin/AnyCPU/Release/SkiaSharp.Desktop.Tests.dll");
} }
// .NET Core // .NET Core
RunDotNetCoreRestore ("./tests/SkiaSharp.NetCore.Tests"); RunDotNetCoreRestore ("./tests/SkiaSharp.NetCore.Tests");
@ -664,8 +663,7 @@ Task ("Windows-CI")
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
Information ("Cake.exe ToolPath: {0}", CakeToolPath); Information ("Cake.exe ToolPath: {0}", CakeToolPath);
Information ("Cake.exe TestConsoleToolPath_x86: {0}", TestConsoleToolPath_x86); Information ("Cake.exe NUnitConsoleToolPath: {0}", NUnitConsoleToolPath);
Information ("Cake.exe TestConsoleToolPath_x64: {0}", TestConsoleToolPath_x64);
Information ("NuGet.exe ToolPath: {0}", NugetToolPath); Information ("NuGet.exe ToolPath: {0}", NugetToolPath);
Information ("Xamarin-Component.exe ToolPath: {0}", XamarinComponentToolPath); Information ("Xamarin-Component.exe ToolPath: {0}", XamarinComponentToolPath);
Information ("genapi.exe ToolPath: {0}", GenApiToolPath); Information ("genapi.exe ToolPath: {0}", GenApiToolPath);

Просмотреть файл

@ -39,11 +39,11 @@ var RunProcess = new Action<FilePath, ProcessSettings> ((process, settings) =>
} }
}); });
var RunTests = new Action<FilePath, bool> ((testAssembly, is64) => var RunTests = new Action<FilePath> ((testAssembly) =>
{ {
var dir = testAssembly.GetDirectory (); var dir = testAssembly.GetDirectory ();
RunProcess (is64 ? TestConsoleToolPath_x64 : TestConsoleToolPath_x86, new ProcessSettings { RunProcess (NUnitConsoleToolPath, new ProcessSettings {
Arguments = string.Format ("\"{0}\"", testAssembly), Arguments = string.Format ("\"{0}\" --work=\"{1}\"", testAssembly, dir),
}); });
}); });

Просмотреть файл

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -74,6 +73,10 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="nunit.framework, Version=3.6.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>packages\NUnit.3.6.0\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
@ -83,22 +86,6 @@
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="xunit.abstractions">
<HintPath>packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.assert">
<HintPath>packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.core">
<HintPath>packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.execution.desktop">
<HintPath>packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="..\Tests\GlContexts\Cgl\Cgl.cs"> <Compile Include="..\Tests\GlContexts\Cgl\Cgl.cs">
@ -285,12 +272,6 @@
</ItemGroup> </ItemGroup>
<Import Project="..\..\binding\SkiaSharp.Desktop\bin\$(Configuration)\nuget\build\net45\SkiaSharp.Desktop.targets" /> <Import Project="..\..\binding\SkiaSharp.Desktop\bin\$(Configuration)\nuget\build\net45\SkiaSharp.Desktop.targets" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <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.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\xunit.runner.visualstudio.2.1.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. <!-- 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. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">

Просмотреть файл

@ -1,10 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="xunit" version="2.1.0" targetFramework="net45" /> <package id="NUnit" version="3.6.0" targetFramework="net45" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" /> <package id="NUnit3TestAdapter" version="3.7.0" targetFramework="net45" />
<package id="xunit.assert" version="2.1.0" targetFramework="net45" />
<package id="xunit.core" version="2.1.0" targetFramework="net45" />
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net45" />
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net45" />
<package id="xunit.runner.visualstudio" version="2.1.0" targetFramework="net45" />
</packages> </packages>

Просмотреть файл

@ -20,13 +20,13 @@
} }
}, },
"dependencies": { "dependencies": {
"xunit": "2.2.0-beta5-build3474", "NUnit": "3.6.0",
"dotnet-test-xunit": "2.2.0-preview2-build1029", "dotnet-test-nunit": "3.4.0-beta-3",
"SkiaSharp": "1.56.1", "SkiaSharp": "1.56.1",
"SkiaSharp.Svg": "1.56.1" "SkiaSharp.Svg": "1.56.1"
}, },
"testRunner": "xunit", "testRunner": "nunit",
"frameworks": { "frameworks": {
"netcoreapp1.0": { "netcoreapp1.0": {
"dependencies": { "dependencies": {

Просмотреть файл

@ -1,12 +1,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Xunit; using NUnit.Framework;
namespace SkiaSharp.Tests namespace SkiaSharp.Tests
{ {
[Parallelizable(ParallelScope.None)]
public class GRContextTest : SKTest public class GRContextTest : SKTest
{ {
[Fact] [Test]
public void CreateDefaultContextIsValid() public void CreateDefaultContextIsValid()
{ {
using (var ctx = CreateGlContext()) { using (var ctx = CreateGlContext()) {
@ -18,7 +19,7 @@ namespace SkiaSharp.Tests
} }
} }
[Fact] [Test]
public void CreateSpecificContextIsValid() public void CreateSpecificContextIsValid()
{ {
using (var ctx = CreateGlContext()) { using (var ctx = CreateGlContext()) {

Просмотреть файл

@ -1,13 +1,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Xunit; using NUnit.Framework;
namespace SkiaSharp.Tests namespace SkiaSharp.Tests
{ {
[Parallelizable(ParallelScope.None)]
public class GRGlInterfaceTest : SKTest public class GRGlInterfaceTest : SKTest
{ {
[Fact] [Test]
public void CreateDefaultInterfaceIsValid() public void CreateDefaultInterfaceIsValid()
{ {
using (var ctx = CreateGlContext()) { using (var ctx = CreateGlContext()) {

Просмотреть файл

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Xunit; using NUnit.Framework;
namespace SkiaSharp.Tests namespace SkiaSharp.Tests
{ {
@ -8,24 +8,24 @@ namespace SkiaSharp.Tests
{ {
private const float EPSILON = 0.0001f; private const float EPSILON = 0.0001f;
[Fact] [Test]
public void RectanlgeHasCorrectProperties() public void RectanlgeHasCorrectProperties()
{ {
var rect = new SKRect(15, 25, 55, 75); var rect = new SKRect(15, 25, 55, 75);
Assert.Equal(15f, rect.Left); Assert.AreEqual(15f, rect.Left);
Assert.Equal(25f, rect.Top); Assert.AreEqual(25f, rect.Top);
Assert.Equal(55f, rect.Right); Assert.AreEqual(55f, rect.Right);
Assert.Equal(75f, rect.Bottom); Assert.AreEqual(75f, rect.Bottom);
Assert.Equal(40f, rect.Width); Assert.AreEqual(40f, rect.Width);
Assert.Equal(50f, rect.Height); Assert.AreEqual(50f, rect.Height);
Assert.Equal(35f, rect.MidX); Assert.AreEqual(35f, rect.MidX);
Assert.Equal(50f, rect.MidY); Assert.AreEqual(50f, rect.MidY);
} }
[Fact] [Test]
public void RectanlgeOffsetsCorrectly() public void RectanlgeOffsetsCorrectly()
{ {
var expected = new SKRect(25, 30, 65, 80); var expected = new SKRect(25, 30, 65, 80);
@ -36,54 +36,54 @@ namespace SkiaSharp.Tests
var rect2 = new SKRect(15, 25, 55, 75); var rect2 = new SKRect(15, 25, 55, 75);
rect2.Offset (10, 5); rect2.Offset (10, 5);
Assert.Equal(expected, rect1); Assert.AreEqual(expected, rect1);
Assert.Equal(expected, rect2); Assert.AreEqual(expected, rect2);
} }
[Fact] [Test]
public void RectanlgeInflatesCorrectly() public void RectanlgeInflatesCorrectly()
{ {
var rect = new SKRect(15, 25, 55, 75); var rect = new SKRect(15, 25, 55, 75);
Assert.Equal(15f, rect.Left); Assert.AreEqual(15f, rect.Left);
Assert.Equal(25f, rect.Top); Assert.AreEqual(25f, rect.Top);
Assert.Equal(55f, rect.Right); Assert.AreEqual(55f, rect.Right);
Assert.Equal(75f, rect.Bottom); Assert.AreEqual(75f, rect.Bottom);
rect.Inflate(10, 20); rect.Inflate(10, 20);
Assert.Equal(5f, rect.Left); Assert.AreEqual(5f, rect.Left);
Assert.Equal(5f, rect.Top); Assert.AreEqual(5f, rect.Top);
Assert.Equal(65f, rect.Right); Assert.AreEqual(65f, rect.Right);
Assert.Equal(95f, rect.Bottom); Assert.AreEqual(95f, rect.Bottom);
} }
[Fact] [Test]
public void RectanlgeStandardizeCorrectly() public void RectanlgeStandardizeCorrectly()
{ {
var rect = new SKRect(5, 5, 15, 15); var rect = new SKRect(5, 5, 15, 15);
Assert.Equal(10, rect.Width); Assert.AreEqual(10, rect.Width);
Assert.Equal(10, rect.Height); Assert.AreEqual(10, rect.Height);
Assert.Equal(rect, rect.Standardized); Assert.AreEqual(rect, rect.Standardized);
var negW = new SKRect(15, 5, 5, 15); var negW = new SKRect(15, 5, 5, 15);
Assert.Equal(-10, negW.Width); Assert.AreEqual(-10, negW.Width);
Assert.Equal(10, negW.Height); Assert.AreEqual(10, negW.Height);
Assert.Equal(rect, negW.Standardized); Assert.AreEqual(rect, negW.Standardized);
var negH = new SKRect(5, 15, 15, 5); var negH = new SKRect(5, 15, 15, 5);
Assert.Equal(10, negH.Width); Assert.AreEqual(10, negH.Width);
Assert.Equal(-10, negH.Height); Assert.AreEqual(-10, negH.Height);
Assert.Equal(rect, negH.Standardized); Assert.AreEqual(rect, negH.Standardized);
var negWH = new SKRect(15, 15, 5, 5); var negWH = new SKRect(15, 15, 5, 5);
Assert.Equal(-10, negWH.Width); Assert.AreEqual(-10, negWH.Width);
Assert.Equal(-10, negWH.Height); Assert.AreEqual(-10, negWH.Height);
Assert.Equal(rect, negWH.Standardized); Assert.AreEqual(rect, negWH.Standardized);
} }
[Fact] [Test]
public void RectanlgeAspectFitIsCorrect() public void RectanlgeAspectFitIsCorrect()
{ {
var bigRect = SKRect.Create(5, 5, 20, 20); var bigRect = SKRect.Create(5, 5, 20, 20);
@ -91,19 +91,19 @@ namespace SkiaSharp.Tests
var wideSize = new SKSize(10, 5); var wideSize = new SKSize(10, 5);
var fitTall = bigRect.AspectFit(tallSize); var fitTall = bigRect.AspectFit(tallSize);
Assert.Equal(5 + 5, fitTall.Left); Assert.AreEqual(5 + 5, fitTall.Left);
Assert.Equal(5 + 0, fitTall.Top); Assert.AreEqual(5 + 0, fitTall.Top);
Assert.Equal(10, fitTall.Width); Assert.AreEqual(10, fitTall.Width);
Assert.Equal(20, fitTall.Height); Assert.AreEqual(20, fitTall.Height);
var fitWide = bigRect.AspectFit(wideSize); var fitWide = bigRect.AspectFit(wideSize);
Assert.Equal(5 + 0, fitWide.Left); Assert.AreEqual(5 + 0, fitWide.Left);
Assert.Equal(5 + 5, fitWide.Top); Assert.AreEqual(5 + 5, fitWide.Top);
Assert.Equal(20, fitWide.Width); Assert.AreEqual(20, fitWide.Width);
Assert.Equal(10, fitWide.Height); Assert.AreEqual(10, fitWide.Height);
} }
[Fact] [Test]
public void RectanlgeAspectFillIsCorrect() public void RectanlgeAspectFillIsCorrect()
{ {
var bigRect = SKRect.Create(5, 5, 20, 20); var bigRect = SKRect.Create(5, 5, 20, 20);
@ -111,19 +111,19 @@ namespace SkiaSharp.Tests
var wideSize = new SKSize(10, 5); var wideSize = new SKSize(10, 5);
var fitTall = bigRect.AspectFill(tallSize); var fitTall = bigRect.AspectFill(tallSize);
Assert.Equal(5 + 0, fitTall.Left); Assert.AreEqual(5 + 0, fitTall.Left);
Assert.Equal(5 - 10, fitTall.Top); Assert.AreEqual(5 - 10, fitTall.Top);
Assert.Equal(20, fitTall.Width); Assert.AreEqual(20, fitTall.Width);
Assert.Equal(40, fitTall.Height); Assert.AreEqual(40, fitTall.Height);
var fitWide = bigRect.AspectFill(wideSize); var fitWide = bigRect.AspectFill(wideSize);
Assert.Equal(5 - 10, fitWide.Left); Assert.AreEqual(5 - 10, fitWide.Left);
Assert.Equal(5 + 0, fitWide.Top); Assert.AreEqual(5 + 0, fitWide.Top);
Assert.Equal(40, fitWide.Width); Assert.AreEqual(40, fitWide.Width);
Assert.Equal(20, fitWide.Height); Assert.AreEqual(20, fitWide.Height);
} }
[Fact] [Test]
public unsafe void FixedImageMaskIsHandledCorrectly() public unsafe void FixedImageMaskIsHandledCorrectly()
{ {
byte rawMask = 1 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 1; byte rawMask = 1 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 1;
@ -136,11 +136,11 @@ namespace SkiaSharp.Tests
{ {
var mask = SKMask.Create(buffer, bounds, rowBytes, format); var mask = SKMask.Create(buffer, bounds, rowBytes, format);
Assert.Equal(rawMask, mask.GetAddr1(0, 0)); Assert.AreEqual(rawMask, mask.GetAddr1(0, 0));
} }
} }
[Fact] [Test]
public void MonochromeMaskBufferIsCopied() public void MonochromeMaskBufferIsCopied()
{ {
byte rawMask = 1 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 1; byte rawMask = 1 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 1;
@ -151,12 +151,12 @@ namespace SkiaSharp.Tests
var mask = SKMask.Create(buffer, bounds, rowBytes, format); var mask = SKMask.Create(buffer, bounds, rowBytes, format);
Assert.Equal(rawMask, mask.GetAddr1(0, 0)); Assert.AreEqual(rawMask, mask.GetAddr1(0, 0));
mask.FreeImage(); mask.FreeImage();
} }
[Fact] [Test]
public void Alpha8MaskBufferIsCopied() public void Alpha8MaskBufferIsCopied()
{ {
var buffer = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; var buffer = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
@ -166,19 +166,19 @@ namespace SkiaSharp.Tests
var mask = SKMask.Create(buffer, bounds, rowBytes, format); var mask = SKMask.Create(buffer, bounds, rowBytes, format);
Assert.Equal(buffer[0], mask.GetAddr8(0, 0)); Assert.AreEqual(buffer[0], mask.GetAddr8(0, 0));
Assert.Equal(buffer[1], mask.GetAddr8(1, 0)); Assert.AreEqual(buffer[1], mask.GetAddr8(1, 0));
Assert.Equal(buffer[2], mask.GetAddr8(2, 0)); Assert.AreEqual(buffer[2], mask.GetAddr8(2, 0));
Assert.Equal(buffer[3], mask.GetAddr8(3, 0)); Assert.AreEqual(buffer[3], mask.GetAddr8(3, 0));
Assert.Equal(buffer[4], mask.GetAddr8(0, 1)); Assert.AreEqual(buffer[4], mask.GetAddr8(0, 1));
Assert.Equal(buffer[5], mask.GetAddr8(1, 1)); Assert.AreEqual(buffer[5], mask.GetAddr8(1, 1));
Assert.Equal(buffer[6], mask.GetAddr8(2, 1)); Assert.AreEqual(buffer[6], mask.GetAddr8(2, 1));
Assert.Equal(buffer[7], mask.GetAddr8(3, 1)); Assert.AreEqual(buffer[7], mask.GetAddr8(3, 1));
mask.FreeImage(); mask.FreeImage();
} }
[Fact] [Test]
public void ThirtyTwoBitMaskBufferIsCopied() public void ThirtyTwoBitMaskBufferIsCopied()
{ {
var buffer = new byte[] var buffer = new byte[]
@ -200,14 +200,14 @@ namespace SkiaSharp.Tests
var red = SKColors.Red; var red = SKColors.Red;
var blue = SKColors.Blue; var blue = SKColors.Blue;
Assert.Equal((uint)red, mask.GetAddr32(0, 0)); Assert.AreEqual((uint)red, mask.GetAddr32(0, 0));
Assert.Equal((uint)blue, mask.GetAddr32(1, 0)); Assert.AreEqual((uint)blue, mask.GetAddr32(1, 0));
Assert.Equal((uint)red, mask.GetAddr32(2, 0)); Assert.AreEqual((uint)red, mask.GetAddr32(2, 0));
Assert.Equal((uint)blue, mask.GetAddr32(3, 0)); Assert.AreEqual((uint)blue, mask.GetAddr32(3, 0));
Assert.Equal((uint)red, mask.GetAddr32(0, 1)); Assert.AreEqual((uint)red, mask.GetAddr32(0, 1));
Assert.Equal((uint)blue, mask.GetAddr32(1, 1)); Assert.AreEqual((uint)blue, mask.GetAddr32(1, 1));
Assert.Equal((uint)red, mask.GetAddr32(2, 1)); Assert.AreEqual((uint)red, mask.GetAddr32(2, 1));
Assert.Equal((uint)blue, mask.GetAddr32(3, 1)); Assert.AreEqual((uint)blue, mask.GetAddr32(3, 1));
mask.FreeImage(); mask.FreeImage();
} }

Просмотреть файл

@ -1,13 +1,13 @@
using System; using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Xunit; using NUnit.Framework;
namespace SkiaSharp.Tests namespace SkiaSharp.Tests
{ {
public class SKBitmapTest : SKTest public class SKBitmapTest : SKTest
{ {
[Fact] [Test]
public void ReleaseBitmapPixelsWasInvoked() public void ReleaseBitmapPixelsWasInvoked()
{ {
bool released = false; bool released = false;
@ -27,7 +27,7 @@ namespace SkiaSharp.Tests
Assert.True(released, "The SKBitmapReleaseDelegate was not called."); Assert.True(released, "The SKBitmapReleaseDelegate was not called.");
} }
[Fact] [Test]
public void ReleaseBitmapPixelsWithNullDelegate() public void ReleaseBitmapPixelsWithNullDelegate()
{ {
var info = new SKImageInfo(1, 1); var info = new SKImageInfo(1, 1);
@ -40,7 +40,7 @@ namespace SkiaSharp.Tests
Marshal.FreeCoTaskMem(pixels); Marshal.FreeCoTaskMem(pixels);
} }
[Fact] [Test]
public void TestExtractAlpha() public void TestExtractAlpha()
{ {
var path = Path.Combine(PathToImages, "color-wheel.png"); var path = Path.Combine(PathToImages, "color-wheel.png");
@ -55,30 +55,30 @@ namespace SkiaSharp.Tests
Assert.True(bitmap.ExtractAlpha(alpha, paint, out offset)); Assert.True(bitmap.ExtractAlpha(alpha, paint, out offset));
Assert.Equal(new SKPointI(-7, -7), offset); Assert.AreEqual(new SKPointI(-7, -7), offset);
} }
[Fact] [Test]
public void BitmapAndPixmapAreValid() public void BitmapAndPixmapAreValid()
{ {
var info = new SKImageInfo(10, 10); var info = new SKImageInfo(10, 10);
using (var bitmap = new SKBitmap(info)) { using (var bitmap = new SKBitmap(info)) {
Assert.Equal(10, bitmap.Width); Assert.AreEqual(10, bitmap.Width);
Assert.Equal(10, bitmap.Height); Assert.AreEqual(10, bitmap.Height);
var pixmap = bitmap.PeekPixels(); var pixmap = bitmap.PeekPixels();
Assert.NotNull(pixmap); Assert.NotNull(pixmap);
Assert.Equal(10, pixmap.Width); Assert.AreEqual(10, pixmap.Width);
Assert.Equal(10, pixmap.Height); Assert.AreEqual(10, pixmap.Height);
Assert.True(bitmap.GetPixels() != IntPtr.Zero); Assert.True(bitmap.GetPixels() != IntPtr.Zero);
Assert.True(pixmap.GetPixels() != IntPtr.Zero); Assert.True(pixmap.GetPixels() != IntPtr.Zero);
Assert.Equal(bitmap.GetPixels(), pixmap.GetPixels()); Assert.AreEqual(bitmap.GetPixels(), pixmap.GetPixels());
} }
} }
[Fact] [Test]
public void BitmapResizes() public void BitmapResizes()
{ {
var srcInfo = new SKImageInfo(200, 200); var srcInfo = new SKImageInfo(200, 200);
@ -92,17 +92,17 @@ namespace SkiaSharp.Tests
canvas.DrawRect(new SKRect(0, 0, 100, 200), paint); canvas.DrawRect(new SKRect(0, 0, 100, 200), paint);
} }
Assert.Equal(SKColors.Green, srcBmp.GetPixel(75, 75)); Assert.AreEqual(SKColors.Green, srcBmp.GetPixel(75, 75));
Assert.Equal(SKColors.Blue, srcBmp.GetPixel(175, 175)); Assert.AreEqual(SKColors.Blue, srcBmp.GetPixel(175, 175));
var dstBmp = srcBmp.Resize(dstInfo, SKBitmapResizeMethod.Mitchell); var dstBmp = srcBmp.Resize(dstInfo, SKBitmapResizeMethod.Mitchell);
Assert.NotNull(dstBmp); Assert.NotNull(dstBmp);
Assert.Equal(SKColors.Green, dstBmp.GetPixel(25, 25)); Assert.AreEqual(SKColors.Green, dstBmp.GetPixel(25, 25));
Assert.Equal(SKColors.Blue, dstBmp.GetPixel(75, 75)); Assert.AreEqual(SKColors.Blue, dstBmp.GetPixel(75, 75));
} }
[Fact] [Test]
public void AlphaMaskIsApplied() public void AlphaMaskIsApplied()
{ {
var srcInfo = new SKImageInfo(4, 4); var srcInfo = new SKImageInfo(4, 4);
@ -112,7 +112,7 @@ namespace SkiaSharp.Tests
foreach (var pixel in pixels) foreach (var pixel in pixels)
{ {
Assert.Equal(255, pixel.Alpha); Assert.AreEqual(255, pixel.Alpha);
} }
var maskBuffer = new byte[] var maskBuffer = new byte[]
@ -130,22 +130,22 @@ namespace SkiaSharp.Tests
srcBmp.InstallMaskPixels(mask); srcBmp.InstallMaskPixels(mask);
pixels = srcBmp.Pixels; pixels = srcBmp.Pixels;
Assert.Equal(128, pixels[0].Alpha); Assert.AreEqual(128, pixels[0].Alpha);
Assert.Equal(127, pixels[1].Alpha); Assert.AreEqual(127, pixels[1].Alpha);
Assert.Equal(126, pixels[2].Alpha); Assert.AreEqual(126, pixels[2].Alpha);
Assert.Equal(125, pixels[3].Alpha); Assert.AreEqual(125, pixels[3].Alpha);
Assert.Equal(101, pixels[4].Alpha); Assert.AreEqual(101, pixels[4].Alpha);
Assert.Equal(102, pixels[5].Alpha); Assert.AreEqual(102, pixels[5].Alpha);
Assert.Equal(103, pixels[6].Alpha); Assert.AreEqual(103, pixels[6].Alpha);
Assert.Equal(104, pixels[7].Alpha); Assert.AreEqual(104, pixels[7].Alpha);
Assert.Equal(96, pixels[8].Alpha); Assert.AreEqual(96, pixels[8].Alpha);
Assert.Equal(95, pixels[9].Alpha); Assert.AreEqual(95, pixels[9].Alpha);
Assert.Equal(94, pixels[10].Alpha); Assert.AreEqual(94, pixels[10].Alpha);
Assert.Equal(93, pixels[11].Alpha); Assert.AreEqual(93, pixels[11].Alpha);
Assert.Equal(72, pixels[12].Alpha); Assert.AreEqual(72, pixels[12].Alpha);
Assert.Equal(73, pixels[13].Alpha); Assert.AreEqual(73, pixels[13].Alpha);
Assert.Equal(74, pixels[14].Alpha); Assert.AreEqual(74, pixels[14].Alpha);
Assert.Equal(75, pixels[15].Alpha); Assert.AreEqual(75, pixels[15].Alpha);
mask.FreeImage(); mask.FreeImage();
} }

Просмотреть файл

@ -1,44 +1,44 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Xunit; using NUnit.Framework;
namespace SkiaSharp.Tests namespace SkiaSharp.Tests
{ {
public class SKCodecTest : SKTest public class SKCodecTest : SKTest
{ {
[Fact] [Test]
public void MinBufferedBytesNeededHasAValue () public void MinBufferedBytesNeededHasAValue ()
{ {
Assert.True (SKCodec.MinBufferedBytesNeeded > 0); Assert.True (SKCodec.MinBufferedBytesNeeded > 0);
} }
[Fact] [Test]
public void CanCreateStreamCodec () public void CanCreateStreamCodec ()
{ {
var stream = new SKFileStream (Path.Combine (PathToImages, "color-wheel.png")); var stream = new SKFileStream (Path.Combine (PathToImages, "color-wheel.png"));
using (var codec = SKCodec.Create (stream)) { using (var codec = SKCodec.Create (stream)) {
Assert.Equal (SKEncodedFormat.Png, codec.EncodedFormat); Assert.AreEqual (SKEncodedFormat.Png, codec.EncodedFormat);
Assert.Equal (128, codec.Info.Width); Assert.AreEqual (128, codec.Info.Width);
Assert.Equal (128, codec.Info.Height); Assert.AreEqual (128, codec.Info.Height);
Assert.Equal (SKAlphaType.Unpremul, codec.Info.AlphaType); Assert.AreEqual (SKAlphaType.Unpremul, codec.Info.AlphaType);
Assert.Equal (SKImageInfo.PlatformColorType, codec.Info.ColorType); Assert.AreEqual (SKImageInfo.PlatformColorType, codec.Info.ColorType);
} }
} }
[Fact] [Test]
public void GetGifFrames () public void GetGifFrames ()
{ {
const int FrameCount = 16; const int FrameCount = 16;
var stream = new SKFileStream (Path.Combine (PathToImages, "animated-heart.gif")); var stream = new SKFileStream (Path.Combine (PathToImages, "animated-heart.gif"));
using (var codec = SKCodec.Create (stream)) { using (var codec = SKCodec.Create (stream)) {
Assert.Equal (-1, codec.RepetitionCount); Assert.AreEqual (-1, codec.RepetitionCount);
var frameInfos = codec.FrameInfo; var frameInfos = codec.FrameInfo;
Assert.Equal (FrameCount, frameInfos.Length); Assert.AreEqual (FrameCount, frameInfos.Length);
Assert.Equal (-1, frameInfos [0].RequiredFrame); Assert.AreEqual (-1, frameInfos [0].RequiredFrame);
var cachedFrames = new SKBitmap [FrameCount]; var cachedFrames = new SKBitmap [FrameCount];
var info = new SKImageInfo (codec.Info.Width, codec.Info.Height); var info = new SKImageInfo (codec.Info.Width, codec.Info.Height);
@ -52,7 +52,7 @@ namespace SkiaSharp.Tests
} }
var opts = new SKCodecOptions (index, cached); var opts = new SKCodecOptions (index, cached);
var result = codec.GetPixels (info, bm.GetPixels (), opts); var result = codec.GetPixels (info, bm.GetPixels (), opts);
Assert.Equal (SKCodecResult.Success, result); Assert.AreEqual (SKCodecResult.Success, result);
}); });
for (var i = 0; i < FrameCount; i++) { for (var i = 0; i < FrameCount; i++) {
@ -62,33 +62,33 @@ namespace SkiaSharp.Tests
var uncachedFrame = new SKBitmap (info); var uncachedFrame = new SKBitmap (info);
decode (uncachedFrame, false, i); decode (uncachedFrame, false, i);
Assert.Equal (cachedFrame.Bytes, uncachedFrame.Bytes); Assert.AreEqual (cachedFrame.Bytes, uncachedFrame.Bytes);
} }
} }
} }
[Fact] [Test]
public void GetEncodedInfo () public void GetEncodedInfo ()
{ {
var stream = new SKFileStream (Path.Combine (PathToImages, "color-wheel.png")); var stream = new SKFileStream (Path.Combine (PathToImages, "color-wheel.png"));
using (var codec = SKCodec.Create (stream)) { using (var codec = SKCodec.Create (stream)) {
Assert.Equal (SKEncodedInfoColor.Rgba, codec.EncodedInfo.Color); Assert.AreEqual (SKEncodedInfoColor.Rgba, codec.EncodedInfo.Color);
Assert.Equal (SKEncodedInfoAlpha.Unpremul, codec.EncodedInfo.Alpha); Assert.AreEqual (SKEncodedInfoAlpha.Unpremul, codec.EncodedInfo.Alpha);
Assert.Equal (8, codec.EncodedInfo.BitsPerComponent); Assert.AreEqual (8, codec.EncodedInfo.BitsPerComponent);
} }
} }
[Fact] [Test]
public void CanGetPixels () public void CanGetPixels ()
{ {
var stream = new SKFileStream (Path.Combine (PathToImages, "baboon.png")); var stream = new SKFileStream (Path.Combine (PathToImages, "baboon.png"));
using (var codec = SKCodec.Create (stream)) { using (var codec = SKCodec.Create (stream)) {
var pixels = codec.Pixels; var pixels = codec.Pixels;
Assert.Equal (codec.Info.BytesSize, pixels.Length); Assert.AreEqual (codec.Info.BytesSize, pixels.Length);
} }
} }
[Fact] [Test]
public void DecodeImageScanlines () public void DecodeImageScanlines ()
{ {
var path = Path.Combine (PathToImages, "CMYK.jpg"); var path = Path.Combine (PathToImages, "CMYK.jpg");
@ -104,37 +104,37 @@ namespace SkiaSharp.Tests
scanlineBitmap.Erase (SKColors.Fuchsia); scanlineBitmap.Erase (SKColors.Fuchsia);
var result = codec.StartScanlineDecode (info); var result = codec.StartScanlineDecode (info);
Assert.Equal (SKCodecResult.Success, result); Assert.AreEqual (SKCodecResult.Success, result);
Assert.Equal (SKCodecScanlineOrder.TopDown, codec.ScanlineOrder); Assert.AreEqual (SKCodecScanlineOrder.TopDown, codec.ScanlineOrder);
Assert.Equal (0, codec.NextScanline); Assert.AreEqual (0, codec.NextScanline);
// only decode every second line // only decode every second line
for (int y = 0; y < info.Height; y += 2) { for (int y = 0; y < info.Height; y += 2) {
Assert.Equal (1, codec.GetScanlines (scanlineBitmap.GetAddr (0, y), 1, info.RowBytes)); Assert.AreEqual (1, codec.GetScanlines (scanlineBitmap.GetAddr (0, y), 1, info.RowBytes));
Assert.Equal (y + 1, codec.NextScanline); Assert.AreEqual (y + 1, codec.NextScanline);
if (codec.SkipScanlines (1)) if (codec.SkipScanlines (1))
Assert.Equal (y + 2, codec.NextScanline); Assert.AreEqual (y + 2, codec.NextScanline);
else else
Assert.Equal (imageHeight, codec.NextScanline); // reached the end Assert.AreEqual (imageHeight, codec.NextScanline); // reached the end
} }
Assert.False (codec.SkipScanlines (1)); Assert.False (codec.SkipScanlines (1));
Assert.Equal (imageHeight, codec.NextScanline); Assert.AreEqual (imageHeight, codec.NextScanline);
for (var x = 0; x < info.Width; x++) { for (var x = 0; x < info.Width; x++) {
for (var y = 0; y < info.Height; y++) { for (var y = 0; y < info.Height; y++) {
if (y % 2 == 0) if (y % 2 == 0)
Assert.Equal (correctBitmap.GetPixel (x, y), scanlineBitmap.GetPixel (x, y)); Assert.AreEqual (correctBitmap.GetPixel (x, y), scanlineBitmap.GetPixel (x, y));
else else
Assert.Equal (SKColors.Fuchsia, scanlineBitmap.GetPixel (x, y)); Assert.AreEqual (SKColors.Fuchsia, scanlineBitmap.GetPixel (x, y));
} }
} }
} }
} }
} }
[Fact] [Test]
public void DecodePartialImage () public void DecodePartialImage ()
{ {
// read the data here, so we can fake a throttle/download // read the data here, so we can fake a throttle/download
@ -166,7 +166,7 @@ namespace SkiaSharp.Tests
var result = codec.StartIncrementalDecode (info, pixels, info.RowBytes); var result = codec.StartIncrementalDecode (info, pixels, info.RowBytes);
// make sure the start was successful // make sure the start was successful
Assert.Equal (SKCodecResult.Success, result); Assert.AreEqual (SKCodecResult.Success, result);
result = SKCodecResult.IncompleteInput; result = SKCodecResult.IncompleteInput;
while (result == SKCodecResult.IncompleteInput) { while (result == SKCodecResult.IncompleteInput) {
@ -182,12 +182,12 @@ namespace SkiaSharp.Tests
} }
// compare to original // compare to original
Assert.Equal (correctBytes, incremental.Pixels); Assert.AreEqual (correctBytes, incremental.Pixels);
} }
} }
} }
[Fact] [Test]
public void BitmapDecodesCorrectly () public void BitmapDecodesCorrectly ()
{ {
byte[] codecPixels; byte[] codecPixels;
@ -201,10 +201,10 @@ namespace SkiaSharp.Tests
bitmapPixels = bitmap.Bytes; bitmapPixels = bitmap.Bytes;
} }
Assert.Equal (codecPixels, bitmapPixels); Assert.AreEqual (codecPixels, bitmapPixels);
} }
[Fact] [Test]
public void BitmapDecodesCorrectlyWithManagedStream () public void BitmapDecodesCorrectlyWithManagedStream ()
{ {
byte[] codecPixels; byte[] codecPixels;
@ -219,7 +219,7 @@ namespace SkiaSharp.Tests
bitmapPixels = bitmap.Bytes; bitmapPixels = bitmap.Bytes;
} }
Assert.Equal (codecPixels, bitmapPixels); Assert.AreEqual (codecPixels, bitmapPixels);
} }
} }
} }

Просмотреть файл

@ -1,6 +1,6 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Xunit; using NUnit.Framework;
namespace SkiaSharp.Tests namespace SkiaSharp.Tests
{ {
@ -15,23 +15,23 @@ namespace SkiaSharp.Tests
SKColors.Blue SKColors.Blue
}; };
[Fact] [Test]
public void MembersRetrieveColors() public void MembersRetrieveColors()
{ {
var colorTable = new SKColorTable(Colors); var colorTable = new SKColorTable(Colors);
Assert.Equal(Colors.Length, colorTable.Count); Assert.AreEqual(Colors.Length, colorTable.Count);
Assert.Equal(Colors, colorTable.Colors); Assert.AreEqual(Colors, colorTable.Colors);
Assert.Equal(Colors[0], colorTable[0]); Assert.AreEqual(Colors[0], colorTable[0]);
Assert.Equal(Colors[1], colorTable[1]); Assert.AreEqual(Colors[1], colorTable[1]);
Assert.Equal(Colors[2], colorTable[2]); Assert.AreEqual(Colors[2], colorTable[2]);
Assert.Equal(Colors[3], colorTable[3]); Assert.AreEqual(Colors[3], colorTable[3]);
Assert.Equal(Colors[4], colorTable[4]); Assert.AreEqual(Colors[4], colorTable[4]);
} }
[Fact] [Test]
public void IndexerOutOfRangeBelow() public void IndexerOutOfRangeBelow()
{ {
var colorTable = new SKColorTable(Colors); var colorTable = new SKColorTable(Colors);
@ -42,7 +42,7 @@ namespace SkiaSharp.Tests
}); });
} }
[Fact] [Test]
public void IndexerOutOfRangeAbove() public void IndexerOutOfRangeAbove()
{ {
var colorTable = new SKColorTable(Colors); var colorTable = new SKColorTable(Colors);

Просмотреть файл

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Xunit; using NUnit.Framework;
using SKOtherColor = System.Tuple<float, float, float>; using SKOtherColor = System.Tuple<float, float, float>;
using ToOtherColor = System.Tuple<SkiaSharp.SKColor, System.Tuple<float, float, float>, string>; using ToOtherColor = System.Tuple<SkiaSharp.SKColor, System.Tuple<float, float, float>, string>;
@ -11,41 +11,41 @@ namespace SkiaSharp.Tests
{ {
private const int Precision = 2; private const int Precision = 2;
[Fact] [Test]
public void ColorWithComponent() public void ColorWithComponent()
{ {
var color = new SKColor(); var color = new SKColor();
Assert.Equal(0, color.Red); Assert.AreEqual(0, color.Red);
Assert.Equal(0, color.Green); Assert.AreEqual(0, color.Green);
Assert.Equal(0, color.Blue); Assert.AreEqual(0, color.Blue);
Assert.Equal(0, color.Alpha); Assert.AreEqual(0, color.Alpha);
var red = color.WithRed(255); var red = color.WithRed(255);
Assert.Equal(255, red.Red); Assert.AreEqual(255, red.Red);
Assert.Equal(0, red.Green); Assert.AreEqual(0, red.Green);
Assert.Equal(0, red.Blue); Assert.AreEqual(0, red.Blue);
Assert.Equal(0, red.Alpha); Assert.AreEqual(0, red.Alpha);
var green = color.WithGreen(255); var green = color.WithGreen(255);
Assert.Equal(0, green.Red); Assert.AreEqual(0, green.Red);
Assert.Equal(255, green.Green); Assert.AreEqual(255, green.Green);
Assert.Equal(0, green.Blue); Assert.AreEqual(0, green.Blue);
Assert.Equal(0, green.Alpha); Assert.AreEqual(0, green.Alpha);
var blue = color.WithBlue(255); var blue = color.WithBlue(255);
Assert.Equal(0, blue.Red); Assert.AreEqual(0, blue.Red);
Assert.Equal(0, blue.Green); Assert.AreEqual(0, blue.Green);
Assert.Equal(255, blue.Blue); Assert.AreEqual(255, blue.Blue);
Assert.Equal(0, blue.Alpha); Assert.AreEqual(0, blue.Alpha);
var alpha = color.WithAlpha(255); var alpha = color.WithAlpha(255);
Assert.Equal(0, alpha.Red); Assert.AreEqual(0, alpha.Red);
Assert.Equal(0, alpha.Green); Assert.AreEqual(0, alpha.Green);
Assert.Equal(0, alpha.Blue); Assert.AreEqual(0, alpha.Blue);
Assert.Equal(255, alpha.Alpha); Assert.AreEqual(255, alpha.Alpha);
} }
[Fact] [Test]
public void ColorRgbToHsl() public void ColorRgbToHsl()
{ {
var tuples = new List<ToOtherColor> { var tuples = new List<ToOtherColor> {
@ -69,21 +69,21 @@ namespace SkiaSharp.Tests
float h, s, l; float h, s, l;
rgb.ToHsl(out h, out s, out l); rgb.ToHsl(out h, out s, out l);
Assert.Equal(other.Item1, h, Precision); Assert.AreEqual(other.Item1, h, Precision);
Assert.Equal(other.Item2, s, Precision); Assert.AreEqual(other.Item2, s, Precision);
Assert.Equal(other.Item3, l, Precision); Assert.AreEqual(other.Item3, l, Precision);
// to RGB // to RGB
SKColor back = SKColor.FromHsl(other.Item1, other.Item2, other.Item3); SKColor back = SKColor.FromHsl(other.Item1, other.Item2, other.Item3);
Assert.Equal(rgb.Red, back.Red); Assert.AreEqual(rgb.Red, back.Red);
Assert.Equal(rgb.Green, back.Green); Assert.AreEqual(rgb.Green, back.Green);
Assert.Equal(rgb.Blue, back.Blue); Assert.AreEqual(rgb.Blue, back.Blue);
Assert.Equal(rgb.Alpha, back.Alpha); Assert.AreEqual(rgb.Alpha, back.Alpha);
} }
} }
[Fact] [Test]
public void ColorRgbToHsv() public void ColorRgbToHsv()
{ {
var tuples = new List<ToOtherColor> { var tuples = new List<ToOtherColor> {
@ -107,21 +107,21 @@ namespace SkiaSharp.Tests
float h, s, v; float h, s, v;
rgb.ToHsv(out h, out s, out v); rgb.ToHsv(out h, out s, out v);
Assert.Equal(other.Item1, h, Precision); Assert.AreEqual(other.Item1, h, Precision);
Assert.Equal(other.Item2, s, Precision); Assert.AreEqual(other.Item2, s, Precision);
Assert.Equal(other.Item3, v, Precision); Assert.AreEqual(other.Item3, v, Precision);
// to RGB // to RGB
SKColor back = SKColor.FromHsv(other.Item1, other.Item2, other.Item3); SKColor back = SKColor.FromHsv(other.Item1, other.Item2, other.Item3);
Assert.Equal(rgb.Red, back.Red); Assert.AreEqual(rgb.Red, back.Red);
Assert.Equal(rgb.Green, back.Green); Assert.AreEqual(rgb.Green, back.Green);
Assert.Equal(rgb.Blue, back.Blue); Assert.AreEqual(rgb.Blue, back.Blue);
Assert.Equal(rgb.Alpha, back.Alpha); Assert.AreEqual(rgb.Alpha, back.Alpha);
} }
} }
[Fact] [Test]
public void HexToColor() public void HexToColor()
{ {
var tuples = new List<Tuple<string, SKColor>> { var tuples = new List<Tuple<string, SKColor>> {
@ -151,11 +151,11 @@ namespace SkiaSharp.Tests
SKColor color = SKColor.Parse(hex); SKColor color = SKColor.Parse(hex);
Assert.Equal(other, color); Assert.AreEqual(other, color);
} }
} }
[Fact] [Test]
public void InvalidHexToColor() public void InvalidHexToColor()
{ {
var tuples = new List<string> { var tuples = new List<string> {

Просмотреть файл

@ -1,6 +1,6 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Xunit; using NUnit.Framework;
namespace SkiaSharp.Tests namespace SkiaSharp.Tests
{ {
@ -8,16 +8,17 @@ namespace SkiaSharp.Tests
{ {
private readonly static byte[] OddData = new byte[] { 1, 3, 5, 7, 9 }; private readonly static byte[] OddData = new byte[] { 1, 3, 5, 7, 9 };
[Fact] [Test]
public void ValidDataProperties() public void ValidDataProperties()
{ {
var data = new SKData(OddData); var data = new SKData(OddData);
Assert.Equal(OddData.Length, data.Size); Assert.AreEqual(OddData.Length, data.Size);
Assert.Equal(OddData, data.ToArray()); Assert.AreEqual(OddData, data.ToArray());
} }
[Fact(Skip = "Doesn't work as it relies on memory being overwritten by an external process.")] [Test]
[Ignore("Doesn't work as it relies on memory being overwritten by an external process.")]
public void DataDisposedReturnsInvalidStream() public void DataDisposedReturnsInvalidStream()
{ {
// create data // create data
@ -28,14 +29,14 @@ namespace SkiaSharp.Tests
// nuke the data // nuke the data
data.Dispose(); data.Dispose();
Assert.Equal(IntPtr.Zero, data.Handle); Assert.AreEqual(IntPtr.Zero, data.Handle);
// read the stream // read the stream
var buffer = new byte[OddData.Length]; var buffer = new byte[OddData.Length];
stream.Read(buffer, 0, buffer.Length); stream.Read(buffer, 0, buffer.Length);
// since the data was nuked, they will differ // since the data was nuked, they will differ
Assert.NotEqual(OddData, buffer); Assert.AreNotEqual(OddData, buffer);
} }
} }
} }

Просмотреть файл

@ -1,13 +1,13 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Xunit; using NUnit.Framework;
namespace SkiaSharp.Tests namespace SkiaSharp.Tests
{ {
public class SKManagedStreamTest : SKTest public class SKManagedStreamTest : SKTest
{ {
[Fact] [Test]
public void ManagedStreamReadsByteCorrectly() public void ManagedStreamReadsByteCorrectly()
{ {
var data = new byte[1024]; var data = new byte[1024];
@ -20,25 +20,25 @@ namespace SkiaSharp.Tests
var skManagedStream = new SKManagedStream(stream); var skManagedStream = new SKManagedStream(stream);
skManagedStream.Rewind(); skManagedStream.Rewind();
Assert.Equal(0, stream.Position); Assert.AreEqual(0, stream.Position);
Assert.Equal(0, skManagedStream.Position); Assert.AreEqual(0, skManagedStream.Position);
for (int i = 0; i < data.Length; i++) for (int i = 0; i < data.Length; i++)
{ {
skManagedStream.Position = i; skManagedStream.Position = i;
Assert.Equal(i, stream.Position); Assert.AreEqual(i, stream.Position);
Assert.Equal(i, skManagedStream.Position); Assert.AreEqual(i, skManagedStream.Position);
Assert.Equal((byte)(i % byte.MaxValue), data[i]); Assert.AreEqual((byte)(i % byte.MaxValue), data[i]);
Assert.Equal((byte)(i % byte.MaxValue), skManagedStream.ReadByte()); Assert.AreEqual((byte)(i % byte.MaxValue), skManagedStream.ReadByte());
Assert.Equal(i + 1, stream.Position); Assert.AreEqual(i + 1, stream.Position);
Assert.Equal(i + 1, skManagedStream.Position); Assert.AreEqual(i + 1, skManagedStream.Position);
} }
} }
[Fact] [Test]
public void ManagedStreamReadsChunkCorrectly() public void ManagedStreamReadsChunkCorrectly()
{ {
var data = new byte[1024]; var data = new byte[1024];
@ -51,16 +51,16 @@ namespace SkiaSharp.Tests
var skManagedStream = new SKManagedStream(stream); var skManagedStream = new SKManagedStream(stream);
skManagedStream.Rewind(); skManagedStream.Rewind();
Assert.Equal(0, stream.Position); Assert.AreEqual(0, stream.Position);
Assert.Equal(0, skManagedStream.Position); Assert.AreEqual(0, skManagedStream.Position);
var buffer = new byte[data.Length / 2]; var buffer = new byte[data.Length / 2];
skManagedStream.Read(buffer, buffer.Length); skManagedStream.Read(buffer, buffer.Length);
Assert.Equal(data.Take(buffer.Length), buffer); Assert.AreEqual(data.Take(buffer.Length), buffer);
} }
[Fact] [Test]
public void ManagedStreamReadsOffsetChunkCorrectly() public void ManagedStreamReadsOffsetChunkCorrectly()
{ {
var data = new byte[1024]; var data = new byte[1024];
@ -79,11 +79,11 @@ namespace SkiaSharp.Tests
var buffer = new byte[data.Length]; var buffer = new byte[data.Length];
var taken = skManagedStream.Read(buffer, buffer.Length); var taken = skManagedStream.Read(buffer, buffer.Length);
Assert.Equal(data.Length - offset, taken); Assert.AreEqual(data.Length - offset, taken);
var resultData = data.Skip(offset).Take(buffer.Length).ToArray(); var resultData = data.Skip(offset).Take(buffer.Length).ToArray();
resultData = resultData.Concat(Enumerable.Repeat<byte>(0, offset)).ToArray(); resultData = resultData.Concat(Enumerable.Repeat<byte>(0, offset)).ToArray();
Assert.Equal(resultData, buffer); Assert.AreEqual(resultData, buffer);
} }
} }
} }

Просмотреть файл

@ -1,12 +1,12 @@
using System; using System;
using System.Linq; using System.Linq;
using Xunit; using NUnit.Framework;
namespace SkiaSharp.Tests namespace SkiaSharp.Tests
{ {
public class SKPaintTest : SKTest public class SKPaintTest : SKTest
{ {
[Fact] [Test]
public void StrokePropertyValuesAreCorrect() public void StrokePropertyValuesAreCorrect()
{ {
var paint = new SKPaint(); var paint = new SKPaint();
@ -18,7 +18,7 @@ namespace SkiaSharp.Tests
Assert.False(paint.IsStroke); Assert.False(paint.IsStroke);
} }
[Fact] [Test]
public void GetFillPathIsWorking() public void GetFillPathIsWorking()
{ {
var paint = new SKPaint(); var paint = new SKPaint();
@ -32,11 +32,11 @@ namespace SkiaSharp.Tests
var isFilled = paint.GetFillPath(path, fillPath); var isFilled = paint.GetFillPath(path, fillPath);
Assert.True(isFilled); Assert.True(isFilled);
Assert.Equal(rect, fillPath.Bounds); Assert.AreEqual(rect, fillPath.Bounds);
Assert.Equal(4, fillPath.PointCount); Assert.AreEqual(4, fillPath.PointCount);
} }
[Fact] [Test]
public void GetFillPathIsWorkingWithLine() public void GetFillPathIsWorkingWithLine()
{ {
var paint = new SKPaint(); var paint = new SKPaint();
@ -52,17 +52,17 @@ namespace SkiaSharp.Tests
var isFilled = paint.GetFillPath(path, fillPath); var isFilled = paint.GetFillPath(path, fillPath);
Assert.True(isFilled); Assert.True(isFilled);
Assert.Equal(thinRect, fillPath.Bounds); Assert.AreEqual(thinRect, fillPath.Bounds);
Assert.Equal(2, fillPath.PointCount); Assert.AreEqual(2, fillPath.PointCount);
paint.StrokeWidth = 20; paint.StrokeWidth = 20;
paint.IsStroke = true; paint.IsStroke = true;
isFilled = paint.GetFillPath(path, fillPath); isFilled = paint.GetFillPath(path, fillPath);
Assert.True(isFilled); Assert.True(isFilled);
Assert.Equal(rect, fillPath.Bounds); Assert.AreEqual(rect, fillPath.Bounds);
Assert.Equal(4 + 1, fillPath.PointCount); // +1 becuase the last point is the same as the first Assert.AreEqual(4 + 1, fillPath.PointCount); // +1 becuase the last point is the same as the first
Assert.Equal(4, fillPath.Points.Distinct().Count()); Assert.AreEqual(4, fillPath.Points.Distinct().Count());
} }
} }
} }

Просмотреть файл

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Xunit; using NUnit.Framework;
using ParsePathTest = System.Tuple<System.String, SkiaSharp.SKRect>; using ParsePathTest = System.Tuple<System.String, SkiaSharp.SKRect>;
@ -34,10 +34,10 @@ namespace SkiaSharp.Tests
var str2 = path2.ToSvgPathData (); var str2 = path2.ToSvgPathData ();
Assert.NotNull (str2); Assert.NotNull (str2);
Assert.Equal (str, str2); Assert.AreEqual (str, str2);
} }
[Fact] [Test]
public void PathPointsAreCorrect() public void PathPointsAreCorrect()
{ {
using (var path = new SKPath ()) { using (var path = new SKPath ()) {
@ -58,19 +58,19 @@ namespace SkiaSharp.Tests
path.Close (); path.Close ();
// the right number/count // the right number/count
Assert.Equal (25, path.PointCount); Assert.AreEqual (25, path.PointCount);
Assert.Equal (25, path.Points.Length); Assert.AreEqual (25, path.Points.Length);
// the right value // the right value
Assert.Equal (new SKPoint (68.6763107f, 56.0058575f), path.GetPoint (1)); Assert.AreEqual (new SKPoint (68.6763107f, 56.0058575f), path.GetPoint (1));
Assert.Equal (new SKPoint (68.6763107f, 56.0058575f), path.Points [1]); Assert.AreEqual (new SKPoint (68.6763107f, 56.0058575f), path.Points [1]);
// the right segment masks // the right segment masks
Assert.Equal (SKPathSegmentMask.Cubic | SKPathSegmentMask.Line, path.SegmentMasks); Assert.AreEqual (SKPathSegmentMask.Cubic | SKPathSegmentMask.Line, path.SegmentMasks);
} }
} }
[Fact] [Test]
public void PathContainsPoint() public void PathContainsPoint()
{ {
using (var path = new SKPath ()) { using (var path = new SKPath ()) {
@ -81,18 +81,18 @@ namespace SkiaSharp.Tests
} }
} }
[Fact] [Test]
public void GetLastPoint() public void GetLastPoint()
{ {
using (var path = new SKPath ()) { using (var path = new SKPath ()) {
path.MoveTo (0, 0); path.MoveTo (0, 0);
path.LineTo (10, 20); path.LineTo (10, 20);
Assert.Equal (new SKPoint(10, 20), path.LastPoint); Assert.AreEqual (new SKPoint(10, 20), path.LastPoint);
} }
} }
[Fact] [Test]
public void ThumbtackShapeIsConcave () public void ThumbtackShapeIsConcave ()
{ {
// based on test_skbug_3469 // based on test_skbug_3469
@ -102,11 +102,11 @@ namespace SkiaSharp.Tests
path.QuadTo (20, 50, 80, 50); path.QuadTo (20, 50, 80, 50);
path.QuadTo (20, 50, 20, 80); path.QuadTo (20, 50, 20, 80);
Assert.Equal (SKPathConvexity.Concave, path.Convexity); Assert.AreEqual (SKPathConvexity.Concave, path.Convexity);
} }
} }
[Fact] [Test]
public void PathConsistentAfterClose () public void PathConsistentAfterClose ()
{ {
// based on test_path_close_issue1474 // based on test_path_close_issue1474
@ -123,8 +123,8 @@ namespace SkiaSharp.Tests
path.RLineTo (50, 50); // This should go to 50,50. path.RLineTo (50, 50); // This should go to 50,50.
last = path.LastPoint; last = path.LastPoint;
Assert.Equal (50, last.X); Assert.AreEqual (50, last.X);
Assert.Equal (50, last.Y); Assert.AreEqual (50, last.Y);
// Test rQuadTo(). // Test rQuadTo().
path.Rewind (); path.Rewind ();
@ -134,8 +134,8 @@ namespace SkiaSharp.Tests
path.RQuadTo (50, 50, 75, 75); path.RQuadTo (50, 50, 75, 75);
last = path.LastPoint; last = path.LastPoint;
Assert.Equal (75, last.X); Assert.AreEqual (75, last.X);
Assert.Equal (75, last.Y); Assert.AreEqual (75, last.Y);
// Test rConicTo(). // Test rConicTo().
path.Rewind (); path.Rewind ();
@ -145,8 +145,8 @@ namespace SkiaSharp.Tests
path.RConicTo (50, 50, 85, 85, 2); path.RConicTo (50, 50, 85, 85, 2);
last = path.LastPoint; last = path.LastPoint;
Assert.Equal (85, last.X); Assert.AreEqual (85, last.X);
Assert.Equal (85, last.Y); Assert.AreEqual (85, last.Y);
// Test rCubicTo(). // Test rCubicTo().
path.Rewind (); path.Rewind ();
@ -156,12 +156,12 @@ namespace SkiaSharp.Tests
path.RCubicTo (50, 50, 85, 85, 95, 95); path.RCubicTo (50, 50, 85, 85, 95, 95);
last = path.LastPoint; last = path.LastPoint;
Assert.Equal (95, last.X); Assert.AreEqual (95, last.X);
Assert.Equal (95, last.Y); Assert.AreEqual (95, last.Y);
} }
} }
[Fact] [Test]
public void ParsePathReturnsValidPath () public void ParsePathReturnsValidPath ()
{ {
// based on ParsePath // based on ParsePath
@ -170,7 +170,7 @@ namespace SkiaSharp.Tests
var path = SKPath.ParseSvgPathData (test.Item1); var path = SKPath.ParseSvgPathData (test.Item1);
Assert.NotNull (path); Assert.NotNull (path);
Assert.Equal (test.Item2, path.Bounds); Assert.AreEqual (test.Item2, path.Bounds);
TestToFromSvgPath (path); TestToFromSvgPath (path);
} }
@ -188,7 +188,7 @@ namespace SkiaSharp.Tests
} }
} }
[Fact] [Test]
public void PathBoundsAndRegionBoundsMatch () public void PathBoundsAndRegionBoundsMatch ()
{ {
var path = new SKPath (); var path = new SKPath ();
@ -196,22 +196,22 @@ namespace SkiaSharp.Tests
path.LineTo (90, 90); path.LineTo (90, 90);
var bounds = path.Bounds; var bounds = path.Bounds;
Assert.Equal (10f, bounds.Left); Assert.AreEqual (10f, bounds.Left);
Assert.Equal (10f, bounds.Top); Assert.AreEqual (10f, bounds.Top);
Assert.Equal (90f, bounds.Right); Assert.AreEqual (90f, bounds.Right);
Assert.Equal (90f, bounds.Bottom); Assert.AreEqual (90f, bounds.Bottom);
var region = new SKRegion (); var region = new SKRegion ();
region.SetRect (new SKRectI (10, 10, 90, 90)); region.SetRect (new SKRectI (10, 10, 90, 90));
var regionBounds = region.Bounds; var regionBounds = region.Bounds;
Assert.Equal (10f, regionBounds.Left); Assert.AreEqual (10f, regionBounds.Left);
Assert.Equal (10f, regionBounds.Top); Assert.AreEqual (10f, regionBounds.Top);
Assert.Equal (90f, regionBounds.Right); Assert.AreEqual (90f, regionBounds.Right);
Assert.Equal (90f, regionBounds.Bottom); Assert.AreEqual (90f, regionBounds.Bottom);
} }
[Fact] [Test]
public void BoundsAndTightBoundAreCorrect () public void BoundsAndTightBoundAreCorrect ()
{ {
const int Precision = 6; const int Precision = 6;
@ -222,20 +222,20 @@ namespace SkiaSharp.Tests
path.RCubicTo (-34.64102137842175f, 19.9999998f, 0f, 40f, 0f, 40f); path.RCubicTo (-34.64102137842175f, 19.9999998f, 0f, 40f, 0f, 40f);
var bounds = path.Bounds; var bounds = path.Bounds;
Assert.Equal (-34.641022f, bounds.Left, Precision); Assert.AreEqual (-34.641022f, bounds.Left, Precision);
Assert.Equal (-25.814698f, bounds.Top, Precision); Assert.AreEqual (-25.814698f, bounds.Top, Precision);
Assert.Equal (-6.215782e-07f, bounds.Right, Precision); Assert.AreEqual (-6.215782e-07f, bounds.Right, Precision);
Assert.Equal (14.185303f, bounds.Bottom, Precision); Assert.AreEqual (14.185303f, bounds.Bottom, Precision);
var tightBounds = path.TightBounds; var tightBounds = path.TightBounds;
Assert.Equal (-15.396009f, tightBounds.Left, Precision); Assert.AreEqual (-15.396009f, tightBounds.Left, Precision);
Assert.Equal (-25.814698f, tightBounds.Top, Precision); Assert.AreEqual (-25.814698f, tightBounds.Top, Precision);
Assert.Equal (0f, tightBounds.Right, Precision); Assert.AreEqual (0f, tightBounds.Right, Precision);
Assert.Equal (14.185303f, tightBounds.Bottom, Precision); Assert.AreEqual (14.185303f, tightBounds.Bottom, Precision);
} }
} }
[Fact] [Test]
public void MeasuringSegementsWorks () public void MeasuringSegementsWorks ()
{ {
using (SKPath path = new SKPath ()) using (SKPath path = new SKPath ())
@ -243,18 +243,18 @@ namespace SkiaSharp.Tests
path.MoveTo (10f, 10f); path.MoveTo (10f, 10f);
path.LineTo (110f, 10f); path.LineTo (110f, 10f);
Assert.Equal (SKPathSegmentMask.Line, path.SegmentMasks); Assert.AreEqual (SKPathSegmentMask.Line, path.SegmentMasks);
var measure = new SKPathMeasure (path); var measure = new SKPathMeasure (path);
Assert.Equal (100f, measure.Length); Assert.AreEqual (100f, measure.Length);
var segment = new SKPath (); var segment = new SKPath ();
var result = measure.GetSegment (20, 50, segment, true); var result = measure.GetSegment (20, 50, segment, true);
Assert.True (result); Assert.True (result);
Assert.Equal (2, segment.PointCount); Assert.AreEqual (2, segment.PointCount);
Assert.Equal (new SKPoint (30, 10), segment.Points [0]); Assert.AreEqual (new SKPoint (30, 10), segment.Points [0]);
Assert.Equal (new SKPoint (60, 10), segment.Points [1]); Assert.AreEqual (new SKPoint (60, 10), segment.Points [1]);
} }
} }
} }

Просмотреть файл

@ -1,20 +1,20 @@
using System; using System;
using System.IO; using System.IO;
using Xunit; using NUnit.Framework;
namespace SkiaSharp.Tests namespace SkiaSharp.Tests
{ {
public class SKStringTest : SKTest public class SKStringTest : SKTest
{ {
[Fact] [Test]
public void StringIsMarshaledCorrectly () public void StringIsMarshaledCorrectly ()
{ {
using (var typeface = SKTypeface.FromFile (Path.Combine (PathToFonts, "SpiderSymbol.ttf"))) using (var typeface = SKTypeface.FromFile (Path.Combine (PathToFonts, "SpiderSymbol.ttf")))
{ {
if (IsLinux) // see issue #225 if (IsLinux) // see issue #225
Assert.Equal("", typeface.FamilyName); Assert.AreEqual("", typeface.FamilyName);
else else
Assert.Equal ("SpiderSymbol", typeface.FamilyName); Assert.AreEqual ("SpiderSymbol", typeface.FamilyName);
} }
} }
} }

Просмотреть файл

@ -1,7 +1,7 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using Xunit; using NUnit.Framework;
namespace SkiaSharp.Tests namespace SkiaSharp.Tests
{ {
@ -35,7 +35,7 @@ namespace SkiaSharp.Tests
bitmap.UnlockBits(data); bitmap.UnlockBits(data);
} }
[Fact] [Test]
public void SurfaceCanvasReturnTheSameInstance() public void SurfaceCanvasReturnTheSameInstance()
{ {
Draw(surface => Draw(surface =>
@ -46,14 +46,14 @@ namespace SkiaSharp.Tests
Assert.NotNull(skcanvas1); Assert.NotNull(skcanvas1);
Assert.NotNull(skcanvas2); Assert.NotNull(skcanvas2);
Assert.Equal(skcanvas1, skcanvas2); Assert.AreEqual(skcanvas1, skcanvas2);
Assert.True(skcanvas1 == skcanvas2); Assert.True(skcanvas1 == skcanvas2);
Assert.Same(skcanvas1, skcanvas2); Assert.AreSame(skcanvas1, skcanvas2);
}); });
} }
[Fact] [Test]
public void SecondSurfaceWasCreatedDifferent() public void SecondSurfaceWasCreatedDifferent()
{ {
var data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bitmap.PixelFormat); var data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bitmap.PixelFormat);
@ -64,8 +64,8 @@ namespace SkiaSharp.Tests
Assert.NotNull(surface1); Assert.NotNull(surface1);
Assert.NotNull(surface2); Assert.NotNull(surface2);
Assert.NotEqual(surface1, surface2); Assert.AreNotEqual(surface1, surface2);
Assert.NotEqual(surface1.Handle, surface2.Handle); Assert.AreNotEqual(surface1.Handle, surface2.Handle);
surface1.Dispose(); surface1.Dispose();
surface2.Dispose(); surface2.Dispose();
@ -73,7 +73,7 @@ namespace SkiaSharp.Tests
bitmap.UnlockBits(data); bitmap.UnlockBits(data);
} }
[Fact] [Test]
public void SurfaceWasCreated() public void SurfaceWasCreated()
{ {
var data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bitmap.PixelFormat); var data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bitmap.PixelFormat);
@ -81,11 +81,11 @@ namespace SkiaSharp.Tests
var surface = SKSurface.Create(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, data.Scan0, data.Stride); var surface = SKSurface.Create(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, data.Scan0, data.Stride);
Assert.NotNull(surface); Assert.NotNull(surface);
Assert.NotEqual(IntPtr.Zero, surface.Handle); Assert.AreNotEqual(IntPtr.Zero, surface.Handle);
surface.Dispose(); surface.Dispose();
Assert.Equal(IntPtr.Zero, surface.Handle); Assert.AreEqual(IntPtr.Zero, surface.Handle);
bitmap.UnlockBits(data); bitmap.UnlockBits(data);
} }

Просмотреть файл

@ -1,13 +1,13 @@
using System; using System;
using System.IO; using System.IO;
using Xunit; using NUnit.Framework;
using System.Xml.Linq; using System.Xml.Linq;
namespace SkiaSharp.Tests namespace SkiaSharp.Tests
{ {
public class SKSvgTest : SKTest public class SKSvgTest : SKTest
{ {
[Fact] [Test]
public void LoadSvgCanvasSize() public void LoadSvgCanvasSize()
{ {
var path = Path.Combine(PathToImages, "logos.svg"); var path = Path.Combine(PathToImages, "logos.svg");
@ -15,10 +15,10 @@ namespace SkiaSharp.Tests
var svg = new SKSvg(); var svg = new SKSvg();
svg.Load(path); svg.Load(path);
Assert.Equal(new SKSize(300, 300), svg.CanvasSize); Assert.AreEqual(new SKSize(300, 300), svg.CanvasSize);
} }
[Fact] [Test]
public void LoadSvgCustomCanvasSize() public void LoadSvgCustomCanvasSize()
{ {
var path = Path.Combine(PathToImages, "logos.svg"); var path = Path.Combine(PathToImages, "logos.svg");
@ -26,10 +26,10 @@ namespace SkiaSharp.Tests
var svg = new SKSvg(new SKSize(150, 150)); var svg = new SKSvg(new SKSize(150, 150));
svg.Load(path); svg.Load(path);
Assert.Equal(new SKSize(150, 150), svg.CanvasSize); Assert.AreEqual(new SKSize(150, 150), svg.CanvasSize);
} }
[Fact] [Test]
public void SvgLoadsToBitmap() public void SvgLoadsToBitmap()
{ {
var path = Path.Combine(PathToImages, "logos.svg"); var path = Path.Combine(PathToImages, "logos.svg");
@ -43,10 +43,10 @@ namespace SkiaSharp.Tests
canvas.DrawPicture(svg.Picture); canvas.DrawPicture(svg.Picture);
canvas.Flush(); canvas.Flush();
Assert.Equal(background, bmp.GetPixel(0, 0)); Assert.AreEqual(background, bmp.GetPixel(0, 0));
} }
[Fact] [Test]
public void SvgCanvasCreatesValidDrawing() public void SvgCanvasCreatesValidDrawing()
{ {
using (var stream = new MemoryStream()) using (var stream = new MemoryStream())
@ -74,23 +74,23 @@ namespace SkiaSharp.Tests
var ns = (XNamespace)"http://www.w3.org/2000/svg"; var ns = (XNamespace)"http://www.w3.org/2000/svg";
Assert.Equal(ns, svg.GetDefaultNamespace()); Assert.AreEqual(ns, svg.GetDefaultNamespace());
Assert.Equal("200", svg.Attribute("width").Value); Assert.AreEqual("200", svg.Attribute("width").Value);
Assert.Equal("150", svg.Attribute("height").Value); Assert.AreEqual("150", svg.Attribute("height").Value);
var rect = svg.Element(ns + "rect"); var rect = svg.Element(ns + "rect");
Assert.Equal("rgb(0,0,255)", rect.Attribute("fill").Value); Assert.AreEqual("rgb(0,0,255)", rect.Attribute("fill").Value);
Assert.Equal("50", rect.Attribute("x").Value); Assert.AreEqual("50", rect.Attribute("x").Value);
Assert.Equal("70", rect.Attribute("y").Value); Assert.AreEqual("70", rect.Attribute("y").Value);
Assert.Equal("100", rect.Attribute("width").Value); Assert.AreEqual("100", rect.Attribute("width").Value);
Assert.Equal("30", rect.Attribute("height").Value); Assert.AreEqual("30", rect.Attribute("height").Value);
var ellipse = svg.Element(ns + "ellipse"); var ellipse = svg.Element(ns + "ellipse");
Assert.Equal("rgb(255,0,0)", ellipse.Attribute("fill").Value); Assert.AreEqual("rgb(255,0,0)", ellipse.Attribute("fill").Value);
Assert.Equal("100", ellipse.Attribute("cx").Value); Assert.AreEqual("100", ellipse.Attribute("cx").Value);
Assert.Equal("85", ellipse.Attribute("cy").Value); Assert.AreEqual("85", ellipse.Attribute("cy").Value);
Assert.Equal("50", ellipse.Attribute("rx").Value); Assert.AreEqual("50", ellipse.Attribute("rx").Value);
Assert.Equal("15", ellipse.Attribute("ry").Value); Assert.AreEqual("15", ellipse.Attribute("ry").Value);
} }
} }
} }

Просмотреть файл

@ -2,17 +2,19 @@
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Xunit; using NUnit.Framework;
[assembly: Parallelizable(ParallelScope.Fixtures)]
namespace SkiaSharp.Tests namespace SkiaSharp.Tests
{ {
public abstract class SKTest public abstract class SKTest
{ {
#if NET_STANDARD
protected static readonly string PathToAssembly = Path.GetDirectoryName(typeof(SKTest).GetTypeInfo().Assembly.Location); protected static readonly string PathToAssembly = Path.GetDirectoryName(typeof(SKTest).GetTypeInfo().Assembly.Location);
protected static readonly string PathToFonts = Path.Combine(PathToAssembly, "fonts"); protected static readonly string PathToFonts = Path.Combine(PathToAssembly, "fonts");
protected static readonly string PathToImages = Path.Combine(PathToAssembly, "images"); protected static readonly string PathToImages = Path.Combine(PathToAssembly, "images");
#if NET_STANDARD
protected static bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); protected static bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
protected static bool IsMac => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); protected static bool IsMac => RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
protected static bool IsUnix => IsLinux || IsMac; protected static bool IsUnix => IsLinux || IsMac;
@ -45,9 +47,6 @@ namespace SkiaSharp.Tests
} }
} }
protected const string PathToFonts = "fonts";
protected const string PathToImages = "images";
protected static bool IsMac => MacPlatformDetector.IsMac.Value; protected static bool IsMac => MacPlatformDetector.IsMac.Value;
protected static bool IsUnix => Environment.OSVersion.Platform == PlatformID.Unix || IsMac; protected static bool IsUnix => Environment.OSVersion.Platform == PlatformID.Unix || IsMac;
protected static bool IsLinux => IsUnix && !IsMac; protected static bool IsLinux => IsUnix && !IsMac;

Просмотреть файл

@ -1,5 +1,5 @@
using System; using System;
using Xunit; using NUnit.Framework;
using System.IO; using System.IO;
namespace SkiaSharp.Tests namespace SkiaSharp.Tests
@ -22,21 +22,21 @@ namespace SkiaSharp.Tests
0x02, 0x00, 0x24, 0x00, 0x44, 0x02, 0x00, 0x24, 0x00, 0x44,
}; };
[Fact] [Test]
public void NullInWrongFileName() public void NullInWrongFileName()
{ {
Assert.Null(SKTypeface.FromFile(Path.Combine(PathToFonts, "font that doesn't exist.ttf"))); Assert.Null(SKTypeface.FromFile(Path.Combine(PathToFonts, "font that doesn't exist.ttf")));
} }
[Fact] [Test]
public void TestFamilyName() public void TestFamilyName()
{ {
using (var typeface = SKTypeface.FromFile(Path.Combine(PathToFonts, "Roboto2-Regular_NoEmbed.ttf"))) using (var typeface = SKTypeface.FromFile(Path.Combine(PathToFonts, "Roboto2-Regular_NoEmbed.ttf")))
{ {
if (IsLinux) // see issue #225 if (IsLinux) // see issue #225
Assert.Equal("", typeface.FamilyName); Assert.AreEqual("", typeface.FamilyName);
else else
Assert.Equal("Roboto2", typeface.FamilyName); Assert.AreEqual("Roboto2", typeface.FamilyName);
} }
} }
@ -58,46 +58,46 @@ namespace SkiaSharp.Tests
(UInt32)(v[3]) << 00; (UInt32)(v[3]) << 00;
} }
[Fact] [Test]
public void TestGetTableTags() public void TestGetTableTags()
{ {
using (var typeface = SKTypeface.FromFile(Path.Combine(PathToFonts, "SpiderSymbol.ttf"))) using (var typeface = SKTypeface.FromFile(Path.Combine(PathToFonts, "SpiderSymbol.ttf")))
{ {
if (IsLinux) // see issue #225 if (IsLinux) // see issue #225
Assert.Equal("", typeface.FamilyName); Assert.AreEqual("", typeface.FamilyName);
else else
Assert.Equal("SpiderSymbol", typeface.FamilyName); Assert.AreEqual("SpiderSymbol", typeface.FamilyName);
var tables = typeface.GetTableTags(); var tables = typeface.GetTableTags();
Assert.Equal(ExpectedTablesSpiderFont.Length, tables.Length); Assert.AreEqual(ExpectedTablesSpiderFont.Length, tables.Length);
for (int i = 0; i < tables.Length; i++) { for (int i = 0; i < tables.Length; i++) {
Assert.Equal(ExpectedTablesSpiderFont[i], GetReadableTag(tables[i])); Assert.AreEqual(ExpectedTablesSpiderFont[i], GetReadableTag(tables[i]));
} }
} }
} }
[Fact] [Test]
public void TestGetTableData() public void TestGetTableData()
{ {
using (var typeface = SKTypeface.FromFile(Path.Combine(PathToFonts, "ReallyBigA.ttf"))) using (var typeface = SKTypeface.FromFile(Path.Combine(PathToFonts, "ReallyBigA.ttf")))
{ {
if (IsLinux) // see issue #225 if (IsLinux) // see issue #225
Assert.Equal("", typeface.FamilyName); Assert.AreEqual("", typeface.FamilyName);
else else
Assert.Equal("ReallyBigA", typeface.FamilyName); Assert.AreEqual("ReallyBigA", typeface.FamilyName);
var tables = typeface.GetTableTags(); var tables = typeface.GetTableTags();
for (int i = 0; i < tables.Length; i++) { for (int i = 0; i < tables.Length; i++) {
byte[] tableData = typeface.GetTableData(tables[i]); byte[] tableData = typeface.GetTableData(tables[i]);
Assert.Equal(ExpectedTableLengthsReallyBigAFont[i], tableData.Length); Assert.AreEqual(ExpectedTableLengthsReallyBigAFont[i], tableData.Length);
} }
Assert.Equal(ExpectedTableDataPostReallyBigAFont, typeface.GetTableData(GetIntTag("post"))); Assert.AreEqual(ExpectedTableDataPostReallyBigAFont, typeface.GetTableData(GetIntTag("post")));
} }
} }
[Fact] [Test]
public void TestFontManagerMatchCharacter() public void TestFontManagerMatchCharacter()
{ {
var fonts = SKFontManager.Default; var fonts = SKFontManager.Default;
@ -106,15 +106,15 @@ namespace SkiaSharp.Tests
using (var typeface = fonts.MatchCharacter(emojiChar)) using (var typeface = fonts.MatchCharacter(emojiChar))
{ {
if (IsLinux) if (IsLinux)
Assert.Equal("Symbola", typeface.FamilyName); Assert.AreEqual("Symbola", typeface.FamilyName);
else if (IsMac) else if (IsMac)
Assert.Equal("Apple Color Emoji", typeface.FamilyName); Assert.AreEqual("Apple Color Emoji", typeface.FamilyName);
else if (IsWindows) else if (IsWindows)
Assert.Equal("Segoe UI Emoji", typeface.FamilyName); Assert.AreEqual("Segoe UI Emoji", typeface.FamilyName);
} }
} }
[Fact] [Test]
public void ExceptionInInvalidGetTableData() public void ExceptionInInvalidGetTableData()
{ {
using (var typeface = SKTypeface.FromFile(Path.Combine(PathToFonts, "Distortable.ttf"))) using (var typeface = SKTypeface.FromFile(Path.Combine(PathToFonts, "Distortable.ttf")))
@ -123,7 +123,7 @@ namespace SkiaSharp.Tests
} }
} }
[Fact] [Test]
public void TestTryGetTableData() public void TestTryGetTableData()
{ {
using (var typeface = SKTypeface.FromFile(Path.Combine(PathToFonts, "ReallyBigA.ttf"))) using (var typeface = SKTypeface.FromFile(Path.Combine(PathToFonts, "ReallyBigA.ttf")))
@ -132,15 +132,15 @@ namespace SkiaSharp.Tests
for (int i = 0; i < tables.Length; i++) { for (int i = 0; i < tables.Length; i++) {
byte[] tableData; byte[] tableData;
Assert.True(typeface.TryGetTableData(tables[i], out tableData)); Assert.True(typeface.TryGetTableData(tables[i], out tableData));
Assert.Equal(ExpectedTableLengthsReallyBigAFont[i], tableData.Length); Assert.AreEqual(ExpectedTableLengthsReallyBigAFont[i], tableData.Length);
} }
Assert.Equal(ExpectedTableDataPostReallyBigAFont, typeface.GetTableData(GetIntTag("post"))); Assert.AreEqual(ExpectedTableDataPostReallyBigAFont, typeface.GetTableData(GetIntTag("post")));
} }
} }
[Fact] [Test]
public void InvalidTryGetTableData() public void InvalidTryGetTableData()
{ {
using (var typeface = SKTypeface.FromFile(Path.Combine(PathToFonts, "Distortable.ttf"))) using (var typeface = SKTypeface.FromFile(Path.Combine(PathToFonts, "Distortable.ttf")))

Просмотреть файл

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Cake" version="0.17.0" /> <package id="Cake" version="0.17.0" />
<package id="XUnit.Runner.Console" version="2.1.0" /> <package id="NUnit.Console" version="3.6.0" />
<package id="Microsoft.DotNet.BuildTools.GenAPI" version="1.0.0-beta-00081" /> <package id="Microsoft.DotNet.BuildTools.GenAPI" version="1.0.0-beta-00081" />
</packages> </packages>