-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix up Clipboard on all platforms to behave similarly.
- Wpf: Can now specify more than one type in the clipboard by setting various properties. - Wpf: Added protection when getting the value and retries 10 times after 100ms delay as some times it throws a com exception that it cannot open the clipboard. - Gtk: Fix up Clipboard.Image so it doesn't wipe all other values in the clipboard - Gtk: Setting Clipboard.Text sets all text variants, not just utf8. - Gtk: Getting/Setting Clipboard.Html now works correctly - Added unit tests to verify behaviour
- Loading branch information
Showing
6 changed files
with
224 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
Source/Eto.Test/Eto.Test/UnitTests/Forms/ClipboardTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using Eto.Forms; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Eto.Test.UnitTests.Forms | ||
{ | ||
[TestFixture] | ||
public class ClipboardTests : TestBase | ||
{ | ||
[Test] | ||
public void GettingAndSettingTextShouldNotCrash() | ||
{ | ||
Invoke(() => | ||
{ | ||
for (int i = 0; i < 100; i++) | ||
{ | ||
// this crashes on WPF on some machines.. don't know why as I can't repro the issue. | ||
var clipboard = new Clipboard(); | ||
var val = "Hello" + i; | ||
clipboard.Text = val; | ||
Assert.AreEqual(val, clipboard.Text); | ||
} | ||
}); | ||
} | ||
|
||
[Test] | ||
public void SettingMultipleFormatsShouldWork() | ||
{ | ||
Invoke(() => | ||
{ | ||
var byteData = new byte[] { 10, 20, 30 }; | ||
using (var clipboard = new Clipboard()) | ||
{ | ||
clipboard.Text = "Text"; | ||
clipboard.Html = "<strong>Some Html</strong>"; | ||
clipboard.SetString("woot", "eto-woot"); | ||
clipboard.SetData(byteData, "eto-byte-data"); | ||
|
||
Assert.AreEqual("Text", clipboard.Text); | ||
Assert.AreEqual("<strong>Some Html</strong>", clipboard.Html); | ||
Assert.AreEqual("woot", clipboard.GetString("eto-woot")); | ||
Assert.AreEqual(byteData, clipboard.GetData("eto-byte-data")); | ||
|
||
Assert.Contains("eto-woot", clipboard.Types); | ||
Assert.Contains("eto-byte-data", clipboard.Types); | ||
} | ||
|
||
using (var clipboard = new Clipboard()) | ||
{ | ||
Assert.AreEqual("Text", clipboard.Text); | ||
Assert.AreEqual("<strong>Some Html</strong>", clipboard.Html); | ||
Assert.AreEqual("woot", clipboard.GetString("eto-woot")); | ||
Assert.AreEqual(byteData, clipboard.GetData("eto-byte-data")); | ||
|
||
Assert.Contains("eto-woot", clipboard.Types); | ||
Assert.Contains("eto-byte-data", clipboard.Types); | ||
|
||
clipboard.Clear(); | ||
CollectionAssert.DoesNotContain("eto-woot", clipboard.Types); | ||
CollectionAssert.DoesNotContain("eto-byte-data", clipboard.Types); | ||
Assert.AreEqual(null, clipboard.Text); | ||
Assert.AreEqual(null, clipboard.Html); | ||
Assert.AreEqual(null, clipboard.Image); | ||
Assert.AreEqual(null, clipboard.GetString("eto-woot")); | ||
Assert.AreEqual(null, clipboard.GetData("eto-byte-data")); | ||
} | ||
|
||
using (var clipboard = new Clipboard()) | ||
{ | ||
CollectionAssert.DoesNotContain("eto-woot", clipboard.Types); | ||
CollectionAssert.DoesNotContain("eto-byte-data", clipboard.Types); | ||
Assert.AreEqual(null, clipboard.Text); | ||
Assert.AreEqual(null, clipboard.Html); | ||
Assert.AreEqual(null, clipboard.Image); | ||
Assert.AreEqual(null, clipboard.GetString("eto-woot")); | ||
Assert.AreEqual(null, clipboard.GetData("eto-byte-data")); | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.