Merge pull request #325 from adbre/iss5464
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ToolStripTest.cs
index df50130f59ef717c97a26a126f00765636c12ea6..67ecf6250ed13d56534476294fdec3d1b58a7163 100644 (file)
 // Authors:
 //     Jonathan Pobst (monkey@jpobst.com)
 //
+
 #if NET_2_0
 using System;
 using System.Collections.Generic;
-using System.Text;
-using NUnit.Framework;
+using System.ComponentModel;
 using System.Drawing;
+using System.Text;
 using System.Windows.Forms;
-using System.ComponentModel;
+
+using NUnit.Framework;
 
 namespace MonoTests.System.Windows.Forms
 {
        [TestFixture]
-       public class ToolStripTests
+       public class ToolStripTests : TestHelper
        {
                [Test]
                public void Constructor ()
@@ -46,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");
@@ -72,24 +75,27 @@ 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");
                }
 
                [Test]
-               [Ignore ("OptimizedDoubleBuffer is disabled due to bug #80447")]
                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;
@@ -99,7 +105,31 @@ namespace MonoTests.System.Windows.Forms
                        cs |= ControlStyles.OptimizedDoubleBuffer;
                        cs |= ControlStyles.UseTextForAccessibility;
 
-                       Assert.AreEqual (cs, epp.GetControlStyles (), "Styles");                
+                       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
+               public void DockSize ()
+               {
+                       ToolStrip ts = new ToolStrip();
+                       Assert.AreEqual (new Size (100, 25), ts.Size, "#1");
+                       ts.Dock = DockStyle.None;
+                       Assert.AreEqual (new Size (100, 25), ts.Size, "#2");
                }
 
                [Test]
@@ -113,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]
@@ -160,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 ()
@@ -208,7 +244,6 @@ namespace MonoTests.System.Windows.Forms
                }
 
                [Test]
-               //[Ignore ("Needs Control.AutoSizeChanged to fire")]
                public void PropertyAutoSize ()
                {
                        ToolStrip ts = new ToolStrip ();
@@ -246,16 +281,16 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual (string.Empty, ew.ToString (), "B2");
                }
 
-               //[Test]
-               //public void PropertyCanOverflow ()
-               //{
-               //        ToolStrip ts = new ToolStrip ();
-               //        EventWatcher ew = new EventWatcher (ts);
+               [Test]
+               public void PropertyCanOverflow ()
+               {
+                       ToolStrip ts = new ToolStrip ();
+                       EventWatcher ew = new EventWatcher (ts);
 
-               //        ts.CanOverflow = false;
-               //        Assert.AreEqual (false, ts.CanOverflow, "B1");
-               //        Assert.AreEqual (string.Empty, ew.ToString (), "B2");
-               //}
+                       ts.CanOverflow = false;
+                       Assert.AreEqual (false, ts.CanOverflow, "B1");
+                       Assert.AreEqual (string.Empty, ew.ToString (), "B2");
+               }
 
                [Test]
                public void PropertyCausesValidation ()
@@ -287,26 +322,26 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual (string.Empty, ew.ToString (), "B3");
                }
 
-               //[Test]
-               //public void PropertyDefaultDropDownDirection ()
-               //{
-               //        ToolStrip ts = new ToolStrip ();
-               //        EventWatcher ew = new EventWatcher (ts);
+               [Test]
+               public void PropertyDefaultDropDownDirection ()
+               {
+                       ToolStrip ts = new ToolStrip ();
+                       EventWatcher ew = new EventWatcher (ts);
 
-               //        ts.DefaultDropDownDirection = ToolStripDropDownDirection.AboveLeft;
-               //        Assert.AreEqual (ToolStripDropDownDirection.AboveLeft, ts.DefaultDropDownDirection, "B1");
-               //        Assert.AreEqual (string.Empty, ew.ToString (), "B2");
-               //}
+                       ts.DefaultDropDownDirection = ToolStripDropDownDirection.AboveLeft;
+                       Assert.AreEqual (ToolStripDropDownDirection.AboveLeft, ts.DefaultDropDownDirection, "B1");
+                       Assert.AreEqual (string.Empty, ew.ToString (), "B2");
+               }
 
-               //[Test]
-               //[ExpectedException (typeof (InvalidEnumArgumentException))]
-               //public void PropertyDefaultDropDownDirectionIEAE ()
-               //{
-               //        ToolStrip ts = new ToolStrip ();
-               //        EventWatcher ew = new EventWatcher (ts);
+               [Test]
+               [ExpectedException (typeof (InvalidEnumArgumentException))]
+               public void PropertyDefaultDropDownDirectionIEAE ()
+               {
+                       ToolStrip ts = new ToolStrip ();
+                       EventWatcher ew = new EventWatcher (ts);
 
-               //        ts.DefaultDropDownDirection = (ToolStripDropDownDirection) 42;
-               //}
+                       ts.DefaultDropDownDirection = (ToolStripDropDownDirection)42;
+               }
 
                [Test]
                [ExpectedException (typeof (InvalidEnumArgumentException))]
@@ -534,19 +569,166 @@ 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")]
+               public void BehaviorDisplayRectangleAndOverflow ()
+               {
+                       // WM decoration size dependent
+                       Form f = new Form ();
+                       f.ShowInTaskbar = false;
+                       ToolStrip ts = new ToolStrip ();
+                       f.Controls.Add (ts);
+                       f.Show ();
+
+                       Assert.AreEqual (false, ts.OverflowButton.Visible, "D1");
+                       Assert.AreEqual (new Rectangle (7, 0, 284, 25), ts.DisplayRectangle, "D2");
+
+                       ts.Items.Add (new ToolStripButton ("hello11111111111"));
+                       ts.Items.Add (new ToolStripButton ("hello11111111111"));
+                       ts.Items.Add (new ToolStripButton ("hello11111111111"));
+                       ts.Items.Add (new ToolStripButton ("hello11111111111"));
+                       ts.Items.Add (new ToolStripButton ("hello11111111111"));
+                       ts.Items.Add (new ToolStripButton ("hello11111111111"));
+                       
+                       Assert.AreEqual (true, ts.OverflowButton.Visible, "D3");
+                       Assert.AreEqual (new Rectangle (7, 0, 284, 25), ts.DisplayRectangle, "D4");
+                       f.Dispose ();
+               }
+       
+               [Test]
+               public void BehaviorGripAndOverflowWithFlowLayout ()
+               {
+                       ToolStrip ts = new ToolStrip ();
+                       ts.LayoutStyle = ToolStripLayoutStyle.Flow;
+                       
+                       Assert.AreEqual (ToolStripGripStyle.Visible, ts.GripStyle, "A1");
+                       Assert.AreEqual (false, ts.OverflowButton.Visible, "A2");
+                       Assert.AreEqual ("System.Windows.Forms.Layout.FlowLayout", ts.LayoutEngine.ToString (), "A3");                  
+               }
+       
+               [Test]
+               public void BehaviorDockAndOrientation ()
+               {
+                       Form f = new Form ();
+                       f.ShowInTaskbar = false;
+                       
+                       ToolStrip ts = new ToolStrip ();
+                       ts.Dock = DockStyle.Left;
+                       
+                       f.Controls.Add (ts);
+                       f.Show ();
+                       
+                       Assert.AreEqual (ToolStripLayoutStyle.VerticalStackWithOverflow, ts.LayoutStyle, "A1");
+                       Assert.AreEqual (Orientation.Vertical, ts.Orientation, "A2");
 
+                       ts.LayoutStyle = ToolStripLayoutStyle.StackWithOverflow;
+                       Assert.AreEqual (ToolStripLayoutStyle.VerticalStackWithOverflow, ts.LayoutStyle, "A3");
+                       Assert.AreEqual (Orientation.Vertical, ts.Orientation, "A4");
 
-       
+                       ts.LayoutStyle = ToolStripLayoutStyle.HorizontalStackWithOverflow;
+                       Assert.AreEqual (ToolStripLayoutStyle.HorizontalStackWithOverflow, ts.LayoutStyle, "A5");
+                       Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A6");
+                       
+                       ts.LayoutStyle = ToolStripLayoutStyle.Flow;
+                       Assert.AreEqual (ToolStripLayoutStyle.Flow, ts.LayoutStyle, "A7");
+                       Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A8");
+
+                       ts.LayoutStyle = ToolStripLayoutStyle.StackWithOverflow;
+                       Assert.AreEqual (ToolStripLayoutStyle.VerticalStackWithOverflow, ts.LayoutStyle, "A9");
+                       Assert.AreEqual (Orientation.Vertical, ts.Orientation, "A10");
+                       
+                       f.Close ();
+               }
+               
+               [Test]
+               public void MethodCreateLayoutSettings ()
+               {
+                       ExposeProtectedProperties ts = new ExposeProtectedProperties ();
+
+                       Assert.AreEqual ("System.Windows.Forms.FlowLayoutSettings", ts.PublicCreateLayoutSettings (ToolStripLayoutStyle.Flow).ToString (), "A1");
+                       Assert.AreEqual (null, ts.PublicCreateLayoutSettings (ToolStripLayoutStyle.HorizontalStackWithOverflow), "A2");
+                       Assert.AreEqual (null, ts.PublicCreateLayoutSettings (ToolStripLayoutStyle.StackWithOverflow), "A3");
+                       //Assert.AreEqual ("System.Windows.Forms.TableLayoutSettings", ts.PublicCreateLayoutSettings (ToolStripLayoutStyle.Table).ToString (), "A4");
+                       Assert.AreEqual (null, ts.PublicCreateLayoutSettings (ToolStripLayoutStyle.VerticalStackWithOverflow), "A5");
+               }
+
+               [Test]
+               public void MethodDipose()
+               {
+                       ToolStrip ts = new ToolStrip ();
+                       ToolStripItem item_a = ts.Items.Add ("A");
+                       ToolStripItem item_b = ts.Items.Add ("B");
+                       ToolStripItem item_c = ts.Items.Add ("C");
+
+                       Assert.AreEqual (3, ts.Items.Count, "A1");
+
+                       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), "A3");
+                       Assert.AreEqual (ts.Items[1], ts.GetNextItem (ts.Items[0], ArrowDirection.Right), "A4");
+
+                       f.Dispose ();
+               }
+               
+               [Test]
+               [ExpectedException (typeof (InvalidEnumArgumentException))]
+               public void MethodGetNextItemIEAE ()
+               {
+                       ToolStrip ts = new ToolStrip ();
+                       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 ()
                {
@@ -658,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 ()
                        {
@@ -670,7 +852,9 @@ namespace MonoTests.System.Windows.Forms
                                                
                                return retval;
                        }
+                       
+                       public LayoutSettings PublicCreateLayoutSettings (ToolStripLayoutStyle layoutStyle) { return base.CreateLayoutSettings (layoutStyle); }
                }
        }
 }
-#endif
\ No newline at end of file
+#endif