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)
31 using System.Collections.Generic;
32 using System.ComponentModel;
35 using System.Windows.Forms;
37 using NUnit.Framework;
39 namespace MonoTests.System.Windows.Forms
42 public class ToolStripTests : TestHelper
45 public void Constructor ()
47 ToolStrip ts = new ToolStrip ();
49 Assert.AreEqual (false, ts.AllowDrop, "A1");
50 //Assert.AreEqual (false, ts.AllowItemReorder, "A2");
51 Assert.AreEqual (true, ts.AllowMerge, "A3");
52 Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A4");
53 Assert.AreEqual (true, ts.AutoSize, "A5");
54 Assert.AreEqual (SystemColors.Control, ts.BackColor, "A6");
55 Assert.AreEqual (null, ts.BindingContext, "A7");
56 Assert.AreEqual (false, ts.CanSelect, "A7-1");
57 Assert.AreEqual (true, ts.CanOverflow, "A8");
58 Assert.AreEqual (false, ts.CausesValidation, "A9");
59 Assert.AreEqual (Cursors.Default, ts.Cursor, "A10");
60 Assert.AreEqual (ToolStripDropDownDirection.BelowRight, ts.DefaultDropDownDirection, "A11");
61 Assert.AreEqual (new Rectangle (7, 0, 92, 25), ts.DisplayRectangle, "A12");
62 Assert.AreEqual (DockStyle.Top, ts.Dock, "A13");
63 Assert.AreEqual (new Font ("Tahoma", 8.25f), ts.Font, "A14");
64 Assert.AreEqual (SystemColors.ControlText, ts.ForeColor, "A15");
65 Assert.AreEqual (ToolStripGripDisplayStyle.Vertical, ts.GripDisplayStyle, "A16");
66 Assert.AreEqual (new Padding (2), ts.GripMargin, "A17");
67 Assert.AreEqual (new Rectangle (2, 0, 3, 25), ts.GripRectangle, "A18");
68 Assert.AreEqual (ToolStripGripStyle.Visible, ts.GripStyle, "A19");
69 Assert.AreEqual (null, ts.ImageList, "A20");
70 Assert.AreEqual (new Size (16, 16), ts.ImageScalingSize, "A21");
71 //Assert.AreEqual (false, ts.IsCurrentlyDragging, "A22");
72 Assert.AreEqual (false, ts.IsDropDown, "A23");
73 Assert.AreEqual ("System.Windows.Forms.ToolStripItemCollection", ts.Items.ToString (), "A24");
74 Assert.AreEqual ("System.Windows.Forms.ToolStripSplitStackLayout", ts.LayoutEngine.ToString (), "A25");
75 Assert.AreEqual (null, ts.LayoutSettings, "A26");
76 Assert.AreEqual (ToolStripLayoutStyle.HorizontalStackWithOverflow, ts.LayoutStyle, "A27");
77 Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A28");
78 Assert.AreEqual ("System.Windows.Forms.ToolStripOverflowButton", ts.OverflowButton.GetType ().ToString (), "A29");
79 Assert.AreEqual ("System.Windows.Forms.ToolStripProfessionalRenderer", ts.Renderer.ToString (), "A30");
80 Assert.AreEqual (ToolStripRenderMode.ManagerRenderMode, ts.RenderMode, "A31");
81 Assert.AreEqual (true, ts.ShowItemToolTips, "A32");
82 Assert.AreEqual (false, ts.Stretch, "A33");
83 Assert.AreEqual (false, ts.TabStop, "A34");
84 Assert.AreEqual (ToolStripTextDirection.Horizontal, ts.TextDirection, "A35");
86 ts = new ToolStrip (new ToolStripButton (), new ToolStripSeparator (), new ToolStripButton ());
87 Assert.AreEqual (3, ts.Items.Count, "A36");
91 public void ControlStyle ()
94 f.ShowInTaskbar = false;
96 ExposeProtectedProperties epp = new ExposeProtectedProperties ();
99 ControlStyles cs = ControlStyles.ContainerControl;
100 cs |= ControlStyles.UserPaint;
101 cs |= ControlStyles.StandardClick;
102 cs |= ControlStyles.SupportsTransparentBackColor;
103 cs |= ControlStyles.StandardDoubleClick;
104 cs |= ControlStyles.AllPaintingInWmPaint;
105 cs |= ControlStyles.OptimizedDoubleBuffer;
106 cs |= ControlStyles.UseTextForAccessibility;
108 Assert.AreEqual (cs, epp.GetControlStyles (), "Styles");
112 cs |= ControlStyles.Selectable;
114 Assert.AreEqual (cs, epp.GetControlStyles (), "Styles-2");
118 cs &= ~ControlStyles.Selectable;
120 Assert.AreEqual (cs, epp.GetControlStyles (), "Styles-3");
127 public void DockSize ()
129 ToolStrip ts = new ToolStrip();
130 Assert.AreEqual (new Size (100, 25), ts.Size, "#1");
131 ts.Dock = DockStyle.None;
132 Assert.AreEqual (new Size (100, 25), ts.Size, "#2");
136 public void ProtectedProperties ()
138 ExposeProtectedProperties epp = new ExposeProtectedProperties ();
140 Assert.AreEqual (DockStyle.Top, epp.DefaultDock, "C1");
141 Assert.AreEqual (new Padding (2), epp.DefaultGripMargin, "C2");
142 Assert.AreEqual (new Padding (0), epp.DefaultMargin, "C3");
143 Assert.AreEqual (new Padding (0,0,1,0), epp.DefaultPadding, "C4");
144 Assert.AreEqual (true, epp.DefaultShowItemToolTips, "C5");
145 Assert.AreEqual (new Size (100, 25), epp.DefaultSize, "C6");
146 Assert.AreEqual (new Size (92, 25), epp.MaxItemSize, "C7");
148 epp.Size = new Size (300, 100);
149 Assert.AreEqual (new Size (292, 100), epp.MaxItemSize, "C8");
151 epp.GripStyle = ToolStripGripStyle.Hidden;
152 Assert.AreEqual (new Size (299, 100), epp.MaxItemSize, "C9");
156 public void PropertyAllowDrop ()
158 ToolStrip ts = new ToolStrip ();
159 EventWatcher ew = new EventWatcher (ts);
162 Assert.AreEqual (true, ts.AllowDrop, "B1");
163 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
167 //public void PropertyAllowItemReorder ()
169 // ToolStrip ts = new ToolStrip ();
170 // EventWatcher ew = new EventWatcher (ts);
172 // ts.AllowItemReorder = true;
173 // Assert.AreEqual (true, ts.AllowItemReorder, "B1");
174 // Assert.AreEqual (string.Empty, ew.ToString (), "B2");
178 //[ExpectedException (typeof (ArgumentException))]
179 //public void PropertyAllowDropAndAllowItemReorderAE ()
181 // ToolStrip ts = new ToolStrip ();
182 // EventWatcher ew = new EventWatcher (ts);
184 // ts.AllowDrop = true;
185 // ts.AllowItemReorder = true;
189 //[ExpectedException (typeof (ArgumentException))]
190 //public void PropertyAllowDropAndAllowItemReorderAE2 ()
192 // ToolStrip ts = new ToolStrip ();
193 // EventWatcher ew = new EventWatcher (ts);
195 // ts.AllowItemReorder = true;
196 // ts.AllowDrop = true;
200 public void PropertyAllowMerge ()
202 ToolStrip ts = new ToolStrip ();
203 EventWatcher ew = new EventWatcher (ts);
205 ts.AllowMerge = false;
206 Assert.AreEqual (false, ts.AllowMerge, "B1");
207 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
211 public void PropertyAnchorAndDocking ()
213 ToolStrip ts = new ToolStrip ();
215 ts.Anchor = AnchorStyles.Top | AnchorStyles.Bottom;
217 Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Bottom, ts.Anchor, "A1");
218 Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
219 Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A3");
221 ts.Anchor = AnchorStyles.Left | AnchorStyles.Right;
223 Assert.AreEqual (AnchorStyles.Left | AnchorStyles.Right, ts.Anchor, "A1");
224 Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
225 Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A3");
227 ts.Dock = DockStyle.Left;
229 Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
230 Assert.AreEqual (DockStyle.Left, ts.Dock, "A2");
231 Assert.AreEqual (Orientation.Vertical, ts.Orientation, "A3");
233 ts.Dock = DockStyle.None;
235 Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
236 Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
237 Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A3");
239 ts.Dock = DockStyle.Top;
241 Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
242 Assert.AreEqual (DockStyle.Top, ts.Dock, "A2");
243 Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A3");
247 public void PropertyAutoSize ()
249 ToolStrip ts = new ToolStrip ();
250 EventWatcher ew = new EventWatcher (ts);
253 Assert.AreEqual (false, ts.AutoSize, "B1");
254 Assert.AreEqual ("AutoSizeChanged", ew.ToString (), "B2");
258 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
262 public void PropertyBackColor ()
264 ToolStrip ts = new ToolStrip ();
265 EventWatcher ew = new EventWatcher (ts);
267 ts.BackColor = Color.BurlyWood;
268 Assert.AreEqual (Color.BurlyWood, ts.BackColor, "B1");
269 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
273 public void PropertyBindingContext ()
275 ToolStrip ts = new ToolStrip ();
276 EventWatcher ew = new EventWatcher (ts);
278 BindingContext b = new BindingContext ();
279 ts.BindingContext = b;
280 Assert.AreSame (b, ts.BindingContext, "B1");
281 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
285 public void PropertyCanOverflow ()
287 ToolStrip ts = new ToolStrip ();
288 EventWatcher ew = new EventWatcher (ts);
290 ts.CanOverflow = false;
291 Assert.AreEqual (false, ts.CanOverflow, "B1");
292 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
296 public void PropertyCausesValidation ()
298 ToolStrip ts = new ToolStrip ();
299 EventWatcher ew = new EventWatcher (ts);
301 ts.CausesValidation = true;
302 Assert.AreEqual (true, ts.CausesValidation, "B1");
303 Assert.AreEqual ("CausesValidationChanged", ew.ToString (), "B2");
306 ts.CausesValidation = true;
307 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
311 public void PropertyCursor ()
313 ToolStrip ts = new ToolStrip ();
314 EventWatcher ew = new EventWatcher (ts);
316 ts.Cursor = Cursors.Cross;
317 Assert.AreEqual (Cursors.Cross, ts.Cursor, "B1");
318 Assert.AreEqual ("CursorChanged", ew.ToString (), "B2");
321 ts.Cursor = Cursors.Cross;
322 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
326 public void PropertyDefaultDropDownDirection ()
328 ToolStrip ts = new ToolStrip ();
329 EventWatcher ew = new EventWatcher (ts);
331 ts.DefaultDropDownDirection = ToolStripDropDownDirection.AboveLeft;
332 Assert.AreEqual (ToolStripDropDownDirection.AboveLeft, ts.DefaultDropDownDirection, "B1");
333 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
337 [ExpectedException (typeof (InvalidEnumArgumentException))]
338 public void PropertyDefaultDropDownDirectionIEAE ()
340 ToolStrip ts = new ToolStrip ();
341 EventWatcher ew = new EventWatcher (ts);
343 ts.DefaultDropDownDirection = (ToolStripDropDownDirection)42;
347 [ExpectedException (typeof (InvalidEnumArgumentException))]
348 public void PropertyDockIEAE ()
350 ToolStrip ts = new ToolStrip ();
351 ts.Dock = (DockStyle)42;
355 public void PropertyFont ()
357 ToolStrip ts = new ToolStrip ();
358 EventWatcher ew = new EventWatcher (ts);
360 Font f = new Font ("Arial", 12);
363 Assert.AreSame (f, ts.Font, "B1");
364 Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B2");
368 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
372 public void PropertyForeColor ()
374 ToolStrip ts = new ToolStrip ();
375 EventWatcher ew = new EventWatcher (ts);
377 ts.ForeColor = Color.BurlyWood;
378 Assert.AreEqual (Color.BurlyWood, ts.ForeColor, "B1");
379 Assert.AreEqual ("ForeColorChanged", ew.ToString (), "B2");
382 ts.ForeColor = Color.BurlyWood;
383 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
387 public void PropertyGripMargin ()
389 ToolStrip ts = new ToolStrip ();
390 EventWatcher ew = new EventWatcher (ts);
392 ts.GripMargin = new Padding (6);
393 Assert.AreEqual (new Padding (6), ts.GripMargin, "B1");
394 Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B2");
397 ts.GripMargin = new Padding (6);
398 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
402 public void PropertyGripStyle ()
404 ToolStrip ts = new ToolStrip ();
405 EventWatcher ew = new EventWatcher (ts);
407 ts.GripStyle = ToolStripGripStyle.Hidden;
408 Assert.AreEqual (ToolStripGripStyle.Hidden, ts.GripStyle, "B1");
409 Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B2");
412 ts.GripStyle = ToolStripGripStyle.Hidden;
413 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
417 [ExpectedException (typeof (InvalidEnumArgumentException))]
418 public void PropertyGripStyleIEAE ()
420 ToolStrip ts = new ToolStrip ();
422 ts.GripStyle = (ToolStripGripStyle) 42;
426 public void PropertyImageList ()
428 ToolStrip ts = new ToolStrip ();
429 EventWatcher ew = new EventWatcher (ts);
431 ImageList il = new ImageList ();
434 Assert.AreSame (il, ts.ImageList, "B1");
435 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
439 public void PropertyImageScalingSize ()
441 ToolStrip ts = new ToolStrip ();
442 EventWatcher ew = new EventWatcher (ts);
444 ts.ImageScalingSize = new Size (32, 32);
445 Assert.AreEqual (new Size (32, 32), ts.ImageScalingSize, "B1");
446 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
450 public void PropertyLayoutStyle ()
452 ToolStrip ts = new ToolStrip ();
453 EventWatcher ew = new EventWatcher (ts);
455 ts.LayoutStyle = ToolStripLayoutStyle.VerticalStackWithOverflow;
456 Assert.AreEqual (ToolStripLayoutStyle.VerticalStackWithOverflow, ts.LayoutStyle, "B1");
457 Assert.AreEqual ("LayoutCompleted;LayoutStyleChanged", ew.ToString (), "B2");
460 ts.LayoutStyle = ToolStripLayoutStyle.VerticalStackWithOverflow;
461 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
465 [ExpectedException (typeof (InvalidEnumArgumentException))]
466 public void PropertyLayoutStyleIEAE ()
468 ToolStrip ts = new ToolStrip ();
470 ts.LayoutStyle = (ToolStripLayoutStyle) 42;
474 public void PropertyRenderer ()
476 ToolStrip ts = new ToolStrip ();
477 EventWatcher ew = new EventWatcher (ts);
479 ToolStripProfessionalRenderer pr = new ToolStripProfessionalRenderer ();
482 Assert.AreSame (pr, ts.Renderer, "B1");
483 Assert.AreEqual ("LayoutCompleted;RendererChanged", ew.ToString (), "B2");
484 Assert.AreEqual (ToolStripRenderMode.Custom, ts.RenderMode, "B4");
488 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
492 public void PropertyRenderMode ()
494 ToolStrip ts = new ToolStrip ();
495 EventWatcher ew = new EventWatcher (ts);
497 ts.RenderMode = ToolStripRenderMode.System;
498 Assert.AreEqual (ToolStripRenderMode.System, ts.RenderMode, "B1");
499 Assert.AreEqual ("LayoutCompleted;RendererChanged", ew.ToString (), "B2");
502 ts.RenderMode = ToolStripRenderMode.System;
503 Assert.AreEqual ("LayoutCompleted;RendererChanged", ew.ToString (), "B3");
507 [ExpectedException (typeof (NotSupportedException))]
508 public void PropertyRenderModeNSE ()
510 ToolStrip ts = new ToolStrip ();
512 ts.RenderMode = ToolStripRenderMode.Custom;
516 [ExpectedException (typeof (InvalidEnumArgumentException))]
517 public void PropertyRenderModeIEAE ()
519 ToolStrip ts = new ToolStrip ();
521 ts.RenderMode = (ToolStripRenderMode) 42;
525 public void PropertyShowItemToolTips ()
527 ToolStrip ts = new ToolStrip ();
528 EventWatcher ew = new EventWatcher (ts);
530 ts.ShowItemToolTips = false;
531 Assert.AreEqual (false, ts.ShowItemToolTips, "B1");
532 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
536 public void PropertyStretch ()
538 ToolStrip ts = new ToolStrip ();
539 EventWatcher ew = new EventWatcher (ts);
542 Assert.AreEqual (true, ts.Stretch, "B1");
543 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
547 public void PropertyTabStop ()
549 ToolStrip ts = new ToolStrip ();
550 EventWatcher ew = new EventWatcher (ts);
553 Assert.AreEqual (true, ts.TabStop, "B1");
554 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
558 //public void PropertyTextDirection ()
560 // ToolStrip ts = new ToolStrip ();
561 // EventWatcher ew = new EventWatcher (ts);
563 // ts.TextDirection = ToolStripTextDirection.Vertical270;
564 // Assert.AreEqual (ToolStripTextDirection.Vertical270, ts.TextDirection, "B1");
565 // Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B2");
568 // ts.TextDirection = ToolStripTextDirection.Vertical270;
569 // Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B3");
573 [ExpectedException (typeof (InvalidEnumArgumentException))]
574 public void PropertyTextDirectionIEAE ()
576 ToolStrip ts = new ToolStrip ();
577 EventWatcher ew = new EventWatcher (ts);
579 ts.TextDirection = (ToolStripTextDirection)42;
583 [NUnit.Framework.Category ("NotWorking")]
584 public void BehaviorDisplayRectangleAndOverflow ()
586 // WM decoration size dependent
587 Form f = new Form ();
588 f.ShowInTaskbar = false;
589 ToolStrip ts = new ToolStrip ();
593 Assert.AreEqual (false, ts.OverflowButton.Visible, "D1");
594 Assert.AreEqual (new Rectangle (7, 0, 284, 25), ts.DisplayRectangle, "D2");
596 ts.Items.Add (new ToolStripButton ("hello11111111111"));
597 ts.Items.Add (new ToolStripButton ("hello11111111111"));
598 ts.Items.Add (new ToolStripButton ("hello11111111111"));
599 ts.Items.Add (new ToolStripButton ("hello11111111111"));
600 ts.Items.Add (new ToolStripButton ("hello11111111111"));
601 ts.Items.Add (new ToolStripButton ("hello11111111111"));
603 Assert.AreEqual (true, ts.OverflowButton.Visible, "D3");
604 Assert.AreEqual (new Rectangle (7, 0, 284, 25), ts.DisplayRectangle, "D4");
609 public void BehaviorGripAndOverflowWithFlowLayout ()
611 ToolStrip ts = new ToolStrip ();
612 ts.LayoutStyle = ToolStripLayoutStyle.Flow;
614 Assert.AreEqual (ToolStripGripStyle.Visible, ts.GripStyle, "A1");
615 Assert.AreEqual (false, ts.OverflowButton.Visible, "A2");
616 Assert.AreEqual ("System.Windows.Forms.Layout.FlowLayout", ts.LayoutEngine.ToString (), "A3");
620 public void BehaviorDockAndOrientation ()
622 Form f = new Form ();
623 f.ShowInTaskbar = false;
625 ToolStrip ts = new ToolStrip ();
626 ts.Dock = DockStyle.Left;
631 Assert.AreEqual (ToolStripLayoutStyle.VerticalStackWithOverflow, ts.LayoutStyle, "A1");
632 Assert.AreEqual (Orientation.Vertical, ts.Orientation, "A2");
634 ts.LayoutStyle = ToolStripLayoutStyle.StackWithOverflow;
635 Assert.AreEqual (ToolStripLayoutStyle.VerticalStackWithOverflow, ts.LayoutStyle, "A3");
636 Assert.AreEqual (Orientation.Vertical, ts.Orientation, "A4");
638 ts.LayoutStyle = ToolStripLayoutStyle.HorizontalStackWithOverflow;
639 Assert.AreEqual (ToolStripLayoutStyle.HorizontalStackWithOverflow, ts.LayoutStyle, "A5");
640 Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A6");
642 ts.LayoutStyle = ToolStripLayoutStyle.Flow;
643 Assert.AreEqual (ToolStripLayoutStyle.Flow, ts.LayoutStyle, "A7");
644 Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A8");
646 ts.LayoutStyle = ToolStripLayoutStyle.StackWithOverflow;
647 Assert.AreEqual (ToolStripLayoutStyle.VerticalStackWithOverflow, ts.LayoutStyle, "A9");
648 Assert.AreEqual (Orientation.Vertical, ts.Orientation, "A10");
654 public void MethodCreateLayoutSettings ()
656 ExposeProtectedProperties ts = new ExposeProtectedProperties ();
658 Assert.AreEqual ("System.Windows.Forms.FlowLayoutSettings", ts.PublicCreateLayoutSettings (ToolStripLayoutStyle.Flow).ToString (), "A1");
659 Assert.AreEqual (null, ts.PublicCreateLayoutSettings (ToolStripLayoutStyle.HorizontalStackWithOverflow), "A2");
660 Assert.AreEqual (null, ts.PublicCreateLayoutSettings (ToolStripLayoutStyle.StackWithOverflow), "A3");
661 //Assert.AreEqual ("System.Windows.Forms.TableLayoutSettings", ts.PublicCreateLayoutSettings (ToolStripLayoutStyle.Table).ToString (), "A4");
662 Assert.AreEqual (null, ts.PublicCreateLayoutSettings (ToolStripLayoutStyle.VerticalStackWithOverflow), "A5");
666 public void MethodGetNextItem ()
668 ToolStrip ts = new ToolStrip ();
669 ts.Items.Add ("Test Item 1");
671 Form f = new Form ();
672 f.ShowInTaskbar = false;
676 Assert.AreEqual (ts.Items[0], ts.GetNextItem (null, ArrowDirection.Right), "A1");
677 Assert.AreEqual (ts.Items[0], ts.GetNextItem (ts.Items[0], ArrowDirection.Right), "A2");
679 ts.Items.Add ("Test Item 2");
681 Assert.AreEqual (ts.Items[0], ts.GetNextItem (null, ArrowDirection.Right), "A3");
682 Assert.AreEqual (ts.Items[1], ts.GetNextItem (ts.Items[0], ArrowDirection.Right), "A4");
688 [ExpectedException (typeof (InvalidEnumArgumentException))]
689 public void MethodGetNextItemIEAE ()
691 ToolStrip ts = new ToolStrip ();
692 ts.GetNextItem (null, (ArrowDirection)42);
696 [NUnit.Framework.Category ("NotWorking")]
697 public void MethodResetMinimumSize ()
699 ToolStrip ts = new ToolStrip ();
700 ts.Size = new Size (600, 600);
702 Assert.AreEqual (new Size (0, 0), ts.MinimumSize, "M0");
704 ts.MinimumSize = new Size (400, 400);
706 Assert.AreEqual (new Size (600, 600), ts.Size, "M1");
707 Assert.AreEqual (new Size (400, 400), ts.MinimumSize, "M2");
709 ts.ResetMinimumSize ();
710 Assert.AreEqual (new Size (600, 600), ts.Size, "M3");
711 Assert.AreEqual (new Size (-1, -1), ts.MinimumSize, "M4");
715 public void TestToolStrip ()
717 ToolStrip ts = new ToolStrip ();
719 ts.Items.Add (new ToolStripButton ());
720 Assert.AreEqual (new Rectangle (0, 0, 100, 25), ts.Bounds, "D1");
721 Assert.AreEqual (new Rectangle (7, 0, 92, 25), ts.DisplayRectangle, "D2");
722 Assert.AreEqual (new Rectangle (2, 0, 3, 25), ts.GripRectangle, "D4");
723 Assert.AreEqual (new Padding (2), ts.GripMargin, "D5");
725 ts.GripStyle = ToolStripGripStyle.Hidden;
727 Assert.AreEqual (new Rectangle (0, 0, 0, 0), ts.GripRectangle, "D8");
728 Assert.AreEqual (new Rectangle (0, 0, 99, 25), ts.DisplayRectangle, "D3");
729 Assert.AreEqual (new Padding (2), ts.GripMargin, "D5");
731 ts.BackColor = Color.Aquamarine;
732 Assert.AreEqual (Color.Aquamarine, ts.BackColor, "A2");
734 ts.ForeColor = Color.LightSalmon;
735 Assert.AreEqual (Color.LightSalmon, ts.ForeColor, "A5");
737 ts.GripMargin = new Padding (3);
738 Assert.AreEqual (new Padding (3), ts.GripMargin, "A7");
742 [Ignore ("Accessibility still needs some work")]
743 public void Accessibility ()
745 ToolStrip ts = new ToolStrip ();
746 AccessibleObject ao = ts.AccessibilityObject;
748 Assert.AreEqual ("ControlAccessibleObject: Owner = " + ts.ToString (), ao.ToString (), "L");
749 //Assert.AreEqual (Rectangle.Empty, ao.Bounds, "L1");
750 Assert.AreEqual (null, ao.DefaultAction, "L2");
751 Assert.AreEqual (null, ao.Description, "L3");
752 Assert.AreEqual (null, ao.Help, "L4");
753 Assert.AreEqual (null, ao.KeyboardShortcut, "L5");
754 Assert.AreEqual (null, ao.Name, "L6");
755 //Assert.AreEqual (null, ao.Parent, "L7");
756 Assert.AreEqual (AccessibleRole.ToolBar, ao.Role, "L8");
757 Assert.AreEqual (AccessibleStates.None, ao.State, "L9");
758 Assert.AreEqual (null, ao.Value, "L10");
761 ts.Text = "Test Label";
762 ts.AccessibleDescription = "Label Desc";
764 //Assert.AreEqual (Rectangle.Empty, ao.Bounds, "L11");
765 Assert.AreEqual (null, ao.DefaultAction, "L12");
766 Assert.AreEqual ("Label Desc", ao.Description, "L13");
767 Assert.AreEqual (null, ao.Help, "L14");
768 Assert.AreEqual (null, ao.KeyboardShortcut, "L15");
769 //Assert.AreEqual ("Test Label", ao.Name, "L16");
770 //Assert.AreEqual (null, ao.Parent, "L17");
771 Assert.AreEqual (AccessibleRole.ToolBar, ao.Role, "L18");
772 Assert.AreEqual (AccessibleStates.None, ao.State, "L19");
773 Assert.AreEqual (null, ao.Value, "L20");
775 ts.AccessibleName = "Access Label";
776 Assert.AreEqual ("Access Label", ao.Name, "L21");
778 ts.Text = "Test Label";
779 Assert.AreEqual ("Access Label", ao.Name, "L22");
781 ts.AccessibleDefaultActionDescription = "AAA";
782 Assert.AreEqual ("AAA", ts.AccessibleDefaultActionDescription, "L23");
785 private class EventWatcher
787 private string events = string.Empty;
789 public EventWatcher (ToolStrip ts)
791 ts.AutoSizeChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("AutoSizeChanged;"); });
792 //ts.BeginDrag += new EventHandler (delegate (Object obj, EventArgs e) { events += ("BeginDrag;"); });
793 ts.CausesValidationChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("CausesValidationChanged;"); });
794 ts.CursorChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("CursorChanged;"); });
795 //ts.EndDrag += new EventHandler (delegate (Object obj, EventArgs e) { events += ("EndDrag;"); });
796 ts.ForeColorChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("ForeColorChanged;"); });
797 ts.ItemAdded += new ToolStripItemEventHandler (delegate (Object obj, ToolStripItemEventArgs e) { events += ("ItemAdded;"); });
798 ts.ItemClicked += new ToolStripItemClickedEventHandler (delegate (Object obj, ToolStripItemClickedEventArgs e) { events += ("ItemClicked;"); });
799 ts.ItemRemoved += new ToolStripItemEventHandler (delegate (Object obj, ToolStripItemEventArgs e) { events += ("ItemRemoved;"); });
800 ts.LayoutCompleted += new EventHandler (delegate (Object obj, EventArgs e) { events += ("LayoutCompleted;"); });
801 ts.LayoutStyleChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("LayoutStyleChanged;"); });
802 ts.PaintGrip += new PaintEventHandler (delegate (Object obj, PaintEventArgs e) { events += ("PaintGrip;"); });
803 ts.RendererChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("RendererChanged;"); });
806 public override string ToString ()
808 return events.TrimEnd (';');
813 events = string.Empty;
817 private class ExposeProtectedProperties : ToolStrip
819 public new DockStyle DefaultDock { get { return base.DefaultDock; } }
820 public new Padding DefaultGripMargin { get { return base.DefaultGripMargin; } }
821 public new Padding DefaultMargin { get { return base.DefaultMargin; } }
822 public new Padding DefaultPadding { get { return base.DefaultPadding; } }
823 public new bool DefaultShowItemToolTips { get { return base.DefaultShowItemToolTips; } }
824 public new Size DefaultSize { get { return base.DefaultSize; } }
825 public new Size MaxItemSize { get { return base.MaxItemSize; } }
827 public ControlStyles GetControlStyles ()
829 ControlStyles retval = (ControlStyles) 0;
831 foreach (ControlStyles cs in Enum.GetValues (typeof (ControlStyles)))
832 if (this.GetStyle (cs) == true)
838 public LayoutSettings PublicCreateLayoutSettings (ToolStripLayoutStyle layoutStyle) { return base.CreateLayoutSettings (layoutStyle); }