2007-01-10 Chris Toshok <toshok@ximian.com>
[mono-project.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / DefaultLayoutTest.cs
blob217fc4fe0031a95aa3a3a4eaf2006f271e1c529b
1 using System;
2 using System.Drawing;
3 using System.Windows.Forms;
5 using NUnit.Framework;
7 namespace MonoTests.System.Windows.Forms
9 [TestFixture]
10 public class DefaultLayoutTest
12 int event_count;
13 LayoutEventArgs most_recent_args;
15 void p_Layout (object sender, LayoutEventArgs e)
17 event_count ++;
18 most_recent_args = e;
21 [Test]
22 public void AnchorLayoutEvents ()
24 Panel p;
25 Button b;
27 p = new Panel ();
29 b = new Button ();
30 p.Controls.Add (b);
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 */
40 event_count = 0;
41 p.SuspendLayout ();
42 b.Anchor = AnchorStyles.Top;
43 Assert.AreEqual (0, event_count, "3");
44 p.ResumeLayout ();
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 */
49 event_count = 0;
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 */
55 event_count = 0;
56 p.SuspendLayout ();
57 p.Size = new Size (400, 400);
58 Assert.AreEqual (0, event_count, "8");
59 p.ResumeLayout ();
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 */
64 event_count = 0;
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 */
70 event_count = 0;
71 p.SuspendLayout ();
72 b.Size = new Size (200, 200);
73 Assert.AreEqual (0, event_count, "13");
74 p.ResumeLayout ();
75 Assert.AreEqual (1, event_count, "14");
76 Assert.AreEqual (null, most_recent_args.AffectedProperty, "15");
79 [Test]
80 public void AnchorTopLeftTest ()
82 Form f = new Form ();
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;
91 f.Controls.Add (b);
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");
100 f.Dispose ();
103 [Test]
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;
115 f.Controls.Add (b);
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");
125 f.Dispose ();
128 [Test]
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;
140 f.Controls.Add (b);
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");
150 f.Dispose ();
153 [Test]
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;
165 f.Controls.Add (b);
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");
175 f.Dispose ();
178 [Test]
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;
190 f.Controls.Add (b);
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");
200 f.Dispose ();
203 [Test]
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;
215 f.Controls.Add (b);
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");
225 f.Dispose ();
228 // Unit test version of the test case in bug #80336
229 [Test]
230 public void AnchorSuspendLayoutTest ()
232 Form f = new Form ();
233 f.ShowInTaskbar = false;
235 f.SuspendLayout ();
237 Button b = new Button ();
238 b.Size = new Size (100, 100);
240 f.Controls.Add (b);
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");
254 f.ResumeLayout();
256 Assert.AreEqual (100, b.Top, "5");
257 Assert.AreEqual (100, b.Left, "6");
259 f.Dispose ();
262 // another variant of AnchorSuspendLayoutTest1, with
263 // the SuspendLayout moved after the Anchor
264 // assignment.
265 [Test]
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);
274 f.Controls.Add (b);
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");
283 f.SuspendLayout ();
285 f.Size = new Size (300, 300);
287 Assert.AreEqual (0, b.Top, "3");
288 Assert.AreEqual (0, b.Left, "4");
290 f.ResumeLayout();
292 Assert.AreEqual (100, b.Top, "5");
293 Assert.AreEqual (100, b.Left, "6");
295 f.Dispose ();
298 // yet another variant, this time with no Suspend/Resume.
299 [Test]
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);
308 f.Controls.Add (b);
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");
322 f.Dispose ();
326 [TestFixture]
327 public class DockingTests
329 Form form;
330 Panel panel;
332 int event_count;
334 [SetUp]
335 public void Init ()
337 form = new Form ();
338 form.ShowInTaskbar = false;
339 form.Size = new Size (400, 400);
340 panel = new Panel ();
341 form.Controls.Add (panel);
342 event_count = 0;
345 [TearDown]
346 public void Cleanup ()
348 form.Dispose ();
351 void IncrementEventCount (object o, EventArgs args)
353 event_count++;
356 [Test]
357 public void TestDockSizeChangedEvent ()
359 panel.SizeChanged += new EventHandler (IncrementEventCount);
360 panel.Dock = DockStyle.Bottom;
361 Assert.AreEqual (1, event_count);
364 [Test]
365 public void TestDockLocationChangedEvent ()
367 panel.LocationChanged += new EventHandler (IncrementEventCount);
368 panel.Dock = DockStyle.Bottom;
369 Assert.AreEqual (1, event_count);
374 [TestFixture]
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);
390 Form form;
391 TestPanel panel;
393 [SetUp]
394 public void Init ()
396 form = new Form ();
397 form.ShowInTaskbar = false;
398 form.Size = new Size (400, 400);
399 panel = new TestPanel ();
400 form.Controls.Add (panel);
403 [TearDown]
404 public void Cleanup ()
406 form.Dispose ();
409 [Test]
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);
418 [Test]
419 public void TestUndockDefaultLocationVisible ()
421 form.Show ();
422 Point loc = panel.Location;
423 panel.Dock = DockStyle.Bottom;
424 panel.Dock = DockStyle.None;
425 Assert.AreEqual (loc, panel.Location);
428 [Test]
429 public void TestUndockExplicitLeft ()
431 panel.Left = 150;
432 panel.Dock = DockStyle.Top;
433 panel.Dock = DockStyle.None;
434 Assert.AreEqual (150, panel.Left);
437 [Test]
438 public void TestUndockExplicitTop ()
440 panel.Top = 150;
441 panel.Dock = DockStyle.Top;
442 panel.Dock = DockStyle.None;
443 Assert.AreEqual (150, panel.Top);
446 [Test]
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);
456 [Test]
457 public void TestUndockExplicitLeftVisible ()
459 form.Show ();
460 panel.Left = 150;
461 panel.Dock = DockStyle.Top;
462 panel.Dock = DockStyle.None;
463 Assert.AreEqual (150, panel.Left);
466 [Test]
467 public void TestUndockExplicitTopVisible ()
469 form.Show ();
470 panel.Top = 150;
471 panel.Dock = DockStyle.Top;
472 panel.Dock = DockStyle.None;
473 Assert.AreEqual (150, panel.Top);
476 [Test]
477 public void TestUndockExplicitLocationVisible ()
479 form.Show ();
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);
487 [Test]
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);
497 [Test]
498 public void TestUndockExplicitHeight ()
500 panel.Height = 50;
501 panel.Dock = DockStyle.Left;
502 panel.Dock = DockStyle.None;
503 Assert.AreEqual (50, panel.Height);
506 [Test]
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);
517 [Test]
518 public void TestUndockExplicitWidth ()
520 panel.Width = 50;
521 panel.Dock = DockStyle.Top;
522 panel.Dock = DockStyle.None;
523 Assert.AreEqual (50, panel.Width);
526 [Test]
527 public void TestUndockExplicitHeightVisible ()
529 form.Show ();
530 panel.Height = 50;
531 panel.Dock = DockStyle.Left;
532 panel.Dock = DockStyle.None;
533 Assert.AreEqual (50, panel.Height);
536 [Test]
537 [Category ("NotWorking")]
538 public void TestUndockExplicitSizeVisible ()
540 form.Show ();
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);
548 [Test]
549 public void TestUndockExplicitWidthVisible ()
551 form.Show ();
552 panel.Width = 50;
553 panel.Dock = DockStyle.Top;
554 panel.Dock = DockStyle.None;
555 Assert.AreEqual (50, panel.Width);
558 [Test]
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");
570 [Test]
571 public void TestUndockSetBoundsVisible ()
573 form.Show ();
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");
583 [Test]
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");
595 [Test]
596 public void TestUndockSetBoundsCoreVisible ()
598 form.Show ();
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");
608 [Test]
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");
620 [Test]
621 public void TestUndockUpdateBoundsVisible ()
623 form.Show ();
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");