Author: toshok
Date: 2006-11-15 19:36:51 -0500 (Wed, 15 Nov 2006)
New Revision: 67963

Added:
   
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ApplicationContextTest.cs
Log:
add some tests for Form/ApplicationContext interaction

Added: 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ApplicationContextTest.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ApplicationContextTest.cs
   2006-11-16 00:31:54 UTC (rev 67962)
+++ 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ApplicationContextTest.cs
   2006-11-16 00:36:51 UTC (rev 67963)
@@ -0,0 +1,120 @@
+//
+// 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;
+
+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");
+               }
+
+               
+       }
+}

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to