diff options
author | Eberhard Beilharz <eb1@sil.org> | 2012-05-09 12:49:42 +0400 |
---|---|---|
committer | Eberhard Beilharz <eb1@sil.org> | 2012-05-21 13:12:23 +0400 |
commit | 4989bf10402c0a3a20debd900b7e0d1499655bfa (patch) | |
tree | 2a28bf64a0879340569a147148d71222d81644e0 /mcs/class/Managed.Windows.Forms/Test | |
parent | 5a349bae393347c099dcc8fde2ec2b7ec1dcad6e (diff) |
Unit test for bug Xamarin-4959
Because the clipboard is a shared resource between applications
it is possible that the test sometimes fails for wrong reasons
if another app manipulates the clipboard just at the right time.
Change-Id: I1a52b62d2958ece35c8927172d94ab6ccb3183b0
Diffstat (limited to 'mcs/class/Managed.Windows.Forms/Test')
-rw-r--r-- | mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ClipboardTest.cs | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ClipboardTest.cs b/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ClipboardTest.cs index 66832bc9131..f90a1b98c12 100644 --- a/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ClipboardTest.cs +++ b/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ClipboardTest.cs @@ -24,6 +24,9 @@ // using System; +using System.CodeDom.Compiler; +using System.Diagnostics; +using System.IO; using System.Text; using System.Windows.Forms; using NUnit.Framework; @@ -99,6 +102,82 @@ namespace MonoTests.System.Windows.Forms public string Name; public int Id; } + + [Test] + public void DataRemainsOnClipboard_Xamarin4959 () + { + // Compile an app that puts something on the clipboard + var source = @" +using System; +using System.Windows.Forms; +public static class MainClass +{ + public static void Main () + { + Clipboard.SetDataObject (""testing bug 4959"", true, 10, 100); + } +} +"; + var exeName = Path.GetTempFileName (); + try { + var parameters = new CompilerParameters (); + parameters.GenerateExecutable = true; + parameters.ReferencedAssemblies.Add ("System.Windows.Forms.dll"); + parameters.OutputAssembly = exeName; + var compiler = CodeDomProvider.CreateProvider ("CSharp"); + var compilerResults = compiler.CompileAssemblyFromSource (parameters, source); + Assert.AreEqual (0, compilerResults.Errors.Count); + + // Execute the app + using (var app = Process.Start (exeName)) { + app.WaitForExit (); + } + + // Text should still be on the clipboard + Assert.AreEqual ("testing bug 4959", Clipboard.GetText ()); + } finally { + File.Delete (exeName); + } + } + + [Test] + public void DataGetsCleared_Xamarin4959 () + { + // This is the reverse of the previous test + + // Compile an app that puts something on the clipboard + var source = @" +using System; +using System.Windows.Forms; +public static class MainClass +{ + public static void Main () + { + Clipboard.SetDataObject (""testing bug 4959"", false, 10, 100); + } +} +"; + var exeName = Path.GetTempFileName (); + try { + var parameters = new CompilerParameters (); + parameters.GenerateExecutable = true; + parameters.ReferencedAssemblies.Add ("System.Windows.Forms.dll"); + parameters.OutputAssembly = exeName; + var compiler = CodeDomProvider.CreateProvider ("CSharp"); + var compilerResults = compiler.CompileAssemblyFromSource (parameters, source); + Assert.AreEqual (0, compilerResults.Errors.Count); + + // Execute the app + using (var app = Process.Start (exeName)) { + app.WaitForExit (); + } + + // Text should no longer be on the clipboard + Assert.IsTrue (string.IsNullOrEmpty (Clipboard.GetText ())); + } finally { + File.Delete (exeName); + } + } #endif } } |