mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
Robustness improvements in prep for implementing Virtual Terminal Sequences (#3094)
* Fixes #2616. Support combining sequences that don't normalize * Decouples Application from ConsoleDriver in TestHelpers * Updates driver tests to match new arch * Start on making all driver tests test all drivers * Improves handling if combining marks. * Fix unit tests fails. * Fix unit tests fails. * Handling combining mask. * Tying to fix this unit test that sometimes fail. * Add support for combining mask on NetDriver. * Enable CombiningMarks as List<Rune>. * Prevents combining marks on invalid runes default and space. * Formatting for CI tests. * Fix non-normalized combining mark to add 1 to Col. * Reformatting for retest the CI. * Forces non-normalized CMs to be ignored. * Initial experiment * Created ANSiDriver. Updated UI Catalog command line handling * Fixed ForceDriver logic * Fixed ForceDriver logic * Updating P/Invoke * Force16 colors WIP * Fixed 16 colo mode * Updated unit tests * UI catalog tweak * Added chinese scenario from bdisp * Disabled AnsiDriver unit tests for now. * Code cleanup * Initial commit (fork from v2_fixes_2610_WT_VTS) * Code cleanup * Removed nativemethods.txt * Removed not needed native stuff * Code cleanup * Ensures command line handler doesn't eat exceptions --------- Co-authored-by: BDisp <bd.bdisp@gmail.com>
This commit is contained in:
@@ -7,20 +7,22 @@ using Xunit.Abstractions;
|
||||
// Alias Console to MockConsole so we don't accidentally use Console
|
||||
|
||||
namespace Terminal.Gui.DriverTests;
|
||||
|
||||
public class AddRuneTests {
|
||||
readonly ITestOutputHelper _output;
|
||||
|
||||
public AddRuneTests (ITestOutputHelper output)
|
||||
{
|
||||
ConsoleDriver.RunningUnitTests = true;
|
||||
this._output = output;
|
||||
_output = output;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
//[InlineData (typeof (ANSIDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void AddRune (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
@@ -44,8 +46,8 @@ public class AddRuneTests {
|
||||
driver.Move (driver.Cols, driver.Rows);
|
||||
driver.AddRune ('a');
|
||||
|
||||
for (var col = 0; col < driver.Cols; col++) {
|
||||
for (var row = 0; row < driver.Rows; row++) {
|
||||
for (int col = 0; col < driver.Cols; col++) {
|
||||
for (int row = 0; row < driver.Rows; row++) {
|
||||
Assert.Equal ((Rune)' ', driver.Contents [row, col].Rune);
|
||||
}
|
||||
}
|
||||
@@ -70,7 +72,7 @@ public class AddRuneTests {
|
||||
Assert.Equal (2, driver.Col);
|
||||
|
||||
// Move to the last column of the first row
|
||||
var lastCol = driver.Cols - 1;
|
||||
int lastCol = driver.Cols - 1;
|
||||
driver.Move (lastCol, 0);
|
||||
Assert.Equal (0, driver.Row);
|
||||
Assert.Equal (lastCol, driver.Col);
|
||||
@@ -83,8 +85,8 @@ public class AddRuneTests {
|
||||
// Add a rune; should succeed but do nothing as it's outside of Contents
|
||||
driver.AddRune ('d');
|
||||
Assert.Equal (lastCol + 2, driver.Col);
|
||||
for (var col = 0; col < driver.Cols; col++) {
|
||||
for (var row = 0; row < driver.Rows; row++) {
|
||||
for (int col = 0; col < driver.Cols; col++) {
|
||||
for (int row = 0; row < driver.Rows; row++) {
|
||||
Assert.NotEqual ((Rune)'d', driver.Contents [row, col].Rune);
|
||||
}
|
||||
}
|
||||
@@ -99,7 +101,7 @@ public class AddRuneTests {
|
||||
driver.Init ();
|
||||
|
||||
// 🍕 Slice of Pizza "\U0001F355"
|
||||
var operationStatus = Rune.DecodeFromUtf16 ("\U0001F355", out Rune rune, out int charsConsumed);
|
||||
var operationStatus = Rune.DecodeFromUtf16 ("\U0001F355", out var rune, out int charsConsumed);
|
||||
Assert.Equal (OperationStatus.Done, operationStatus);
|
||||
Assert.Equal (charsConsumed, rune.Utf16SequenceLength);
|
||||
Assert.Equal (2, rune.GetColumns ());
|
||||
@@ -145,7 +147,7 @@ public class AddRuneTests {
|
||||
|
||||
var expected = new Rune ('ắ');
|
||||
|
||||
var text = "\u1eaf";
|
||||
string text = "\u1eaf";
|
||||
driver.AddStr (text);
|
||||
Assert.Equal (expected, driver.Contents [0, 0].Rune);
|
||||
Assert.Equal ((Rune)' ', driver.Contents [0, 1].Rune);
|
||||
@@ -188,4 +190,4 @@ public class AddRuneTests {
|
||||
//ắ", output);
|
||||
driver.End ();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,108 +9,125 @@ using Xunit.Abstractions;
|
||||
// Alias Console to MockConsole so we don't accidentally use Console
|
||||
using Console = Terminal.Gui.FakeConsole;
|
||||
|
||||
namespace Terminal.Gui.DriverTests {
|
||||
public class ClipRegionTests {
|
||||
readonly ITestOutputHelper output;
|
||||
namespace Terminal.Gui.DriverTests;
|
||||
|
||||
public ClipRegionTests (ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
public void IsValidLocation (Type driverType)
|
||||
{
|
||||
var driver = (FakeDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
public class ClipRegionTests {
|
||||
readonly ITestOutputHelper output;
|
||||
|
||||
// positive
|
||||
Assert.True (driver.IsValidLocation (0, 0));
|
||||
Assert.True (driver.IsValidLocation (1, 1));
|
||||
Assert.True (driver.IsValidLocation (driver.Cols - 1, driver.Rows - 1));
|
||||
// negative
|
||||
Assert.False (driver.IsValidLocation (-1, 0));
|
||||
Assert.False (driver.IsValidLocation (0, -1));
|
||||
Assert.False (driver.IsValidLocation (-1, -1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows - 1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows - 1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows));
|
||||
|
||||
// Define a clip rectangle
|
||||
driver.Clip = new Rect (5, 5, 5, 5);
|
||||
// positive
|
||||
Assert.True (driver.IsValidLocation (5, 5));
|
||||
Assert.True (driver.IsValidLocation (9, 9));
|
||||
// negative
|
||||
Assert.False (driver.IsValidLocation (4, 5));
|
||||
Assert.False (driver.IsValidLocation (5, 4));
|
||||
Assert.False (driver.IsValidLocation (10, 9));
|
||||
Assert.False (driver.IsValidLocation (9, 10));
|
||||
Assert.False (driver.IsValidLocation (-1, 0));
|
||||
Assert.False (driver.IsValidLocation (0, -1));
|
||||
Assert.False (driver.IsValidLocation (-1, -1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows - 1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows - 1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows));
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
public void Clip_Set_To_Empty_AllInvalid (Type driverType)
|
||||
{
|
||||
var driver = (FakeDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
// Define a clip rectangle
|
||||
driver.Clip = Rect.Empty;
|
||||
|
||||
// negative
|
||||
Assert.False (driver.IsValidLocation (4, 5));
|
||||
Assert.False (driver.IsValidLocation (5, 4));
|
||||
Assert.False (driver.IsValidLocation (10, 9));
|
||||
Assert.False (driver.IsValidLocation (9, 10));
|
||||
Assert.False (driver.IsValidLocation (-1, 0));
|
||||
Assert.False (driver.IsValidLocation (0, -1));
|
||||
Assert.False (driver.IsValidLocation (-1, -1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows - 1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows - 1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows));
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
public void AddRune_Is_Clipped (Type driverType)
|
||||
{
|
||||
var driver = (FakeDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
driver.Move (0, 0);
|
||||
driver.AddRune ('x');
|
||||
Assert.Equal ((Rune)'x', driver.Contents [0, 0].Rune);
|
||||
|
||||
driver.Move (5, 5);
|
||||
driver.AddRune ('x');
|
||||
Assert.Equal ((Rune)'x', driver.Contents [5, 5].Rune);
|
||||
|
||||
// Clear the contents
|
||||
driver.FillRect (new Rect (0, 0, driver.Rows, driver.Cols), ' ');
|
||||
Assert.Equal ((Rune)' ', driver.Contents [0, 0].Rune);
|
||||
|
||||
// Setup the region with a single rectangle, fill screen with 'x'
|
||||
driver.Clip = new Rect (5, 5, 5, 5);
|
||||
driver.FillRect (new Rect (0, 0, driver.Rows, driver.Cols), 'x');
|
||||
Assert.Equal ((Rune)' ', driver.Contents [0, 0].Rune);
|
||||
Assert.Equal ((Rune)' ', driver.Contents [4, 9].Rune);
|
||||
Assert.Equal ((Rune)'x', driver.Contents [5, 5].Rune);
|
||||
Assert.Equal ((Rune)'x', driver.Contents [9, 9].Rune);
|
||||
Assert.Equal ((Rune)' ', driver.Contents [10, 10].Rune);
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
public ClipRegionTests (ITestOutputHelper output)
|
||||
{
|
||||
ConsoleDriver.RunningUnitTests = true;
|
||||
this.output = output;
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
//[InlineData (typeof (ANSIDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void IsValidLocation (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
Application.Driver.Rows = 10;
|
||||
Application.Driver.Cols = 10;
|
||||
|
||||
// positive
|
||||
Assert.True (driver.IsValidLocation (0, 0));
|
||||
Assert.True (driver.IsValidLocation (1, 1));
|
||||
Assert.True (driver.IsValidLocation (driver.Cols - 1, driver.Rows - 1));
|
||||
// negative
|
||||
Assert.False (driver.IsValidLocation (-1, 0));
|
||||
Assert.False (driver.IsValidLocation (0, -1));
|
||||
Assert.False (driver.IsValidLocation (-1, -1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows - 1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows - 1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows));
|
||||
|
||||
// Define a clip rectangle
|
||||
driver.Clip = new Rect (5, 5, 5, 5);
|
||||
// positive
|
||||
Assert.True (driver.IsValidLocation (5, 5));
|
||||
Assert.True (driver.IsValidLocation (9, 9));
|
||||
// negative
|
||||
Assert.False (driver.IsValidLocation (4, 5));
|
||||
Assert.False (driver.IsValidLocation (5, 4));
|
||||
Assert.False (driver.IsValidLocation (10, 9));
|
||||
Assert.False (driver.IsValidLocation (9, 10));
|
||||
Assert.False (driver.IsValidLocation (-1, 0));
|
||||
Assert.False (driver.IsValidLocation (0, -1));
|
||||
Assert.False (driver.IsValidLocation (-1, -1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows - 1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows - 1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows));
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
//[InlineData (typeof (ANSIDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void Clip_Set_To_Empty_AllInvalid (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
// Define a clip rectangle
|
||||
driver.Clip = Rect.Empty;
|
||||
|
||||
// negative
|
||||
Assert.False (driver.IsValidLocation (4, 5));
|
||||
Assert.False (driver.IsValidLocation (5, 4));
|
||||
Assert.False (driver.IsValidLocation (10, 9));
|
||||
Assert.False (driver.IsValidLocation (9, 10));
|
||||
Assert.False (driver.IsValidLocation (-1, 0));
|
||||
Assert.False (driver.IsValidLocation (0, -1));
|
||||
Assert.False (driver.IsValidLocation (-1, -1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows - 1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows - 1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows));
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
//[InlineData (typeof (ANSIDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void AddRune_Is_Clipped (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
Application.Driver.Rows = 25;
|
||||
Application.Driver.Cols = 80;
|
||||
|
||||
driver.Move (0, 0);
|
||||
driver.AddRune ('x');
|
||||
Assert.Equal ((Rune)'x', driver.Contents [0, 0].Rune);
|
||||
|
||||
driver.Move (5, 5);
|
||||
driver.AddRune ('x');
|
||||
Assert.Equal ((Rune)'x', driver.Contents [5, 5].Rune);
|
||||
|
||||
// Clear the contents
|
||||
driver.FillRect (new Rect (0, 0, driver.Rows, driver.Cols), ' ');
|
||||
Assert.Equal ((Rune)' ', driver.Contents [0, 0].Rune);
|
||||
|
||||
// Setup the region with a single rectangle, fill screen with 'x'
|
||||
driver.Clip = new Rect (5, 5, 5, 5);
|
||||
driver.FillRect (new Rect (0, 0, driver.Rows, driver.Cols), 'x');
|
||||
Assert.Equal ((Rune)' ', driver.Contents [0, 0].Rune);
|
||||
Assert.Equal ((Rune)' ', driver.Contents [4, 9].Rune);
|
||||
Assert.Equal ((Rune)'x', driver.Contents [5, 5].Rune);
|
||||
Assert.Equal ((Rune)'x', driver.Contents [9, 9].Rune);
|
||||
Assert.Equal ((Rune)' ', driver.Contents [10, 10].Rune);
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
}
|
||||
@@ -8,264 +8,271 @@ using Xunit.Abstractions;
|
||||
// Alias Console to MockConsole so we don't accidentally use Console
|
||||
using Console = Terminal.Gui.FakeConsole;
|
||||
|
||||
namespace Terminal.Gui.DriverTests {
|
||||
public class ConsoleDriverTests {
|
||||
readonly ITestOutputHelper output;
|
||||
namespace Terminal.Gui.DriverTests;
|
||||
|
||||
public ConsoleDriverTests (ITestOutputHelper output)
|
||||
{
|
||||
ConsoleDriver.RunningUnitTests = true;
|
||||
this.output = output;
|
||||
}
|
||||
public class ConsoleDriverTests {
|
||||
readonly ITestOutputHelper output;
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
public void Init_Inits (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var ml = driver.Init ();
|
||||
Assert.NotNull (ml);
|
||||
Assert.NotNull (driver.Clipboard);
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Assert.Equal (ConsoleColor.Red, Console.ForegroundColor);
|
||||
Console.BackgroundColor = ConsoleColor.Green;
|
||||
Assert.Equal (ConsoleColor.Green, Console.BackgroundColor);
|
||||
|
||||
driver.End ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
public void End_Cleans_Up (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
driver.End ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
public void FakeDriver_Only_Sends_Keystrokes_Through_MockKeyPresses (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
var top = Application.Top;
|
||||
var view = new View () {
|
||||
CanFocus = true
|
||||
};
|
||||
var count = 0;
|
||||
var wasKeyPressed = false;
|
||||
|
||||
view.KeyDown += (s, e) => {
|
||||
wasKeyPressed = true;
|
||||
};
|
||||
top.Add (view);
|
||||
|
||||
Application.Iteration += (s, a) => {
|
||||
count++;
|
||||
if (count == 10) Application.RequestStop ();
|
||||
};
|
||||
|
||||
Application.Run ();
|
||||
|
||||
Assert.False (wasKeyPressed);
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
public void FakeDriver_MockKeyPresses (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
var text = "MockKeyPresses";
|
||||
var mKeys = new Stack<ConsoleKeyInfo> ();
|
||||
foreach (var r in text.Reverse ()) {
|
||||
var ck = char.IsLetter (r) ? (ConsoleKey)char.ToUpper (r) : (ConsoleKey)r;
|
||||
var cki = new ConsoleKeyInfo (r, ck, false, false, false);
|
||||
mKeys.Push (cki);
|
||||
}
|
||||
Console.MockKeyPresses = mKeys;
|
||||
|
||||
var top = Application.Top;
|
||||
var view = new View () {
|
||||
CanFocus = true
|
||||
};
|
||||
var rText = "";
|
||||
var idx = 0;
|
||||
|
||||
view.KeyDown += (s, e) => {
|
||||
Assert.Equal (text [idx], (char)e.KeyCode);
|
||||
rText += (char)e.KeyCode;
|
||||
Assert.Equal (rText, text.Substring (0, idx + 1));
|
||||
e.Handled = true;
|
||||
idx++;
|
||||
};
|
||||
top.Add (view);
|
||||
|
||||
Application.Iteration += (s, a) => {
|
||||
if (mKeys.Count == 0) Application.RequestStop ();
|
||||
};
|
||||
|
||||
Application.Run ();
|
||||
|
||||
Assert.Equal ("MockKeyPresses", rText);
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
//[Theory]
|
||||
//[InlineData (typeof (FakeDriver))]
|
||||
//public void FakeDriver_MockKeyPresses_Press_AfterTimeOut (Type driverType)
|
||||
//{
|
||||
// var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
// Application.Init (driver);
|
||||
|
||||
// // Simulating pressing of QuitKey after a short period of time
|
||||
// uint quitTime = 100;
|
||||
// Func<MainLoop, bool> closeCallback = (MainLoop loop) => {
|
||||
// // Prove the scenario is using Application.QuitKey correctly
|
||||
// output.WriteLine ($" {quitTime}ms elapsed; Simulating keypresses...");
|
||||
// FakeConsole.PushMockKeyPress (Key.F);
|
||||
// FakeConsole.PushMockKeyPress (Key.U);
|
||||
// FakeConsole.PushMockKeyPress (Key.C);
|
||||
// FakeConsole.PushMockKeyPress (Key.K);
|
||||
// return false;
|
||||
// };
|
||||
// output.WriteLine ($"Add timeout to simulate key presses after {quitTime}ms");
|
||||
// _ = Application.AddTimeout (TimeSpan.FromMilliseconds (quitTime), closeCallback);
|
||||
|
||||
// // If Top doesn't quit within abortTime * 5 (500ms), this will force it
|
||||
// uint abortTime = quitTime * 5;
|
||||
// Func<MainLoop, bool> forceCloseCallback = (MainLoop loop) => {
|
||||
// Application.RequestStop ();
|
||||
// Assert.Fail ($" failed to Quit after {abortTime}ms. Force quit.");
|
||||
// return false;
|
||||
// };
|
||||
// output.WriteLine ($"Add timeout to force quit after {abortTime}ms");
|
||||
// _ = Application.AddTimeout (TimeSpan.FromMilliseconds (abortTime), forceCloseCallback);
|
||||
|
||||
// Key key = Key.Unknown;
|
||||
|
||||
// Application.Top.KeyPress += (e) => {
|
||||
// key = e.Key;
|
||||
// output.WriteLine ($" Application.Top.KeyPress: {key}");
|
||||
// e.Handled = true;
|
||||
|
||||
// };
|
||||
|
||||
// int iterations = 0;
|
||||
// Application.Iteration += (s, a) => {
|
||||
// output.WriteLine ($" iteration {++iterations}");
|
||||
|
||||
// if (Console.MockKeyPresses.Count == 0) {
|
||||
// output.WriteLine ($" No more MockKeyPresses; RequestStop");
|
||||
// Application.RequestStop ();
|
||||
// }
|
||||
// };
|
||||
|
||||
// Application.Run ();
|
||||
|
||||
// // Shutdown must be called to safely clean up Application if Init has been called
|
||||
// Application.Shutdown ();
|
||||
//}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
public void TerminalResized_Simulation (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver?.Init ();
|
||||
driver.Cols = 80;
|
||||
driver.Rows = 25;
|
||||
|
||||
var wasTerminalResized = false;
|
||||
driver.SizeChanged += (s, e) => {
|
||||
wasTerminalResized = true;
|
||||
Assert.Equal (120, e.Size.Width);
|
||||
Assert.Equal (40, e.Size.Height);
|
||||
};
|
||||
|
||||
Assert.Equal (80, driver.Cols);
|
||||
Assert.Equal (25, driver.Rows);
|
||||
Assert.False (wasTerminalResized);
|
||||
|
||||
driver.Cols = 120;
|
||||
driver.Rows = 40;
|
||||
driver.OnSizeChanged (new SizeChangedEventArgs(new Size(driver.Cols, driver.Rows)));
|
||||
Assert.Equal (120, driver.Cols);
|
||||
Assert.Equal (40, driver.Rows);
|
||||
Assert.True (wasTerminalResized);
|
||||
driver.End ();
|
||||
}
|
||||
|
||||
// Disabled due to test error - Change Task.Delay to an await
|
||||
// [Fact, AutoInitShutdown]
|
||||
// public void Write_Do_Not_Change_On_ProcessKey ()
|
||||
// {
|
||||
// var win = new Window ();
|
||||
// Application.Begin (win);
|
||||
// ((FakeDriver)Application.Driver).SetBufferSize (20, 8);
|
||||
|
||||
// System.Threading.Tasks.Task.Run (() => {
|
||||
// System.Threading.Tasks.Task.Delay (500).Wait ();
|
||||
// Application.Invoke (() => {
|
||||
// var lbl = new Label ("Hello World") { X = Pos.Center () };
|
||||
// var dlg = new Dialog ();
|
||||
// dlg.Add (lbl);
|
||||
// Application.Begin (dlg);
|
||||
|
||||
// var expected = @"
|
||||
//┌──────────────────┐
|
||||
//│┌───────────────┐ │
|
||||
//││ Hello World │ │
|
||||
//││ │ │
|
||||
//││ │ │
|
||||
//││ │ │
|
||||
//│└───────────────┘ │
|
||||
//└──────────────────┘
|
||||
//";
|
||||
|
||||
// var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
||||
// Assert.Equal (new Rect (0, 0, 20, 8), pos);
|
||||
|
||||
// Assert.True (dlg.ProcessKey (new (Key.Tab)));
|
||||
// dlg.Draw ();
|
||||
|
||||
// expected = @"
|
||||
//┌──────────────────┐
|
||||
//│┌───────────────┐ │
|
||||
//││ Hello World │ │
|
||||
//││ │ │
|
||||
//││ │ │
|
||||
//││ │ │
|
||||
//│└───────────────┘ │
|
||||
//└──────────────────┘
|
||||
//";
|
||||
|
||||
// pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
||||
// Assert.Equal (new Rect (0, 0, 20, 8), pos);
|
||||
|
||||
// win.RequestStop ();
|
||||
// });
|
||||
// });
|
||||
|
||||
// Application.Run (win);
|
||||
// Application.Shutdown ();
|
||||
// }
|
||||
public ConsoleDriverTests (ITestOutputHelper output)
|
||||
{
|
||||
ConsoleDriver.RunningUnitTests = true;
|
||||
this.output = output;
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
//[InlineData (typeof (ANSIDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void Init_Inits (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var ml = driver.Init ();
|
||||
Assert.NotNull (ml);
|
||||
Assert.NotNull (driver.Clipboard);
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Assert.Equal (ConsoleColor.Red, Console.ForegroundColor);
|
||||
Console.BackgroundColor = ConsoleColor.Green;
|
||||
Assert.Equal (ConsoleColor.Green, Console.BackgroundColor);
|
||||
|
||||
driver.End ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
//[InlineData (typeof (ANSIDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void End_Cleans_Up (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
driver.End ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
public void FakeDriver_Only_Sends_Keystrokes_Through_MockKeyPresses (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
var top = Application.Top;
|
||||
var view = new View () {
|
||||
CanFocus = true
|
||||
};
|
||||
int count = 0;
|
||||
bool wasKeyPressed = false;
|
||||
|
||||
view.KeyDown += (s, e) => {
|
||||
wasKeyPressed = true;
|
||||
};
|
||||
top.Add (view);
|
||||
|
||||
Application.Iteration += (s, a) => {
|
||||
count++;
|
||||
if (count == 10) {
|
||||
Application.RequestStop ();
|
||||
}
|
||||
};
|
||||
|
||||
Application.Run ();
|
||||
|
||||
Assert.False (wasKeyPressed);
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
public void FakeDriver_MockKeyPresses (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
string text = "MockKeyPresses";
|
||||
var mKeys = new Stack<ConsoleKeyInfo> ();
|
||||
foreach (char r in text.Reverse ()) {
|
||||
var ck = char.IsLetter (r) ? (ConsoleKey)char.ToUpper (r) : (ConsoleKey)r;
|
||||
var cki = new ConsoleKeyInfo (r, ck, false, false, false);
|
||||
mKeys.Push (cki);
|
||||
}
|
||||
Console.MockKeyPresses = mKeys;
|
||||
|
||||
var top = Application.Top;
|
||||
var view = new View () {
|
||||
CanFocus = true
|
||||
};
|
||||
string rText = "";
|
||||
int idx = 0;
|
||||
|
||||
view.KeyDown += (s, e) => {
|
||||
Assert.Equal (text [idx], (char)e.KeyCode);
|
||||
rText += (char)e.KeyCode;
|
||||
Assert.Equal (rText, text.Substring (0, idx + 1));
|
||||
e.Handled = true;
|
||||
idx++;
|
||||
};
|
||||
top.Add (view);
|
||||
|
||||
Application.Iteration += (s, a) => {
|
||||
if (mKeys.Count == 0) {
|
||||
Application.RequestStop ();
|
||||
}
|
||||
};
|
||||
|
||||
Application.Run ();
|
||||
|
||||
Assert.Equal ("MockKeyPresses", rText);
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
//[Theory]
|
||||
//[InlineData (typeof (FakeDriver))]
|
||||
//public void FakeDriver_MockKeyPresses_Press_AfterTimeOut (Type driverType)
|
||||
//{
|
||||
// var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
// Application.Init (driver);
|
||||
|
||||
// // Simulating pressing of QuitKey after a short period of time
|
||||
// uint quitTime = 100;
|
||||
// Func<MainLoop, bool> closeCallback = (MainLoop loop) => {
|
||||
// // Prove the scenario is using Application.QuitKey correctly
|
||||
// output.WriteLine ($" {quitTime}ms elapsed; Simulating keypresses...");
|
||||
// FakeConsole.PushMockKeyPress (Key.F);
|
||||
// FakeConsole.PushMockKeyPress (Key.U);
|
||||
// FakeConsole.PushMockKeyPress (Key.C);
|
||||
// FakeConsole.PushMockKeyPress (Key.K);
|
||||
// return false;
|
||||
// };
|
||||
// output.WriteLine ($"Add timeout to simulate key presses after {quitTime}ms");
|
||||
// _ = Application.AddTimeout (TimeSpan.FromMilliseconds (quitTime), closeCallback);
|
||||
|
||||
// // If Top doesn't quit within abortTime * 5 (500ms), this will force it
|
||||
// uint abortTime = quitTime * 5;
|
||||
// Func<MainLoop, bool> forceCloseCallback = (MainLoop loop) => {
|
||||
// Application.RequestStop ();
|
||||
// Assert.Fail ($" failed to Quit after {abortTime}ms. Force quit.");
|
||||
// return false;
|
||||
// };
|
||||
// output.WriteLine ($"Add timeout to force quit after {abortTime}ms");
|
||||
// _ = Application.AddTimeout (TimeSpan.FromMilliseconds (abortTime), forceCloseCallback);
|
||||
|
||||
// Key key = Key.Unknown;
|
||||
|
||||
// Application.Top.KeyPress += (e) => {
|
||||
// key = e.Key;
|
||||
// output.WriteLine ($" Application.Top.KeyPress: {key}");
|
||||
// e.Handled = true;
|
||||
|
||||
// };
|
||||
|
||||
// int iterations = 0;
|
||||
// Application.Iteration += (s, a) => {
|
||||
// output.WriteLine ($" iteration {++iterations}");
|
||||
|
||||
// if (Console.MockKeyPresses.Count == 0) {
|
||||
// output.WriteLine ($" No more MockKeyPresses; RequestStop");
|
||||
// Application.RequestStop ();
|
||||
// }
|
||||
// };
|
||||
|
||||
// Application.Run ();
|
||||
|
||||
// // Shutdown must be called to safely clean up Application if Init has been called
|
||||
// Application.Shutdown ();
|
||||
//}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
//[InlineData (typeof (ANSIDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void TerminalResized_Simulation (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver?.Init ();
|
||||
driver.Cols = 80;
|
||||
driver.Rows = 25;
|
||||
|
||||
bool wasTerminalResized = false;
|
||||
driver.SizeChanged += (s, e) => {
|
||||
wasTerminalResized = true;
|
||||
Assert.Equal (120, e.Size.Width);
|
||||
Assert.Equal (40, e.Size.Height);
|
||||
};
|
||||
|
||||
Assert.Equal (80, driver.Cols);
|
||||
Assert.Equal (25, driver.Rows);
|
||||
Assert.False (wasTerminalResized);
|
||||
|
||||
driver.Cols = 120;
|
||||
driver.Rows = 40;
|
||||
driver.OnSizeChanged (new SizeChangedEventArgs (new Size (driver.Cols, driver.Rows)));
|
||||
Assert.Equal (120, driver.Cols);
|
||||
Assert.Equal (40, driver.Rows);
|
||||
Assert.True (wasTerminalResized);
|
||||
driver.End ();
|
||||
}
|
||||
|
||||
// Disabled due to test error - Change Task.Delay to an await
|
||||
// [Fact, AutoInitShutdown]
|
||||
// public void Write_Do_Not_Change_On_ProcessKey ()
|
||||
// {
|
||||
// var win = new Window ();
|
||||
// Application.Begin (win);
|
||||
// ((FakeDriver)Application.Driver).SetBufferSize (20, 8);
|
||||
|
||||
// System.Threading.Tasks.Task.Run (() => {
|
||||
// System.Threading.Tasks.Task.Delay (500).Wait ();
|
||||
// Application.Invoke (() => {
|
||||
// var lbl = new Label ("Hello World") { X = Pos.Center () };
|
||||
// var dlg = new Dialog ();
|
||||
// dlg.Add (lbl);
|
||||
// Application.Begin (dlg);
|
||||
|
||||
// var expected = @"
|
||||
//┌──────────────────┐
|
||||
//│┌───────────────┐ │
|
||||
//││ Hello World │ │
|
||||
//││ │ │
|
||||
//││ │ │
|
||||
//││ │ │
|
||||
//│└───────────────┘ │
|
||||
//└──────────────────┘
|
||||
//";
|
||||
|
||||
// var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
||||
// Assert.Equal (new Rect (0, 0, 20, 8), pos);
|
||||
|
||||
// Assert.True (dlg.ProcessKey (new (Key.Tab)));
|
||||
// dlg.Draw ();
|
||||
|
||||
// expected = @"
|
||||
//┌──────────────────┐
|
||||
//│┌───────────────┐ │
|
||||
//││ Hello World │ │
|
||||
//││ │ │
|
||||
//││ │ │
|
||||
//││ │ │
|
||||
//│└───────────────┘ │
|
||||
//└──────────────────┘
|
||||
//";
|
||||
|
||||
// pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
||||
// Assert.Equal (new Rect (0, 0, 20, 8), pos);
|
||||
|
||||
// win.RequestStop ();
|
||||
// });
|
||||
// });
|
||||
|
||||
// Application.Run (win);
|
||||
// Application.Shutdown ();
|
||||
// }
|
||||
}
|
||||
@@ -8,31 +8,35 @@ using Xunit.Abstractions;
|
||||
// Alias Console to MockConsole so we don't accidentally use Console
|
||||
using Console = Terminal.Gui.FakeConsole;
|
||||
|
||||
namespace Terminal.Gui.DriverTests {
|
||||
public class ConsoleScrollingTests {
|
||||
readonly ITestOutputHelper output;
|
||||
namespace Terminal.Gui.DriverTests;
|
||||
|
||||
public ConsoleScrollingTests (ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
}
|
||||
public class ConsoleScrollingTests {
|
||||
readonly ITestOutputHelper output;
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
public void Left_And_Top_Is_Always_Zero (Type driverType)
|
||||
{
|
||||
var driver = (FakeDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
Assert.Equal (0, Console.WindowLeft);
|
||||
Assert.Equal (0, Console.WindowTop);
|
||||
|
||||
driver.SetWindowPosition (5, 5);
|
||||
Assert.Equal (0, Console.WindowLeft);
|
||||
Assert.Equal (0, Console.WindowTop);
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
public ConsoleScrollingTests (ITestOutputHelper output)
|
||||
{
|
||||
ConsoleDriver.RunningUnitTests = true;
|
||||
this.output = output;
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
//[InlineData (typeof (NetDriver))]
|
||||
//[InlineData (typeof (ANSIDriver))]
|
||||
//[InlineData (typeof (WindowsDriver))]
|
||||
//[InlineData (typeof (CursesDriver))]
|
||||
public void Left_And_Top_Is_Always_Zero (Type driverType)
|
||||
{
|
||||
var driver = (FakeDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
Assert.Equal (0, Console.WindowLeft);
|
||||
Assert.Equal (0, Console.WindowTop);
|
||||
|
||||
driver.SetWindowPosition (5, 5);
|
||||
Assert.Equal (0, Console.WindowLeft);
|
||||
Assert.Equal (0, Console.WindowTop);
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ using Xunit.Abstractions;
|
||||
using Console = Terminal.Gui.FakeConsole;
|
||||
|
||||
namespace Terminal.Gui.DriverTests;
|
||||
|
||||
public class ContentsTests {
|
||||
readonly ITestOutputHelper output;
|
||||
|
||||
@@ -23,13 +24,14 @@ public class ContentsTests {
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
//[InlineData (typeof (ANSIDriver))]
|
||||
//[InlineData (typeof (CursesDriver))] // TODO: Uncomment when #2796 and #2615 are fixed
|
||||
//[InlineData (typeof (WindowsDriver))] // TODO: Uncomment when #2610 is fixed
|
||||
public void AddStr_Combining_Character_1st_Column (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
var expected = "\u0301!";
|
||||
string expected = "\u0301!";
|
||||
driver.AddStr ("\u0301!"); // acute accent + exclamation mark
|
||||
TestHelpers.AssertDriverContentsAre (expected, output, driver);
|
||||
|
||||
@@ -39,6 +41,7 @@ public class ContentsTests {
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
//[InlineData (typeof (ANSIDriver))]
|
||||
//[InlineData (typeof (CursesDriver))] // TODO: Uncomment when #2796 and #2615 are fixed
|
||||
//[InlineData (typeof (WindowsDriver))] // TODO: Uncomment when #2610 is fixed
|
||||
public void AddStr_With_Combining_Characters (Type driverType)
|
||||
@@ -46,18 +49,18 @@ public class ContentsTests {
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
|
||||
var acuteaccent = new System.Text.Rune (0x0301); // Combining acute accent (é)
|
||||
var combined = "e" + acuteaccent;
|
||||
var expected = "é";
|
||||
var acuteaccent = new Rune (0x0301); // Combining acute accent (é)
|
||||
string combined = "e" + acuteaccent;
|
||||
string expected = "é";
|
||||
|
||||
driver.AddStr (combined);
|
||||
TestHelpers.AssertDriverContentsAre (expected, output, driver);
|
||||
|
||||
// 3 char combine
|
||||
// a + ogonek + acute = <U+0061, U+0328, U+0301> ( ą́ )
|
||||
var ogonek = new System.Text.Rune (0x0328); // Combining ogonek (a small hook or comma shape)
|
||||
var ogonek = new Rune (0x0328); // Combining ogonek (a small hook or comma shape)
|
||||
combined = "a" + ogonek + acuteaccent;
|
||||
expected = ("a" + ogonek).Normalize(NormalizationForm.FormC); // See Issue #2616
|
||||
expected = ("a" + ogonek).Normalize (NormalizationForm.FormC); // See Issue #2616
|
||||
|
||||
driver.Move (0, 0);
|
||||
driver.AddStr (combined);
|
||||
@@ -93,8 +96,9 @@ public class ContentsTests {
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
//[InlineData (typeof (ANSIDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void Move_Bad_Coordinates (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
@@ -160,5 +164,4 @@ public class ContentsTests {
|
||||
// Refresh works correctly
|
||||
|
||||
// IsDirty tests
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,69 +4,69 @@ using Xunit;
|
||||
// Alias Console to MockConsole so we don't accidentally use Console
|
||||
using Console = Terminal.Gui.FakeConsole;
|
||||
|
||||
namespace Terminal.Gui.DriverTests {
|
||||
public class DriverColorTests {
|
||||
public DriverColorTests ()
|
||||
{
|
||||
ConsoleDriver.RunningUnitTests = true;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
public void SetColors_Changes_Colors (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
namespace Terminal.Gui.DriverTests;
|
||||
|
||||
Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
|
||||
Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);
|
||||
public class DriverColorTests {
|
||||
public DriverColorTests () => ConsoleDriver.RunningUnitTests = true;
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Assert.Equal (ConsoleColor.Red, Console.ForegroundColor);
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
//[InlineData (typeof (ANSIDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void SetColors_Changes_Colors (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
|
||||
Console.BackgroundColor = ConsoleColor.Green;
|
||||
Assert.Equal (ConsoleColor.Green, Console.BackgroundColor);
|
||||
Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
|
||||
Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);
|
||||
|
||||
Console.ResetColor ();
|
||||
Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
|
||||
Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Assert.Equal (ConsoleColor.Red, Console.ForegroundColor);
|
||||
|
||||
driver.End ();
|
||||
}
|
||||
Console.BackgroundColor = ConsoleColor.Green;
|
||||
Assert.Equal (ConsoleColor.Green, Console.BackgroundColor);
|
||||
|
||||
Console.ResetColor ();
|
||||
Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
|
||||
Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);
|
||||
|
||||
driver.End ();
|
||||
}
|
||||
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver), false)]
|
||||
[InlineData (typeof (NetDriver), true)]
|
||||
[InlineData (typeof (CursesDriver), false)]
|
||||
[InlineData (typeof (WindowsDriver), true)] // Because we're not Windows Terminal
|
||||
public void SupportsTrueColor_Defaults (Type driverType, bool expectedSetting)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver), false)]
|
||||
[InlineData (typeof (NetDriver), true)]
|
||||
//[InlineData (typeof (ANSIDriver), true)]
|
||||
[InlineData (typeof (WindowsDriver), true)]
|
||||
[InlineData (typeof (CursesDriver), false)]
|
||||
public void SupportsTrueColor_Defaults (Type driverType, bool expectedSetting)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
|
||||
Assert.Equal (expectedSetting, driver.SupportsTrueColor);
|
||||
Assert.Equal (expectedSetting, driver.SupportsTrueColor);
|
||||
|
||||
driver.End ();
|
||||
}
|
||||
driver.End ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
public void Force16Colors_Sets (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
//[InlineData (typeof (ANSIDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void Force16Colors_Sets (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
|
||||
driver.Force16Colors = true;
|
||||
Assert.True (driver.Force16Colors);
|
||||
driver.Force16Colors = true;
|
||||
Assert.True (driver.Force16Colors);
|
||||
|
||||
driver.End ();
|
||||
}
|
||||
driver.End ();
|
||||
}
|
||||
}
|
||||
@@ -12,17 +12,14 @@ using Console = Terminal.Gui.FakeConsole;
|
||||
namespace Terminal.Gui.DriverTests;
|
||||
|
||||
public class MainLoopDriverTests {
|
||||
|
||||
public MainLoopDriverTests (ITestOutputHelper output)
|
||||
{
|
||||
ConsoleDriver.RunningUnitTests = true;
|
||||
}
|
||||
public MainLoopDriverTests (ITestOutputHelper output) => ConsoleDriver.RunningUnitTests = true;
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver), typeof (FakeMainLoop))]
|
||||
[InlineData (typeof (NetDriver), typeof (NetMainLoop))]
|
||||
[InlineData (typeof (CursesDriver), typeof (UnixMainLoop))]
|
||||
[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
||||
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
||||
public void MainLoop_Constructs_Disposes (Type driverType, Type mainLoopDriverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
@@ -45,20 +42,21 @@ public class MainLoopDriverTests {
|
||||
Assert.Empty (mainLoop.Timeouts);
|
||||
Assert.False (mainLoop.Running);
|
||||
}
|
||||
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver), typeof (FakeMainLoop))]
|
||||
[InlineData (typeof (NetDriver), typeof (NetMainLoop))]
|
||||
[InlineData (typeof (CursesDriver), typeof (UnixMainLoop))]
|
||||
[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
||||
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
||||
public void MainLoop_AddTimeout_ValidParameters_ReturnsToken (Type driverType, Type mainLoopDriverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, new object [] { driver });
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
var callbackInvoked = false;
|
||||
bool callbackInvoked = false;
|
||||
|
||||
var token = mainLoop.AddTimeout (TimeSpan.FromMilliseconds (100), () => {
|
||||
object token = mainLoop.AddTimeout (TimeSpan.FromMilliseconds (100), () => {
|
||||
callbackInvoked = true;
|
||||
return false;
|
||||
});
|
||||
@@ -77,14 +75,15 @@ public class MainLoopDriverTests {
|
||||
[InlineData (typeof (NetDriver), typeof (NetMainLoop))]
|
||||
[InlineData (typeof (CursesDriver), typeof (UnixMainLoop))]
|
||||
[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
||||
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
||||
public void MainLoop_RemoveTimeout_ValidToken_ReturnsTrue (Type driverType, Type mainLoopDriverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, new object [] { driver });
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
|
||||
var token = mainLoop.AddTimeout (TimeSpan.FromMilliseconds (100), () => false);
|
||||
var result = mainLoop.RemoveTimeout (token);
|
||||
object token = mainLoop.AddTimeout (TimeSpan.FromMilliseconds (100), () => false);
|
||||
bool result = mainLoop.RemoveTimeout (token);
|
||||
|
||||
Assert.True (result);
|
||||
mainLoop.Dispose ();
|
||||
@@ -95,13 +94,14 @@ public class MainLoopDriverTests {
|
||||
[InlineData (typeof (NetDriver), typeof (NetMainLoop))]
|
||||
[InlineData (typeof (CursesDriver), typeof (UnixMainLoop))]
|
||||
[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
||||
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
||||
public void MainLoop_RemoveTimeout_InvalidToken_ReturnsFalse (Type driverType, Type mainLoopDriverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, new object [] { driver });
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
|
||||
var result = mainLoop.RemoveTimeout (new object ());
|
||||
bool result = mainLoop.RemoveTimeout (new object ());
|
||||
|
||||
Assert.False (result);
|
||||
}
|
||||
@@ -111,12 +111,13 @@ public class MainLoopDriverTests {
|
||||
[InlineData (typeof (NetDriver), typeof (NetMainLoop))]
|
||||
[InlineData (typeof (CursesDriver), typeof (UnixMainLoop))]
|
||||
[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
||||
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
||||
public void MainLoop_AddIdle_ValidIdleHandler_ReturnsToken (Type driverType, Type mainLoopDriverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, new object [] { driver });
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
var idleHandlerInvoked = false;
|
||||
bool idleHandlerInvoked = false;
|
||||
|
||||
bool IdleHandler ()
|
||||
{
|
||||
@@ -124,7 +125,7 @@ public class MainLoopDriverTests {
|
||||
return false;
|
||||
}
|
||||
|
||||
Func<bool> token = mainLoop.AddIdle (IdleHandler);
|
||||
var token = mainLoop.AddIdle (IdleHandler);
|
||||
|
||||
Assert.NotNull (token);
|
||||
Assert.False (idleHandlerInvoked); // Idle handler should not be invoked immediately
|
||||
@@ -138,6 +139,7 @@ public class MainLoopDriverTests {
|
||||
[InlineData (typeof (NetDriver), typeof (NetMainLoop))]
|
||||
[InlineData (typeof (CursesDriver), typeof (UnixMainLoop))]
|
||||
[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
||||
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
||||
public void MainLoop_RemoveIdle_ValidToken_ReturnsTrue (Type driverType, Type mainLoopDriverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
@@ -145,8 +147,8 @@ public class MainLoopDriverTests {
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
|
||||
bool IdleHandler () => false;
|
||||
Func<bool> token = mainLoop.AddIdle (IdleHandler);
|
||||
var result = mainLoop.RemoveIdle (token);
|
||||
var token = mainLoop.AddIdle (IdleHandler);
|
||||
bool result = mainLoop.RemoveIdle (token);
|
||||
|
||||
Assert.True (result);
|
||||
mainLoop.Dispose ();
|
||||
@@ -157,13 +159,14 @@ public class MainLoopDriverTests {
|
||||
[InlineData (typeof (NetDriver), typeof (NetMainLoop))]
|
||||
[InlineData (typeof (CursesDriver), typeof (UnixMainLoop))]
|
||||
[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
||||
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
||||
public void MainLoop_RemoveIdle_InvalidToken_ReturnsFalse (Type driverType, Type mainLoopDriverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, new object [] { driver });
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
|
||||
var result = mainLoop.RemoveIdle (() => false);
|
||||
bool result = mainLoop.RemoveIdle (() => false);
|
||||
|
||||
Assert.False (result);
|
||||
mainLoop.Dispose ();
|
||||
@@ -174,14 +177,15 @@ public class MainLoopDriverTests {
|
||||
[InlineData (typeof (NetDriver), typeof (NetMainLoop))]
|
||||
[InlineData (typeof (CursesDriver), typeof (UnixMainLoop))]
|
||||
[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
||||
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
||||
public void MainLoop_RunIteration_ValidIdleHandler_CallsIdleHandler (Type driverType, Type mainLoopDriverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, new object [] { driver });
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
var idleHandlerInvoked = false;
|
||||
bool idleHandlerInvoked = false;
|
||||
|
||||
Func<bool> idleHandler = () => {
|
||||
var idleHandler = () => {
|
||||
idleHandlerInvoked = true;
|
||||
return false;
|
||||
};
|
||||
@@ -198,13 +202,14 @@ public class MainLoopDriverTests {
|
||||
[InlineData (typeof (NetDriver), typeof (NetMainLoop))]
|
||||
[InlineData (typeof (CursesDriver), typeof (UnixMainLoop))]
|
||||
[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
||||
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
||||
public void MainLoop_CheckTimersAndIdleHandlers_NoTimersOrIdleHandlers_ReturnsFalse (Type driverType, Type mainLoopDriverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, new object [] { driver });
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
|
||||
var result = mainLoop.CheckTimersAndIdleHandlers (out var waitTimeout);
|
||||
bool result = mainLoop.CheckTimersAndIdleHandlers (out int waitTimeout);
|
||||
|
||||
Assert.False (result);
|
||||
Assert.Equal (-1, waitTimeout);
|
||||
@@ -216,6 +221,7 @@ public class MainLoopDriverTests {
|
||||
[InlineData (typeof (NetDriver), typeof (NetMainLoop))]
|
||||
[InlineData (typeof (CursesDriver), typeof (UnixMainLoop))]
|
||||
[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
||||
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
||||
public void MainLoop_CheckTimersAndIdleHandlers_TimersActive_ReturnsTrue (Type driverType, Type mainLoopDriverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
@@ -223,7 +229,7 @@ public class MainLoopDriverTests {
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
|
||||
mainLoop.AddTimeout (TimeSpan.FromMilliseconds (100), () => false);
|
||||
var result = mainLoop.CheckTimersAndIdleHandlers (out var waitTimeout);
|
||||
bool result = mainLoop.CheckTimersAndIdleHandlers (out int waitTimeout);
|
||||
|
||||
Assert.True (result);
|
||||
Assert.True (waitTimeout >= 0);
|
||||
@@ -235,6 +241,7 @@ public class MainLoopDriverTests {
|
||||
[InlineData (typeof (NetDriver), typeof (NetMainLoop))]
|
||||
[InlineData (typeof (CursesDriver), typeof (UnixMainLoop))]
|
||||
[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
||||
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
||||
public void MainLoop_CheckTimersAndIdleHandlers_IdleHandlersActive_ReturnsTrue (Type driverType, Type mainLoopDriverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
@@ -242,7 +249,7 @@ public class MainLoopDriverTests {
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
|
||||
mainLoop.AddIdle (() => false);
|
||||
var result = mainLoop.CheckTimersAndIdleHandlers (out var waitTimeout);
|
||||
bool result = mainLoop.CheckTimersAndIdleHandlers (out int waitTimeout);
|
||||
|
||||
Assert.True (result);
|
||||
Assert.Equal (-1, waitTimeout);
|
||||
@@ -267,4 +274,4 @@ public class MainLoopDriverTests {
|
||||
// Assert.True (actionInvoked);
|
||||
// mainLoop.Dispose ();
|
||||
//}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user