| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- //
- // ApplicationContextTest.cs
- //
- // Author:
- // Chris Toshok ([email protected])
- //
- // (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;
- using CategoryAttribute=NUnit.Framework.CategoryAttribute;
- namespace MonoTests.System.Windows.Forms
- {
- class MyForm : Form
- {
- public void DoDestroyHandle ()
- {
- DestroyHandle();
- }
- }
- [TestFixture]
- public class ApplicationContextTest : TestHelper
- {
- 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.ShowInTaskbar = false;
- 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");
- f1.Dispose ();
- }
- [Test]
- public void TestEventOrdering2 ()
- {
- thread_exit_count = 0;
- reached_form_handle_destroyed = false;
- MyForm f1 = new MyForm ();
- f1.ShowInTaskbar = false;
- 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");
-
- f1.Dispose ();
- }
- [Test]
- public void ThreadExitTest ()
- {
- thread_exit_count = 0;
- MyForm f1 = new MyForm ();
- f1.ShowInTaskbar = false;
- 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");
- 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 ();
- }
- }
- }
- }
|