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 CreateHandleTest ()
1090 parent = new Control ();
1091 child = new Control ();
1093 parent.Visible = true;
1094 parent.Controls.Add (child);
1096 Assert.IsFalse (parent.IsHandleCreated, "CH1");
1097 Assert.IsFalse (child.IsHandleCreated, "CH2");
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");
1111 // Accessing Handle Property creates the handle
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");
1131 [Category ("NotWorking")]
1132 public void CreateHandleTest2 ()
1134 // This should eventually test all operations
1135 // that can be performed on a control (within
1137 Control c = new Control ();
1139 Assert.IsFalse (c.IsHandleCreated, "0");
1142 Assert.IsFalse (c.IsHandleCreated, "1");
1145 Assert.IsFalse (c.IsHandleCreated, "2");
1148 Assert.IsFalse (c.IsHandleCreated, "3");
1151 Assert.IsFalse (c.IsHandleCreated, "5");
1154 Assert.IsFalse (c.IsHandleCreated, "6");
1156 c.Location = new Point (1, 1);
1157 Assert.IsFalse (c.IsHandleCreated, "7");
1159 c.Region = new Region ();
1160 Assert.IsFalse (c.IsHandleCreated, "8");
1162 c.Size = new Size (100, 100);
1163 Assert.IsFalse (c.IsHandleCreated, "9");
1166 Assert.IsFalse (c.IsHandleCreated, "10");
1168 c.Visible = !c.Visible;
1169 Assert.IsFalse (c.IsHandleCreated, "11");
1173 [Category ("NotWorking")]
1174 public void IsHandleCreated_NotVisible ()
1176 Control c = new Control ();
1179 Form form = new Form ();
1180 form.ShowInTaskbar = false;
1181 form.Controls.Add (c);
1184 Assert.IsFalse (c.IsHandleCreated, "#1");
1186 Assert.IsTrue (c.IsHandleCreated, "#2");
1188 Assert.IsTrue (c.IsHandleCreated, "#3");
1192 public void CreateGraphicsTest ()
1198 Control c = new Control ();
1199 c.SetBounds (0,0, 20, 20);
1200 g = c.CreateGraphics ();
1201 Assert.IsNotNull (g, "Graph1");
1210 bool delegateCalled = false;
1211 public delegate void TestDelegate ();
1213 public void delegate_call () {
1214 delegateCalled = true;
1216 TestHelper.RemoveWarning (delegateCalled);
1220 [ExpectedException(typeof(InvalidOperationException))]
1221 public void InvokeException1 () {
1222 Control c = new Control ();
1223 IAsyncResult result;
1225 result = c.BeginInvoke (new TestDelegate (delegate_call));
1226 c.EndInvoke (result);
1230 public void FindFormTest () {
1231 Form f = new Form ();
1233 f.ShowInTaskbar = false;
1238 f.Controls.Add (c = new Control ());
1239 Assert.AreEqual (f.Name, c.FindForm ().Name, "Find1");
1241 f.Controls.Remove (c);
1243 GroupBox g = new GroupBox ();
1248 Assert.AreEqual (f.Name, f.FindForm ().Name, "Find2");
1250 g.Controls.Remove (c);
1251 Assert.IsNull(c.FindForm (), "Find3");
1262 public void FocusTest ()
1265 Button c = null, d = null;
1269 f.ShowInTaskbar = false;
1279 Assert.IsTrue (c.CanFocus, "Focus1");
1280 Assert.IsFalse (c.Focused, "Focus2");
1282 Assert.IsTrue (c.Focused, "Focus3");
1284 Assert.IsFalse (d.Focused, "Focus4");
1288 Assert.IsTrue (d.Focused, "Focus5");
1289 Assert.IsFalse (c.Focused, "Focus6");
1292 Assert.IsFalse (c.Focused, "Focus7");
1304 public void FromHandleTest ()
1310 c1 = new Control ();
1311 c2 = new Control ();
1315 c1.Controls.Add(c2);
1318 Assert.AreEqual (c1.Name, Control.FromHandle (c1.Handle).Name, "Handle1");
1319 Assert.IsNull (Control.FromHandle (IntPtr.Zero), "Handle2");
1322 Assert.AreEqual (c1.Name, Control.FromChildHandle (c1.Handle).Name, "Handle3");
1323 Assert.IsNull (Control.FromChildHandle (IntPtr.Zero), "Handle4");
1336 public void GetChildAtPointTest ()
1338 Control c = null, d = null, e = null;
1343 c.SetBounds (0, 0, 100, 100);
1347 d.SetBounds (10, 10, 40, 40);
1352 e.SetBounds (55, 55, 10, 10);
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");
1358 l = c.GetChildAtPoint (new Point (57, 57));
1359 Assert.IsNull (l, "Child3");
1361 l = c.GetChildAtPoint (new Point (10, 10));
1362 Assert.AreEqual (d.Name, l.Name, "Child4");
1364 // GetChildAtPointSkip is not implemented and the following test is breaking for Net_2_0 profile
1366 // c.Controls.Add (e);
1367 // e.Visible = false;
1368 // l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
1369 // Assert.IsNull (l, "Child5");
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
1384 public void ResetFontTest ()
1386 Control c = new Control ();
1387 c.Font = new Font (c.Font.FontFamily, 3, FontStyle.Italic);
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");
1400 Assert.AreEqual (true, c.Font.IsSystemFont, "#10");
1404 public class LayoutTestControl : Control {
1405 public int LayoutCount;
1407 public LayoutTestControl () : base() {
1411 protected override void OnLayout(LayoutEventArgs levent) {
1413 base.OnLayout (levent);
1418 public void LayoutTest() {
1419 LayoutTestControl c;
1421 c = new LayoutTestControl();
1428 c.ResumeLayout(true);
1430 c.ResumeLayout(true);
1432 c.ResumeLayout(true);
1434 c.ResumeLayout(true);
1436 c.ResumeLayout(true);
1438 c.ResumeLayout(true);
1440 c.ResumeLayout(true);
1445 Assert.AreEqual(5, c.LayoutCount, "Layout Suspend/Resume locking does not bottom out at 0");
1449 [ExpectedException(typeof(ArgumentException))]
1450 public void TransparentBackgroundTest1() {
1454 c.BackColor = Color.Transparent;
1458 public void TransparentBackgroundTest2() {
1462 c.BackColor = Color.Transparent;
1463 Assert.AreEqual(Color.Transparent, c.BackColor, "Transparent background not set");
1467 public void TransparentBackgroundTest3() {
1471 c.BackColor = Color.Empty;
1472 Assert.AreEqual(Control.DefaultBackColor, c.BackColor, "Setting empty color failed");
1476 public void Dock_Value_Invalid ()
1478 Control c = new Control ();
1480 c.Dock = (DockStyle) 666;
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");
1492 public void EnabledTest1() {
1497 grandma = new Control();
1498 parent = new Control();
1499 child = new Control();
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");
1507 int EnabledCalledCount = 0;
1508 private void EnabledTest2EnabledChanged(object sender, EventArgs e) {
1509 EnabledCalledCount++;
1513 public void EnabledTest2() {
1514 // Check nesting of enabled calls
1515 // OnEnabled is not called for disabled child controls
1520 EnabledCalledCount = 0;
1522 grandma = new Control();
1523 parent = new Control();
1524 child = new Control();
1525 child.EnabledChanged += new EventHandler(EnabledTest2EnabledChanged);
1527 grandma.Controls.Add(parent);
1528 parent.Controls.Add(child);
1529 grandma.Enabled = false;
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");
1540 public void ControlsRemoveNullTest ()
1542 Control c = new Control ();
1543 c.Controls.Remove (null);
1547 public void ControlsAddNullTest ()
1549 Control c = new Control ();
1550 c.Controls.Add (null);
1554 [ExpectedException (typeof (ArgumentNullException))]
1555 public void ControlsSetChildIndexNullTest ()
1557 Control c = new Control ();
1558 c.Controls.SetChildIndex (null, 1);
1562 [ExpectedException (typeof (ArgumentNullException))]
1563 public void ControlsAddRangeNullTest ()
1565 Control c = new Control ();
1566 c.Controls.AddRange (null);
1570 public void ControlsAddRangeNullElementTest ()
1572 Control c = new Control ();
1573 Control[] subcontrols = new Control[2];
1574 subcontrols[0] = new Control ();
1575 subcontrols[1] = null;
1577 c.Controls.AddRange (subcontrols);
1581 public void RegionTest () {
1582 Form f = new Form ();
1583 f.ShowInTaskbar = false;
1584 Control c = new Control ();
1586 Assert.IsNull (c.Region, "#A1");
1588 Assert.IsNull (c.Region, "#A2");
1590 Assert.IsNull (c.Region, "#A3");
1593 Region region = new Region ();
1595 f.ShowInTaskbar = false;
1599 Assert.IsNotNull (c.Region, "#B1");
1600 Assert.AreSame (region, c.Region, "#B2");
1603 Assert.IsNull (c.Region, "#B3");
1608 [Test] // bug #80280
1609 public void Validated_Multiple_Containers ()
1611 Form form = new Form ();
1612 form.ShowInTaskbar = false;
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);
1621 UserControl container2 = new UserControl();
1622 UserControl control2 = new UserControl();
1623 container2.Controls.Add(control2);
1624 form.Controls.Add (container2);
1626 Assert.IsTrue ((bool) control1.Tag, "#1");
1628 Assert.IsTrue ((bool) control1.Tag, "#2");
1630 Assert.IsFalse ((bool) control1.Tag, "#3");
1635 private void Control_ValidatedHandler (object sender, EventArgs e)
1637 ((Control) sender).Tag = false;
1640 public class MockControl : Control
1642 public int font_height {
1643 get { return base.FontHeight; }
1644 set { base.FontHeight = value; }
1650 public class ControlSetTopLevelTest
1652 class ControlPoker : Control {
1653 public void DoSetTopLevel ()
1657 public bool DoGetTopLevel ()
1659 return GetTopLevel ();
1664 public void TestControl ()
1666 ControlPoker c = new ControlPoker ();
1669 Assert.IsTrue (c.DoGetTopLevel (), "1");
1670 Assert.IsFalse (c.Visible, "2");
1674 [ExpectedException (typeof (ArgumentException))]
1675 public void TestChildControl ()
1677 Control c1 = new Control();
1678 ControlPoker c2 = new ControlPoker ();
1680 c1.Controls.Add (c2);
1681 c2.DoSetTopLevel ();
1685 [ExpectedException (typeof (ArgumentException))]
1686 public void TestTopLevelAdd () {
1687 Form f = new Form();
1688 Form f1 = new Form();
1692 [Category ("NotWorking")]
1694 public void TestForm ()
1696 Form f = new Form ();
1697 Assert.IsFalse (f.Visible, "3");
1699 Assert.IsFalse (f.Visible, "4");
1704 public class ControlResizeLayoutTest
1706 class ControlPoker : Control {
1707 public void DoOnResize ()
1709 OnResize (EventArgs.Empty);
1714 string child_affected_property;
1715 void ChildLayoutEvent (object sender, LayoutEventArgs e)
1718 child_affected_property = e.AffectedProperty;
1722 string parent_affected_property;
1723 void ParentLayoutEvent (object sender, LayoutEventArgs e)
1726 parent_affected_property = e.AffectedProperty;
1728 TestHelper.RemoveWarning (parent_affected_property);
1734 Panel p = new Panel ();
1735 ControlPoker c = new ControlPoker();
1739 p.Layout += new LayoutEventHandler (ParentLayoutEvent);
1740 c.Layout += new LayoutEventHandler (ChildLayoutEvent);
1744 Assert.AreEqual (1, child_event, "1");
1745 Assert.AreEqual ("Bounds", child_affected_property, "2");
1747 Assert.AreEqual (0, parent_event, "3");
1752 public class ControlInvokeTest {
1753 public delegate void TestDelegate ();
1758 ApplicationContext control_context;
1759 bool delegateCalled = false;
1763 void CreateControl ()
1766 f.ShowInTaskbar = false;
1772 Console.WriteLine ("f.Handle = {0}", f.Handle);
1773 Console.WriteLine ("c.Handle = {0}", c.Handle);
1775 control_context = new ApplicationContext (f);
1778 Console.WriteLine ("pulsing");
1781 Console.WriteLine ("control thread running");
1782 Application.Run (control_context);
1787 public void InvokeTest ()
1791 control_t = new Thread(new ThreadStart(CreateControl));
1797 Console.WriteLine ("waiting on monitor");
1800 Console.WriteLine ("making async call");
1802 IAsyncResult result;
1803 result = c.BeginInvoke (new TestDelegate (delegate_call));
1804 c.EndInvoke (result);
1806 Assert.AreEqual (true, delegateCalled, "Invoke1");
1809 public void delegate_call () {
1810 /* invoked on control_context's thread */
1811 delegateCalled = true;
1813 Application.Exit ();
1819 public class ControlWMTest
1822 public void WM_PARENTNOTIFY_Test ()
1828 tester = new WMTester ();
1829 child = new Control ();
1830 tester.Controls.Add (child);
1832 tester.Visible = true;
1833 child.Visible = true;
1835 child_handle = child.Handle.ToInt32 ();
1840 msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
1842 Assert.AreEqual (1, msgs.Count, "#1");
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");
1851 msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
1852 Assert.AreEqual (2, msgs.Count, "#5");
1853 m1 = (Message) msgs [1];
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");
1862 internal static int LowOrder (int param)
1864 return ((int)(short)(param & 0xffff));
1867 internal static int HighOrder (int param)
1869 return ((int)(short)(param >> 16));
1872 internal static int LowOrder (IntPtr param)
1874 return ((int)(short)(param.ToInt32 () & 0xffff));
1877 internal static int HighOrder (IntPtr param)
1879 return ((int)(short)(param.ToInt32 () >> 16));
1882 internal class WMTester : Form
1884 internal ArrayList Messages = new ArrayList ();
1886 internal bool Contains (WndMsg msg)
1888 return Contains (msg, Messages);
1891 internal bool Contains (WndMsg msg, ArrayList list)
1893 foreach (Message m in Messages)
1895 if (m.Msg == (int) msg)
1901 internal ArrayList Find (WndMsg msg)
1903 ArrayList result = new ArrayList ();
1905 foreach (Message m in Messages)
1907 if (m.Msg == (int) msg)
1913 protected override void WndProc(ref Message m)
1915 Console.WriteLine ("WndProc: " + m.ToString ());
1917 base.WndProc (ref m);
1924 public class ControlLayoutTest
1927 public void SetUp ()
1932 [Test] // bug #80456
1933 public void LayoutTest ()
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");
1941 Assert.IsTrue (layoutEngine.LayoutInvoked, "#A3");
1942 Assert.AreEqual (1, _layoutCount, "#A4");
1944 layoutEngine.Reset ();
1945 c.OverrideOnLayout = true;
1946 Assert.IsFalse (layoutEngine.LayoutInvoked, "#B1");
1948 Assert.IsFalse (layoutEngine.LayoutInvoked, "#B2");
1949 Assert.AreEqual (1, _layoutCount, "#B3");
1952 void LayoutEvent (object sender, LayoutEventArgs e)
1957 private int _layoutCount;
1959 class MockControl : Control
1961 public MockControl (LayoutEngine layoutEngine)
1963 _layoutEngine = layoutEngine;
1966 public bool OverrideOnLayout
1968 get { return _overrideOnLayout; }
1969 set { _overrideOnLayout = value; }
1972 protected override void OnLayout (LayoutEventArgs levent)
1974 if (!OverrideOnLayout)
1975 base.OnLayout (levent);
1978 public override LayoutEngine LayoutEngine {
1980 if (_layoutEngine == null)
1981 return base.LayoutEngine;
1982 return _layoutEngine;
1986 private bool _overrideOnLayout;
1987 private LayoutEngine _layoutEngine;
1990 class MockLayoutEngine : LayoutEngine
1992 public bool LayoutInvoked {
1993 get { return _layoutInvoked; }
1996 public void Reset ()
1998 _layoutInvoked = false;
2001 public override bool Layout (object container, LayoutEventArgs args)
2003 _layoutInvoked = true;
2007 private bool _layoutInvoked;