using System.Windows.Forms;
using System.Drawing;
using System.Reflection;
+using System.Threading;
using NUnit.Framework;
namespace MonoTests.System.Windows.Forms
{
[TestFixture]
- public class ApplicationTest
+ public class ApplicationTest : TestHelper
{
ApplicationContext ctx;
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))]
TestHelper.RemoveWarning (dummy);
}
+ [Test]
+ public void MethodRaiseIdle ()
+ {
+ bool idle_raised = false;
+
+ Application.Idle += new EventHandler (delegate (Object obj, EventArgs e) { idle_raised = true; });
+ Application.RaiseIdle (EventArgs.Empty);
+
+ Assert.AreEqual (true, idle_raised, "R1");
+ }
+
+ void Application_Idle (object sender, EventArgs e)
+ {
+ throw new Exception ("The method or operation is not implemented.");
+ }
+
class OpenFormsTestForm : Form
{
public bool have_been_opened;
Assert.AreEqual (true, IsInOpenForms (), "#OnCreateControl-B");
}
+ // Activation may not be synchronous, causing too many false positives
protected override void OnActivated (EventArgs e)
{
- Assert.AreEqual (true, IsInOpenForms (), "#OnActivated-A");
+ bool dummy = IsInOpenForms ();
+ //Assert.AreEqual (true, IsInOpenForms (), "#OnActivated-A");
base.OnActivated (e);
- Assert.AreEqual (true, IsInOpenForms (), "#OnActivated-B");
+ dummy = IsInOpenForms ();
+ //Assert.AreEqual (true, IsInOpenForms (), "#OnActivated-B");
}
protected override void OnClosed (EventArgs e)