Unit test for bug #821.
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ToolStripTest.cs
1 //
2 // ToolStripTests.cs
3 //
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:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
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.
22 //
23 // Copyright (c) 2006 Jonathan Pobst
24 //
25 // Authors:
26 //      Jonathan Pobst (monkey@jpobst.com)
27 //
28
29 #if NET_2_0
30 using System;
31 using System.Collections.Generic;
32 using System.ComponentModel;
33 using System.Drawing;
34 using System.Text;
35 using System.Windows.Forms;
36
37 using NUnit.Framework;
38
39 namespace MonoTests.System.Windows.Forms
40 {
41         [TestFixture]
42         public class ToolStripTests : TestHelper
43         {
44                 [Test]
45                 public void Constructor ()
46                 {
47                         ToolStrip ts = new ToolStrip ();
48
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");
85                         
86                         ts = new ToolStrip (new ToolStripButton (), new ToolStripSeparator (), new ToolStripButton ());
87                         Assert.AreEqual (3, ts.Items.Count, "A36");
88                 }
89
90                 [Test]
91                 public void ControlStyle ()
92                 {
93                         Form f = new Form ();
94                         f.ShowInTaskbar = false;
95                         
96                         ExposeProtectedProperties epp = new ExposeProtectedProperties ();
97                         f.Controls.Add (epp);
98                         
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;
107
108                         Assert.AreEqual (cs, epp.GetControlStyles (), "Styles");
109                         
110                         epp.TabStop = true;
111                         
112                         cs |= ControlStyles.Selectable;
113
114                         Assert.AreEqual (cs, epp.GetControlStyles (), "Styles-2");
115                         
116                         epp.TabStop = false;
117                         
118                         cs &= ~ControlStyles.Selectable;
119
120                         Assert.AreEqual (cs, epp.GetControlStyles (), "Styles-3");
121                         
122                         f.Close ();
123                         f.Dispose ();
124                 }
125
126                 [Test] // bug #80762
127                 public void DockSize ()
128                 {
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");
133                 }
134
135                 [Test]
136                 public void ProtectedProperties ()
137                 {
138                         ExposeProtectedProperties epp = new ExposeProtectedProperties ();
139
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");
147                         
148                         epp.Size = new Size (300, 100);
149                         Assert.AreEqual (new Size (292, 100), epp.MaxItemSize, "C8");
150                         
151                         epp.GripStyle = ToolStripGripStyle.Hidden;
152                         Assert.AreEqual (new Size (299, 100), epp.MaxItemSize, "C9");
153                 }
154                 
155                 [Test]
156                 public void PropertyAllowDrop ()
157                 {
158                         ToolStrip ts = new ToolStrip ();
159                         EventWatcher ew = new EventWatcher (ts);
160                         
161                         ts.AllowDrop = true;
162                         Assert.AreEqual (true, ts.AllowDrop, "B1");
163                         Assert.AreEqual (string.Empty, ew.ToString (), "B2");
164                 }
165
166                 //[Test]        
167                 //public void PropertyAllowItemReorder ()
168                 //{
169                 //        ToolStrip ts = new ToolStrip ();
170                 //        EventWatcher ew = new EventWatcher (ts);
171
172                 //        ts.AllowItemReorder = true;
173                 //        Assert.AreEqual (true, ts.AllowItemReorder, "B1");
174                 //        Assert.AreEqual (string.Empty, ew.ToString (), "B2");
175                 //}
176
177                 //[Test]
178                 //[ExpectedException (typeof (ArgumentException))]
179                 //public void PropertyAllowDropAndAllowItemReorderAE ()
180                 //{
181                 //        ToolStrip ts = new ToolStrip ();
182                 //        EventWatcher ew = new EventWatcher (ts);
183
184                 //        ts.AllowDrop = true;
185                 //        ts.AllowItemReorder = true;
186                 //}
187
188                 //[Test]
189                 //[ExpectedException (typeof (ArgumentException))]
190                 //public void PropertyAllowDropAndAllowItemReorderAE2 ()
191                 //{
192                 //        ToolStrip ts = new ToolStrip ();
193                 //        EventWatcher ew = new EventWatcher (ts);
194
195                 //        ts.AllowItemReorder = true;
196                 //        ts.AllowDrop = true;
197                 //}
198
199                 [Test]
200                 public void PropertyAllowMerge ()
201                 {
202                         ToolStrip ts = new ToolStrip ();
203                         EventWatcher ew = new EventWatcher (ts);
204
205                         ts.AllowMerge = false;
206                         Assert.AreEqual (false, ts.AllowMerge, "B1");
207                         Assert.AreEqual (string.Empty, ew.ToString (), "B2");
208                 }
209
210                 [Test]
211                 public void PropertyAnchorAndDocking ()
212                 {
213                         ToolStrip ts = new ToolStrip ();
214
215                         ts.Anchor = AnchorStyles.Top | AnchorStyles.Bottom;
216
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");
220
221                         ts.Anchor = AnchorStyles.Left | AnchorStyles.Right;
222
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");
226
227                         ts.Dock = DockStyle.Left;
228
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");
232
233                         ts.Dock = DockStyle.None;
234
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");
238
239                         ts.Dock = DockStyle.Top;
240
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");
244                 }
245
246                 [Test]
247                 public void PropertyAutoSize ()
248                 {
249                         ToolStrip ts = new ToolStrip ();
250                         EventWatcher ew = new EventWatcher (ts);
251
252                         ts.AutoSize = false;
253                         Assert.AreEqual (false, ts.AutoSize, "B1");
254                         Assert.AreEqual ("AutoSizeChanged", ew.ToString (), "B2");
255                         
256                         ew.Clear ();
257                         ts.AutoSize = false;
258                         Assert.AreEqual (string.Empty, ew.ToString (), "B3");
259                 }
260
261                 [Test]
262                 public void PropertyBackColor ()
263                 {
264                         ToolStrip ts = new ToolStrip ();
265                         EventWatcher ew = new EventWatcher (ts);
266
267                         ts.BackColor = Color.BurlyWood;
268                         Assert.AreEqual (Color.BurlyWood, ts.BackColor, "B1");
269                         Assert.AreEqual (string.Empty, ew.ToString (), "B2");
270                 }
271
272                 [Test]
273                 public void PropertyBindingContext ()
274                 {
275                         ToolStrip ts = new ToolStrip ();
276                         EventWatcher ew = new EventWatcher (ts);
277
278                         BindingContext b = new BindingContext ();
279                         ts.BindingContext = b;
280                         Assert.AreSame (b, ts.BindingContext, "B1");
281                         Assert.AreEqual (string.Empty, ew.ToString (), "B2");
282                 }
283
284                 [Test]
285                 public void PropertyCanOverflow ()
286                 {
287                         ToolStrip ts = new ToolStrip ();
288                         EventWatcher ew = new EventWatcher (ts);
289
290                         ts.CanOverflow = false;
291                         Assert.AreEqual (false, ts.CanOverflow, "B1");
292                         Assert.AreEqual (string.Empty, ew.ToString (), "B2");
293                 }
294
295                 [Test]
296                 public void PropertyCausesValidation ()
297                 {
298                         ToolStrip ts = new ToolStrip ();
299                         EventWatcher ew = new EventWatcher (ts);
300
301                         ts.CausesValidation = true;
302                         Assert.AreEqual (true, ts.CausesValidation, "B1");
303                         Assert.AreEqual ("CausesValidationChanged", ew.ToString (), "B2");
304
305                         ew.Clear ();
306                         ts.CausesValidation = true;
307                         Assert.AreEqual (string.Empty, ew.ToString (), "B3");
308                 }
309
310                 [Test]
311                 public void PropertyCursor ()
312                 {
313                         ToolStrip ts = new ToolStrip ();
314                         EventWatcher ew = new EventWatcher (ts);
315
316                         ts.Cursor = Cursors.Cross;
317                         Assert.AreEqual (Cursors.Cross, ts.Cursor, "B1");
318                         Assert.AreEqual ("CursorChanged", ew.ToString (), "B2");
319
320                         ew.Clear ();
321                         ts.Cursor = Cursors.Cross;
322                         Assert.AreEqual (string.Empty, ew.ToString (), "B3");
323                 }
324
325                 [Test]
326                 public void PropertyDefaultDropDownDirection ()
327                 {
328                         ToolStrip ts = new ToolStrip ();
329                         EventWatcher ew = new EventWatcher (ts);
330
331                         ts.DefaultDropDownDirection = ToolStripDropDownDirection.AboveLeft;
332                         Assert.AreEqual (ToolStripDropDownDirection.AboveLeft, ts.DefaultDropDownDirection, "B1");
333                         Assert.AreEqual (string.Empty, ew.ToString (), "B2");
334                 }
335
336                 [Test]
337                 [ExpectedException (typeof (InvalidEnumArgumentException))]
338                 public void PropertyDefaultDropDownDirectionIEAE ()
339                 {
340                         ToolStrip ts = new ToolStrip ();
341                         EventWatcher ew = new EventWatcher (ts);
342
343                         ts.DefaultDropDownDirection = (ToolStripDropDownDirection)42;
344                 }
345
346                 [Test]
347                 [ExpectedException (typeof (InvalidEnumArgumentException))]
348                 public void PropertyDockIEAE ()
349                 {
350                         ToolStrip ts = new ToolStrip ();
351                         ts.Dock = (DockStyle)42;
352                 }
353
354                 [Test]
355                 public void PropertyFont ()
356                 {
357                         ToolStrip ts = new ToolStrip ();
358                         EventWatcher ew = new EventWatcher (ts);
359
360                         Font f = new Font ("Arial", 12);
361                         
362                         ts.Font = f;
363                         Assert.AreSame (f, ts.Font, "B1");
364                         Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B2");
365
366                         ew.Clear ();
367                         ts.Font = f;
368                         Assert.AreEqual (string.Empty, ew.ToString (), "B3");
369                 }
370
371                 [Test]
372                 public void PropertyForeColor ()
373                 {
374                         ToolStrip ts = new ToolStrip ();
375                         EventWatcher ew = new EventWatcher (ts);
376
377                         ts.ForeColor = Color.BurlyWood;
378                         Assert.AreEqual (Color.BurlyWood, ts.ForeColor, "B1");
379                         Assert.AreEqual ("ForeColorChanged", ew.ToString (), "B2");
380
381                         ew.Clear ();
382                         ts.ForeColor = Color.BurlyWood;
383                         Assert.AreEqual (string.Empty, ew.ToString (), "B3");
384                 }
385
386                 [Test]
387                 public void PropertyGripMargin ()
388                 {
389                         ToolStrip ts = new ToolStrip ();
390                         EventWatcher ew = new EventWatcher (ts);
391
392                         ts.GripMargin = new Padding (6);
393                         Assert.AreEqual (new Padding (6), ts.GripMargin, "B1");
394                         Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B2");
395
396                         ew.Clear ();
397                         ts.GripMargin = new Padding (6);
398                         Assert.AreEqual (string.Empty, ew.ToString (), "B3");
399                 }
400
401                 [Test]
402                 public void PropertyGripStyle ()
403                 {
404                         ToolStrip ts = new ToolStrip ();
405                         EventWatcher ew = new EventWatcher (ts);
406
407                         ts.GripStyle = ToolStripGripStyle.Hidden;
408                         Assert.AreEqual (ToolStripGripStyle.Hidden, ts.GripStyle, "B1");
409                         Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B2");
410
411                         ew.Clear ();
412                         ts.GripStyle = ToolStripGripStyle.Hidden;
413                         Assert.AreEqual (string.Empty, ew.ToString (), "B3");
414                 }
415
416                 [Test]
417                 [ExpectedException (typeof (InvalidEnumArgumentException))]
418                 public void PropertyGripStyleIEAE ()
419                 {
420                         ToolStrip ts = new ToolStrip ();
421
422                         ts.GripStyle = (ToolStripGripStyle) 42;
423                 }
424
425                 [Test]
426                 public void PropertyImageList ()
427                 {
428                         ToolStrip ts = new ToolStrip ();
429                         EventWatcher ew = new EventWatcher (ts);
430
431                         ImageList il = new ImageList ();
432
433                         ts.ImageList = il;
434                         Assert.AreSame (il, ts.ImageList, "B1");
435                         Assert.AreEqual (string.Empty, ew.ToString (), "B2");
436                 }
437
438                 [Test]
439                 public void PropertyImageScalingSize ()
440                 {
441                         ToolStrip ts = new ToolStrip ();
442                         EventWatcher ew = new EventWatcher (ts);
443
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");
447                 }
448
449                 [Test]
450                 public void PropertyLayoutStyle ()
451                 {
452                         ToolStrip ts = new ToolStrip ();
453                         EventWatcher ew = new EventWatcher (ts);
454
455                         ts.LayoutStyle = ToolStripLayoutStyle.VerticalStackWithOverflow;
456                         Assert.AreEqual (ToolStripLayoutStyle.VerticalStackWithOverflow, ts.LayoutStyle, "B1");
457                         Assert.AreEqual ("LayoutCompleted;LayoutStyleChanged", ew.ToString (), "B2");
458
459                         ew.Clear ();
460                         ts.LayoutStyle = ToolStripLayoutStyle.VerticalStackWithOverflow;
461                         Assert.AreEqual (string.Empty, ew.ToString (), "B3");
462                 }
463
464                 [Test]
465                 [ExpectedException (typeof (InvalidEnumArgumentException))]
466                 public void PropertyLayoutStyleIEAE ()
467                 {
468                         ToolStrip ts = new ToolStrip ();
469
470                         ts.LayoutStyle = (ToolStripLayoutStyle) 42;
471                 }
472
473                 [Test]
474                 public void PropertyRenderer ()
475                 {
476                         ToolStrip ts = new ToolStrip ();
477                         EventWatcher ew = new EventWatcher (ts);
478
479                         ToolStripProfessionalRenderer pr = new ToolStripProfessionalRenderer ();
480
481                         ts.Renderer = pr;
482                         Assert.AreSame (pr, ts.Renderer, "B1");
483                         Assert.AreEqual ("LayoutCompleted;RendererChanged", ew.ToString (), "B2");
484                         Assert.AreEqual (ToolStripRenderMode.Custom, ts.RenderMode, "B4");
485                         
486                         ew.Clear ();
487                         ts.Renderer = pr;
488                         Assert.AreEqual (string.Empty, ew.ToString (), "B3");
489                 }
490
491                 [Test]
492                 public void PropertyRenderMode ()
493                 {
494                         ToolStrip ts = new ToolStrip ();
495                         EventWatcher ew = new EventWatcher (ts);
496
497                         ts.RenderMode = ToolStripRenderMode.System;
498                         Assert.AreEqual (ToolStripRenderMode.System, ts.RenderMode, "B1");
499                         Assert.AreEqual ("LayoutCompleted;RendererChanged", ew.ToString (), "B2");
500
501                         ew.Clear ();
502                         ts.RenderMode = ToolStripRenderMode.System;
503                         Assert.AreEqual ("LayoutCompleted;RendererChanged", ew.ToString (), "B3");
504                 }
505
506                 [Test]
507                 [ExpectedException (typeof (NotSupportedException))]
508                 public void PropertyRenderModeNSE ()
509                 {
510                         ToolStrip ts = new ToolStrip ();
511
512                         ts.RenderMode = ToolStripRenderMode.Custom;
513                 }
514
515                 [Test]
516                 [ExpectedException (typeof (InvalidEnumArgumentException))]
517                 public void PropertyRenderModeIEAE ()
518                 {
519                         ToolStrip ts = new ToolStrip ();
520
521                         ts.RenderMode = (ToolStripRenderMode) 42;
522                 }
523
524                 [Test]
525                 public void PropertyShowItemToolTips ()
526                 {
527                         ToolStrip ts = new ToolStrip ();
528                         EventWatcher ew = new EventWatcher (ts);
529
530                         ts.ShowItemToolTips = false;
531                         Assert.AreEqual (false, ts.ShowItemToolTips, "B1");
532                         Assert.AreEqual (string.Empty, ew.ToString (), "B2");
533                 }
534
535                 [Test]
536                 public void PropertyStretch ()
537                 {
538                         ToolStrip ts = new ToolStrip ();
539                         EventWatcher ew = new EventWatcher (ts);
540
541                         ts.Stretch = true;
542                         Assert.AreEqual (true, ts.Stretch, "B1");
543                         Assert.AreEqual (string.Empty, ew.ToString (), "B2");
544                 }
545
546                 [Test]
547                 public void PropertyTabStop ()
548                 {
549                         ToolStrip ts = new ToolStrip ();
550                         EventWatcher ew = new EventWatcher (ts);
551
552                         ts.TabStop = true;
553                         Assert.AreEqual (true, ts.TabStop, "B1");
554                         Assert.AreEqual (string.Empty, ew.ToString (), "B2");
555                 }
556
557                 //[Test]
558                 //public void PropertyTextDirection ()
559                 //{
560                 //        ToolStrip ts = new ToolStrip ();
561                 //        EventWatcher ew = new EventWatcher (ts);
562
563                 //        ts.TextDirection = ToolStripTextDirection.Vertical270;
564                 //        Assert.AreEqual (ToolStripTextDirection.Vertical270, ts.TextDirection, "B1");
565                 //        Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B2");
566
567                 //        ew.Clear ();
568                 //        ts.TextDirection = ToolStripTextDirection.Vertical270;
569                 //        Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B3");
570                 //}
571
572                 [Test]
573                 [ExpectedException (typeof (InvalidEnumArgumentException))]
574                 public void PropertyTextDirectionIEAE ()
575                 {
576                         ToolStrip ts = new ToolStrip ();
577                         EventWatcher ew = new EventWatcher (ts);
578
579                         ts.TextDirection = (ToolStripTextDirection)42;
580                 }
581
582                 [Test]
583                 [NUnit.Framework.Category ("NotWorking")]
584                 public void BehaviorDisplayRectangleAndOverflow ()
585                 {
586                         // WM decoration size dependent
587                         Form f = new Form ();
588                         f.ShowInTaskbar = false;
589                         ToolStrip ts = new ToolStrip ();
590                         f.Controls.Add (ts);
591                         f.Show ();
592
593                         Assert.AreEqual (false, ts.OverflowButton.Visible, "D1");
594                         Assert.AreEqual (new Rectangle (7, 0, 284, 25), ts.DisplayRectangle, "D2");
595
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"));
602                         
603                         Assert.AreEqual (true, ts.OverflowButton.Visible, "D3");
604                         Assert.AreEqual (new Rectangle (7, 0, 284, 25), ts.DisplayRectangle, "D4");
605                         f.Dispose ();
606                 }
607         
608                 [Test]
609                 public void BehaviorGripAndOverflowWithFlowLayout ()
610                 {
611                         ToolStrip ts = new ToolStrip ();
612                         ts.LayoutStyle = ToolStripLayoutStyle.Flow;
613                         
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");                  
617                 }
618         
619                 [Test]
620                 public void BehaviorDockAndOrientation ()
621                 {
622                         Form f = new Form ();
623                         f.ShowInTaskbar = false;
624                         
625                         ToolStrip ts = new ToolStrip ();
626                         ts.Dock = DockStyle.Left;
627                         
628                         f.Controls.Add (ts);
629                         f.Show ();
630                         
631                         Assert.AreEqual (ToolStripLayoutStyle.VerticalStackWithOverflow, ts.LayoutStyle, "A1");
632                         Assert.AreEqual (Orientation.Vertical, ts.Orientation, "A2");
633
634                         ts.LayoutStyle = ToolStripLayoutStyle.StackWithOverflow;
635                         Assert.AreEqual (ToolStripLayoutStyle.VerticalStackWithOverflow, ts.LayoutStyle, "A3");
636                         Assert.AreEqual (Orientation.Vertical, ts.Orientation, "A4");
637
638                         ts.LayoutStyle = ToolStripLayoutStyle.HorizontalStackWithOverflow;
639                         Assert.AreEqual (ToolStripLayoutStyle.HorizontalStackWithOverflow, ts.LayoutStyle, "A5");
640                         Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A6");
641                         
642                         ts.LayoutStyle = ToolStripLayoutStyle.Flow;
643                         Assert.AreEqual (ToolStripLayoutStyle.Flow, ts.LayoutStyle, "A7");
644                         Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A8");
645
646                         ts.LayoutStyle = ToolStripLayoutStyle.StackWithOverflow;
647                         Assert.AreEqual (ToolStripLayoutStyle.VerticalStackWithOverflow, ts.LayoutStyle, "A9");
648                         Assert.AreEqual (Orientation.Vertical, ts.Orientation, "A10");
649                         
650                         f.Close ();
651                 }
652                 
653                 [Test]
654                 public void MethodCreateLayoutSettings ()
655                 {
656                         ExposeProtectedProperties ts = new ExposeProtectedProperties ();
657
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");
663                 }
664
665                 [Test]
666                 public void MethodDipose()
667                 {
668                         ToolStrip ts = new ToolStrip ();
669                         ToolStripItem item_a = ts.Items.Add ("A");
670                         ToolStripItem item_b = ts.Items.Add ("B");
671                         ToolStripItem item_c = ts.Items.Add ("C");
672
673                         Assert.AreEqual (3, ts.Items.Count, "A1");
674
675                         ts.Dispose ();
676
677                         Assert.AreEqual (0, ts.Items.Count, "A2");
678                         Assert.IsTrue (item_a.IsDisposed, "A3");
679                         Assert.IsTrue (item_b.IsDisposed, "A4");
680                         Assert.IsTrue (item_c.IsDisposed, "A5");
681                 }
682
683                 [Test]
684                 public void MethodGetNextItem ()
685                 {
686                         ToolStrip ts = new ToolStrip ();
687                         ts.Items.Add ("Test Item 1");
688                         
689                         Form f = new Form ();
690                         f.ShowInTaskbar = false;
691                         f.Controls.Add (ts);
692                         f.Show ();
693
694                         Assert.AreEqual (ts.Items[0], ts.GetNextItem (null, ArrowDirection.Right), "A1");
695                         Assert.AreEqual (ts.Items[0], ts.GetNextItem (ts.Items[0], ArrowDirection.Right), "A2");
696
697                         ts.Items.Add ("Test Item 2");
698                         
699                         Assert.AreEqual (ts.Items[0], ts.GetNextItem (null, ArrowDirection.Right), "A3");
700                         Assert.AreEqual (ts.Items[1], ts.GetNextItem (ts.Items[0], ArrowDirection.Right), "A4");
701
702                         f.Dispose ();
703                 }
704                 
705                 [Test]
706                 [ExpectedException (typeof (InvalidEnumArgumentException))]
707                 public void MethodGetNextItemIEAE ()
708                 {
709                         ToolStrip ts = new ToolStrip ();
710                         ts.GetNextItem (null, (ArrowDirection)42);
711                 }
712                 
713                 [Test]
714                 [NUnit.Framework.Category ("NotWorking")]
715                 public void MethodResetMinimumSize ()
716                 {
717                         ToolStrip ts = new ToolStrip ();
718                         ts.Size = new Size (600, 600);
719                         
720                         Assert.AreEqual (new Size (0, 0), ts.MinimumSize, "M0");
721                         
722                         ts.MinimumSize = new Size (400, 400);
723
724                         Assert.AreEqual (new Size (600, 600), ts.Size, "M1");
725                         Assert.AreEqual (new Size (400, 400), ts.MinimumSize, "M2");
726                         
727                         ts.ResetMinimumSize ();
728                         Assert.AreEqual (new Size (600, 600), ts.Size, "M3");
729                         Assert.AreEqual (new Size (-1, -1), ts.MinimumSize, "M4");
730                 }
731                 
732                 [Test]
733                 public void TestToolStrip ()
734                 {
735                         ToolStrip ts = new ToolStrip ();
736
737                         ts.Items.Add (new ToolStripButton ());
738                         Assert.AreEqual (new Rectangle (0, 0, 100, 25), ts.Bounds, "D1");
739                         Assert.AreEqual (new Rectangle (7, 0, 92, 25), ts.DisplayRectangle, "D2");
740                         Assert.AreEqual (new Rectangle (2, 0, 3, 25), ts.GripRectangle, "D4");
741                         Assert.AreEqual (new Padding (2), ts.GripMargin, "D5");
742
743                         ts.GripStyle = ToolStripGripStyle.Hidden;
744
745                         Assert.AreEqual (new Rectangle (0, 0, 0, 0), ts.GripRectangle, "D8");
746                         Assert.AreEqual (new Rectangle (0, 0, 99, 25), ts.DisplayRectangle, "D3");
747                         Assert.AreEqual (new Padding (2), ts.GripMargin, "D5");
748
749                         ts.BackColor = Color.Aquamarine;
750                         Assert.AreEqual (Color.Aquamarine, ts.BackColor, "A2");
751
752                         ts.ForeColor = Color.LightSalmon;
753                         Assert.AreEqual (Color.LightSalmon, ts.ForeColor, "A5");
754
755                         ts.GripMargin = new Padding (3);
756                         Assert.AreEqual (new Padding (3), ts.GripMargin, "A7");
757                 }
758                 
759                 [Test]
760                 [Ignore ("Accessibility still needs some work")]
761                 public void Accessibility ()
762                 {
763                         ToolStrip ts = new ToolStrip ();
764                         AccessibleObject ao = ts.AccessibilityObject;
765
766                         Assert.AreEqual ("ControlAccessibleObject: Owner = " + ts.ToString (), ao.ToString (), "L");
767                         //Assert.AreEqual (Rectangle.Empty, ao.Bounds, "L1");
768                         Assert.AreEqual (null, ao.DefaultAction, "L2");
769                         Assert.AreEqual (null, ao.Description, "L3");
770                         Assert.AreEqual (null, ao.Help, "L4");
771                         Assert.AreEqual (null, ao.KeyboardShortcut, "L5");
772                         Assert.AreEqual (null, ao.Name, "L6");
773                         //Assert.AreEqual (null, ao.Parent, "L7");
774                         Assert.AreEqual (AccessibleRole.ToolBar, ao.Role, "L8");
775                         Assert.AreEqual (AccessibleStates.None, ao.State, "L9");
776                         Assert.AreEqual (null, ao.Value, "L10");
777
778                         ts.Name = "Label1";
779                         ts.Text = "Test Label";
780                         ts.AccessibleDescription = "Label Desc";
781
782                         //Assert.AreEqual (Rectangle.Empty, ao.Bounds, "L11");
783                         Assert.AreEqual (null, ao.DefaultAction, "L12");
784                         Assert.AreEqual ("Label Desc", ao.Description, "L13");
785                         Assert.AreEqual (null, ao.Help, "L14");
786                         Assert.AreEqual (null, ao.KeyboardShortcut, "L15");
787                         //Assert.AreEqual ("Test Label", ao.Name, "L16");
788                         //Assert.AreEqual (null, ao.Parent, "L17");
789                         Assert.AreEqual (AccessibleRole.ToolBar, ao.Role, "L18");
790                         Assert.AreEqual (AccessibleStates.None, ao.State, "L19");
791                         Assert.AreEqual (null, ao.Value, "L20");
792
793                         ts.AccessibleName = "Access Label";
794                         Assert.AreEqual ("Access Label", ao.Name, "L21");
795
796                         ts.Text = "Test Label";
797                         Assert.AreEqual ("Access Label", ao.Name, "L22");
798
799                         ts.AccessibleDefaultActionDescription = "AAA";
800                         Assert.AreEqual ("AAA", ts.AccessibleDefaultActionDescription, "L23");
801                 }
802                 
803                 private class EventWatcher
804                 {
805                         private string events = string.Empty;
806                         
807                         public EventWatcher (ToolStrip ts)
808                         {
809                                 ts.AutoSizeChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("AutoSizeChanged;"); });
810                                 //ts.BeginDrag += new EventHandler (delegate (Object obj, EventArgs e) { events += ("BeginDrag;"); });
811                                 ts.CausesValidationChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("CausesValidationChanged;"); });
812                                 ts.CursorChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("CursorChanged;"); });
813                                 //ts.EndDrag += new EventHandler (delegate (Object obj, EventArgs e) { events += ("EndDrag;"); });
814                                 ts.ForeColorChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("ForeColorChanged;"); });
815                                 ts.ItemAdded += new ToolStripItemEventHandler (delegate (Object obj, ToolStripItemEventArgs e) { events += ("ItemAdded;"); });
816                                 ts.ItemClicked += new ToolStripItemClickedEventHandler (delegate (Object obj, ToolStripItemClickedEventArgs e) { events += ("ItemClicked;"); });
817                                 ts.ItemRemoved += new ToolStripItemEventHandler (delegate (Object obj, ToolStripItemEventArgs e) { events += ("ItemRemoved;"); });
818                                 ts.LayoutCompleted += new EventHandler (delegate (Object obj, EventArgs e) { events += ("LayoutCompleted;"); });
819                                 ts.LayoutStyleChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("LayoutStyleChanged;"); });
820                                 ts.PaintGrip += new PaintEventHandler (delegate (Object obj, PaintEventArgs e) { events += ("PaintGrip;"); });
821                                 ts.RendererChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("RendererChanged;"); });
822                         }
823
824                         public override string ToString ()
825                         {
826                                 return events.TrimEnd (';');
827                         }
828                         
829                         public void Clear ()
830                         {
831                                 events = string.Empty;
832                         }
833                 }
834                 
835                 private class ExposeProtectedProperties : ToolStrip
836                 {
837                         public new DockStyle DefaultDock { get { return base.DefaultDock; } }
838                         public new Padding DefaultGripMargin { get { return base.DefaultGripMargin; } }
839                         public new Padding DefaultMargin { get { return base.DefaultMargin; } }
840                         public new Padding DefaultPadding { get { return base.DefaultPadding; } }
841                         public new bool DefaultShowItemToolTips { get { return base.DefaultShowItemToolTips; } }
842                         public new Size DefaultSize { get { return base.DefaultSize; } }
843                         public new Size MaxItemSize { get { return base.MaxItemSize; } }
844                         
845                         public ControlStyles GetControlStyles ()
846                         {
847                                 ControlStyles retval = (ControlStyles) 0;
848                                 
849                                 foreach (ControlStyles cs in Enum.GetValues (typeof (ControlStyles)))
850                                         if (this.GetStyle (cs) == true)
851                                                 retval |= cs;
852                                                 
853                                 return retval;
854                         }
855                         
856                         public LayoutSettings PublicCreateLayoutSettings (ToolStripLayoutStyle layoutStyle) { return base.CreateLayoutSettings (layoutStyle); }
857                 }
858         }
859 }
860 #endif