From cbbeb404a70ac14c23a25f2a2affe094eafafd6e Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Mon, 7 Nov 2022 18:21:32 -0700 Subject: [PATCH] inital impl --- .../ConsoleDrivers/FakeDriver/FakeDriver.cs | 37 +++++++++++++++---- UnitTests/ClipboardTests.cs | 18 ++++++--- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs index a59a863a0..05366cfe3 100644 --- a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs @@ -57,17 +57,21 @@ namespace Terminal.Gui { static bool sync = false; - public FakeDriver () + public FakeDriver (bool useFakeClipboard = true) { - if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) { - Clipboard = new WindowsClipboard (); - } else if (RuntimeInformation.IsOSPlatform (OSPlatform.OSX)) { - Clipboard = new MacOSXClipboard (); + if (useFakeClipboard) { + Clipboard = new FakeClipboard (); } else { - if (CursesDriver.Is_WSL_Platform ()) { - Clipboard = new WSLClipboard (); + if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) { + Clipboard = new WindowsClipboard (); + } else if (RuntimeInformation.IsOSPlatform (OSPlatform.OSX)) { + Clipboard = new MacOSXClipboard (); } else { - Clipboard = new CursesClipboard (); + if (CursesDriver.Is_WSL_Platform ()) { + Clipboard = new WSLClipboard (); + } else { + Clipboard = new CursesClipboard (); + } } } } @@ -641,6 +645,23 @@ namespace Terminal.Gui { } #endregion + + public class FakeClipboard : ClipboardBase { + public override bool IsSupported => true; + + string contents = string.Empty; + + protected override string GetClipboardDataImpl () + { + return contents; + } + + protected override void SetClipboardDataImpl (string text) + { + contents = text; + } + } + #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member } } \ No newline at end of file diff --git a/UnitTests/ClipboardTests.cs b/UnitTests/ClipboardTests.cs index 25c59d180..5161aecbd 100644 --- a/UnitTests/ClipboardTests.cs +++ b/UnitTests/ClipboardTests.cs @@ -5,9 +5,9 @@ using Xunit; namespace Terminal.Gui.Core { public class ClipboardTests { [Fact] - [AutoInitShutdown] public void Contents_Gets_Sets () { + Application.Init (new FakeDriver (useFakeClipboard: false), new FakeMainLoop (() => FakeConsole.ReadKey (true))); var clipText = "This is a clipboard unit test."; Clipboard.Contents = clipText; @@ -16,23 +16,25 @@ namespace Terminal.Gui.Core { Application.Run (); Assert.Equal (clipText, Clipboard.Contents); + Application.Shutdown (); } [Fact] - [AutoInitShutdown] public void IsSupported_Get () { + Application.Init (new FakeDriver (useFakeClipboard: false), new FakeMainLoop (() => FakeConsole.ReadKey (true))); if (Clipboard.IsSupported) { Assert.True (Clipboard.IsSupported); } else { Assert.False (Clipboard.IsSupported); } + Application.Shutdown (); } [Fact] - [AutoInitShutdown] public void TryGetClipboardData_Gets_From_OS_Clipboard () { + Application.Init (new FakeDriver (useFakeClipboard: false), new FakeMainLoop (() => FakeConsole.ReadKey (true))); var clipText = "Trying to get from the OS clipboard."; Clipboard.Contents = clipText; @@ -47,12 +49,13 @@ namespace Terminal.Gui.Core { Assert.False (Clipboard.TryGetClipboardData (out string result)); Assert.NotEqual (clipText, result); } + Application.Shutdown (); } [Fact] - [AutoInitShutdown] public void TrySetClipboardData_Sets_The_OS_Clipboard () { + Application.Init (new FakeDriver (useFakeClipboard: false), new FakeMainLoop (() => FakeConsole.ReadKey (true))); var clipText = "Trying to set the OS clipboard."; if (Clipboard.IsSupported) { Assert.True (Clipboard.TrySetClipboardData (clipText)); @@ -69,12 +72,13 @@ namespace Terminal.Gui.Core { } else { Assert.NotEqual (clipText, Clipboard.Contents); } + Application.Shutdown (); } [Fact] - [AutoInitShutdown] public void Contents_Gets_From_OS_Clipboard () { + Application.Init (new FakeDriver (useFakeClipboard: false), new FakeMainLoop (() => FakeConsole.ReadKey (true))); var clipText = "This is a clipboard unit test to get clipboard from OS."; var exit = false; var getClipText = ""; @@ -189,12 +193,13 @@ namespace Terminal.Gui.Core { if (!exit) { Assert.Equal (clipText, getClipText); } + Application.Shutdown (); } [Fact] - [AutoInitShutdown] public void Contents_Sets_The_OS_Clipboard () { + Application.Init (new FakeDriver (useFakeClipboard: false), new FakeMainLoop (() => FakeConsole.ReadKey (true))); var clipText = "This is a clipboard unit test to set the OS clipboard."; var clipReadText = ""; var exit = false; @@ -274,6 +279,7 @@ namespace Terminal.Gui.Core { if (!exit) { Assert.Equal (clipText, clipReadText); } + Application.Shutdown (); } bool Is_WSL_Platform ()