* TestHelper.cs: Remove extraneous debug message
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / UserControlTest.cs
index a043ff49c92998015c8a36573a0150da926c527e..d86ebc4eb7cf012d93fb35abd48eea8741298152 100644 (file)
@@ -37,14 +37,14 @@ using System.ComponentModel;
 namespace MonoTests.System.Windows.Forms
 {
        [TestFixture]
-       public class UserControlTest
+       public class UserControlTest : TestHelper
        {
                UserControl uc = null;
 
                [SetUp]
-               public void SetUp()
-               {
+               protected override void SetUp () {
                        uc = new UserControl();
+                       base.SetUp ();
                }
 
                [Test]
@@ -70,6 +70,108 @@ namespace MonoTests.System.Windows.Forms
                {
                        uc.BorderStyle = (BorderStyle) 9999;
                }
+               
+               [Test]
+               public void MethodCreateParams ()
+               {
+                       ExposeProtectedProperties uc = new ExposeProtectedProperties ();
+
+                       Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_MAXIMIZEBOX | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_VISIBLE | WindowStyles.WS_CHILD, (WindowStyles)uc.CreateParams.Style, "D1");
+                       Assert.AreEqual (WindowExStyles.WS_EX_CONTROLPARENT, (WindowExStyles)uc.CreateParams.ExStyle, "D2");
+               }
+
+               private class ExposeProtectedProperties : UserControl
+               {
+                       public new CreateParams CreateParams { get { return base.CreateParams; } }
+               }
+
+               [Test]
+               public void AutoSize ()
+               {
+                       Form f = new Form ();
+                       f.ShowInTaskbar = false;
+
+                       Panel p = new Panel ();
+                       p.AutoSize = true;
+                       f.Controls.Add (p);
+
+                       Button b = new Button ();
+                       b.Size = new Size (200, 200);
+                       b.Location = new Point (200, 200);
+                       p.Controls.Add (b);
+
+                       f.Show ();
+
+                       Assert.AreEqual (new Size (403, 403), p.ClientSize, "A1");
+
+                       p.Controls.Remove (b);
+                       Assert.AreEqual (new Size (200, 100), p.ClientSize, "A2");
+
+                       p.AutoSizeMode = AutoSizeMode.GrowAndShrink;
+                       Assert.AreEqual (new Size (0, 0), p.ClientSize, "A3");
+                       
+                       f.Close ();
+               }
+
+               [Test]
+               public void PreferredSize ()
+               {
+                       Form f = new Form ();
+                       f.ShowInTaskbar = false;
+
+                       UserControl p = new UserControl ();
+                       f.Controls.Add (p);
+
+                       Button b1 = new Button ();
+                       b1.Size = new Size (200, 200);
+                       b1.Dock = DockStyle.Fill;
+                       p.Controls.Add (b1);
+
+                       Button b = new Button ();
+                       b.Size = new Size (100, 100);
+                       b.Dock = DockStyle.Top;
+                       p.Controls.Add (b);
+                       
+                       f.Show ();
+                       
+                       Assert.AreEqual (new Size (0, 100), p.PreferredSize, "A1");
+                       
+                       b1.Dock = DockStyle.Left;
+                       Assert.AreEqual (new Size (200, 100), p.PreferredSize, "A2");
+
+                       b1.Dock = DockStyle.None;
+                       Assert.AreEqual (new Size (203, 203), p.PreferredSize, "A3");
+
+                       b1.Dock = DockStyle.Fill;
+                       b.Dock = DockStyle.Fill;
+                       Assert.AreEqual (new Size (0, 0), p.PreferredSize, "A4");
+                       
+                       b1.Dock = DockStyle.Top;
+                       b.Dock = DockStyle.Left;
+
+                       Assert.AreEqual (new Size (100, 200), p.PreferredSize, "A5");
+               
+                       Button b2 = new Button ();
+                       b2.Size = new Size (50, 50);
+                       p.Controls.Add (b2);
+
+                       Assert.AreEqual (new Size (100, 200), p.PreferredSize, "A6");
+                       
+                       b2.Left = 300;
+                       Assert.AreEqual (new Size (353, 200), p.PreferredSize, "A7");
+
+                       b2.Top = 300;
+                       Assert.AreEqual (new Size (353, 353), p.PreferredSize, "A8");
+
+                       b2.Anchor = AnchorStyles.Bottom;
+                       Assert.AreEqual (new Size (100, 200), p.PreferredSize, "A9");
+
+                       b2.Anchor = AnchorStyles.Left;
+                       Assert.AreEqual (new Size (353, 353), p.PreferredSize, "A10");
+                       
+                       f.Dispose ();
+               }
+       
 #endif 
        }
 }