Add unit test projects and fix some tests
This commit is contained in:
Родитель
372af676b7
Коммит
654bb9860e
|
@ -0,0 +1,42 @@
|
|||
//
|
||||
// BoxTests.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;
|
||||
|
||||
namespace Xwt
|
||||
{
|
||||
public abstract class BoxTests: WidgetTests
|
||||
{
|
||||
public override Widget CreateWidget ()
|
||||
{
|
||||
var box = CreateBox ();
|
||||
box.PackStart (new Label ("Hello Worlds"));
|
||||
return box;
|
||||
}
|
||||
|
||||
public abstract Box CreateBox ();
|
||||
}
|
||||
}
|
||||
|
|
@ -27,9 +27,9 @@ using System;
|
|||
|
||||
namespace Xwt
|
||||
{
|
||||
public class HBoxTests: WidgetTests
|
||||
public class HBoxTests: BoxTests
|
||||
{
|
||||
public override Widget CreateWidget ()
|
||||
public override Box CreateBox ()
|
||||
{
|
||||
return new HBox ();
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace Xwt
|
|||
{
|
||||
public override Widget CreateWidget ()
|
||||
{
|
||||
return new ImageView ();
|
||||
return new ImageView (StockIcons.Warning.WithBoxSize (16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace Xwt
|
|||
{
|
||||
public override Widget CreateWidget ()
|
||||
{
|
||||
return new Label ();
|
||||
return new Label ("Hello World");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
<RootNamespace>MacTestRunner</RootNamespace>
|
||||
<MonoMacResourcePrefix>Resources</MonoMacResourcePrefix>
|
||||
<AssemblyName>MacTestRunner</AssemblyName>
|
||||
<SuppressXamMacMigration>True</SuppressXamMacMigration>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>True</DebugSymbols>
|
||||
|
|
|
@ -31,7 +31,9 @@ namespace Xwt
|
|||
{
|
||||
public override Widget CreateWidget ()
|
||||
{
|
||||
return new Table ();
|
||||
var t = new Table ();
|
||||
t.Attach (new Label ("Hello Worlds"), 0, 0);
|
||||
return t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
<Compile Include="VSeparatorTests.cs" />
|
||||
<Compile Include="WidgetTests.cs" />
|
||||
<Compile Include="ConsoleTestRunner.cs" />
|
||||
<Compile Include="BoxTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Test.csproj" />
|
||||
|
|
|
@ -27,9 +27,9 @@ using System;
|
|||
|
||||
namespace Xwt
|
||||
{
|
||||
public class VBoxTests: WidgetTests
|
||||
public class VBoxTests: BoxTests
|
||||
{
|
||||
public override Widget CreateWidget ()
|
||||
public override Box CreateBox ()
|
||||
{
|
||||
return new VBox ();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
// THE SOFTWARE.
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using System.Threading;
|
||||
|
||||
namespace Xwt
|
||||
{
|
||||
|
@ -59,6 +60,28 @@ namespace Xwt
|
|||
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 ()
|
||||
{
|
||||
|
@ -183,53 +206,79 @@ namespace Xwt
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Ignore]
|
||||
public void MinSize ()
|
||||
{
|
||||
var win = new Window ();
|
||||
var w = CreateWidget ();
|
||||
using (var win = new Window ()) {
|
||||
var w = CreateWidget ();
|
||||
|
||||
win.Content = w;
|
||||
win.Show ();
|
||||
VBox box1 = new VBox ();
|
||||
HBox box2 = new HBox ();
|
||||
box1.PackStart (box2);
|
||||
box2.PackStart (w);
|
||||
win.Content = box1;
|
||||
|
||||
Application.MainLoop.DispatchPendingEvents ();
|
||||
ShowWindow (win);
|
||||
|
||||
var defw = w.Size.Width;
|
||||
var defh = w.Size.Height;
|
||||
var defw = w.Size.Width;
|
||||
var defh = w.Size.Height;
|
||||
|
||||
w.MinWidth = 300;
|
||||
Assert.AreEqual (300, w.MinWidth);
|
||||
Assert.AreEqual (300, w.Size.Width);
|
||||
w.MinWidth = 300;
|
||||
WaitForEvents ();
|
||||
Assert.AreEqual (300d, w.MinWidth);
|
||||
Assert.AreEqual (300d, w.Size.Width);
|
||||
|
||||
w.MinHeight = 400;
|
||||
Assert.AreEqual (400, w.MinHeight);
|
||||
Assert.AreEqual (400, w.Size.Height);
|
||||
w.MinHeight = 400;
|
||||
WaitForEvents ();
|
||||
Assert.AreEqual (400d, w.MinHeight);
|
||||
Assert.AreEqual (400d, w.Size.Height);
|
||||
|
||||
w.MinWidth = -1;
|
||||
Assert.AreEqual (-1, w.MinWidth);
|
||||
Assert.AreEqual (defw, w.Size.Width);
|
||||
w.MinWidth = -1;
|
||||
WaitForEvents ();
|
||||
Assert.AreEqual (-1, w.MinWidth);
|
||||
Assert.AreEqual (defw, w.Size.Width);
|
||||
|
||||
w.MinHeight = -1;
|
||||
Assert.AreEqual (-1, w.MinHeight);
|
||||
Assert.AreEqual (defh, w.Size.Height);
|
||||
|
||||
win.Dispose ();
|
||||
w.MinHeight = -1;
|
||||
WaitForEvents ();
|
||||
Assert.AreEqual (-1, w.MinHeight);
|
||||
Assert.AreEqual (defh, w.Size.Height);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore]
|
||||
public void Coordinates ()
|
||||
{
|
||||
var win = new Window ();
|
||||
var w = CreateWidget ();
|
||||
win.Content = w;
|
||||
win.Show ();
|
||||
double padding = 40;
|
||||
using (var win = new Window ()) {
|
||||
var w = CreateWidget ();
|
||||
win.Content = w;
|
||||
win.Padding = padding;
|
||||
win.Location = new Point (300,300);
|
||||
|
||||
Application.MainLoop.DispatchPendingEvents ();
|
||||
ShowWindow (win);
|
||||
/* Console.WriteLine (win.ScreenBounds.Inflate (-padding,-padding) + " w: " + w.ScreenBounds);
|
||||
|
||||
Assert.AreEqual (w.ScreenBounds, win.ScreenBounds);
|
||||
for (int n=0;n<100; n++) {
|
||||
System.Threading.Thread.Sleep (100);
|
||||
Application.MainLoop.DispatchPendingEvents ();
|
||||
}
|
||||
*/
|
||||
Assert.AreEqual (w.ScreenBounds, win.ScreenBounds.Inflate (-padding,-padding));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
win.Dispose ();
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
2
Xwt.sln
2
Xwt.sln
|
@ -178,7 +178,7 @@ Global
|
|||
{14CF6E75-0D08-4BBD-B0F5-742196E5656D} = {83D74DDF-581E-4E2A-AE02-F4047A5B96C7}
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
StartupItem = Testing\Tests\MacTestRunner\MacTestRunner.csproj
|
||||
StartupItem = Testing\Tests\GtkTestRunner\GtkTestRunner.csproj
|
||||
Policies = $0
|
||||
$0.DotNetNamingPolicy = $1
|
||||
$1.DirectoryNamespaceAssociation = None
|
||||
|
|
Загрузка…
Ссылка в новой задаче