mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
Fix all tests.
This commit is contained in:
@@ -711,12 +711,13 @@ public class BorderTests
|
||||
[AutoInitShutdown]
|
||||
public void HasSuperView ()
|
||||
{
|
||||
Application.Top.BorderStyle = LineStyle.Double;
|
||||
var top = new Toplevel ();
|
||||
top.BorderStyle = LineStyle.Double;
|
||||
|
||||
var frame = new FrameView { Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
|
||||
Application.Top.Add (frame);
|
||||
RunState rs = Application.Begin (Application.Top);
|
||||
top.Add (frame);
|
||||
RunState rs = Application.Begin (top);
|
||||
var firstIteration = false;
|
||||
|
||||
((FakeDriver)Application.Driver).SetBufferSize (5, 5);
|
||||
@@ -737,12 +738,13 @@ public class BorderTests
|
||||
[AutoInitShutdown]
|
||||
public void HasSuperView_Title ()
|
||||
{
|
||||
Application.Top.BorderStyle = LineStyle.Double;
|
||||
var top = new Toplevel ();
|
||||
top.BorderStyle = LineStyle.Double;
|
||||
|
||||
var frame = new FrameView { Title = "1234", Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
|
||||
Application.Top.Add (frame);
|
||||
RunState rs = Application.Begin (Application.Top);
|
||||
top.Add (frame);
|
||||
RunState rs = Application.Begin (top);
|
||||
var firstIteration = false;
|
||||
|
||||
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
|
||||
|
||||
@@ -70,7 +70,7 @@ public class DrawTests
|
||||
var view = new View { Text = r.ToString (), Height = Dim.Fill (), Width = Dim.Fill () };
|
||||
var tf = new TextField { Text = us, Y = 1, Width = 3 };
|
||||
win.Add (view, tf);
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.Add (win);
|
||||
|
||||
Application.Begin (top);
|
||||
@@ -135,7 +135,8 @@ public class DrawTests
|
||||
};
|
||||
var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
win.Add (tv);
|
||||
Application.Top.Add (win);
|
||||
var top = new Toplevel ();
|
||||
top.Add (win);
|
||||
|
||||
// Don't use Label. It sets AutoSize = true which is not what we're testing here.
|
||||
var view = new View { Text = "ワイドルーン。", Height = Dim.Fill (), Width = Dim.Fill () };
|
||||
@@ -143,8 +144,8 @@ public class DrawTests
|
||||
// Don't have unit tests use things that aren't absolutely critical for the test, like Dialog
|
||||
var dg = new Window { X = 2, Y = 2, Width = 14, Height = 3 };
|
||||
dg.Add (view);
|
||||
Application.Begin (Application.Top);
|
||||
Application.Begin (dg);
|
||||
RunState rsTop = Application.Begin (top);
|
||||
RunState rsDiag = Application.Begin (dg);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (30, 10);
|
||||
|
||||
const string expectedOutput = """
|
||||
@@ -163,6 +164,9 @@ public class DrawTests
|
||||
|
||||
Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expectedOutput, _output);
|
||||
Assert.Equal (new Rectangle (0, 0, 30, 10), pos);
|
||||
|
||||
Application.End (rsDiag);
|
||||
Application.End (rsTop);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -189,7 +193,7 @@ public class DrawTests
|
||||
VerticalTextAlignment = VerticalTextAlignment.Bottom,
|
||||
ColorScheme = Colors.ColorSchemes ["Base"]
|
||||
};
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.Add (viewRight, viewBottom);
|
||||
|
||||
Application.Begin (top);
|
||||
@@ -402,7 +406,7 @@ public class DrawTests
|
||||
Height = 5
|
||||
};
|
||||
container.Add (content);
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.Add (container);
|
||||
Application.Driver.Clip = container.Frame;
|
||||
Application.Begin (top);
|
||||
@@ -517,7 +521,7 @@ public class DrawTests
|
||||
Height = 5
|
||||
};
|
||||
container.Add (content);
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.Add (container);
|
||||
|
||||
// BUGBUG: v2 - it's bogus to reference .Frame before BeginInit. And why is the clip being set anyway???
|
||||
@@ -604,7 +608,7 @@ public class DrawTests
|
||||
Height = 5
|
||||
};
|
||||
container.Add (content);
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.Add (container);
|
||||
Application.Driver.Clip = container.Frame;
|
||||
Application.Begin (top);
|
||||
@@ -723,7 +727,7 @@ public class DrawTests
|
||||
var view = new Label { Text = r.ToString () };
|
||||
var tf = new TextField { Text = us, Y = 1, Width = 3 };
|
||||
win.Add (view, tf);
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.Add (win);
|
||||
|
||||
Application.Begin (top);
|
||||
|
||||
@@ -28,7 +28,7 @@ public class DimTests
|
||||
[AutoInitShutdown]
|
||||
public void Dim_Add_Operator ()
|
||||
{
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
|
||||
var view = new View { X = 0, Y = 0, Width = 20, Height = 0 };
|
||||
var field = new TextField { X = 0, Y = Pos.Bottom (view), Width = 20 };
|
||||
@@ -102,7 +102,7 @@ public class DimTests
|
||||
[AutoInitShutdown]
|
||||
public void Dim_Subtract_Operator ()
|
||||
{
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
|
||||
var view = new View { X = 0, Y = 0, Width = 20, Height = 0 };
|
||||
var field = new TextField { X = 0, Y = Pos.Bottom (view), Width = 20 };
|
||||
@@ -386,10 +386,11 @@ public class DimTests
|
||||
};
|
||||
|
||||
container.Add (label);
|
||||
Application.Top.Add (container);
|
||||
Application.Top.BeginInit ();
|
||||
Application.Top.EndInit ();
|
||||
Application.Top.LayoutSubviews ();
|
||||
var top = new Toplevel ();
|
||||
top.Add (container);
|
||||
top.BeginInit ();
|
||||
top.EndInit ();
|
||||
top.LayoutSubviews ();
|
||||
|
||||
Assert.Equal (100, container.Frame.Width);
|
||||
Assert.Equal (100, container.Frame.Height);
|
||||
@@ -528,7 +529,7 @@ public class DimTests
|
||||
public void Only_DimAbsolute_And_DimFactor_As_A_Different_Procedure_For_Assigning_Value_To_Width_Or_Height ()
|
||||
{
|
||||
// Testing with the Button because it properly handles the Dim class.
|
||||
Toplevel t = Application.Top;
|
||||
Toplevel t = new ();
|
||||
|
||||
var w = new Window { Width = 100, Height = 100 };
|
||||
|
||||
@@ -765,7 +766,7 @@ public class DimTests
|
||||
|
||||
Application.Iteration += (s, a) => Application.RequestStop ();
|
||||
|
||||
Application.Run ();
|
||||
Application.Run (t);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -331,12 +331,13 @@ public class LayoutTests
|
||||
public void DimFill_SizedCorrectly ()
|
||||
{
|
||||
var view = new View { Width = Dim.Fill (), Height = Dim.Fill (), BorderStyle = LineStyle.Single };
|
||||
Application.Top.Add (view);
|
||||
RunState rs = Application.Begin (Application.Top);
|
||||
var top = new Toplevel ();
|
||||
top.Add (view);
|
||||
RunState rs = Application.Begin (top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (32, 5);
|
||||
|
||||
//view.SetNeedsLayout ();
|
||||
Application.Top.LayoutSubviews ();
|
||||
top.LayoutSubviews ();
|
||||
|
||||
//view.SetRelativeLayout (new (0, 0, 32, 5));
|
||||
Assert.Equal (32, view.Frame.Width);
|
||||
@@ -349,7 +350,7 @@ public class LayoutTests
|
||||
{
|
||||
Application.Init (new FakeDriver ());
|
||||
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
|
||||
var view = new View { X = -2, Text = "view" };
|
||||
top.Add (view);
|
||||
@@ -363,7 +364,7 @@ public class LayoutTests
|
||||
|
||||
try
|
||||
{
|
||||
Application.Run ();
|
||||
Application.Run (top);
|
||||
}
|
||||
catch (IndexOutOfRangeException ex)
|
||||
{
|
||||
@@ -371,6 +372,7 @@ public class LayoutTests
|
||||
Assert.IsType<IndexOutOfRangeException> (ex);
|
||||
}
|
||||
|
||||
top.Dispose ();
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
}
|
||||
@@ -381,7 +383,7 @@ public class LayoutTests
|
||||
{
|
||||
Application.Init (new FakeDriver ());
|
||||
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
|
||||
var view = new View { Y = -2, Height = 10, TextDirection = TextDirection.TopBottom_LeftRight, Text = "view" };
|
||||
top.Add (view);
|
||||
@@ -395,7 +397,7 @@ public class LayoutTests
|
||||
|
||||
try
|
||||
{
|
||||
Application.Run ();
|
||||
Application.Run (top);
|
||||
}
|
||||
catch (IndexOutOfRangeException ex)
|
||||
{
|
||||
@@ -403,6 +405,7 @@ public class LayoutTests
|
||||
Assert.IsType<IndexOutOfRangeException> (ex);
|
||||
}
|
||||
|
||||
top.Dispose ();
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
}
|
||||
@@ -488,7 +491,7 @@ public class LayoutTests
|
||||
{
|
||||
Application.Init (new FakeDriver ());
|
||||
|
||||
Toplevel t = Application.Top;
|
||||
Toplevel t = new ();
|
||||
|
||||
var w = new Window { X = Pos.Left (t) + 2, Y = Pos.At (2) };
|
||||
|
||||
@@ -506,7 +509,8 @@ public class LayoutTests
|
||||
|
||||
Application.Iteration += (s, a) => Application.RequestStop ();
|
||||
|
||||
Application.Run ();
|
||||
Application.Run (t);
|
||||
t.Dispose ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
@@ -545,14 +549,16 @@ public class LayoutTests
|
||||
{
|
||||
Application.Init (new FakeDriver ());
|
||||
|
||||
var w = new Window { X = Pos.Left (Application.Top) + 2, Y = Pos.Top (Application.Top) + 2 };
|
||||
var top = new Toplevel ();
|
||||
var w = new Window { X = Pos.Left (top) + 2, Y = Pos.Top (top) + 2 };
|
||||
var f = new FrameView ();
|
||||
var v1 = new View { X = Pos.Left (w) + 2, Y = Pos.Top (w) + 2 };
|
||||
var v2 = new View { X = Pos.Left (v1) + 2, Y = Pos.Top (v1) + 2 };
|
||||
|
||||
f.Add (v1, v2);
|
||||
w.Add (f);
|
||||
Application.Top.Add (w);
|
||||
top.Add (w);
|
||||
Application.Begin (top);
|
||||
|
||||
f.X = Pos.X (Application.Top) + Pos.X (v2) - Pos.X (v1);
|
||||
f.Y = Pos.Y (Application.Top) + Pos.Y (v2) - Pos.Y (v1);
|
||||
@@ -574,6 +580,7 @@ public class LayoutTests
|
||||
Application.Iteration += (s, a) => Application.RequestStop ();
|
||||
|
||||
Assert.Throws<InvalidOperationException> (() => Application.Run ());
|
||||
top.Dispose ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
@@ -634,8 +641,9 @@ public class LayoutTests
|
||||
Assert.Equal (10, rHeight);
|
||||
Assert.False (v.IsInitialized);
|
||||
|
||||
Application.Top.Add (top);
|
||||
Application.Begin (Application.Top);
|
||||
var toplevel = new Toplevel ();
|
||||
toplevel.Add (top);
|
||||
Application.Begin (toplevel);
|
||||
|
||||
Assert.True (v.IsInitialized);
|
||||
|
||||
@@ -665,8 +673,9 @@ public class LayoutTests
|
||||
Assert.Equal (70, rWidth);
|
||||
Assert.False (v.IsInitialized);
|
||||
|
||||
Application.Top.Add (top);
|
||||
Application.Begin (Application.Top);
|
||||
var toplevel = new Toplevel ();
|
||||
toplevel.Add (top);
|
||||
Application.Begin (toplevel);
|
||||
|
||||
Assert.True (v.IsInitialized);
|
||||
v.Width = 75;
|
||||
|
||||
@@ -43,7 +43,7 @@ public class PosTests
|
||||
|
||||
win.Add (tv);
|
||||
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.Add (win);
|
||||
RunState rs = Application.Begin (top);
|
||||
|
||||
@@ -73,7 +73,7 @@ public class PosTests
|
||||
|
||||
var menu = new MenuBar ();
|
||||
var status = new StatusBar ();
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.Add (win, menu, status);
|
||||
RunState rs = Application.Begin (top);
|
||||
|
||||
@@ -317,17 +317,18 @@ public class PosTests
|
||||
public void LeftTopBottomRight_Win_ShouldNotThrow ()
|
||||
{
|
||||
// Setup Fake driver
|
||||
(Window win, Button button) setup ()
|
||||
(Toplevel top, Window win, Button button) setup ()
|
||||
{
|
||||
Application.Init (new FakeDriver ());
|
||||
Application.Iteration += (s, a) => { Application.RequestStop (); };
|
||||
var win = new Window { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
Application.Top.Add (win);
|
||||
var top = new Toplevel ();
|
||||
top.Add (win);
|
||||
|
||||
var button = new Button { X = Pos.Center (), Text = "button" };
|
||||
win.Add (button);
|
||||
|
||||
return (win, button);
|
||||
return (top, win, button);
|
||||
}
|
||||
|
||||
RunState rs;
|
||||
@@ -337,14 +338,15 @@ public class PosTests
|
||||
// Cleanup
|
||||
Application.End (rs);
|
||||
|
||||
Application.Top.Dispose ();
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
// Test cases:
|
||||
(Window win, Button button) app = setup ();
|
||||
(Toplevel top, Window win, Button button) app = setup ();
|
||||
app.button.Y = Pos.Left (app.win);
|
||||
rs = Application.Begin (Application.Top);
|
||||
rs = Application.Begin (app.top);
|
||||
|
||||
// If Application.RunState is used then we must use Application.RunLoop with the rs parameter
|
||||
Application.RunLoop (rs);
|
||||
@@ -352,7 +354,7 @@ public class PosTests
|
||||
|
||||
app = setup ();
|
||||
app.button.Y = Pos.X (app.win);
|
||||
rs = Application.Begin (Application.Top);
|
||||
rs = Application.Begin (app.top);
|
||||
|
||||
// If Application.RunState is used then we must use Application.RunLoop with the rs parameter
|
||||
Application.RunLoop (rs);
|
||||
@@ -360,7 +362,7 @@ public class PosTests
|
||||
|
||||
app = setup ();
|
||||
app.button.Y = Pos.Top (app.win);
|
||||
rs = Application.Begin (Application.Top);
|
||||
rs = Application.Begin (app.top);
|
||||
|
||||
// If Application.RunState is used then we must use Application.RunLoop with the rs parameter
|
||||
Application.RunLoop (rs);
|
||||
@@ -368,7 +370,7 @@ public class PosTests
|
||||
|
||||
app = setup ();
|
||||
app.button.Y = Pos.Y (app.win);
|
||||
rs = Application.Begin (Application.Top);
|
||||
rs = Application.Begin (app.top);
|
||||
|
||||
// If Application.RunState is used then we must use Application.RunLoop with the rs parameter
|
||||
Application.RunLoop (rs);
|
||||
@@ -376,7 +378,7 @@ public class PosTests
|
||||
|
||||
app = setup ();
|
||||
app.button.Y = Pos.Bottom (app.win);
|
||||
rs = Application.Begin (Application.Top);
|
||||
rs = Application.Begin (app.top);
|
||||
|
||||
// If Application.RunState is used then we must use Application.RunLoop with the rs parameter
|
||||
Application.RunLoop (rs);
|
||||
@@ -384,7 +386,7 @@ public class PosTests
|
||||
|
||||
app = setup ();
|
||||
app.button.Y = Pos.Right (app.win);
|
||||
rs = Application.Begin (Application.Top);
|
||||
rs = Application.Begin (app.top);
|
||||
|
||||
// If Application.RunState is used then we must use Application.RunLoop with the rs parameter
|
||||
Application.RunLoop (rs);
|
||||
@@ -467,7 +469,7 @@ public class PosTests
|
||||
{
|
||||
Application.Init (new FakeDriver ());
|
||||
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
|
||||
var view = new View { X = 0, Y = 0, Width = 20, Height = 20 };
|
||||
var field = new TextField { X = 0, Y = 0, Width = 20 };
|
||||
@@ -510,6 +512,7 @@ public class PosTests
|
||||
|
||||
Assert.Equal (20, count);
|
||||
|
||||
top.Dispose ();
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
}
|
||||
@@ -522,7 +525,7 @@ public class PosTests
|
||||
{
|
||||
Application.Init (new FakeDriver ());
|
||||
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
|
||||
var view = new View { X = 0, Y = 0, Width = 20, Height = 20 };
|
||||
var field = new TextField { X = 0, Y = 0, Width = 20 };
|
||||
@@ -578,6 +581,7 @@ public class PosTests
|
||||
|
||||
Assert.Equal (0, count);
|
||||
|
||||
top.Dispose ();
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
}
|
||||
@@ -589,7 +593,7 @@ public class PosTests
|
||||
{
|
||||
Application.Init (new FakeDriver ());
|
||||
|
||||
Toplevel t = Application.Top;
|
||||
Toplevel t = new ();
|
||||
|
||||
var w = new Window { X = 1, Y = 2, Width = 3, Height = 5 };
|
||||
t.Add (w);
|
||||
@@ -602,7 +606,8 @@ public class PosTests
|
||||
|
||||
Application.Iteration += (s, a) => Application.RequestStop ();
|
||||
|
||||
Application.Run ();
|
||||
Application.Run (t);
|
||||
t.Dispose ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
@@ -637,7 +642,7 @@ public class PosTests
|
||||
{
|
||||
Application.Init (new FakeDriver ());
|
||||
|
||||
Toplevel t = Application.Top;
|
||||
Toplevel t = new ();
|
||||
|
||||
var w = new Window { X = Pos.Left (t) + 2, Y = Pos.Top (t) + 2 };
|
||||
var f = new FrameView ();
|
||||
@@ -651,7 +656,8 @@ public class PosTests
|
||||
f.X = Pos.X (v2) - Pos.X (v1);
|
||||
f.Y = Pos.Y (v2) - Pos.Y (v1);
|
||||
|
||||
Assert.Throws<InvalidOperationException> (() => Application.Run ());
|
||||
Assert.Throws<InvalidOperationException> (() => Application.Run (t));
|
||||
t.Dispose ();
|
||||
Application.Shutdown ();
|
||||
|
||||
v2.Dispose ();
|
||||
@@ -676,8 +682,9 @@ public class PosTests
|
||||
};
|
||||
|
||||
container.Add (view);
|
||||
Application.Top.Add (container);
|
||||
Application.Top.LayoutSubviews ();
|
||||
var top = new Toplevel ();
|
||||
top.Add (container);
|
||||
top.LayoutSubviews ();
|
||||
|
||||
Assert.Equal (100, container.Frame.Width);
|
||||
Assert.Equal (100, container.Frame.Height);
|
||||
|
||||
@@ -68,7 +68,9 @@ public class MouseTests (ITestOutputHelper output)
|
||||
testView.Border.Thickness = new (borderThickness);
|
||||
testView.Padding.Thickness = new (paddingThickness);
|
||||
|
||||
Application.Top.Add (testView);
|
||||
var top = new Toplevel ();
|
||||
top.Add (testView);
|
||||
Application.Begin (top);
|
||||
|
||||
Assert.Equal (new Point (4, 4), testView.Frame.Location);
|
||||
Application.OnMouseEvent (new (new () { X = xy, Y = xy, Flags = MouseFlags.Button1Pressed }));
|
||||
|
||||
@@ -57,7 +57,7 @@ public class NavigationTests
|
||||
{
|
||||
Application.Init (new FakeDriver ());
|
||||
|
||||
Toplevel t = Application.Top;
|
||||
Toplevel t = new ();
|
||||
|
||||
var w = new Window ();
|
||||
var f = new FrameView ();
|
||||
@@ -84,7 +84,8 @@ public class NavigationTests
|
||||
|
||||
Application.Iteration += (s, a) => Application.RequestStop ();
|
||||
|
||||
Application.Run ();
|
||||
Application.Run (t);
|
||||
t.Dispose ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
@@ -93,7 +94,7 @@ public class NavigationTests
|
||||
{
|
||||
Application.Init (new FakeDriver ());
|
||||
|
||||
Toplevel t = Application.Top;
|
||||
Toplevel t = new ();
|
||||
|
||||
var w = new Window ();
|
||||
var f = new FrameView ();
|
||||
@@ -126,7 +127,8 @@ public class NavigationTests
|
||||
|
||||
Application.Iteration += (s, a) => Application.RequestStop ();
|
||||
|
||||
Application.Run ();
|
||||
Application.Run (t);
|
||||
t.Dispose ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
@@ -166,7 +168,7 @@ public class NavigationTests
|
||||
{
|
||||
Application.Init (new FakeDriver ());
|
||||
|
||||
Toplevel t = Application.Top;
|
||||
Toplevel t = new ();
|
||||
|
||||
var w = new Window ();
|
||||
var f = new FrameView ();
|
||||
@@ -201,7 +203,8 @@ public class NavigationTests
|
||||
|
||||
Application.Iteration += (s, a) => Application.RequestStop ();
|
||||
|
||||
Application.Run ();
|
||||
Application.Run (t);
|
||||
t.Dispose ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
@@ -210,7 +213,7 @@ public class NavigationTests
|
||||
{
|
||||
Application.Init (new FakeDriver ());
|
||||
|
||||
Toplevel t = Application.Top;
|
||||
Toplevel t = new ();
|
||||
|
||||
var w = new Window ();
|
||||
var f = new FrameView ();
|
||||
@@ -238,7 +241,8 @@ public class NavigationTests
|
||||
|
||||
Application.Iteration += (s, a) => Application.RequestStop ();
|
||||
|
||||
Application.Run ();
|
||||
Application.Run (t);
|
||||
t.Dispose ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
@@ -292,8 +296,9 @@ public class NavigationTests
|
||||
var view = new View { CanFocus = true };
|
||||
var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
win.Add (view);
|
||||
Application.Top.Add (win);
|
||||
Application.Begin (Application.Top);
|
||||
var top = new Toplevel ();
|
||||
top.Add (win);
|
||||
Application.Begin (top);
|
||||
|
||||
Assert.True (view.CanFocus);
|
||||
Assert.True (view.HasFocus);
|
||||
@@ -315,21 +320,22 @@ public class NavigationTests
|
||||
var view2 = new View { Id = "view2", Width = 20, Height = 2, CanFocus = true };
|
||||
var win2 = new Window { Id = "win2", X = Pos.Right (win1), Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
win2.Add (view2);
|
||||
Application.Top.Add (win1, win2);
|
||||
Application.Begin (Application.Top);
|
||||
var top = new Toplevel ();
|
||||
top.Add (win1, win2);
|
||||
Application.Begin (top);
|
||||
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.True (view1.HasFocus);
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus
|
||||
|
||||
Assert.True (Application.Top.NewKeyDownEvent (Key.Tab));
|
||||
Assert.True (top.NewKeyDownEvent (Key.Tab));
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.False (view1.HasFocus); // Only one of the most focused toplevels view can have focus
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.True (view2.HasFocus);
|
||||
|
||||
Assert.True (Application.Top.NewKeyDownEvent (Key.Tab));
|
||||
Assert.True (top.NewKeyDownEvent (Key.Tab));
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.True (view1.HasFocus);
|
||||
Assert.True (view2.CanFocus);
|
||||
@@ -354,21 +360,22 @@ public class NavigationTests
|
||||
var view2 = new View { Id = "view2", Width = 20, Height = 2, CanFocus = true };
|
||||
var win2 = new Window { Id = "win2", X = Pos.Right (win1), Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
win2.Add (view2);
|
||||
Application.Top.Add (win1, win2);
|
||||
Application.Begin (Application.Top);
|
||||
var top = new Toplevel ();
|
||||
top.Add (win1, win2);
|
||||
Application.Begin (top);
|
||||
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.True (view1.HasFocus);
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus
|
||||
|
||||
Assert.True (Application.Top.NewKeyDownEvent (Key.Tab.WithCtrl));
|
||||
Assert.True (top.NewKeyDownEvent (Key.Tab.WithCtrl));
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.False (view1.HasFocus); // Only one of the most focused toplevels view can have focus
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.True (view2.HasFocus);
|
||||
|
||||
Assert.True (Application.Top.NewKeyDownEvent (Key.Tab.WithCtrl));
|
||||
Assert.True (top.NewKeyDownEvent (Key.Tab.WithCtrl));
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.True (view1.HasFocus);
|
||||
Assert.True (view2.CanFocus);
|
||||
@@ -404,22 +411,23 @@ public class NavigationTests
|
||||
var view2 = new View { Id = "view2", Width = 20, Height = 2, CanFocus = true };
|
||||
var win2 = new Window { Id = "win2", X = Pos.Right (win1), Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
win2.Add (view2);
|
||||
Application.Top.Add (win1, win2);
|
||||
Application.Begin (Application.Top);
|
||||
var top = new Toplevel ();
|
||||
top.Add (win1, win2);
|
||||
Application.Begin (top);
|
||||
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.True (view1.HasFocus);
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus
|
||||
|
||||
Assert.True (Application.Top.NewKeyDownEvent (Key.Tab.WithCtrl));
|
||||
Assert.True (Application.Top.NewKeyDownEvent (Key.Tab.WithCtrl));
|
||||
Assert.True (top.NewKeyDownEvent (Key.Tab.WithCtrl));
|
||||
Assert.True (top.NewKeyDownEvent (Key.Tab.WithCtrl));
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.False (view1.HasFocus); // Only one of the most focused toplevels view can have focus
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.True (view2.HasFocus);
|
||||
|
||||
Assert.True (Application.Top.NewKeyDownEvent (Key.Tab.WithCtrl));
|
||||
Assert.True (top.NewKeyDownEvent (Key.Tab.WithCtrl));
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.True (view1.HasFocus);
|
||||
Assert.True (view2.CanFocus);
|
||||
@@ -441,7 +449,6 @@ public class NavigationTests
|
||||
var wasClicked = false;
|
||||
var view = new Button { Text = "Click Me" };
|
||||
view.Accept += (s, e) => wasClicked = !wasClicked;
|
||||
Application.Top.Add (view);
|
||||
|
||||
view.NewKeyDownEvent (Key.Space);
|
||||
Assert.True (wasClicked);
|
||||
@@ -473,7 +480,8 @@ public class NavigationTests
|
||||
button.Accept += (s, e) => wasClicked = !wasClicked;
|
||||
var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
win.Add (button);
|
||||
Application.Top.Add (win);
|
||||
var top = new Toplevel ();
|
||||
top.Add (win);
|
||||
|
||||
var iterations = 0;
|
||||
|
||||
@@ -518,7 +526,7 @@ public class NavigationTests
|
||||
Application.RequestStop ();
|
||||
};
|
||||
|
||||
Application.Run ();
|
||||
Application.Run (top);
|
||||
|
||||
Assert.Equal (1, iterations);
|
||||
}
|
||||
@@ -556,7 +564,7 @@ public class NavigationTests
|
||||
[AutoInitShutdown]
|
||||
public void FocusNext_Does_Not_Throws_If_A_View_Was_Removed_From_The_Collection ()
|
||||
{
|
||||
Toplevel top1 = Application.Top;
|
||||
Toplevel top1 = new ();
|
||||
var view1 = new View { Id = "view1", Width = 10, Height = 5, CanFocus = true };
|
||||
var top2 = new Toplevel { Id = "top2", Y = 1, Width = 10, Height = 5 };
|
||||
|
||||
@@ -644,7 +652,7 @@ public class NavigationTests
|
||||
|
||||
var win = new Window ();
|
||||
win.Add (sb, tf);
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.KeyDown += Top_KeyPress;
|
||||
|
||||
void Top_KeyPress (object sender, Key obj)
|
||||
@@ -718,7 +726,7 @@ public class NavigationTests
|
||||
|
||||
var win = new Window ();
|
||||
win.Add (sb, tf);
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.Add (win);
|
||||
Application.Begin (top);
|
||||
|
||||
@@ -746,14 +754,16 @@ public class NavigationTests
|
||||
|
||||
Application.Init (new FakeDriver ());
|
||||
|
||||
Application.Top.Ready += (s, e) => { Assert.Null (Application.Top.Focused); };
|
||||
var top = new Toplevel ();
|
||||
top.Ready += (s, e) => { Assert.Null (top.Focused); };
|
||||
|
||||
// Keyboard navigation with tab
|
||||
Console.MockKeyPresses.Push (new ConsoleKeyInfo ('\t', ConsoleKey.Tab, false, false, false));
|
||||
|
||||
Application.Iteration += (s, a) => Application.RequestStop ();
|
||||
|
||||
Application.Run ();
|
||||
Application.Run (top);
|
||||
top.Dispose ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
@@ -761,8 +771,9 @@ public class NavigationTests
|
||||
[AutoInitShutdown]
|
||||
public void Remove_Does_Not_Change_Focus ()
|
||||
{
|
||||
Assert.True (Application.Top.CanFocus);
|
||||
Assert.False (Application.Top.HasFocus);
|
||||
var top = new Toplevel ();
|
||||
Assert.True (top.CanFocus);
|
||||
Assert.False (top.HasFocus);
|
||||
|
||||
var container = new View { Width = 10, Height = 10 };
|
||||
var leave = false;
|
||||
@@ -776,11 +787,11 @@ public class NavigationTests
|
||||
Assert.True (child.CanFocus);
|
||||
Assert.False (child.HasFocus);
|
||||
|
||||
Application.Top.Add (container);
|
||||
Application.Begin (Application.Top);
|
||||
top.Add (container);
|
||||
Application.Begin (top);
|
||||
|
||||
Assert.True (Application.Top.CanFocus);
|
||||
Assert.True (Application.Top.HasFocus);
|
||||
Assert.True (top.CanFocus);
|
||||
Assert.True (top.HasFocus);
|
||||
Assert.True (container.CanFocus);
|
||||
Assert.True (container.HasFocus);
|
||||
Assert.True (child.CanFocus);
|
||||
@@ -789,7 +800,7 @@ public class NavigationTests
|
||||
container.Remove (child);
|
||||
child.Dispose ();
|
||||
child = null;
|
||||
Assert.True (Application.Top.HasFocus);
|
||||
Assert.True (top.HasFocus);
|
||||
Assert.True (container.CanFocus);
|
||||
Assert.True (container.HasFocus);
|
||||
Assert.Null (child);
|
||||
@@ -800,7 +811,7 @@ public class NavigationTests
|
||||
[AutoInitShutdown]
|
||||
public void ScreenToView_ViewToScreen_FindDeepestView_Full_Top ()
|
||||
{
|
||||
Toplevel top = Application.Current;
|
||||
Toplevel top = new ();
|
||||
top.BorderStyle = LineStyle.Single;
|
||||
|
||||
var view = new View
|
||||
@@ -1120,13 +1131,14 @@ public class NavigationTests
|
||||
[AutoInitShutdown]
|
||||
public void SetFocus_View_With_Null_Superview_Does_Not_Throw_Exception ()
|
||||
{
|
||||
Assert.True (Application.Top.CanFocus);
|
||||
Assert.False (Application.Top.HasFocus);
|
||||
var top = new Toplevel ();
|
||||
Assert.True (top.CanFocus);
|
||||
Assert.False (top.HasFocus);
|
||||
|
||||
Exception exception = Record.Exception (Application.Top.SetFocus);
|
||||
Exception exception = Record.Exception (top.SetFocus);
|
||||
Assert.Null (exception);
|
||||
Assert.True (Application.Top.CanFocus);
|
||||
Assert.True (Application.Top.HasFocus);
|
||||
Assert.True (top.CanFocus);
|
||||
Assert.True (top.HasFocus);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1136,7 +1148,7 @@ public class NavigationTests
|
||||
var view1Leave = false;
|
||||
var subView1Leave = false;
|
||||
var subView1subView1Leave = false;
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
var view1 = new View { CanFocus = true };
|
||||
var subView1 = new View { CanFocus = true };
|
||||
var subView1subView1 = new View { CanFocus = true };
|
||||
@@ -1459,6 +1471,7 @@ public class NavigationTests
|
||||
// Act
|
||||
RunState rs = Application.Begin (top);
|
||||
Application.End (rs);
|
||||
top.Dispose ();
|
||||
Application.Shutdown ();
|
||||
|
||||
// Assert does Not throw NullReferenceException
|
||||
|
||||
@@ -206,6 +206,7 @@ public class SubviewTests
|
||||
};
|
||||
|
||||
Application.Run (top);
|
||||
top.Dispose ();
|
||||
Application.Shutdown ();
|
||||
|
||||
Assert.Equal (1, tc);
|
||||
@@ -301,6 +302,7 @@ public class SubviewTests
|
||||
};
|
||||
|
||||
Application.Run (t);
|
||||
t.Dispose ();
|
||||
Application.Shutdown ();
|
||||
|
||||
Assert.Equal (1, tc);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -15,8 +15,9 @@ public class ViewKeyBindingTests
|
||||
var invoked = false;
|
||||
view.InvokingKeyBindings += (s, e) => invoked = true;
|
||||
|
||||
Application.Top.Add (view);
|
||||
Application.Begin (Application.Top);
|
||||
var top = new Toplevel ();
|
||||
top.Add (view);
|
||||
Application.Begin (top);
|
||||
|
||||
Application.OnKeyDown (Key.A);
|
||||
Assert.True (invoked);
|
||||
@@ -51,8 +52,9 @@ public class ViewKeyBindingTests
|
||||
var invoked = false;
|
||||
view.InvokingKeyBindings += (s, e) => invoked = true;
|
||||
|
||||
Application.Top.Add (view);
|
||||
Application.Begin (Application.Top);
|
||||
var top = new Toplevel ();
|
||||
top.Add (view);
|
||||
Application.Begin (top);
|
||||
|
||||
Application.OnKeyDown (Key.Z);
|
||||
Assert.False (invoked);
|
||||
@@ -77,8 +79,9 @@ public class ViewKeyBindingTests
|
||||
var invoked = false;
|
||||
view.InvokingKeyBindings += (s, e) => invoked = true;
|
||||
|
||||
Application.Top.Add (view);
|
||||
Application.Begin (Application.Top);
|
||||
var top = new Toplevel ();
|
||||
top.Add (view);
|
||||
Application.Begin (top);
|
||||
|
||||
invoked = false;
|
||||
Application.OnKeyDown (Key.H);
|
||||
@@ -105,8 +108,9 @@ public class ViewKeyBindingTests
|
||||
var invoked = false;
|
||||
view.InvokingKeyBindings += (s, e) => invoked = true;
|
||||
|
||||
Application.Top.Add (view);
|
||||
Application.Begin (Application.Top);
|
||||
var top = new Toplevel ();
|
||||
top.Add (view);
|
||||
Application.Begin (top);
|
||||
|
||||
Application.OnKeyDown (Key.Z);
|
||||
Assert.False (invoked);
|
||||
|
||||
@@ -33,8 +33,9 @@ public class ViewTests
|
||||
Application.Driver.Clip = savedClip;
|
||||
e.Cancel = true;
|
||||
};
|
||||
Application.Top.Add (view);
|
||||
Application.Begin (Application.Top);
|
||||
var top = new Toplevel ();
|
||||
top.Add (view);
|
||||
Application.Begin (top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (20, 10);
|
||||
|
||||
var expected = @"
|
||||
@@ -95,8 +96,9 @@ public class ViewTests
|
||||
Application.Driver.Clip = savedClip;
|
||||
e.Cancel = true;
|
||||
};
|
||||
Application.Top.Add (view);
|
||||
Application.Begin (Application.Top);
|
||||
var top = new Toplevel ();
|
||||
top.Add (view);
|
||||
Application.Begin (top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (20, 10);
|
||||
|
||||
var expected = @"
|
||||
@@ -147,8 +149,9 @@ public class ViewTests
|
||||
|
||||
root.Add (v);
|
||||
|
||||
Application.Top.Add (root);
|
||||
RunState runState = Application.Begin (Application.Top);
|
||||
var top = new Toplevel ();
|
||||
top.Add (root);
|
||||
RunState runState = Application.Begin (top);
|
||||
|
||||
if (label)
|
||||
{
|
||||
@@ -232,7 +235,7 @@ cccccccccccccccccccc",
|
||||
Height = 2,
|
||||
Text = "A text with some long width\n and also with two lines."
|
||||
};
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.Add (label, view);
|
||||
RunState runState = Application.Begin (top);
|
||||
|
||||
@@ -277,7 +280,7 @@ At 0,0
|
||||
Height = 2,
|
||||
Text = "A text with some long width\n and also with two lines."
|
||||
};
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.Add (label, view);
|
||||
RunState runState = Application.Begin (top);
|
||||
|
||||
@@ -326,7 +329,7 @@ At 0,0
|
||||
Height = 2,
|
||||
Text = "A text with some long width\n and also with two lines."
|
||||
};
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.Add (label, view);
|
||||
RunState runState = Application.Begin (top);
|
||||
|
||||
@@ -371,7 +374,7 @@ At 0,0
|
||||
Height = 2,
|
||||
Text = "A text with some long width\n and also with two lines."
|
||||
};
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.Add (label, view);
|
||||
RunState runState = Application.Begin (top);
|
||||
|
||||
@@ -435,8 +438,9 @@ At 0,0
|
||||
var tv = new TextView { Y = 11, Width = 10, Height = 10 };
|
||||
tv.DrawContentComplete += (s, e) => tvCalled = true;
|
||||
|
||||
Application.Top.Add (view, tv);
|
||||
Application.Begin (Application.Top);
|
||||
var top = new Toplevel ();
|
||||
top.Add (view, tv);
|
||||
Application.Begin (top);
|
||||
|
||||
Assert.True (viewCalled);
|
||||
Assert.True (tvCalled);
|
||||
@@ -467,7 +471,7 @@ At 0,0
|
||||
frame.Width = 40;
|
||||
frame.Height = 8;
|
||||
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
|
||||
top.Add (frame);
|
||||
|
||||
@@ -539,7 +543,7 @@ At 0,0
|
||||
Height = 2,
|
||||
Text = "A text with some long width\n and also with two lines."
|
||||
};
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.Add (label, view);
|
||||
RunState runState = Application.Begin (top);
|
||||
|
||||
@@ -584,7 +588,7 @@ At 0,0
|
||||
Height = 2,
|
||||
Text = "A text with some long width\n and also with two lines."
|
||||
};
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.Add (label, view);
|
||||
RunState runState = Application.Begin (top);
|
||||
|
||||
@@ -633,7 +637,7 @@ At 0,0
|
||||
Height = 2,
|
||||
Text = "A text with some long width\n and also with two lines."
|
||||
};
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.Add (label, view);
|
||||
RunState runState = Application.Begin (top);
|
||||
|
||||
@@ -680,7 +684,7 @@ At 0,0
|
||||
Height = 2,
|
||||
Text = "A text with some long width\n and also with two lines."
|
||||
};
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.Add (label, view);
|
||||
RunState runState = Application.Begin (top);
|
||||
|
||||
@@ -999,7 +1003,7 @@ At 0,0
|
||||
Assert.Equal (0, view.Height);
|
||||
var win = new Window ();
|
||||
win.Add (view);
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.Add (win);
|
||||
RunState rs = Application.Begin (top);
|
||||
|
||||
@@ -1044,7 +1048,7 @@ At 0,0
|
||||
var button = new Button { Text = "Click Me" };
|
||||
var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
win.Add (button);
|
||||
Toplevel top = Application.Top;
|
||||
Toplevel top = new ();
|
||||
top.Add (win);
|
||||
|
||||
var iterations = 0;
|
||||
@@ -1087,7 +1091,7 @@ At 0,0
|
||||
Application.RequestStop ();
|
||||
};
|
||||
|
||||
Application.Run ();
|
||||
Application.Run (top);
|
||||
|
||||
Assert.Equal (1, iterations);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user