* FormHandleTest.cs, ControlEventTest.cs, MenuStripTest.cs,
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ApplicationContextTest.cs
index d0786dc898e46ba7e184b0859f9bf48d4cdd0812..4bdd2bc78112711fab3e9321196910264670c849 100644 (file)
@@ -13,6 +13,7 @@ using System.Windows.Forms;
 using System.Drawing;
 using System.Reflection;
 using NUnit.Framework;
+using CategoryAttribute=NUnit.Framework.CategoryAttribute;
 
 namespace MonoTests.System.Windows.Forms
 {
@@ -58,6 +59,7 @@ namespace MonoTests.System.Windows.Forms
                        reached_form_handle_destroyed = false;
 
                        MyForm f1 = new MyForm ();
+                       f1.ShowInTaskbar = false;
                        f1.HandleDestroyed += new EventHandler (form_handle_destroyed);
 
                        ctx = new ApplicationContext (f1);
@@ -68,6 +70,8 @@ namespace MonoTests.System.Windows.Forms
 
                        Assert.AreEqual (true, reached_form_handle_destroyed, "3");
                        Assert.AreEqual (1, thread_exit_count, "4");
+
+                       f1.Dispose ();
                }
 
                [Test]
@@ -77,6 +81,7 @@ namespace MonoTests.System.Windows.Forms
                        reached_form_handle_destroyed = false;
 
                        MyForm f1 = new MyForm ();
+                       f1.ShowInTaskbar = false;
 
                        ctx = new ApplicationContext (f1);
                        ctx.ThreadExit += new EventHandler (thread_exit);
@@ -87,6 +92,8 @@ namespace MonoTests.System.Windows.Forms
                        f1.DoDestroyHandle ();
                        Assert.AreEqual (true, reached_form_handle_destroyed, "3");
                        Assert.AreEqual (1, thread_exit_count, "4");
+                       
+                       f1.Dispose ();
                }
 
                [Test]
@@ -95,6 +102,7 @@ namespace MonoTests.System.Windows.Forms
                        thread_exit_count = 0;
 
                        MyForm f1 = new MyForm ();
+                       f1.ShowInTaskbar = false;
                        ctx = new ApplicationContext (f1);
                        ctx.ThreadExit += new EventHandler (thread_exit);
 
@@ -113,8 +121,34 @@ namespace MonoTests.System.Windows.Forms
                        f1.DoDestroyHandle ();
                        Assert.AreEqual (f1, ctx.MainForm, "4");
                        Assert.AreEqual (2, thread_exit_count, "5");
+                       f1.Dispose ();
                }
 
-               
+               [Test]
+               [Category ("NotWorking")]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void NestedApplicationContextTest ()
+               {
+                       using (NestedForm frm = new NestedForm ()) {
+                               Application.Run (frm);
+                       }
+               }
+
+               private class NestedForm : Form
+               {
+                       static int counter = 1;
+                       protected override void OnVisibleChanged (EventArgs e)
+                       {
+                               base.OnVisibleChanged (e);
+
+                               Text = counter.ToString ();
+
+                               if (counter <= 3) {
+                                       counter++;
+                                       Application.Run (new NestedForm ());
+                               }
+                               Close ();
+                       }
+               }
        }
 }