Merge pull request #325 from adbre/iss5464
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ToolStripTest.cs
index a33b5072b96f701a76c74b2aaf420a8909a7530b..67ecf6250ed13d56534476294fdec3d1b58a7163 100644 (file)
@@ -39,7 +39,7 @@ using NUnit.Framework;
 namespace MonoTests.System.Windows.Forms
 {
        [TestFixture]
-       public class ToolStripTests
+       public class ToolStripTests : TestHelper
        {
                [Test]
                public void Constructor ()
@@ -48,15 +48,16 @@ namespace MonoTests.System.Windows.Forms
 
                        Assert.AreEqual (false, ts.AllowDrop, "A1");
                        //Assert.AreEqual (false, ts.AllowItemReorder, "A2");
-                       //Assert.AreEqual (true, ts.AllowMerge, "A3");
+                       Assert.AreEqual (true, ts.AllowMerge, "A3");
                        Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A4");
                        Assert.AreEqual (true, ts.AutoSize, "A5");
                        Assert.AreEqual (SystemColors.Control, ts.BackColor, "A6");
                        Assert.AreEqual (null, ts.BindingContext, "A7");
-                       //Assert.AreEqual (true, ts.CanOverflow, "A8");
+                       Assert.AreEqual (false, ts.CanSelect, "A7-1");
+                       Assert.AreEqual (true, ts.CanOverflow, "A8");
                        Assert.AreEqual (false, ts.CausesValidation, "A9");
                        Assert.AreEqual (Cursors.Default, ts.Cursor, "A10");
-                       //Assert.AreEqual (ToolStripDropDownDirection.BelowRight, ts.DefaultDropDownDirection, "A11");
+                       Assert.AreEqual (ToolStripDropDownDirection.BelowRight, ts.DefaultDropDownDirection, "A11");
                        Assert.AreEqual (new Rectangle (7, 0, 92, 25), ts.DisplayRectangle, "A12");
                        Assert.AreEqual (DockStyle.Top, ts.Dock, "A13");
                        Assert.AreEqual (new Font ("Tahoma", 8.25f), ts.Font, "A14");
@@ -74,13 +75,13 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual (null, ts.LayoutSettings, "A26");
                        Assert.AreEqual (ToolStripLayoutStyle.HorizontalStackWithOverflow, ts.LayoutStyle, "A27");
                        Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A28");
-                       //Assert.AreEqual ("System.Windows.Forms.ToolStripOverflowButton", ts.OverflowButton.ToString (), "A29");
+                       Assert.AreEqual ("System.Windows.Forms.ToolStripOverflowButton", ts.OverflowButton.GetType ().ToString (), "A29");
                        Assert.AreEqual ("System.Windows.Forms.ToolStripProfessionalRenderer", ts.Renderer.ToString (), "A30");
                        Assert.AreEqual (ToolStripRenderMode.ManagerRenderMode, ts.RenderMode, "A31");
                        Assert.AreEqual (true, ts.ShowItemToolTips, "A32");
                        Assert.AreEqual (false, ts.Stretch, "A33");
                        Assert.AreEqual (false, ts.TabStop, "A34");
-                       //Assert.AreEqual (ToolStripTextDirection.Horizontal, ts.TextDirection, "A35");
+                       Assert.AreEqual (ToolStripTextDirection.Horizontal, ts.TextDirection, "A35");
                        
                        ts = new ToolStrip (new ToolStripButton (), new ToolStripSeparator (), new ToolStripButton ());
                        Assert.AreEqual (3, ts.Items.Count, "A36");
@@ -89,8 +90,12 @@ namespace MonoTests.System.Windows.Forms
                [Test]
                public void ControlStyle ()
                {
+                       Form f = new Form ();
+                       f.ShowInTaskbar = false;
+                       
                        ExposeProtectedProperties epp = new ExposeProtectedProperties ();
-               
+                       f.Controls.Add (epp);
+                       
                        ControlStyles cs = ControlStyles.ContainerControl;
                        cs |= ControlStyles.UserPaint;
                        cs |= ControlStyles.StandardClick;
@@ -101,6 +106,21 @@ namespace MonoTests.System.Windows.Forms
                        cs |= ControlStyles.UseTextForAccessibility;
 
                        Assert.AreEqual (cs, epp.GetControlStyles (), "Styles");
+                       
+                       epp.TabStop = true;
+                       
+                       cs |= ControlStyles.Selectable;
+
+                       Assert.AreEqual (cs, epp.GetControlStyles (), "Styles-2");
+                       
+                       epp.TabStop = false;
+                       
+                       cs &= ~ControlStyles.Selectable;
+
+                       Assert.AreEqual (cs, epp.GetControlStyles (), "Styles-3");
+                       
+                       f.Close ();
+                       f.Dispose ();
                }
 
                [Test] // bug #80762
@@ -123,7 +143,13 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual (new Padding (0,0,1,0), epp.DefaultPadding, "C4");
                        Assert.AreEqual (true, epp.DefaultShowItemToolTips, "C5");
                        Assert.AreEqual (new Size (100, 25), epp.DefaultSize, "C6");
-                       //Assert.AreEqual (new Size (92, 25), epp.MaxItemSize, "C7");
+                       Assert.AreEqual (new Size (92, 25), epp.MaxItemSize, "C7");
+                       
+                       epp.Size = new Size (300, 100);
+                       Assert.AreEqual (new Size (292, 100), epp.MaxItemSize, "C8");
+                       
+                       epp.GripStyle = ToolStripGripStyle.Hidden;
+                       Assert.AreEqual (new Size (299, 100), epp.MaxItemSize, "C9");
                }
                
                [Test]
@@ -170,16 +196,16 @@ namespace MonoTests.System.Windows.Forms
                //        ts.AllowDrop = true;
                //}
 
-               //[Test]
-               //public void PropertyAllowMerge ()
-               //{
-               //        ToolStrip ts = new ToolStrip ();
-               //        EventWatcher ew = new EventWatcher (ts);
+               [Test]
+               public void PropertyAllowMerge ()
+               {
+                       ToolStrip ts = new ToolStrip ();
+                       EventWatcher ew = new EventWatcher (ts);
 
-               //        ts.AllowMerge = false;
-               //        Assert.AreEqual (false, ts.AllowMerge, "B1");
-               //        Assert.AreEqual (string.Empty, ew.ToString (), "B2");
-               //}
+                       ts.AllowMerge = false;
+                       Assert.AreEqual (false, ts.AllowMerge, "B1");
+                       Assert.AreEqual (string.Empty, ew.ToString (), "B2");
+               }
 
                [Test]
                public void PropertyAnchorAndDocking ()
@@ -543,15 +569,15 @@ namespace MonoTests.System.Windows.Forms
                //        Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B3");
                //}
 
-               //[Test]
-               //[ExpectedException (typeof (InvalidEnumArgumentException))]
-               //public void PropertyTextDirectionIEAE ()
-               //{
-               //        ToolStrip ts = new ToolStrip ();
-               //        EventWatcher ew = new EventWatcher (ts);
+               [Test]
+               [ExpectedException (typeof (InvalidEnumArgumentException))]
+               public void PropertyTextDirectionIEAE ()
+               {
+                       ToolStrip ts = new ToolStrip ();
+                       EventWatcher ew = new EventWatcher (ts);
 
-               //        ts.TextDirection = (ToolStripTextDirection) 42;
-               //}
+                       ts.TextDirection = (ToolStripTextDirection)42;
+               }
 
                [Test]
                [NUnit.Framework.Category ("NotWorking")]
@@ -635,29 +661,44 @@ namespace MonoTests.System.Windows.Forms
                        //Assert.AreEqual ("System.Windows.Forms.TableLayoutSettings", ts.PublicCreateLayoutSettings (ToolStripLayoutStyle.Table).ToString (), "A4");
                        Assert.AreEqual (null, ts.PublicCreateLayoutSettings (ToolStripLayoutStyle.VerticalStackWithOverflow), "A5");
                }
-               
+
                [Test]
-               public void MethodGetNextItem ()
+               public void MethodDipose()
                {
                        ToolStrip ts = new ToolStrip ();
-                       ts.Items.Add ("Test Item 1");
-                       
+                       ToolStripItem item_a = ts.Items.Add ("A");
+                       ToolStripItem item_b = ts.Items.Add ("B");
+                       ToolStripItem item_c = ts.Items.Add ("C");
 
-                       Assert.AreEqual (null, ts.GetNextItem (null, ArrowDirection.Right), "A1");
-                       Assert.AreEqual (null, ts.GetNextItem (ts.Items[0], ArrowDirection.Right), "A2");
+                       Assert.AreEqual (3, ts.Items.Count, "A1");
 
-                       ts.Items.Add ("Test Item 2");
-                       Assert.AreEqual (ts.Items[0], ts.GetNextItem (null, ArrowDirection.Right), "A3");
-                       Assert.AreEqual (ts.Items[0], ts.GetNextItem (ts.Items[0], ArrowDirection.Right), "A4");
+                       ts.Dispose ();
 
+                       Assert.AreEqual (0, ts.Items.Count, "A2");
+                       Assert.IsTrue (item_a.IsDisposed, "A3");
+                       Assert.IsTrue (item_b.IsDisposed, "A4");
+                       Assert.IsTrue (item_c.IsDisposed, "A5");
+               }
+
+               [Test]
+               public void MethodGetNextItem ()
+               {
+                       ToolStrip ts = new ToolStrip ();
+                       ts.Items.Add ("Test Item 1");
+                       
                        Form f = new Form ();
                        f.ShowInTaskbar = false;
                        f.Controls.Add (ts);
                        f.Show ();
+
+                       Assert.AreEqual (ts.Items[0], ts.GetNextItem (null, ArrowDirection.Right), "A1");
+                       Assert.AreEqual (ts.Items[0], ts.GetNextItem (ts.Items[0], ArrowDirection.Right), "A2");
+
+                       ts.Items.Add ("Test Item 2");
                        
-                       Assert.AreEqual (ts.Items[0], ts.GetNextItem (null, ArrowDirection.Right), "A5");
-                       Assert.AreEqual (ts.Items[1], ts.GetNextItem (ts.Items[0], ArrowDirection.Right), "A6");
-                       
+                       Assert.AreEqual (ts.Items[0], ts.GetNextItem (null, ArrowDirection.Right), "A3");
+                       Assert.AreEqual (ts.Items[1], ts.GetNextItem (ts.Items[0], ArrowDirection.Right), "A4");
+
                        f.Dispose ();
                }
                
@@ -669,6 +710,25 @@ namespace MonoTests.System.Windows.Forms
                        ts.GetNextItem (null, (ArrowDirection)42);
                }
                
+               [Test]
+               [NUnit.Framework.Category ("NotWorking")]
+               public void MethodResetMinimumSize ()
+               {
+                       ToolStrip ts = new ToolStrip ();
+                       ts.Size = new Size (600, 600);
+                       
+                       Assert.AreEqual (new Size (0, 0), ts.MinimumSize, "M0");
+                       
+                       ts.MinimumSize = new Size (400, 400);
+
+                       Assert.AreEqual (new Size (600, 600), ts.Size, "M1");
+                       Assert.AreEqual (new Size (400, 400), ts.MinimumSize, "M2");
+                       
+                       ts.ResetMinimumSize ();
+                       Assert.AreEqual (new Size (600, 600), ts.Size, "M3");
+                       Assert.AreEqual (new Size (-1, -1), ts.MinimumSize, "M4");
+               }
+               
                [Test]
                public void TestToolStrip ()
                {
@@ -780,7 +840,7 @@ namespace MonoTests.System.Windows.Forms
                        public new Padding DefaultPadding { get { return base.DefaultPadding; } }
                        public new bool DefaultShowItemToolTips { get { return base.DefaultShowItemToolTips; } }
                        public new Size DefaultSize { get { return base.DefaultSize; } }
-                       //public new Size MaxItemSize { get { return base.MaxItemSize; } }
+                       public new Size MaxItemSize { get { return base.MaxItemSize; } }
                        
                        public ControlStyles GetControlStyles ()
                        {