|
@@ -16,12 +16,14 @@ public class GuiTestContext : IDisposable
|
|
private readonly FakeNetInput _netInput;
|
|
private readonly FakeNetInput _netInput;
|
|
private View? _lastView;
|
|
private View? _lastView;
|
|
private readonly StringBuilder _logsSb;
|
|
private readonly StringBuilder _logsSb;
|
|
|
|
+ private readonly V2TestDriver _driver;
|
|
|
|
|
|
- internal GuiTestContext (Func<Toplevel> topLevelBuilder, int width, int height)
|
|
|
|
|
|
+ internal GuiTestContext (Func<Toplevel> topLevelBuilder, int width, int height, V2TestDriver driver)
|
|
{
|
|
{
|
|
IApplication origApp = ApplicationImpl.Instance;
|
|
IApplication origApp = ApplicationImpl.Instance;
|
|
ILogger? origLogger = Logging.Logger;
|
|
ILogger? origLogger = Logging.Logger;
|
|
_logsSb = new ();
|
|
_logsSb = new ();
|
|
|
|
+ _driver = driver;
|
|
|
|
|
|
_netInput = new (_cts.Token);
|
|
_netInput = new (_cts.Token);
|
|
_winInput = new (_cts.Token);
|
|
_winInput = new (_cts.Token);
|
|
@@ -51,7 +53,7 @@ public class GuiTestContext : IDisposable
|
|
.CreateLogger ("Test Logging");
|
|
.CreateLogger ("Test Logging");
|
|
Logging.Logger = logger;
|
|
Logging.Logger = logger;
|
|
|
|
|
|
- v2.Init (null, "v2win");
|
|
|
|
|
|
+ v2.Init (null, GetDriverName());
|
|
|
|
|
|
booting.Release ();
|
|
booting.Release ();
|
|
|
|
|
|
@@ -84,6 +86,17 @@ public class GuiTestContext : IDisposable
|
|
WaitIteration ();
|
|
WaitIteration ();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private string GetDriverName ()
|
|
|
|
+ {
|
|
|
|
+ return _driver switch
|
|
|
|
+ {
|
|
|
|
+ V2TestDriver.V2Win => "v2win",
|
|
|
|
+ V2TestDriver.V2Net => "v2net",
|
|
|
|
+ _ =>
|
|
|
|
+ throw new ArgumentOutOfRangeException ()
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Stops the application and waits for the background thread to exit.
|
|
/// Stops the application and waits for the background thread to exit.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -212,6 +225,8 @@ public class GuiTestContext : IDisposable
|
|
|
|
|
|
private GuiTestContext Click (WindowsConsole.ButtonState btn, int screenX, int screenY)
|
|
private GuiTestContext Click (WindowsConsole.ButtonState btn, int screenX, int screenY)
|
|
{
|
|
{
|
|
|
|
+ // TODO: Support net style ansi escape sequence generation for arrow keys
|
|
|
|
+
|
|
_winInput.InputBuffer.Enqueue (
|
|
_winInput.InputBuffer.Enqueue (
|
|
new ()
|
|
new ()
|
|
{
|
|
{
|
|
@@ -241,11 +256,25 @@ public class GuiTestContext : IDisposable
|
|
|
|
|
|
public GuiTestContext Down ()
|
|
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;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
public GuiTestContext Right ()
|
|
public GuiTestContext Right ()
|
|
{
|
|
{
|
|
SendWindowsKey (ConsoleKeyMapping.VK.RIGHT);
|
|
SendWindowsKey (ConsoleKeyMapping.VK.RIGHT);
|
|
@@ -269,15 +298,25 @@ public class GuiTestContext : IDisposable
|
|
|
|
|
|
public GuiTestContext Enter ()
|
|
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;
|
|
return this;
|
|
}
|
|
}
|
|
@@ -311,6 +350,13 @@ public class GuiTestContext : IDisposable
|
|
WaitIteration ();
|
|
WaitIteration ();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ private void SendNetKey (ConsoleKeyInfo consoleKeyInfo)
|
|
|
|
+ {
|
|
|
|
+ _netInput.InputBuffer.Enqueue (consoleKeyInfo);
|
|
|
|
+ WaitIteration ();
|
|
|
|
+ }
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Sends a special key e.g. cursor key that does not map to a specific character
|
|
/// Sends a special key e.g. cursor key that does not map to a specific character
|
|
/// </summary>
|
|
/// </summary>
|