* TestHelper.cs: Add virtual setup and teardown methods. Any forms left
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / DefaultLayoutTest.cs
1 using System;
2 using System.Drawing;
3 using System.Windows.Forms;
4
5 using NUnit.Framework;
6
7 namespace MonoTests.System.Windows.Forms
8 {
9         [TestFixture]
10         public class DefaultLayoutTest : TestHelper
11         {
12                 int event_count;
13                 LayoutEventArgs most_recent_args;
14
15                 void p_Layout (object sender, LayoutEventArgs e)
16                 {
17                         event_count ++;
18                         most_recent_args = e;
19                 }
20
21                 [Test]
22                 public void AnchorLayoutEvents ()
23                 {
24                         Panel p;
25                         Button b;
26
27                         p = new Panel ();
28
29                         b = new Button ();
30                         p.Controls.Add (b);
31
32                         p.Layout += new LayoutEventHandler (p_Layout);
33
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");
38
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");
47
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");
53
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");
62
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");
68
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");
77                 }
78
79                 [Test]
80                 public void AnchorTopLeftTest ()
81                 {
82                         Form f = new Form ();
83                         f.ShowInTaskbar = false;
84
85                         f.Size = new Size (200, 200);
86
87                         Button b = new Button ();
88                         b.Size = new Size (100, 100);
89                         b.Anchor = AnchorStyles.Top | AnchorStyles.Left;
90
91                         f.Controls.Add (b);
92
93                         Assert.AreEqual (0, b.Left, "1");
94                         Assert.AreEqual (0, b.Top, "2");
95                         f.Size = new Size (300, 300);
96
97                         Assert.AreEqual (0, b.Left, "3");
98                         Assert.AreEqual (0, b.Top, "4");
99                         
100                         f.Dispose ();
101                 }
102
103                 [Test]
104                 public void AnchorTopRightTest ()
105                 {
106                         Form f = new Form ();
107                         f.ShowInTaskbar = false;
108
109                         f.Size = new Size (200, 200);
110
111                         Button b = new Button ();
112                         b.Size = new Size (100, 100);
113                         b.Anchor = AnchorStyles.Top | AnchorStyles.Right;
114
115                         f.Controls.Add (b);
116
117                         Assert.AreEqual (0, b.Left, "1");
118                         Assert.AreEqual (0, b.Top, "2");
119
120                         f.Size = new Size (300, 300);
121
122                         Assert.AreEqual (100, b.Left, "3");
123                         Assert.AreEqual (0, b.Top, "4");
124                         
125                         f.Dispose ();
126                 }
127
128                 [Test]
129                 public void AnchorLeftRightTest ()
130                 {
131                         Form f = new Form ();
132                         f.ShowInTaskbar = false;
133
134                         f.Size = new Size (200, 200);
135
136                         Button b = new Button ();
137                         b.Size = new Size (100, 100);
138                         b.Anchor = AnchorStyles.Left | AnchorStyles.Right;
139
140                         f.Controls.Add (b);
141
142                         Assert.AreEqual (0, b.Left, "1");
143                         Assert.AreEqual (100, b.Right, "2");
144
145                         f.Size = new Size (300, 300);
146
147                         Assert.AreEqual (0, b.Left, "3");
148                         Assert.AreEqual (200, b.Right, "4");
149                         
150                         f.Dispose ();
151                 }
152
153                 [Test]
154                 public void AnchorBottomLeftTest ()
155                 {
156                         Form f = new Form ();
157                         f.ShowInTaskbar = false;
158
159                         f.Size = new Size (200, 200);
160
161                         Button b = new Button ();
162                         b.Size = new Size (100, 100);
163                         b.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
164
165                         f.Controls.Add (b);
166
167                         Assert.AreEqual (0, b.Left, "1");
168                         Assert.AreEqual (0, b.Top, "2");
169
170                         f.Size = new Size (300, 300);
171
172                         Assert.AreEqual (0, b.Left, "3");
173                         Assert.AreEqual (100, b.Top, "4");
174                         
175                         f.Dispose ();
176                 }
177
178                 [Test]
179                 public void AnchorBottomRightTest ()
180                 {
181                         Form f = new Form ();
182                         f.ShowInTaskbar = false;
183
184                         f.Size = new Size (200, 200);
185
186                         Button b = new Button ();
187                         b.Size = new Size (100, 100);
188                         b.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
189
190                         f.Controls.Add (b);
191
192                         Assert.AreEqual (0, b.Left, "1");
193                         Assert.AreEqual (0, b.Top, "2");
194
195                         f.Size = new Size (300, 300);
196
197                         Assert.AreEqual (100, b.Left, "3");
198                         Assert.AreEqual (100, b.Top, "4");
199                         
200                         f.Dispose ();
201                 }
202
203                 [Test]
204                 public void AnchorTopBottomTest ()
205                 {
206                         Form f = new Form ();
207                         f.ShowInTaskbar = false;
208
209                         f.Size = new Size (200, 200);
210
211                         Button b = new Button ();
212                         b.Size = new Size (100, 100);
213                         b.Anchor = AnchorStyles.Top | AnchorStyles.Bottom;
214
215                         f.Controls.Add (b);
216
217                         Assert.AreEqual (0, b.Top, "1");
218                         Assert.AreEqual (100, b.Bottom, "2");
219
220                         f.Size = new Size (300, 300);
221
222                         Assert.AreEqual (0, b.Top, "3");
223                         Assert.AreEqual (200, b.Bottom, "4");
224                         
225                         f.Dispose ();
226                 }
227
228                 // Unit test version of the test case in bug #80336
229                 [Test]
230                 public void AnchorSuspendLayoutTest ()
231                 {
232                         Form f = new Form ();
233                         f.ShowInTaskbar = false;
234
235                         f.SuspendLayout ();
236
237                         Button b = new Button ();
238                         b.Size = new Size (100, 100);
239
240                         f.Controls.Add (b);
241
242                         f.Size = new Size (200, 200);
243
244                         b.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
245
246                         Assert.AreEqual (0, b.Top, "1");
247                         Assert.AreEqual (0, b.Left, "2");
248
249                         f.Size = new Size (300, 300);
250
251                         Assert.AreEqual (0, b.Top, "3");
252                         Assert.AreEqual (0, b.Left, "4");
253
254                         f.ResumeLayout();
255
256                         Assert.AreEqual (100, b.Top, "5");
257                         Assert.AreEqual (100, b.Left, "6");
258                         
259                         f.Dispose ();
260                 }
261
262                 // another variant of AnchorSuspendLayoutTest1, with
263                 // the SuspendLayout moved after the Anchor
264                 // assignment.
265                 [Test]
266                 public void AnchorSuspendLayoutTest2 ()
267                 {
268                         Form f = new Form ();
269                         f.ShowInTaskbar = false;
270
271                         Button b = new Button ();
272                         b.Size = new Size (100, 100);
273
274                         f.Controls.Add (b);
275
276                         f.Size = new Size (200, 200);
277
278                         b.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
279
280                         Assert.AreEqual (0, b.Top, "1");
281                         Assert.AreEqual (0, b.Left, "2");
282
283                         f.SuspendLayout ();
284
285                         f.Size = new Size (300, 300);
286
287                         Assert.AreEqual (0, b.Top, "3");
288                         Assert.AreEqual (0, b.Left, "4");
289
290                         f.ResumeLayout();
291
292                         Assert.AreEqual (100, b.Top, "5");
293                         Assert.AreEqual (100, b.Left, "6");
294                         
295                         f.Dispose ();
296                 }
297
298                 // yet another variant, this time with no Suspend/Resume.
299                 [Test]
300                 public void AnchorSuspendLayoutTest3 ()
301                 {
302                         Form f = new Form ();
303                         f.ShowInTaskbar = false;
304
305                         Button b = new Button ();
306                         b.Size = new Size (100, 100);
307
308                         f.Controls.Add (b);
309
310                         f.Size = new Size (200, 200);
311
312                         b.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
313
314                         Assert.AreEqual (0, b.Top, "1");
315                         Assert.AreEqual (0, b.Left, "2");
316
317                         f.Size = new Size (300, 300);
318
319                         Assert.AreEqual (100, b.Top, "5");
320                         Assert.AreEqual (100, b.Left, "6");
321                         
322                         f.Dispose ();
323                 }
324
325                 private string event_raised = string.Empty;
326
327                 [Test]
328                 public void TestAnchorDockInteraction ()
329                 {
330                         Panel p = new Panel ();
331                         p.DockChanged += new EventHandler (DockChanged_Handler);
332
333                         Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, p.Anchor, "A1");
334                         Assert.AreEqual (DockStyle.None, p.Dock, "A2");
335
336                         p.Dock = DockStyle.Right;
337                         Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, p.Anchor, "A3");
338                         Assert.AreEqual (DockStyle.Right, p.Dock, "A4");
339                         Assert.AreEqual ("DockStyleChanged", event_raised, "A5");
340                         event_raised = string.Empty;
341
342                         p.Anchor = AnchorStyles.Bottom;
343                         Assert.AreEqual (AnchorStyles.Bottom, p.Anchor, "A6");
344                         Assert.AreEqual (DockStyle.None, p.Dock, "A7");
345                         Assert.AreEqual (string.Empty, event_raised, "A8");
346
347                         p.Dock = DockStyle.Fill;
348                         Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, p.Anchor, "A9");
349                         Assert.AreEqual (DockStyle.Fill, p.Dock, "A10");
350                         Assert.AreEqual ("DockStyleChanged", event_raised, "A11");
351                         event_raised = string.Empty;
352
353                         p.Anchor = AnchorStyles.Top | AnchorStyles.Left;
354                         Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, p.Anchor, "A12");
355                         Assert.AreEqual (DockStyle.Fill, p.Dock, "A13");
356                         Assert.AreEqual (string.Empty, event_raised, "A14");
357
358                         p.Dock = DockStyle.None;
359                         Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, p.Anchor, "A15");
360                         Assert.AreEqual (DockStyle.None, p.Dock, "A16");
361                         Assert.AreEqual ("DockStyleChanged", event_raised, "A17");
362                         event_raised = string.Empty;
363
364                         p.Anchor = AnchorStyles.Bottom;
365                         p.Dock = DockStyle.None;
366                         Assert.AreEqual (AnchorStyles.Bottom, p.Anchor, "A18");
367                         Assert.AreEqual (DockStyle.None, p.Dock, "A19");
368                         Assert.AreEqual (string.Empty, event_raised, "A20");
369                 }
370
371                 public void DockChanged_Handler (object sender, EventArgs e)
372                 {
373                         event_raised += "DockStyleChanged";
374                 }
375
376                 [Test]  // bug #80917
377                 [Category ("NotWorking")]
378                 public void BehaviorOverriddenDisplayRectangle ()
379                 {
380                         Control c = new Control ();
381                         c.Anchor |= AnchorStyles.Bottom;
382                         c.Size = new Size (100, 100);
383
384                         Form f = new DisplayRectangleForm ();
385                         f.Controls.Add (c);
386                         f.ShowInTaskbar = false;
387                         f.Show ();
388                         
389                         Assert.AreEqual (new Size (100, 100), c.Size, "A1");
390                         
391                         f.Dispose ();
392                 }
393
394                 private class DisplayRectangleForm : Form
395                 {
396                         public override Rectangle DisplayRectangle
397                         {
398                                 get { return Rectangle.Empty; }
399                         }
400                 }
401                 
402                 [Test]  // bug 80912
403                 public void AnchoredControlWithZeroWidthAndHeight ()
404                 {
405                         Form f = new Form ();
406                         f.ShowInTaskbar = false;
407                         
408                         Control c = new Control ();
409                         c.Anchor = AnchorStyles.Left | AnchorStyles.Right;
410                         f.Controls.Add (c);
411
412                         Assert.AreEqual (new Rectangle (0, 0, 0, 0), c.Bounds, "N1");
413                 }
414
415                 [Test] // bug 81694
416                 public void TestNestedControls ()
417                 {
418                         MainForm f = new MainForm ();
419                         f.ShowInTaskbar = false;
420                         
421                         f.Show ();
422                         Assert.AreEqual (new Rectangle (210, 212, 75, 23), f._userControl._button2.Bounds, "K1");
423                         
424                         f.Dispose ();
425                 }
426
427                 [Test] // bug 81695
428                 public void TestNestedControls2 ()
429                 {
430                         MainForm f = new MainForm ();
431                         f.ShowInTaskbar = false;
432
433                         f.Show ();
434                         
435                         Size s = f.Size;
436                         f.Size = new Size (10, 10);
437                         f.Size = s;
438                         
439                         Assert.AreEqual (new Rectangle (210, 212, 75, 23), f._userControl._button2.Bounds, "K1");
440
441                         f.Dispose ();
442                 }
443
444                 private class MainForm : Form
445                 {
446                         public UserControl1 _userControl;
447                         
448                         public MainForm ()
449                         {
450                                 SuspendLayout ();
451                                 // 
452                                 // _userControl
453                                 // 
454                                 _userControl = new UserControl1 ();
455                                 _userControl.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right);
456                                 _userControl.BackColor = Color.White;
457                                 _userControl.Location = new Point (8, 8);
458                                 _userControl.Size = new Size (288, 238);
459                                 _userControl.TabIndex = 0;
460                                 Controls.Add (_userControl);
461                                 // 
462                                 // MainForm
463                                 // 
464                                 ClientSize = new Size (304, 280);
465                                 Location = new Point (250, 100);
466                                 StartPosition = FormStartPosition.Manual;
467                                 Text = "bug #81694";
468                                 ResumeLayout (false);
469                         }
470                 }
471                 
472                 private class UserControl1 : UserControl
473                 {
474                         private Button _button1;
475                         public Button _button2;
476
477                         public UserControl1 ()
478                         {
479                                 SuspendLayout ();
480                                 // 
481                                 // _button1
482                                 // 
483                                 _button1 = new Button ();
484                                 _button1.Location = new Point (4, 4);
485                                 _button1.Size = new Size (75, 23);
486                                 _button1.TabIndex = 0;
487                                 _button1.Text = "Button1";
488                                 Controls.Add (_button1);
489                                 // 
490                                 // _button2
491                                 // 
492                                 _button2 = new Button ();
493                                 _button2.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
494                                 _button2.Location = new Point (210, 212);
495                                 _button2.Size = new Size (75, 23);
496                                 _button2.TabIndex = 1;
497                                 _button2.Text = "Button2";
498                                 Controls.Add (_button2);
499                                 // 
500                                 // UserControl1
501                                 // 
502                                 BackColor = Color.White;
503                                 ClientSize = new Size (288, 238);
504                                 ResumeLayout (false);
505                         }
506                 }
507
508 #if NET_2_0
509                 [Test]
510                 public void TestDockFillWithPadding ()
511                 {
512                         Form f = new Form ();
513                         f.ShowInTaskbar = false;
514                         f.Padding = new Padding (15, 15, 15, 15);
515
516                         Control c = new Control ();
517                         c.Dock = DockStyle.Fill;
518                         f.Controls.Add (c);
519
520                         f.Show ();
521                         Assert.AreEqual (new Size (f.ClientSize.Width - 30, f.ClientSize.Height - 30), c.Size, "K1");
522
523                         f.Dispose ();
524                 }
525 #endif
526
527                 [Test]
528                 public void Bug82762 ()
529                 {
530                         if (TestHelper.RunningOnUnix)
531                                 Assert.Ignore ("WM Size dependent");
532                                 
533                         Form f = new Form ();
534                         f.ShowInTaskbar = false;
535                         
536                         Button b = new Button ();
537                         b.Size = new Size (100, 100);
538                         b.Anchor = AnchorStyles.None;
539                         f.Controls.Add (b);
540                         
541                         f.Show ();
542                         
543                         Assert.AreEqual (new Rectangle (0, 0, 100, 100), b.Bounds, "A1");
544                         
545                         f.ClientSize = new Size (600, 600);
546
547                         Assert.AreEqual (new Rectangle (158, 168, 100, 100), b.Bounds, "A2");
548
549                         f.Close ();
550                         f.Dispose ();
551                 }
552                 
553                 [Test]
554                 public void Bug82805 ()
555                 {
556                         Control c1 = new Control ();
557                         c1.Size = new Size (100, 100);
558                         Control c2 = new Control ();
559                         c2.Size = new Size (100, 100);
560
561                         c2.SuspendLayout ();
562                         c1.Anchor = AnchorStyles.Left | AnchorStyles.Right;
563                         c2.Controls.Add (c1);
564                         c2.Size = new Size (200, 200);
565                         c2.ResumeLayout ();
566
567                         Assert.AreEqual (200, c1.Width, "A1");
568                 }
569                 
570 #if NET_2_0
571                 [Test]
572                 public void DockedAutoSizeControls ()
573                 {
574                         Form f = new Form ();
575                         f.ShowInTaskbar = false;
576                         
577                         Button b = new Button ();
578                         b.Text = "Yo";
579                         b.AutoSize = true;
580                         b.AutoSizeMode = AutoSizeMode.GrowAndShrink;
581                         b.Width = 200;
582                         b.Dock = DockStyle.Left;
583                         f.Controls.Add (b);
584                         
585                         f.Show ();
586                         
587                         if (b.Width >= 200)
588                                 Assert.Fail ("button should be less than 200 width: actual {0}", b.Width);
589                         
590                         f.Close ();
591                         f.Dispose ();
592                 }
593 #endif
594                 
595                 [Test]  // bug #81199
596                 public void NestedControls ()
597                 {
598                         Form f = new Form ();
599                         f.ShowInTaskbar = false;
600                         
601                         MyUserControl c = new MyUserControl ();
602                         c.Dock = DockStyle.Fill;
603                         c.Size = new Size (500, 500);
604                         
605                         f.SuspendLayout ();
606                         f.Controls.Add (c);
607                         f.ClientSize = new Size (500, 500);
608                         f.ResumeLayout (false);
609                         
610                         f.Show ();
611                         
612                         Assert.AreEqual (new Size (600, 600), c.lv.Size, "I1");
613                         f.Close ();
614                 }
615                 
616                 private class MyUserControl : UserControl
617                 {
618                         public ListView lv;
619                         
620                         public MyUserControl ()
621                         {
622                                 lv = new ListView ();
623                                 SuspendLayout ();
624                                 lv.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
625                                 lv.Size = new Size (300, 300);
626                                 
627                                 Controls.Add (lv);
628                                 Size = new Size (200, 200);
629                                 ResumeLayout (false);
630                         }
631                 }
632         }
633
634         [TestFixture]   
635         public class DockingTests : TestHelper
636         {
637                 Form form;
638                 Panel panel;
639
640                 int event_count;
641
642                 [SetUp]
643                 protected override void SetUp () {
644                         form = new Form ();
645                         form.ShowInTaskbar = false;
646                         form.Size = new Size (400, 400);
647                         panel = new Panel ();
648                         form.Controls.Add (panel);
649                         event_count = 0;
650                         base.SetUp ();
651                 }
652
653                 [TearDown]
654                 protected override void TearDown () {
655                         form.Dispose ();
656                         base.TearDown ();
657                 }
658
659                 void IncrementEventCount (object o, EventArgs args)
660                 {
661                         event_count++;
662                 }
663
664                 [Test]
665                 public void TestDockSizeChangedEvent ()
666                 {
667                         panel.SizeChanged += new EventHandler (IncrementEventCount);
668                         panel.Dock = DockStyle.Bottom;
669                         Assert.AreEqual (1, event_count);
670                 }
671
672                 [Test]
673                 public void TestDockLocationChangedEvent ()
674                 {
675                         panel.LocationChanged += new EventHandler (IncrementEventCount);
676                         panel.Dock = DockStyle.Bottom;
677                         Assert.AreEqual (1, event_count);
678                 }
679
680                 [Test]
681                 public void TestDockFillFirst ()
682                 {
683                         Form f = new Form ();
684                         f.ShowInTaskbar = false;
685
686                         Panel b1 = new Panel ();
687                         Panel b2 = new Panel ();
688
689                         b1.Dock = DockStyle.Fill;
690                         b2.Dock = DockStyle.Left;
691
692                         f.Controls.Add (b1);
693                         f.Controls.Add (b2);
694
695                         f.Show ();
696                         Assert.AreEqual (new Rectangle (b2.Width, 0, f.ClientRectangle.Width - b2.Width, f.ClientRectangle.Height), b1.Bounds, "A1");
697                         Assert.AreEqual (new Rectangle (0, 0, 200, f.ClientRectangle.Height), b2.Bounds, "A2");
698                         f.Dispose ();
699                 }
700
701                 [Test]
702                 public void TestDockFillLast ()
703                 {
704                         Form f = new Form ();
705                         f.ShowInTaskbar = false;
706
707                         Panel b1 = new Panel ();
708                         Panel b2 = new Panel ();
709
710                         b1.Dock = DockStyle.Fill;
711                         b2.Dock = DockStyle.Left;
712
713                         f.Controls.Add (b2);
714                         f.Controls.Add (b1);
715
716                         f.Show ();
717                         Assert.AreEqual (new Rectangle (0, 0, f.ClientRectangle.Width, f.ClientRectangle.Height), b1.Bounds, "B1");
718                         Assert.AreEqual (new Rectangle (0, 0, 200, f.ClientRectangle.Height), b2.Bounds, "B2");
719                         f.Dispose ();
720                 }
721                 
722                 [Test]  // bug #81397
723                 public void TestDockingWithCustomDisplayRectangle ()
724                 {
725                         MyControl mc = new MyControl ();
726                         mc.Size = new Size (200, 200);
727                         
728                         Control c = new Control ();
729                         c.Dock = DockStyle.Fill;
730                         
731                         mc.Controls.Add (c);
732                         
733                         Form f = new Form ();
734                         f.ShowInTaskbar = false;
735                         
736                         f.Controls.Add (mc);
737                         f.Show ();
738                         
739                         Assert.AreEqual (new Point (20, 20), c.Location, "A1");
740                         Assert.AreEqual (new Size (160, 160), c.Size, "A2");
741                         
742                         f.Dispose ();
743                 }
744                 
745                 private class MyControl : Control
746                 {
747                         public override Rectangle DisplayRectangle { 
748                                 get { return new Rectangle (20, 20, this.Width - 40, this.Height - 40); }
749                         }
750                 }
751                 [Test]
752                 public void ResettingDockToNone ()
753                 {
754                         Form f = new Form ();
755                         f.ShowInTaskbar = false;
756                         f.ClientSize = new Size (300, 300);
757                         
758                         Control c = new Control ();
759                         c.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
760                         
761                         f.Controls.Add (c);
762                         
763                         f.Show ();
764                         
765                         f.ClientSize = new Size (350, 350);
766
767                         Assert.IsTrue (c.Left > 0, string.Format ("A1: c.Left ({0}) must be greater than 0", c.Left));
768                         Assert.IsTrue (c.Top > 0, string.Format ("A2: c.Top ({0}) must be greater than 0", c.Top));
769                         
770                         c.Dock = DockStyle.None;
771                         Assert.IsTrue (c.Left > 0, string.Format ("A3: c.Left ({0}) must be greater than 0", c.Left));
772                         Assert.IsTrue (c.Top > 0, string.Format ("A4: c.Top ({0}) must be greater than 0", c.Top));
773                         
774                         f.ClientSize = new Size (400, 400);
775                         Assert.IsTrue (c.Left > 70, string.Format ("A5: c.Left ({0}) must be greater than 70", c.Left));
776                         Assert.IsTrue (c.Top > 70, string.Format ("A6: c.Top ({0}) must be greater than 70", c.Top));
777                         
778                         f.Dispose ();
779                 }
780         }
781
782         [TestFixture]   
783         public class UndockingTests : TestHelper
784         {
785                 class TestPanel : Panel {
786
787                         public void InvokeSetBoundsCore ()
788                         {
789                                 SetBoundsCore (37, 37, 37, 37, BoundsSpecified.All);
790                         }
791
792                         public void InvokeUpdateBounds ()
793                         {
794                                 UpdateBounds (37, 37, 37, 37);
795                         }
796                 }
797
798                 Form form;
799                 TestPanel panel;
800
801                 [SetUp]
802                 protected override void SetUp () {
803                         form = new Form ();
804                         form.ShowInTaskbar = false;
805                         form.Size = new Size (400, 400);
806                         panel = new TestPanel ();
807                         form.Controls.Add (panel);
808                         base.SetUp ();
809                 }
810
811                 [TearDown]
812                 protected override void TearDown ()
813                 {
814                         form.Dispose ();
815                         base.TearDown ();
816                 }
817
818                 [Test]
819                 public void TestUndockDefaultLocation ()
820                 {
821                         Point loc = panel.Location;
822                         panel.Dock = DockStyle.Bottom;
823                         panel.Dock = DockStyle.None;
824                         Assert.AreEqual (loc, panel.Location);
825                 }
826
827                 [Test]
828                 public void TestUndockDefaultLocationVisible ()
829                 {
830                         form.Show ();
831                         Point loc = panel.Location;
832                         panel.Dock = DockStyle.Bottom;
833                         panel.Dock = DockStyle.None;
834                         Assert.AreEqual (loc, panel.Location);
835                 }
836
837                 [Test]
838                 public void TestUndockExplicitLeft ()
839                 {
840                         panel.Left = 150;
841                         panel.Dock = DockStyle.Top;
842                         panel.Dock = DockStyle.None;
843                         Assert.AreEqual (150, panel.Left);
844                 }
845
846                 [Test]
847                 public void TestUndockExplicitTop ()
848                 {
849                         panel.Top = 150;
850                         panel.Dock = DockStyle.Top;
851                         panel.Dock = DockStyle.None;
852                         Assert.AreEqual (150, panel.Top);
853                 }
854
855                 [Test]
856                 public void TestUndockExplicitLocation ()
857                 {
858                         panel.Location = new Point (50, 50);
859                         Point loc = panel.Location;
860                         panel.Dock = DockStyle.Bottom;
861                         panel.Dock = DockStyle.None;
862                         Assert.AreEqual (loc, panel.Location);
863                 }
864
865                 [Test]
866                 public void TestUndockExplicitLeftVisible ()
867                 {
868                         form.Show ();
869                         panel.Left = 150;
870                         panel.Dock = DockStyle.Top;
871                         panel.Dock = DockStyle.None;
872                         Assert.AreEqual (150, panel.Left);
873                 }
874
875                 [Test]
876                 public void TestUndockExplicitTopVisible ()
877                 {
878                         form.Show ();
879                         panel.Top = 150;
880                         panel.Dock = DockStyle.Top;
881                         panel.Dock = DockStyle.None;
882                         Assert.AreEqual (150, panel.Top);
883                 }
884
885                 [Test]
886                 public void TestUndockExplicitLocationVisible ()
887                 {
888                         form.Show ();
889                         panel.Location = new Point (50, 50);
890                         Point loc = panel.Location;
891                         panel.Dock = DockStyle.Bottom;
892                         panel.Dock = DockStyle.None;
893                         Assert.AreEqual (loc, panel.Location);
894                 }
895
896                 [Test]
897                 public void TestUndockDefaultSize ()
898                 {
899                         Size sz = panel.Size;
900                         panel.Dock = DockStyle.Fill;
901                         panel.Dock = DockStyle.None;
902                         Assert.AreEqual (sz, panel.Size);
903                 }
904
905                 [Test]
906                 public void TestUndockExplicitHeight ()
907                 {
908                         panel.Height = 50;
909                         panel.Dock = DockStyle.Left;
910                         panel.Dock = DockStyle.None;
911                         Assert.AreEqual (50, panel.Height);
912                 }
913
914                 [Test]
915                 public void TestUndockExplicitSize ()
916                 {
917                         panel.Size = new Size (50, 50);
918                         Size sz = panel.Size;
919                         panel.Dock = DockStyle.Fill;
920                         panel.Dock = DockStyle.None;
921                         Assert.AreEqual (sz, panel.Size);
922                 }
923
924                 [Test]
925                 public void TestUndockExplicitWidth ()
926                 {
927                         panel.Width = 50;
928                         panel.Dock = DockStyle.Top;
929                         panel.Dock = DockStyle.None;
930                         Assert.AreEqual (50, panel.Width);
931                 }
932
933                 [Test]
934                 public void TestUndockExplicitHeightVisible ()
935                 {
936                         form.Show ();
937                         panel.Height = 50;
938                         panel.Dock = DockStyle.Left;
939                         panel.Dock = DockStyle.None;
940                         Assert.AreEqual (50, panel.Height);
941                 }
942
943                 [Test]
944                 public void TestUndockExplicitSizeVisible ()
945                 {
946                         form.Show ();
947                         panel.Size = new Size (50, 50);
948                         Size sz = panel.Size;
949                         panel.Dock = DockStyle.Fill;
950                         panel.Dock = DockStyle.None;
951                         Assert.AreEqual (sz, panel.Size);
952                 }
953
954                 [Test]
955                 public void TestUndockExplicitWidthVisible ()
956                 {
957                         form.Show ();
958                         panel.Width = 50;
959                         panel.Dock = DockStyle.Top;
960                         panel.Dock = DockStyle.None;
961                         Assert.AreEqual (50, panel.Width);
962                 }
963
964                 [Test]
965                 public void TestUndockSetBounds ()
966                 {
967                         panel.SetBounds (50, 50, 50, 50, BoundsSpecified.All);
968                         panel.Dock = DockStyle.Top;
969                         panel.Dock = DockStyle.None;
970                         Assert.AreEqual (50, panel.Height, "Height");
971                         Assert.AreEqual (50, panel.Left, "Left");
972                         Assert.AreEqual (50, panel.Top, "Top");
973                         Assert.AreEqual (50, panel.Width, "Width");
974                 }
975
976                 [Test]
977                 public void TestUndockSetBoundsVisible ()
978                 {
979                         form.Show ();
980                         panel.SetBounds (50, 50, 50, 50, BoundsSpecified.All);
981                         panel.Dock = DockStyle.Top;
982                         panel.Dock = DockStyle.None;
983                         Assert.AreEqual (50, panel.Height, "Height");
984                         Assert.AreEqual (50, panel.Left, "Left");
985                         Assert.AreEqual (50, panel.Top, "Top");
986                         Assert.AreEqual (50, panel.Width, "Width");
987                 }
988
989                 [Test]
990                 public void TestUndockSetBoundsCore ()
991                 {
992                         panel.InvokeSetBoundsCore ();
993                         panel.Dock = DockStyle.Top;
994                         panel.Dock = DockStyle.None;
995                         Assert.AreEqual (37, panel.Height, "Height");
996                         Assert.AreEqual (37, panel.Left, "Left");
997                         Assert.AreEqual (37, panel.Top, "Top");
998                         Assert.AreEqual (37, panel.Width, "Width");
999                 }
1000
1001                 [Test]
1002                 public void TestUndockSetBoundsCoreVisible ()
1003                 {
1004                         form.Show ();
1005                         panel.InvokeSetBoundsCore ();
1006                         panel.Dock = DockStyle.Top;
1007                         panel.Dock = DockStyle.None;
1008                         Assert.AreEqual (37, panel.Height, "Height");
1009                         Assert.AreEqual (37, panel.Left, "Left");
1010                         Assert.AreEqual (37, panel.Top, "Top");
1011                         Assert.AreEqual (37, panel.Width, "Width");
1012                 }
1013
1014                 [Test]
1015                 public void TestUndockUpdateBounds ()
1016                 {
1017                         panel.InvokeUpdateBounds ();
1018                         panel.Dock = DockStyle.Top;
1019                         panel.Dock = DockStyle.None;
1020                         Assert.AreEqual (37, panel.Height, "Height");
1021                         Assert.AreEqual (37, panel.Left, "Left");
1022                         Assert.AreEqual (37, panel.Top, "Top");
1023                         Assert.AreEqual (37, panel.Width, "Width");
1024                 }
1025
1026                 [Test]
1027                 public void TestUndockUpdateBoundsVisible ()
1028                 {
1029                         form.Show ();
1030                         panel.InvokeUpdateBounds ();
1031                         panel.Dock = DockStyle.Top;
1032                         panel.Dock = DockStyle.None;
1033                         Assert.AreEqual (37, panel.Height, "Height");
1034                         Assert.AreEqual (37, panel.Left, "Left");
1035                         Assert.AreEqual (37, panel.Top, "Top");
1036                         Assert.AreEqual (37, panel.Width, "Width");
1037                 }
1038         }
1039 }