mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* Tons of API doc updates * Removed stale test * Removed stale tests * Fixed Skipped Shadow test 1 * Fixed Skipped Shadow test 2 * Fixed Skipped Shadow test 3 * Removed stale test * Removed stale test2 * Explicit unregister of event handler on Application.Driver!.ClearedContents * Added Toplevels to dict * code cleanup * spelling error * Removed stale test3 * Removed stale test4 * Removed stale test5 * added script * tweaked script * tweaked script * Created StressTests project; moved some tests * Created IntegrationTests project; moved some tests * New yml * made old yml just unit tests * Tweaked Button_IsDefault_Raises_Accepted_Correctly * tweaked script * cleaned up ymls * tweakled up ymls * stress tests... * stress tests on ubuntu only * Fixed WindowsDriver in InvokeLeakTest * Fixed WindowsDriver in InvokeLeakTest2 * Added Directory.Packages.props. Added Directory.Build.props * Shortened StressTest time * Removed dupe file. * DemoFiles * Moved all tests to ./Tests dir. * Fixed release build issue * Fixed .sln file * Fixed .sl* files * Fixing ymls * Fixing interation tests * Create link to the file TestHelpers. * Created Tests/UnitTestsParallelizable. Moved all obviously parallelizable tests. Updated yml. * fixing logs * fixing logs2 * fixing logs3 * don't require stress to pass for PRs * Fix a failure? * tweaked script * Coudl this be it? * Moved tons of tests to parallelizable * Fixed some stuff * Script to find duplicate tests * Testing workflows * Updated to v4 * Fix RelativeBasePath issue * Replace powershell to pwsh * Add ignore projects. * Removed dupe unit tests * Code cleanup of tests * Cleaned up test warnings * yml tweak * Moved setter * tweak ymls * just randomly throwing spaghetti at a wall * Enable runing 5 test runners in par * Turned off DEBUG_DISPOSABLE for par tests * RunningUnitTests=true * code cleanup (forcing more Action runs) * DISABLE_DEBUG_IDISPOSABLE * Added View.DebugIDisposable. False by default. * Remobed bogus tareet * Remobed bogus tareet2 * fixed warning * added api doc * fixed warning * fixed warning * fixed warning2 * fixed warning3 * fixed warning4 --------- Co-authored-by: BDisp <bd.bdisp@gmail.com>
1486 lines
56 KiB
C#
1486 lines
56 KiB
C#
using UnitTests;
|
|
using UnitTests;
|
|
using Xunit.Abstractions;
|
|
using static Terminal.Gui.Application;
|
|
|
|
namespace Terminal.Gui.DialogTests;
|
|
|
|
public class DialogTests
|
|
{
|
|
private readonly ITestOutputHelper _output;
|
|
|
|
public DialogTests (ITestOutputHelper output)
|
|
{
|
|
#if DEBUG_IDISPOSABLE
|
|
View.DebugIDisposable = true;
|
|
#endif
|
|
_output = output;
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Add_Button_Works ()
|
|
{
|
|
RunState runstate = null;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
|
|
var title = "1234";
|
|
var btn1Text = "yes";
|
|
var btn1 = $"{Glyphs.LeftBracket} {btn1Text} {Glyphs.RightBracket}";
|
|
var btn2Text = "no";
|
|
var btn2 = $"{Glyphs.LeftBracket} {btn2Text} {Glyphs.RightBracket}";
|
|
|
|
// We test with one button first, but do this to get the width right for 2
|
|
int width = $@"{Glyphs.VLine} {btn1} {btn2} {Glyphs.VLine}".Length;
|
|
d.SetBufferSize (width, 1);
|
|
|
|
// Override CM
|
|
Dialog.DefaultButtonAlignment = Alignment.Center;
|
|
Dialog.DefaultBorderStyle = LineStyle.Single;
|
|
Dialog.DefaultShadow = ShadowStyle.None;
|
|
Button.DefaultShadow = ShadowStyle.None;
|
|
|
|
// Default (center)
|
|
var dlg = new Dialog
|
|
{
|
|
Title = title,
|
|
Width = width,
|
|
Height = 1,
|
|
ButtonAlignment = Alignment.Center,
|
|
Buttons = [new() { Text = btn1Text }]
|
|
};
|
|
|
|
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
|
|
dlg.Border.Thickness = new (1, 0, 1, 0);
|
|
runstate = Begin (dlg);
|
|
var buttonRow = $"{Glyphs.VLine} {btn1} {Glyphs.VLine}";
|
|
|
|
RunIteration (ref runstate);
|
|
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
|
|
// Now add a second button
|
|
buttonRow = $"{Glyphs.VLine} {btn1} {btn2} {Glyphs.VLine}";
|
|
dlg.AddButton (new () { Text = btn2Text });
|
|
|
|
RunIteration (ref runstate);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Justify
|
|
dlg = new ()
|
|
{
|
|
Title = title,
|
|
Width = width,
|
|
Height = 1,
|
|
ButtonAlignment = Alignment.Fill,
|
|
Buttons = [new() { Text = btn1Text }]
|
|
};
|
|
|
|
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
|
|
dlg.Border.Thickness = new (1, 0, 1, 0);
|
|
runstate = Begin (dlg);
|
|
|
|
RunIteration (ref runstate);
|
|
|
|
buttonRow = $"{Glyphs.VLine}{btn1} {Glyphs.VLine}";
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
|
|
// Now add a second button
|
|
buttonRow = $"{Glyphs.VLine}{btn1} {btn2}{Glyphs.VLine}";
|
|
dlg.AddButton (new () { Text = btn2Text });
|
|
RunIteration (ref runstate);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Right
|
|
dlg = new ()
|
|
{
|
|
Title = title,
|
|
Width = width,
|
|
Height = 1,
|
|
ButtonAlignment = Alignment.End,
|
|
Buttons = [new() { Text = btn1Text }]
|
|
};
|
|
|
|
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
|
|
dlg.Border.Thickness = new (1, 0, 1, 0);
|
|
runstate = Begin (dlg);
|
|
|
|
RunIteration (ref runstate);
|
|
|
|
buttonRow = $"{Glyphs.VLine}{new (' ', width - btn1.Length - 2)}{btn1}{Glyphs.VLine}";
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
|
|
// Now add a second button
|
|
buttonRow = $"{Glyphs.VLine} {btn1} {btn2}{Glyphs.VLine}";
|
|
dlg.AddButton (new () { Text = btn2Text });
|
|
|
|
RunIteration (ref runstate);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Left
|
|
dlg = new ()
|
|
{
|
|
Title = title,
|
|
Width = width,
|
|
Height = 1,
|
|
ButtonAlignment = Alignment.Start,
|
|
Buttons = [new() { Text = btn1Text }]
|
|
};
|
|
|
|
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
|
|
dlg.Border.Thickness = new (1, 0, 1, 0);
|
|
runstate = Begin (dlg);
|
|
RunIteration (ref runstate);
|
|
|
|
buttonRow = $"{Glyphs.VLine}{btn1}{new (' ', width - btn1.Length - 2)}{Glyphs.VLine}";
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
|
|
// Now add a second button
|
|
buttonRow = $"{Glyphs.VLine}{btn1} {btn2} {Glyphs.VLine}";
|
|
dlg.AddButton (new () { Text = btn2Text });
|
|
|
|
RunIteration (ref runstate);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void ButtonAlignment_Four ()
|
|
{
|
|
RunState runstate = null;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
Dialog.DefaultShadow = ShadowStyle.None;
|
|
Button.DefaultShadow = ShadowStyle.None;
|
|
|
|
var title = "1234";
|
|
|
|
// E.g "|[ yes ][ no ][ maybe ]|"
|
|
var btn1Text = "yes";
|
|
var btn1 = $"{Glyphs.LeftBracket} {btn1Text} {Glyphs.RightBracket}";
|
|
var btn2Text = "no";
|
|
var btn2 = $"{Glyphs.LeftBracket} {btn2Text} {Glyphs.RightBracket}";
|
|
var btn3Text = "maybe";
|
|
var btn3 = $"{Glyphs.LeftBracket} {btn3Text} {Glyphs.RightBracket}";
|
|
var btn4Text = "never";
|
|
var btn4 = $"{Glyphs.LeftBracket} {btn4Text} {Glyphs.RightBracket}";
|
|
|
|
var buttonRow = $"{Glyphs.VLine} {btn1} {btn2} {btn3} {btn4} {Glyphs.VLine}";
|
|
int width = buttonRow.Length;
|
|
d.SetBufferSize (buttonRow.Length, 3);
|
|
|
|
// Default - Center
|
|
(runstate, Dialog dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Center,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Justify
|
|
buttonRow = $"{Glyphs.VLine}{btn1} {btn2} {btn3} {btn4}{Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Fill,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Right
|
|
buttonRow = $"{Glyphs.VLine} {btn1} {btn2} {btn3} {btn4}{Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.End,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Left
|
|
buttonRow = $"{Glyphs.VLine}{btn1} {btn2} {btn3} {btn4} {Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Start,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void ButtonAlignment_Four_On_Too_Small_Width ()
|
|
{
|
|
RunState runstate = null;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
Dialog.DefaultShadow = ShadowStyle.None;
|
|
Button.DefaultShadow = ShadowStyle.None;
|
|
|
|
var title = "1234";
|
|
|
|
// E.g "|[ yes ][ no ][ maybe ][ never ]|"
|
|
var btn1Text = "yes";
|
|
var btn1 = $"{Glyphs.LeftBracket} {btn1Text} {Glyphs.RightBracket}";
|
|
var btn2Text = "no";
|
|
var btn2 = $"{Glyphs.LeftBracket} {btn2Text} {Glyphs.RightBracket}";
|
|
var btn3Text = "maybe";
|
|
var btn3 = $"{Glyphs.LeftBracket} {btn3Text} {Glyphs.RightBracket}";
|
|
var btn4Text = "never";
|
|
var btn4 = $"{Glyphs.LeftBracket} {btn4Text} {Glyphs.RightBracket}";
|
|
var buttonRow = string.Empty;
|
|
|
|
var width = 30;
|
|
d.SetBufferSize (width, 1);
|
|
|
|
// Default - Center
|
|
buttonRow =
|
|
$"{Glyphs.VLine} yes {Glyphs.RightBracket}{btn2}{btn3}{Glyphs.LeftBracket} never{Glyphs.VLine}";
|
|
|
|
(runstate, Dialog dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Center,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
Assert.Equal (new (width, 1), dlg.Frame.Size);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Justify
|
|
buttonRow =
|
|
$"{Glyphs.VLine}{Glyphs.LeftBracket} yes {Glyphs.LeftBracket} no {Glyphs.LeftBracket} maybe {Glyphs.LeftBracket} never {Glyphs.RightBracket}{Glyphs.VLine}";
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Fill,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Right
|
|
buttonRow = $"{Glyphs.VLine}es {Glyphs.RightBracket}{btn2}{btn3}{btn4}{Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.End,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Left
|
|
buttonRow = $"{Glyphs.VLine}{btn1}{btn2}{btn3}{Glyphs.LeftBracket} neve{Glyphs.VLine}";
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Start,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void ButtonAlignment_Four_WideOdd ()
|
|
{
|
|
RunState runstate = null;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
Dialog.DefaultShadow = ShadowStyle.None;
|
|
Button.DefaultShadow = ShadowStyle.None;
|
|
|
|
var title = "1234";
|
|
|
|
// E.g "|[ yes ][ no ][ maybe ]|"
|
|
var btn1Text = "really long button 1";
|
|
var btn1 = $"{Glyphs.LeftBracket} {btn1Text} {Glyphs.RightBracket}";
|
|
var btn2Text = "really long button 2";
|
|
var btn2 = $"{Glyphs.LeftBracket} {btn2Text} {Glyphs.RightBracket}";
|
|
var btn3Text = "really long button 3";
|
|
var btn3 = $"{Glyphs.LeftBracket} {btn3Text} {Glyphs.RightBracket}";
|
|
var btn4Text = "really long button 44"; // 44 is intentional to make length different than rest
|
|
var btn4 = $"{Glyphs.LeftBracket} {btn4Text} {Glyphs.RightBracket}";
|
|
|
|
// Note extra spaces to make dialog even wider
|
|
// 123456 1234567
|
|
var buttonRow = $"{Glyphs.VLine} {btn1} {btn2} {btn3} {btn4} {Glyphs.VLine}";
|
|
int width = buttonRow.Length;
|
|
d.SetBufferSize (buttonRow.Length, 1);
|
|
|
|
// Default - Center
|
|
(runstate, Dialog dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Center,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Justify
|
|
buttonRow = $"{Glyphs.VLine}{btn1} {btn2} {btn3} {btn4}{Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Fill,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Right
|
|
buttonRow = $"{Glyphs.VLine} {btn1} {btn2} {btn3} {btn4}{Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.End,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Left
|
|
buttonRow = $"{Glyphs.VLine}{btn1} {btn2} {btn3} {btn4} {Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Start,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void ButtonAlignment_Four_Wider ()
|
|
{
|
|
RunState runstate = null;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
Dialog.DefaultShadow = ShadowStyle.None;
|
|
Button.DefaultShadow = ShadowStyle.None;
|
|
|
|
var title = "1234";
|
|
|
|
// E.g "|[ yes ][ no ][ maybe ]|"
|
|
var btn1Text = "yes";
|
|
var btn1 = $"{Glyphs.LeftBracket} {btn1Text} {Glyphs.RightBracket}";
|
|
var btn2Text = "no";
|
|
var btn2 = $"{Glyphs.LeftBracket} {btn2Text} {Glyphs.RightBracket}";
|
|
var btn3Text = "你你你你你"; // This is a wide char
|
|
var btn3 = $"{Glyphs.LeftBracket} {btn3Text} {Glyphs.RightBracket}";
|
|
|
|
// Requires a Nerd Font
|
|
var btn4Text = "\uE36E\uE36F\uE370\uE371\uE372\uE373";
|
|
var btn4 = $"{Glyphs.LeftBracket} {btn4Text} {Glyphs.RightBracket}";
|
|
|
|
// Note extra spaces to make dialog even wider
|
|
// 123456 123456
|
|
var buttonRow = $"{Glyphs.VLine} {btn1} {btn2} {btn3} {btn4} {Glyphs.VLine}";
|
|
int width = buttonRow.GetColumns ();
|
|
d.SetBufferSize (width, 3);
|
|
|
|
// Default - Center
|
|
(runstate, Dialog dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Center,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Justify
|
|
buttonRow = $"{Glyphs.VLine}{btn1} {btn2} {btn3} {btn4}{Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.GetColumns ());
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Fill,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Right
|
|
buttonRow = $"{Glyphs.VLine} {btn1} {btn2} {btn3} {btn4}{Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.GetColumns ());
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.End,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Left
|
|
buttonRow = $"{Glyphs.VLine}{btn1} {btn2} {btn3} {btn4} {Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.GetColumns ());
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Start,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void ButtonAlignment_One ()
|
|
{
|
|
var d = (FakeDriver)Driver;
|
|
RunState runstate = null;
|
|
Dialog.DefaultShadow = ShadowStyle.None;
|
|
Button.DefaultShadow = ShadowStyle.None;
|
|
|
|
var title = "1234";
|
|
|
|
// E.g "|[ ok ]|"
|
|
var btnText = "ok";
|
|
|
|
var buttonRow =
|
|
$"{Glyphs.VLine} {Glyphs.LeftBracket} {btnText} {Glyphs.RightBracket} {Glyphs.VLine}";
|
|
int width = buttonRow.Length;
|
|
|
|
d.SetBufferSize (width, 1);
|
|
|
|
(runstate, Dialog dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Center,
|
|
new Button { Text = btnText }
|
|
);
|
|
|
|
// Center
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Justify
|
|
buttonRow =
|
|
$"{Glyphs.VLine}{Glyphs.LeftBracket} {btnText} {Glyphs.RightBracket} {Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Fill,
|
|
new Button { Text = btnText }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Right
|
|
buttonRow =
|
|
$"{Glyphs.VLine} {Glyphs.LeftBracket} {btnText} {Glyphs.RightBracket}{Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.End,
|
|
new Button { Text = btnText }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Left
|
|
buttonRow =
|
|
$"{Glyphs.VLine}{Glyphs.LeftBracket} {btnText} {Glyphs.RightBracket} {Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Start,
|
|
new Button { Text = btnText }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Wider
|
|
buttonRow =
|
|
$"{Glyphs.VLine} {Glyphs.LeftBracket} {btnText} {Glyphs.RightBracket} {Glyphs.VLine}";
|
|
width = buttonRow.Length;
|
|
|
|
d.SetBufferSize (width, 1);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Center,
|
|
new Button { Text = btnText }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Justify
|
|
buttonRow =
|
|
$"{Glyphs.VLine}{Glyphs.LeftBracket} {btnText} {Glyphs.RightBracket} {Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Fill,
|
|
new Button { Text = btnText }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Right
|
|
buttonRow =
|
|
$"{Glyphs.VLine} {Glyphs.LeftBracket} {btnText} {Glyphs.RightBracket}{Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.End,
|
|
new Button { Text = btnText }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Left
|
|
buttonRow =
|
|
$"{Glyphs.VLine}{Glyphs.LeftBracket} {btnText} {Glyphs.RightBracket} {Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Start,
|
|
new Button { Text = btnText }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void ButtonAlignment_Three ()
|
|
{
|
|
RunState runstate = null;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
Dialog.DefaultShadow = ShadowStyle.None;
|
|
Button.DefaultShadow = ShadowStyle.None;
|
|
|
|
var title = "1234";
|
|
|
|
// E.g "|[ yes ][ no ][ maybe ]|"
|
|
var btn1Text = "yes";
|
|
var btn1 = $"{Glyphs.LeftBracket} {btn1Text} {Glyphs.RightBracket}";
|
|
var btn2Text = "no";
|
|
var btn2 = $"{Glyphs.LeftBracket} {btn2Text} {Glyphs.RightBracket}";
|
|
var btn3Text = "maybe";
|
|
var btn3 = $"{Glyphs.LeftBracket} {btn3Text} {Glyphs.RightBracket}";
|
|
|
|
var buttonRow = $@"{Glyphs.VLine} {btn1} {btn2} {btn3} {Glyphs.VLine}";
|
|
int width = buttonRow.Length;
|
|
|
|
d.SetBufferSize (buttonRow.Length, 3);
|
|
|
|
(runstate, Dialog dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Center,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Justify
|
|
buttonRow = $@"{Glyphs.VLine}{btn1} {btn2} {btn3}{Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Fill,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Right
|
|
buttonRow = $@"{Glyphs.VLine} {btn1} {btn2} {btn3}{Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.End,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Left
|
|
buttonRow = $@"{Glyphs.VLine}{btn1} {btn2} {btn3} {Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Start,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void ButtonAlignment_Two ()
|
|
{
|
|
RunState runstate = null;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
Dialog.DefaultShadow = ShadowStyle.None;
|
|
Button.DefaultShadow = ShadowStyle.None;
|
|
|
|
var title = "1234";
|
|
|
|
// E.g "|[ yes ][ no ]|"
|
|
var btn1Text = "yes";
|
|
var btn1 = $"{Glyphs.LeftBracket} {btn1Text} {Glyphs.RightBracket}";
|
|
var btn2Text = "no";
|
|
var btn2 = $"{Glyphs.LeftBracket} {btn2Text} {Glyphs.RightBracket}";
|
|
|
|
var buttonRow = $@"{Glyphs.VLine} {btn1} {btn2} {Glyphs.VLine}";
|
|
int width = buttonRow.Length;
|
|
|
|
d.SetBufferSize (buttonRow.Length, 3);
|
|
|
|
(runstate, Dialog dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Center,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Justify
|
|
buttonRow = $@"{Glyphs.VLine}{btn1} {btn2}{Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Fill,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Right
|
|
buttonRow = $@"{Glyphs.VLine} {btn1} {btn2}{Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.End,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Left
|
|
buttonRow = $@"{Glyphs.VLine}{btn1} {btn2} {Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Start,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void ButtonAlignment_Two_Hidden ()
|
|
{
|
|
RunState runstate = null;
|
|
var firstIteration = false;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
Dialog.DefaultShadow = ShadowStyle.None;
|
|
Button.DefaultShadow = ShadowStyle.None;
|
|
|
|
var title = "1234";
|
|
|
|
// E.g "|[ yes ][ no ]|"
|
|
var btn1Text = "yes";
|
|
var btn1 = $"{Glyphs.LeftBracket} {btn1Text} {Glyphs.RightBracket}";
|
|
var btn2Text = "no";
|
|
var btn2 = $"{Glyphs.LeftBracket} {btn2Text} {Glyphs.RightBracket}";
|
|
|
|
var buttonRow = $@"{Glyphs.VLine} {btn1} {btn2} {Glyphs.VLine}";
|
|
int width = buttonRow.Length;
|
|
|
|
d.SetBufferSize (buttonRow.Length, 3);
|
|
|
|
Dialog dlg = null;
|
|
Button button1, button2;
|
|
|
|
// Default (Center)
|
|
button1 = new() { Text = btn1Text };
|
|
button2 = new() { Text = btn2Text };
|
|
(runstate, dlg) = BeginButtonTestDialog (title, width, Alignment.Center, button1, button2);
|
|
button1.Visible = false;
|
|
RunIteration (ref runstate, firstIteration);
|
|
buttonRow = $@"{Glyphs.VLine} {btn2} {Glyphs.VLine}";
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Justify
|
|
Assert.Equal (width, buttonRow.Length);
|
|
button1 = new() { Text = btn1Text };
|
|
button2 = new() { Text = btn2Text };
|
|
(runstate, dlg) = BeginButtonTestDialog (title, width, Alignment.Fill, button1, button2);
|
|
button1.Visible = false;
|
|
RunIteration (ref runstate, firstIteration);
|
|
buttonRow = $@"{Glyphs.VLine} {btn2}{Glyphs.VLine}";
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Right
|
|
Assert.Equal (width, buttonRow.Length);
|
|
button1 = new() { Text = btn1Text };
|
|
button2 = new() { Text = btn2Text };
|
|
(runstate, dlg) = BeginButtonTestDialog (title, width, Alignment.End, button1, button2);
|
|
button1.Visible = false;
|
|
RunIteration (ref runstate, firstIteration);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
|
|
// Left
|
|
Assert.Equal (width, buttonRow.Length);
|
|
button1 = new() { Text = btn1Text };
|
|
button2 = new() { Text = btn2Text };
|
|
(runstate, dlg) = BeginButtonTestDialog (title, width, Alignment.Start, button1, button2);
|
|
button1.Visible = false;
|
|
RunIteration (ref runstate, firstIteration);
|
|
buttonRow = $@"{Glyphs.VLine} {btn2} {Glyphs.VLine}";
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Dialog_In_Window_With_Size_One_Button_Aligns ()
|
|
{
|
|
((FakeDriver)Driver).SetBufferSize (20, 5);
|
|
|
|
// Override CM
|
|
Window.DefaultBorderStyle = LineStyle.Single;
|
|
Dialog.DefaultButtonAlignment = Alignment.Center;
|
|
Dialog.DefaultBorderStyle = LineStyle.Single;
|
|
Dialog.DefaultShadow = ShadowStyle.None;
|
|
Button.DefaultShadow = ShadowStyle.None;
|
|
|
|
var win = new Window ();
|
|
|
|
var iterations = 0;
|
|
|
|
Iteration += (s, a) =>
|
|
{
|
|
if (++iterations > 2)
|
|
{
|
|
RequestStop ();
|
|
}
|
|
};
|
|
var btn = $"{Glyphs.LeftBracket} Ok {Glyphs.RightBracket}";
|
|
|
|
win.Loaded += (s, a) =>
|
|
{
|
|
var dlg = new Dialog { Width = 18, Height = 3, Buttons = [new () { Text = "Ok" }] };
|
|
|
|
dlg.Loaded += (s, a) =>
|
|
{
|
|
LayoutAndDraw ();
|
|
|
|
var expected = @$"
|
|
┌──────────────────┐
|
|
│┌────────────────┐│
|
|
││ {btn} ││
|
|
│└────────────────┘│
|
|
└──────────────────┘";
|
|
_ = DriverAssert.AssertDriverContentsWithFrameAre (expected, _output);
|
|
};
|
|
|
|
Run (dlg);
|
|
dlg.Dispose ();
|
|
};
|
|
Run (win);
|
|
win.Dispose ();
|
|
}
|
|
|
|
[Theory]
|
|
[AutoInitShutdown]
|
|
[InlineData (
|
|
5,
|
|
@"
|
|
┌┌───────────────┐─┐
|
|
││ │ │
|
|
││ ⟦ Ok ⟧ │ │
|
|
│└───────────────┘ │
|
|
└──────────────────┘"
|
|
)]
|
|
[InlineData (
|
|
6,
|
|
@"
|
|
┌┌───────────────┐─┐
|
|
││ │ │
|
|
││ │ │
|
|
││ ⟦ Ok ⟧ │ │
|
|
│└───────────────┘ │
|
|
└──────────────────┘"
|
|
)]
|
|
[InlineData (
|
|
7,
|
|
@"
|
|
┌──────────────────┐
|
|
│┌───────────────┐ │
|
|
││ │ │
|
|
││ │ │
|
|
││ ⟦ Ok ⟧ │ │
|
|
│└───────────────┘ │
|
|
└──────────────────┘"
|
|
)]
|
|
[InlineData (
|
|
8,
|
|
@"
|
|
┌──────────────────┐
|
|
│┌───────────────┐ │
|
|
││ │ │
|
|
││ │ │
|
|
││ │ │
|
|
││ ⟦ Ok ⟧ │ │
|
|
│└───────────────┘ │
|
|
└──────────────────┘"
|
|
)]
|
|
[InlineData (
|
|
9,
|
|
@"
|
|
┌──────────────────┐
|
|
│┌───────────────┐ │
|
|
││ │ │
|
|
││ │ │
|
|
││ │ │
|
|
││ │ │
|
|
││ ⟦ Ok ⟧ │ │
|
|
│└───────────────┘ │
|
|
└──────────────────┘"
|
|
)]
|
|
public void Dialog_In_Window_Without_Size_One_Button_Aligns (int height, string expected)
|
|
{
|
|
((FakeDriver)Driver).SetBufferSize (20, height);
|
|
var win = new Window ();
|
|
|
|
int iterations = -1;
|
|
|
|
// Override CM
|
|
Dialog.DefaultButtonAlignment = Alignment.Center;
|
|
Dialog.DefaultBorderStyle = LineStyle.Single;
|
|
Dialog.DefaultShadow = ShadowStyle.None;
|
|
Button.DefaultShadow = ShadowStyle.None;
|
|
|
|
Iteration += (s, a) =>
|
|
{
|
|
iterations++;
|
|
|
|
if (iterations == 0)
|
|
{
|
|
var dlg = new Dialog
|
|
{
|
|
Buttons = [new () { Text = "Ok" }],
|
|
Width = Dim.Percent (85),
|
|
Height = Dim.Percent (85)
|
|
};
|
|
Run (dlg);
|
|
dlg.Dispose ();
|
|
}
|
|
else if (iterations == 1)
|
|
{
|
|
LayoutAndDraw ();
|
|
|
|
// BUGBUG: This seems wrong; is it a bug in Dim.Percent(85)?? No
|
|
_ = DriverAssert.AssertDriverContentsWithFrameAre (expected, _output);
|
|
}
|
|
else
|
|
{
|
|
RequestStop ();
|
|
}
|
|
};
|
|
|
|
Run (win);
|
|
win.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Dialog_Opened_From_Another_Dialog ()
|
|
{
|
|
((FakeDriver)Driver).SetBufferSize (30, 10);
|
|
|
|
// Override CM
|
|
Dialog.DefaultButtonAlignment = Alignment.Center;
|
|
Dialog.DefaultBorderStyle = LineStyle.Single;
|
|
Dialog.DefaultShadow = ShadowStyle.None;
|
|
Button.DefaultShadow = ShadowStyle.None;
|
|
|
|
var btn1 = new Button { Text = "press me 1" };
|
|
Button btn2 = null;
|
|
Button btn3 = null;
|
|
string expected = null;
|
|
|
|
btn1.Accepting += (s, e) =>
|
|
{
|
|
btn2 = new () { Text = "Show Sub" };
|
|
btn3 = new () { Text = "Close" };
|
|
btn3.Accepting += (s, e) => RequestStop ();
|
|
|
|
btn2.Accepting += (s, e) =>
|
|
{
|
|
// Don't test MessageBox in Dialog unit tests!
|
|
var subBtn = new Button { Text = "Ok", IsDefault = true };
|
|
var subDlg = new Dialog { Text = "ya", Width = 20, Height = 5, Buttons = [subBtn] };
|
|
subBtn.Accepting += (s, e) => RequestStop (subDlg);
|
|
Run (subDlg);
|
|
};
|
|
|
|
var dlg = new Dialog
|
|
{
|
|
Buttons = [btn2, btn3],
|
|
Width = Dim.Percent (85),
|
|
Height = Dim.Percent (85)
|
|
};
|
|
|
|
Run (dlg);
|
|
dlg.Dispose ();
|
|
};
|
|
|
|
var btn =
|
|
$"{Glyphs.LeftBracket}{Glyphs.LeftDefaultIndicator} Ok {Glyphs.RightDefaultIndicator}{Glyphs.RightBracket}";
|
|
|
|
int iterations = -1;
|
|
|
|
Iteration += (s, a) =>
|
|
{
|
|
iterations++;
|
|
|
|
switch (iterations)
|
|
{
|
|
case 0:
|
|
Top.SetNeedsLayout();
|
|
Top.SetNeedsDraw();
|
|
LayoutAndDraw ();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
Assert.False (btn1.NewKeyDownEvent (Key.Space));
|
|
|
|
break;
|
|
case 2:
|
|
LayoutAndDraw ();
|
|
|
|
expected = @$"
|
|
┌───────────────────────┐
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│{Glyphs.LeftBracket} Show Sub {Glyphs.RightBracket} {Glyphs.LeftBracket} Close {Glyphs.RightBracket} │
|
|
└───────────────────────┘";
|
|
DriverAssert.AssertDriverContentsWithFrameAre (expected, _output);
|
|
|
|
Assert.False (btn2.NewKeyDownEvent (Key.Space));
|
|
|
|
break;
|
|
case 3:
|
|
LayoutAndDraw ();
|
|
|
|
DriverAssert.AssertDriverContentsWithFrameAre (
|
|
@$"
|
|
┌───────────────────────┐
|
|
│ ┌──────────────────┐ │
|
|
│ │ya │ │
|
|
│ │ │ │
|
|
│ │ {btn} │ │
|
|
│ └──────────────────┘ │
|
|
│{Glyphs.LeftBracket} Show Sub {Glyphs.RightBracket} {Glyphs.LeftBracket} Close {Glyphs.RightBracket} │
|
|
└───────────────────────┘",
|
|
_output
|
|
);
|
|
|
|
Assert.False (Top.NewKeyDownEvent (Key.Enter));
|
|
|
|
break;
|
|
case 4:
|
|
LayoutAndDraw ();
|
|
|
|
DriverAssert.AssertDriverContentsWithFrameAre (expected, _output);
|
|
|
|
Assert.False (btn3.NewKeyDownEvent (Key.Space));
|
|
|
|
break;
|
|
case 5:
|
|
DriverAssert.AssertDriverContentsWithFrameAre ("", _output);
|
|
|
|
RequestStop ();
|
|
|
|
break;
|
|
}
|
|
};
|
|
|
|
Run ().Dispose ();
|
|
Shutdown ();
|
|
|
|
Assert.Equal (5, iterations);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void FileDialog_FileSystemWatcher ()
|
|
{
|
|
for (var i = 0; i < 8; i++)
|
|
{
|
|
var fd = new FileDialog ();
|
|
fd.Ready += (s, e) => RequestStop ();
|
|
Run (fd);
|
|
fd.Dispose ();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Location_Default ()
|
|
{
|
|
var d = new Dialog
|
|
{
|
|
Width = Dim.Percent (85),
|
|
Height = Dim.Percent (85)
|
|
};
|
|
Begin (d);
|
|
((FakeDriver)Driver).SetBufferSize (100, 100);
|
|
|
|
// Default location is centered, so 100 / 2 - 85 / 2 = 7
|
|
var expected = 7;
|
|
Assert.Equal (new (expected, expected), d.Frame.Location);
|
|
d.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Location_Not_Default ()
|
|
{
|
|
var d = new Dialog { X = 1, Y = 1 };
|
|
Begin (d);
|
|
((FakeDriver)Driver).SetBufferSize (100, 100);
|
|
|
|
// Default location is centered, so 100 / 2 - 85 / 2 = 7
|
|
var expected = 1;
|
|
Assert.Equal (new (expected, expected), d.Frame.Location);
|
|
d.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Location_When_Application_Top_Not_Default ()
|
|
{
|
|
// Override CM
|
|
Window.DefaultBorderStyle = LineStyle.Single;
|
|
Dialog.DefaultButtonAlignment = Alignment.Center;
|
|
Dialog.DefaultBorderStyle = LineStyle.Single;
|
|
Dialog.DefaultShadow = ShadowStyle.None;
|
|
Button.DefaultShadow = ShadowStyle.None;
|
|
|
|
var expected = 5;
|
|
var d = new Dialog { X = expected, Y = expected, Height = 5, Width = 5 };
|
|
Begin (d);
|
|
((FakeDriver)Driver).SetBufferSize (20, 10);
|
|
|
|
// Default location is centered, so 100 / 2 - 85 / 2 = 7
|
|
Assert.Equal (new (expected, expected), d.Frame.Location);
|
|
|
|
DriverAssert.AssertDriverContentsWithFrameAre (
|
|
@"
|
|
┌───┐
|
|
│ │
|
|
│ │
|
|
│ │
|
|
└───┘",
|
|
_output
|
|
);
|
|
d.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void One_Button_Works ()
|
|
{
|
|
RunState runstate = null;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
|
|
Button.DefaultShadow = ShadowStyle.None;
|
|
|
|
var title = "";
|
|
var btnText = "ok";
|
|
|
|
var buttonRow =
|
|
$"{Glyphs.VLine} {Glyphs.LeftBracket} {btnText} {Glyphs.RightBracket} {Glyphs.VLine}";
|
|
|
|
int width = buttonRow.Length;
|
|
d.SetBufferSize (buttonRow.Length, 10);
|
|
|
|
(runstate, Dialog dlg) = BeginButtonTestDialog (
|
|
title,
|
|
width,
|
|
Alignment.Center,
|
|
new Button { Text = btnText }
|
|
);
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Size_Default ()
|
|
{
|
|
var d = new Dialog
|
|
{
|
|
Width = Dim.Percent (85),
|
|
Height = Dim.Percent (85)
|
|
};
|
|
|
|
Begin (d);
|
|
((FakeDriver)Driver).SetBufferSize (100, 100);
|
|
|
|
// Default size is Percent(85)
|
|
Assert.Equal (new ((int)(100 * .85), (int)(100 * .85)), d.Frame.Size);
|
|
d.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Size_Not_Default ()
|
|
{
|
|
Dialog.DefaultShadow = ShadowStyle.None;
|
|
Button.DefaultShadow = ShadowStyle.None;
|
|
var d = new Dialog { Width = 50, Height = 50 };
|
|
|
|
Begin (d);
|
|
((FakeDriver)Driver).SetBufferSize (100, 100);
|
|
|
|
// Default size is Percent(85)
|
|
Assert.Equal (new (50, 50), d.Frame.Size);
|
|
d.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[SetupFakeDriver]
|
|
public void Zero_Buttons_Works ()
|
|
{
|
|
RunState runstate = null;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
|
|
var title = "1234";
|
|
|
|
var buttonRow = $"{Glyphs.VLine} {Glyphs.VLine}";
|
|
int width = buttonRow.Length;
|
|
d.SetBufferSize (buttonRow.Length, 3);
|
|
|
|
(runstate, Dialog dlg) = BeginButtonTestDialog (title, width, Alignment.Center, null);
|
|
|
|
DriverAssert.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
|
|
End (runstate);
|
|
dlg.Dispose ();
|
|
}
|
|
|
|
private (RunState, Dialog) BeginButtonTestDialog (
|
|
string title,
|
|
int width,
|
|
Alignment align,
|
|
params Button [] btns
|
|
)
|
|
{
|
|
// Override CM
|
|
Dialog.DefaultButtonAlignment = Alignment.Center;
|
|
Dialog.DefaultBorderStyle = LineStyle.Single;
|
|
Dialog.DefaultShadow = ShadowStyle.None;
|
|
Button.DefaultShadow = ShadowStyle.None;
|
|
|
|
var dlg = new Dialog
|
|
{
|
|
Title = title,
|
|
X = 0,
|
|
Y = 0,
|
|
Width = width,
|
|
Height = 1,
|
|
ButtonAlignment = align,
|
|
Buttons = btns
|
|
};
|
|
|
|
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
|
|
dlg.Border.Thickness = new (1, 0, 1, 0);
|
|
|
|
RunState runState = Begin (dlg);
|
|
|
|
dlg.SetNeedsDraw();
|
|
dlg.SetNeedsLayout ();
|
|
dlg.Layout ();
|
|
dlg.Draw ();
|
|
|
|
return (runState, dlg);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Run_Does_Not_Dispose_Dialog ()
|
|
{
|
|
var top = new Toplevel ();
|
|
|
|
Dialog dlg = new ();
|
|
|
|
dlg.Ready += Dlg_Ready;
|
|
|
|
Run (dlg);
|
|
|
|
#if DEBUG_IDISPOSABLE
|
|
Assert.False (dlg.WasDisposed);
|
|
Assert.False (Top.WasDisposed);
|
|
Assert.NotEqual (top, Top);
|
|
Assert.Equal (dlg, Top);
|
|
#endif
|
|
|
|
// dlg wasn't disposed yet and it's possible to access to his properties
|
|
Assert.False (dlg.Canceled);
|
|
Assert.NotNull (dlg);
|
|
|
|
dlg.Canceled = true;
|
|
Assert.True (dlg.Canceled);
|
|
|
|
dlg.Dispose ();
|
|
top.Dispose ();
|
|
#if DEBUG_IDISPOSABLE
|
|
Assert.True (dlg.WasDisposed);
|
|
Assert.True (Top.WasDisposed);
|
|
Assert.NotNull (Top);
|
|
#endif
|
|
Shutdown ();
|
|
Assert.Null (Top);
|
|
|
|
return;
|
|
|
|
void Dlg_Ready (object sender, EventArgs e) { RequestStop (); }
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Can_Access_Cancel_Property_After_Run ()
|
|
{
|
|
Dialog dlg = new ();
|
|
|
|
dlg.Ready += Dlg_Ready;
|
|
|
|
Run (dlg);
|
|
|
|
#if DEBUG_IDISPOSABLE
|
|
Assert.False (dlg.WasDisposed);
|
|
Assert.False (Top.WasDisposed);
|
|
Assert.Equal (dlg, Top);
|
|
#endif
|
|
|
|
Assert.True (dlg.Canceled);
|
|
|
|
// Run it again is possible because it isn't disposed yet
|
|
Run (dlg);
|
|
|
|
// Run another view without dispose the prior will throw an assertion
|
|
#if DEBUG_IDISPOSABLE
|
|
Dialog dlg2 = new ();
|
|
dlg2.Ready += Dlg_Ready;
|
|
Exception exception = Record.Exception (() => Run (dlg2));
|
|
Assert.NotNull (exception);
|
|
|
|
dlg.Dispose ();
|
|
|
|
// Now it's possible to tun dlg2 without throw
|
|
Run (dlg2);
|
|
|
|
Assert.True (dlg.WasDisposed);
|
|
Assert.False (Top.WasDisposed);
|
|
Assert.Equal (dlg2, Top);
|
|
Assert.False (dlg2.WasDisposed);
|
|
|
|
dlg2.Dispose ();
|
|
|
|
// Now an assertion will throw accessing the Canceled property
|
|
exception = Record.Exception (() => Assert.True (dlg.Canceled));
|
|
Assert.NotNull (exception);
|
|
Assert.True (Top.WasDisposed);
|
|
Shutdown ();
|
|
Assert.True (dlg2.WasDisposed);
|
|
Assert.Null (Top);
|
|
#endif
|
|
|
|
return;
|
|
|
|
void Dlg_Ready (object sender, EventArgs e)
|
|
{
|
|
((Dialog)sender).Canceled = true;
|
|
RequestStop ();
|
|
}
|
|
}
|
|
}
|