inital impl

This commit is contained in:
Charlie Kindel
2022-11-07 18:21:32 -07:00
parent eb080188c4
commit cbbeb404a7
2 changed files with 41 additions and 14 deletions

View File

@@ -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
}
}

View File

@@ -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 ()