[Tests] Added a set of unit tests for Windows Desktop

This commit is contained in:
Matthew Leibowitz 2016-02-02 00:23:45 +02:00
Родитель 033c724f21
Коммит 81b487bd00
8 изменённых файлов: 428 добавлений и 0 удалений

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

@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Skia.WindowsDesktop.Demo",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkiaSharp.WindowsDesktop", "..\..\binding\SkiaSharp.WindowsDesktop\SkiaSharp.WindowsDesktop.csproj", "{EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkiaSharp.WindowsDesktop.Tests", "..\..\tests\SkiaSharp.WindowsDesktop.Tests\SkiaSharp.WindowsDesktop.Tests.csproj", "{F0179CDB-9435-4FB4-8E52-DBF191079491}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
..\..\binding\Binding\Binding.projitems*{9c502b9a-25d4-473f-89bd-5a13dde16354}*SharedItemsImports = 13
@ -47,6 +49,18 @@ Global
{EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}.Release|x64.Build.0 = Release|x64
{EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}.Release|x86.ActiveCfg = Release|x86
{EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}.Release|x86.Build.0 = Release|x86
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Debug|x64.ActiveCfg = Debug|x64
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Debug|x64.Build.0 = Debug|x64
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Debug|x86.ActiveCfg = Debug|x86
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Debug|x86.Build.0 = Debug|x86
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Release|Any CPU.Build.0 = Release|Any CPU
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Release|x64.ActiveCfg = Release|x64
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Release|x64.Build.0 = Release|x64
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Release|x86.ActiveCfg = Release|x86
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

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

@ -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("SkiaSharp.WindowsDesktop.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SkiaSharp.WindowsDesktop.Tests")]
[assembly: AssemblyCopyright("Copyright © Xamarin 2016")]
[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("f0179cdb-9435-4fb4-8e52-dbf191079491")]
// 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,95 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SkiaSharp.WindowsDesktop.Tests
{
[TestFixture]
public class SKManagedStreamTest : SKTest
{
[Test]
public void ManagedStreamReadsByteCorrectly()
{
var data = new byte[1024];
for (int i = 0; i < data.Length; i++)
{
data[i] = (byte)(i % byte.MaxValue);
}
var stream = new MemoryStream(data);
var skManagedStream = new SKManagedStream(stream);
skManagedStream.Rewind();
Assert.AreEqual(0, stream.Position);
Assert.AreEqual(0, skManagedStream.Position);
for (int i = 0; i < data.Length; i++)
{
skManagedStream.Position = i;
Assert.AreEqual(i, stream.Position);
Assert.AreEqual(i, skManagedStream.Position);
Assert.AreEqual((byte)(i % byte.MaxValue), data[i]);
Assert.AreEqual((byte)(i % byte.MaxValue), skManagedStream.ReadByte());
Assert.AreEqual(i + 1, stream.Position);
Assert.AreEqual(i + 1, skManagedStream.Position);
}
}
[Test]
public void ManagedStreamReadsChunkCorrectly()
{
var data = new byte[1024];
for (int i = 0; i < data.Length; i++)
{
data[i] = (byte)(i % byte.MaxValue);
}
var stream = new MemoryStream(data);
var skManagedStream = new SKManagedStream(stream);
skManagedStream.Rewind();
Assert.AreEqual(0, stream.Position);
Assert.AreEqual(0, skManagedStream.Position);
var buffer = new byte[data.Length / 2];
skManagedStream.Read(buffer, buffer.Length);
CollectionAssert.AreEqual(data.Take(buffer.Length), buffer);
}
[Test]
public void ManagedStreamReadsOffsetChunkCorrectly()
{
var data = new byte[1024];
for (int i = 0; i < data.Length; i++)
{
data[i] = (byte)(i % byte.MaxValue);
}
var stream = new MemoryStream(data);
var skManagedStream = new SKManagedStream(stream);
var offset = 768;
skManagedStream.Position = offset;
var buffer = new byte[data.Length];
var taken = skManagedStream.Read(buffer, buffer.Length);
Assert.AreEqual(data.Length - offset, taken);
var resultData = data.Skip(offset).Take(buffer.Length).ToArray();
resultData = resultData.Concat(Enumerable.Repeat<byte>(0, offset)).ToArray();
CollectionAssert.AreEqual(resultData, buffer);
}
}
}

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

@ -0,0 +1,70 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SkiaSharp.WindowsDesktop.Tests
{
[TestFixture]
public class SKSurfaceTest : SKTest
{
[Test]
public void SurfaceCanvasReturnTheSameInstance()
{
Draw(surface =>
{
var skcanvas1 = surface.Canvas;
var skcanvas2 = surface.Canvas;
Assert.IsNotNull(skcanvas1);
Assert.IsNotNull(skcanvas2);
Assert.AreEqual(skcanvas1, skcanvas2);
Assert.IsTrue(skcanvas1 == skcanvas2);
Assert.AreSame(skcanvas1, skcanvas2);
});
}
[Test]
public void SecondSurfaceWasCreatedDifferent()
{
var data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bitmap.PixelFormat);
var surface1 = SKSurface.Create(width, height, SKColorType.Bgra_8888, SKAlphaType.Premul, data.Scan0, width * 4);
var surface2 = SKSurface.Create(width, height, SKColorType.Bgra_8888, SKAlphaType.Premul, data.Scan0, width * 4);
Assert.IsNotNull(surface1);
Assert.IsNotNull(surface2);
Assert.AreNotEqual(surface1, surface2);
Assert.AreNotEqual(surface1.Handle, surface2.Handle);
surface1.Dispose();
surface2.Dispose();
bitmap.UnlockBits(data);
}
[Test]
public void SurfaceWasCreated()
{
var data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bitmap.PixelFormat);
var surface = SKSurface.Create(width, height, SKColorType.Bgra_8888, SKAlphaType.Premul, data.Scan0, width * 4);
Assert.IsNotNull(surface);
Assert.AreNotEqual(IntPtr.Zero, surface.Handle);
surface.Dispose();
Assert.AreEqual(IntPtr.Zero, surface.Handle);
bitmap.UnlockBits(data);
}
}
}

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

@ -0,0 +1,45 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SkiaSharp.WindowsDesktop.Tests
{
[TestFixture]
public abstract class SKTest
{
protected const int width = 100;
protected const int height = 100;
protected Bitmap bitmap;
[SetUp]
public void Setup()
{
bitmap = new Bitmap(width, height, PixelFormat.Format32bppPArgb);
}
[TearDown]
public void TearDown()
{
bitmap.Dispose();
bitmap = null;
}
public void Draw(Action<SKSurface> draw)
{
var data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bitmap.PixelFormat);
using (var surface = SKSurface.Create(width, height, SKColorType.Bgra_8888, SKAlphaType.Premul, data.Scan0, width * 4))
{
draw(surface);
}
bitmap.UnlockBits(data);
}
}
}

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

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<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>{F0179CDB-9435-4FB4-8E52-DBF191079491}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SkiaSharp.WindowsDesktop.Tests</RootNamespace>
<AssemblyName>SkiaSharp.WindowsDesktop.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=3.0.5813.39031, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\..\samples\Skia.WindowsDesktop.Demo\packages\NUnit.3.0.1\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<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" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SKManagedStreamTest.cs" />
<Compile Include="SKTest.cs" />
<Compile Include="SKSurfaceTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\binding\SkiaSharp.WindowsDesktop\SkiaSharp.WindowsDesktop.csproj">
<Project>{eb1bbdcc-fb07-40d5-8b9e-0079e2c2f2df}</Project>
<Name>SkiaSharp.WindowsDesktop</Name>
</ProjectReference>
</ItemGroup>
<Import Project="..\..\binding\SkiaSharp.WindowsDesktop\bin\$(Platform)\$(Configuration)\SkiaSharp.WindowsDesktop.targets" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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,54 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Binding", "..\..\binding\Binding\Binding.shproj", "{9C502B9A-25D4-473F-89BD-5A13DDE16354}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkiaSharp.WindowsDesktop", "..\..\binding\SkiaSharp.WindowsDesktop\SkiaSharp.WindowsDesktop.csproj", "{EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkiaSharp.WindowsDesktop.Tests", "SkiaSharp.WindowsDesktop.Tests.csproj", "{F0179CDB-9435-4FB4-8E52-DBF191079491}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
..\..\binding\Binding\Binding.projitems*{9c502b9a-25d4-473f-89bd-5a13dde16354}*SharedItemsImports = 13
..\..\binding\Binding\Binding.projitems*{eb1bbdcc-fb07-40d5-8b9e-0079e2c2f2df}*SharedItemsImports = 4
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}.Debug|x64.ActiveCfg = Debug|x64
{EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}.Debug|x64.Build.0 = Debug|x64
{EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}.Debug|x86.ActiveCfg = Debug|x86
{EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}.Debug|x86.Build.0 = Debug|x86
{EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}.Release|Any CPU.Build.0 = Release|Any CPU
{EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}.Release|x64.ActiveCfg = Release|x64
{EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}.Release|x64.Build.0 = Release|x64
{EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}.Release|x86.ActiveCfg = Release|x86
{EB1BBDCC-FB07-40D5-8B9E-0079E2C2F2DF}.Release|x86.Build.0 = Release|x86
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Debug|x64.ActiveCfg = Debug|x64
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Debug|x64.Build.0 = Debug|x64
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Debug|x86.ActiveCfg = Debug|x86
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Debug|x86.Build.0 = Debug|x86
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Release|Any CPU.Build.0 = Release|Any CPU
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Release|x64.ActiveCfg = Release|x64
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Release|x64.Build.0 = Release|x64
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Release|x86.ActiveCfg = Release|x86
{F0179CDB-9435-4FB4-8E52-DBF191079491}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

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

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.0.1" targetFramework="net451" />
</packages>