Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/xwt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLluis Sanchez <lluis@xamarin.com>2013-12-01 17:16:49 +0400
committerLluis Sanchez <lluis@xamarin.com>2013-12-01 17:16:49 +0400
commit2b7a78e58e6571505eae8b8797fe1a76d30cd5de (patch)
tree42821aa11e2a4cb22287a9f5fa3bf34c4873dab9 /Testing
parentd60200bd007151bc75004812bfae7ef1cf6fa96c (diff)
Added unit tests for 9-patch images
Also fixed some rendering issues in gtk.
Diffstat (limited to 'Testing')
-rw-r--r--Testing/GtkTestRunner.csproj16
-rw-r--r--Testing/MacTestRunner.csproj14
-rw-r--r--Testing/Tests/DrawingTests.cs30
-rw-r--r--Testing/Tests/DrawingTestsBase.cs68
-rw-r--r--Testing/Tests/NinePatchTests.cs194
5 files changed, 293 insertions, 29 deletions
diff --git a/Testing/GtkTestRunner.csproj b/Testing/GtkTestRunner.csproj
index 11aca398..dfaf3fea 100644
--- a/Testing/GtkTestRunner.csproj
+++ b/Testing/GtkTestRunner.csproj
@@ -113,6 +113,8 @@
<Compile Include="Tests\LinkLabelTests.cs" />
<Compile Include="Tests\FormattedTextTests.cs" />
<Compile Include="GtkTests\GtkIntegrationTests.cs" />
+ <Compile Include="Tests\DrawingTestsBase.cs" />
+ <Compile Include="Tests\NinePatchTests.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
@@ -128,4 +130,18 @@
<ItemGroup>
<Folder Include="GtkTests\" />
</ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Tests\ninep-ss.9.png">
+ <LogicalName>ninep-ss.9.png</LogicalName>
+ </EmbeddedResource>
+ <EmbeddedResource Include="Tests\ninep-st.9.png">
+ <LogicalName>ninep-st.9.png</LogicalName>
+ </EmbeddedResource>
+ <EmbeddedResource Include="Tests\ninep-ts.9.png">
+ <LogicalName>ninep-ts.9.png</LogicalName>
+ </EmbeddedResource>
+ <EmbeddedResource Include="Tests\ninep-tt.9.png">
+ <LogicalName>ninep-tt.9.png</LogicalName>
+ </EmbeddedResource>
+ </ItemGroup>
</Project> \ No newline at end of file
diff --git a/Testing/MacTestRunner.csproj b/Testing/MacTestRunner.csproj
index 73bff26e..587d5812 100644
--- a/Testing/MacTestRunner.csproj
+++ b/Testing/MacTestRunner.csproj
@@ -88,6 +88,8 @@
<ItemGroup>
<Compile Include="MacTestRunner\Main.cs" />
<Compile Include="Tests\**\*.cs" />
+ <Compile Include="Tests\DrawingTestsBase.cs" />
+ <Compile Include="Tests\NinePatchTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="MacTestRunner\Info.plist" />
@@ -256,5 +258,17 @@
<EmbeddedResource Include="MacTestRunner\ReferenceImages\Label.AlignRightWrapped.png">
<LogicalName>Label.AlignRightWrapped.png</LogicalName>
</EmbeddedResource>
+ <EmbeddedResource Include="Tests\ninep-ss.9.png">
+ <LogicalName>ninep-ss.9.png</LogicalName>
+ </EmbeddedResource>
+ <EmbeddedResource Include="Tests\ninep-st.9.png">
+ <LogicalName>ninep-st.9.png</LogicalName>
+ </EmbeddedResource>
+ <EmbeddedResource Include="Tests\ninep-ts.9.png">
+ <LogicalName>ninep-ts.9.png</LogicalName>
+ </EmbeddedResource>
+ <EmbeddedResource Include="Tests\ninep-tt.9.png">
+ <LogicalName>ninep-tt.9.png</LogicalName>
+ </EmbeddedResource>
</ItemGroup>
</Project> \ No newline at end of file
diff --git a/Testing/Tests/DrawingTests.cs b/Testing/Tests/DrawingTests.cs
index ac617f8e..c27f0dff 100644
--- a/Testing/Tests/DrawingTests.cs
+++ b/Testing/Tests/DrawingTests.cs
@@ -34,36 +34,8 @@ using System.Collections.Generic;
namespace Xwt
{
[TestFixture]
- public class DrawingTests
+ public class DrawingTests: DrawingTestsBase
{
- ImageBuilder builder;
- Context context;
-
- void InitBlank (int width = 50, int height = 50)
- {
- if (builder != null)
- builder.Dispose ();
-
- builder = new ImageBuilder (width, height);
- context = builder.Context;
- context.Rectangle (0, 0, width, height);
- context.SetColor (Colors.White);
- context.Fill ();
- context.SetColor (Colors.Black);
- context.SetLineWidth (1);
- }
-
- void CheckImage (string refImageName)
- {
- if (builder == null)
- return;
- var img = builder.ToBitmap ();
- builder.Dispose ();
- builder = null;
-
- ReferenceImageManager.CheckImage (refImageName, img);
- }
-
[Test]
public void Line ()
{
diff --git a/Testing/Tests/DrawingTestsBase.cs b/Testing/Tests/DrawingTestsBase.cs
new file mode 100644
index 00000000..959014d0
--- /dev/null
+++ b/Testing/Tests/DrawingTestsBase.cs
@@ -0,0 +1,68 @@
+//
+// DrawingTestsBase.cs
+//
+// Author:
+// Lluis Sanchez Gual <lluis@xamarin.com>
+//
+// Copyright (c) 2013 Xamarin, Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using NUnit.Framework;
+using System.Threading;
+using Xwt.Drawing;
+using System.IO;
+using System.Collections.Generic;
+
+namespace Xwt
+{
+ public class DrawingTestsBase
+ {
+ protected ImageBuilder builder;
+ protected Context context;
+
+ protected void InitBlank (int width = 50, int height = 50)
+ {
+ if (builder != null)
+ builder.Dispose ();
+
+ builder = new ImageBuilder (width, height);
+ context = builder.Context;
+ context.Rectangle (0, 0, width, height);
+ context.SetColor (Colors.White);
+ context.Fill ();
+ context.SetColor (Colors.Black);
+ context.SetLineWidth (1);
+ }
+
+ protected void CheckImage (string refImageName)
+ {
+ if (builder == null)
+ return;
+ var img = builder.ToBitmap ();
+ builder.Dispose ();
+ builder = null;
+
+ ReferenceImageManager.CheckImage (refImageName, img);
+ }
+
+ }
+}
+
diff --git a/Testing/Tests/NinePatchTests.cs b/Testing/Tests/NinePatchTests.cs
new file mode 100644
index 00000000..d3d17122
--- /dev/null
+++ b/Testing/Tests/NinePatchTests.cs
@@ -0,0 +1,194 @@
+//
+// NinePatch.cs
+//
+// Author:
+// Lluis Sanchez Gual <lluis@xamarin.com>
+//
+// Copyright (c) 2013 Xamarin, Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using NUnit.Framework;
+using Xwt.Drawing;
+
+namespace Xwt
+{
+ public class NinePatchTests: DrawingTestsBase
+ {
+ [Test]
+ public void NinePatchStretchStretchDefaultSize ()
+ {
+ var np = Image.FromResource ("ninep-ss.9.png");
+ InitBlank ((int)np.Width, (int)np.Height);
+ context.DrawImage (np, 0, 0);
+ CheckImage ("NinePatchStretchStretchDefaultSize.png");
+ }
+
+ [Test]
+ public void NinePatchStretchStretchWiderHigher ()
+ {
+ var np = Image.FromResource ("ninep-ss.9.png");
+ np = np.WithSize (np.Width * 3, np.Height * 3);
+ InitBlank ((int)np.Width, (int)np.Height);
+ context.DrawImage (np, 0, 0);
+ CheckImage ("NinePatchStretchStretchWiderHigher.png");
+ }
+
+ [Test]
+ public void NinePatchStretchStretchWider ()
+ {
+ var np = Image.FromResource ("ninep-ss.9.png");
+ np = np.WithSize (np.Width * 3, np.Height);
+ InitBlank ((int)np.Width, (int)np.Height);
+ context.DrawImage (np, 0, 0);
+ CheckImage ("NinePatchStretchStretchWider.png");
+ }
+
+ [Test]
+ public void NinePatchStretchStretchHigher ()
+ {
+ var np = Image.FromResource ("ninep-ss.9.png");
+ np = np.WithSize (np.Width, np.Height * 3);
+ InitBlank ((int)np.Width, (int)np.Height);
+ context.DrawImage (np, 0, 0);
+ CheckImage ("NinePatchStretchStretchHigher.png");
+ }
+
+
+ [Test]
+ public void NinePatchStretchTileDefaultSize ()
+ {
+ var np = Image.FromResource ("ninep-st.9.png");
+ InitBlank ((int)np.Width, (int)np.Height);
+ context.DrawImage (np, 0, 0);
+ CheckImage ("NinePatchStretchTileDefaultSize.png");
+ }
+
+ [Test]
+ public void NinePatchStretchTileWiderHigher ()
+ {
+ var np = Image.FromResource ("ninep-st.9.png");
+ np = np.WithSize (np.Width * 3, np.Height * 3);
+ InitBlank ((int)np.Width, (int)np.Height);
+ context.DrawImage (np, 0, 0);
+ CheckImage ("NinePatchStretchTileWiderHigher.png");
+ }
+
+ [Test]
+ public void NinePatchStretchTileWider ()
+ {
+ var np = Image.FromResource ("ninep-st.9.png");
+ np = np.WithSize (np.Width * 3, np.Height);
+ InitBlank ((int)np.Width, (int)np.Height);
+ context.DrawImage (np, 0, 0);
+ CheckImage ("NinePatchStretchTileWider.png");
+ }
+
+ [Test]
+ public void NinePatchStretchTileHigher ()
+ {
+ var np = Image.FromResource ("ninep-st.9.png");
+ np = np.WithSize (np.Width, np.Height * 3);
+ InitBlank ((int)np.Width, (int)np.Height);
+ context.DrawImage (np, 0, 0);
+ CheckImage ("NinePatchStretchTileHigher.png");
+ }
+
+
+ [Test]
+ public void NinePatchTileStretchDefaultSize ()
+ {
+ var np = Image.FromResource ("ninep-ts.9.png");
+ InitBlank ((int)np.Width, (int)np.Height);
+ context.DrawImage (np, 0, 0);
+ CheckImage ("NinePatchTileStretchDefaultSize.png");
+ }
+
+ [Test]
+ public void NinePatchTileStretchWiderHigher ()
+ {
+ var np = Image.FromResource ("ninep-ts.9.png");
+ np = np.WithSize (np.Width * 3, np.Height * 3);
+ InitBlank ((int)np.Width, (int)np.Height);
+ context.DrawImage (np, 0, 0);
+ CheckImage ("NinePatchTileStretchWiderHigher.png");
+ }
+
+ [Test]
+ public void NinePatchTileStretchWider ()
+ {
+ var np = Image.FromResource ("ninep-ts.9.png");
+ np = np.WithSize (np.Width * 3, np.Height);
+ InitBlank ((int)np.Width, (int)np.Height);
+ context.DrawImage (np, 0, 0);
+ CheckImage ("NinePatchTileStretchWider.png");
+ }
+
+ [Test]
+ public void NinePatchTileStretchHigher ()
+ {
+ var np = Image.FromResource ("ninep-ts.9.png");
+ np = np.WithSize (np.Width, np.Height * 3);
+ InitBlank ((int)np.Width, (int)np.Height);
+ context.DrawImage (np, 0, 0);
+ CheckImage ("NinePatchTileStretchHigher.png");
+ }
+
+
+ [Test]
+ public void NinePatchTileTileDefaultSize ()
+ {
+ var np = Image.FromResource ("ninep-tt.9.png");
+ InitBlank ((int)np.Width, (int)np.Height);
+ context.DrawImage (np, 0, 0);
+ CheckImage ("NinePatchTileTileDefaultSize.png");
+ }
+
+ [Test]
+ public void NinePatchTileTileWiderHigher ()
+ {
+ var np = Image.FromResource ("ninep-tt.9.png");
+ np = np.WithSize (np.Width * 3, np.Height * 3);
+ InitBlank ((int)np.Width, (int)np.Height);
+ context.DrawImage (np, 0, 0);
+ CheckImage ("NinePatchTileTileWiderHigher.png");
+ }
+
+ [Test]
+ public void NinePatchTileTileWider ()
+ {
+ var np = Image.FromResource ("ninep-tt.9.png");
+ np = np.WithSize (np.Width * 3, np.Height);
+ InitBlank ((int)np.Width, (int)np.Height);
+ context.DrawImage (np, 0, 0);
+ CheckImage ("NinePatchTileTileWider.png");
+ }
+
+ [Test]
+ public void NinePatchTileTileHigher ()
+ {
+ var np = Image.FromResource ("ninep-tt.9.png");
+ np = np.WithSize (np.Width, np.Height * 3);
+ InitBlank ((int)np.Width, (int)np.Height);
+ context.DrawImage (np, 0, 0);
+ CheckImage ("NinePatchTileTileHigher.png");
+ }
+ }
+}
+