Add test for bug 694908.
authorEberhard Beilharz <eb1@sil.org>
Thu, 16 Jun 2011 18:27:41 +0000 (20:27 +0200)
committerThomas Goldstein <stifu@free.fr>
Thu, 16 Jun 2011 18:33:12 +0000 (20:33 +0200)
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ApplicationTest.cs

index ba12096d4dad825226c7fb4a84b36d046df7bd26..78a082ded286b2d21c68ed239fe2a22fd0e6ffcb 100644 (file)
@@ -12,6 +12,7 @@ using System.ComponentModel;
 using System.Windows.Forms;
 using System.Drawing;
 using System.Reflection;
+using System.Threading;
 using NUnit.Framework;
 
 namespace MonoTests.System.Windows.Forms
@@ -41,6 +42,54 @@ namespace MonoTests.System.Windows.Forms
                        Assert.IsNull (ctx.MainForm, "2");
                        f1.Dispose ();
                }
+
+               [Test]
+               public void Bug694908 ()
+               {
+                       Application.ThreadException += CrashingForm.HandleThreadException;
+
+                       using (var form = new CrashingForm ())
+                       {
+                               form.Show ();
+                               Application.DoEvents ();
+                       }
+                       // with bug 694908 we don't come here. Instead NUnit exits.
+                       Assert.IsTrue (CrashingForm.HasHandledException);
+               }
+
+               class CrashingForm: Form
+               {
+                       private static Form _thisForm;
+
+                       public CrashingForm ()
+                       {
+                               _thisForm = this;
+                               var btn = new Button ();
+                               SuspendLayout ();
+
+                               btn.Paint += OnButtonPaint;
+                               Controls.Add (btn);
+
+                               ResumeLayout (false);
+                               PerformLayout ();
+                       }
+
+                       private void OnButtonPaint (object sender, PaintEventArgs e)
+                       {
+                               throw new ArgumentException ();
+                       }
+
+                       public static bool HasHandledException { get; private set; }
+
+                       public static void HandleThreadException (object sender, ThreadExceptionEventArgs args)
+                       {
+                               _thisForm.Refresh ();
+                               Application.DoEvents ();
+                               HasHandledException = true;
+                               _thisForm.Close ();
+                       }
+               }
+
 #if NET_2_0
                [Test]
                [ExpectedException (typeof (NotSupportedException))]