2 // Copyright (c) 2005 Novell, Inc.
5 // Ritvik Mayank (mritvik@novell.com)
9 using System
.Collections
;
10 using InvalidEnumArgumentException
= System
.ComponentModel
.InvalidEnumArgumentException
;
12 using System
.Reflection
;
13 using System
.Runtime
.Remoting
;
14 using System
.Threading
;
15 using System
.Windows
.Forms
;
17 using System
.Windows
.Forms
.Layout
;
20 using NUnit
.Framework
;
22 namespace MonoTests
.System
.Windows
.Forms
25 public class ControlTest
27 public class ControlStylesTester
: Control
{
28 private WindowStyles style
;
29 private WindowStyles ex_style
;
30 private bool or_styles
;
32 public ControlStylesTester (WindowStyles Style
, WindowStyles ExStyle
, bool OrStyles
)
39 protected override CreateParams CreateParams
{
41 CreateParams result
= base.CreateParams
;
43 result
.Style
|= (int) style
;
44 result
.ExStyle
|= (int) ex_style
;
46 result
.Style
= (int) style
;
47 result
.ExStyle
= (int) ex_style
;
55 public void ControlSizeTest ()
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");
64 public void CaptureTest ()
66 Form frm
= new Form ();
67 ControlOverrideLogger log
= new ControlOverrideLogger ();
68 frm
.Controls
.Add (log
);
72 log
.BackColor
= Color
.Blue
;
73 log
.Size
= new Size (100, 100);
76 Application
.DoEvents ();
79 Assert
.IsTrue (log
.Log
.ToString ().IndexOf ("OnMouseCaptureChanged") > -1, "#01");
81 log
= new ControlOverrideLogger ();
84 Assert
.IsTrue (log
.Log
.ToString ().IndexOf ("OnMouseCaptureChanged") > -1, "#02");
86 log
= new ControlOverrideLogger ();
88 Assert
.IsTrue (log
.IsHandleCreated
, "#03");
89 Assert
.IsTrue (log
.Log
.ToString ().IndexOf ("OnMouseCaptureChanged") == -1, "#04");
91 log
= new ControlOverrideLogger ();
93 Assert
.IsFalse (log
.IsHandleCreated
, "#05");
94 Assert
.IsTrue (log
.Log
.ToString ().IndexOf ("OnMouseCaptureChanged") == -1, "#06");
98 public class OnPaintTester
: Form
102 ArrayList list
= new ArrayList ();
103 public bool Recursive
;
104 public bool TestRefresh
;
105 public bool TestInvalidate
;
106 public bool TestUpdate
;
108 public new bool DoubleBuffered
{
110 return base.DoubleBuffered
;
113 base.DoubleBuffered
= value;
117 protected override void OnPaint (PaintEventArgs pevent
)
119 Assert
.IsFalse (list
.Contains (pevent
.Graphics
), "OnPaintTester.OnPaint: Got the same Graphics twice");
120 list
.Add (pevent
.Graphics
);
124 Recursive
= counter
> 0 || Recursive
;
129 else if (TestInvalidate
)
135 base.OnPaint (pevent
);
139 public new void Show ()
142 Application
.DoEvents ();
147 public void ControlCollectionTest ()
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
;
158 [ExpectedException (typeof (ArgumentException
))]
159 public void ControlCollectionExceptionTest ()
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;
170 [Category ("NotWorking")]
171 public void OnPaintTest ()
173 using (OnPaintTester t
= new OnPaintTester ()) {
174 t
.TestRefresh
= true;
176 Assert
.IsTrue (t
.Recursive
, "#1");
179 using (OnPaintTester t
= new OnPaintTester ()) {
182 Assert
.IsFalse (t
.Recursive
, "#2");
185 using (OnPaintTester t
= new OnPaintTester ()) {
186 t
.TestInvalidate
= true;
188 Assert
.IsFalse (t
.Recursive
, "#3");
193 [Category ("Interactive")]
194 public void OnPaintDoubleBufferedTest ()
196 using (OnPaintTester t
= new OnPaintTester ()) {
197 t
.DoubleBuffered
= true;
198 t
.TestRefresh
= true;
200 Assert
.IsTrue (t
.Recursive
, "#1");
203 using (OnPaintTester t
= new OnPaintTester ()) {
204 t
.DoubleBuffered
= true;
207 Assert
.IsFalse (t
.Recursive
, "#2");
210 using (OnPaintTester t
= new OnPaintTester ()) {
211 t
.DoubleBuffered
= true;
212 t
.TestInvalidate
= true;
214 Assert
.IsFalse (t
.Recursive
, "#3");
218 public class PaintEventForm
: Form
220 public ArrayList overrides
= new ArrayList ();
221 public ArrayList events
= new ArrayList ();
223 public PaintEventForm ()
225 Paint
+= new PaintEventHandler (DoubleBufferEventForm_Paint
);
227 public bool GetControlStyle (ControlStyles style
)
229 return base.GetStyle (style
);
232 public void SetControlStyle (ControlStyles style
, bool value)
234 base.SetStyle (style
, value);
237 void DoubleBufferEventForm_Paint (object sender
, PaintEventArgs e
)
242 protected override void OnPaintBackground (PaintEventArgs e
)
244 base.OnPaintBackground (e
);
245 overrides
.Add("OnPaintBackground");
248 protected override void OnPaint (PaintEventArgs pevent
)
250 base.OnPaint (pevent
);
251 overrides
.Add("OnPaint");
256 public void EventStyleTest ()
259 using (PaintEventForm f
= new PaintEventForm ()) {
261 f
.SetControlStyle (ControlStyles
.OptimizedDoubleBuffer
, true);
263 Assert
.IsTrue (f
.overrides
.Contains ("OnPaintBackground"), "#A1");
264 Assert
.IsTrue (f
.overrides
.Contains ("OnPaint"), "#A2");
265 Assert
.IsTrue (f
.events
.Contains ("Paint"), "#A3");
268 using (PaintEventForm f
= new PaintEventForm ()) {
270 f
.SetControlStyle (ControlStyles
.DoubleBuffer
, true);
272 Assert
.IsTrue (f
.overrides
.Contains ("OnPaintBackground"), "#B1");
273 Assert
.IsTrue (f
.overrides
.Contains ("OnPaint"), "#B2");
274 Assert
.IsTrue (f
.events
.Contains ("Paint"), "#B3");
277 using (PaintEventForm f
= new PaintEventForm ()) {
279 f
.SetControlStyle (ControlStyles
.AllPaintingInWmPaint
, true);
281 Assert
.IsTrue (f
.overrides
.Contains ("OnPaintBackground"), "#C1");
282 Assert
.IsTrue (f
.overrides
.Contains ("OnPaint"), "#C2");
283 Assert
.IsTrue (f
.events
.Contains ("Paint"), "#C3");
286 using (PaintEventForm f
= new PaintEventForm ()) {
288 f
.SetControlStyle (ControlStyles
.UserPaint
, true);
290 Assert
.IsTrue (f
.overrides
.Contains ("OnPaintBackground"), "#D1");
291 Assert
.IsTrue (f
.overrides
.Contains ("OnPaint"), "#D2");
292 Assert
.IsTrue (f
.events
.Contains ("Paint"), "#D3");
295 using (PaintEventForm f
= new PaintEventForm ()) {
297 f
.SetControlStyle (ControlStyles
.UserPaint
| ControlStyles
.AllPaintingInWmPaint
, true);
299 Assert
.IsTrue (f
.overrides
.Contains ("OnPaintBackground"), "#E1");
300 Assert
.IsTrue (f
.overrides
.Contains ("OnPaint"), "#E2");
301 Assert
.IsTrue (f
.events
.Contains ("Paint"), "#E3");
304 using (PaintEventForm f
= new PaintEventForm ()) {
306 f
.SetControlStyle (ControlStyles
.UserPaint
| ControlStyles
.DoubleBuffer
, true);
308 Assert
.IsTrue (f
.overrides
.Contains ("OnPaintBackground"), "#F1");
309 Assert
.IsTrue (f
.overrides
.Contains ("OnPaint"), "#F2");
310 Assert
.IsTrue (f
.events
.Contains ("Paint"), "#F3");
313 using (PaintEventForm f
= new PaintEventForm ()) {
315 f
.SetControlStyle (ControlStyles
.DoubleBuffer
| ControlStyles
.AllPaintingInWmPaint
, true);
317 Assert
.IsTrue (f
.overrides
.Contains ("OnPaintBackground"), "#G1");
318 Assert
.IsTrue (f
.overrides
.Contains ("OnPaint"), "#G2");
319 Assert
.IsTrue (f
.events
.Contains ("Paint"), "#G3");
322 using (PaintEventForm f
= new PaintEventForm ()) {
324 f
.SetControlStyle (ControlStyles
.UserPaint
| ControlStyles
.AllPaintingInWmPaint
| ControlStyles
.DoubleBuffer
, true);
326 Assert
.IsTrue (f
.overrides
.Contains ("OnPaintBackground"), "#H1");
327 Assert
.IsTrue (f
.overrides
.Contains ("OnPaint"), "#H2");
328 Assert
.IsTrue (f
.events
.Contains ("Paint"), "#H3");
332 public class DoubleBufferedForm
: Form
336 public DoubleBufferedForm ()
338 this.DoubleBuffered
= true;
341 protected override void OnPaint (PaintEventArgs e
)
343 if (failed
|| painted
)
348 e
.Graphics
.DrawString (Size
.ToString (), Font
, Brushes
.AliceBlue
, new Point (2, 2));
349 } catch (Exception exception
) {
350 Console
.WriteLine (exception
.StackTrace
);
356 public class DoubleBufferControl
: Control
358 public bool IsDoubleBuffered
360 get { return base.DoubleBuffered; }
361 set { base.DoubleBuffered = value; }
364 public bool GetControlStyle (ControlStyles style
)
366 return base.GetStyle (style
);
369 public void SetControlStyle (ControlStyles style
, bool value)
371 base.SetStyle (style
, value);
376 public void DoubleBufferTest ()
378 DoubleBufferedForm f
= new DoubleBufferedForm ();
382 Assert
.IsFalse (f
.failed
, "#01");
383 Assert
.IsTrue (f
.painted
, "The control was never painted, so please check the test");
387 public void DoubleBufferedTest ()
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");
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");
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");
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");
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");
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");
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");
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");
452 public void DoubleBufferedStyleTest ()
454 DoubleBufferControl c
= new DoubleBufferControl ();
455 TestControlStyle
.CheckStyles (c
, "#A1", ControlStyles
.UserPaint
, ControlStyles
.StandardClick
, ControlStyles
.Selectable
, ControlStyles
.StandardDoubleClick
, ControlStyles
.AllPaintingInWmPaint
, ControlStyles
.UseTextForAccessibility
);
457 c
.IsDoubleBuffered
= true;
458 TestControlStyle
.CheckStyles (c
, "#A2", ControlStyles
.UserPaint
, ControlStyles
.StandardClick
, ControlStyles
.Selectable
, ControlStyles
.StandardDoubleClick
, ControlStyles
.AllPaintingInWmPaint
, ControlStyles
.UseTextForAccessibility
, ControlStyles
.OptimizedDoubleBuffer
);
460 c
.IsDoubleBuffered
= false;
461 TestControlStyle
.CheckStyles (c
, "#A3", ControlStyles
.UserPaint
, ControlStyles
.StandardClick
, ControlStyles
.Selectable
, ControlStyles
.StandardDoubleClick
, ControlStyles
.AllPaintingInWmPaint
, ControlStyles
.UseTextForAccessibility
);
463 c
= new DoubleBufferControl ();
464 foreach (ControlStyles style
in Enum
.GetValues (typeof(ControlStyles
))) {
465 c
.SetControlStyle (style
, false);
468 TestControlStyle
.CheckStyles (c
, "#B1");
470 c
.IsDoubleBuffered
= true;
471 TestControlStyle
.CheckStyles (c
, "#B2", ControlStyles
.OptimizedDoubleBuffer
, ControlStyles
.AllPaintingInWmPaint
);
473 c
.IsDoubleBuffered
= false;
474 TestControlStyle
.CheckStyles (c
, "#B3", ControlStyles
.AllPaintingInWmPaint
);
480 public static void TestAccessibility(Control c
, string Default
, string Description
, string Name
, AccessibleRole Role
)
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");
489 public static string TestControl(Control container
, Control start
, bool forward
) {
492 ctl
= container
.GetNextControl(start
, forward
);
503 public void CreatedTest ()
505 Control c
= new Control ();
506 Assert
.IsFalse (c
.Created
, "A1");
510 [Category ("NotWorking")]
511 public void CreatedAccessibilityTest ()
513 Control c
= new Control ();
514 Assert
.IsFalse (c
.Created
, "A1");
516 Helper
.TestAccessibility(c
, null, null, null, AccessibleRole
.Default
);
518 Assert
.IsTrue (c
.Created
, "A2");
522 Assert
.IsFalse (c
.Created
, "A3");
526 [Category ("NotWorking")]
527 public void BoundsTest ()
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");
535 Assert
.AreEqual (((IWin32Window
)c
).Handle
, c
.Handle
, "A5");
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 */
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");
547 [Ignore ("Depends on specific DPI")]
548 public void FontHeightTest ()
550 MockControl c
= new MockControl ();
551 Assert
.AreEqual (13, c
.font_height
);
555 public void FontTest ()
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");
568 Assert
.IsTrue (c
.Font
.IsSystemFont
, "#A10");
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");
582 Assert
.AreEqual (false, c
.Font
.IsSystemFont
, "#B10");
587 [Category ("NotWorking")] // on Unix mapping is done to Bitstream Vera Sans
588 public void FontTest_Names ()
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");
596 public void PubPropTest()
598 Control c
= new Control();
600 Assert
.IsFalse (c
.AllowDrop
, "A1");
601 Assert
.AreEqual(AnchorStyles
.Top
| AnchorStyles
.Left
, c
.Anchor
, "A2");
603 Assert
.AreEqual ("Control", c
.BackColor
.Name
, "B1");
604 Assert
.IsNull (c
.BackgroundImage
, "B2");
605 Assert
.IsNull (c
.BindingContext
, "B3");
607 Assert
.AreEqual (ImageLayout
.Tile
, c
.BackgroundImageLayout
, "B4");
610 Assert
.IsFalse (c
.CanFocus
, "C1");
611 Assert
.IsTrue (c
.CanSelect
, "C2");
612 Assert
.IsFalse (c
.Capture
, "C3");
613 Assert
.IsTrue (c
.CausesValidation
, "C4");
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");
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");
631 Assert
.IsTrue (c
.Enabled
, "E1");
633 Assert
.IsFalse (c
.Focused
, "F1");
634 Assert
.AreEqual (FontStyle
.Regular
, c
.Font
.Style
, "F2");
635 Assert
.AreEqual (SystemColors
.ControlText
, c
.ForeColor
, "F3");
637 Assert
.IsFalse (c
.HasChildren
, "H2");
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");
645 Assert
.AreEqual(Point
.Empty
, c
.Location
, "L2");
648 Assert
.IsTrue(c
.MaximumSize
.IsEmpty
);
649 Assert
.IsTrue(c
.MinimumSize
.IsEmpty
);
651 Assert
.AreEqual (Keys
.None
, Control
.ModifierKeys
, "M1");
652 Assert
.IsFalse (Control
.MousePosition
.IsEmpty
, "M2");
653 Assert
.AreEqual (MouseButtons
.None
, Control
.MouseButtons
, "M3");
655 Assert
.AreEqual("", c
.Name
, "N1");
656 c
.Name
= "Control Name";
657 Assert
.AreEqual("Control Name", c
.Name
, "N2");
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");
665 Assert
.IsFalse (c
.RecreatingHandle
, "R1");
666 Assert
.IsNull (c
.Region
, "R2");
667 Assert
.AreEqual (RightToLeft
.No
, c
.RightToLeft
, "R4");
669 Assert
.IsNull (c
.Site
, "S1");
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");
676 Assert
.IsTrue (c
.Visible
, "V1");
680 public void SizeChangeTest ()
682 Form f
= new Form ();
683 Control c
= new Control ();
686 c
.Resize
+= new EventHandler(SizeChangedTest_ResizeHandler
);
689 Assert
.AreEqual (true, (bool) c
.Tag
, "#1");
693 private void SizeChangedTest_ResizeHandler (object sender
, EventArgs e
)
695 ((Control
) sender
).Tag
= false;
699 public void NegativeHeightTest ()
701 Control c
= new Control ();
702 IntPtr handle
= c
.Handle
;
703 c
.Resize
+= new EventHandler(NegativeHeightTest_ResizeHandler
);
707 Assert
.AreEqual (0, (int) c
.Tag
, "#1");
709 Assert
.AreEqual (handle
, handle
, "Removes warning.");
712 private void NegativeHeightTest_ResizeHandler (object sender
, EventArgs e
)
714 Control c
= (Control
) sender
;
719 public void TopLevelControlTest () {
720 Control c
= new Control ();
722 Assert
.AreEqual(null, c
.TopLevelControl
, "T1");
724 Panel p
= new Panel ();
728 Assert
.AreEqual(null, c
.TopLevelControl
, "T2");
730 Form f
= new Form ();
731 f
.ShowInTaskbar
= false;
735 Assert
.AreEqual (f
, c
.TopLevelControl
, "T3");
736 Assert
.AreEqual (f
, f
.TopLevelControl
, "T4");
740 public void RelationTest() {
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");
752 Assert
.AreEqual(true , c2
.Visible
, "Rel4");
753 Assert
.AreEqual(true, c1
.Contains(c2
) , "Rel5");
755 c1
.Anchor
= AnchorStyles
.Top
;
757 c1
.Anchor
= AnchorStyles
.Left
;
759 Assert
.AreEqual(AnchorStyles
.Left
, c1
.Anchor
, "Rel6");
761 c1
.SetBounds(10, 20, 30, 40) ;
762 Assert
.AreEqual(new Rectangle(10, 20, 30, 40), c1
.Bounds
, "Rel7");
764 Assert
.AreEqual(c1
, c2
.Parent
, "Rel8");
768 public void AnchorDockTest ()
770 Control c
= new Control ();
772 Assert
.AreEqual (DockStyle
.None
, c
.Dock
, "1");
773 Assert
.AreEqual (AnchorStyles
.Top
| AnchorStyles
.Left
, c
.Anchor
, "2");
775 c
.Dock
= DockStyle
.Top
;
776 Assert
.AreEqual (DockStyle
.Top
, c
.Dock
, "3");
777 Assert
.AreEqual (AnchorStyles
.Top
| AnchorStyles
.Left
, c
.Anchor
, "4");
779 c
.Anchor
= AnchorStyles
.Top
;
780 Assert
.AreEqual (DockStyle
.None
, c
.Dock
, "5");
781 Assert
.AreEqual (AnchorStyles
.Top
, c
.Anchor
, "6");
785 [Category ("NotWorking")]
786 public void TabOrder()
791 Label label1
= new Label(); // To test non-tabstop items as well
792 Label label2
= new Label();
794 GroupBox group1
= new GroupBox();
795 GroupBox group2
= new GroupBox();
796 GroupBox group3
= new GroupBox();
798 TextBox text1
= new TextBox();
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();
814 form
.ShowInTaskbar
= false;
816 form
.ClientSize
= new Size (520, 520);
817 Assert
.AreEqual(new Size(520, 520), form
.ClientSize
, "Tab1");
819 form
.Text
= "SWF Taborder Test App Form";
820 Assert
.AreEqual("SWF Taborder Test App Form", form
.Text
, "Tab2");
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
);
827 label2
.Location
= new Point(200, 10);
828 label2
.Text
= "Label2";
829 form
.Controls
.Add(label2
);
831 group1
.Text
= "Group1";
832 group2
.Text
= "Group2";
833 group3
.Text
= "Group3";
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");
840 group1
.Location
= new Point(10, 40);
841 group2
.Location
= new Point(220, 40);
842 group3
.Location
= new Point(10, 210);
844 group1
.TabIndex
= 30;
845 Assert
.AreEqual(30, group1
.TabIndex
, "Tab5");
846 group1
.TabStop
= true;
848 // Don't assign, test automatic assignment
849 //group2.TabIndex = 0;
850 group2
.TabStop
= true;
851 Assert
.AreEqual(0, group2
.TabIndex
, "Tab6");
853 group3
.TabIndex
= 35;
854 group3
.TabStop
= true;
856 // Test default tab index
857 Assert
.AreEqual(0, radio11
.TabIndex
, "Tab7");
859 text1
.Text
= "Edit Control";
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]";
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]";
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]";
876 // We don't assign TabIndex for radio1X; test automatic assignment
877 text1
.TabStop
= true;
878 radio11
.TabStop
= true;
880 radio21
.TabIndex
= 4;
881 radio22
.TabIndex
= 3;
882 radio23
.TabIndex
= 2;
883 radio24
.TabIndex
= 1;
884 radio24
.TabStop
= true;
886 radio31
.TabIndex
= 11;
887 radio31
.TabStop
= true;
888 radio32
.TabIndex
= 13;
889 radio33
.TabIndex
= 12;
890 radio34
.TabIndex
= 14;
892 text1
.Location
= new Point(10, 100);
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);
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);
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);
909 text1
.Size
= new Size(150, text1
.PreferredHeight
);
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);
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);
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);
926 group1
.Controls
.Add(text1
);
928 group1
.Controls
.Add(radio11
);
929 group1
.Controls
.Add(radio12
);
930 group1
.Controls
.Add(radio13
);
931 group1
.Controls
.Add(radio14
);
933 group2
.Controls
.Add(radio21
);
934 group2
.Controls
.Add(radio22
);
935 group2
.Controls
.Add(radio23
);
936 group2
.Controls
.Add(radio24
);
938 group3
.Controls
.Add(radio31
);
939 group3
.Controls
.Add(radio32
);
940 group3
.Controls
.Add(radio33
);
941 group3
.Controls
.Add(radio34
);
943 form
.Controls
.Add(group1
);
944 form
.Controls
.Add(group2
);
945 group2
.Controls
.Add(group3
);
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");
951 // Does the taborder of containers and non-selectable things change behaviour?
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");
970 Assert
.AreEqual(null, Helper
.TestControl(radio11
, radio21
, true), "Tab20");
971 Assert
.AreEqual(text1
.Text
, Helper
.TestControl(group1
, radio21
, true), "Tab21");
973 Assert
.AreEqual(radio14
.Text
, Helper
.TestControl(form
, label2
, false), "Tab22");
974 Assert
.AreEqual(radio21
.Text
, Helper
.TestControl(group2
, group3
, false), "Tab23");
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");
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");
986 Assert
.AreEqual(null, Helper
.TestControl(label1
, label1
, false), "Tab31");
987 Assert
.AreEqual(null, Helper
.TestControl(radio11
, radio21
, false), "Tab32");
992 public void ScaleTest()
994 Control r1
= new Control();
999 Assert
.AreEqual(80, r1
.Width
, "Scale1");
1000 Assert
.AreEqual(40, r1
.Height
, "Scale2");
1004 public void TextTest()
1006 Control r1
= new Control();
1008 Assert
.AreEqual("Hi" , r1
.Text
, "Text1");
1011 Assert
.AreEqual("" , r1
.Text
, "Text2");
1015 public void PubMethodTest7()
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();
1029 //Assert.AreEqual(FontFamily.GenericSansSerif , r1.Font , "#83");
1030 r1
.Cursor
= Cursors
.Hand
;
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
;
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");
1048 public void ScreenClientCoords()
1059 p1
= new Point (10,10);
1060 p2
= l
.PointToScreen(p1
);
1061 p3
= l
.PointToClient(p2
);
1063 Assert
.AreEqual (p1
, p3
, "SC1");
1067 public void ContainsTest ()
1069 Control t
= new Control ();
1070 Control s
= new Control ();
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");
1081 public void IsHandleCreated_NotVisible ()
1083 Control c
= new Control ();
1086 Form form
= new Form ();
1087 form
.ShowInTaskbar
= false;
1088 form
.Controls
.Add (c
);
1091 Assert
.IsFalse (c
.IsHandleCreated
, "#1");
1093 Assert
.IsTrue (c
.IsHandleCreated
, "#2");
1095 Assert
.IsTrue (c
.IsHandleCreated
, "#3");
1098 class OnCreateControlTest
: Control
{
1099 public bool reached
= false;
1100 protected override void OnCreateControl () {
1106 public void CreateControlVisibleTest ()
1108 OnCreateControlTest test
= new OnCreateControlTest ();
1109 test
.Visible
= false;
1110 Assert
.IsFalse (test
.IsHandleCreated
, "0");
1111 Assert
.IsFalse (test
.Visible
, "1");
1112 test
.Visible
= true;
1113 Assert
.IsTrue (test
.Visible
, "2");
1114 Assert
.IsTrue (test
.reached
, "3");
1119 public void CreateGraphicsTest ()
1125 Control c
= new Control ();
1126 c
.SetBounds (0,0, 20, 20);
1127 g
= c
.CreateGraphics ();
1128 Assert
.IsNotNull (g
, "Graph1");
1137 bool delegateCalled
= false;
1138 public delegate void TestDelegate ();
1140 public void delegate_call () {
1141 delegateCalled
= true;
1143 TestHelper
.RemoveWarning (delegateCalled
);
1147 [ExpectedException(typeof(InvalidOperationException
))]
1148 public void InvokeException1 () {
1149 Control c
= new Control ();
1150 IAsyncResult result
;
1152 result
= c
.BeginInvoke (new TestDelegate (delegate_call
));
1153 c
.EndInvoke (result
);
1157 public void FindFormTest () {
1158 Form f
= new Form ();
1160 f
.ShowInTaskbar
= false;
1165 f
.Controls
.Add (c
= new Control ());
1166 Assert
.AreEqual (f
.Name
, c
.FindForm ().Name
, "Find1");
1168 f
.Controls
.Remove (c
);
1170 GroupBox g
= new GroupBox ();
1175 Assert
.AreEqual (f
.Name
, f
.FindForm ().Name
, "Find2");
1177 g
.Controls
.Remove (c
);
1178 Assert
.IsNull(c
.FindForm (), "Find3");
1189 public void FocusTest ()
1192 Button c
= null, d
= null;
1196 f
.ShowInTaskbar
= false;
1206 Assert
.IsTrue (c
.CanFocus
, "Focus1");
1207 Assert
.IsFalse (c
.Focused
, "Focus2");
1209 Assert
.IsTrue (c
.Focused
, "Focus3");
1211 Assert
.IsFalse (d
.Focused
, "Focus4");
1215 Assert
.IsTrue (d
.Focused
, "Focus5");
1216 Assert
.IsFalse (c
.Focused
, "Focus6");
1219 Assert
.IsFalse (c
.Focused
, "Focus7");
1231 public void FromHandleTest ()
1237 c1
= new Control ();
1238 c2
= new Control ();
1242 c1
.Controls
.Add(c2
);
1245 Assert
.AreEqual (c1
.Name
, Control
.FromHandle (c1
.Handle
).Name
, "Handle1");
1246 Assert
.IsNull (Control
.FromHandle (IntPtr
.Zero
), "Handle2");
1249 Assert
.AreEqual (c1
.Name
, Control
.FromChildHandle (c1
.Handle
).Name
, "Handle3");
1250 Assert
.IsNull (Control
.FromChildHandle (IntPtr
.Zero
), "Handle4");
1263 public void GetChildAtPointTest ()
1265 Control c
= null, d
= null, e
= null;
1270 c
.SetBounds (0, 0, 100, 100);
1274 d
.SetBounds (10, 10, 40, 40);
1279 e
.SetBounds (55, 55, 10, 10);
1281 Control l
= c
.GetChildAtPoint (new Point (15, 15));
1282 Assert
.AreEqual (d
.Name
, l
.Name
, "Child1");
1283 Assert
.IsFalse (e
.Name
== l
.Name
, "Child2");
1285 l
= c
.GetChildAtPoint (new Point (57, 57));
1286 Assert
.IsNull (l
, "Child3");
1288 l
= c
.GetChildAtPoint (new Point (10, 10));
1289 Assert
.AreEqual (d
.Name
, l
.Name
, "Child4");
1291 // GetChildAtPointSkip is not implemented and the following test is breaking for Net_2_0 profile
1293 // c.Controls.Add (e);
1294 // e.Visible = false;
1295 // l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
1296 // Assert.IsNull (l, "Child5");
1298 // e.Visible = true;
1299 // l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
1300 // Assert.AreSame (e.Name, l.Name, "Child6");
1301 // #endif // NET_2_0
1311 public void ResetFontTest ()
1313 Control c
= new Control ();
1314 c
.Font
= new Font (c
.Font
.FontFamily
, 3, FontStyle
.Italic
);
1317 Assert
.IsFalse (c
.Font
.Bold
, "#1");
1318 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#2");
1319 Assert
.IsFalse (c
.Font
.Italic
, "#3");
1320 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#4");
1321 Assert
.AreEqual (8.25, c
.Font
.Size
, "#5");
1322 Assert
.AreEqual (8.25, c
.Font
.SizeInPoints
, "#6");
1323 Assert
.IsFalse (c
.Font
.Strikeout
, "#7");
1324 Assert
.IsFalse (c
.Font
.Underline
, "#8");
1325 Assert
.AreEqual (GraphicsUnit
.Point
, c
.Font
.Unit
, "#9");
1327 Assert
.AreEqual (true, c
.Font
.IsSystemFont
, "#10");
1331 public class LayoutTestControl
: Control
{
1332 public int LayoutCount
;
1334 public LayoutTestControl () : base() {
1338 protected override void OnLayout(LayoutEventArgs levent
) {
1340 base.OnLayout (levent
);
1345 public void LayoutTest() {
1346 LayoutTestControl c
;
1348 c
= new LayoutTestControl();
1355 c
.ResumeLayout(true);
1357 c
.ResumeLayout(true);
1359 c
.ResumeLayout(true);
1361 c
.ResumeLayout(true);
1363 c
.ResumeLayout(true);
1365 c
.ResumeLayout(true);
1367 c
.ResumeLayout(true);
1372 Assert
.AreEqual(5, c
.LayoutCount
, "Layout Suspend/Resume locking does not bottom out at 0");
1376 [ExpectedException(typeof(ArgumentException
))]
1377 public void TransparentBackgroundTest1() {
1381 c
.BackColor
= Color
.Transparent
;
1385 public void TransparentBackgroundTest2() {
1389 c
.BackColor
= Color
.Transparent
;
1390 Assert
.AreEqual(Color
.Transparent
, c
.BackColor
, "Transparent background not set");
1394 public void TransparentBackgroundTest3() {
1398 c
.BackColor
= Color
.Empty
;
1399 Assert
.AreEqual(Control
.DefaultBackColor
, c
.BackColor
, "Setting empty color failed");
1403 public void Dock_Value_Invalid ()
1405 Control c
= new Control ();
1407 c
.Dock
= (DockStyle
) 666;
1409 } catch (InvalidEnumArgumentException ex
) {
1410 Assert
.AreEqual (typeof (InvalidEnumArgumentException
), ex
.GetType (), "#2");
1411 Assert
.IsNotNull (ex
.Message
, "#3");
1412 Assert
.IsNotNull (ex
.ParamName
, "#4");
1413 Assert
.AreEqual ("value", ex
.ParamName
, "#5");
1414 Assert
.IsNull (ex
.InnerException
, "#6");
1419 public void EnabledTest1() {
1424 grandma
= new Control();
1425 parent
= new Control();
1426 child
= new Control();
1428 grandma
.Controls
.Add(parent
);
1429 parent
.Controls
.Add(child
);
1430 grandma
.Enabled
= false;
1431 Assert
.AreEqual(grandma
.Enabled
, child
.Enabled
, "Child did not inherit disabled state");
1434 int EnabledCalledCount
= 0;
1435 private void EnabledTest2EnabledChanged(object sender
, EventArgs e
) {
1436 EnabledCalledCount
++;
1440 public void EnabledTest2() {
1441 // Check nesting of enabled calls
1442 // OnEnabled is not called for disabled child controls
1447 EnabledCalledCount
= 0;
1449 grandma
= new Control();
1450 parent
= new Control();
1451 child
= new Control();
1452 child
.EnabledChanged
+= new EventHandler(EnabledTest2EnabledChanged
);
1454 grandma
.Controls
.Add(parent
);
1455 parent
.Controls
.Add(child
);
1456 grandma
.Enabled
= false;
1458 Assert
.AreEqual(1, EnabledCalledCount
, "Child Enabled Event not properly fired");
1459 grandma
.Enabled
= true;
1460 Assert
.AreEqual(2, EnabledCalledCount
, "Child Enabled Event not properly fired");
1461 child
.Enabled
= false;
1462 grandma
.Enabled
= false;
1463 Assert
.AreEqual(3, EnabledCalledCount
, "Child Enabled Event not properly fired");
1467 public void ControlsRemoveNullTest ()
1469 Control c
= new Control ();
1470 c
.Controls
.Remove (null);
1474 public void ControlsAddNullTest ()
1476 Control c
= new Control ();
1477 c
.Controls
.Add (null);
1481 [ExpectedException (typeof (ArgumentNullException
))]
1482 public void ControlsSetChildIndexNullTest ()
1484 Control c
= new Control ();
1485 c
.Controls
.SetChildIndex (null, 1);
1489 [ExpectedException (typeof (ArgumentNullException
))]
1490 public void ControlsAddRangeNullTest ()
1492 Control c
= new Control ();
1493 c
.Controls
.AddRange (null);
1497 public void ControlsAddRangeNullElementTest ()
1499 Control c
= new Control ();
1500 Control
[] subcontrols
= new Control
[2];
1501 subcontrols
[0] = new Control ();
1502 subcontrols
[1] = null;
1504 c
.Controls
.AddRange (subcontrols
);
1508 public void RegionTest () {
1509 Form f
= new Form ();
1510 f
.ShowInTaskbar
= false;
1511 Control c
= new Control ();
1513 Assert
.IsNull (c
.Region
, "#A1");
1515 Assert
.IsNull (c
.Region
, "#A2");
1517 Assert
.IsNull (c
.Region
, "#A3");
1520 Region region
= new Region ();
1522 f
.ShowInTaskbar
= false;
1526 Assert
.IsNotNull (c
.Region
, "#B1");
1527 Assert
.AreSame (region
, c
.Region
, "#B2");
1530 Assert
.IsNull (c
.Region
, "#B3");
1535 [Test
] // bug #80280
1536 public void Validated_Multiple_Containers ()
1538 Form form
= new Form ();
1539 form
.ShowInTaskbar
= false;
1541 UserControl control1
= new UserControl();
1542 UserControl container1
= new UserControl();
1543 control1
.Tag
= true;
1544 control1
.Validated
+= new EventHandler (Control_ValidatedHandler
);
1545 container1
.Controls
.Add(control1
);
1546 form
.Controls
.Add (container1
);
1548 UserControl container2
= new UserControl();
1549 UserControl control2
= new UserControl();
1550 container2
.Controls
.Add(control2
);
1551 form
.Controls
.Add (container2
);
1553 Assert
.IsTrue ((bool) control1
.Tag
, "#1");
1555 Assert
.IsTrue ((bool) control1
.Tag
, "#2");
1557 Assert
.IsFalse ((bool) control1
.Tag
, "#3");
1562 private void Control_ValidatedHandler (object sender
, EventArgs e
)
1564 ((Control
) sender
).Tag
= false;
1568 [Test
] // bug #80621
1569 public void DontCallSizeFromClientSizeInConstructor ()
1571 SizeControl sc
= new SizeControl ();
1573 Assert
.AreEqual (0, sc
.size_from_client_size_count
, "A1");
1576 private class SizeControl
: Control
1578 public int size_from_client_size_count
= 0;
1580 protected override Size
SizeFromClientSize (Size clientSize
)
1582 size_from_client_size_count
++;
1583 return base.SizeFromClientSize (clientSize
);
1588 public class MockControl
: Control
1590 public int font_height
{
1591 get { return base.FontHeight; }
1592 set { base.FontHeight = value; }
1598 public class ControlSetTopLevelTest
1600 class ControlPoker
: Control
{
1601 public void DoSetTopLevel ()
1605 public bool DoGetTopLevel ()
1607 return GetTopLevel ();
1612 public void TestControl ()
1614 ControlPoker c
= new ControlPoker ();
1617 Assert
.IsTrue (c
.DoGetTopLevel (), "1");
1618 Assert
.IsFalse (c
.Visible
, "2");
1622 [ExpectedException (typeof (ArgumentException
))]
1623 public void TestChildControl ()
1625 Control c1
= new Control();
1626 ControlPoker c2
= new ControlPoker ();
1628 c1
.Controls
.Add (c2
);
1629 c2
.DoSetTopLevel ();
1633 [ExpectedException (typeof (ArgumentException
))]
1634 public void TestTopLevelAdd () {
1635 Form f
= new Form();
1636 Form f1
= new Form();
1640 [Category ("NotWorking")]
1642 public void TestForm ()
1644 Form f
= new Form ();
1645 Assert
.IsFalse (f
.Visible
, "3");
1647 Assert
.IsFalse (f
.Visible
, "4");
1652 public class ControlResizeLayoutTest
1654 class ControlPoker
: Control
{
1655 public void DoOnResize ()
1657 OnResize (EventArgs
.Empty
);
1662 string child_affected_property
;
1663 void ChildLayoutEvent (object sender
, LayoutEventArgs e
)
1666 child_affected_property
= e
.AffectedProperty
;
1670 string parent_affected_property
;
1671 void ParentLayoutEvent (object sender
, LayoutEventArgs e
)
1674 parent_affected_property
= e
.AffectedProperty
;
1676 TestHelper
.RemoveWarning (parent_affected_property
);
1682 Panel p
= new Panel ();
1683 ControlPoker c
= new ControlPoker();
1687 p
.Layout
+= new LayoutEventHandler (ParentLayoutEvent
);
1688 c
.Layout
+= new LayoutEventHandler (ChildLayoutEvent
);
1692 Assert
.AreEqual (1, child_event
, "1");
1693 Assert
.AreEqual ("Bounds", child_affected_property
, "2");
1695 Assert
.AreEqual (0, parent_event
, "3");
1700 [Category ("NotWorking")]
1701 public class ControlInvokeTest
{
1702 public delegate void TestDelegate ();
1707 ApplicationContext control_context
;
1708 bool delegateCalled
= false;
1709 bool threadDied
= false;
1713 void CreateControl ()
1717 f
.ShowInTaskbar
= false;
1723 Console
.WriteLine ("f.Handle = {0}", f
.Handle
);
1724 Console
.WriteLine ("c.Handle = {0}", c
.Handle
);
1726 control_context
= new ApplicationContext (f
);
1729 Console
.WriteLine ("pulsing");
1732 Console
.WriteLine ("control thread running");
1733 Application
.Run (control_context
);
1735 Console
.WriteLine ("dying");
1738 Console
.WriteLine ("pulsing again");
1741 } catch (Exception e
) { Console.WriteLine (e); }
1745 public void InvokeTest ()
1749 control_t
= new Thread(new ThreadStart(CreateControl
));
1755 Console
.WriteLine ("waiting on monitor");
1758 Console
.WriteLine ("making async call");
1760 IAsyncResult result
;
1761 result
= c
.BeginInvoke (new TestDelegate (delegate_call
));
1762 c
.EndInvoke (result
);
1764 Assert
.IsTrue (delegateCalled
, "Invoke1");
1767 Assert
.IsTrue (threadDied
, "Invoke2");
1770 public void delegate_call () {
1772 /* invoked on control_context's thread */
1773 delegateCalled
= true;
1775 Console
.WriteLine ("calling Application.Exit");
1776 control_context
.ExitThread ();
1777 } catch (Exception e
) { Console.WriteLine (e); }
1783 public class ControlWMTest
1786 public void WM_PARENTNOTIFY_Test ()
1792 tester
= new WMTester ();
1793 child
= new Control ();
1794 tester
.Controls
.Add (child
);
1796 tester
.Visible
= true;
1797 child
.Visible
= true;
1799 child_handle
= child
.Handle
.ToInt32 ();
1804 msgs
= tester
.Find (WndMsg
.WM_PARENTNOTIFY
);
1806 Assert
.AreEqual (1, msgs
.Count
, "#1");
1808 m1
= (Message
) msgs
[0];
1809 Assert
.AreEqual (WndMsg
.WM_CREATE
, ((WndMsg
) LowOrder (m1
.WParam
)), "#2");
1810 //Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam), "#3");
1811 Assert
.AreEqual (child_handle
, m1
.LParam
.ToInt32 (), "#4");
1815 msgs
= tester
.Find (WndMsg
.WM_PARENTNOTIFY
);
1816 Assert
.AreEqual (2, msgs
.Count
, "#5");
1817 m1
= (Message
) msgs
[1];
1819 Assert
.AreEqual (WndMsg
.WM_DESTROY
, ((WndMsg
) LowOrder (m1
.WParam
)), "#6");
1820 //Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam), "#7");
1821 Assert
.AreEqual (child_handle
, m1
.LParam
.ToInt32 (), "#8");
1826 internal static int LowOrder (int param
)
1828 return ((int)(short)(param
& 0xffff));
1831 internal static int HighOrder (int param
)
1833 return ((int)(short)(param
>> 16));
1836 internal static int LowOrder (IntPtr param
)
1838 return ((int)(short)(param
.ToInt32 () & 0xffff));
1841 internal static int HighOrder (IntPtr param
)
1843 return ((int)(short)(param
.ToInt32 () >> 16));
1846 internal class WMTester
: Form
1848 internal ArrayList Messages
= new ArrayList ();
1850 internal bool Contains (WndMsg msg
)
1852 return Contains (msg
, Messages
);
1855 internal bool Contains (WndMsg msg
, ArrayList list
)
1857 foreach (Message m
in Messages
)
1859 if (m
.Msg
== (int) msg
)
1865 internal ArrayList
Find (WndMsg msg
)
1867 ArrayList result
= new ArrayList ();
1869 foreach (Message m
in Messages
)
1871 if (m
.Msg
== (int) msg
)
1877 protected override void WndProc(ref Message m
)
1879 Console
.WriteLine ("WndProc: " + m
.ToString ());
1881 base.WndProc (ref m
);
1888 public class ControlLayoutTest
1891 public void SetUp ()
1896 [Test
] // bug #80456
1897 public void LayoutTest ()
1899 MockLayoutEngine layoutEngine
= new MockLayoutEngine ();
1900 MockControl c
= new MockControl (layoutEngine
);
1901 c
.Layout
+= new LayoutEventHandler (LayoutEvent
);
1902 Assert
.IsFalse (layoutEngine
.LayoutInvoked
, "#A1");
1903 Assert
.AreEqual (0, _layoutCount
, "#A2");
1905 Assert
.IsTrue (layoutEngine
.LayoutInvoked
, "#A3");
1906 Assert
.AreEqual (1, _layoutCount
, "#A4");
1908 layoutEngine
.Reset ();
1909 c
.OverrideOnLayout
= true;
1910 Assert
.IsFalse (layoutEngine
.LayoutInvoked
, "#B1");
1912 Assert
.IsFalse (layoutEngine
.LayoutInvoked
, "#B2");
1913 Assert
.AreEqual (1, _layoutCount
, "#B3");
1916 void LayoutEvent (object sender
, LayoutEventArgs e
)
1921 private int _layoutCount
;
1923 class MockControl
: Control
1925 public MockControl (LayoutEngine layoutEngine
)
1927 _layoutEngine
= layoutEngine
;
1930 public bool OverrideOnLayout
1932 get { return _overrideOnLayout; }
1933 set { _overrideOnLayout = value; }
1936 protected override void OnLayout (LayoutEventArgs levent
)
1938 if (!OverrideOnLayout
)
1939 base.OnLayout (levent
);
1942 public override LayoutEngine LayoutEngine
{
1944 if (_layoutEngine
== null)
1945 return base.LayoutEngine
;
1946 return _layoutEngine
;
1950 private bool _overrideOnLayout
;
1951 private LayoutEngine _layoutEngine
;
1954 class MockLayoutEngine
: LayoutEngine
1956 public bool LayoutInvoked
{
1957 get { return _layoutInvoked; }
1960 public void Reset ()
1962 _layoutInvoked
= false;
1965 public override bool Layout (object container
, LayoutEventArgs args
)
1967 _layoutInvoked
= true;
1971 private bool _layoutInvoked
;