Removed OverlappedTop.

Updated unit tess.
Fixed bad code paths.
This commit is contained in:
Tig
2024-09-17 17:20:19 -06:00
parent 86d21ef3b7
commit b717892235
43 changed files with 400 additions and 4123 deletions

View File

@@ -254,39 +254,39 @@ public class PosAnchorEndTests (ITestOutputHelper output)
top.Dispose ();
}
// TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
// TODO: A new test that calls SetRelativeLayout directly is needed.
[Fact]
[AutoInitShutdown]
public void PosAnchorEnd_Equal_Inside_Window_With_MenuBar_And_StatusBar_On_Toplevel ()
{
var viewWidth = 10;
var viewHeight = 1;
//// TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
//// TODO: A new test that calls SetRelativeLayout directly is needed.
//[Fact]
//[AutoInitShutdown]
//public void PosAnchorEnd_Equal_Inside_Window_With_MenuBar_And_StatusBar_On_Toplevel ()
//{
// var viewWidth = 10;
// var viewHeight = 1;
var tv = new TextView
{
X = Pos.AnchorEnd (viewWidth), Y = Pos.AnchorEnd (viewHeight), Width = viewWidth, Height = viewHeight
};
// var tv = new TextView
// {
// X = Pos.AnchorEnd (viewWidth), Y = Pos.AnchorEnd (viewHeight), Width = viewWidth, Height = viewHeight
// };
var win = new Window ();
// var win = new Window ();
win.Add (tv);
// win.Add (tv);
var menu = new MenuBar ();
var status = new StatusBar ();
Toplevel top = new ();
top.Add (win, menu, status);
RunState rs = Application.Begin (top);
// var menu = new MenuBar ();
// var status = new StatusBar ();
// Toplevel top = new ();
// top.Add (win, menu, status);
// RunState rs = Application.Begin (top);
Assert.Equal (new (0, 0, 80, 25), top.Frame);
Assert.Equal (new (0, 0, 80, 1), menu.Frame);
Assert.Equal (new (0, 24, 80, 1), status.Frame);
Assert.Equal (new (0, 1, 80, 23), win.Frame);
Assert.Equal (new (68, 20, 10, 1), tv.Frame);
// Assert.Equal (new (0, 0, 80, 25), top.Frame);
// Assert.Equal (new (0, 0, 80, 1), menu.Frame);
// Assert.Equal (new (0, 24, 80, 1), status.Frame);
// Assert.Equal (new (0, 1, 80, 23), win.Frame);
// Assert.Equal (new (68, 20, 10, 1), tv.Frame);
Application.End (rs);
top.Dispose ();
}
// Application.End (rs);
// top.Dispose ();
//}
[Fact]
public void PosAnchorEnd_Calculate_ReturnsExpectedValue ()

View File

@@ -136,7 +136,7 @@ public class PosCombineTests (ITestOutputHelper output)
Assert.Throws<InvalidOperationException> (() => Application.Run ());
top.Dispose ();
Application.Shutdown ();
Application.ResetState (ignoreDisposed: true);
}
}

View File

@@ -961,7 +961,6 @@ public class ToScreenTests (ITestOutputHelper output)
Application.Begin (top);
Assert.Equal (Application.Current, top);
Assert.Equal (new (0, 0, 80, 25), new Rectangle (0, 0, View.Driver.Cols, View.Driver.Rows));
Assert.Equal (new (0, 0, View.Driver.Cols, View.Driver.Rows), top.Frame);
Assert.Equal (new (0, 0, 80, 25), top.Frame);
@@ -1117,7 +1116,6 @@ public class ToScreenTests (ITestOutputHelper output)
Application.Begin (top);
Assert.Equal (Application.Current, top);
Assert.Equal (new (0, 0, 80, 25), new Rectangle (0, 0, View.Driver.Cols, View.Driver.Rows));
Assert.NotEqual (new (0, 0, View.Driver.Cols, View.Driver.Rows), top.Frame);
Assert.Equal (new (3, 2, 20, 10), top.Frame);

View File

@@ -325,10 +325,10 @@ public class CanFocusTests () : TestsAllViews
Label label = new () { Text = "label" };
View view = new () { Text = "view", CanFocus = true };
Application.Navigation = new ();
Application.Current = new ();
Application.Current.Add (label, view);
Application.Top = new ();
Application.Top.Add (label, view);
Application.Current.SetFocus ();
Application.Top.SetFocus ();
Assert.Equal (view, Application.Navigation.GetFocused ());
Assert.False (label.CanFocus);
Assert.False (label.HasFocus);
@@ -358,278 +358,10 @@ public class CanFocusTests () : TestsAllViews
Assert.True (label.HasFocus);
Assert.False (view.HasFocus);
Application.Current.Dispose ();
Application.Top.Dispose ();
Application.ResetState ();
}
#if V2_NEW_FOCUS_IMPL // Bogus test - depends on auto CanFocus behavior
[Fact]
public void CanFocus_Container_ToFalse_Turns_All_Subviews_ToFalse_Too ()
{
Application.Init (new FakeDriver ());
Toplevel t = new ();
var w = new Window ();
var f = new FrameView ();
var v1 = new View { CanFocus = true };
var v2 = new View { CanFocus = true };
f.Add (v1, v2);
w.Add (f);
t.Add (w);
t.Ready += (s, e) =>
{
Assert.True (t.CanFocus);
Assert.True (w.CanFocus);
Assert.True (f.CanFocus);
Assert.True (v1.CanFocus);
Assert.True (v2.CanFocus);
w.CanFocus = false;
Assert.False (w.CanFocus);
Assert.False (f.CanFocus);
Assert.False (v1.CanFocus);
Assert.False (v2.CanFocus);
};
Application.Iteration += (s, a) => Application.RequestStop ();
Application.Run (t);
t.Dispose ();
Application.Shutdown ();
}
#endif
#if V2_NEW_FOCUS_IMPL // Bogus test - depends on auto CanFocus behavior
[Fact]
public void CanFocus_Container_Toggling_All_Subviews_To_Old_Value_When_Is_True ()
{
Application.Init (new FakeDriver ());
Toplevel t = new ();
var w = new Window ();
var f = new FrameView ();
var v1 = new View ();
var v2 = new View { CanFocus = true };
f.Add (v1, v2);
w.Add (f);
t.Add (w);
t.Ready += (s, e) =>
{
Assert.True (t.CanFocus);
Assert.True (w.CanFocus);
Assert.True (f.CanFocus);
Assert.False (v1.CanFocus);
Assert.True (v2.CanFocus);
w.CanFocus = false;
Assert.False (w.CanFocus);
Assert.False (f.CanFocus);
Assert.False (v1.CanFocus);
Assert.False (v2.CanFocus);
w.CanFocus = true;
Assert.True (w.CanFocus);
Assert.True (f.CanFocus);
Assert.False (v1.CanFocus);
Assert.True (v2.CanFocus);
};
Application.Iteration += (s, a) => Application.RequestStop ();
Application.Run (t);
t.Dispose ();
Application.Shutdown ();
}
#endif
#if V2_NEW_FOCUS_IMPL // Bogus test - depends on auto CanFocus behavior
[Fact]
public void CanFocus_Faced_With_Container_After_Run ()
{
Application.Init (new FakeDriver ());
Toplevel t = new ();
var w = new Window ();
var f = new FrameView ();
var v = new View { CanFocus = true };
f.Add (v);
w.Add (f);
t.Add (w);
t.Ready += (s, e) =>
{
Assert.True (t.CanFocus);
Assert.True (w.CanFocus);
Assert.True (f.CanFocus);
Assert.True (v.CanFocus);
f.CanFocus = false;
Assert.False (f.CanFocus);
Assert.False (v.CanFocus);
v.CanFocus = false;
Assert.False (f.CanFocus);
Assert.False (v.CanFocus);
Assert.Throws<InvalidOperationException> (() => v.CanFocus = true);
Assert.False (f.CanFocus);
Assert.False (v.CanFocus);
f.CanFocus = true;
Assert.True (f.CanFocus);
Assert.True (v.CanFocus);
};
Application.Iteration += (s, a) => Application.RequestStop ();
Application.Run (t);
t.Dispose ();
Application.Shutdown ();
}
#endif
#if V2_NEW_FOCUS_IMPL
[Fact]
[AutoInitShutdown]
public void CanFocus_Sets_To_False_On_Single_View_Focus_View_On_Another_Toplevel ()
{
var view1 = new View { Id = "view1", Width = 10, Height = 1, CanFocus = true };
var win1 = new Window { Id = "win1", Width = Dim.Percent (50), Height = Dim.Fill () };
win1.Add (view1);
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);
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.OnKeyDown (Key.F6));
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.OnKeyDown (Key.F6));
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
view1.CanFocus = false;
Assert.False (view1.CanFocus);
Assert.False (view1.HasFocus);
Assert.True (view2.CanFocus);
Assert.True (view2.HasFocus);
Assert.Equal (win2, Application.Current.GetFocused ());
Assert.Equal (view2, Application.Current.GetMostFocused ());
top.Dispose ();
}
[Fact]
[AutoInitShutdown]
public void CanFocus_Sets_To_False_On_Toplevel_Focus_View_On_Another_Toplevel ()
{
var view1 = new View { Id = "view1", Width = 10, Height = 1, CanFocus = true };
var win1 = new Window { Id = "win1", Width = Dim.Percent (50), Height = Dim.Fill () };
win1.Add (view1);
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);
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.OnKeyDown (Key.F6));
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.OnKeyDown (Key.F6));
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
win1.CanFocus = false;
Assert.False (view1.CanFocus);
Assert.False (view1.HasFocus);
Assert.False (win1.CanFocus);
Assert.False (win1.HasFocus);
Assert.True (view2.CanFocus);
Assert.True (view2.HasFocus);
Assert.Equal (win2, Application.Current.GetFocused ());
Assert.Equal (view2, Application.Current.GetMostFocused ());
top.Dispose ();
}
[Fact]
[AutoInitShutdown]
public void CanFocus_Sets_To_False_With_Two_Views_Focus_Another_View_On_The_Same_Toplevel ()
{
var view1 = new View { Id = "view1", Width = 10, Height = 1, CanFocus = true };
var view12 = new View
{
Id = "view12",
Y = 5,
Width = 10,
Height = 1,
CanFocus = true
};
var win1 = new Window { Id = "win1", Width = Dim.Percent (50), Height = Dim.Fill () };
win1.Add (view1, view12);
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);
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.OnKeyDown (Key.F6)); // move to win2
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.OnKeyDown (Key.F6));
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
view1.CanFocus = false;
Assert.False (view1.CanFocus);
Assert.False (view1.HasFocus);
Assert.True (view2.CanFocus);
Assert.False (view2.HasFocus);
Assert.Equal (win1, Application.Current.GetFocused ());
Assert.Equal (view12, Application.Current.GetMostFocused ());
top.Dispose ();
}
#endif
[Fact (Skip = "Causes crash on Ubuntu in Github Action. Bogus test anyway.")]
public void WindowDispose_CanFocusProblem ()
{

View File

@@ -28,7 +28,7 @@ public class NavigationTests (ITestOutputHelper _output) : TestsAllViews
Toplevel top = new ();
Application.Current = top;
Application.Top = top;
Application.Navigation = new ApplicationNavigation ();
View otherView = new ()
@@ -115,7 +115,7 @@ public class NavigationTests (ITestOutputHelper _output) : TestsAllViews
}
Toplevel top = new ();
Application.Current = top;
Application.Top = top;
Application.Navigation = new ApplicationNavigation ();
View otherView = new ()
@@ -144,8 +144,8 @@ public class NavigationTests (ITestOutputHelper _output) : TestsAllViews
Assert.False (view.HasFocus);
Assert.False (otherView.HasFocus);
Application.Current.SetFocus ();
Assert.True (Application.Current!.HasFocus);
Application.Top.SetFocus ();
Assert.True (Application.Top!.HasFocus);
Assert.True (top.HasFocus);
// Start with the focus on our test view
@@ -275,7 +275,7 @@ public class NavigationTests (ITestOutputHelper _output) : TestsAllViews
Toplevel top = new ();
Application.Current = top;
Application.Top = top;
Application.Navigation = new ApplicationNavigation ();
View otherView = new ()
@@ -373,134 +373,6 @@ public class NavigationTests (ITestOutputHelper _output) : TestsAllViews
Assert.Equal (subview2, view.MostFocused);
}
// [Fact]
// [AutoInitShutdown]
// public void HotKey_Will_Invoke_KeyPressed_Only_For_The_MostFocused_With_Top_KeyPress_Event ()
// {
// var sbQuiting = false;
// var tfQuiting = false;
// var topQuiting = false;
// var sb = new StatusBar (
// new Shortcut []
// {
// new (
// KeyCode.CtrlMask | KeyCode.Q,
// "Quit",
// () => sbQuiting = true
// )
// }
// );
// var tf = new TextField ();
// tf.KeyDown += Tf_KeyPressed;
// void Tf_KeyPressed (object sender, Key obj)
// {
// if (obj.KeyCode == (KeyCode.Q | KeyCode.CtrlMask))
// {
// obj.Handled = tfQuiting = true;
// }
// }
// var win = new Window ();
// win.Add (sb, tf);
// Toplevel top = new ();
// top.KeyDown += Top_KeyPress;
// void Top_KeyPress (object sender, Key obj)
// {
// if (obj.KeyCode == (KeyCode.Q | KeyCode.CtrlMask))
// {
// obj.Handled = topQuiting = true;
// }
// }
// top.Add (win);
// Application.Begin (top);
// Assert.False (sbQuiting);
// Assert.False (tfQuiting);
// Assert.False (topQuiting);
// Application.Driver?.SendKeys ('Q', ConsoleKey.Q, false, false, true);
// Assert.False (sbQuiting);
// Assert.True (tfQuiting);
// Assert.False (topQuiting);
//#if BROKE_WITH_2927
// tf.KeyPressed -= Tf_KeyPress;
// tfQuiting = false;
// Application.Driver?.SendKeys ('q', ConsoleKey.Q, false, false, true);
// Application.MainLoop.RunIteration ();
// Assert.True (sbQuiting);
// Assert.False (tfQuiting);
// Assert.False (topQuiting);
// sb.RemoveItem (0);
// sbQuiting = false;
// Application.Driver?.SendKeys ('q', ConsoleKey.Q, false, false, true);
// Application.MainLoop.RunIteration ();
// Assert.False (sbQuiting);
// Assert.False (tfQuiting);
//// This test is now invalid because `win` is focused, so it will receive the keypress
// Assert.True (topQuiting);
//#endif
// top.Dispose ();
// }
// [Fact]
// [AutoInitShutdown]
// public void HotKey_Will_Invoke_KeyPressed_Only_For_The_MostFocused_Without_Top_KeyPress_Event ()
// {
// var sbQuiting = false;
// var tfQuiting = false;
// var sb = new StatusBar (
// new Shortcut []
// {
// new (
// KeyCode.CtrlMask | KeyCode.Q,
// "~^Q~ Quit",
// () => sbQuiting = true
// )
// }
// );
// var tf = new TextField ();
// tf.KeyDown += Tf_KeyPressed;
// void Tf_KeyPressed (object sender, Key obj)
// {
// if (obj.KeyCode == (KeyCode.Q | KeyCode.CtrlMask))
// {
// obj.Handled = tfQuiting = true;
// }
// }
// var win = new Window ();
// win.Add (sb, tf);
// Toplevel top = new ();
// top.Add (win);
// Application.Begin (top);
// Assert.False (sbQuiting);
// Assert.False (tfQuiting);
// Application.Driver?.SendKeys ('Q', ConsoleKey.Q, false, false, true);
// Assert.False (sbQuiting);
// Assert.True (tfQuiting);
// tf.KeyDown -= Tf_KeyPressed;
// tfQuiting = false;
// Application.Driver?.SendKeys ('Q', ConsoleKey.Q, false, false, true);
// Application.MainLoop.RunIteration ();
//#if BROKE_WITH_2927
// Assert.True (sbQuiting);
// Assert.False (tfQuiting);
//#endif
// top.Dispose ();
// }
[Fact]
[SetupFakeDriver]
public void Navigation_With_Null_Focused_View ()
@@ -542,49 +414,4 @@ public class NavigationTests (ITestOutputHelper _output) : TestsAllViews
Assert.False (view2.HasFocus);
win1.Dispose ();
}
#if V2_NEW_FOCUS_IMPL // bogus test - Depends on auto setting of CanFocus
[Fact]
[AutoInitShutdown]
public void Remove_Does_Not_Change_Focus ()
{
var top = new Toplevel ();
Assert.True (top.CanFocus);
Assert.False (top.HasFocus);
var container = new View { Width = 10, Height = 10 };
var leave = false;
container.Leave += (s, e) => leave = true;
Assert.False (container.CanFocus);
var child = new View { Width = Dim.Fill (), Height = Dim.Fill (), CanFocus = true };
container.Add (child);
Assert.True (container.CanFocus);
Assert.False (container.HasFocus);
Assert.True (child.CanFocus);
Assert.False (child.HasFocus);
top.Add (container);
Application.Begin (top);
Assert.True (top.CanFocus);
Assert.True (top.HasFocus);
Assert.True (container.CanFocus);
Assert.True (container.HasFocus);
Assert.True (child.CanFocus);
Assert.True (child.HasFocus);
container.Remove (child);
child.Dispose ();
child = null;
Assert.True (top.HasFocus);
Assert.True (container.CanFocus);
Assert.True (container.HasFocus);
Assert.Null (child);
Assert.False (leave);
top.Dispose ();
}
#endif
}