fixed tests
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ControlTest.cs
1 //
2 // Copyright (c) 2005 Novell, Inc.
3 //
4 // Authors:
5 //      Ritvik Mayank (mritvik@novell.com)
6 //
7
8 using System;
9 using System.Collections;
10 using InvalidEnumArgumentException = System.ComponentModel.InvalidEnumArgumentException;
11 using System.Drawing;
12 using System.Reflection;
13 using System.Runtime.Remoting;
14 using System.Threading;
15 using System.Windows.Forms;
16 #if NET_2_0
17 using System.Windows.Forms.Layout;
18 #endif
19
20 using NUnit.Framework;
21
22 namespace MonoTests.System.Windows.Forms
23 {
24         [TestFixture]
25         public class ControlTest
26         {
27                 public class ControlStylesTester : Control {
28                         private WindowStyles style;
29                         private WindowStyles ex_style;
30                         private bool or_styles;
31
32                         public ControlStylesTester (WindowStyles Style, WindowStyles ExStyle, bool OrStyles)
33                         {
34                                 style = Style;
35                                 ex_style = ExStyle;
36                                 or_styles = OrStyles;
37                         }
38
39                         protected override CreateParams CreateParams {
40                                 get {
41                                         CreateParams result = base.CreateParams;
42                                         if (or_styles) {
43                                                 result.Style |= (int) style;
44                                                 result.ExStyle |= (int) ex_style;
45                                         } else {
46                                                 result.Style = (int) style;
47                                                 result.ExStyle = (int) ex_style;
48                                         }
49                                         return result;
50                                 }
51                         }
52                 }
53                 
54                 [Test]
55                 public void ControlSizeTest ()
56                 {
57                         ControlStylesTester c = new ControlStylesTester (WindowStyles.WS_CHILD, 0, true);
58                         Assert.AreEqual ("{X=0,Y=0}", c.Location.ToString (), "#L1");
59                         Assert.AreEqual ("{Width=0, Height=0}", c.Size.ToString (), "#S1");
60                 }
61
62 #if NET_2_0
63                 [Test]
64                 public void CaptureTest ()
65                 {
66                         Form frm = new Form ();
67                         ControlOverrideLogger log = new ControlOverrideLogger ();
68                         frm.Controls.Add (log);
69                         log.Visible = true;
70                         log.Capture = true;
71                         log.Capture = false;
72                         log.BackColor = Color.Blue;
73                         log.Size = new Size (100, 100);
74                         
75                         frm.Show ();
76                         Application.DoEvents ();
77                         
78                         frm.Dispose ();
79                         Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") > -1, "#01");
80                         
81                         log = new ControlOverrideLogger ();
82                         log.Capture = true;
83                         log.Capture = false;
84                         Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") > -1, "#02");
85
86                         log = new ControlOverrideLogger ();
87                         log.Capture = true;
88                         Assert.IsTrue (log.IsHandleCreated, "#03");
89                         Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") == -1, "#04");
90                         
91                         log = new ControlOverrideLogger ();
92                         log.Capture = false;
93                         Assert.IsFalse (log.IsHandleCreated, "#05");
94                         Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") == -1, "#06");
95                 }
96 #endif
97         
98                 public class OnPaintTester : Form
99                 {
100                         int counter;
101                         int total;
102                         ArrayList list = new ArrayList ();
103                         public bool Recursive;
104                         public bool TestRefresh;
105                         public bool TestInvalidate;
106                         public bool TestUpdate;
107 #if NET_2_0
108                         public new bool DoubleBuffered {
109                                 get {
110                                         return base.DoubleBuffered;
111                                 }
112                                 set {
113                                         base.DoubleBuffered = value;
114                                 }
115                         }
116 #endif
117                         protected override void OnPaint (PaintEventArgs pevent)
118                         {
119                                 Assert.IsFalse (list.Contains (pevent.Graphics), "OnPaintTester.OnPaint: Got the same Graphics twice");
120                                 list.Add (pevent.Graphics);
121                                 
122                                 if (total > 10)
123                                         return;
124                                 Recursive = counter > 0 || Recursive;
125                                 counter++;
126                                 if (counter < 2) {
127                                         if (TestRefresh)
128                                                 Refresh ();
129                                         else if (TestInvalidate)
130                                                 Invalidate ();
131                                         else {
132                                                 Update ();
133                                         }
134                                 }
135                                 base.OnPaint (pevent);
136                                 counter--;
137                                 total++;
138                         }
139                         public new void Show ()
140                         {
141                                 base.Show ();
142                                 Application.DoEvents ();
143                         }
144                 }
145
146                 [Test]
147                 public void ControlCollectionTest ()
148                 {
149                         Form frm = new Form ();
150                         frm.IsMdiContainer = true;
151                         Form child = new Form ();
152                         Control.ControlCollection c = new Control.ControlCollection (frm);
153                         child.MdiParent = frm;
154                         c.Add (child);
155                 }
156
157                 [Test]
158                 [ExpectedException (typeof (ArgumentException))]
159                 public void ControlCollectionExceptionTest ()
160                 {
161                         Form frm = new Form ();
162                         frm.IsMdiContainer = true;
163                         Form child = new Form ();
164                         Control.ControlCollection c = new Control.ControlCollection (frm);
165                         //child.MdiParent = frm;
166                         c.Add (child);
167                 }
168                 
169                 [Test]
170                 [Category ("NotWorking")]
171                 public void OnPaintTest ()
172                 {
173                         using (OnPaintTester t = new OnPaintTester ()) {
174                                 t.TestRefresh = true;
175                                 t.Show ();
176                                 Assert.IsTrue (t.Recursive, "#1");
177                         }
178
179                         using (OnPaintTester t = new OnPaintTester ()) {
180                                 t.TestUpdate = true;
181                                 t.Show ();
182                                 Assert.IsFalse (t.Recursive, "#2");
183                         }
184
185                         using (OnPaintTester t = new OnPaintTester ()) {
186                                 t.TestInvalidate = true;
187                                 t.Show ();
188                                 Assert.IsFalse (t.Recursive, "#3");
189                         }
190                 }
191 #if NET_2_0
192                 [Test]
193                 [Category ("Interactive")]
194                 public void OnPaintDoubleBufferedTest ()
195                 {
196                         using (OnPaintTester t = new OnPaintTester ()) {
197                                 t.DoubleBuffered = true;
198                                 t.TestRefresh = true;
199                                 t.Show ();
200                                 Assert.IsTrue (t.Recursive, "#1");
201                         }
202
203                         using (OnPaintTester t = new OnPaintTester ()) {
204                                 t.DoubleBuffered = true;
205                                 t.TestUpdate = true;
206                                 t.Show ();
207                                 Assert.IsFalse (t.Recursive, "#2");
208                         }
209
210                         using (OnPaintTester t = new OnPaintTester ()) {
211                                 t.DoubleBuffered = true;
212                                 t.TestInvalidate = true;
213                                 t.Show ();
214                                 Assert.IsFalse (t.Recursive, "#3");
215                         }
216                 }
217 #endif
218                 public class PaintEventForm : Form
219                 {
220                         public ArrayList overrides = new ArrayList ();
221                         public ArrayList events = new ArrayList ();
222
223                         public PaintEventForm ()
224                         {
225                                 Paint += new PaintEventHandler (DoubleBufferEventForm_Paint);
226                         }
227                         public bool GetControlStyle (ControlStyles style)
228                         {
229                                 return base.GetStyle (style);
230                         }
231
232                         public void SetControlStyle (ControlStyles style, bool value)
233                         {
234                                 base.SetStyle (style, value);
235                         }
236                         
237                         void DoubleBufferEventForm_Paint (object sender, PaintEventArgs e)
238                         {
239                                 events.Add("Paint");
240                         }
241                         
242                         protected override void OnPaintBackground (PaintEventArgs e)
243                         {
244                                 base.OnPaintBackground (e);
245                                 overrides.Add("OnPaintBackground");
246                         }
247
248                         protected override void OnPaint (PaintEventArgs pevent)
249                         {
250                                 base.OnPaint (pevent);
251                                 overrides.Add("OnPaint");
252                         }
253                 }
254                 
255                 [Test]
256                 public void EventStyleTest ()
257                 {
258 #if NET_2_0
259                         using (PaintEventForm f = new PaintEventForm ()) {
260                                 f.Show ();
261                                 f.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
262                                 f.Refresh ();
263                                 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#A1");
264                                 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#A2");
265                                 Assert.IsTrue (f.events.Contains ("Paint"), "#A3");
266                         }
267 #endif
268                         using (PaintEventForm f = new PaintEventForm ()) {
269                                 f.Show ();
270                                 f.SetControlStyle (ControlStyles.DoubleBuffer, true);
271                                 f.Refresh ();
272                                 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#B1");
273                                 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#B2");
274                                 Assert.IsTrue (f.events.Contains ("Paint"), "#B3");
275                         }
276
277                         using (PaintEventForm f = new PaintEventForm ()) {
278                                 f.Show ();
279                                 f.SetControlStyle (ControlStyles.AllPaintingInWmPaint, true);
280                                 f.Refresh ();
281                                 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#C1");
282                                 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#C2");
283                                 Assert.IsTrue (f.events.Contains ("Paint"), "#C3");
284                         }
285
286                         using (PaintEventForm f = new PaintEventForm ()) {
287                                 f.Show ();
288                                 f.SetControlStyle (ControlStyles.UserPaint, true);
289                                 f.Refresh ();
290                                 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#D1");
291                                 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#D2");
292                                 Assert.IsTrue (f.events.Contains ("Paint"), "#D3");
293                         }
294
295                         using (PaintEventForm f = new PaintEventForm ()) {
296                                 f.Show ();
297                                 f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
298                                 f.Refresh ();
299                                 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#E1");
300                                 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#E2");
301                                 Assert.IsTrue (f.events.Contains ("Paint"), "#E3");
302                         }
303
304                         using (PaintEventForm f = new PaintEventForm ()) {
305                                 f.Show ();
306                                 f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
307                                 f.Refresh ();
308                                 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#F1");
309                                 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#F2");
310                                 Assert.IsTrue (f.events.Contains ("Paint"), "#F3");
311                         }
312
313                         using (PaintEventForm f = new PaintEventForm ()) {
314                                 f.Show ();
315                                 f.SetControlStyle (ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
316                                 f.Refresh ();
317                                 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#G1");
318                                 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#G2");
319                                 Assert.IsTrue (f.events.Contains ("Paint"), "#G3");
320                         }
321
322                         using (PaintEventForm f = new PaintEventForm ()) {
323                                 f.Show ();
324                                 f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true);
325                                 f.Refresh ();
326                                 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#H1");
327                                 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#H2");
328                                 Assert.IsTrue (f.events.Contains ("Paint"), "#H3");
329                         }
330                 }
331 #if NET_2_0
332                 public class DoubleBufferedForm : Form
333                 {
334                         public bool painted;
335                         public bool failed;
336                         public DoubleBufferedForm ()
337                         {
338                                 this.DoubleBuffered = true;
339                         }
340
341                         protected override void OnPaint (PaintEventArgs e)
342                         {
343                                 if (failed || painted)
344                                         return;
345                                 painted = true;
346                                 Height = Height + 1;
347                                 try {
348                                         e.Graphics.DrawString (Size.ToString (), Font, Brushes.AliceBlue, new Point (2, 2));
349                                 } catch (Exception exception) {
350                                         Console.WriteLine (exception.StackTrace);
351                                         failed = true;
352                                 }
353                         }
354                 }
355
356                 public class DoubleBufferControl : Control
357                 {
358                         public bool IsDoubleBuffered
359                         {
360                                 get { return base.DoubleBuffered; }
361                                 set { base.DoubleBuffered = value; }
362                         }
363
364                         public bool GetControlStyle (ControlStyles style)
365                         {
366                                 return base.GetStyle (style);
367                         }
368
369                         public void SetControlStyle (ControlStyles style, bool value)
370                         {
371                                 base.SetStyle (style, value);
372                         }
373                 }
374
375                 [Test]
376                 public void DoubleBufferTest ()
377                 {
378                         DoubleBufferedForm f = new DoubleBufferedForm ();
379                         f.Show ();
380                         f.Refresh ();
381                         
382                         Assert.IsFalse (f.failed, "#01");
383                         Assert.IsTrue (f.painted, "The control was never painted, so please check the test");
384                 }
385
386                 [Test]
387                 public void DoubleBufferedTest ()
388                 {
389                         DoubleBufferControl c = new DoubleBufferControl ();
390                         Assert.IsFalse (c.IsDoubleBuffered, "#A1");
391                         Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#A2");
392                         Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#A3");
393                         Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#A4");
394                         Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#A5");
395
396                         c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
397                         Assert.IsTrue (c.IsDoubleBuffered, "#B1");
398                         Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#B2");
399                         Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#B3");
400                         Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#B4");
401                         Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#A5");
402
403                         c.SetControlStyle (ControlStyles.AllPaintingInWmPaint, false);
404                         c.SetControlStyle (ControlStyles.UserPaint, false);
405                         Assert.IsTrue (c.IsDoubleBuffered, "#C1");
406                         Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#C2");
407                         Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#C3");
408                         Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#C4");
409                         Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#C5");
410
411                         c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, false);
412                         Assert.IsFalse (c.IsDoubleBuffered, "#D1");
413                         Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#D2");
414                         Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#D3");
415                         Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#D4");
416                         Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#D5");
417
418                         c.SetControlStyle (ControlStyles.DoubleBuffer, true);
419                         Assert.IsFalse (c.IsDoubleBuffered, "#E1");
420                         Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#E2");
421                         Assert.IsTrue (c.GetControlStyle (ControlStyles.DoubleBuffer), "#E3");
422                         Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#E4");
423                         Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#E5");
424
425                         c.SetControlStyle (ControlStyles.DoubleBuffer, false);
426                         Assert.IsFalse (c.IsDoubleBuffered, "#F1");
427                         Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#F2");
428                         Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#F3");
429                         Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#F4");
430                         Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#F5");
431
432                         c.IsDoubleBuffered = true;
433                         Assert.IsTrue (c.IsDoubleBuffered, "#G1");
434                         Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#G2");
435                         Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#G3");
436                         Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#G4");
437                         Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#G5");
438
439                         c.SetControlStyle (ControlStyles.AllPaintingInWmPaint, true);
440                         c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
441                         c.SetControlStyle (ControlStyles.DoubleBuffer, true);
442                         c.SetControlStyle (ControlStyles.UserPaint, true);
443                         c.IsDoubleBuffered = false;
444                         Assert.IsFalse (c.IsDoubleBuffered, "#H1");
445                         Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#H2");
446                         Assert.IsTrue (c.GetControlStyle (ControlStyles.DoubleBuffer), "#H3");
447                         Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#H4");
448                         Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#H5");
449                 }
450
451                 [Test]
452                 public void DoubleBufferedStyleTest ()
453                 {
454                         DoubleBufferControl c = new DoubleBufferControl ();
455                         TestControlStyle.CheckStyles (c, "#A1", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility);
456
457                         c.IsDoubleBuffered = true;
458                         TestControlStyle.CheckStyles (c, "#A2", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility, ControlStyles.OptimizedDoubleBuffer);
459
460                         c.IsDoubleBuffered = false;
461                         TestControlStyle.CheckStyles (c, "#A3", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility);
462
463                         c = new DoubleBufferControl ();
464                         foreach (ControlStyles style in Enum.GetValues (typeof(ControlStyles))) {
465                                 c.SetControlStyle (style, false);
466                         }
467
468                         TestControlStyle.CheckStyles (c, "#B1");
469
470                         c.IsDoubleBuffered = true;
471                         TestControlStyle.CheckStyles (c, "#B2", ControlStyles.OptimizedDoubleBuffer, ControlStyles.AllPaintingInWmPaint);
472
473                         c.IsDoubleBuffered = false;
474                         TestControlStyle.CheckStyles (c, "#B3", ControlStyles.AllPaintingInWmPaint);
475
476                 }
477 #endif
478
479                 class Helper {
480                         public static void TestAccessibility(Control c, string Default, string Description, string Name, AccessibleRole Role)
481                         {
482                                 Assert.IsNotNull (c.AccessibilityObject, "Acc1");
483                                 Assert.AreEqual (Default, c.AccessibleDefaultActionDescription, "Acc2");
484                                 Assert.AreEqual (Description, c.AccessibleDescription, "Acc3");
485                                 Assert.AreEqual (Name, c.AccessibleName, "Acc4");
486                                 Assert.AreEqual (Role, c.AccessibleRole, "Acc5");
487                         }
488
489                         public static string TestControl(Control container, Control start, bool forward) {
490                                 Control ctl;
491
492                                 ctl = container.GetNextControl(start, forward);
493
494                                 if (ctl == null) {
495                                         return null;
496                                 }
497
498                                 return ctl.Text;
499                         }
500                 }
501
502                 [Test]
503                 public void CreatedTest ()
504                 {
505                         Control c = new Control ();
506                         Assert.IsFalse (c.Created, "A1");
507                 }
508
509                 [Test]
510                 [Category ("NotWorking")]
511                 public void CreatedAccessibilityTest ()
512                 {
513                         Control c = new Control ();
514                         Assert.IsFalse (c.Created, "A1");
515
516                         Helper.TestAccessibility(c, null, null, null, AccessibleRole.Default);
517
518                         Assert.IsTrue (c.Created, "A2");
519
520                         c.Dispose ();
521
522                         Assert.IsFalse (c.Created, "A3");
523                 }
524
525                 [Test]
526                 [Category ("NotWorking")]
527                 public void BoundsTest ()
528                 {
529                         Control c = new Control ();
530                         Assert.IsTrue (c.Bounds.IsEmpty, "A1");
531                         Assert.IsTrue (c.Size.IsEmpty, "A2");
532                         Assert.IsTrue (c.ClientSize.IsEmpty, "A3");
533                         Assert.IsTrue (c.ClientRectangle.IsEmpty, "A4");
534
535                         Assert.AreEqual (((IWin32Window)c).Handle, c.Handle, "A5");
536
537                         /* this part fails on linux because we can't allocate X windows which are 0x0,
538                            and the Control bounds directly reflect the size of the X window */
539
540                         Assert.IsTrue (c.Bounds.IsEmpty, "A6");
541                         Assert.IsTrue (c.Size.IsEmpty, "A7");
542                         Assert.IsTrue (c.ClientSize.IsEmpty, "A8");
543                         Assert.IsTrue (c.ClientRectangle.IsEmpty, "A9");
544                 }
545
546                 [Test]
547                 [Ignore ("Depends on specific DPI")]
548                 public void FontHeightTest ()
549                 {
550                         MockControl c = new MockControl ();
551                         Assert.AreEqual (13, c.font_height);
552                 }
553
554                 [Test]
555                 public void FontTest ()
556                 {
557                         Control c = new Control ();
558                         Assert.IsFalse (c.Font.Bold, "#A1");
559                         //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#A2");
560                         Assert.IsFalse (c.Font.Italic, "#A3");
561                         //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#A4");
562                         Assert.AreEqual (8.25, c.Font.Size, "#A5");
563                         Assert.AreEqual (8.25, c.Font.SizeInPoints, "#A6");
564                         Assert.IsFalse (c.Font.Strikeout, "#A7");
565                         Assert.IsFalse (c.Font.Underline, "#A8");
566                         Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#A9");
567 #if NET_2_0
568                         Assert.IsTrue (c.Font.IsSystemFont, "#A10");
569 #endif
570
571                         c.Font = new Font (c.Font.FontFamily, 3, FontStyle.Italic);
572                         Assert.IsFalse (c.Font.Bold, "#B1");
573                         //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#B2");
574                         Assert.IsTrue (c.Font.Italic, "#B3");
575                         //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#B4");
576                         Assert.AreEqual (3, c.Font.Size, "#B5");
577                         Assert.AreEqual (3, c.Font.SizeInPoints, "#B6");
578                         Assert.IsFalse (c.Font.Strikeout, "#B7");
579                         Assert.IsFalse (c.Font.Underline, "#B8");
580                         Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#B9");
581 #if NET_2_0
582                         Assert.AreEqual (false, c.Font.IsSystemFont, "#B10");
583 #endif
584                 }
585
586                 [Test]
587                 [Category ("NotWorking")] // on Unix mapping is done to Bitstream Vera Sans
588                 public void FontTest_Names ()
589                 {
590                         Control c = new Control ();
591                         Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#1");
592                         Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#2");
593                 }
594
595                 [Test]
596                 public void PubPropTest()
597                 {
598                         Control c = new Control();
599
600                         Assert.IsFalse (c.AllowDrop , "A1");
601                         Assert.AreEqual(AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "A2");
602
603                         Assert.AreEqual ("Control", c.BackColor.Name , "B1");
604                         Assert.IsNull (c.BackgroundImage, "B2");
605                         Assert.IsNull (c.BindingContext, "B3");
606 #if NET_2_0
607                         Assert.AreEqual (ImageLayout.Tile, c.BackgroundImageLayout, "B4");
608 #endif
609
610                         Assert.IsFalse (c.CanFocus, "C1");
611                         Assert.IsTrue (c.CanSelect, "C2");
612                         Assert.IsFalse (c.Capture, "C3");
613                         Assert.IsTrue (c.CausesValidation, "C4");
614
615                         Assert.IsNotNull (c.CompanyName, "C7");
616                         Assert.IsNull (c.Container, "C8");
617                         Assert.IsFalse (c.ContainsFocus, "C9");
618                         Assert.IsNull (c.ContextMenu, "C10");
619                         Assert.AreEqual (0, c.Controls.Count, "C11");
620                         Assert.IsFalse (c.Created, "C12");
621                         Assert.AreEqual (Cursors.Default, c.Cursor, "C13");
622
623                         Assert.IsNotNull(c.DataBindings, "D1");
624                         Assert.AreEqual("Control", Control.DefaultBackColor.Name, "D2");
625                         Assert.AreEqual("ControlText", Control.DefaultForeColor.Name, "D3");
626                         Assert.AreEqual(FontStyle.Regular, Control.DefaultFont.Style, "D4");
627                         Assert.AreEqual (new Rectangle(0, 0, 0, 0), c.DisplayRectangle , "D5");
628                         Assert.IsFalse (c.Disposing, "D6");
629                         Assert.AreEqual(DockStyle.None, c.Dock, "D7");
630
631                         Assert.IsTrue (c.Enabled, "E1");
632
633                         Assert.IsFalse  (c.Focused, "F1");
634                         Assert.AreEqual (FontStyle.Regular, c.Font.Style, "F2");
635                         Assert.AreEqual (SystemColors.ControlText, c.ForeColor, "F3");
636
637                         Assert.IsFalse  (c.HasChildren, "H2");
638
639                         Assert.AreEqual (ImeMode.NoControl, c.ImeMode, "I1");
640                         Assert.IsFalse (c.InvokeRequired, "I2");
641                         Assert.IsFalse (c.IsAccessible, "I3");
642                         Assert.IsFalse (c.IsDisposed, "I4");
643                         Assert.IsFalse (c.IsHandleCreated, "I5");
644
645                         Assert.AreEqual(Point.Empty, c.Location, "L2");
646
647 #if NET_2_0
648                         Assert.IsTrue(c.MaximumSize.IsEmpty);
649                         Assert.IsTrue(c.MinimumSize.IsEmpty);
650 #endif
651                         Assert.AreEqual (Keys.None, Control.ModifierKeys, "M1");
652                         Assert.IsFalse (Control.MousePosition.IsEmpty, "M2");
653                         Assert.AreEqual (MouseButtons.None, Control.MouseButtons, "M3");
654
655                         Assert.AreEqual("", c.Name, "N1");
656                         c.Name = "Control Name";
657                         Assert.AreEqual("Control Name", c.Name, "N2");
658
659                         Assert.IsNull (c.Parent, "P1");
660                         Assert.IsNotNull (c.ProductName, "P2");
661                         Assert.IsTrue (c.ProductName != "", "P3");
662                         Assert.IsNotNull (c.ProductVersion, "P4");
663                         Assert.IsTrue (c.ProductVersion != "", "P5");
664
665                         Assert.IsFalse (c.RecreatingHandle, "R1");
666                         Assert.IsNull (c.Region, "R2");
667                         Assert.AreEqual (RightToLeft.No, c.RightToLeft, "R4");
668
669                         Assert.IsNull (c.Site, "S1");
670
671                         Assert.AreEqual (0, c.TabIndex , "T1");
672                         Assert.IsTrue (c.TabStop, "T2");
673                         Assert.IsNull (c.Tag, "T3");
674                         Assert.AreEqual ("", c.Text, "T4");
675
676                         Assert.IsTrue (c.Visible, "V1");
677                 }
678
679                 [Test]
680                 public void SizeChangeTest ()
681                 {
682                         Form f = new Form ();
683                         Control c = new Control ();
684                         f.Controls.Add(c);
685                         f.Show();
686                         c.Resize += new EventHandler(SizeChangedTest_ResizeHandler);
687                         c.Tag = true;
688                         c.Size = c.Size;
689                         Assert.AreEqual (true, (bool) c.Tag, "#1");
690                         f.Close ();
691                 }
692
693                 private void SizeChangedTest_ResizeHandler (object sender, EventArgs e)
694                 {
695                         ((Control) sender).Tag = false;
696                 }
697
698                 [Test]
699                 public void NegativeHeightTest ()
700                 {
701                         Control c = new Control ();
702                         IntPtr handle = c.Handle;
703                         c.Resize += new EventHandler(NegativeHeightTest_ResizeHandler);
704                         c.Tag = -2;
705                         c.Height = 2;
706                         c.Height = -2;
707                         Assert.AreEqual (0, (int) c.Tag, "#1");
708                         c.Dispose ();
709                         Assert.AreEqual (handle, handle, "Removes warning.");
710                 }
711                 
712                 private void NegativeHeightTest_ResizeHandler (object sender, EventArgs e)
713                 {
714                         Control c = (Control) sender;
715                         c.Tag = c.Height;
716                 }
717                 
718                 [Test]
719                 public void TopLevelControlTest () {
720                         Control c = new Control ();
721
722                         Assert.AreEqual(null, c.TopLevelControl, "T1");
723
724                         Panel p = new Panel ();
725
726                         p.Controls.Add (c);
727
728                         Assert.AreEqual(null, c.TopLevelControl, "T2");
729
730                         Form f = new Form ();
731                         f.ShowInTaskbar = false;
732
733                         f.Controls.Add (p);
734
735                         Assert.AreEqual (f, c.TopLevelControl, "T3");
736                         Assert.AreEqual (f, f.TopLevelControl, "T4");
737                 }
738
739                 [Test]
740                 public void RelationTest() {
741                         Control c1;
742                         Control c2;
743
744                         c1 = new Control();
745                         c2 = new Control();
746
747                         Assert.AreEqual(true , c1.Visible , "Rel1");
748                         Assert.AreEqual(false, c1.Contains(c2) , "Rel2");
749                         Assert.AreEqual("System.Windows.Forms.Control", c1.ToString() , "Rel3");
750
751                         c1.Controls.Add(c2);
752                         Assert.AreEqual(true , c2.Visible , "Rel4");
753                         Assert.AreEqual(true, c1.Contains(c2) , "Rel5");
754
755                         c1.Anchor = AnchorStyles.Top;
756                         c1.SuspendLayout ();
757                         c1.Anchor = AnchorStyles.Left ;
758                         c1.ResumeLayout ();
759                         Assert.AreEqual(AnchorStyles.Left , c1.Anchor, "Rel6");
760
761                         c1.SetBounds(10, 20, 30, 40) ;
762                         Assert.AreEqual(new Rectangle(10, 20, 30, 40), c1.Bounds, "Rel7");
763
764                         Assert.AreEqual(c1, c2.Parent, "Rel8");
765                 }
766
767                 [Test]
768                 public void AnchorDockTest ()
769                 {
770                         Control c = new Control ();
771
772                         Assert.AreEqual (DockStyle.None, c.Dock, "1");
773                         Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "2");
774
775                         c.Dock = DockStyle.Top;
776                         Assert.AreEqual (DockStyle.Top, c.Dock, "3");
777                         Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "4");
778
779                         c.Anchor = AnchorStyles.Top;
780                         Assert.AreEqual (DockStyle.None, c.Dock, "5");
781                         Assert.AreEqual (AnchorStyles.Top, c.Anchor, "6");
782                 }
783
784                 [Test]
785                 [Category ("NotWorking")]
786                 public void TabOrder()
787                 {
788                         Form            form;
789                         //Control               active;
790
791                         Label           label1 = new Label();           // To test non-tabstop items as well
792                         Label           label2 = new Label();
793
794                         GroupBox        group1 = new GroupBox();
795                         GroupBox        group2 = new GroupBox();
796                         GroupBox        group3 = new GroupBox();
797
798                         TextBox         text1 = new TextBox();
799
800                         RadioButton     radio11 = new RadioButton();
801                         RadioButton     radio12 = new RadioButton();
802                         RadioButton     radio13 = new RadioButton();
803                         RadioButton     radio14 = new RadioButton();
804                         RadioButton     radio21 = new RadioButton();
805                         RadioButton     radio22 = new RadioButton();
806                         RadioButton     radio23 = new RadioButton();
807                         RadioButton     radio24 = new RadioButton();
808                         RadioButton     radio31 = new RadioButton();
809                         RadioButton     radio32 = new RadioButton();
810                         RadioButton     radio33 = new RadioButton();
811                         RadioButton     radio34 = new RadioButton();
812
813                         form = new Form();
814                         form.ShowInTaskbar = false;
815
816                         form.ClientSize = new Size (520, 520);
817                         Assert.AreEqual(new Size(520, 520), form.ClientSize, "Tab1");
818
819                         form.Text = "SWF Taborder Test App Form";
820                         Assert.AreEqual("SWF Taborder Test App Form", form.Text, "Tab2");
821
822                         label1.Location = new Point(10, 10);
823                         Assert.AreEqual(new Point(10, 10), label1.Location, "Tab3");
824                         label1.Text = "Label1";
825                         form.Controls.Add(label1);
826
827                         label2.Location = new Point(200, 10);
828                         label2.Text = "Label2";
829                         form.Controls.Add(label2);
830
831                         group1.Text = "Group1";
832                         group2.Text = "Group2";
833                         group3.Text = "Group3";
834
835                         group1.Size = new Size(200, 400);
836                         group2.Size = new Size(200, 400);
837                         group3.Size = new Size(180, 180);
838                         Assert.AreEqual(new Size(180, 180), group3.Size, "Tab4");
839
840                         group1.Location = new Point(10, 40);
841                         group2.Location = new Point(220, 40);
842                         group3.Location = new Point(10, 210);
843
844                         group1.TabIndex = 30;
845                         Assert.AreEqual(30, group1.TabIndex, "Tab5");
846                         group1.TabStop = true;
847
848                         // Don't assign, test automatic assignment
849                         //group2.TabIndex = 0;
850                         group2.TabStop = true;
851                         Assert.AreEqual(0, group2.TabIndex, "Tab6");
852
853                         group3.TabIndex = 35;
854                         group3.TabStop = true;
855
856                         // Test default tab index
857                         Assert.AreEqual(0, radio11.TabIndex, "Tab7");
858
859                         text1.Text = "Edit Control";
860
861                         radio11.Text = "Radio 1-1 [Tab1]";
862                         radio12.Text = "Radio 1-2 [Tab2]";
863                         radio13.Text = "Radio 1-3 [Tab3]";
864                         radio14.Text = "Radio 1-4 [Tab4]";
865
866                         radio21.Text = "Radio 2-1 [Tab4]";
867                         radio22.Text = "Radio 2-2 [Tab3]";
868                         radio23.Text = "Radio 2-3 [Tab2]";
869                         radio24.Text = "Radio 2-4 [Tab1]";
870
871                         radio31.Text = "Radio 3-1 [Tab1]";
872                         radio32.Text = "Radio 3-2 [Tab3]";
873                         radio33.Text = "Radio 3-3 [Tab2]";
874                         radio34.Text = "Radio 3-4 [Tab4]";
875
876                         // We don't assign TabIndex for radio1X; test automatic assignment
877                         text1.TabStop = true;
878                         radio11.TabStop = true;
879
880                         radio21.TabIndex = 4;
881                         radio22.TabIndex = 3;
882                         radio23.TabIndex = 2;
883                         radio24.TabIndex = 1;
884                         radio24.TabStop = true;
885
886                         radio31.TabIndex = 11;
887                         radio31.TabStop = true;
888                         radio32.TabIndex = 13;
889                         radio33.TabIndex = 12;
890                         radio34.TabIndex = 14;
891
892                         text1.Location = new Point(10, 100);
893
894                         radio11.Location = new Point(10, 20);
895                         radio12.Location = new Point(10, 40);
896                         radio13.Location = new Point(10, 60);
897                         radio14.Location = new Point(10, 80);
898
899                         radio21.Location = new Point(10, 20);
900                         radio22.Location = new Point(10, 40);
901                         radio23.Location = new Point(10, 60);
902                         radio24.Location = new Point(10, 80);
903
904                         radio31.Location = new Point(10, 20);
905                         radio32.Location = new Point(10, 40);
906                         radio33.Location = new Point(10, 60);
907                         radio34.Location = new Point(10, 80);
908
909                         text1.Size = new Size(150, text1.PreferredHeight);
910
911                         radio11.Size = new Size(150, 20);
912                         radio12.Size = new Size(150, 20);
913                         radio13.Size = new Size(150, 20);
914                         radio14.Size = new Size(150, 20);
915
916                         radio21.Size = new Size(150, 20);
917                         radio22.Size = new Size(150, 20);
918                         radio23.Size = new Size(150, 20);
919                         radio24.Size = new Size(150, 20);
920
921                         radio31.Size = new Size(150, 20);
922                         radio32.Size = new Size(150, 20);
923                         radio33.Size = new Size(150, 20);
924                         radio34.Size = new Size(150, 20);
925
926                         group1.Controls.Add(text1);
927
928                         group1.Controls.Add(radio11);
929                         group1.Controls.Add(radio12);
930                         group1.Controls.Add(radio13);
931                         group1.Controls.Add(radio14);
932
933                         group2.Controls.Add(radio21);
934                         group2.Controls.Add(radio22);
935                         group2.Controls.Add(radio23);
936                         group2.Controls.Add(radio24);
937
938                         group3.Controls.Add(radio31);
939                         group3.Controls.Add(radio32);
940                         group3.Controls.Add(radio33);
941                         group3.Controls.Add(radio34);
942
943                         form.Controls.Add(group1);
944                         form.Controls.Add(group2);
945                         group2.Controls.Add(group3);
946
947                         // Perform some tests, the TabIndex stuff below will alter the outcome
948                         Assert.AreEqual(null, Helper.TestControl(group2, radio34, true), "Tab8");
949                         Assert.AreEqual(31, group2.TabIndex, "Tab9");
950
951                         // Does the taborder of containers and non-selectable things change behaviour?
952                         label1.TabIndex = 5;
953                         label2.TabIndex = 4;
954                         group1.TabIndex = 3;
955                         group2.TabIndex = 1;
956
957                         // Start verification
958                         Assert.AreEqual(null, Helper.TestControl(group2, radio34, true), "Tab10");
959                         Assert.AreEqual(radio24.Text, Helper.TestControl(group2, group2, true), "Tab11");
960                         Assert.AreEqual(radio31.Text, Helper.TestControl(group2, group3, true), "Tab12");
961                         Assert.AreEqual(null, Helper.TestControl(group1, radio14, true), "Tab13");
962                         Assert.AreEqual(radio23.Text, Helper.TestControl(group2, radio24, true), "Tab14");
963                         Assert.AreEqual(group3.Text, Helper.TestControl(group2, radio21, true), "Tab15");
964                         Assert.AreEqual(radio13.Text, Helper.TestControl(form, radio12, true), "Tab16");
965                         Assert.AreEqual(label2.Text, Helper.TestControl(form, radio14, true), "Tab17");
966                         Assert.AreEqual(group1.Text, Helper.TestControl(form, radio34, true), "Tab18");
967                         Assert.AreEqual(radio23.Text, Helper.TestControl(group2, radio24, true), "Tab19");
968
969                         // Sanity checks
970                         Assert.AreEqual(null, Helper.TestControl(radio11, radio21, true), "Tab20");
971                         Assert.AreEqual(text1.Text, Helper.TestControl(group1, radio21, true), "Tab21");
972
973                         Assert.AreEqual(radio14.Text, Helper.TestControl(form, label2, false), "Tab22");
974                         Assert.AreEqual(radio21.Text, Helper.TestControl(group2, group3, false), "Tab23");
975
976                         Assert.AreEqual(4, radio21.TabIndex, "Tab24");
977                         Assert.AreEqual(1, radio11.TabIndex, "Tab25");
978                         Assert.AreEqual(3, radio13.TabIndex, "Tab26");
979                         Assert.AreEqual(35, group3.TabIndex, "Tab27");
980                         Assert.AreEqual(1, group2.TabIndex, "Tab28");
981
982                         Assert.AreEqual(label1.Text, Helper.TestControl(form, form, false), "Tab29");
983                         Assert.AreEqual(radio14.Text, Helper.TestControl(group1, group1, false), "Tab30");
984                         Assert.AreEqual(radio34.Text, Helper.TestControl(group3, group3, false), "Tab31");
985
986                         Assert.AreEqual(null, Helper.TestControl(label1, label1, false), "Tab31");
987                         Assert.AreEqual(null, Helper.TestControl(radio11, radio21, false), "Tab32");
988                         form.Dispose ();
989                 }
990
991                 [Test]
992                 public void ScaleTest()
993                 {
994                         Control r1 = new Control();
995
996                         r1.Width = 40;
997                         r1.Height = 20;
998                         r1.Scale(2);
999                         Assert.AreEqual(80, r1.Width, "Scale1");
1000                         Assert.AreEqual(40, r1.Height, "Scale2");
1001                 }
1002
1003                 [Test]
1004                 public void TextTest()
1005                 {
1006                         Control r1 = new Control();
1007                         r1.Text = "Hi" ;
1008                         Assert.AreEqual("Hi" , r1.Text , "Text1");
1009
1010                         r1.ResetText();
1011                         Assert.AreEqual("" , r1.Text , "Text2");
1012                 }
1013
1014                 [Test]
1015                 public void PubMethodTest7()
1016                 {
1017                         Control r1 = new Control();
1018                         r1.RightToLeft = RightToLeft.Yes ;
1019                         r1.ResetRightToLeft() ;
1020                         Assert.AreEqual(RightToLeft.No , r1.RightToLeft , "#81");
1021                         r1.ImeMode = ImeMode.Off ;
1022                         r1.ResetImeMode () ;
1023                         Assert.AreEqual(ImeMode.NoControl , r1.ImeMode , "#82");
1024                         r1.ForeColor= SystemColors.GrayText ;
1025                         r1.ResetForeColor() ;
1026                         Assert.AreEqual(SystemColors.ControlText , r1.ForeColor , "#83");
1027                         //r1.Font = Font.FromHdc();
1028                         r1.ResetFont () ;
1029                         //Assert.AreEqual(FontFamily.GenericSansSerif , r1.Font , "#83");
1030                         r1.Cursor = Cursors.Hand ;
1031                         r1.ResetCursor () ;
1032                         Assert.AreEqual(Cursors.Default , r1.Cursor , "#83");
1033                         //r1.DataBindings = System.Windows.Forms.Binding ;
1034                         //r1.ResetBindings() ;
1035                         //Assert.AreEqual(ControlBindingsCollection , r1.DataBindings  , "#83");
1036                         r1.BackColor = Color.Black ;
1037                         r1.ResetBackColor() ;
1038                         Assert.AreEqual( SystemColors.Control , r1.BackColor  , "#84");
1039                         r1.BackColor = Color.Black ;
1040                         r1.Refresh() ;
1041                         Assert.AreEqual( null , r1.Region , "#85");
1042                         Rectangle M = new Rectangle(10, 20, 30 ,40);
1043                         r1.RectangleToScreen(M) ;
1044                         Assert.AreEqual( null , r1.Region , "#86");
1045                 }
1046
1047                 [Test]
1048                 public void ScreenClientCoords()
1049                 {
1050                         Label l;
1051                         Point p1;
1052                         Point p2;
1053                         Point p3;
1054
1055                         l = new Label();
1056                         l.Left = 10;
1057                         l.Top  = 12;
1058                         l.Visible = true;
1059                         p1 = new Point (10,10);
1060                         p2 = l.PointToScreen(p1);
1061                         p3 = l.PointToClient(p2);
1062
1063                         Assert.AreEqual (p1, p3, "SC1");
1064                 }
1065
1066                 [Test]
1067                 public void ContainsTest ()
1068                 {
1069                         Control t = new Control ();
1070                         Control s = new Control ();
1071
1072                         t.Controls.Add (s);
1073
1074                         Assert.AreEqual (true, t.Contains (s), "Con1");
1075                         Assert.AreEqual (false, s.Contains (t), "Con2");
1076                         Assert.AreEqual (false, s.Contains (null), "Con3");
1077                         Assert.AreEqual (false, t.Contains (new Control ()), "Con4");
1078                 }
1079
1080                 [Test]
1081                 public void CreateHandleTest ()
1082                 {
1083                         Control parent;
1084                         Control child;
1085
1086                         parent = null;
1087                         child = null;
1088
1089                         try {
1090                                 parent = new Control ();
1091                                 child = new Control ();
1092
1093                                 parent.Visible = true;
1094                                 parent.Controls.Add (child);
1095
1096                                 Assert.IsFalse (parent.IsHandleCreated, "CH1");
1097                                 Assert.IsFalse (child.IsHandleCreated, "CH2");
1098
1099                                 parent.CreateControl ();
1100                                 Assert.IsNotNull (parent.Handle, "CH3");
1101                                 Assert.IsNotNull (child.Handle, "CH4");
1102                                 Assert.IsTrue (parent.IsHandleCreated, "CH5");
1103                                 Assert.IsTrue (child.IsHandleCreated, "CH6");
1104                         } finally {
1105                                 if (parent != null)
1106                                         parent.Dispose ();
1107                                 if (child != null)
1108                                         child.Dispose ();
1109                         }
1110
1111                         // Accessing Handle Property creates the handle
1112                         try {
1113                                 parent = new Control ();
1114                                 parent.Visible = true;
1115                                 child = new Control ();
1116                                 parent.Controls.Add (child);
1117                                 Assert.IsFalse (parent.IsHandleCreated, "CH7");
1118                                 Assert.IsFalse (child.IsHandleCreated, "CH8");
1119                                 Assert.IsNotNull (parent.Handle, "CH9");
1120                                 Assert.IsTrue (parent.IsHandleCreated, "CH10");
1121                                 Assert.IsTrue (child.IsHandleCreated, "CH11");
1122                         } finally {
1123                                 if (parent != null)
1124                                         parent.Dispose ();
1125                                 if (child != null)
1126                                         child.Dispose ();
1127                         }
1128                 }
1129
1130                 [Test]
1131                 [Category ("NotWorking")]
1132                 public void CreateHandleTest2 ()
1133                 {
1134                         // This should eventually test all operations
1135                         // that can be performed on a control (within
1136                         // reason)
1137                         Control c = new Control ();
1138
1139                         Assert.IsFalse (c.IsHandleCreated, "0");
1140
1141                         c.Width = 100;
1142                         Assert.IsFalse (c.IsHandleCreated, "1");
1143
1144                         c.Height = 100;
1145                         Assert.IsFalse (c.IsHandleCreated, "2");
1146
1147                         c.Name = "hi";
1148                         Assert.IsFalse (c.IsHandleCreated, "3");
1149
1150                         c.Left = 5;
1151                         Assert.IsFalse (c.IsHandleCreated, "5");
1152
1153                         c.Top = 5;
1154                         Assert.IsFalse (c.IsHandleCreated, "6");
1155
1156                         c.Location = new Point (1, 1);
1157                         Assert.IsFalse (c.IsHandleCreated, "7");
1158
1159                         c.Region = new Region ();
1160                         Assert.IsFalse (c.IsHandleCreated, "8");
1161
1162                         c.Size = new Size (100, 100);
1163                         Assert.IsFalse (c.IsHandleCreated, "9");
1164
1165                         c.Text = "bye";
1166                         Assert.IsFalse (c.IsHandleCreated, "10");
1167
1168                         c.Visible = !c.Visible;
1169                         Assert.IsFalse (c.IsHandleCreated, "11");
1170                 }
1171
1172                 [Test]
1173                 [Category ("NotWorking")]
1174                 public void IsHandleCreated_NotVisible ()
1175                 {
1176                         Control c = new Control ();
1177                         c.Visible = false;
1178
1179                         Form form = new Form ();
1180                         form.ShowInTaskbar = false;
1181                         form.Controls.Add (c);
1182                         form.Show ();
1183
1184                         Assert.IsFalse (c.IsHandleCreated, "#1");
1185                         c.Visible = true;
1186                         Assert.IsTrue (c.IsHandleCreated, "#2");
1187                         c.Visible = false;
1188                         Assert.IsTrue (c.IsHandleCreated, "#3");
1189                 }
1190
1191                 [Test]
1192                 public void CreateGraphicsTest ()
1193                 {
1194                         Graphics g = null;
1195                         Pen p = null;
1196
1197                         try {
1198                                 Control c = new Control ();
1199                                 c.SetBounds (0,0, 20, 20);
1200                                 g = c.CreateGraphics ();
1201                                 Assert.IsNotNull (g, "Graph1");
1202                         } finally {
1203                                 if (p != null)
1204                                         p.Dispose ();
1205                                 if (g != null)
1206                                         g.Dispose ();
1207                         }
1208                 }
1209
1210                 bool delegateCalled = false;
1211                 public delegate void TestDelegate ();
1212
1213                 public void delegate_call () {
1214                         delegateCalled = true;
1215
1216                         TestHelper.RemoveWarning (delegateCalled);
1217                 }
1218
1219                 [Test]
1220                 [ExpectedException(typeof(InvalidOperationException))]
1221                 public void InvokeException1 () {
1222                         Control c = new Control ();
1223                         IAsyncResult result;
1224
1225                         result = c.BeginInvoke (new TestDelegate (delegate_call));
1226                         c.EndInvoke (result);
1227                 }
1228
1229                 [Test]
1230                 public void FindFormTest () {
1231                         Form f = new Form ();
1232
1233                         f.ShowInTaskbar = false;
1234                         f.Name = "form";
1235                         Control c = null;
1236
1237                         try {
1238                                 f.Controls.Add (c = new Control ());
1239                                 Assert.AreEqual (f.Name, c.FindForm ().Name, "Find1");
1240
1241                                 f.Controls.Remove (c);
1242
1243                                 GroupBox g = new GroupBox ();
1244                                 g.Name = "box";
1245                                 f.Controls.Add (g);
1246                                 g.Controls.Add (c);
1247
1248                                 Assert.AreEqual (f.Name, f.FindForm ().Name, "Find2");
1249
1250                                 g.Controls.Remove (c);
1251                                 Assert.IsNull(c.FindForm (), "Find3");
1252
1253                         } finally {
1254                                 if (c != null)
1255                                         c.Dispose ();
1256                                 if (f != null)
1257                                         f.Dispose ();
1258                         }
1259                 }
1260
1261                 [Test]
1262                 public void FocusTest ()
1263                 {
1264                         Form f = null;
1265                         Button c = null, d = null;
1266
1267                         try {
1268                                 f = new Form ();
1269                                 f.ShowInTaskbar = false;
1270                                 f.Visible = true;
1271                                 c = new Button ();
1272                                 c.Visible = true;
1273                                 f.Controls.Add (c);
1274
1275                                 d = new Button ();
1276                                 d.Visible = false;
1277                                 f.Controls.Add (d);
1278
1279                                 Assert.IsTrue (c.CanFocus, "Focus1");
1280                                 Assert.IsFalse (c.Focused, "Focus2");
1281                                 c.Focus ();
1282                                 Assert.IsTrue (c.Focused, "Focus3");
1283                                 d.Focus ();
1284                                 Assert.IsFalse (d.Focused, "Focus4");
1285
1286                                 d.Visible = true;
1287                                 d.Focus ();
1288                                 Assert.IsTrue (d.Focused, "Focus5");
1289                                 Assert.IsFalse (c.Focused, "Focus6");
1290
1291                                 c.Enabled = false;
1292                                 Assert.IsFalse (c.Focused, "Focus7");
1293                         } finally {
1294                                 if (f != null)
1295                                         f.Dispose ();
1296                                 if (c != null)
1297                                         c.Dispose ();
1298                                 if (d != null)
1299                                         d.Dispose ();
1300                         }
1301                 }
1302
1303                 [Test]
1304                 public void FromHandleTest ()
1305                 {
1306                         Control c1 = null;
1307                         Control c2 = null;
1308
1309                         try {
1310                                 c1 = new Control ();
1311                                 c2 = new Control ();
1312
1313                                 c1.Name = "parent";
1314                                 c2.Name = "child";
1315                                 c1.Controls.Add(c2);
1316
1317                                 // Handle
1318                                 Assert.AreEqual (c1.Name, Control.FromHandle (c1.Handle).Name, "Handle1");
1319                                 Assert.IsNull (Control.FromHandle (IntPtr.Zero), "Handle2");
1320
1321                                 // ChildHandle
1322                                 Assert.AreEqual (c1.Name, Control.FromChildHandle (c1.Handle).Name, "Handle3");
1323                                 Assert.IsNull (Control.FromChildHandle (IntPtr.Zero), "Handle4");
1324
1325
1326                         } finally {
1327                                 if (c1 != null)
1328                                         c1.Dispose ();
1329
1330                                 if (c2 != null)
1331                                         c2.Dispose ();
1332                         }
1333                 }
1334
1335                 [Test]
1336                 public void GetChildAtPointTest ()
1337                 {
1338                         Control c = null, d = null, e = null;
1339
1340                         try {
1341                                 c = new Control ();
1342                                 c.Name = "c1";
1343                                 c.SetBounds (0, 0, 100, 100);
1344
1345                                 d = new Control ();
1346                                 d.Name = "d1";
1347                                 d.SetBounds (10, 10, 40, 40);
1348                                 c.Controls.Add (d);
1349
1350                                 e = new Control ();
1351                                 e.Name = "e1";
1352                                 e.SetBounds (55, 55, 10, 10);
1353
1354                                 Control l = c.GetChildAtPoint (new Point (15, 15));
1355                                 Assert.AreEqual (d.Name, l.Name, "Child1");
1356                                 Assert.IsFalse (e.Name == l.Name, "Child2");
1357
1358                                 l = c.GetChildAtPoint (new Point (57, 57));
1359                                 Assert.IsNull (l, "Child3");
1360
1361                                 l = c.GetChildAtPoint (new Point (10, 10));
1362                                 Assert.AreEqual (d.Name, l.Name, "Child4");
1363
1364                                 // GetChildAtPointSkip is not implemented and the following test is breaking for Net_2_0 profile
1365 //                              #if NET_2_0
1366 //                                      c.Controls.Add (e);
1367 //                                      e.Visible = false;
1368 //                                      l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
1369 //                                      Assert.IsNull (l, "Child5");
1370
1371 //                                      e.Visible = true;
1372 //                                      l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
1373 //                                      Assert.AreSame (e.Name, l.Name, "Child6");
1374 //                              #endif // NET_2_0
1375                         } finally {
1376                                 if (c != null)
1377                                         c.Dispose ();
1378                                 if (d != null)
1379                                         d.Dispose ();
1380                         }
1381                 }
1382
1383                 [Test]
1384                 public void ResetFontTest ()
1385                 {
1386                         Control c = new Control ();
1387                         c.Font = new Font (c.Font.FontFamily, 3, FontStyle.Italic);
1388                         c.ResetFont ();
1389
1390                         Assert.IsFalse (c.Font.Bold, "#1");
1391                         //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#2");
1392                         Assert.IsFalse (c.Font.Italic, "#3");
1393                         //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#4");
1394                         Assert.AreEqual (8.25, c.Font.Size, "#5");
1395                         Assert.AreEqual (8.25, c.Font.SizeInPoints, "#6");
1396                         Assert.IsFalse (c.Font.Strikeout, "#7");
1397                         Assert.IsFalse (c.Font.Underline, "#8");
1398                         Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#9");
1399 #if NET_2_0
1400                         Assert.AreEqual (true, c.Font.IsSystemFont, "#10");
1401 #endif
1402                 }
1403
1404                 public class LayoutTestControl : Control {
1405                         public int LayoutCount;
1406
1407                         public LayoutTestControl () : base() {
1408                                 LayoutCount = 0;
1409                         }
1410
1411                         protected override void OnLayout(LayoutEventArgs levent) {
1412                                 LayoutCount++;
1413                                 base.OnLayout (levent);
1414                         }
1415                 }
1416
1417                 [Test]
1418                 public void LayoutTest() {
1419                         LayoutTestControl c;
1420
1421                         c = new LayoutTestControl();
1422
1423                         c.SuspendLayout();
1424                         c.SuspendLayout();
1425                         c.SuspendLayout();
1426                         c.SuspendLayout();
1427
1428                         c.ResumeLayout(true);
1429                         c.PerformLayout();
1430                         c.ResumeLayout(true);
1431                         c.PerformLayout();
1432                         c.ResumeLayout(true);
1433                         c.PerformLayout();
1434                         c.ResumeLayout(true);
1435                         c.PerformLayout();
1436                         c.ResumeLayout(true);
1437                         c.PerformLayout();
1438                         c.ResumeLayout(true);
1439                         c.PerformLayout();
1440                         c.ResumeLayout(true);
1441                         c.PerformLayout();
1442                         c.SuspendLayout();
1443                         c.PerformLayout();
1444
1445                         Assert.AreEqual(5, c.LayoutCount, "Layout Suspend/Resume locking does not bottom out at 0");
1446                 }
1447
1448                 [Test]
1449                 [ExpectedException(typeof(ArgumentException))]
1450                 public void TransparentBackgroundTest1() {
1451                         Control c;
1452
1453                         c = new Control();
1454                         c.BackColor = Color.Transparent;
1455                 }
1456
1457                 [Test]
1458                 public void TransparentBackgroundTest2() {
1459                         Panel   c;
1460
1461                         c = new Panel();
1462                         c.BackColor = Color.Transparent;
1463                         Assert.AreEqual(Color.Transparent, c.BackColor, "Transparent background not set");
1464                 }
1465
1466                 [Test]
1467                 public void TransparentBackgroundTest3() {
1468                         Control c;
1469
1470                         c = new Control();
1471                         c.BackColor = Color.Empty;
1472                         Assert.AreEqual(Control.DefaultBackColor, c.BackColor, "Setting empty color failed");
1473                 }
1474
1475                 [Test]
1476                 public void Dock_Value_Invalid ()
1477                 {
1478                         Control c = new Control ();
1479                         try {
1480                                 c.Dock = (DockStyle) 666;
1481                                 Assert.Fail ("#1");
1482                         } catch (InvalidEnumArgumentException ex) {
1483                                 Assert.AreEqual (typeof (InvalidEnumArgumentException), ex.GetType (), "#2");
1484                                 Assert.IsNotNull (ex.Message, "#3");
1485                                 Assert.IsNotNull (ex.ParamName, "#4");
1486                                 Assert.AreEqual ("value", ex.ParamName, "#5");
1487                                 Assert.IsNull (ex.InnerException, "#6");
1488                         }
1489                 }
1490
1491                 [Test]
1492                 public void EnabledTest1() {
1493                         Control child;
1494                         Control parent;
1495                         Control grandma;
1496
1497                         grandma = new Control();
1498                         parent = new Control();
1499                         child = new Control();
1500
1501                         grandma.Controls.Add(parent);
1502                         parent.Controls.Add(child);
1503                         grandma.Enabled = false;
1504                         Assert.AreEqual(grandma.Enabled, child.Enabled, "Child did not inherit disabled state");
1505                 }
1506
1507                 int EnabledCalledCount = 0;
1508                 private void EnabledTest2EnabledChanged(object sender, EventArgs e) {
1509                         EnabledCalledCount++;
1510                 }
1511
1512                 [Test]
1513                 public void EnabledTest2() {
1514                         // Check nesting of enabled calls
1515                         // OnEnabled is not called for disabled child controls
1516                         Control child;
1517                         Control parent;
1518                         Control grandma;
1519
1520                         EnabledCalledCount = 0;
1521
1522                         grandma = new Control();
1523                         parent = new Control();
1524                         child = new Control();
1525                         child.EnabledChanged += new EventHandler(EnabledTest2EnabledChanged);
1526
1527                         grandma.Controls.Add(parent);
1528                         parent.Controls.Add(child);
1529                         grandma.Enabled = false;
1530
1531                         Assert.AreEqual(1, EnabledCalledCount, "Child Enabled Event not properly fired");
1532                         grandma.Enabled = true;
1533                         Assert.AreEqual(2, EnabledCalledCount, "Child Enabled Event not properly fired");
1534                         child.Enabled = false;
1535                         grandma.Enabled = false;
1536                         Assert.AreEqual(3, EnabledCalledCount, "Child Enabled Event not properly fired");
1537                 }
1538
1539                 [Test]
1540                 public void ControlsRemoveNullTest ()
1541                 {
1542                         Control c = new Control ();
1543                         c.Controls.Remove (null);
1544                 }
1545
1546                 [Test]
1547                 public void ControlsAddNullTest ()
1548                 {
1549                         Control c = new Control ();
1550                         c.Controls.Add (null);
1551                 }
1552
1553                 [Test]
1554                 [ExpectedException (typeof (ArgumentNullException))]
1555                 public void ControlsSetChildIndexNullTest ()
1556                 {
1557                         Control c = new Control ();
1558                         c.Controls.SetChildIndex (null, 1);
1559                 }
1560
1561                 [Test]
1562                 [ExpectedException (typeof (ArgumentNullException))]
1563                 public void ControlsAddRangeNullTest ()
1564                 {
1565                         Control c = new Control ();
1566                         c.Controls.AddRange (null);
1567                 }
1568
1569                 [Test]
1570                 public void ControlsAddRangeNullElementTest ()
1571                 {
1572                         Control c = new Control ();
1573                         Control[] subcontrols = new Control[2];
1574                         subcontrols[0] = new Control ();
1575                         subcontrols[1] = null;
1576
1577                         c.Controls.AddRange (subcontrols);
1578                 }
1579
1580                 [Test]
1581                 public void RegionTest () {
1582                         Form f = new Form ();
1583                         f.ShowInTaskbar = false;
1584                         Control c = new Control ();
1585                         f.Controls.Add (c);
1586                         Assert.IsNull (c.Region, "#A1");
1587                         f.Show ();
1588                         Assert.IsNull (c.Region, "#A2");
1589                         c.Region = null;
1590                         Assert.IsNull (c.Region, "#A3");
1591                         f.Dispose ();
1592
1593                         Region region = new Region ();
1594                         f = new Form ();
1595                         f.ShowInTaskbar = false;
1596                         c = new Control ();
1597                         f.Controls.Add (c);
1598                         c.Region = region;
1599                         Assert.IsNotNull (c.Region, "#B1");
1600                         Assert.AreSame (region, c.Region, "#B2");
1601                         f.Show ();
1602                         c.Region = null;
1603                         Assert.IsNull (c.Region, "#B3");
1604
1605                         f.Dispose ();
1606                 }
1607
1608                 [Test] // bug #80280
1609                 public void Validated_Multiple_Containers ()
1610                 {
1611                         Form form = new Form ();
1612                         form.ShowInTaskbar = false;
1613
1614                         UserControl control1 = new UserControl();
1615                         UserControl container1 = new UserControl();
1616                         control1.Tag = true;
1617                         control1.Validated += new EventHandler (Control_ValidatedHandler);
1618                         container1.Controls.Add(control1);
1619                         form.Controls.Add (container1);
1620
1621                         UserControl container2 = new UserControl();
1622                         UserControl control2 = new UserControl();
1623                         container2.Controls.Add(control2);
1624                         form.Controls.Add (container2);
1625
1626                         Assert.IsTrue ((bool) control1.Tag, "#1");
1627                         control1.Select();
1628                         Assert.IsTrue ((bool) control1.Tag, "#2");
1629                         control2.Select();
1630                         Assert.IsFalse ((bool) control1.Tag, "#3");
1631
1632                         form.Dispose ();
1633                 }
1634
1635                 private void Control_ValidatedHandler (object sender, EventArgs e)
1636                 {
1637                         ((Control) sender).Tag = false;
1638                 }
1639
1640                 public class MockControl : Control
1641                 {
1642                         public int font_height {
1643                                 get { return base.FontHeight; }
1644                                 set { base.FontHeight = value; }
1645                         }
1646                 }
1647         }
1648
1649         [TestFixture]
1650         public class ControlSetTopLevelTest
1651         {
1652                 class ControlPoker : Control {
1653                         public void DoSetTopLevel ()
1654                         {
1655                                 SetTopLevel (true);
1656                         }
1657                         public bool DoGetTopLevel ()
1658                         {
1659                                 return GetTopLevel ();
1660                         }
1661                 }
1662
1663                 [Test]
1664                 public void TestControl ()
1665                 {
1666                         ControlPoker c = new ControlPoker ();
1667                         c.Visible = false;
1668                         c.DoSetTopLevel ();
1669                         Assert.IsTrue (c.DoGetTopLevel (), "1");
1670                         Assert.IsFalse (c.Visible, "2");
1671                 }
1672
1673                 [Test]
1674                 [ExpectedException (typeof (ArgumentException))]
1675                 public void TestChildControl ()
1676                 {
1677                         Control c1 = new Control();
1678                         ControlPoker c2 = new ControlPoker ();
1679
1680                         c1.Controls.Add (c2);
1681                         c2.DoSetTopLevel ();
1682                 }
1683
1684                 [Test]
1685                 [ExpectedException (typeof (ArgumentException))]
1686                 public void TestTopLevelAdd () {
1687                         Form f = new Form();
1688                         Form f1 = new Form();
1689                         f.Controls.Add(f1);
1690                 }
1691                 
1692                 [Category ("NotWorking")]
1693                 [Test]
1694                 public void TestForm ()
1695                 {
1696                         Form f = new Form ();
1697                         Assert.IsFalse (f.Visible, "3");
1698                         f.TopLevel = true;
1699                         Assert.IsFalse (f.Visible, "4");
1700                 }
1701         }
1702
1703         [TestFixture]
1704         public class ControlResizeLayoutTest
1705         {
1706                 class ControlPoker : Control {
1707                         public void DoOnResize ()
1708                         {
1709                                 OnResize (EventArgs.Empty);
1710                         }
1711                 }
1712
1713                 int child_event;
1714                 string child_affected_property;
1715                 void ChildLayoutEvent (object sender, LayoutEventArgs e)
1716                 {
1717                         child_event ++;
1718                         child_affected_property = e.AffectedProperty;
1719                 }
1720
1721                 int parent_event;
1722                 string parent_affected_property;
1723                 void ParentLayoutEvent (object sender, LayoutEventArgs e)
1724                 {
1725                         parent_event ++;
1726                         parent_affected_property = e.AffectedProperty;
1727
1728                         TestHelper.RemoveWarning (parent_affected_property);
1729                 }
1730
1731                 [Test]
1732                 public void Test ()
1733                 {
1734                         Panel p = new Panel ();
1735                         ControlPoker c = new ControlPoker();
1736
1737                         p.Controls.Add (c);
1738
1739                         p.Layout += new LayoutEventHandler (ParentLayoutEvent);
1740                         c.Layout += new LayoutEventHandler (ChildLayoutEvent);
1741
1742                         c.DoOnResize ();
1743
1744                         Assert.AreEqual (1, child_event, "1");
1745                         Assert.AreEqual ("Bounds", child_affected_property, "2");
1746
1747                         Assert.AreEqual (0, parent_event, "3");
1748                 }
1749         }
1750
1751         [TestFixture]
1752         public class ControlInvokeTest {
1753                 public delegate void TestDelegate ();
1754
1755                 Form f;
1756                 Control c;
1757                 Thread control_t;
1758                 ApplicationContext control_context;
1759                 bool delegateCalled = false;
1760
1761                 object m;
1762
1763                 void CreateControl ()
1764                 {
1765                         f = new Form ();
1766                         f.ShowInTaskbar = false;
1767                         
1768                         c = new Control ();
1769
1770                         f.Controls.Add (c);
1771
1772                         Console.WriteLine ("f.Handle = {0}", f.Handle);
1773                         Console.WriteLine ("c.Handle = {0}", c.Handle);
1774
1775                         control_context = new ApplicationContext (f);
1776
1777                         Monitor.Enter (m);
1778                         Console.WriteLine ("pulsing");
1779                         Monitor.Pulse (m);
1780                         Monitor.Exit (m);
1781                         Console.WriteLine ("control thread running");
1782                         Application.Run (control_context);
1783                         c.Dispose ();
1784                 }
1785
1786                 [Test]
1787                 public void InvokeTest ()
1788                 {
1789                         m = new object ();
1790
1791                         control_t = new Thread(new ThreadStart(CreateControl));
1792
1793                         Monitor.Enter (m);
1794
1795                         control_t.Start ();
1796
1797                         Console.WriteLine ("waiting on monitor");
1798                         Monitor.Wait (m);
1799
1800                         Console.WriteLine ("making async call");
1801
1802                         IAsyncResult result;
1803                         result = c.BeginInvoke (new TestDelegate (delegate_call));
1804                         c.EndInvoke (result);
1805
1806                         Assert.AreEqual (true, delegateCalled, "Invoke1");
1807                 }
1808
1809                 public void delegate_call () {
1810                         /* invoked on control_context's thread */
1811                         delegateCalled = true;
1812                         f.Dispose ();
1813                         Application.Exit ();
1814                 }
1815                 
1816         }
1817
1818         [TestFixture]
1819         public class ControlWMTest
1820         {
1821                 [Test]
1822                 public void WM_PARENTNOTIFY_Test ()
1823                 {
1824                         WMTester tester;
1825                         Control child;
1826                         int child_handle;
1827                         
1828                         tester = new WMTester ();
1829                         child = new Control ();
1830                         tester.Controls.Add (child);
1831                         
1832                         tester.Visible = true;
1833                         child.Visible = true;
1834
1835                         child_handle = child.Handle.ToInt32 ();
1836
1837                         ArrayList msgs;
1838                         Message m1;
1839                                 
1840                         msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
1841                         
1842                         Assert.AreEqual (1, msgs.Count, "#1");
1843                         
1844                         m1 = (Message) msgs [0];
1845                         Assert.AreEqual (WndMsg.WM_CREATE, ((WndMsg) LowOrder (m1.WParam)),  "#2");
1846                         //Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam),  "#3");
1847                         Assert.AreEqual (child_handle, m1.LParam.ToInt32 (),  "#4");
1848
1849                         child.Dispose ();
1850
1851                         msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
1852                         Assert.AreEqual (2, msgs.Count, "#5");
1853                         m1 = (Message) msgs [1];
1854
1855                         Assert.AreEqual (WndMsg.WM_DESTROY, ((WndMsg) LowOrder (m1.WParam)),  "#6");
1856                         //Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam),  "#7");
1857                         Assert.AreEqual (child_handle, m1.LParam.ToInt32 (),  "#8");
1858
1859                         tester.Dispose ();
1860                 }
1861
1862                 internal static int LowOrder (int param) 
1863                 {
1864                         return ((int)(short)(param & 0xffff));
1865                 }
1866
1867                 internal static int HighOrder (int param) 
1868                 {
1869                         return ((int)(short)(param >> 16));
1870                 }
1871
1872                 internal static int LowOrder (IntPtr param) 
1873                 {
1874                         return ((int)(short)(param.ToInt32 () & 0xffff));
1875                 }
1876
1877                 internal static int HighOrder (IntPtr param) 
1878                 {
1879                         return ((int)(short)(param.ToInt32 () >> 16));
1880                 }
1881
1882                 internal class WMTester : Form
1883                 {
1884                         internal ArrayList Messages = new ArrayList ();
1885                         
1886                         internal bool Contains (WndMsg msg)
1887                         {
1888                                 return Contains (msg, Messages);
1889                         }
1890
1891                         internal bool Contains (WndMsg msg, ArrayList list)
1892                         {
1893                                 foreach (Message m in Messages) 
1894                                 {
1895                                         if (m.Msg == (int) msg)
1896                                                 return true;
1897                                 }
1898                                 return false;
1899                         }
1900
1901                         internal ArrayList Find (WndMsg msg)
1902                         {
1903                                 ArrayList result = new ArrayList ();
1904
1905                                 foreach (Message m in Messages)
1906                                 {
1907                                         if (m.Msg == (int) msg)
1908                                                 result.Add (m);
1909                                 }
1910                                 return result;
1911                         }
1912
1913                         protected override void WndProc(ref Message m)
1914                         {
1915                                 Console.WriteLine ("WndProc: " + m.ToString ());
1916                                 Messages.Add (m);
1917                                 base.WndProc (ref m);
1918                         }
1919                 }
1920         }
1921
1922 #if NET_2_0
1923         [TestFixture]
1924         public class ControlLayoutTest
1925         {
1926                 [Test]
1927                 public void SetUp ()
1928                 {
1929                         _layoutCount = 0;
1930                 }
1931
1932                 [Test] // bug #80456
1933                 public void LayoutTest ()
1934                 {
1935                         MockLayoutEngine layoutEngine = new MockLayoutEngine ();
1936                         MockControl c = new MockControl (layoutEngine);
1937                         c.Layout += new LayoutEventHandler (LayoutEvent);
1938                         Assert.IsFalse (layoutEngine.LayoutInvoked, "#A1");
1939                         Assert.AreEqual (0, _layoutCount, "#A2");
1940                         c.PerformLayout ();
1941                         Assert.IsTrue (layoutEngine.LayoutInvoked, "#A3");
1942                         Assert.AreEqual (1, _layoutCount, "#A4");
1943
1944                         layoutEngine.Reset ();
1945                         c.OverrideOnLayout = true;
1946                         Assert.IsFalse (layoutEngine.LayoutInvoked, "#B1");
1947                         c.PerformLayout ();
1948                         Assert.IsFalse (layoutEngine.LayoutInvoked, "#B2");
1949                         Assert.AreEqual (1, _layoutCount, "#B3");
1950                 }
1951
1952                 void LayoutEvent (object sender, LayoutEventArgs e)
1953                 {
1954                         _layoutCount++;
1955                 }
1956
1957                 private int _layoutCount;
1958
1959                 class MockControl : Control
1960                 {
1961                         public MockControl (LayoutEngine layoutEngine)
1962                         {
1963                                 _layoutEngine = layoutEngine;
1964                         }
1965
1966                         public bool OverrideOnLayout
1967                         {
1968                                 get { return _overrideOnLayout; }
1969                                 set { _overrideOnLayout = value; }
1970                         }
1971
1972                         protected override void OnLayout (LayoutEventArgs levent)
1973                         {
1974                                 if (!OverrideOnLayout)
1975                                         base.OnLayout (levent);
1976                         }
1977
1978                         public override LayoutEngine LayoutEngine {
1979                                 get {
1980                                         if (_layoutEngine == null)
1981                                                 return base.LayoutEngine;
1982                                         return _layoutEngine;
1983                                 }
1984                         }
1985
1986                         private bool _overrideOnLayout;
1987                         private LayoutEngine _layoutEngine;
1988                 }
1989
1990                 class MockLayoutEngine : LayoutEngine
1991                 {
1992                         public bool LayoutInvoked {
1993                                 get { return _layoutInvoked; }
1994                         }
1995
1996                         public void Reset ()
1997                         {
1998                                 _layoutInvoked = false;
1999                         }
2000
2001                         public override bool Layout (object container, LayoutEventArgs args)
2002                         {
2003                                 _layoutInvoked = true;
2004                                 return true;
2005                         }
2006
2007                         private bool _layoutInvoked;
2008                 }
2009         }
2010 #endif
2011 }