* TestHelper.cs: Remove extraneous debug message
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ControlTest.cs
index b1fe2d60698d0fa74bec006b67c42db498d8b0d6..632d70123adb111e391e1eb8d1ff072f7f6c10ea 100644 (file)
@@ -24,9 +24,337 @@ using CategoryAttribute = NUnit.Framework.CategoryAttribute;
 namespace MonoTests.System.Windows.Forms
 {
        [TestFixture]
-       public class ControlTest
+       public class ControlTest : TestHelper
        {
-               
+               [Test] // .ctor ()
+               public void Constructor1 ()
+               {
+                       MockControl c = new MockControl ();
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "Height");
+                       Assert.AreEqual (0, c.Left, "Left");
+                       Assert.AreEqual (string.Empty, c.Name, "Name");
+                       Assert.IsNull (c.Parent, "Parent");
+                       Assert.AreEqual (string.Empty, c.Text, "#A:Text");
+                       Assert.AreEqual (0, c.Top, "Top");
+                       Assert.AreEqual (0, c.Width, "Width");
+               }
+
+               [Test] // .ctor (String)
+               public void Constructor2 ()
+               {
+                       MockControl c = new MockControl ((string) null);
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#A:Height");
+                       Assert.AreEqual (0, c.Left, "#A:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#A:Name");
+                       Assert.IsNull (c.Parent, "#A:Parent");
+                       Assert.AreEqual (string.Empty, c.Text, "#A:Text");
+                       Assert.AreEqual (0, c.Top, "#A:Top");
+                       Assert.AreEqual (0, c.Width, "#A:Width");
+
+                       c = new MockControl ("child");
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#B:Height");
+                       Assert.AreEqual (0, c.Left, "#B:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#B:Name");
+                       Assert.IsNull (c.Parent, "#B:Parent");
+                       Assert.AreEqual ("child", c.Text, "#B:Text");
+                       Assert.AreEqual (0, c.Top, "#B:Top");
+                       Assert.AreEqual (0, c.Width, "#B:Width");
+               }
+
+               [Test] // .ctor (Control, String)
+               public void Constructor3 ()
+               {
+                       Control parent = new Control ("parent");
+                       MockControl c = new MockControl ((Control) null, (string) null);
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#A:Height");
+                       Assert.AreEqual (0, c.Left, "#A:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#A:Name");
+                       Assert.IsNull (c.Parent, "#A:Parent");
+                       Assert.AreEqual (string.Empty, c.Text, "#A:Text");
+                       Assert.AreEqual (0, c.Top, "#A:Top");
+                       Assert.AreEqual (0, c.Width, "#A:Width");
+
+                       c = new MockControl ((Control) null, "child");
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#B:Height");
+                       Assert.AreEqual (0, c.Left, "#B:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#B:Name");
+                       Assert.IsNull (c.Parent, "#B:Parent");
+                       Assert.AreEqual ("child", c.Text, "#B:Text");
+                       Assert.AreEqual (0, c.Top, "#B:Top");
+                       Assert.AreEqual (0, c.Width, "#B:Width");
+
+                       c = new MockControl (parent, (string) null);
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#C:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#C:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#C:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#C:Height");
+                       Assert.AreEqual (0, c.Left, "#C:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#C:Name");
+                       Assert.AreSame (parent, c.Parent, "#C:Parent");
+                       Assert.AreEqual (string.Empty, c.Text, "#C:Text");
+                       Assert.AreEqual (0, c.Top, "#C:Top");
+                       Assert.AreEqual (0, c.Width, "#C:Width");
+
+                       c = new MockControl (parent, "child");
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#D:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#D:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#D:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#D:Height");
+                       Assert.AreEqual (0, c.Left, "#D:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#D:Name");
+                       Assert.AreSame (parent, c.Parent, "#D:Parent");
+                       Assert.AreEqual ("child", c.Text, "#D:Text");
+                       Assert.AreEqual (0, c.Top, "#D:Top");
+                       Assert.AreEqual (0, c.Width, "#D:Width");
+               }
+
+               [Test] // .ctor (String, Int32, Int32, Int32, Int32)
+               public void Constructor4 ()
+               {
+                       MockControl c = new MockControl ((string) null, 0, 0, 0, 0);
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#A:Height");
+                       Assert.AreEqual (0, c.Left, "#A:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#A:Name");
+                       Assert.IsNull (c.Parent, "#A:Parent");
+                       Assert.AreEqual (string.Empty, c.Text, "#A:Text");
+                       Assert.AreEqual (0, c.Top, "#A:Top");
+                       Assert.AreEqual (0, c.Width, "#A:Width");
+
+                       c = new MockControl ((string) null, 1, 0, 0, 0);
+
+                       Assert.AreEqual (1, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#B:Height");
+                       Assert.AreEqual (1, c.Left, "#B:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#B:Name");
+                       Assert.IsNull (c.Parent, "#B:Parent");
+                       Assert.AreEqual (string.Empty, c.Text, "#B:Text");
+                       Assert.AreEqual (0, c.Top, "#B:Top");
+                       Assert.AreEqual (0, c.Width, "#B:Width");
+
+                       c = new MockControl ("child", 0, 1, 0, 0);
+
+                       Assert.AreEqual (1, c.OnLocationChangedCount, "#C:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#C:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#C:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#C:Height");
+                       Assert.AreEqual (0, c.Left, "#C:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#C:Name");
+                       Assert.IsNull (c.Parent, "#C:Parent");
+                       Assert.AreEqual ("child", c.Text, "#C:Text");
+                       Assert.AreEqual (1, c.Top, "#C:Top");
+                       Assert.AreEqual (0, c.Width, "#C:Width");
+
+                       c = new MockControl ("child", 0, 0, 1, 0);
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#D:OnLocationChangedCount");
+                       Assert.AreEqual (1, c.OnResizeCount, "#D:OnResizeCount");
+                       Assert.AreEqual (1, c.OnSizeChangedCount, "#D:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#D:Height");
+                       Assert.AreEqual (0, c.Left, "#D:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#D:Name");
+                       Assert.IsNull (c.Parent, "#D:Parent");
+                       Assert.AreEqual ("child", c.Text, "#D:Text");
+                       Assert.AreEqual (0, c.Top, "#D:Top");
+                       Assert.AreEqual (1, c.Width, "#D:Width");
+
+                       c = new MockControl ("child", 0, 0, 0, 1);
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#E:OnLocationChangedCount");
+                       Assert.AreEqual (1, c.OnResizeCount, "#E:OnResizeCount");
+                       Assert.AreEqual (1, c.OnSizeChangedCount, "#E:OnSizeChangedCount");
+                       Assert.AreEqual (1, c.Height, "#E:Height");
+                       Assert.AreEqual (0, c.Left, "#E:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#E:Name");
+                       Assert.IsNull (c.Parent, "#E:Parent");
+                       Assert.AreEqual ("child", c.Text, "#E:Text");
+                       Assert.AreEqual (0, c.Top, "#E:Top");
+                       Assert.AreEqual (0, c.Width, "#E:Width");
+
+                       c = new MockControl ("child", 1, 0, 1, 0);
+
+                       Assert.AreEqual (1, c.OnLocationChangedCount, "#F:OnLocationChangedCount");
+                       Assert.AreEqual (1, c.OnResizeCount, "#F:OnResizeCount");
+                       Assert.AreEqual (1, c.OnSizeChangedCount, "#F:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#F:Height");
+                       Assert.AreEqual (1, c.Left, "#F:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#F:Name");
+                       Assert.IsNull (c.Parent, "#F:Parent");
+                       Assert.AreEqual ("child", c.Text, "#F:Text");
+                       Assert.AreEqual (0, c.Top, "#F:Top");
+                       Assert.AreEqual (1, c.Width, "#F:Width");
+
+                       c = new MockControl ("child", 0, 1, 0, 1);
+
+                       Assert.AreEqual (1, c.OnLocationChangedCount, "#G:OnLocationChangedCount");
+                       Assert.AreEqual (1, c.OnResizeCount, "#G:OnResizeCount");
+                       Assert.AreEqual (1, c.OnSizeChangedCount, "#G:OnSizeChangedCount");
+                       Assert.AreEqual (1, c.Height, "#G:Height");
+                       Assert.AreEqual (0, c.Left, "#G:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#G:Name");
+                       Assert.IsNull (c.Parent, "#G:Parent");
+                       Assert.AreEqual ("child", c.Text, "#G:Text");
+                       Assert.AreEqual (1, c.Top, "#G:Top");
+                       Assert.AreEqual (0, c.Width, "#G:Width");
+               }
+
+               [Test] // .ctor (Control, String, Int32, Int32, Int32, Int32)
+               public void Constructor5 ()
+               {
+                       Control parent = new Control ("parent");
+                       MockControl c = new MockControl ((Control) null,
+                               (string) null, 0, 0, 0, 0);
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#A:Height");
+                       Assert.AreEqual (0, c.Left, "#A:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#A:Name");
+                       Assert.IsNull (c.Parent, "#A:Parent");
+                       Assert.AreEqual (string.Empty, c.Text, "#A:Text");
+                       Assert.AreEqual (0, c.Top, "#A:Top");
+                       Assert.AreEqual (0, c.Width, "#A:Width");
+
+                       c = new MockControl (parent, (string) null, 1, 0, 0, 0);
+
+                       Assert.AreEqual (1, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#B:Height");
+                       Assert.AreEqual (1, c.Left, "#B:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#B:Name");
+                       Assert.AreSame (parent, c.Parent, "#B:Parent");
+                       Assert.AreEqual (string.Empty, c.Text, "#B:Text");
+                       Assert.AreEqual (0, c.Top, "#B:Top");
+                       Assert.AreEqual (0, c.Width, "#B:Width");
+
+                       c = new MockControl ((Control) null, "child", 0, 1, 0, 0);
+
+                       Assert.AreEqual (1, c.OnLocationChangedCount, "#C:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#C:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#C:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#C:Height");
+                       Assert.AreEqual (0, c.Left, "#C:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#C:Name");
+                       Assert.IsNull (c.Parent, "#C:Parent");
+                       Assert.AreEqual ("child", c.Text, "#C:Text");
+                       Assert.AreEqual (1, c.Top, "#C:Top");
+                       Assert.AreEqual (0, c.Width, "#C:Width");
+
+                       c = new MockControl (parent, "child", 0, 0, 1, 0);
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#D:OnLocationChangedCount");
+                       Assert.AreEqual (1, c.OnResizeCount, "#D:OnResizeCount");
+                       Assert.AreEqual (1, c.OnSizeChangedCount, "#D:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#D:Height");
+                       Assert.AreEqual (0, c.Left, "#D:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#D:Name");
+                       Assert.AreSame (parent, c.Parent, "#D:Parent");
+                       Assert.AreEqual ("child", c.Text, "#D:Text");
+                       Assert.AreEqual (0, c.Top, "#D:Top");
+                       Assert.AreEqual (1, c.Width, "#D:Width");
+
+                       c = new MockControl (parent, "child", 0, 0, 0, 1);
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#E:OnLocationChangedCount");
+                       Assert.AreEqual (1, c.OnResizeCount, "#E:OnResizeCount");
+                       Assert.AreEqual (1, c.OnSizeChangedCount, "#E:OnSizeChangedCount");
+                       Assert.AreEqual (1, c.Height, "#E:Height");
+                       Assert.AreEqual (0, c.Left, "#E:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#E:Name");
+                       Assert.AreSame (parent, c.Parent, "#E:Parent");
+                       Assert.AreEqual ("child", c.Text, "#E:Text");
+                       Assert.AreEqual (0, c.Top, "#E:Top");
+                       Assert.AreEqual (0, c.Width, "#E:Width");
+
+                       c = new MockControl (parent, "child", 1, 0, 1, 0);
+
+                       Assert.AreEqual (1, c.OnLocationChangedCount, "#F:OnLocationChangedCount");
+                       Assert.AreEqual (1, c.OnResizeCount, "#F:OnResizeCount");
+                       Assert.AreEqual (1, c.OnSizeChangedCount, "#F:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#F:Height");
+                       Assert.AreEqual (1, c.Left, "#F:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#F:Name");
+                       Assert.AreSame (parent, c.Parent, "#F:Parent");
+                       Assert.AreEqual ("child", c.Text, "#F:Text");
+                       Assert.AreEqual (0, c.Top, "#F:Top");
+                       Assert.AreEqual (1, c.Width, "#F:Width");
+
+                       c = new MockControl (parent, "child", 0, 1, 0, 1);
+
+                       Assert.AreEqual (1, c.OnLocationChangedCount, "#G:OnLocationChangedCount");
+                       Assert.AreEqual (1, c.OnResizeCount, "#G:OnResizeCount");
+                       Assert.AreEqual (1, c.OnSizeChangedCount, "#G:OnSizeChangedCount");
+                       Assert.AreEqual (1, c.Height, "#G:Height");
+                       Assert.AreEqual (0, c.Left, "#G:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#G:Name");
+                       Assert.AreSame (parent, c.Parent, "#G:Parent");
+                       Assert.AreEqual ("child", c.Text, "#G:Text");
+                       Assert.AreEqual (1, c.Top, "#G:Top");
+                       Assert.AreEqual (0, c.Width, "#G:Width");
+               }
+
+               [Test]
+               public void DisposeTest ()
+               {
+                       ControlDisposeTester control = new ControlDisposeTester ();
+                       control.Visible = true;
+                       control.Dispose ();
+
+                       try {
+                               control.CreateControl ();
+                       } catch (ObjectDisposedException ex) {
+                               Console.WriteLine (ex);
+                               Assert.Fail ("#1");
+                       }
+                       Assert.IsFalse (control.IsHandleCreated, "#2");
+
+                       // The control remains Visible until WM_DESTROY is received.
+                       Assert.IsTrue (control.Visible, "#3");
+
+                       try {
+                               control.InvokeCreateHandle ();
+                               Assert.Fail ("#4");
+                       } catch (ObjectDisposedException ex) {
+                               //Console.WriteLine (ex);
+                       }
+               }
+
+               private class ControlDisposeTester : Control
+               {
+                       public void InvokeCreateHandle ()
+                       {
+                               CreateHandle ();
+                       }
+               }
 #if NET_2_0
                [Test]
                public void AutoSizeTest ()
@@ -327,6 +655,9 @@ namespace MonoTests.System.Windows.Forms
                        Control.ControlCollection c = new Control.ControlCollection (frm);
                        child.MdiParent = frm;
                        c.Add (child);
+                       
+                       child.Dispose ();
+                       frm.Dispose ();
                }
 
                [Test]
@@ -339,6 +670,9 @@ namespace MonoTests.System.Windows.Forms
                        Control.ControlCollection c = new Control.ControlCollection (frm);
                        //child.MdiParent = frm;
                        c.Add (child);
+                       
+                       child.Dispose ();
+                       frm.Dispose ();                 
                }
                
                [Test]
@@ -913,6 +1247,8 @@ namespace MonoTests.System.Windows.Forms
 
                        Assert.AreEqual (f, c.TopLevelControl, "T3");
                        Assert.AreEqual (f, f.TopLevelControl, "T4");
+                       
+                       f.Dispose ();
                }
 
                [Test]
@@ -1936,7 +2272,6 @@ namespace MonoTests.System.Windows.Forms
                }
 
                [Test] // bug #330501
-               [Category ("NotWorking")]
                public void OnValidating_Parent_Close ()
                {
                        MockControl control = new MockControl ();
@@ -1946,11 +2281,9 @@ namespace MonoTests.System.Windows.Forms
                        f.ShowInTaskbar = false;
 
                        f.Show ();
-                       Assert.AreEqual (0, control.ValidatingCount, "#A1");
-                       Assert.IsTrue (control.Focused, "#A2");
+                       Assert.AreEqual (0, control.OnValidatingCount, "#A1");
                        f.Close ();
-                       Assert.AreEqual (1, control.ValidatingCount, "#B1");
-                       Assert.IsFalse (control.Focused, "#B2");
+                       Assert.AreEqual (1, control.OnValidatingCount, "#A2");
                        f.Dispose ();
                }
 
@@ -2002,6 +2335,8 @@ namespace MonoTests.System.Windows.Forms
                        form.Controls.Add (l);
                        Assert.AreEqual (0, l.Left, "#A3");
                        Assert.AreEqual (0, l.Top, "#A4");
+                       
+                       form.Dispose ();
                }
 
 #if NET_2_0
@@ -2072,16 +2407,62 @@ namespace MonoTests.System.Windows.Forms
 
                public class MockControl : Control
                {
-                       public int font_height {
+                       public int OnValidatingCount;
+                       public int OnSizeChangedCount;
+                       public int OnResizeCount;
+                       public int OnLocationChangedCount;
+
+                       public MockControl ()
+                       {
+                       }
+
+                       public MockControl (string text)
+                               : base (text)
+                       {
+                       }
+
+                       public MockControl (Control parent, string text)
+                               : base (parent, text)
+                       {
+                       }
+
+                       public MockControl (string text, int left, int top, int width, int height)
+                               : base (text, left, top, width, height)
+                       {
+                       }
+
+                       public MockControl (Control parent, string text, int left, int top, int width, int height)
+                               : base (parent, text, left, top, width, height)
+                       {
+                       }
+
+                       public int font_height
+                       {
                                get { return base.FontHeight; }
                                set { base.FontHeight = value; }
                        }
 
-                       public int ValidatingCount;
+                       protected override void OnLocationChanged (EventArgs e)
+                       {
+                               OnLocationChangedCount++;
+                               base.OnLocationChanged (e);
+                       }
+
+                       protected override void OnSizeChanged (EventArgs e)
+                       {
+                               OnSizeChangedCount++;
+                               base.OnSizeChanged (e);
+                       }
+
+                       protected override void OnResize (EventArgs e)
+                       {
+                               OnResizeCount++;
+                               base.OnResize (e);
+                       }
 
                        protected override void OnValidating (CancelEventArgs e)
                        {
-                               ValidatingCount++;
+                               OnValidatingCount++;
                        }
                }
 
@@ -2439,6 +2820,8 @@ namespace MonoTests.System.Windows.Forms
                        c.Visible = true;
                        
                        Assert.AreEqual (f.ClientSize.Width, c.Width, "L1");
+                       
+                       f.Dispose ();
                }
                
                [Test]
@@ -2484,10 +2867,42 @@ namespace MonoTests.System.Windows.Forms
                        foreach (Control c1 in c.Controls)
                                c.Controls.Remove (c1);
                }
+               
+               [Test]
+               public void MethodSetBounds ()
+               {
+                       Control myControl = new Control();
+                       myControl.SetBounds(10, 20, 30, 40);
+                       myControl.SetBounds(50, 60, 70, 70, BoundsSpecified.Location);
+
+                       Assert.AreEqual (new Rectangle (50, 60, 30, 40), myControl.Bounds, "A1");
+               }
+               
+               [Test]
+               public void Bug386450 ()
+               {
+                       // Should not crash.  We have to check for the font object
+                       // being different, not just if they represent the same font.
+                       Form f = new Form ();
+                       Label l = new Label ();
+                       l.Text = "Hello";
+
+                       Font f1 = new Font ("Arial", 12);
+                       Font f2 = new Font ("Arial", 12);
+
+                       l.Font = f1;
+                       l.Font = f2;
+
+                       f1.Dispose ();
+
+                       f.Controls.Add (l);
+                       f.Show ();
+                       f.Dispose ();
+               }
        }
 
        [TestFixture]
-       public class ControlSetTopLevelTest
+       public class ControlSetTopLevelTest : TestHelper
        {
                class ControlPoker : Control {
                        public void DoSetTopLevel ()
@@ -2529,19 +2944,21 @@ namespace MonoTests.System.Windows.Forms
                        f.Controls.Add(f1);
                }
                
-               [Category ("NotWorking")]
                [Test]
+               [Category ("NotWorking")]
                public void TestForm ()
                {
                        Form f = new Form ();
                        Assert.IsFalse (f.Visible, "3");
                        f.TopLevel = true;
                        Assert.IsFalse (f.Visible, "4");
+                       
+                       f.Dispose ();
                }
        }
 
        [TestFixture]
-       public class ControlResizeLayoutTest
+       public class ControlResizeLayoutTest : TestHelper
        {
                class ControlPoker : Control {
                        public void DoOnResize ()
@@ -2591,7 +3008,17 @@ namespace MonoTests.System.Windows.Forms
 
        [TestFixture]
        [Category ("NotWorking")]
-       public class ControlInvokeTest {
+       public class ControlInvokeTest  : TestHelper {
+
+               [TearDown]
+               protected override void TearDown ()
+               {
+                       if (f != null && !f.IsDisposed)                 
+                               f.Dispose ();
+                       base.TearDown ();
+               }
+
+               
                public delegate void TestDelegate ();
 
                Form f;
@@ -2673,7 +3100,7 @@ namespace MonoTests.System.Windows.Forms
        }
 
        [TestFixture]
-       public class ControlWMTest
+       public class ControlWMTest : TestHelper
        {
                [Test]
                public void WM_PARENTNOTIFY_Test ()
@@ -2778,12 +3205,13 @@ namespace MonoTests.System.Windows.Forms
 
 #if NET_2_0
        [TestFixture]
-       public class ControlLayoutTest
+       public class ControlLayoutTest : TestHelper
        {
-               [Test]
-               public void SetUp ()
+               [SetUp]
+               protected override void SetUp ()
                {
                        _layoutCount = 0;
+                       base.SetUp ();
                }
 
                [Test] // bug #80456