* TestHelper.cs: Remove extraneous debug message
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ControlTest.cs
index 67a6477be9eed120d5a7c5fd2aa5601dc86d971d..632d70123adb111e391e1eb8d1ff072f7f6c10ea 100644 (file)
@@ -24,7 +24,7 @@ using CategoryAttribute = NUnit.Framework.CategoryAttribute;
 namespace MonoTests.System.Windows.Forms
 {
        [TestFixture]
-       public class ControlTest
+       public class ControlTest : TestHelper
        {
                [Test] // .ctor ()
                public void Constructor1 ()
@@ -344,7 +344,7 @@ namespace MonoTests.System.Windows.Forms
                                control.InvokeCreateHandle ();
                                Assert.Fail ("#4");
                        } catch (ObjectDisposedException ex) {
-                               Console.WriteLine (ex);
+                               //Console.WriteLine (ex);
                        }
                }
 
@@ -655,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]
@@ -667,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]
@@ -1241,6 +1247,8 @@ namespace MonoTests.System.Windows.Forms
 
                        Assert.AreEqual (f, c.TopLevelControl, "T3");
                        Assert.AreEqual (f, f.TopLevelControl, "T4");
+                       
+                       f.Dispose ();
                }
 
                [Test]
@@ -2327,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
@@ -2810,6 +2820,8 @@ namespace MonoTests.System.Windows.Forms
                        c.Visible = true;
                        
                        Assert.AreEqual (f.ClientSize.Width, c.Width, "L1");
+                       
+                       f.Dispose ();
                }
                
                [Test]
@@ -2865,10 +2877,32 @@ namespace MonoTests.System.Windows.Forms
 
                        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 ()
@@ -2918,11 +2952,13 @@ namespace MonoTests.System.Windows.Forms
                        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 ()
@@ -2972,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;
@@ -3054,7 +3100,7 @@ namespace MonoTests.System.Windows.Forms
        }
 
        [TestFixture]
-       public class ControlWMTest
+       public class ControlWMTest : TestHelper
        {
                [Test]
                public void WM_PARENTNOTIFY_Test ()
@@ -3159,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