4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 // Copyright (c) 2006 Jonathan Pobst
26 // Jonathan Pobst (monkey@jpobst.com)
30 using System.Collections.Generic;
32 using NUnit.Framework;
34 using System.Windows.Forms;
35 using System.ComponentModel;
37 namespace MonoTests.System.Windows.Forms
40 public class MenuStripTest
43 public void Constructor ()
45 MenuStrip ms = new MenuStrip ();
47 Assert.AreEqual (false, ms.CanSelect, "A0");
48 Assert.AreEqual (false, ms.CanOverflow, "A1");
49 Assert.AreEqual (ToolStripGripStyle.Hidden, ms.GripStyle, "A2");
50 Assert.AreEqual (null, ms.MdiWindowListItem, "A3");
51 Assert.AreEqual (false, ms.ShowItemToolTips, "A4");
52 Assert.AreEqual (true, ms.Stretch, "A5");
53 Assert.AreEqual (ToolStripLayoutStyle.HorizontalStackWithOverflow, ms.LayoutStyle, "A6");
55 Assert.AreEqual ("System.Windows.Forms.MenuStrip+MenuStripAccessibleObject", ms.AccessibilityObject.GetType ().ToString (), "A7");
59 public void ControlStyle ()
61 ExposeProtectedProperties epp = new ExposeProtectedProperties ();
63 ControlStyles cs = ControlStyles.ContainerControl;
64 cs |= ControlStyles.UserPaint;
65 cs |= ControlStyles.StandardClick;
66 cs |= ControlStyles.SupportsTransparentBackColor;
67 cs |= ControlStyles.StandardDoubleClick;
68 cs |= ControlStyles.AllPaintingInWmPaint;
69 cs |= ControlStyles.OptimizedDoubleBuffer;
70 cs |= ControlStyles.UseTextForAccessibility;
72 Assert.AreEqual (cs, epp.GetControlStyles (), "Styles");
76 public void ProtectedProperties ()
78 ExposeProtectedProperties epp = new ExposeProtectedProperties ();
80 Assert.AreEqual (new Padding (2, 2, 0, 2), epp.DefaultGripMargin, "C1");
81 Assert.AreEqual (new Padding (6, 2, 0, 2), epp.DefaultPadding, "C2");
82 Assert.AreEqual (false, epp.DefaultShowItemToolTips, "C3");
83 Assert.AreEqual (new Size (200, 24), epp.DefaultSize, "C4");
87 public void PropertyCanOverflow ()
89 StatusStrip ts = new StatusStrip ();
91 ts.CanOverflow = true;
92 Assert.AreEqual (true, ts.CanOverflow, "B1");
96 public void PropertyGripStyle ()
98 StatusStrip ts = new StatusStrip ();
100 ts.GripStyle = ToolStripGripStyle.Visible;
101 Assert.AreEqual (ToolStripGripStyle.Visible, ts.GripStyle, "B1");
105 [ExpectedException (typeof (InvalidEnumArgumentException))]
106 public void PropertyGripStyleIEAE ()
108 StatusStrip ts = new StatusStrip ();
110 ts.GripStyle = (ToolStripGripStyle)42;
114 public void PropertyShowItemToolTips ()
116 StatusStrip ts = new StatusStrip ();
118 ts.ShowItemToolTips = true;
119 Assert.AreEqual (true, ts.ShowItemToolTips, "B1");
123 public void PropertyStretch ()
125 StatusStrip ts = new StatusStrip ();
128 Assert.AreEqual (false, ts.Stretch, "B1");
132 public void BehaviorMdiWindowMenuItem ()
134 Form f = new Form ();
135 f.ShowInTaskbar = false;
136 f.IsMdiContainer = true;
137 Form c1 = new Form ();
139 Form c2 = new Form ();
142 MenuStrip ms = new MenuStrip ();
143 ToolStripMenuItem tsmi = (ToolStripMenuItem)ms.Items.Add ("Window");
145 ms.MdiWindowListItem = tsmi;
147 Assert.AreSame (tsmi, ms.MdiWindowListItem, "Q1");
148 Assert.AreEqual (0, tsmi.DropDownItems.Count, "Q2");
150 f.MainMenuStrip = ms;
151 Assert.AreEqual (0, tsmi.DropDownItems.Count, "Q3");
154 Assert.AreEqual (0, tsmi.DropDownItems.Count, "Q4");
157 Assert.AreEqual (1, tsmi.DropDownItems.Count, "Q5");
158 Assert.AreEqual (true, (tsmi.DropDownItems[0] as ToolStripMenuItem).Checked, "Q6");
161 Assert.AreEqual (2, tsmi.DropDownItems.Count, "Q7");
162 Assert.AreEqual (true, (tsmi.DropDownItems[1] as ToolStripMenuItem).Checked, "Q8");
164 Form c3 = new Form ();
166 Assert.AreEqual (2, tsmi.DropDownItems.Count, "Q9");
169 Assert.AreEqual (3, tsmi.DropDownItems.Count, "Q10");
170 Assert.AreEqual (true, (tsmi.DropDownItems[2] as ToolStripMenuItem).Checked, "Q11");
173 Assert.AreEqual (2, tsmi.DropDownItems.Count, "Q12");
174 // Assert.AreEqual (true, (tsmi.DropDownItems[1] as ToolStripMenuItem).Checked, "Q13");
176 // Technically, adding the Cascade item adds it to the end of the list until
177 // anything regarding Mdi is clicked, which then moves it to the top of
178 // the list and adds the separator.
179 // Calling c3.Show() forces the Cascade menu to the top.
180 tsmi.DropDownItems.Add ("Cascade");
182 Assert.AreEqual (5, tsmi.DropDownItems.Count, "Q14");
183 Assert.AreEqual (true, (tsmi.DropDownItems[4] as ToolStripMenuItem).Checked, "Q15");
188 private class ExposeProtectedProperties : MenuStrip
190 public new Padding DefaultGripMargin { get { return base.DefaultGripMargin; } }
191 public new Padding DefaultPadding { get { return base.DefaultPadding; } }
192 public new bool DefaultShowItemToolTips { get { return base.DefaultShowItemToolTips; } }
193 public new Size DefaultSize { get { return base.DefaultSize; } }
195 public ControlStyles GetControlStyles ()
197 ControlStyles retval = (ControlStyles)0;
199 foreach (ControlStyles cs in Enum.GetValues (typeof (ControlStyles)))
200 if (this.GetStyle (cs) == true)