// // ApplicationContextTest.cs // // Author: // Chris Toshok (toshok@ximian.com) // // (C) 2006 Novell, Inc. (http://www.novell.com) // using System; using System.ComponentModel; using System.Windows.Forms; using System.Drawing; using System.Reflection; using NUnit.Framework; namespace MonoTests.System.Windows.Forms { class MyForm : Form { public void DoDestroyHandle () { DestroyHandle(); } } [TestFixture] public class ApplicationContextTest { ApplicationContext ctx; int thread_exit_count; bool reached_form_handle_destroyed; void thread_exit (object sender, EventArgs e) { thread_exit_count++; } void form_handle_destroyed (object sender, EventArgs e) { Assert.AreEqual (0, thread_exit_count, "1"); Assert.AreEqual (sender, ctx.MainForm, "2"); reached_form_handle_destroyed = true; } void form_handle_destroyed2 (object sender, EventArgs e) { Assert.AreEqual (1, thread_exit_count, "1"); Assert.AreEqual (sender, ctx.MainForm, "2"); reached_form_handle_destroyed = true; } [Test] public void TestEventOrdering () { thread_exit_count = 0; reached_form_handle_destroyed = false; MyForm f1 = new MyForm (); f1.HandleDestroyed += new EventHandler (form_handle_destroyed); ctx = new ApplicationContext (f1); ctx.ThreadExit += new EventHandler (thread_exit); f1.Show (); f1.DoDestroyHandle (); Assert.AreEqual (true, reached_form_handle_destroyed, "3"); Assert.AreEqual (1, thread_exit_count, "4"); } [Test] public void TestEventOrdering2 () { thread_exit_count = 0; reached_form_handle_destroyed = false; MyForm f1 = new MyForm (); ctx = new ApplicationContext (f1); ctx.ThreadExit += new EventHandler (thread_exit); f1.HandleDestroyed += new EventHandler (form_handle_destroyed2); f1.Show (); f1.DoDestroyHandle (); Assert.AreEqual (true, reached_form_handle_destroyed, "3"); Assert.AreEqual (1, thread_exit_count, "4"); } [Test] public void ThreadExitTest () { thread_exit_count = 0; MyForm f1 = new MyForm (); ctx = new ApplicationContext (f1); ctx.ThreadExit += new EventHandler (thread_exit); Assert.AreEqual (f1, ctx.MainForm, "1"); f1.ShowInTaskbar = false; f1.Show (); f1.Dispose (); Assert.AreEqual (f1, ctx.MainForm, "2"); Assert.AreEqual (1, thread_exit_count, "3"); f1 = new MyForm (); ctx = new ApplicationContext (f1); ctx.ThreadExit += new EventHandler (thread_exit); f1.ShowInTaskbar = false; f1.Show (); f1.DoDestroyHandle (); Assert.AreEqual (f1, ctx.MainForm, "4"); Assert.AreEqual (2, thread_exit_count, "5"); } } }