diff --git a/Terminal.Gui/ConsoleDrivers/V2/NetInputProcessor.cs b/Terminal.Gui/ConsoleDrivers/V2/NetInputProcessor.cs index e507c97f6..0cc188322 100644 --- a/Terminal.Gui/ConsoleDrivers/V2/NetInputProcessor.cs +++ b/Terminal.Gui/ConsoleDrivers/V2/NetInputProcessor.cs @@ -16,7 +16,7 @@ public class NetInputProcessor : InputProcessor /// to input stream. /// /// - public static bool GenerateTestCasesForKeyPresses = false; + public static bool GenerateTestCasesForKeyPresses = true; #pragma warning restore CA2211 /// diff --git a/TerminalGuiFluentTesting/ClassDiagram1.cd b/TerminalGuiFluentTesting/ClassDiagram1.cd index 81442de09..d7e0263c6 100644 --- a/TerminalGuiFluentTesting/ClassDiagram1.cd +++ b/TerminalGuiFluentTesting/ClassDiagram1.cd @@ -24,7 +24,7 @@ - + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= FakeWindowsInput.cs @@ -39,13 +39,13 @@ - + - ABJAAAIAACBAAQAAgYAAAAAgABIEgAQAIAAIBACAIgA= + ABJAAAIAACBACQAAg4AAAAAgAJIEgAQAKACIBACAIgI= GuiTestContext.cs @@ -55,5 +55,21 @@ + + + + AAAAAIAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= + TextWriterLoggerProvider.cs + + + + + + + AAAAAAAAAAAAAAAAAAEAAAAAAAgAAAAAAAAIAAAAAAA= + TextWriterLogger.cs + + + \ No newline at end of file diff --git a/TerminalGuiFluentTesting/GuiTestContext.cs b/TerminalGuiFluentTesting/GuiTestContext.cs index c425e0426..8678df507 100644 --- a/TerminalGuiFluentTesting/GuiTestContext.cs +++ b/TerminalGuiFluentTesting/GuiTestContext.cs @@ -16,12 +16,14 @@ public class GuiTestContext : IDisposable private readonly FakeNetInput _netInput; private View? _lastView; private readonly StringBuilder _logsSb; + private readonly V2TestDriver _driver; - internal GuiTestContext (Func topLevelBuilder, int width, int height) + internal GuiTestContext (Func topLevelBuilder, int width, int height, V2TestDriver driver) { IApplication origApp = ApplicationImpl.Instance; ILogger? origLogger = Logging.Logger; _logsSb = new (); + _driver = driver; _netInput = new (_cts.Token); _winInput = new (_cts.Token); @@ -51,7 +53,7 @@ public class GuiTestContext : IDisposable .CreateLogger ("Test Logging"); Logging.Logger = logger; - v2.Init (null, "v2win"); + v2.Init (null, GetDriverName()); booting.Release (); @@ -84,6 +86,17 @@ public class GuiTestContext : IDisposable WaitIteration (); } + private string GetDriverName () + { + return _driver switch + { + V2TestDriver.V2Win => "v2win", + V2TestDriver.V2Net => "v2net", + _ => + throw new ArgumentOutOfRangeException () + }; + } + /// /// Stops the application and waits for the background thread to exit. /// @@ -212,6 +225,8 @@ public class GuiTestContext : IDisposable private GuiTestContext Click (WindowsConsole.ButtonState btn, int screenX, int screenY) { + // TODO: Support net style ansi escape sequence generation for arrow keys + _winInput.InputBuffer.Enqueue ( new () { @@ -241,11 +256,25 @@ public class GuiTestContext : IDisposable public GuiTestContext Down () { - SendWindowsKey (ConsoleKeyMapping.VK.DOWN); + switch (_driver) + { + case V2TestDriver.V2Win: + SendWindowsKey (ConsoleKeyMapping.VK.DOWN); + break; + case V2TestDriver.V2Net: + // TODO: Support ansi sequence + + throw new NotImplementedException ("Coming soon"); + break; + default: + throw new ArgumentOutOfRangeException (); + } + return this; } + public GuiTestContext Right () { SendWindowsKey (ConsoleKeyMapping.VK.RIGHT); @@ -269,15 +298,25 @@ public class GuiTestContext : IDisposable public GuiTestContext Enter () { - SendWindowsKey ( - new WindowsConsole.KeyEventRecord - { - UnicodeChar = '\r', - dwControlKeyState = WindowsConsole.ControlKeyState.NoControlKeyPressed, - wRepeatCount = 1, - wVirtualKeyCode = ConsoleKeyMapping.VK.RETURN, - wVirtualScanCode = 28 - }); + switch (_driver) + { + case V2TestDriver.V2Win: + SendWindowsKey ( + new WindowsConsole.KeyEventRecord + { + UnicodeChar = '\r', + dwControlKeyState = WindowsConsole.ControlKeyState.NoControlKeyPressed, + wRepeatCount = 1, + wVirtualKeyCode = ConsoleKeyMapping.VK.RETURN, + wVirtualScanCode = 28 + }); + break; + case V2TestDriver.V2Net: + SendNetKey (new ('\r', ConsoleKey.Enter, false, false, false)); + break; + default: + throw new ArgumentOutOfRangeException (); + } return this; } @@ -311,6 +350,13 @@ public class GuiTestContext : IDisposable WaitIteration (); } + + private void SendNetKey (ConsoleKeyInfo consoleKeyInfo) + { + _netInput.InputBuffer.Enqueue (consoleKeyInfo); + WaitIteration (); + } + /// /// Sends a special key e.g. cursor key that does not map to a specific character /// diff --git a/TerminalGuiFluentTesting/V2TestDriver.cs b/TerminalGuiFluentTesting/V2TestDriver.cs new file mode 100644 index 000000000..5560a1c82 --- /dev/null +++ b/TerminalGuiFluentTesting/V2TestDriver.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TerminalGuiFluentTesting; + +/// +/// Which v2 driver should be used +/// +public enum V2TestDriver +{ + V2Win, + V2Net +} diff --git a/TerminalGuiFluentTesting/With.cs b/TerminalGuiFluentTesting/With.cs index dde0867d3..963eb8bfc 100644 --- a/TerminalGuiFluentTesting/With.cs +++ b/TerminalGuiFluentTesting/With.cs @@ -12,8 +12,12 @@ public static class With /// /// /// + /// Which v2 v2TestDriver to use for the test /// - public static GuiTestContext A (int width, int height) where T : Toplevel, new () { return new (() => new T (), width, height); } + public static GuiTestContext A (int width, int height, V2TestDriver v2TestDriver = V2TestDriver.V2Win) where T : Toplevel, new () + { + return new (() => new T (), width, height,v2TestDriver); + } /// /// The global timeout to allow for any given application to run for before shutting down. diff --git a/Tests/IntegrationTests/FluentTests/BasicFluentAssertionTests.cs b/Tests/IntegrationTests/FluentTests/BasicFluentAssertionTests.cs index d4ca228b8..3c2f31886 100644 --- a/Tests/IntegrationTests/FluentTests/BasicFluentAssertionTests.cs +++ b/Tests/IntegrationTests/FluentTests/BasicFluentAssertionTests.cs @@ -79,8 +79,10 @@ public class BasicFluentAssertionTests Assert.True (clicked); } - [Fact] - public void ContextMenu_OpenSubmenu () + [Theory] + [InlineData(V2TestDriver.V2Win)] + //[InlineData (V2TestDriver.V2Net)] // TODO + public void ContextMenu_OpenSubmenu (V2TestDriver v2TestDriver) { var clicked = false; @@ -110,7 +112,7 @@ public class BasicFluentAssertionTests ] ); - using GuiTestContext c = With.A (40, 10) + using GuiTestContext c = With.A (40, 10,v2TestDriver) .WithContextMenu (ctx, menuItems) .ScreenShot ("Before open menu", _out)