Merge pull request #325 from adbre/iss5464
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ToolStripControlHostTest.cs
index 2dcc27d660ffb700a256c05c7b62bb0bec71d19f..c5028d205347679457fbded29d6245be6d8acddf 100644 (file)
@@ -176,6 +176,19 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual (string.Empty, ew.ToString (), "B3");
                }
 
+               [Test]
+               public void PropertyDefaultSize ()
+               {
+                       VariableSizeControl c = new VariableSizeControl ();
+                       ExposeProtectedProperties epp = new ExposeProtectedProperties (c);
+
+                       Assert.AreEqual (new Size (-1, -1), epp.DefaultSize, "#A1");
+
+                       c.Size = new Size (666, 666);
+                       Assert.AreEqual (new Size (666, 666), c.Size, "#B99");
+                       Assert.AreEqual (new Size (666, 666), epp.DefaultSize, "#B1");
+               }
+
                [Test]
                public void PropertyEnabled ()
                {
@@ -432,7 +445,41 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual (new Size (100, 50), tsi.Size, "H10");
                        Assert.AreEqual (new Size (292, 53), ts.Size, "H11");
                }
-               
+
+               [Test]
+               public void MethodOnHostedControlResize ()
+               {
+                       ToolStripControlHostChild control_host = new ToolStripControlHostChild (new Control ());
+                       Control c = control_host.Control;
+
+                       Assert.AreEqual (false, control_host.OnHostedControlResizeFired, "#A1");
+
+                       c.Size = new Size (666, 666);
+                       Assert.AreEqual (true, control_host.OnHostedControlResizeFired, "#A2");
+               }
+
+               private class ToolStripControlHostChild : ToolStripControlHost {
+                       bool on_hosted_control_resize_fired;
+
+                       public ToolStripControlHostChild (Control c) : base (c)
+                       {
+                       }
+
+                       protected override void OnHostedControlResize (EventArgs e)
+                       {
+                               base.OnHostedControlResize (e);
+                               on_hosted_control_resize_fired = true;
+                       }
+
+                       public bool OnHostedControlResizeFired
+                       {
+                               get
+                               {
+                                       return on_hosted_control_resize_fired;
+                               }
+                       }
+               }
+
                private class EventWatcher
                {
                        private string events = string.Empty;
@@ -463,10 +510,25 @@ namespace MonoTests.System.Windows.Forms
                
                private class ExposeProtectedProperties : ToolStripControlHost
                {
+                       public ExposeProtectedProperties (Control c) : base (c) {}
                        public ExposeProtectedProperties () : base (new Control ()) {}
                        
                        public new Size DefaultSize { get { return base.DefaultSize; } }
                }
+
+               private class VariableSizeControl : Control 
+               {
+                       public override Size GetPreferredSize (Size proposedSize)
+                       {
+                               return new Size (999, 999);
+                       }
+
+                       protected override Size DefaultSize {
+                               get {
+                                       return new Size (-1, -1);
+                               }
+                       }
+               }
        }
 }
 #endif