3 using System
.Windows
.Forms
;
7 namespace MonoTests
.System
.Windows
.Forms
10 public class DefaultLayoutTest
13 LayoutEventArgs most_recent_args
;
15 void p_Layout (object sender
, LayoutEventArgs e
)
22 public void AnchorLayoutEvents ()
32 p
.Layout
+= new LayoutEventHandler (p_Layout
);
34 /* set the button's anchor to something different */
35 b
.Anchor
= AnchorStyles
.Bottom
;
36 Assert
.AreEqual (1, event_count
, "1");
37 Assert
.AreEqual ("Anchor", most_recent_args
.AffectedProperty
, "2");
39 /* reset it to something new with the panel's layout suspended */
42 b
.Anchor
= AnchorStyles
.Top
;
43 Assert
.AreEqual (0, event_count
, "3");
45 Assert
.AreEqual (1, event_count
, "4");
46 Assert
.AreEqual (null, most_recent_args
.AffectedProperty
, "5");
48 /* with the anchor style set to something, resize the parent */
50 p
.Size
= new Size (500, 500);
51 Assert
.AreEqual (1, event_count
, "6");
52 Assert
.AreEqual ("Bounds", most_recent_args
.AffectedProperty
, "7");
54 /* now try it with layout suspended */
57 p
.Size
= new Size (400, 400);
58 Assert
.AreEqual (0, event_count
, "8");
60 Assert
.AreEqual (1, event_count
, "9");
61 Assert
.AreEqual (null, most_recent_args
.AffectedProperty
, "10");
63 /* with the anchor style set to something, resize the child */
65 b
.Size
= new Size (100, 100);
66 Assert
.AreEqual (1, event_count
, "11");
67 Assert
.AreEqual ("Bounds", most_recent_args
.AffectedProperty
, "12");
69 /* and again with layout suspended */
72 b
.Size
= new Size (200, 200);
73 Assert
.AreEqual (0, event_count
, "13");
75 Assert
.AreEqual (1, event_count
, "14");
76 Assert
.AreEqual (null, most_recent_args
.AffectedProperty
, "15");
80 public void AnchorTopLeftTest ()
83 f
.ShowInTaskbar
= false;
85 f
.Size
= new Size (200, 200);
87 Button b
= new Button ();
88 b
.Size
= new Size (100, 100);
89 b
.Anchor
= AnchorStyles
.Top
| AnchorStyles
.Left
;
93 Assert
.AreEqual (0, b
.Left
, "1");
94 Assert
.AreEqual (0, b
.Top
, "2");
95 f
.Size
= new Size (300, 300);
97 Assert
.AreEqual (0, b
.Left
, "3");
98 Assert
.AreEqual (0, b
.Top
, "4");
104 public void AnchorTopRightTest ()
106 Form f
= new Form ();
107 f
.ShowInTaskbar
= false;
109 f
.Size
= new Size (200, 200);
111 Button b
= new Button ();
112 b
.Size
= new Size (100, 100);
113 b
.Anchor
= AnchorStyles
.Top
| AnchorStyles
.Right
;
117 Assert
.AreEqual (0, b
.Left
, "1");
118 Assert
.AreEqual (0, b
.Top
, "2");
120 f
.Size
= new Size (300, 300);
122 Assert
.AreEqual (100, b
.Left
, "3");
123 Assert
.AreEqual (0, b
.Top
, "4");
129 public void AnchorLeftRightTest ()
131 Form f
= new Form ();
132 f
.ShowInTaskbar
= false;
134 f
.Size
= new Size (200, 200);
136 Button b
= new Button ();
137 b
.Size
= new Size (100, 100);
138 b
.Anchor
= AnchorStyles
.Left
| AnchorStyles
.Right
;
142 Assert
.AreEqual (0, b
.Left
, "1");
143 Assert
.AreEqual (100, b
.Right
, "2");
145 f
.Size
= new Size (300, 300);
147 Assert
.AreEqual (0, b
.Left
, "3");
148 Assert
.AreEqual (200, b
.Right
, "4");
154 public void AnchorBottomLeftTest ()
156 Form f
= new Form ();
157 f
.ShowInTaskbar
= false;
159 f
.Size
= new Size (200, 200);
161 Button b
= new Button ();
162 b
.Size
= new Size (100, 100);
163 b
.Anchor
= AnchorStyles
.Left
| AnchorStyles
.Bottom
;
167 Assert
.AreEqual (0, b
.Left
, "1");
168 Assert
.AreEqual (0, b
.Top
, "2");
170 f
.Size
= new Size (300, 300);
172 Assert
.AreEqual (0, b
.Left
, "3");
173 Assert
.AreEqual (100, b
.Top
, "4");
179 public void AnchorBottomRightTest ()
181 Form f
= new Form ();
182 f
.ShowInTaskbar
= false;
184 f
.Size
= new Size (200, 200);
186 Button b
= new Button ();
187 b
.Size
= new Size (100, 100);
188 b
.Anchor
= AnchorStyles
.Right
| AnchorStyles
.Bottom
;
192 Assert
.AreEqual (0, b
.Left
, "1");
193 Assert
.AreEqual (0, b
.Top
, "2");
195 f
.Size
= new Size (300, 300);
197 Assert
.AreEqual (100, b
.Left
, "3");
198 Assert
.AreEqual (100, b
.Top
, "4");
204 public void AnchorTopBottomTest ()
206 Form f
= new Form ();
207 f
.ShowInTaskbar
= false;
209 f
.Size
= new Size (200, 200);
211 Button b
= new Button ();
212 b
.Size
= new Size (100, 100);
213 b
.Anchor
= AnchorStyles
.Top
| AnchorStyles
.Bottom
;
217 Assert
.AreEqual (0, b
.Top
, "1");
218 Assert
.AreEqual (100, b
.Bottom
, "2");
220 f
.Size
= new Size (300, 300);
222 Assert
.AreEqual (0, b
.Top
, "3");
223 Assert
.AreEqual (200, b
.Bottom
, "4");
228 // Unit test version of the test case in bug #80336
230 public void AnchorSuspendLayoutTest ()
232 Form f
= new Form ();
233 f
.ShowInTaskbar
= false;
237 Button b
= new Button ();
238 b
.Size
= new Size (100, 100);
242 f
.Size
= new Size (200, 200);
244 b
.Anchor
= AnchorStyles
.Bottom
| AnchorStyles
.Right
;
246 Assert
.AreEqual (0, b
.Top
, "1");
247 Assert
.AreEqual (0, b
.Left
, "2");
249 f
.Size
= new Size (300, 300);
251 Assert
.AreEqual (0, b
.Top
, "3");
252 Assert
.AreEqual (0, b
.Left
, "4");
256 Assert
.AreEqual (100, b
.Top
, "5");
257 Assert
.AreEqual (100, b
.Left
, "6");
262 // another variant of AnchorSuspendLayoutTest1, with
263 // the SuspendLayout moved after the Anchor
266 public void AnchorSuspendLayoutTest2 ()
268 Form f
= new Form ();
269 f
.ShowInTaskbar
= false;
271 Button b
= new Button ();
272 b
.Size
= new Size (100, 100);
276 f
.Size
= new Size (200, 200);
278 b
.Anchor
= AnchorStyles
.Bottom
| AnchorStyles
.Right
;
280 Assert
.AreEqual (0, b
.Top
, "1");
281 Assert
.AreEqual (0, b
.Left
, "2");
285 f
.Size
= new Size (300, 300);
287 Assert
.AreEqual (0, b
.Top
, "3");
288 Assert
.AreEqual (0, b
.Left
, "4");
292 Assert
.AreEqual (100, b
.Top
, "5");
293 Assert
.AreEqual (100, b
.Left
, "6");
298 // yet another variant, this time with no Suspend/Resume.
300 public void AnchorSuspendLayoutTest3 ()
302 Form f
= new Form ();
303 f
.ShowInTaskbar
= false;
305 Button b
= new Button ();
306 b
.Size
= new Size (100, 100);
310 f
.Size
= new Size (200, 200);
312 b
.Anchor
= AnchorStyles
.Bottom
| AnchorStyles
.Right
;
314 Assert
.AreEqual (0, b
.Top
, "1");
315 Assert
.AreEqual (0, b
.Left
, "2");
317 f
.Size
= new Size (300, 300);
319 Assert
.AreEqual (100, b
.Top
, "5");
320 Assert
.AreEqual (100, b
.Left
, "6");
327 public class DockingTests
338 form
.ShowInTaskbar
= false;
339 form
.Size
= new Size (400, 400);
340 panel
= new Panel ();
341 form
.Controls
.Add (panel
);
346 public void Cleanup ()
351 void IncrementEventCount (object o
, EventArgs args
)
357 public void TestDockSizeChangedEvent ()
359 panel
.SizeChanged
+= new EventHandler (IncrementEventCount
);
360 panel
.Dock
= DockStyle
.Bottom
;
361 Assert
.AreEqual (1, event_count
);
365 public void TestDockLocationChangedEvent ()
367 panel
.LocationChanged
+= new EventHandler (IncrementEventCount
);
368 panel
.Dock
= DockStyle
.Bottom
;
369 Assert
.AreEqual (1, event_count
);
375 public class UndockingTests
377 class TestPanel
: Panel
{
379 public void InvokeSetBoundsCore ()
381 SetBoundsCore (37, 37, 37, 37, BoundsSpecified
.All
);
384 public void InvokeUpdateBounds ()
386 UpdateBounds (37, 37, 37, 37);
397 form
.ShowInTaskbar
= false;
398 form
.Size
= new Size (400, 400);
399 panel
= new TestPanel ();
400 form
.Controls
.Add (panel
);
404 public void Cleanup ()
410 public void TestUndockDefaultLocation ()
412 Point loc
= panel
.Location
;
413 panel
.Dock
= DockStyle
.Bottom
;
414 panel
.Dock
= DockStyle
.None
;
415 Assert
.AreEqual (loc
, panel
.Location
);
419 public void TestUndockDefaultLocationVisible ()
422 Point loc
= panel
.Location
;
423 panel
.Dock
= DockStyle
.Bottom
;
424 panel
.Dock
= DockStyle
.None
;
425 Assert
.AreEqual (loc
, panel
.Location
);
429 public void TestUndockExplicitLeft ()
432 panel
.Dock
= DockStyle
.Top
;
433 panel
.Dock
= DockStyle
.None
;
434 Assert
.AreEqual (150, panel
.Left
);
438 public void TestUndockExplicitTop ()
441 panel
.Dock
= DockStyle
.Top
;
442 panel
.Dock
= DockStyle
.None
;
443 Assert
.AreEqual (150, panel
.Top
);
447 public void TestUndockExplicitLocation ()
449 panel
.Location
= new Point (50, 50);
450 Point loc
= panel
.Location
;
451 panel
.Dock
= DockStyle
.Bottom
;
452 panel
.Dock
= DockStyle
.None
;
453 Assert
.AreEqual (loc
, panel
.Location
);
457 public void TestUndockExplicitLeftVisible ()
461 panel
.Dock
= DockStyle
.Top
;
462 panel
.Dock
= DockStyle
.None
;
463 Assert
.AreEqual (150, panel
.Left
);
467 public void TestUndockExplicitTopVisible ()
471 panel
.Dock
= DockStyle
.Top
;
472 panel
.Dock
= DockStyle
.None
;
473 Assert
.AreEqual (150, panel
.Top
);
477 public void TestUndockExplicitLocationVisible ()
480 panel
.Location
= new Point (50, 50);
481 Point loc
= panel
.Location
;
482 panel
.Dock
= DockStyle
.Bottom
;
483 panel
.Dock
= DockStyle
.None
;
484 Assert
.AreEqual (loc
, panel
.Location
);
488 [Category ("NotWorking")]
489 public void TestUndockDefaultSize ()
491 Size sz
= panel
.Size
;
492 panel
.Dock
= DockStyle
.Fill
;
493 panel
.Dock
= DockStyle
.None
;
494 Assert
.AreEqual (sz
, panel
.Size
);
498 public void TestUndockExplicitHeight ()
501 panel
.Dock
= DockStyle
.Left
;
502 panel
.Dock
= DockStyle
.None
;
503 Assert
.AreEqual (50, panel
.Height
);
507 [Category ("NotWorking")]
508 public void TestUndockExplicitSize ()
510 panel
.Size
= new Size (50, 50);
511 Size sz
= panel
.Size
;
512 panel
.Dock
= DockStyle
.Fill
;
513 panel
.Dock
= DockStyle
.None
;
514 Assert
.AreEqual (sz
, panel
.Size
);
518 public void TestUndockExplicitWidth ()
521 panel
.Dock
= DockStyle
.Top
;
522 panel
.Dock
= DockStyle
.None
;
523 Assert
.AreEqual (50, panel
.Width
);
527 public void TestUndockExplicitHeightVisible ()
531 panel
.Dock
= DockStyle
.Left
;
532 panel
.Dock
= DockStyle
.None
;
533 Assert
.AreEqual (50, panel
.Height
);
537 [Category ("NotWorking")]
538 public void TestUndockExplicitSizeVisible ()
541 panel
.Size
= new Size (50, 50);
542 Size sz
= panel
.Size
;
543 panel
.Dock
= DockStyle
.Fill
;
544 panel
.Dock
= DockStyle
.None
;
545 Assert
.AreEqual (sz
, panel
.Size
);
549 public void TestUndockExplicitWidthVisible ()
553 panel
.Dock
= DockStyle
.Top
;
554 panel
.Dock
= DockStyle
.None
;
555 Assert
.AreEqual (50, panel
.Width
);
559 public void TestUndockSetBounds ()
561 panel
.SetBounds (50, 50, 50, 50, BoundsSpecified
.All
);
562 panel
.Dock
= DockStyle
.Top
;
563 panel
.Dock
= DockStyle
.None
;
564 Assert
.AreEqual (50, panel
.Height
, "Height");
565 Assert
.AreEqual (50, panel
.Left
, "Left");
566 Assert
.AreEqual (50, panel
.Top
, "Top");
567 Assert
.AreEqual (50, panel
.Width
, "Width");
571 public void TestUndockSetBoundsVisible ()
574 panel
.SetBounds (50, 50, 50, 50, BoundsSpecified
.All
);
575 panel
.Dock
= DockStyle
.Top
;
576 panel
.Dock
= DockStyle
.None
;
577 Assert
.AreEqual (50, panel
.Height
, "Height");
578 Assert
.AreEqual (50, panel
.Left
, "Left");
579 Assert
.AreEqual (50, panel
.Top
, "Top");
580 Assert
.AreEqual (50, panel
.Width
, "Width");
584 public void TestUndockSetBoundsCore ()
586 panel
.InvokeSetBoundsCore ();
587 panel
.Dock
= DockStyle
.Top
;
588 panel
.Dock
= DockStyle
.None
;
589 Assert
.AreEqual (37, panel
.Height
, "Height");
590 Assert
.AreEqual (37, panel
.Left
, "Left");
591 Assert
.AreEqual (37, panel
.Top
, "Top");
592 Assert
.AreEqual (37, panel
.Width
, "Width");
596 public void TestUndockSetBoundsCoreVisible ()
599 panel
.InvokeSetBoundsCore ();
600 panel
.Dock
= DockStyle
.Top
;
601 panel
.Dock
= DockStyle
.None
;
602 Assert
.AreEqual (37, panel
.Height
, "Height");
603 Assert
.AreEqual (37, panel
.Left
, "Left");
604 Assert
.AreEqual (37, panel
.Top
, "Top");
605 Assert
.AreEqual (37, panel
.Width
, "Width");
609 public void TestUndockUpdateBounds ()
611 panel
.InvokeUpdateBounds ();
612 panel
.Dock
= DockStyle
.Top
;
613 panel
.Dock
= DockStyle
.None
;
614 Assert
.AreEqual (37, panel
.Height
, "Height");
615 Assert
.AreEqual (37, panel
.Left
, "Left");
616 Assert
.AreEqual (37, panel
.Top
, "Top");
617 Assert
.AreEqual (37, panel
.Width
, "Width");
621 public void TestUndockUpdateBoundsVisible ()
624 panel
.InvokeUpdateBounds ();
625 panel
.Dock
= DockStyle
.Top
;
626 panel
.Dock
= DockStyle
.None
;
627 Assert
.AreEqual (37, panel
.Height
, "Height");
628 Assert
.AreEqual (37, panel
.Left
, "Left");
629 Assert
.AreEqual (37, panel
.Top
, "Top");
630 Assert
.AreEqual (37, panel
.Width
, "Width");