diff options
author | Lluis Sanchez <lluis@xamarin.com> | 2013-05-30 21:16:52 +0400 |
---|---|---|
committer | Lluis Sanchez <lluis@xamarin.com> | 2013-05-30 21:16:52 +0400 |
commit | e390691dcc8c67933653f2eb280aa3ad1a160665 (patch) | |
tree | 17f1bb3e537e80f7df5bdd2f2af9f6b397b07da9 /Testing/Tests | |
parent | a07df7fa9b36bab8f4137e22e409dea442647cee (diff) |
Reorganized unit test suite
We now have a test assembly for each platform, and code is shared
in the different projects.
Diffstat (limited to 'Testing/Tests')
-rw-r--r-- | Testing/Tests/ConsoleTestRunner.cs | 7 | ||||
-rw-r--r-- | Testing/Tests/DrawingTests.cs | 22 | ||||
-rw-r--r-- | Testing/Tests/ReferenceImageManager.cs | 31 | ||||
-rw-r--r-- | Testing/Tests/Tests.csproj | 2 | ||||
-rw-r--r-- | Testing/Tests/VBoxTests.cs | 2 | ||||
-rw-r--r-- | Testing/Tests/WidgetTests.cs | 58 | ||||
-rw-r--r-- | Testing/Tests/WindowTests.cs | 62 | ||||
-rw-r--r-- | Testing/Tests/XwtTest.cs | 88 |
8 files changed, 193 insertions, 79 deletions
diff --git a/Testing/Tests/ConsoleTestRunner.cs b/Testing/Tests/ConsoleTestRunner.cs index 03ddaef9..a7d50621 100644 --- a/Testing/Tests/ConsoleTestRunner.cs +++ b/Testing/Tests/ConsoleTestRunner.cs @@ -31,13 +31,6 @@ namespace Xwt { public void Run (string[] args) { - Application.Invoke (delegate { - var r = new NUnitLite.Runner.TextUI (Console.Out); - r.Execute (args); - ReferenceImageManager.ShowImageVerifier (); - Application.Exit (); - }); - Application.Run (); } } } diff --git a/Testing/Tests/DrawingTests.cs b/Testing/Tests/DrawingTests.cs index f4f59027..d58d4348 100644 --- a/Testing/Tests/DrawingTests.cs +++ b/Testing/Tests/DrawingTests.cs @@ -352,7 +352,7 @@ namespace Xwt { InitBlank (70, 70); context.Rectangle (5, 5, 40, 60); - var img = Image.FromResource (GetType(), "pattern-sample.png"); + var img = ReferenceImageManager.LoadReferenceImage ("pattern-sample.png"); context.Pattern = new Xwt.Drawing.ImagePattern (img); context.Fill (); CheckImage ("ImagePattern.png"); @@ -363,7 +363,7 @@ namespace Xwt { InitBlank (50, 50); context.Arc (25, 25, 20, 0, 360); - var img = Image.FromResource (GetType(), "pattern-sample.png"); + var img = ReferenceImageManager.LoadReferenceImage ("pattern-sample.png"); context.Pattern = new Xwt.Drawing.ImagePattern (img); context.Fill (); CheckImage ("ImagePatternInCircle.png"); @@ -377,7 +377,7 @@ namespace Xwt context.LineTo (45, 20); context.LineTo (5, 45); context.ClosePath (); - var img = Image.FromResource (GetType(), "pattern-sample.png"); + var img = ReferenceImageManager.LoadReferenceImage ("pattern-sample.png"); context.Pattern = new Xwt.Drawing.ImagePattern (img); context.Fill (); CheckImage ("ImagePatternInTriangle.png"); @@ -389,7 +389,7 @@ namespace Xwt InitBlank (70, 70); context.Translate (5, 5); context.Rectangle (0, 0, 40, 60); - var img = Image.FromResource (GetType(), "pattern-sample.png"); + var img = ReferenceImageManager.LoadReferenceImage ("pattern-sample.png"); context.Pattern = new Xwt.Drawing.ImagePattern (img); context.Fill (); CheckImage ("ImagePatternWithTranslateTransform.png"); @@ -401,7 +401,7 @@ namespace Xwt InitBlank (70, 70); context.Rotate (4); context.Rectangle (5, 5, 40, 60); - var img = Image.FromResource (GetType(), "pattern-sample.png"); + var img = ReferenceImageManager.LoadReferenceImage ("pattern-sample.png"); context.Pattern = new Xwt.Drawing.ImagePattern (img); context.Fill (); CheckImage ("ImagePatternWithRotateTransform.png"); @@ -413,7 +413,7 @@ namespace Xwt InitBlank (70, 70); context.Scale (2, 0.5); context.Rectangle (5, 5, 20, 120); - var img = Image.FromResource (GetType(), "pattern-sample.png"); + var img = ReferenceImageManager.LoadReferenceImage ("pattern-sample.png"); context.Pattern = new Xwt.Drawing.ImagePattern (img); context.Fill (); CheckImage ("ImagePatternWithScaleTransform.png"); @@ -424,7 +424,7 @@ namespace Xwt { InitBlank (70, 70); context.Rectangle (5, 5, 40, 60); - var img = Image.FromResource (GetType(), "pattern-sample.png"); + var img = ReferenceImageManager.LoadReferenceImage ("pattern-sample.png"); img = img.WithAlpha (0.5); context.Pattern = new Xwt.Drawing.ImagePattern (img); context.Fill (); @@ -437,7 +437,7 @@ namespace Xwt InitBlank (70, 70); context.Translate (5, 5); context.Rectangle (0, 0, 40, 60); - var img = Image.FromResource (GetType(), "pattern-sample.png"); + var img = ReferenceImageManager.LoadReferenceImage ("pattern-sample.png"); context.Pattern = new Xwt.Drawing.ImagePattern (img.WithAlpha (0.5)); context.Fill (); CheckImage ("ImagePatternWithTranslateTransformWithAlpha.png"); @@ -449,7 +449,7 @@ namespace Xwt InitBlank (70, 70); context.Rotate (4); context.Rectangle (5, 5, 40, 60); - var img = Image.FromResource (GetType(), "pattern-sample.png"); + var img = ReferenceImageManager.LoadReferenceImage ("pattern-sample.png"); context.Pattern = new Xwt.Drawing.ImagePattern (img.WithAlpha (0.5)); context.Fill (); CheckImage ("ImagePatternWithRotateTransformWithAlpha.png"); @@ -461,7 +461,7 @@ namespace Xwt InitBlank (70, 70); context.Scale (2, 0.5); context.Rectangle (5, 5, 20, 120); - var img = Image.FromResource (GetType(), "pattern-sample.png"); + var img = ReferenceImageManager.LoadReferenceImage ("pattern-sample.png"); context.Pattern = new Xwt.Drawing.ImagePattern (img.WithAlpha (0.5)); context.Fill (); CheckImage ("ImagePatternWithScaleTransformWithAlpha.png"); @@ -760,7 +760,7 @@ namespace Xwt // Pattern is saved InitBlank (70, 70); context.Save (); - var img = Image.FromResource (GetType(), "pattern-sample.png"); + var img = ReferenceImageManager.LoadReferenceImage ("pattern-sample.png"); context.Pattern = new Xwt.Drawing.ImagePattern (img); context.Restore (); context.Rectangle (5, 5, 40, 60); diff --git a/Testing/Tests/ReferenceImageManager.cs b/Testing/Tests/ReferenceImageManager.cs index f9935759..f0b39198 100644 --- a/Testing/Tests/ReferenceImageManager.cs +++ b/Testing/Tests/ReferenceImageManager.cs @@ -43,11 +43,30 @@ namespace Xwt static ReferenceImageManager () { - var baseDir = Path.GetDirectoryName (System.Reflection.Assembly.GetEntryAssembly ().Location); + } + + public static void Init (string projectName) + { + var baseDir = Path.GetDirectoryName (typeof(ReferenceImageManager).Assembly.Location); + while (Path.GetFileName (baseDir) != "Testing") + baseDir = Path.GetDirectoryName (baseDir); + ProjectReferenceImageDir = Path.Combine (baseDir, "Tests", "ReferenceImages"); + ProjectCustomReferenceImageDir = Path.Combine (baseDir, projectName, "ReferenceImages"); + FailedImageCacheDir = Path.Combine (baseDir, "bin", projectName, "FailedImageCache"); + } + + public static Image LoadReferenceImage (string name) + { + return Image.FromFile (Path.Combine (ProjectReferenceImageDir, name)); + } - ProjectReferenceImageDir = Path.Combine (baseDir, "..", "..", "..", "Tests", "ReferenceImages"); - ProjectCustomReferenceImageDir = Path.Combine (baseDir, "..", "..", "ReferenceImages"); - FailedImageCacheDir = Path.Combine (baseDir, "FailedImageCache"); + public static Image LoadCustomReferenceImage (string name) + { + var file = Path.Combine (ProjectCustomReferenceImageDir, name); + if (File.Exists (file)) + return Image.FromFile (file); + else + return null; } public static void ShowImageVerifier () @@ -78,9 +97,9 @@ namespace Xwt public static void CheckImage (string refImageName, Image img) { - Image coreRefImage = TryLoadImage (typeof (ReferenceImageManager).Assembly, refImageName); + Image coreRefImage = LoadReferenceImage (refImageName); - Image refImage = !RecheckAll ? TryLoadImage (System.Reflection.Assembly.GetEntryAssembly (), refImageName) : null; + Image refImage = !RecheckAll ? LoadCustomReferenceImage (refImageName) : null; if (refImage == null) refImage = coreRefImage; diff --git a/Testing/Tests/Tests.csproj b/Testing/Tests/Tests.csproj index ee6b8903..6e1a138e 100644 --- a/Testing/Tests/Tests.csproj +++ b/Testing/Tests/Tests.csproj @@ -69,6 +69,8 @@ <Compile Include="MatrixTests.cs" /> <Compile Include="TransformTests.cs" /> <Compile Include="RadioButtonTests.cs" /> + <Compile Include="WindowTests.cs" /> + <Compile Include="XwtTest.cs" /> </ItemGroup> <ItemGroup> <None Include="Test.csproj" /> diff --git a/Testing/Tests/VBoxTests.cs b/Testing/Tests/VBoxTests.cs index 1a964a0c..b73249d1 100644 --- a/Testing/Tests/VBoxTests.cs +++ b/Testing/Tests/VBoxTests.cs @@ -24,9 +24,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; +using NUnit.Framework; namespace Xwt { + [TestFixture] public class VBoxTests: BoxTests { public override Box CreateBox () diff --git a/Testing/Tests/WidgetTests.cs b/Testing/Tests/WidgetTests.cs index 53b2086f..22464d56 100644 --- a/Testing/Tests/WidgetTests.cs +++ b/Testing/Tests/WidgetTests.cs @@ -30,7 +30,7 @@ using System.Threading; namespace Xwt { [TestFixture] - public abstract class WidgetTests + public abstract class WidgetTests: XwtTest { public abstract Widget CreateWidget (); @@ -44,44 +44,6 @@ namespace Xwt { } - public void Run (Action a) - { - Exception ex = null; - Application.Invoke (delegate { - try { - a (); - } catch (Exception e) { - ex = e; - } - Application.Exit (); - }); - Application.Run (); - if (ex != null) - throw new Exception ("Exception in gui event loop", ex); - } - - void WaitForEvents (int ms = 1) - { - DateTime t = DateTime.Now; - do { - Application.MainLoop.DispatchPendingEvents (); - System.Threading.Thread.Sleep (20); - } while ((DateTime.Now - t).TotalMilliseconds < ms); - } - - public void ShowWindow (Window win) - { - var ev = new ManualResetEvent (false); - - win.Shown += delegate { - ev.Set (); - }; - - win.Show (); - ev.WaitForEvent (); - Application.MainLoop.DispatchPendingEvents (); - } - [Test] public void Visibility () { @@ -221,11 +183,12 @@ namespace Xwt f.MinHeight = 10; box1.PackStart (box2); box2.PackStart (f); - f.PackStart (w, BoxMode.FillAndExpand); + f.PackStart (w, true); win.Content = box1; ShowWindow (win); + WaitForEvents (); var defw = w.Size.Width; var defh = w.Size.Height; @@ -268,20 +231,5 @@ namespace Xwt } } } - - static class EventHelper - { - public static void WaitForEvent (this ManualResetEvent ev) - { - DateTime t = DateTime.Now; - do { - Application.MainLoop.DispatchPendingEvents (); - if (ev.WaitOne (100)) - return; - } while ((DateTime.Now - t).TotalMilliseconds < 1000); - - Assert.Fail ("Event not fired"); - } - } } diff --git a/Testing/Tests/WindowTests.cs b/Testing/Tests/WindowTests.cs new file mode 100644 index 00000000..752775dd --- /dev/null +++ b/Testing/Tests/WindowTests.cs @@ -0,0 +1,62 @@ +// +// WindowTests.cs +// +// Author: +// Lluis Sanchez <lluis@xamarin.com> +// +// Copyright (c) 2013 Xamarin Inc. +// +// 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; + +namespace Xwt +{ + public class WindowTests: XwtTest + { + [Test] + public void DefaultSize () + { + using (var win = new Window ()) { + Label test = new Label ("Testing"); + test.MinWidth = 100; + test.MinHeight = 100; + win.Content = test; + ShowWindow (win); + Assert.AreEqual (100, win.Size.Width); + Assert.AreEqual (100, win.Size.Height); + } + } + + [Test] + public void ContentMargin () + { + using (var win = new Window ()) { + Label test = new Label ("Testing"); + test.MinWidth = 100; + test.MinHeight = 100; + win.Content = test; + ShowWindow (win); + Assert.AreEqual (100, win.Size.Width); + Assert.AreEqual (100, win.Size.Height); + } + } + } +} + diff --git a/Testing/Tests/XwtTest.cs b/Testing/Tests/XwtTest.cs new file mode 100644 index 00000000..3f00a44d --- /dev/null +++ b/Testing/Tests/XwtTest.cs @@ -0,0 +1,88 @@ +// +// XwtTest.cs +// +// Author: +// Lluis Sanchez <lluis@xamarin.com> +// +// Copyright (c) 2013 Xamarin Inc. +// +// 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 System.Threading; +using NUnit.Framework; + +namespace Xwt +{ + public class XwtTest + { + public void Run (Action a) + { + Exception ex = null; + Application.Invoke (delegate { + try { + a (); + } catch (Exception e) { + ex = e; + } + Application.Exit (); + }); + Application.Run (); + if (ex != null) + throw new Exception ("Exception in gui event loop", ex); + } + + protected void WaitForEvents (int ms = 1) + { + DateTime t = DateTime.Now; + do { + Application.MainLoop.DispatchPendingEvents (); + System.Threading.Thread.Sleep (20); + } while ((DateTime.Now - t).TotalMilliseconds < ms); + } + + public void ShowWindow (Window win) + { + var ev = new ManualResetEvent (false); + + win.Shown += delegate { + ev.Set (); + }; + + win.Show (); + ev.WaitForEvent (); + Application.MainLoop.DispatchPendingEvents (); + } + } + + static class EventHelper + { + public static void WaitForEvent (this ManualResetEvent ev) + { + DateTime t = DateTime.Now; + do { + Application.MainLoop.DispatchPendingEvents (); + if (ev.WaitOne (100)) + return; + } while ((DateTime.Now - t).TotalMilliseconds < 1000); + + Assert.Fail ("Event not fired"); + } + } +} + |