2007-03-28 Igor Zelmanovich <igorz@mainsoft.com>
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / MdiFormTest.cs
index b3e1a2521565250cc4f7a3af53d3a5d884e616c9..eaa7d8973d06eb8115fd2fa6207614475cc42bb4 100644 (file)
@@ -11,14 +11,831 @@ using System;
 using System.Drawing;
 using System.Reflection;
 using System.Windows.Forms;
-
+using System.ComponentModel;
 using NUnit.Framework;
+using CategoryAttribute = NUnit.Framework.CategoryAttribute;
 
 namespace MonoTests.System.Windows.Forms
 {
        [TestFixture]
        public class MdiFormTest
        {
+               private Form main;
+               private Form child1;
+               private Form child2;
+               private Form child3;
+
+               [TearDown]
+               public void TearDown ()
+               {
+                       if (main != null)
+                               main.Dispose ();
+                       if (child1 != null)
+                               child1.Dispose ();
+                       if (child2 != null)
+                               child2.Dispose ();
+                       if (child3 != null)
+                               child3.Dispose ();
+                       main = null;
+                       child1 = null;
+                       child2 = null;
+                       child3 = null;
+               }
+       
+               // No attribute here since this is supposed to be called from 
+               // each test directly, not by nunit.
+               public void SetUp (bool only_create, bool only_text)
+               {
+                       SetUp (only_create, only_text, false);
+               }       
+                               
+               // No attribute here since this is supposed to be called from 
+               // each test directly, not by nunit.
+               public void SetUp (bool only_create, bool only_text, bool set_parent)
+               {
+                       TearDown ();
+                       
+                       main = new Form ();
+                       child1 = new Form ();
+                       child2 = new Form ();
+                       child3 = new Form ();
+
+                       if (only_create)
+                               return;
+
+                       main.Text = main.Name = "main";
+                       main.ShowInTaskbar = false;
+                       child1.Text = child1.Name = "child1";
+                       child2.Text = child2.Name = "child2";
+                       child3.Text = child3.Name = "child3";
+
+                       if (only_text)
+                               return;
+
+                       main.IsMdiContainer = true;
+                       
+                       if (set_parent) {
+                               child1.MdiParent = main;
+                               child2.MdiParent = main;
+                               child3.MdiParent = main;
+                       }
+               }
+               
+               [Test]
+               public void ActiveControlTest ()
+               {
+                       SetUp (false, false, true);
+                       
+                       main.Show ();
+                       
+                       Assert.IsNull (main.ActiveControl, "#01");                      
+                       child1.Visible = true;
+                       Assert.AreSame (child1, main.ActiveControl, "#02");
+                       child2.Visible = true;
+                       Assert.AreSame (child2, main.ActiveControl, "#03");
+                       child3.Visible = true;
+                       Assert.AreSame (child3, main.ActiveControl, "#04");
+                       TearDown ();
+               }
+               
+               [Test]
+               public void SelectNextControlTest ()
+               {
+                       SetUp (false, false, true);
+
+                       main.Show ();
+                       
+                       child1.Visible = true;
+                       child2.Visible = true;
+                       child3.Visible = true;
+                       
+                       main.SelectNextControl (main.ActiveControl, true, false, true, true);
+                       Assert.AreSame (child1, main.ActiveControl, "#01");
+                       main.SelectNextControl (main.ActiveControl, true, false, true, true);
+                       Assert.AreSame (child2, main.ActiveControl, "#02");
+                       main.SelectNextControl (main.ActiveControl, true, false, true, true);
+                       Assert.AreSame (child3, main.ActiveControl, "#03");
+                                               
+                       TearDown ();
+               }
+
+               [Test]
+               public void SelectPreviousControlTest ()
+               {
+                       SetUp (false, false, true);
+
+                       main.Show ();
+                       
+                       child1.Visible = true;
+                       child2.Visible = true;
+                       child3.Visible = true;
+
+                       main.SelectNextControl (main.ActiveControl, false, false, true, true);
+                       Assert.AreSame (child2, main.ActiveControl, "#01");
+                       main.SelectNextControl (main.ActiveControl, false, false, true, true);
+                       Assert.AreSame (child1, main.ActiveControl, "#02");
+                       main.SelectNextControl (main.ActiveControl, false, false, true, true);
+                       Assert.AreSame (child3, main.ActiveControl, "#03");
+
+                       TearDown ();
+               }
+               
+               [TestFixture]
+               public class CloseTest
+               {
+                       class ChildForm : Form
+                       {
+                               public ChildForm ()
+                               {
+                                       Closed += new EventHandler (ChildForm_Closed);
+                                       Closing += new CancelEventHandler (ChildForm_Closing);
+#if NET_2_0                                    
+                                       FormClosed += new FormClosedEventHandler (ChildForm_FormClosed);
+                                       FormClosing += new FormClosingEventHandler (ChildForm_FormClosing);
+#endif
+                               }
+#if NET_2_0
+                               void ChildForm_FormClosing (object sender, FormClosingEventArgs e)
+                               {
+                                       Assert.IsNotNull (MdiParent, "ChildForm_FormClosing");
+                               }
+
+                               void ChildForm_FormClosed (object sender, FormClosedEventArgs e)
+                               {
+                                       Assert.IsNotNull (MdiParent, "ChildForm_FormClosed");
+                               }
+#endif
+                               void ChildForm_Closing (object sender, CancelEventArgs e)
+                               {
+                                       Assert.IsNotNull (MdiParent, "ChildForm_Closing");
+                               }
+
+                               void ChildForm_Closed (object sender, EventArgs e)
+                               {
+                                       Assert.IsNotNull (MdiParent, "ChildForm_Closed");
+                               }
+                       
+                               protected override void OnClosed (EventArgs e)
+                               {
+                                       Assert.IsNotNull (MdiParent, "OnClosed 1");
+                                       base.OnClosed (e);
+                                       Assert.IsNotNull (MdiParent, "OnClosed 2");
+                               }
+
+                               protected override void OnClosing (CancelEventArgs e)
+                               {
+                                       Assert.IsNotNull (MdiParent, "OnClosing 1");
+                                       base.OnClosing (e);
+                                       Assert.IsNotNull (MdiParent, "OnClosing 2");
+                               }
+                               
+                       }
+                       [Test]
+                       public void Test () {
+                               using (Form main = new Form ()) {
+                                       main.IsMdiContainer = true;
+                                       main.ShowInTaskbar = false;
+                                       main.Visible = true;
+
+                                       ChildForm child = new ChildForm ();
+                                       EventLogger log = new EventLogger (child);
+                                       child.MdiParent = main;
+                                       child.Visible = true;
+                                       child.Close ();
+                                       
+                                       Assert.AreEqual (1, log.CountEvents ("Closed"), "#01");
+                                       Assert.AreEqual (1, log.CountEvents ("Closing"), "#02");
+                                       Assert.IsNull (child.MdiParent, "#03");
+                                       Assert.AreEqual (0, main.MdiChildren.Length, "#04");            
+                                       Assert.AreEqual (false, child.IsMdiChild, "#05");               
+                               }
+                       }
+               }
+               [Test]
+               [Category ("NotWorking")]
+               public void StartLocationTest ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+
+                       child1.Visible = true;
+                       child2.Visible = true;
+
+                       main.Show ();
+
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual (true, "{X=0,Y=0}" != child2.Location.ToString (), "#2");
+
+                       TearDown ();
+               }
+               
+               /* These tests are all failing on WinXP with XP Theme. 
+                * offset seems to be 22,22 normally, and 22,29 with XP theme.
+                * Find a way to test this reliably.
+                * /
+               [Category("NotWorking")]
+               [Test]
+               public void StartLocationTest1 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+
+                       child1.Visible = true;
+                       child2.Visible = true;
+
+                       main.Show ();
+                       
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual ("{X=22,Y=22}", child2.Location.ToString (), "#2");
+
+                       TearDown ();
+               }
+
+               [Category("NotWorking")]
+               [Test]
+               public void StartLocationTest2 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+
+                       child1.StartPosition = FormStartPosition.Manual;
+
+                       child1.Visible = true;
+                       child2.Visible = true;
+
+                       main.Show ();
+                       
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual ("{X=22,Y=22}", child2.Location.ToString (), "#2");
+
+                       TearDown ();
+               }
+
+
+               [Category("NotWorking")]
+               [Test]
+               public void StartLocationTest3 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+
+                       child2.StartPosition = FormStartPosition.Manual;
+
+                       child1.Visible = true;
+                       child2.Visible = true;
+
+                       main.Show ();
+                       
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual ("{X=0,Y=0}", child2.Location.ToString (), "#2");
+
+                       TearDown ();
+               }
+
+               [Category("NotWorking")]
+               [Test]
+               public void StartLocationTest4 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+
+                       child1.StartPosition = FormStartPosition.Manual;
+                       child2.StartPosition = FormStartPosition.Manual;
+
+                       child1.Visible = true;
+                       child2.Visible = true;
+
+                       main.Show ();
+                       
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual ("{X=0,Y=0}", child2.Location.ToString (), "#2");
+
+                       TearDown ();
+               }
+
+               [Category("NotWorking")]
+               [Test]
+               public void StartLocationTest5 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+                       child3.MdiParent = main;
+
+                       child2.StartPosition = FormStartPosition.Manual;
+
+                       child1.Visible = true;
+                       child2.Visible = true;
+                       child3.Visible = true;
+
+                       main.Show ();
+                       
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual ("{X=0,Y=0}", child2.Location.ToString (), "#2");
+                       Assert.AreEqual ("{X=44,Y=44}", child3.Location.ToString (), "#3");
+
+                       TearDown ();
+               }
+
+               [Category("NotWorking")]
+               [Test]
+               public void StartLocationTest6 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+                       child3.MdiParent = main;
+
+                       child2.StartPosition = FormStartPosition.CenterParent;
+
+                       child1.Visible = true;
+                       child2.Visible = true;
+                       child3.Visible = true;
+
+                       main.Show ();
+                       
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual ("{X=22,Y=22}", child2.Location.ToString (), "#2");
+                       Assert.AreEqual ("{X=44,Y=44}", child3.Location.ToString (), "#3");
+
+                       TearDown ();
+               }
+
+               [Category("NotWorking")]
+               [Test]
+               public void StartLocationTest7 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+                       child3.MdiParent = main;
+
+                       child2.StartPosition = FormStartPosition.CenterScreen;
+
+                       child1.Visible = true;
+                       child2.Visible = true;
+                       child3.Visible = true;
+
+                       main.Show ();
+                       
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual ("{X=0,Y=0}", child2.Location.ToString (), "#2");
+                       Assert.AreEqual ("{X=44,Y=44}", child3.Location.ToString (), "#3");
+
+                       TearDown ();
+               }
+
+               [Category("NotWorking")]
+               [Test]
+               public void StartLocationTest8 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+                       child3.MdiParent = main;
+
+                       child2.StartPosition = FormStartPosition.WindowsDefaultBounds;
+
+                       child1.Visible = true;
+                       child2.Visible = true;
+                       child3.Visible = true;
+
+                       main.Show ();
+                       
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual ("{X=22,Y=22}", child2.Location.ToString (), "#2");
+                       Assert.AreEqual ("{X=44,Y=44}", child3.Location.ToString (), "#3");
+
+                       TearDown ();
+               }
+
+               [Category("NotWorking")]
+               [Test]
+               public void StartLocationTest9 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+                       child3.MdiParent = main;
+
+                       child2.StartPosition = FormStartPosition.WindowsDefaultLocation;
+
+                       child1.Visible = true;
+                       child2.Visible = true;
+                       child3.Visible = true;
+
+                       main.Show ();
+                       
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual ("{X=22,Y=22}", child2.Location.ToString (), "#2");
+                       Assert.AreEqual ("{X=44,Y=44}", child3.Location.ToString (), "#3");
+
+                       TearDown ();
+               }
+               
+               [Category("NotWorking")]
+               [Test]
+               public void StartLocationTest10 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+                       child3.MdiParent = main;
+
+                       child2.StartPosition = FormStartPosition.Manual;
+                       child2.Location = new Point (123, 123);
+
+                       child1.Visible = true;
+                       child2.Visible = true;
+                       child3.Visible = true;
+
+                       main.Show ();
+                       
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual ("{X=123,Y=123}", child2.Location.ToString (), "#2");
+                       Assert.AreEqual ("{X=44,Y=44}", child3.Location.ToString (), "#3");
+
+                       TearDown ();
+               }
+
+               [Category("NotWorking")]
+               [Test]
+               public void StartLocationTest11 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+                       child3.MdiParent = main;
+
+                       child2.Location = new Point (123, 123);
+
+                       Assert.AreEqual ("{X=123,Y=123}", child2.Location.ToString (), "#0");
+
+                       child1.Visible = true;
+                       child2.Visible = true;
+                       child3.Visible = true;
+
+                       Assert.AreEqual ("{X=123,Y=123}", child2.Location.ToString (), "#0");
+
+                       main.Show ();
+                       
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual ("{X=22,Y=22}", child2.Location.ToString (), "#2");
+                       Assert.AreEqual ("{X=44,Y=44}", child3.Location.ToString (), "#3");
+
+                       TearDown ();
+               }
+
+               [Category("NotWorking")]
+               [Test]
+               public void StartLocationTest12 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+                       child3.MdiParent = main;
+
+                       child1.Visible = true;
+                       //child2.Visible = true;
+                       child3.Visible = true;
+
+                       main.Show ();
+                       
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual ("{X=0,Y=0}", child2.Location.ToString (), "#2");
+                       Assert.AreEqual ("{X=22,Y=22}", child3.Location.ToString (), "#3");
+
+                       child2.Visible = true;
+                       Assert.AreEqual ("{X=44,Y=44}", child2.Location.ToString (), "#4");
+
+                       child1.Visible = false;
+                       child1.Visible = true;
+                       Assert.AreEqual ("{X=66,Y=66}", child1.Location.ToString (), "#1");
+
+                       TearDown ();
+               }
+
+               [Category("NotWorking")]
+               [Test]
+               public void StartLocationTest13 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+                       child3.MdiParent = main;
+
+                       child1.Visible = true;
+                       //child2.Visible = true;
+                       child3.Visible = true;
+
+                       main.Show ();
+                       
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual ("{X=0,Y=0}", child2.Location.ToString (), "#2");
+                       Assert.AreEqual ("{X=22,Y=22}", child3.Location.ToString (), "#3");
+
+                       child2.Visible = true;
+                       Assert.AreEqual ("{X=44,Y=44}", child2.Location.ToString (), "#4");
+
+                       child1.Visible = false;
+                       child1.Visible = true;
+                       Assert.AreEqual ("{X=66,Y=66}", child1.Location.ToString (), "#5");
+                       
+                       child3.Visible = true;
+                       Assert.AreEqual ("{X=22,Y=22}", child3.Location.ToString (), "#6");
+
+                       // MDI Child size does not seem to affect layout.
+                       // Size 500,500
+                       child2.Visible = false;
+                       child2.Size = new Size (500, 500);
+                       child2.Visible = true;
+                       Assert.AreEqual ("{X=88,Y=88}", child2.Location.ToString (), "#7");
+
+                       child2.Visible = false;
+                       child2.Visible = true;
+                       Assert.AreEqual ("{X=0,Y=0}", child2.Location.ToString (), "#8");
+                       
+                       child2.Visible = false;
+                       child2.Visible = true;
+                       Assert.AreEqual ("{X=22,Y=22}", child2.Location.ToString (), "#9");
+
+                       // Size 5,5
+                       child2.Visible = false;
+                       child2.Size = new Size (5, 5);
+                       child2.Visible = true;
+                       Assert.AreEqual ("{X=44,Y=44}", child2.Location.ToString (), "#10");
+
+                       child2.Visible = false;
+                       child2.Visible = true;
+                       Assert.AreEqual ("{X=66,Y=66}", child2.Location.ToString (), "#11");
+                       
+                       child2.Visible = false;
+                       child2.Visible = true;
+                       Assert.AreEqual ("{X=88,Y=88}", child2.Location.ToString (), "#12");
+
+                       child2.Visible = false;
+                       child2.Visible = true;
+                       Assert.AreEqual ("{X=0,Y=0}", child2.Location.ToString (), "#13");
+
+                       TearDown ();
+               }
+
+               [Category("NotWorking")]
+               [Test]
+               public void StartLocationTest14 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+                       child3.MdiParent = main;
+
+                       child2.StartPosition = FormStartPosition.Manual;
+                       child2.Location = new Point (44, 44);
+                       child1.Visible = true;
+                       child2.Visible = true;
+                       child3.Visible = true;
+
+                       main.Show ();
+                       
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual ("{X=44,Y=44}", child2.Location.ToString (), "#2");
+                       Assert.AreEqual ("{X=44,Y=44}", child3.Location.ToString (), "#3");
+
+                       child1.Visible = false;
+                       child1.Visible = true;
+                       Assert.AreEqual ("{X=66,Y=66}", child1.Location.ToString (), "#4");
+
+                       TearDown ();
+               }
+
+               [Category("NotWorking")]
+               [Test]
+               public void StartLocationTest15 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+                       child3.MdiParent = main;
+
+                       main.Show ();
+
+                       child1.Visible = true;
+                       child2.Visible = true;
+                       child2.Location = new Point (22, 44);
+                       child3.Visible = true;
+
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual ("{X=22,Y=44}", child2.Location.ToString (), "#2");
+                       Assert.AreEqual ("{X=44,Y=44}", child3.Location.ToString (), "#3");
+
+                       child1.Visible = false;
+                       child1.Visible = true;
+                       Assert.AreEqual ("{X=66,Y=66}", child1.Location.ToString (), "#4");
+
+                       TearDown ();
+               }
+
+               [Category("NotWorking")]
+               [Test]
+               public void StartLocationTest16 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+                       child3.MdiParent = main;
+
+                       child1.Visible = true;
+                       child2.Visible = true;
+                       child2.Location = new Point (22, 44);
+                       child3.Visible = true;
+
+                       main.Show ();
+                       
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual ("{X=22,Y=22}", child2.Location.ToString (), "#2");
+                       Assert.AreEqual ("{X=44,Y=44}", child3.Location.ToString (), "#3");
+
+                       child1.Visible = false;
+                       child1.Visible = true;
+                       Assert.AreEqual ("{X=66,Y=66}", child1.Location.ToString (), "#4");
+
+                       TearDown ();
+               }
+               
+               [Category("NotWorking")]
+               [Test]
+               public void StartLocationTest17 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+                       child3.MdiParent = main;
+
+                       child1.Visible = true;
+                       child2.Visible = true;
+
+                       main.Show ();
+                       
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual ("{X=22,Y=22}", child2.Location.ToString (), "#2");
+                       Assert.AreEqual ("{X=0,Y=0}", child3.Location.ToString (), "#3");
+
+                       child2.Visible = false;
+                       child3.Visible = true;
+
+                       Assert.AreEqual ("{X=44,Y=44}", child3.Location.ToString (), "#4");
+
+                       TearDown ();
+               }
+
+               [Category("NotWorking")]
+               [Test]
+               public void StartLocationTest18 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+                       child3.MdiParent = main;
+
+                       child1.Visible = true;
+                       child2.Visible = true;
+
+                       main.Show ();
+                       
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual ("{X=22,Y=22}", child2.Location.ToString (), "#2");
+                       Assert.AreEqual ("{X=0,Y=0}", child3.Location.ToString (), "#3");
+
+                       child2.Visible = false;
+                       child2.Close ();
+                       child2.Dispose ();
+                       child2 = null;
+
+                       child3.Visible = true;
+
+                       Assert.AreEqual ("{X=44,Y=44}", child3.Location.ToString (), "#4");
+
+                       TearDown ();
+               }
+
+               [Category("NotWorking")]                
+               [Test]
+               public void StartLocationTest19 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+                       child3.MdiParent = main;
+
+                       child1.Visible = true;
+                       child2.Visible = true;
+                       child3.Visible = true;
+
+                       child1.StartPosition = FormStartPosition.Manual;
+                       child2.StartPosition = FormStartPosition.Manual;
+                       child3.StartPosition = FormStartPosition.Manual;
+
+                       main.Show ();
+                       
+                       Assert.AreEqual ("{X=0,Y=0}", child1.Location.ToString (), "#1");
+                       Assert.AreEqual ("{X=0,Y=0}", child2.Location.ToString (), "#2");
+                       Assert.AreEqual ("{X=0,Y=0}", child3.Location.ToString (), "#3");
+
+                       TearDown ();
+               }
+*/
+               [Test]
+               public void StartSizeTest1 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+                       child3.MdiParent = main;
+
+                       main.Show ();
+                       
+                       Assert.AreEqual ("{Width=300, Height=300}", main.Size.ToString (), "#1");
+                       Assert.AreEqual ("{Width=300, Height=300}", child1.Size.ToString (), "#2");
+                       Assert.AreEqual ("{Width=300, Height=300}", child2.Size.ToString (), "#3");
+                       Assert.AreEqual ("{Width=300, Height=300}", child3.Size.ToString (), "#4");
+
+                       child1.Visible = true;
+                       child2.Visible = true;
+                       child3.Visible = true;
+
+                       Assert.AreEqual ("{Width=300, Height=300}", main.Size.ToString (), "#1");
+                       Assert.AreEqual ("{Width=300, Height=300}", child1.Size.ToString (), "#2");
+                       Assert.AreEqual ("{Width=300, Height=300}", child2.Size.ToString (), "#3");
+                       Assert.AreEqual ("{Width=300, Height=300}", child3.Size.ToString (), "#4");
+
+                       TearDown ();
+               }
+
+               [Test]
+               public void IsMdiContainerTest ()
+               {
+                       SetUp (false, true);
+
+                       main.Visible = true;
+                       main.Visible = false;
+                       
+                       main.IsMdiContainer = true;
+                       
+                       child1.MdiParent = main;
+
+                       main.IsMdiContainer = false;
+
+                       Assert.AreSame (null, main.ActiveMdiChild, "#1");
+
+                       main.Visible = true;
+                       Assert.AreSame (null, main.ActiveMdiChild, "#2");
+                       
+                       Assert.AreSame (null, main.MdiParent, "#3");
+
+                       TearDown ();
+               }
+
+               [Category("NotWorking")]
+               [Test]
+               [ExpectedException(typeof(ArgumentException), "Cannot add a top level control to a control.")]
+               public void AddToControlsTest ()
+               {
+                       SetUp (false, true);
+                       
+                       main.Visible = true;
+                       main.Visible = false;
+
+                       main.Controls.Add (child1);
+
+                       TearDown ();
+               }
+
                [Test]
                public void Text ()
                {
@@ -86,10 +903,56 @@ namespace MonoTests.System.Windows.Forms
                        main.Dispose ();
                }
 
-               // Setting WindowState to Maximized of a form, of which the handle is 
-               // already created, does not make it ActiveMdiChild
                [Test]
-               [Category ("NotWorking")]
+               public void Text_MdiContainer ()
+               {
+                       Form main = new Form ();
+                       main.ShowInTaskbar = false;
+                       main.Text = "main";
+                       main.IsMdiContainer = true;
+                       main.Show ();
+
+                       Assert.AreEqual ("main", main.Text, "#1");
+
+                       Form child = new Form ();
+                       child.Name = "child";
+                       child.MdiParent = main;
+                       child.Text = child.Name;
+                       child.WindowState = FormWindowState.Maximized;
+                       child.Show ();
+
+                       Assert.AreEqual ("main - [child]", main.Text, "#2");
+
+                       main.Dispose ();
+               }
+
+               [Test] // bug 80038
+               public void Text_ChildClose ()
+               {
+                       Form main = new Form ();
+                       main.ShowInTaskbar = false;
+                       main.IsMdiContainer = true;
+                       main.Text = "main";
+                       main.Show ();
+
+                       Assert.AreEqual ("main", main.Text, "#1");
+
+                       Form child = new Form ();
+                       child.Name = "child";
+                       child.MdiParent = main;
+                       child.Text = child.Name;
+                       child.WindowState = FormWindowState.Maximized;
+                       child.Show ();
+
+                       Assert.AreEqual ("main - [child]", main.Text, "#2");
+
+                       child.Close ();
+                       Assert.AreEqual ("main", main.Text, "#3");
+
+                       main.Dispose ();
+               }
+
+               [Test]
                public void Text_Maximized ()
                {
                        Form main = new Form ();
@@ -121,12 +984,30 @@ namespace MonoTests.System.Windows.Forms
                        child1.WindowState = FormWindowState.Maximized;
 
                        Assert.AreEqual ("main - [child1]", main.Text, "#4");
+
+                       main.Dispose ();
                }
+               
+               [Test]
+               [Category ("NotWorking")]
+               public void TopLevelTest ()
+               {
+                       Form main, child1;
 
-               // Form.ActiveMdiChild should return null if handle is not yet created
-               // Depends on fix for bug #80020
+                       main = new Form ();
+                       main.IsMdiContainer = true;
+                       main.Name = "main";
+
+                       child1 = new Form ();
+                       child1.Name = "child1";
+                       Assert.AreEqual (true, child1.TopLevel, "#01");
+                       child1.MdiParent = main;
+                       Assert.AreEqual (false, child1.TopLevel, "#02");
+                       
+                       child1.Dispose ();
+                       main.Dispose ();
+               }
                [Test]
-               [Category("NotWorking")]
                public void ActiveMdiChild ()
                {
                        Form main, child1, child2;
@@ -158,7 +1039,11 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreSame (child2, main.ActiveMdiChild, "#4");
 
                        main.Visible = false;
+#if NET_2_0
+                       Assert.IsNull (main.ActiveMdiChild, "#5");
+#else
                        Assert.AreSame (child2, main.ActiveMdiChild, "#5");
+#endif
 
                        child2.Dispose ();
                        child1.Dispose ();
@@ -166,6 +1051,44 @@ namespace MonoTests.System.Windows.Forms
                        main.Close();
                }
 
+               [Test]
+               public void ActiveMdiChild2 ()
+               {
+                       SetUp (false, false);
+
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+
+                       main.Show ();
+                       child1.Show ();
+                       child2.Show ();
+                       
+                       child1.Activate ();
+                       child1.Visible = false;
+                       
+                       Assert.AreSame (child2, main.ActiveMdiChild, "#1");
+
+                       TearDown ();
+               }
+
+               [Test]
+               public void ActiveMdiChild3 ()
+               {
+                       SetUp (false, false);
+                       
+                       child1.MdiParent = main;
+                       child2.MdiParent = main;
+
+                       main.Visible = true;
+                       main.Visible = false;
+
+                       Assert.AreSame (null, main.ActiveMdiChild, "#1");
+                       //child2.Visible = true; This will cause StackOverflowException on MS.
+                       main.Visible = true;
+                       Assert.AreSame (null, main.ActiveMdiChild, "#2");
+
+                       TearDown ();
+               }
                [Test]
                public void MdiChild_WindowState1 ()
                {
@@ -178,12 +1101,14 @@ namespace MonoTests.System.Windows.Forms
 
                                child1 = new Form ();
                                child1.Name = "child1";
+                               child1.Text = "child1";
                                child1.MdiParent = main;
                                child1.WindowState = FormWindowState.Maximized;
                                child1.Show ();
                                
                                child2 = new Form ();
                                child2.Name = "child2";
+                               child2.Text = "child2";
                                child2.MdiParent = main;
                                child2.Show();