Fix typos

This commit is contained in:
Tig
2024-08-05 09:40:07 -06:00
66 changed files with 2782 additions and 1962 deletions

View File

@@ -1,5 +1,4 @@
using Microsoft.VisualBasic;
using Xunit.Abstractions;
using Xunit.Abstractions;
// Alias Console to MockConsole so we don't accidentally use Console
@@ -7,8 +6,6 @@ namespace Terminal.Gui.ApplicationTests;
public class ApplicationTests
{
private readonly ITestOutputHelper _output;
public ApplicationTests (ITestOutputHelper output)
{
_output = output;
@@ -20,6 +17,127 @@ public class ApplicationTests
#endif
}
private readonly ITestOutputHelper _output;
private object _timeoutLock;
[Fact]
public void AddTimeout_Fires ()
{
Assert.Null (_timeoutLock);
_timeoutLock = new ();
uint timeoutTime = 250;
var initialized = false;
var iteration = 0;
var shutdown = false;
object timeout = null;
var timeoutCount = 0;
Application.InitializedChanged += OnApplicationOnInitializedChanged;
Application.Init (new FakeDriver ());
Assert.True (initialized);
Assert.False (shutdown);
_output.WriteLine ("Application.Run<Toplevel> ().Dispose ()..");
Application.Run<Toplevel> ().Dispose ();
_output.WriteLine ("Back from Application.Run<Toplevel> ().Dispose ()");
Assert.True (initialized);
Assert.False (shutdown);
Assert.Equal (1, timeoutCount);
Application.Shutdown ();
Application.InitializedChanged -= OnApplicationOnInitializedChanged;
lock (_timeoutLock)
{
if (timeout is { })
{
Application.RemoveTimeout (timeout);
timeout = null;
}
}
Assert.True (initialized);
Assert.True (shutdown);
#if DEBUG_IDISPOSABLE
Assert.Empty (Responder.Instances);
#endif
lock (_timeoutLock)
{
_timeoutLock = null;
}
return;
void OnApplicationOnInitializedChanged (object s, EventArgs<bool> a)
{
if (a.CurrentValue)
{
Application.Iteration += OnApplicationOnIteration;
initialized = true;
lock (_timeoutLock)
{
_output.WriteLine ($"Setting timeout for {timeoutTime}ms");
timeout = Application.AddTimeout (TimeSpan.FromMilliseconds (timeoutTime), TimeoutCallback);
}
}
else
{
Application.Iteration -= OnApplicationOnIteration;
shutdown = true;
}
}
bool TimeoutCallback ()
{
lock (_timeoutLock)
{
_output.WriteLine ($"TimeoutCallback. Count: {++timeoutCount}. Application Iteration: {iteration}");
if (timeout is { })
{
_output.WriteLine (" Nulling timeout.");
timeout = null;
}
}
// False means "don't re-do timer and remove it"
return false;
}
void OnApplicationOnIteration (object s, IterationEventArgs a)
{
lock (_timeoutLock)
{
if (timeoutCount > 0)
{
_output.WriteLine ($"Iteration #{iteration} - Timeout fired. Calling Application.RequestStop.");
Application.RequestStop ();
return;
}
}
iteration++;
// Simulate a delay
Thread.Sleep ((int)timeoutTime / 10);
// Worst case scenario - something went wrong
if (Application.IsInitialized && iteration > 25)
{
_output.WriteLine ($"Too many iterations ({iteration}): Calling Application.RequestStop.");
Application.RequestStop ();
}
}
}
[Fact]
public void Begin_Null_Toplevel_Throws ()
{
@@ -184,15 +302,18 @@ public class ApplicationTests
Assert.Null (Application.Driver);
Assert.Null (Application.MainLoop);
Assert.False (Application.EndAfterFirstIteration);
Assert.Equal (Key.Empty, Application.AlternateBackwardKey);
Assert.Equal (Key.Empty, Application.AlternateForwardKey);
Assert.Equal (Key.Empty, Application.QuitKey);
Assert.Equal (Key.Tab.WithShift, Application.PrevTabKey);
Assert.Equal (Key.Tab, Application.NextTabKey);
Assert.Equal (Key.F6.WithShift, Application.PrevTabGroupKey);
Assert.Equal (Key.F6, Application.NextTabGroupKey);
Assert.Equal (Key.Esc, Application.QuitKey);
Assert.Null (ApplicationOverlapped.OverlappedChildren);
Assert.Null (ApplicationOverlapped.OverlappedTop);
// Internal properties
Assert.False (Application.IsInitialized);
Assert.Equal (Application.GetSupportedCultures (), Application.SupportedCultures);
Assert.Equal (Application.GetAvailableCulturesFromEmbeddedResources (), Application.SupportedCultures);
Assert.False (Application._forceFakeConsole);
Assert.Equal (-1, Application.MainThreadId);
Assert.Empty (Application.TopLevels);
@@ -201,7 +322,8 @@ public class ApplicationTests
// Keyboard
Assert.Empty (Application.GetViewKeyBindings ());
Assert.Null (ApplicationNavigation.Focused);
// Navigation
Assert.Null (Application.Navigation);
// Events - Can't check
//Assert.Null (Application.NotifyNewRunState);
@@ -232,10 +354,10 @@ public class ApplicationTests
//Application.ForceDriver = "driver";
Application.EndAfterFirstIteration = true;
Application.AlternateBackwardKey = Key.A;
Application.AlternateForwardKey = Key.B;
Application.PrevTabGroupKey = Key.A;
Application.NextTabGroupKey = Key.B;
Application.QuitKey = Key.C;
Application.KeyBindings.Add (Key.A, KeyBindingScope.Application, Command.Cancel);
Application.KeyBindings.Add (Key.D, KeyBindingScope.Application, Command.Cancel);
//ApplicationOverlapped.OverlappedChildren = new List<View> ();
//ApplicationOverlapped.OverlappedTop =
@@ -243,6 +365,8 @@ public class ApplicationTests
//Application.WantContinuousButtonPressedView = new View ();
Application.Navigation = new ();
Application.ResetState ();
CheckReset ();
@@ -280,8 +404,8 @@ public class ApplicationTests
[InlineData (typeof (CursesDriver))]
public void Init_Shutdown_Fire_InitializedChanged (Type driverType)
{
bool initialized = false;
bool shutdown = false;
var initialized = false;
var shutdown = false;
Application.InitializedChanged += OnApplicationOnInitializedChanged;
@@ -310,34 +434,6 @@ public class ApplicationTests
}
}
[Fact]
public void Run_Iteration_Fires ()
{
int iteration = 0;
Application.Init (new FakeDriver ());
Application.Iteration += Application_Iteration;
Application.Run<Toplevel> ().Dispose ();
Assert.Equal (1, iteration);
Application.Shutdown ();
return;
void Application_Iteration (object sender, IterationEventArgs e)
{
if (iteration > 0)
{
Assert.Fail ();
}
iteration++;
Application.RequestStop ();
}
}
[Fact]
public void Init_Unbalanced_Throws ()
{
@@ -444,6 +540,33 @@ public class ApplicationTests
Application.Shutdown ();
}
[Fact]
public void Run_Iteration_Fires ()
{
var iteration = 0;
Application.Init (new FakeDriver ());
Application.Iteration += Application_Iteration;
Application.Run<Toplevel> ().Dispose ();
Assert.Equal (1, iteration);
Application.Shutdown ();
return;
void Application_Iteration (object sender, IterationEventArgs e)
{
if (iteration > 0)
{
Assert.Fail ();
}
iteration++;
Application.RequestStop ();
}
}
[Fact]
[AutoInitShutdown]
public void SetCurrentAsTop_Run_A_Not_Modal_Toplevel_Make_It_The_Current_Application_Top ()
@@ -894,15 +1017,15 @@ public class ApplicationTests
RunState rs = Application.Begin (w);
// Don't use visuals to test as style of border can change over time.
Assert.Equal (new Point (0, 0), w.Frame.Location);
Assert.Equal (new (0, 0), w.Frame.Location);
Application.OnMouseEvent (new () { Flags = MouseFlags.Button1Pressed });
Assert.Equal (w.Border, Application.MouseGrabView);
Assert.Equal (new Point (0, 0), w.Frame.Location);
Assert.Equal (new (0, 0), w.Frame.Location);
// Move down and to the right.
Application.OnMouseEvent (new () { Position = new (1, 1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition });
Assert.Equal (new Point (1, 1), w.Frame.Location);
Assert.Equal (new (1, 1), w.Frame.Location);
Application.End (rs);
w.Dispose ();
@@ -1037,6 +1160,7 @@ public class ApplicationTests
Assert.Throws<InvalidOperationException> (() => Application.Run (new Toplevel ()));
Application.Init (driver);
Application.Iteration += (s, e) =>
{
Assert.NotNull (Application.Top);
@@ -1096,123 +1220,4 @@ public class ApplicationTests
}
#endregion
private object _timeoutLock;
[Fact]
public void AddTimeout_Fires ()
{
Assert.Null (_timeoutLock);
_timeoutLock = new object ();
uint timeoutTime = 250;
bool initialized = false;
int iteration = 0;
bool shutdown = false;
object timeout = null;
int timeoutCount = 0;
Application.InitializedChanged += OnApplicationOnInitializedChanged;
Application.Init (new FakeDriver ());
Assert.True (initialized);
Assert.False (shutdown);
_output.WriteLine ("Application.Run<Toplevel> ().Dispose ()..");
Application.Run<Toplevel> ().Dispose ();
_output.WriteLine ("Back from Application.Run<Toplevel> ().Dispose ()");
Assert.True (initialized);
Assert.False (shutdown);
Assert.Equal (1, timeoutCount);
Application.Shutdown ();
Application.InitializedChanged -= OnApplicationOnInitializedChanged;
lock (_timeoutLock)
{
if (timeout is { })
{
Application.RemoveTimeout (timeout);
timeout = null;
}
}
Assert.True (initialized);
Assert.True (shutdown);
#if DEBUG_IDISPOSABLE
Assert.Empty (Responder.Instances);
#endif
lock (_timeoutLock)
{
_timeoutLock = null;
}
return;
void OnApplicationOnInitializedChanged (object s, EventArgs<bool> a)
{
if (a.CurrentValue)
{
Application.Iteration += OnApplicationOnIteration;
initialized = true;
lock (_timeoutLock)
{
_output.WriteLine ($"Setting timeout for {timeoutTime}ms");
timeout = Application.AddTimeout (TimeSpan.FromMilliseconds (timeoutTime), TimeoutCallback);
}
}
else
{
Application.Iteration -= OnApplicationOnIteration;
shutdown = true;
}
}
bool TimeoutCallback ()
{
lock (_timeoutLock)
{
_output.WriteLine ($"TimeoutCallback. Count: {++timeoutCount}. Application Iteration: {iteration}");
if (timeout is { })
{
_output.WriteLine ($" Nulling timeout.");
timeout = null;
}
}
// False means "don't re-do timer and remove it"
return false;
}
void OnApplicationOnIteration (object s, IterationEventArgs a)
{
lock (_timeoutLock)
{
if (timeoutCount > 0)
{
_output.WriteLine ($"Iteration #{iteration} - Timeout fired. Calling Application.RequestStop.");
Application.RequestStop ();
return;
}
}
iteration++;
// Simulate a delay
Thread.Sleep ((int)timeoutTime / 10);
// Worst case scenario - something went wrong
if (Application.IsInitialized && iteration > 25)
{
_output.WriteLine ($"Too many iterations ({iteration}): Calling Application.RequestStop.");
Application.RequestStop ();
}
}
}
}

View File

@@ -65,7 +65,7 @@ public class KeyboardTests
{
Application.ResetState (true);
// Before Init
Assert.Equal (Key.Empty, Application.QuitKey);
Assert.Equal (Key.Esc, Application.QuitKey);
Application.Init (new FakeDriver ());
// After Init
@@ -178,7 +178,7 @@ public class KeyboardTests
}
[Fact (Skip = "Replace when new key statics are added.")]
public void AlternateForwardKey_AlternateBackwardKey_Tests ()
public void NextTabGroupKey_PrevTabGroupKey_Tests ()
{
Application.Init (new FakeDriver ());
@@ -200,45 +200,27 @@ public class KeyboardTests
Assert.True (v1.HasFocus);
// Using default keys.
Application.OnKeyDown (Key.Tab.WithCtrl);
Application.OnKeyDown (Key.F6);
Assert.True (v2.HasFocus);
Application.OnKeyDown (Key.Tab.WithCtrl);
Application.OnKeyDown (Key.F6);
Assert.True (v3.HasFocus);
Application.OnKeyDown (Key.Tab.WithCtrl);
Application.OnKeyDown (Key.F6);
Assert.True (v4.HasFocus);
Application.OnKeyDown (Key.Tab.WithCtrl);
Application.OnKeyDown (Key.F6);
Assert.True (v1.HasFocus);
Application.OnKeyDown (Key.Tab.WithShift.WithCtrl);
Application.OnKeyDown (Key.F6.WithShift);
Assert.True (v4.HasFocus);
Application.OnKeyDown (Key.Tab.WithShift.WithCtrl);
Application.OnKeyDown (Key.F6.WithShift);
Assert.True (v3.HasFocus);
Application.OnKeyDown (Key.Tab.WithShift.WithCtrl);
Application.OnKeyDown (Key.F6.WithShift);
Assert.True (v2.HasFocus);
Application.OnKeyDown (Key.Tab.WithShift.WithCtrl);
Application.OnKeyDown (Key.F6.WithShift);
Assert.True (v1.HasFocus);
Application.OnKeyDown (Key.PageDown.WithCtrl);
Assert.True (v2.HasFocus);
Application.OnKeyDown (Key.PageDown.WithCtrl);
Assert.True (v3.HasFocus);
Application.OnKeyDown (Key.PageDown.WithCtrl);
Assert.True (v4.HasFocus);
Application.OnKeyDown (Key.PageDown.WithCtrl);
Assert.True (v1.HasFocus);
Application.OnKeyDown (Key.PageUp.WithCtrl);
Assert.True (v4.HasFocus);
Application.OnKeyDown (Key.PageUp.WithCtrl);
Assert.True (v3.HasFocus);
Application.OnKeyDown (Key.PageUp.WithCtrl);
Assert.True (v2.HasFocus);
Application.OnKeyDown (Key.PageUp.WithCtrl);
Assert.True (v1.HasFocus);
// Using another's alternate keys.
Application.AlternateForwardKey = Key.F7;
Application.AlternateBackwardKey = Key.F6;
// Using alternate keys.
Application.NextTabGroupKey = Key.F7;
Application.PrevTabGroupKey = Key.F8;
Application.OnKeyDown (Key.F7);
Assert.True (v2.HasFocus);
@@ -249,13 +231,13 @@ public class KeyboardTests
Application.OnKeyDown (Key.F7);
Assert.True (v1.HasFocus);
Application.OnKeyDown (Key.F6);
Application.OnKeyDown (Key.F8);
Assert.True (v4.HasFocus);
Application.OnKeyDown (Key.F6);
Application.OnKeyDown (Key.F8);
Assert.True (v3.HasFocus);
Application.OnKeyDown (Key.F6);
Application.OnKeyDown (Key.F8);
Assert.True (v2.HasFocus);
Application.OnKeyDown (Key.F6);
Application.OnKeyDown (Key.F8);
Assert.True (v1.HasFocus);
Application.RequestStop ();
@@ -264,12 +246,12 @@ public class KeyboardTests
Application.Run (top);
// Replacing the defaults keys to avoid errors on others unit tests that are using it.
Application.AlternateForwardKey = Key.PageDown.WithCtrl;
Application.AlternateBackwardKey = Key.PageUp.WithCtrl;
Application.NextTabGroupKey = Key.PageDown.WithCtrl;
Application.PrevTabGroupKey = Key.PageUp.WithCtrl;
Application.QuitKey = Key.Q.WithCtrl;
Assert.Equal (KeyCode.PageDown | KeyCode.CtrlMask, Application.AlternateForwardKey.KeyCode);
Assert.Equal (KeyCode.PageUp | KeyCode.CtrlMask, Application.AlternateBackwardKey.KeyCode);
Assert.Equal (KeyCode.PageDown | KeyCode.CtrlMask, Application.NextTabGroupKey.KeyCode);
Assert.Equal (KeyCode.PageUp | KeyCode.CtrlMask, Application.PrevTabGroupKey.KeyCode);
Assert.Equal (KeyCode.Q | KeyCode.CtrlMask, Application.QuitKey.KeyCode);
top.Dispose ();
@@ -321,14 +303,14 @@ public class KeyboardTests
Assert.True (win2.HasFocus);
Assert.Equal ("win2", ((Window)top.Subviews [^1]).Title);
Application.OnKeyDown (Key.Tab.WithCtrl);
Application.OnKeyDown (Key.F6);
Assert.True (win2.CanFocus);
Assert.False (win.HasFocus);
Assert.True (win2.CanFocus);
Assert.True (win2.HasFocus);
Assert.Equal ("win2", ((Window)top.Subviews [^1]).Title);
Application.OnKeyDown (Key.Tab.WithCtrl);
Application.OnKeyDown (Key.F6);
Assert.False (win.CanFocus);
Assert.False (win.HasFocus);
Assert.True (win2.CanFocus);
@@ -374,14 +356,14 @@ public class KeyboardTests
Assert.False (win2.HasFocus);
Assert.Equal ("win", ((Window)top.Subviews [^1]).Title);
Application.OnKeyDown (Key.Tab.WithCtrl);
Application.OnKeyDown (Key.F6);
Assert.True (win.CanFocus);
Assert.False (win.HasFocus);
Assert.True (win2.CanFocus);
Assert.True (win2.HasFocus);
Assert.Equal ("win2", ((Window)top.Subviews [^1]).Title);
Application.OnKeyDown (Key.Tab.WithCtrl);
Application.OnKeyDown (Key.F6);
Assert.True (win.CanFocus);
Assert.True (win.HasFocus);
Assert.True (win2.CanFocus);

View File

@@ -33,14 +33,14 @@ public class ConfigurationManagerTests
// assert
Assert.Equal (KeyCode.Q, Application.QuitKey.KeyCode);
Assert.Equal (KeyCode.F, Application.AlternateForwardKey.KeyCode);
Assert.Equal (KeyCode.B, Application.AlternateBackwardKey.KeyCode);
Assert.Equal (KeyCode.F, Application.NextTabGroupKey.KeyCode);
Assert.Equal (KeyCode.B, Application.PrevTabGroupKey.KeyCode);
}
// act
Settings ["Application.QuitKey"].PropertyValue = Key.Q;
Settings ["Application.AlternateForwardKey"].PropertyValue = Key.F;
Settings ["Application.AlternateBackwardKey"].PropertyValue = Key.B;
Settings ["Application.NextTabGroupKey"].PropertyValue = Key.F;
Settings ["Application.PrevTabGroupKey"].PropertyValue = Key.B;
Apply ();
@@ -152,8 +152,8 @@ public class ConfigurationManagerTests
Reset ();
Settings ["Application.QuitKey"].PropertyValue = Key.Q;
Settings ["Application.AlternateForwardKey"].PropertyValue = Key.F;
Settings ["Application.AlternateBackwardKey"].PropertyValue = Key.B;
Settings ["Application.NextTabGroupKey"].PropertyValue = Key.F;
Settings ["Application.PrevTabGroupKey"].PropertyValue = Key.B;
Updated += ConfigurationManager_Updated;
var fired = false;
@@ -166,13 +166,13 @@ public class ConfigurationManagerTests
Assert.Equal (Key.Esc, ((Key)Settings ["Application.QuitKey"].PropertyValue).KeyCode);
Assert.Equal (
KeyCode.PageDown | KeyCode.CtrlMask,
((Key)Settings ["Application.AlternateForwardKey"].PropertyValue).KeyCode
KeyCode.F6,
((Key)Settings ["Application.NextTabGroupKey"].PropertyValue).KeyCode
);
Assert.Equal (
KeyCode.PageUp | KeyCode.CtrlMask,
((Key)Settings ["Application.AlternateBackwardKey"].PropertyValue).KeyCode
KeyCode.F6 | KeyCode.ShiftMask,
((Key)Settings ["Application.PrevTabGroupKey"].PropertyValue).KeyCode
);
}
@@ -229,14 +229,14 @@ public class ConfigurationManagerTests
// arrange
Reset ();
Settings ["Application.QuitKey"].PropertyValue = Key.Q;
Settings ["Application.AlternateForwardKey"].PropertyValue = Key.F;
Settings ["Application.AlternateBackwardKey"].PropertyValue = Key.B;
Settings ["Application.NextTabGroupKey"].PropertyValue = Key.F;
Settings ["Application.PrevTabGroupKey"].PropertyValue = Key.B;
Settings.Apply ();
// assert apply worked
Assert.Equal (KeyCode.Q, Application.QuitKey.KeyCode);
Assert.Equal (KeyCode.F, Application.AlternateForwardKey.KeyCode);
Assert.Equal (KeyCode.B, Application.AlternateBackwardKey.KeyCode);
Assert.Equal (KeyCode.F, Application.NextTabGroupKey.KeyCode);
Assert.Equal (KeyCode.B, Application.PrevTabGroupKey.KeyCode);
//act
Reset ();
@@ -245,13 +245,13 @@ public class ConfigurationManagerTests
Assert.NotEmpty (Themes);
Assert.Equal ("Default", Themes.Theme);
Assert.Equal (Key.Esc, Application.QuitKey);
Assert.Equal (KeyCode.PageDown | KeyCode.CtrlMask, Application.AlternateForwardKey.KeyCode);
Assert.Equal (KeyCode.PageUp | KeyCode.CtrlMask, Application.AlternateBackwardKey.KeyCode);
Assert.Equal (Key.F6, Application.NextTabGroupKey);
Assert.Equal (Key.F6.WithShift, Application.PrevTabGroupKey);
// arrange
Settings ["Application.QuitKey"].PropertyValue = Key.Q;
Settings ["Application.AlternateForwardKey"].PropertyValue = Key.F;
Settings ["Application.AlternateBackwardKey"].PropertyValue = Key.B;
Settings ["Application.NextTabGroupKey"].PropertyValue = Key.F;
Settings ["Application.PrevTabGroupKey"].PropertyValue = Key.B;
Settings.Apply ();
Locations = ConfigLocations.DefaultOnly;
@@ -264,8 +264,8 @@ public class ConfigurationManagerTests
Assert.NotEmpty (Themes);
Assert.Equal ("Default", Themes.Theme);
Assert.Equal (KeyCode.Esc, Application.QuitKey.KeyCode);
Assert.Equal (KeyCode.PageDown | KeyCode.CtrlMask, Application.AlternateForwardKey.KeyCode);
Assert.Equal (KeyCode.PageUp | KeyCode.CtrlMask, Application.AlternateBackwardKey.KeyCode);
Assert.Equal (Key.F6, Application.NextTabGroupKey);
Assert.Equal (Key.F6.WithShift, Application.PrevTabGroupKey);
Reset ();
}

View File

@@ -12,26 +12,26 @@ public class SettingsScopeTests
Assert.Equal (Key.Esc, (Key)Settings ["Application.QuitKey"].PropertyValue);
Assert.Equal (
KeyCode.PageDown | KeyCode.CtrlMask,
((Key)Settings ["Application.AlternateForwardKey"].PropertyValue).KeyCode
Key.F6,
(Key)Settings ["Application.NextTabGroupKey"].PropertyValue
);
Assert.Equal (
KeyCode.PageUp | KeyCode.CtrlMask,
((Key)Settings ["Application.AlternateBackwardKey"].PropertyValue).KeyCode
Key.F6.WithShift,
(Key)Settings["Application.PrevTabGroupKey"].PropertyValue
);
// act
Settings ["Application.QuitKey"].PropertyValue = Key.Q;
Settings ["Application.AlternateForwardKey"].PropertyValue = Key.F;
Settings ["Application.AlternateBackwardKey"].PropertyValue = Key.B;
Settings ["Application.NextTabGroupKey"].PropertyValue = Key.F;
Settings ["Application.PrevTabGroupKey"].PropertyValue = Key.B;
Settings.Apply ();
// assert
Assert.Equal (KeyCode.Q, Application.QuitKey.KeyCode);
Assert.Equal (KeyCode.F, Application.AlternateForwardKey.KeyCode);
Assert.Equal (KeyCode.B, Application.AlternateBackwardKey.KeyCode);
Assert.Equal (Key.Q, Application.QuitKey);
Assert.Equal (Key.F, Application.NextTabGroupKey);
Assert.Equal (Key.B, Application.PrevTabGroupKey);
}
[Fact]
@@ -39,18 +39,17 @@ public class SettingsScopeTests
public void CopyUpdatedPropertiesFrom_ShouldCopyChangedPropertiesOnly ()
{
Settings ["Application.QuitKey"].PropertyValue = Key.End;
;
var updatedSettings = new SettingsScope ();
///Don't set Quitkey
updatedSettings ["Application.AlternateForwardKey"].PropertyValue = Key.F;
updatedSettings ["Application.AlternateBackwardKey"].PropertyValue = Key.B;
updatedSettings ["Application.NextTabGroupKey"].PropertyValue = Key.F;
updatedSettings ["Application.PrevTabGroupKey"].PropertyValue = Key.B;
Settings.Update (updatedSettings);
Assert.Equal (KeyCode.End, ((Key)Settings ["Application.QuitKey"].PropertyValue).KeyCode);
Assert.Equal (KeyCode.F, ((Key)updatedSettings ["Application.AlternateForwardKey"].PropertyValue).KeyCode);
Assert.Equal (KeyCode.B, ((Key)updatedSettings ["Application.AlternateBackwardKey"].PropertyValue).KeyCode);
Assert.Equal (KeyCode.F, ((Key)updatedSettings ["Application.NextTabGroupKey"].PropertyValue).KeyCode);
Assert.Equal (KeyCode.B, ((Key)updatedSettings ["Application.PrevTabGroupKey"].PropertyValue).KeyCode);
}
[Fact]
@@ -65,8 +64,8 @@ public class SettingsScopeTests
Assert.Equal ("Default", Themes.Theme);
Assert.True (Settings ["Application.QuitKey"].PropertyValue is Key);
Assert.True (Settings ["Application.AlternateForwardKey"].PropertyValue is Key);
Assert.True (Settings ["Application.AlternateBackwardKey"].PropertyValue is Key);
Assert.True (Settings ["Application.NextTabGroupKey"].PropertyValue is Key);
Assert.True (Settings ["Application.PrevTabGroupKey"].PropertyValue is Key);
Assert.True (Settings ["Theme"].PropertyValue is string);
Assert.Equal ("Default", Settings ["Theme"].PropertyValue as string);

View File

@@ -26,6 +26,10 @@ public class DialogTests
int width = $@"{CM.Glyphs.VLine} {btn1} {btn2} {CM.Glyphs.VLine}".Length;
d.SetBufferSize (width, 1);
// Override CM
Dialog.DefaultButtonAlignment = Alignment.Center;
Dialog.DefaultBorderStyle = LineStyle.Single;
// Default (center)
var dlg = new Dialog
{
@@ -151,6 +155,7 @@ public class DialogTests
int width = buttonRow.Length;
d.SetBufferSize (buttonRow.Length, 3);
// Default - Center
(runstate, Dialog dlg) = RunButtonTestDialog (
title,
@@ -874,6 +879,11 @@ public class DialogTests
{
((FakeDriver)Driver).SetBufferSize (20, 5);
// Override CM
Window.DefaultBorderStyle = LineStyle.Single;
Dialog.DefaultButtonAlignment = Alignment.Center;
Dialog.DefaultBorderStyle = LineStyle.Single;
var win = new Window ();
var iterations = 0;
@@ -889,7 +899,6 @@ public class DialogTests
win.Loaded += (s, a) =>
{
Dialog.DefaultButtonAlignment = Alignment.Center;
var dlg = new Dialog { Width = 18, Height = 3, Buttons = [new () { Text = "Ok" }] };
dlg.Loaded += (s, a) =>
@@ -975,7 +984,10 @@ public class DialogTests
var win = new Window ();
int iterations = -1;
// Override CM
Dialog.DefaultButtonAlignment = Alignment.Center;
Dialog.DefaultBorderStyle = LineStyle.Single;
Iteration += (s, a) =>
{
@@ -1012,7 +1024,10 @@ public class DialogTests
public void Dialog_Opened_From_Another_Dialog ()
{
((FakeDriver)Driver).SetBufferSize (30, 10);
// Override CM
Dialog.DefaultButtonAlignment = Alignment.Center;
Dialog.DefaultBorderStyle = LineStyle.Single;
var btn1 = new Button { Text = "press me 1" };
Button btn2 = null;
@@ -1159,6 +1174,11 @@ public class DialogTests
[AutoInitShutdown]
public void Location_When_Application_Top_Not_Default ()
{
// Override CM
Window.DefaultBorderStyle = LineStyle.Single;
Dialog.DefaultButtonAlignment = Alignment.Center;
Dialog.DefaultBorderStyle = LineStyle.Single;
var expected = 5;
var d = new Dialog { X = expected, Y = expected, Height = 5, Width = 5 };
Begin (d);
@@ -1188,6 +1208,11 @@ public class DialogTests
int iterations = -1;
// Override CM
Window.DefaultBorderStyle = LineStyle.Single;
Dialog.DefaultButtonAlignment = Alignment.Center;
Dialog.DefaultBorderStyle = LineStyle.Single;
Iteration += (s, a) =>
{
iterations++;
@@ -1361,6 +1386,10 @@ public class DialogTests
params Button [] btns
)
{
// Override CM
Dialog.DefaultButtonAlignment = Alignment.Center;
Dialog.DefaultBorderStyle = LineStyle.Single;
var dlg = new Dialog
{
Title = title,

View File

@@ -174,6 +174,10 @@ public class MessageBoxTests
var btn =
$"{CM.Glyphs.LeftBracket}{CM.Glyphs.LeftDefaultIndicator} btn {CM.Glyphs.RightDefaultIndicator}{CM.Glyphs.RightBracket}";
// Override CM
MessageBox.DefaultButtonAlignment = Alignment.End;
MessageBox.DefaultBorderStyle = LineStyle.Double;
Application.Iteration += (s, a) =>
{
iterations++;
@@ -239,6 +243,10 @@ public class MessageBoxTests
var btn =
$"{CM.Glyphs.LeftBracket}{CM.Glyphs.LeftDefaultIndicator} btn {CM.Glyphs.RightDefaultIndicator}{CM.Glyphs.RightBracket}";
// Override CM
MessageBox.DefaultButtonAlignment = Alignment.End;
MessageBox.DefaultBorderStyle = LineStyle.Double;
Application.Iteration += (s, a) =>
{
iterations++;
@@ -415,6 +423,10 @@ public class MessageBoxTests
int iterations = -1;
((FakeDriver)Application.Driver).SetBufferSize (70, 15);
// Override CM
MessageBox.DefaultButtonAlignment = Alignment.End;
MessageBox.DefaultBorderStyle = LineStyle.Double;
Application.Iteration += (s, a) =>
{
iterations++;

View File

@@ -572,6 +572,11 @@ public class FileDialogTests (ITestOutputHelper output)
private FileDialog GetInitializedFileDialog ()
{
Window.DefaultBorderStyle = LineStyle.Single;
Dialog.DefaultButtonAlignment = Alignment.Center;
Dialog.DefaultBorderStyle = LineStyle.Single;
var dlg = new FileDialog ();
Begin (dlg);
@@ -580,6 +585,10 @@ public class FileDialogTests (ITestOutputHelper output)
private FileDialog GetLinuxDialog ()
{
Window.DefaultBorderStyle = LineStyle.Single;
Dialog.DefaultButtonAlignment = Alignment.Center;
Dialog.DefaultBorderStyle = LineStyle.Single;
// Arrange
var fileSystem = new MockFileSystem (new Dictionary<string, MockFileData> (), "/");
fileSystem.MockTime (() => new (2010, 01, 01, 11, 12, 43));
@@ -623,6 +632,11 @@ public class FileDialogTests (ITestOutputHelper output)
private FileDialog GetWindowsDialog ()
{
// Override CM
Window.DefaultBorderStyle = LineStyle.Single;
Dialog.DefaultButtonAlignment = Alignment.Center;
Dialog.DefaultBorderStyle = LineStyle.Single;
// Arrange
var fileSystem = new MockFileSystem (new Dictionary<string, MockFileData> (), @"c:\");
fileSystem.MockTime (() => new (2010, 01, 01, 11, 12, 43));

View File

@@ -4,15 +4,15 @@ namespace Terminal.Gui.InputTests;
public class KeyBindingTests
{
private readonly ITestOutputHelper _output;
public KeyBindingTests (ITestOutputHelper output) { _output = output; }
private readonly ITestOutputHelper _output;
[Fact]
public void Add_Empty_Throws ()
public void Add_Invalid_Key_Throws ()
{
var keyBindings = new KeyBindings ();
List<Command> commands = new ();
Assert.Throws<ArgumentException> (() => keyBindings.Add (Key.A, commands.ToArray ()));
Assert.Throws<ArgumentException> (() => keyBindings.Add (Key.Empty, KeyBindingScope.HotKey, Command.Accept));
}
[Fact]
@@ -32,6 +32,14 @@ public class KeyBindingTests
Assert.Contains (Command.Left, resultCommands);
}
[Fact]
public void Add_No_Commands_Throws ()
{
var keyBindings = new KeyBindings ();
List<Command> commands = new ();
Assert.Throws<ArgumentException> (() => keyBindings.Add (Key.A, commands.ToArray ()));
}
[Fact]
public void Add_Single_Adds ()
{
@@ -45,6 +53,39 @@ public class KeyBindingTests
Assert.Contains (Command.HotKey, resultCommands);
}
// Add should not allow duplicates
[Fact]
public void Add_Throws_If_Exists ()
{
var keyBindings = new KeyBindings ();
keyBindings.Add (Key.A, KeyBindingScope.Application, Command.HotKey);
Assert.Throws<InvalidOperationException> (() => keyBindings.Add (Key.A, KeyBindingScope.Application, Command.Accept));
Command [] resultCommands = keyBindings.GetCommands (Key.A);
Assert.Contains (Command.HotKey, resultCommands);
keyBindings = new ();
keyBindings.Add (Key.A, KeyBindingScope.Focused, Command.HotKey);
Assert.Throws<InvalidOperationException> (() => keyBindings.Add (Key.A, KeyBindingScope.Focused, Command.Accept));
resultCommands = keyBindings.GetCommands (Key.A);
Assert.Contains (Command.HotKey, resultCommands);
keyBindings = new ();
keyBindings.Add (Key.A, KeyBindingScope.HotKey, Command.HotKey);
Assert.Throws<InvalidOperationException> (() => keyBindings.Add (Key.A, KeyBindingScope.Focused, Command.Accept));
resultCommands = keyBindings.GetCommands (Key.A);
Assert.Contains (Command.HotKey, resultCommands);
keyBindings = new ();
keyBindings.Add (Key.A, new KeyBinding (new [] { Command.HotKey }, KeyBindingScope.HotKey));
Assert.Throws<InvalidOperationException> (() => keyBindings.Add (Key.A, new KeyBinding (new [] { Command.Accept }, KeyBindingScope.HotKey)));
resultCommands = keyBindings.GetCommands (Key.A);
Assert.Contains (Command.HotKey, resultCommands);
}
// Clear
[Fact]
public void Clear_Clears ()
@@ -65,6 +106,14 @@ public class KeyBindingTests
Assert.Throws<InvalidOperationException> (() => keyBindings.GetKeyFromCommands (Command.Accept));
}
[Fact]
public void Get_Binding_Not_Found_Throws ()
{
var keyBindings = new KeyBindings ();
Assert.Throws<InvalidOperationException> (() => keyBindings.Get (Key.A));
Assert.Throws<InvalidOperationException> (() => keyBindings.Get (Key.B, KeyBindingScope.Application));
}
// GetCommands
[Fact]
public void GetCommands_Unknown_ReturnsEmpty ()
@@ -159,41 +208,8 @@ public class KeyBindingTests
Assert.Equal (Key.A, resultKey);
}
// Add should not allow duplicates
[Fact]
public void Add_Throws_If_Exists ()
{
var keyBindings = new KeyBindings ();
keyBindings.Add (Key.A, KeyBindingScope.Application, Command.HotKey);
Assert.Throws<InvalidOperationException> (() => keyBindings.Add (Key.A, KeyBindingScope.Application, Command.Accept));
Command [] resultCommands = keyBindings.GetCommands (Key.A);
Assert.Contains (Command.HotKey, resultCommands);
keyBindings = new ();
keyBindings.Add (Key.A, KeyBindingScope.Focused, Command.HotKey);
Assert.Throws<InvalidOperationException> (() => keyBindings.Add (Key.A, KeyBindingScope.Focused, Command.Accept));
resultCommands = keyBindings.GetCommands (Key.A);
Assert.Contains (Command.HotKey, resultCommands);
keyBindings = new ();
keyBindings.Add (Key.A, KeyBindingScope.HotKey, Command.HotKey);
Assert.Throws<InvalidOperationException> (() => keyBindings.Add (Key.A, KeyBindingScope.Focused, Command.Accept));
resultCommands = keyBindings.GetCommands (Key.A);
Assert.Contains (Command.HotKey, resultCommands);
keyBindings = new ();
keyBindings.Add (Key.A, new KeyBinding (new [] { Command.HotKey }, KeyBindingScope.HotKey));
Assert.Throws<InvalidOperationException> (() => keyBindings.Add (Key.A, new KeyBinding (new [] { Command.Accept }, KeyBindingScope.HotKey)));
resultCommands = keyBindings.GetCommands (Key.A);
Assert.Contains (Command.HotKey, resultCommands);
}
[Fact]
public void Replace_Key ()
public void ReplaceKey_Replaces ()
{
var keyBindings = new KeyBindings ();
keyBindings.Add (Key.A, KeyBindingScope.Application, Command.HotKey);
@@ -218,6 +234,33 @@ public class KeyBindingTests
Assert.Contains (Command.HotKey, keyBindings.GetCommands (Key.H));
}
[Fact]
public void ReplaceKey_Replaces_Leaves_Old_Binding ()
{
var keyBindings = new KeyBindings ();
keyBindings.Add (Key.A, KeyBindingScope.Application, Command.Accept);
keyBindings.Add (Key.B, KeyBindingScope.Application, Command.HotKey);
keyBindings.ReplaceKey (keyBindings.GetKeyFromCommands (Command.Accept), Key.C);
Assert.Empty (keyBindings.GetCommands (Key.A));
Assert.Contains (Command.Accept, keyBindings.GetCommands (Key.C));
}
[Fact]
public void ReplaceKey_Throws_If_DoesNotContain_Old ()
{
var keyBindings = new KeyBindings ();
Assert.Throws<InvalidOperationException> (() => keyBindings.ReplaceKey (Key.A, Key.B));
}
[Fact]
public void ReplaceKey_Throws_If_New_Is_Empty ()
{
var keyBindings = new KeyBindings ();
keyBindings.Add (Key.A, KeyBindingScope.Application, Command.HotKey);
Assert.Throws<InvalidOperationException> (() => keyBindings.ReplaceKey (Key.A, Key.Empty));
}
// Add with scope does the right things
[Theory]
[InlineData (KeyBindingScope.Focused)]
@@ -263,14 +306,6 @@ public class KeyBindingTests
Assert.Contains (Command.Left, binding.Commands);
}
[Fact]
public void Get_Binding_Not_Found_Throws ()
{
var keyBindings = new KeyBindings ();
Assert.Throws<InvalidOperationException> (() => keyBindings.Get (Key.A));
Assert.Throws<InvalidOperationException> (() => keyBindings.Get (Key.B, KeyBindingScope.Application));
}
[Theory]
[InlineData (KeyBindingScope.Focused)]
[InlineData (KeyBindingScope.HotKey)]

View File

@@ -40,6 +40,7 @@ public class ScenarioTests : TestsAllViews
var initialized = false;
var shutdown = false;
object timeout = null;
int iterationCount = 0;
Application.InitializedChanged += OnApplicationOnInitializedChanged;
@@ -106,7 +107,7 @@ public class ScenarioTests : TestsAllViews
}
Assert.Fail (
$"'{scenario.GetName ()}' failed to Quit with {Application.QuitKey} after {abortTime}ms. Force quit.");
$"'{scenario.GetName ()}' failed to Quit with {Application.QuitKey} after {abortTime}ms and {iterationCount} iterations. Force quit.");
Application.ResetState (true);
@@ -115,6 +116,7 @@ public class ScenarioTests : TestsAllViews
void OnApplicationOnIteration (object s, IterationEventArgs a)
{
iterationCount++;
if (Application.IsInitialized)
{
// Press QuitKey

View File

@@ -31,9 +31,9 @@
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="[2024.2.0,)" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="[17.10,18)" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="ReportGenerator" Version="5.3.8" />
<PackageReference Include="TestableIO.System.IO.Abstractions.TestingHelpers" Version="21.0.29" />
<PackageReference Include="Moq" Version="[4.20.70,5)" />
<PackageReference Include="ReportGenerator" Version="[5.3.8,6)" />
<PackageReference Include="TestableIO.System.IO.Abstractions.TestingHelpers" Version="[21.0.29,22)" />
<PackageReference Include="xunit" Version="[2.9.0,3)" />
<PackageReference Include="Xunit.Combinatorial" Version="[1.6.24,2)" />
<PackageReference Include="xunit.runner.visualstudio" Version="[2.8.2,3)">
@@ -59,6 +59,9 @@
<Using Include="Terminal.Gui" />
<Using Include="Xunit" />
</ItemGroup>
<ItemGroup>
<Folder Include="View\Orientation\" />
</ItemGroup>
<PropertyGroup Label="FineCodeCoverage">
<Enabled>
False

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,107 @@
using Moq;
namespace Terminal.Gui.ViewTests.OrientationTests;
public class OrientationHelperTests
{
[Fact]
public void Orientation_Set_NewValue_InvokesChangingAndChangedEvents ()
{
// Arrange
Mock<IOrientation> mockIOrientation = new Mock<IOrientation> ();
var orientationHelper = new OrientationHelper (mockIOrientation.Object);
var changingEventInvoked = false;
var changedEventInvoked = false;
orientationHelper.OrientationChanging += (sender, e) => { changingEventInvoked = true; };
orientationHelper.OrientationChanged += (sender, e) => { changedEventInvoked = true; };
// Act
orientationHelper.Orientation = Orientation.Vertical;
// Assert
Assert.True (changingEventInvoked, "OrientationChanging event was not invoked.");
Assert.True (changedEventInvoked, "OrientationChanged event was not invoked.");
}
[Fact]
public void Orientation_Set_NewValue_InvokesOnChangingAndOnChangedOverrides ()
{
// Arrange
Mock<IOrientation> mockIOrientation = new Mock<IOrientation> ();
var onChangingOverrideCalled = false;
var onChangedOverrideCalled = false;
mockIOrientation.Setup (x => x.OnOrientationChanging (It.IsAny<Orientation> (), It.IsAny<Orientation> ()))
.Callback (() => onChangingOverrideCalled = true)
.Returns (false); // Ensure it doesn't cancel the change
mockIOrientation.Setup (x => x.OnOrientationChanged (It.IsAny<Orientation> ()))
.Callback (() => onChangedOverrideCalled = true);
var orientationHelper = new OrientationHelper (mockIOrientation.Object);
// Act
orientationHelper.Orientation = Orientation.Vertical;
// Assert
Assert.True (onChangingOverrideCalled, "OnOrientationChanging override was not called.");
Assert.True (onChangedOverrideCalled, "OnOrientationChanged override was not called.");
}
[Fact]
public void Orientation_Set_SameValue_DoesNotInvokeChangingOrChangedEvents ()
{
// Arrange
Mock<IOrientation> mockIOrientation = new Mock<IOrientation> ();
var orientationHelper = new OrientationHelper (mockIOrientation.Object);
orientationHelper.Orientation = Orientation.Horizontal; // Set initial orientation
var changingEventInvoked = false;
var changedEventInvoked = false;
orientationHelper.OrientationChanging += (sender, e) => { changingEventInvoked = true; };
orientationHelper.OrientationChanged += (sender, e) => { changedEventInvoked = true; };
// Act
orientationHelper.Orientation = Orientation.Horizontal; // Set to the same value
// Assert
Assert.False (changingEventInvoked, "OrientationChanging event was invoked.");
Assert.False (changedEventInvoked, "OrientationChanged event was invoked.");
}
[Fact]
public void Orientation_Set_NewValue_OrientationChanging_CancellationPreventsChange ()
{
// Arrange
Mock<IOrientation> mockIOrientation = new Mock<IOrientation> ();
var orientationHelper = new OrientationHelper (mockIOrientation.Object);
orientationHelper.OrientationChanging += (sender, e) => { e.Cancel = true; }; // Cancel the change
// Act
orientationHelper.Orientation = Orientation.Vertical;
// Assert
Assert.Equal (Orientation.Horizontal, orientationHelper.Orientation); // Initial orientation is Horizontal
}
[Fact]
public void Orientation_Set_NewValue_OnOrientationChanging_CancelsChange ()
{
// Arrange
Mock<IOrientation> mockIOrientation = new Mock<IOrientation> ();
mockIOrientation.Setup (x => x.OnOrientationChanging (It.IsAny<Orientation> (), It.IsAny<Orientation> ()))
.Returns (true); // Override to return true, cancelling the change
var orientationHelper = new OrientationHelper (mockIOrientation.Object);
// Act
orientationHelper.Orientation = Orientation.Vertical;
// Assert
Assert.Equal (
Orientation.Horizontal,
orientationHelper.Orientation); // Initial orientation is Horizontal, and it should remain unchanged due to cancellation
}
}

View File

@@ -0,0 +1,136 @@
namespace Terminal.Gui.ViewTests.OrientationTests;
public class OrientationTests
{
private class CustomView : View, IOrientation
{
private readonly OrientationHelper _orientationHelper;
public CustomView ()
{
_orientationHelper = new (this);
Orientation = Orientation.Vertical;
_orientationHelper.OrientationChanging += (sender, e) => OrientationChanging?.Invoke (this, e);
_orientationHelper.OrientationChanged += (sender, e) => OrientationChanged?.Invoke (this, e);
}
public Orientation Orientation
{
get => _orientationHelper.Orientation;
set => _orientationHelper.Orientation = value;
}
public event EventHandler<CancelEventArgs<Orientation>> OrientationChanging;
public event EventHandler<EventArgs<Orientation>> OrientationChanged;
public bool CancelOnOrientationChanging { get; set; }
public bool OnOrientationChangingCalled { get; private set; }
public bool OnOrientationChangedCalled { get; private set; }
public bool OnOrientationChanging (Orientation currentOrientation, Orientation newOrientation)
{
OnOrientationChangingCalled = true;
// Custom logic before orientation changes
return CancelOnOrientationChanging; // Return true to cancel the change
}
public void OnOrientationChanged (Orientation newOrientation)
{
OnOrientationChangedCalled = true;
// Custom logic after orientation has changed
}
}
[Fact]
public void Orientation_Change_IsSuccessful ()
{
// Arrange
var customView = new CustomView ();
var orientationChanged = false;
customView.OrientationChanged += (sender, e) => orientationChanged = true;
// Act
customView.Orientation = Orientation.Horizontal;
// Assert
Assert.True (orientationChanged, "OrientationChanged event was not invoked.");
Assert.Equal (Orientation.Horizontal, customView.Orientation);
}
[Fact]
public void Orientation_Change_OrientationChanging_Set_Cancel_IsCancelled ()
{
// Arrange
var customView = new CustomView ();
customView.OrientationChanging += (sender, e) => e.Cancel = true; // Cancel the orientation change
var orientationChanged = false;
customView.OrientationChanged += (sender, e) => orientationChanged = true;
// Act
customView.Orientation = Orientation.Horizontal;
// Assert
Assert.False (orientationChanged, "OrientationChanged event was invoked despite cancellation.");
Assert.Equal (Orientation.Vertical, customView.Orientation); // Assuming Vertical is the default orientation
}
[Fact]
public void Orientation_Change_OnOrientationChanging_Return_True_IsCancelled ()
{
// Arrange
var customView = new CustomView ();
customView.CancelOnOrientationChanging = true; // Cancel the orientation change
var orientationChanged = false;
customView.OrientationChanged += (sender, e) => orientationChanged = true;
// Act
customView.Orientation = Orientation.Horizontal;
// Assert
Assert.False (orientationChanged, "OrientationChanged event was invoked despite cancellation.");
Assert.Equal (Orientation.Vertical, customView.Orientation); // Assuming Vertical is the default orientation
}
[Fact]
public void OrientationChanging_VirtualMethodCalledBeforeEvent ()
{
// Arrange
var radioGroup = new CustomView ();
bool eventCalled = false;
radioGroup.OrientationChanging += (sender, e) =>
{
eventCalled = true;
Assert.True (radioGroup.OnOrientationChangingCalled, "OnOrientationChanging was not called before the event.");
};
// Act
radioGroup.Orientation = Orientation.Horizontal;
// Assert
Assert.True (eventCalled, "OrientationChanging event was not called.");
}
[Fact]
public void OrientationChanged_VirtualMethodCalledBeforeEvent ()
{
// Arrange
var radioGroup = new CustomView ();
bool eventCalled = false;
radioGroup.OrientationChanged += (sender, e) =>
{
eventCalled = true;
Assert.True (radioGroup.OnOrientationChangedCalled, "OnOrientationChanged was not called before the event.");
};
// Act
radioGroup.Orientation = Orientation.Horizontal;
// Assert
Assert.True (eventCalled, "OrientationChanged event was not called.");
}
}

View File

@@ -358,6 +358,11 @@ public class MenuBarTests (ITestOutputHelper output)
[AutoInitShutdown]
public void Draw_A_Menu_Over_A_Dialog ()
{
// Override CM
Window.DefaultBorderStyle = LineStyle.Single;
Dialog.DefaultButtonAlignment = Alignment.Center;
Dialog.DefaultBorderStyle = LineStyle.Single;
Toplevel top = new ();
var win = new Window ();
top.Add (win);
@@ -586,7 +591,12 @@ public class MenuBarTests (ITestOutputHelper output)
[AutoInitShutdown]
public void Draw_A_Menu_Over_A_Top_Dialog ()
{
((FakeDriver)Application.Driver!).SetBufferSize (40, 15);
// Override CM
Window.DefaultBorderStyle = LineStyle.Single;
Dialog.DefaultButtonAlignment = Alignment.Center;
Dialog.DefaultBorderStyle = LineStyle.Single;
((FakeDriver)Application.Driver).SetBufferSize (40, 15);
Assert.Equal (new (0, 0, 40, 15), Application.Driver?.Clip);
TestHelpers.AssertDriverContentsWithFrameAre (@"", output);

View File

@@ -1116,10 +1116,10 @@ public class OverlappedTests
Assert.True (Application.OnKeyDown (Key.Tab.WithShift));
Assert.Equal ($"First line Win1{Environment.NewLine}Second line Win1", tvW1.Text);
Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl)); // move to win2
Assert.True (Application.OnKeyDown (Key.F6)); // move to win2
Assert.Equal (win2, ApplicationOverlapped.OverlappedChildren [0]);
Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl.WithShift)); // move back to win1
Assert.True (Application.OnKeyDown (Key.F6.WithShift)); // move back to win1
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
Assert.Equal (tvW1, win1.MostFocused);
@@ -1156,19 +1156,19 @@ public class OverlappedTests
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
Assert.Equal (tf2W1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl)); // Move to win2
Assert.True (Application.OnKeyDown (Key.F6)); // Move to win2
Assert.Equal (win2, ApplicationOverlapped.OverlappedChildren [0]);
Assert.Equal (tf1W2, win2.MostFocused);
tf2W2.SetFocus ();
Assert.True (tf2W2.HasFocus);
Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl.WithShift));
Assert.True (Application.OnKeyDown (Key.F6.WithShift));
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
Assert.Equal (tf2W1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Application.AlternateForwardKey));
Assert.True (Application.OnKeyDown (Application.NextTabGroupKey));
Assert.Equal (win2, ApplicationOverlapped.OverlappedChildren [0]);
Assert.Equal (tf2W2, win2.MostFocused);
Assert.True (Application.OnKeyDown (Application.AlternateBackwardKey));
Assert.True (Application.OnKeyDown (Application.PrevTabGroupKey));
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
Assert.Equal (tf2W1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorDown));

View File

@@ -155,7 +155,29 @@ public class ShortcutTests
Assert.Equal (Key.Empty, shortcut.Key);
}
// Test KeyBindingScope
[Fact]
public void Key_Set_Binds_Key_To_CommandView_Accept ()
{
var shortcut = new Shortcut ();
shortcut.Key = Key.F1;
// TODO:
}
[Fact]
public void Key_Changing_Removes_Previous_Binding ()
{
Shortcut shortcut = new Shortcut ();
shortcut.Key = Key.A;
Assert.Contains (Key.A, shortcut.KeyBindings.Bindings.Keys);
shortcut.Key = Key.B;
Assert.DoesNotContain (Key.A, shortcut.KeyBindings.Bindings.Keys);
Assert.Contains (Key.B, shortcut.KeyBindings.Bindings.Keys);
}
// Test Key gets bound correctly
[Fact]
@@ -177,15 +199,22 @@ public class ShortcutTests
}
[Fact]
public void Setting_Key_Binds_Key_To_CommandView_Accept ()
public void KeyBindingScope_Changing_Adjusts_KeyBindings ()
{
var shortcut = new Shortcut ();
Shortcut shortcut = new Shortcut ();
shortcut.Key = Key.F1;
shortcut.Key = Key.A;
Assert.Contains (Key.A, shortcut.KeyBindings.Bindings.Keys);
// TODO:
shortcut.KeyBindingScope = KeyBindingScope.Application;
Assert.DoesNotContain (Key.A, shortcut.KeyBindings.Bindings.Keys);
Assert.Contains (Key.A, Application.KeyBindings.Bindings.Keys);
shortcut.KeyBindingScope = KeyBindingScope.HotKey;
Assert.Contains (Key.A, shortcut.KeyBindings.Bindings.Keys);
Assert.DoesNotContain (Key.A, Application.KeyBindings.Bindings.Keys);
}
[Theory]
[InlineData (Orientation.Horizontal)]
[InlineData (Orientation.Vertical)]
@@ -567,7 +596,9 @@ public class ShortcutTests
Application.OnKeyDown (key);
Assert.Equal (expectedAction, action);
current.Dispose ();
}
}

View File

@@ -5407,10 +5407,10 @@ This is the second line.
tv.Text
);
Assert.True (tv.AllowsTab);
Assert.False (tv.NewKeyDownEvent (Key.Tab.WithCtrl));
Assert.False (tv.NewKeyDownEvent (Application.AlternateForwardKey));
Assert.False (tv.NewKeyDownEvent (Key.Tab.WithCtrl.WithShift));
Assert.False (tv.NewKeyDownEvent (Application.AlternateBackwardKey));
Assert.False (tv.NewKeyDownEvent (Key.F6));
Assert.False (tv.NewKeyDownEvent (Application.NextTabGroupKey));
Assert.False (tv.NewKeyDownEvent (Key.F6.WithShift));
Assert.False (tv.NewKeyDownEvent (Application.PrevTabGroupKey));
Assert.True (tv.NewKeyDownEvent (ContextMenu.DefaultKey));
Assert.True (tv.ContextMenu != null && tv.ContextMenu.MenuBar.Visible);

View File

@@ -486,10 +486,10 @@ public partial class ToplevelTests (ITestOutputHelper output)
var prevMostFocusedSubview = top.MostFocused;
Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl)); // move to next TabGroup (win2)
Assert.True (Application.OnKeyDown (Key.F6)); // move to next TabGroup (win2)
Assert.Equal (win2, top.Focused);
Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl.WithShift)); // move to prev TabGroup (win1)
Assert.True (Application.OnKeyDown (Key.F6.WithShift)); // move to prev TabGroup (win1)
Assert.Equal (win1, top.Focused);
Assert.Equal (tf2W1, top.MostFocused); // BUGBUG: Should be prevMostFocusedSubview - We need to cache the last focused view in the TabGroup somehow
@@ -527,16 +527,16 @@ public partial class ToplevelTests (ITestOutputHelper output)
Assert.Equal (tvW1, top.MostFocused);
// nav to win2
Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl));
Assert.True (Application.OnKeyDown (Key.F6));
Assert.Equal (win2, top.Focused);
Assert.Equal (tf1W2, top.MostFocused);
Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl.WithShift));
Assert.True (Application.OnKeyDown (Key.F6.WithShift));
Assert.Equal (win1, top.Focused);
Assert.Equal (tf2W1, top.MostFocused);
Assert.True (Application.OnKeyDown (Application.AlternateForwardKey));
Assert.True (Application.OnKeyDown (Application.NextTabGroupKey));
Assert.Equal (win2, top.Focused);
Assert.Equal (tf1W2, top.MostFocused);
Assert.True (Application.OnKeyDown (Application.AlternateBackwardKey));
Assert.True (Application.OnKeyDown (Application.PrevTabGroupKey));
Assert.Equal (win1, top.Focused);
Assert.Equal (tf2W1, top.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorUp));