2 // Copyright (c) 2005 Novell, Inc.
5 // Ritvik Mayank (mritvik@novell.com)
6 // Stefan Noack (noackstefan@googlemail.com)
10 using System.Collections;
11 using InvalidEnumArgumentException = System.ComponentModel.InvalidEnumArgumentException;
13 using System.Reflection;
14 using System.Runtime.Remoting;
15 using System.Threading;
16 using System.Windows.Forms;
18 using System.Windows.Forms.Layout;
21 using NUnit.Framework;
23 namespace MonoTests.System.Windows.Forms
26 public class ControlTest
31 public void AutoSizeTest ()
33 ControlAutoSizeTester c = new ControlAutoSizeTester (new Size (23, 17), AutoSizeMode.GrowAndShrink);
36 f.Size = new Size (200, 200);
40 Size s = new Size (42, 42);
43 Point l = new Point (10, 10);
46 //Check wether normal size setting is OK
47 Assert.AreEqual (s, c.Size, "#S1");
49 //Check wether size remains without GetPreferredSize implemented even when AutoSize turned on.
52 Assert.AreEqual (s, c.Size, "#S2");
54 //Simulate a Control implementing GetPreferredSize
55 c.UseCustomPrefSize = true;
58 //Check wether size shrinks to preferred size
59 Assert.AreEqual (c.CustomPrefSize, c.Size, "#S3");
60 //Check wether Location stays constant
61 Assert.AreEqual (l, c.Location, "#L1");
63 //Check wether Dock is respected
64 c.Dock = DockStyle.Bottom;
65 Assert.AreEqual (f.ClientSize.Width, c.Width, "#D1");
67 //Check wether size shrinks to preferred size again
68 c.Dock = DockStyle.None;
69 Assert.AreEqual (c.CustomPrefSize, c.Size, "#S4");
71 //Check wether Anchor is respected for adjusting Locatioon
72 c.Anchor = AnchorStyles.Bottom;
74 Assert.AreEqual (l.Y + 50, c.Top, "#A1");
75 //Check wether size is still OK
76 Assert.AreEqual (c.CustomPrefSize, c.Size, "#S5");
80 c.Anchor = AnchorStyles.Top | AnchorStyles.Left;
83 //Check wether shrinking to zero is possible
84 c.CustomPrefSize = new Size (0, 0);
86 Assert.AreEqual (c.CustomPrefSize, c.Size, "#S6");
88 //Check wether MinimumSize is honored
89 c.MinimumSize = new Size (10, 12);
90 c.CustomPrefSize = new Size (5, 5);
92 Assert.AreEqual (c.MinimumSize, c.Size, "#S7");
93 c.MinimumSize = new Size (0, 0);
95 //Check wether MaximumSize is honored
96 c.MaximumSize = new Size (100, 120);
97 c.CustomPrefSize = new Size (500, 500);
99 Assert.AreEqual (c.MaximumSize, c.Size, "#S8");
101 //Check wether shrinking does not happen when GrowOnly
103 s = new Size (23, 23);
105 c.CustomPrefSize = new Size (5, 5);
106 c.AutoSizeMode = AutoSizeMode.GrowOnly;
109 Assert.AreEqual (s, c.Size, "#S9");
113 public class ControlAutoSizeTester : Control {
116 public ControlAutoSizeTester (Size customPrefSize, AutoSizeMode autoSizeMode)
118 custom_prefsize = customPrefSize;
119 AutoSizeMode = autoSizeMode;
122 public AutoSizeMode AutoSizeMode {
124 base.SetAutoSizeMode (value);
128 private bool use_custom_prefsize = false;
129 public bool UseCustomPrefSize {
131 use_custom_prefsize = value;
135 private Size custom_prefsize;
137 public Size CustomPrefSize {
139 return custom_prefsize;
142 custom_prefsize = value;
147 public override Size GetPreferredSize (Size proposedSize)
149 if (use_custom_prefsize) {
150 return custom_prefsize;
152 return base.GetPreferredSize(proposedSize);
160 public void Bug82748 ()
162 Form f = new Form ();
163 f.ShowInTaskbar = false;
165 Control c = new Control ();
166 c.Size = new Size (100, 100);
168 Control c2 = new Control ();
172 c.Anchor = AnchorStyles.Right;
178 Assert.AreEqual (0, c.Left, "A1");
185 public void InvokeTestParentHandle ()
187 Control child, parent;
189 parent = new Control ();
190 child = new Control ();
191 parent.Controls.Add (child);
192 parent.Visible = true;
193 parent.CreateControl ();
194 child.Invoke (new CrossAppDomainDelegate (dummy)) ;
201 public class ControlStylesTester : Control {
202 private WindowStyles style;
203 private WindowStyles ex_style;
204 private bool or_styles;
206 public ControlStylesTester (WindowStyles Style, WindowStyles ExStyle, bool OrStyles)
210 or_styles = OrStyles;
213 protected override CreateParams CreateParams {
215 CreateParams result = base.CreateParams;
217 result.Style |= (int) style;
218 result.ExStyle |= (int) ex_style;
220 result.Style = (int) style;
221 result.ExStyle = (int) ex_style;
229 public void ControlSizeTest ()
231 ControlStylesTester c = new ControlStylesTester (WindowStyles.WS_CHILD, 0, true);
232 Assert.AreEqual ("{X=0,Y=0}", c.Location.ToString (), "#L1");
233 Assert.AreEqual ("{Width=0, Height=0}", c.Size.ToString (), "#S1");
238 public void CaptureTest ()
240 Form frm = new Form ();
241 ControlOverrideLogger log = new ControlOverrideLogger ();
242 frm.Controls.Add (log);
246 log.BackColor = Color.Blue;
247 log.Size = new Size (100, 100);
250 Application.DoEvents ();
253 Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") > -1, "#01");
255 log = new ControlOverrideLogger ();
258 Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") > -1, "#02");
260 log = new ControlOverrideLogger ();
262 Assert.IsTrue (log.IsHandleCreated, "#03");
263 Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") == -1, "#04");
265 log = new ControlOverrideLogger ();
267 Assert.IsFalse (log.IsHandleCreated, "#05");
268 Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") == -1, "#06");
272 public class OnPaintTester : Form
276 ArrayList list = new ArrayList ();
277 public bool Recursive;
278 public bool TestRefresh;
279 public bool TestInvalidate;
280 public bool TestUpdate;
282 public new bool DoubleBuffered {
284 return base.DoubleBuffered;
287 base.DoubleBuffered = value;
291 protected override void OnPaint (PaintEventArgs pevent)
293 Assert.IsFalse (list.Contains (pevent.Graphics), "OnPaintTester.OnPaint: Got the same Graphics twice");
294 list.Add (pevent.Graphics);
298 Recursive = counter > 0 || Recursive;
303 else if (TestInvalidate)
309 base.OnPaint (pevent);
313 public new void Show ()
316 Application.DoEvents ();
321 public void ControlCollectionTest ()
323 Form frm = new Form ();
324 frm.IsMdiContainer = true;
325 Form child = new Form ();
326 Control.ControlCollection c = new Control.ControlCollection (frm);
327 child.MdiParent = frm;
332 [ExpectedException (typeof (ArgumentException))]
333 public void ControlCollectionExceptionTest ()
335 Form frm = new Form ();
336 frm.IsMdiContainer = true;
337 Form child = new Form ();
338 Control.ControlCollection c = new Control.ControlCollection (frm);
339 //child.MdiParent = frm;
344 [Category ("NotWorking")]
345 public void OnPaintTest ()
347 using (OnPaintTester t = new OnPaintTester ()) {
348 t.TestRefresh = true;
350 Assert.IsTrue (t.Recursive, "#1");
353 using (OnPaintTester t = new OnPaintTester ()) {
356 Assert.IsFalse (t.Recursive, "#2");
359 using (OnPaintTester t = new OnPaintTester ()) {
360 t.TestInvalidate = true;
362 Assert.IsFalse (t.Recursive, "#3");
367 [Category ("Interactive")]
368 public void OnPaintDoubleBufferedTest ()
370 using (OnPaintTester t = new OnPaintTester ()) {
371 t.DoubleBuffered = true;
372 t.TestRefresh = true;
374 Assert.IsTrue (t.Recursive, "#1");
377 using (OnPaintTester t = new OnPaintTester ()) {
378 t.DoubleBuffered = true;
381 Assert.IsFalse (t.Recursive, "#2");
384 using (OnPaintTester t = new OnPaintTester ()) {
385 t.DoubleBuffered = true;
386 t.TestInvalidate = true;
388 Assert.IsFalse (t.Recursive, "#3");
392 public class PaintEventForm : Form
394 public ArrayList overrides = new ArrayList ();
395 public ArrayList events = new ArrayList ();
397 public PaintEventForm ()
399 Paint += new PaintEventHandler (DoubleBufferEventForm_Paint);
401 public bool GetControlStyle (ControlStyles style)
403 return base.GetStyle (style);
406 public void SetControlStyle (ControlStyles style, bool value)
408 base.SetStyle (style, value);
411 void DoubleBufferEventForm_Paint (object sender, PaintEventArgs e)
416 protected override void OnPaintBackground (PaintEventArgs e)
418 base.OnPaintBackground (e);
419 overrides.Add("OnPaintBackground");
422 protected override void OnPaint (PaintEventArgs pevent)
424 base.OnPaint (pevent);
425 overrides.Add("OnPaint");
430 [Ignore ("Can't find a reliable way to generate a paint message on Windows.")]
431 public void EventStyleTest ()
434 using (PaintEventForm f = new PaintEventForm ()) {
436 f.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
438 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#A1");
439 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#A2");
440 Assert.IsTrue (f.events.Contains ("Paint"), "#A3");
443 using (PaintEventForm f = new PaintEventForm ()) {
445 f.SetControlStyle (ControlStyles.DoubleBuffer, true);
447 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#B1");
448 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#B2");
449 Assert.IsTrue (f.events.Contains ("Paint"), "#B3");
452 using (PaintEventForm f = new PaintEventForm ()) {
454 f.SetControlStyle (ControlStyles.AllPaintingInWmPaint, true);
456 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#C1");
457 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#C2");
458 Assert.IsTrue (f.events.Contains ("Paint"), "#C3");
461 using (PaintEventForm f = new PaintEventForm ()) {
463 f.SetControlStyle (ControlStyles.UserPaint, true);
465 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#D1");
466 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#D2");
467 Assert.IsTrue (f.events.Contains ("Paint"), "#D3");
470 using (PaintEventForm f = new PaintEventForm ()) {
472 f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
474 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#E1");
475 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#E2");
476 Assert.IsTrue (f.events.Contains ("Paint"), "#E3");
479 using (PaintEventForm f = new PaintEventForm ()) {
481 f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
483 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#F1");
484 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#F2");
485 Assert.IsTrue (f.events.Contains ("Paint"), "#F3");
488 using (PaintEventForm f = new PaintEventForm ()) {
490 f.SetControlStyle (ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
492 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#G1");
493 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#G2");
494 Assert.IsTrue (f.events.Contains ("Paint"), "#G3");
497 using (PaintEventForm f = new PaintEventForm ()) {
499 f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true);
501 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#H1");
502 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#H2");
503 Assert.IsTrue (f.events.Contains ("Paint"), "#H3");
507 public class DoubleBufferedForm : Form
511 public DoubleBufferedForm ()
513 this.DoubleBuffered = true;
516 protected override void OnPaint (PaintEventArgs e)
518 if (failed || painted)
523 e.Graphics.DrawString (Size.ToString (), Font, Brushes.AliceBlue, new Point (2, 2));
524 } catch (Exception exception) {
525 Console.WriteLine (exception.StackTrace);
531 public class DoubleBufferControl : Control
533 public bool IsDoubleBuffered
535 get { return base.DoubleBuffered; }
536 set { base.DoubleBuffered = value; }
539 public bool GetControlStyle (ControlStyles style)
541 return base.GetStyle (style);
544 public void SetControlStyle (ControlStyles style, bool value)
546 base.SetStyle (style, value);
551 [Ignore ("Can't find a reliable way to generate a paint message on Windows.")]
552 public void DoubleBufferTest ()
554 DoubleBufferedForm f = new DoubleBufferedForm ();
555 f.ShowInTaskbar = false;
559 Assert.IsFalse (f.failed, "#01");
560 Assert.IsTrue (f.painted, "The control was never painted, so please check the test");
565 public void DoubleBufferedTest ()
567 DoubleBufferControl c = new DoubleBufferControl ();
568 Assert.IsFalse (c.IsDoubleBuffered, "#A1");
569 Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#A2");
570 Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#A3");
571 Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#A4");
572 Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#A5");
574 c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
575 Assert.IsTrue (c.IsDoubleBuffered, "#B1");
576 Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#B2");
577 Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#B3");
578 Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#B4");
579 Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#A5");
581 c.SetControlStyle (ControlStyles.AllPaintingInWmPaint, false);
582 c.SetControlStyle (ControlStyles.UserPaint, false);
583 Assert.IsTrue (c.IsDoubleBuffered, "#C1");
584 Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#C2");
585 Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#C3");
586 Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#C4");
587 Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#C5");
589 c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, false);
590 Assert.IsFalse (c.IsDoubleBuffered, "#D1");
591 Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#D2");
592 Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#D3");
593 Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#D4");
594 Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#D5");
596 c.SetControlStyle (ControlStyles.DoubleBuffer, true);
597 Assert.IsFalse (c.IsDoubleBuffered, "#E1");
598 Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#E2");
599 Assert.IsTrue (c.GetControlStyle (ControlStyles.DoubleBuffer), "#E3");
600 Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#E4");
601 Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#E5");
603 c.SetControlStyle (ControlStyles.DoubleBuffer, false);
604 Assert.IsFalse (c.IsDoubleBuffered, "#F1");
605 Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#F2");
606 Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#F3");
607 Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#F4");
608 Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#F5");
610 c.IsDoubleBuffered = true;
611 Assert.IsTrue (c.IsDoubleBuffered, "#G1");
612 Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#G2");
613 Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#G3");
614 Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#G4");
615 Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#G5");
617 c.SetControlStyle (ControlStyles.AllPaintingInWmPaint, true);
618 c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
619 c.SetControlStyle (ControlStyles.DoubleBuffer, true);
620 c.SetControlStyle (ControlStyles.UserPaint, true);
621 c.IsDoubleBuffered = false;
622 Assert.IsFalse (c.IsDoubleBuffered, "#H1");
623 Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#H2");
624 Assert.IsTrue (c.GetControlStyle (ControlStyles.DoubleBuffer), "#H3");
625 Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#H4");
626 Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#H5");
630 public void DoubleBufferedStyleTest ()
632 DoubleBufferControl c = new DoubleBufferControl ();
633 TestControlStyle.CheckStyles (c, "#A1", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility);
635 c.IsDoubleBuffered = true;
636 TestControlStyle.CheckStyles (c, "#A2", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility, ControlStyles.OptimizedDoubleBuffer);
638 c.IsDoubleBuffered = false;
639 TestControlStyle.CheckStyles (c, "#A3", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility);
641 c = new DoubleBufferControl ();
642 foreach (ControlStyles style in Enum.GetValues (typeof(ControlStyles))) {
643 c.SetControlStyle (style, false);
646 TestControlStyle.CheckStyles (c, "#B1");
648 c.IsDoubleBuffered = true;
649 TestControlStyle.CheckStyles (c, "#B2", ControlStyles.OptimizedDoubleBuffer, ControlStyles.AllPaintingInWmPaint);
651 c.IsDoubleBuffered = false;
652 TestControlStyle.CheckStyles (c, "#B3", ControlStyles.AllPaintingInWmPaint);
658 public static void TestAccessibility(Control c, string Default, string Description, string Name, AccessibleRole Role)
660 Assert.IsNotNull (c.AccessibilityObject, "Acc1");
661 Assert.AreEqual (Default, c.AccessibleDefaultActionDescription, "Acc2");
662 Assert.AreEqual (Description, c.AccessibleDescription, "Acc3");
663 Assert.AreEqual (Name, c.AccessibleName, "Acc4");
664 Assert.AreEqual (Role, c.AccessibleRole, "Acc5");
667 public static string TestControl(Control container, Control start, bool forward) {
670 ctl = container.GetNextControl(start, forward);
681 public void CreatedTest ()
683 Control c = new Control ();
684 Assert.IsFalse (c.Created, "A1");
688 [Category ("NotWorking")]
689 public void CreatedAccessibilityTest ()
691 Control c = new Control ();
692 Assert.IsFalse (c.Created, "A1");
694 Helper.TestAccessibility(c, null, null, null, AccessibleRole.Default);
696 Assert.IsTrue (c.Created, "A2");
700 Assert.IsFalse (c.Created, "A3");
704 [Category ("NotWorking")]
705 public void BoundsTest ()
707 Control c = new Control ();
708 Assert.IsTrue (c.Bounds.IsEmpty, "A1");
709 Assert.IsTrue (c.Size.IsEmpty, "A2");
710 Assert.IsTrue (c.ClientSize.IsEmpty, "A3");
711 Assert.IsTrue (c.ClientRectangle.IsEmpty, "A4");
713 Assert.AreEqual (((IWin32Window)c).Handle, c.Handle, "A5");
715 /* this part fails on linux because we can't allocate X windows which are 0x0,
716 and the Control bounds directly reflect the size of the X window */
718 Assert.IsTrue (c.Bounds.IsEmpty, "A6");
719 Assert.IsTrue (c.Size.IsEmpty, "A7");
720 Assert.IsTrue (c.ClientSize.IsEmpty, "A8");
721 Assert.IsTrue (c.ClientRectangle.IsEmpty, "A9");
725 [Ignore ("Depends on specific DPI")]
726 public void FontHeightTest ()
728 MockControl c = new MockControl ();
729 Assert.AreEqual (13, c.font_height);
733 public void FontTest ()
735 Control c = new Control ();
736 Assert.IsFalse (c.Font.Bold, "#A1");
737 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#A2");
738 Assert.IsFalse (c.Font.Italic, "#A3");
739 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#A4");
740 Assert.AreEqual (8.25, c.Font.Size, "#A5");
741 Assert.AreEqual (8.25, c.Font.SizeInPoints, "#A6");
742 Assert.IsFalse (c.Font.Strikeout, "#A7");
743 Assert.IsFalse (c.Font.Underline, "#A8");
744 Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#A9");
746 Assert.IsTrue (c.Font.IsSystemFont, "#A10");
749 c.Font = new Font (c.Font.FontFamily, 3, FontStyle.Italic);
750 Assert.IsFalse (c.Font.Bold, "#B1");
751 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#B2");
752 Assert.IsTrue (c.Font.Italic, "#B3");
753 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#B4");
754 Assert.AreEqual (3, c.Font.Size, "#B5");
755 Assert.AreEqual (3, c.Font.SizeInPoints, "#B6");
756 Assert.IsFalse (c.Font.Strikeout, "#B7");
757 Assert.IsFalse (c.Font.Underline, "#B8");
758 Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#B9");
760 Assert.AreEqual (false, c.Font.IsSystemFont, "#B10");
765 [Category ("NotWorking")] // on Unix mapping is done to Bitstream Vera Sans
766 public void FontTest_Names ()
768 Control c = new Control ();
769 Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#1");
770 Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#2");
774 public void PubPropTest()
776 Control c = new Control();
778 Assert.IsFalse (c.AllowDrop , "A1");
779 Assert.AreEqual(AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "A2");
781 Assert.AreEqual ("Control", c.BackColor.Name , "B1");
782 Assert.IsNull (c.BackgroundImage, "B2");
783 Assert.IsNull (c.BindingContext, "B3");
785 Assert.AreEqual (ImageLayout.Tile, c.BackgroundImageLayout, "B4");
788 Assert.IsFalse (c.CanFocus, "C1");
789 Assert.IsTrue (c.CanSelect, "C2");
790 Assert.IsFalse (c.Capture, "C3");
791 Assert.IsTrue (c.CausesValidation, "C4");
793 Assert.IsNotNull (c.CompanyName, "C7");
794 Assert.IsNull (c.Container, "C8");
795 Assert.IsFalse (c.ContainsFocus, "C9");
796 Assert.IsNull (c.ContextMenu, "C10");
797 Assert.AreEqual (0, c.Controls.Count, "C11");
798 Assert.IsFalse (c.Created, "C12");
799 Assert.AreEqual (Cursors.Default, c.Cursor, "C13");
801 Assert.IsNotNull(c.DataBindings, "D1");
802 Assert.AreEqual("Control", Control.DefaultBackColor.Name, "D2");
803 Assert.AreEqual("ControlText", Control.DefaultForeColor.Name, "D3");
804 Assert.AreEqual(FontStyle.Regular, Control.DefaultFont.Style, "D4");
805 Assert.AreEqual (new Rectangle(0, 0, 0, 0), c.DisplayRectangle , "D5");
806 Assert.IsFalse (c.Disposing, "D6");
807 Assert.AreEqual(DockStyle.None, c.Dock, "D7");
809 Assert.IsTrue (c.Enabled, "E1");
811 Assert.IsFalse (c.Focused, "F1");
812 Assert.AreEqual (FontStyle.Regular, c.Font.Style, "F2");
813 Assert.AreEqual (SystemColors.ControlText, c.ForeColor, "F3");
815 Assert.IsFalse (c.HasChildren, "H2");
817 Assert.AreEqual (ImeMode.NoControl, c.ImeMode, "I1");
818 Assert.IsFalse (c.InvokeRequired, "I2");
819 Assert.IsFalse (c.IsAccessible, "I3");
820 Assert.IsFalse (c.IsDisposed, "I4");
821 Assert.IsFalse (c.IsHandleCreated, "I5");
823 Assert.AreEqual(Point.Empty, c.Location, "L2");
826 Assert.IsTrue(c.MaximumSize.IsEmpty);
827 Assert.IsTrue(c.MinimumSize.IsEmpty);
829 Assert.AreEqual (Keys.None, Control.ModifierKeys, "M1");
830 Assert.IsTrue (Control.MousePosition.X >= 0 && Control.MousePosition.Y >= 0, "M2");
831 Assert.AreEqual (MouseButtons.None, Control.MouseButtons, "M3");
833 Assert.AreEqual("", c.Name, "N1");
834 c.Name = "Control Name";
835 Assert.AreEqual("Control Name", c.Name, "N2");
837 Assert.IsNull (c.Parent, "P1");
838 Assert.IsNotNull (c.ProductName, "P2");
839 Assert.IsTrue (c.ProductName != "", "P3");
840 Assert.IsNotNull (c.ProductVersion, "P4");
841 Assert.IsTrue (c.ProductVersion != "", "P5");
843 Assert.IsFalse (c.RecreatingHandle, "R1");
844 Assert.IsNull (c.Region, "R2");
845 Assert.AreEqual (RightToLeft.No, c.RightToLeft, "R4");
847 Assert.IsNull (c.Site, "S1");
849 Assert.AreEqual (0, c.TabIndex , "T1");
850 Assert.IsTrue (c.TabStop, "T2");
851 Assert.IsNull (c.Tag, "T3");
852 Assert.AreEqual ("", c.Text, "T4");
854 Assert.IsTrue (c.Visible, "V1");
858 public void SizeChangeTest ()
860 Form f = new Form ();
861 Control c = new Control ();
864 c.Resize += new EventHandler(SizeChangedTest_ResizeHandler);
867 Assert.AreEqual (true, (bool) c.Tag, "#1");
871 private void SizeChangedTest_ResizeHandler (object sender, EventArgs e)
873 ((Control) sender).Tag = false;
877 public void NegativeHeightTest ()
879 Control c = new Control ();
880 IntPtr handle = c.Handle;
881 c.Resize += new EventHandler(NegativeHeightTest_ResizeHandler);
885 Assert.AreEqual (0, (int) c.Tag, "#1");
887 Assert.AreEqual (handle, handle, "Removes warning.");
890 private void NegativeHeightTest_ResizeHandler (object sender, EventArgs e)
892 Control c = (Control) sender;
897 public void TopLevelControlTest () {
898 Control c = new Control ();
900 Assert.AreEqual(null, c.TopLevelControl, "T1");
902 Panel p = new Panel ();
906 Assert.AreEqual(null, c.TopLevelControl, "T2");
908 Form f = new Form ();
909 f.ShowInTaskbar = false;
913 Assert.AreEqual (f, c.TopLevelControl, "T3");
914 Assert.AreEqual (f, f.TopLevelControl, "T4");
918 public void RelationTest() {
925 Assert.AreEqual(true , c1.Visible , "Rel1");
926 Assert.AreEqual(false, c1.Contains(c2) , "Rel2");
927 Assert.AreEqual("System.Windows.Forms.Control", c1.ToString() , "Rel3");
930 Assert.AreEqual(true , c2.Visible , "Rel4");
931 Assert.AreEqual(true, c1.Contains(c2) , "Rel5");
933 c1.Anchor = AnchorStyles.Top;
935 c1.Anchor = AnchorStyles.Left ;
937 Assert.AreEqual(AnchorStyles.Left , c1.Anchor, "Rel6");
939 c1.SetBounds(10, 20, 30, 40) ;
940 Assert.AreEqual(new Rectangle(10, 20, 30, 40), c1.Bounds, "Rel7");
942 Assert.AreEqual(c1, c2.Parent, "Rel8");
946 public void AnchorDockTest ()
948 Control c = new Control ();
950 Assert.AreEqual (DockStyle.None, c.Dock, "1");
951 Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "2");
953 c.Dock = DockStyle.Top;
954 Assert.AreEqual (DockStyle.Top, c.Dock, "3");
955 Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "4");
957 c.Anchor = AnchorStyles.Top;
958 Assert.AreEqual (DockStyle.None, c.Dock, "5");
959 Assert.AreEqual (AnchorStyles.Top, c.Anchor, "6");
963 [Category ("NotWorking")]
964 public void TabOrder()
969 Label label1 = new Label(); // To test non-tabstop items as well
970 Label label2 = new Label();
972 GroupBox group1 = new GroupBox();
973 GroupBox group2 = new GroupBox();
974 GroupBox group3 = new GroupBox();
976 TextBox text1 = new TextBox();
978 RadioButton radio11 = new RadioButton();
979 RadioButton radio12 = new RadioButton();
980 RadioButton radio13 = new RadioButton();
981 RadioButton radio14 = new RadioButton();
982 RadioButton radio21 = new RadioButton();
983 RadioButton radio22 = new RadioButton();
984 RadioButton radio23 = new RadioButton();
985 RadioButton radio24 = new RadioButton();
986 RadioButton radio31 = new RadioButton();
987 RadioButton radio32 = new RadioButton();
988 RadioButton radio33 = new RadioButton();
989 RadioButton radio34 = new RadioButton();
992 form.ShowInTaskbar = false;
994 form.ClientSize = new Size (520, 520);
995 Assert.AreEqual(new Size(520, 520), form.ClientSize, "Tab1");
997 form.Text = "SWF Taborder Test App Form";
998 Assert.AreEqual("SWF Taborder Test App Form", form.Text, "Tab2");
1000 label1.Location = new Point(10, 10);
1001 Assert.AreEqual(new Point(10, 10), label1.Location, "Tab3");
1002 label1.Text = "Label1";
1003 form.Controls.Add(label1);
1005 label2.Location = new Point(200, 10);
1006 label2.Text = "Label2";
1007 form.Controls.Add(label2);
1009 group1.Text = "Group1";
1010 group2.Text = "Group2";
1011 group3.Text = "Group3";
1013 group1.Size = new Size(200, 400);
1014 group2.Size = new Size(200, 400);
1015 group3.Size = new Size(180, 180);
1016 Assert.AreEqual(new Size(180, 180), group3.Size, "Tab4");
1018 group1.Location = new Point(10, 40);
1019 group2.Location = new Point(220, 40);
1020 group3.Location = new Point(10, 210);
1022 group1.TabIndex = 30;
1023 Assert.AreEqual(30, group1.TabIndex, "Tab5");
1024 group1.TabStop = true;
1026 // Don't assign, test automatic assignment
1027 //group2.TabIndex = 0;
1028 group2.TabStop = true;
1029 Assert.AreEqual(0, group2.TabIndex, "Tab6");
1031 group3.TabIndex = 35;
1032 group3.TabStop = true;
1034 // Test default tab index
1035 Assert.AreEqual(0, radio11.TabIndex, "Tab7");
1037 text1.Text = "Edit Control";
1039 radio11.Text = "Radio 1-1 [Tab1]";
1040 radio12.Text = "Radio 1-2 [Tab2]";
1041 radio13.Text = "Radio 1-3 [Tab3]";
1042 radio14.Text = "Radio 1-4 [Tab4]";
1044 radio21.Text = "Radio 2-1 [Tab4]";
1045 radio22.Text = "Radio 2-2 [Tab3]";
1046 radio23.Text = "Radio 2-3 [Tab2]";
1047 radio24.Text = "Radio 2-4 [Tab1]";
1049 radio31.Text = "Radio 3-1 [Tab1]";
1050 radio32.Text = "Radio 3-2 [Tab3]";
1051 radio33.Text = "Radio 3-3 [Tab2]";
1052 radio34.Text = "Radio 3-4 [Tab4]";
1054 // We don't assign TabIndex for radio1X; test automatic assignment
1055 text1.TabStop = true;
1056 radio11.TabStop = true;
1058 radio21.TabIndex = 4;
1059 radio22.TabIndex = 3;
1060 radio23.TabIndex = 2;
1061 radio24.TabIndex = 1;
1062 radio24.TabStop = true;
1064 radio31.TabIndex = 11;
1065 radio31.TabStop = true;
1066 radio32.TabIndex = 13;
1067 radio33.TabIndex = 12;
1068 radio34.TabIndex = 14;
1070 text1.Location = new Point(10, 100);
1072 radio11.Location = new Point(10, 20);
1073 radio12.Location = new Point(10, 40);
1074 radio13.Location = new Point(10, 60);
1075 radio14.Location = new Point(10, 80);
1077 radio21.Location = new Point(10, 20);
1078 radio22.Location = new Point(10, 40);
1079 radio23.Location = new Point(10, 60);
1080 radio24.Location = new Point(10, 80);
1082 radio31.Location = new Point(10, 20);
1083 radio32.Location = new Point(10, 40);
1084 radio33.Location = new Point(10, 60);
1085 radio34.Location = new Point(10, 80);
1087 text1.Size = new Size(150, text1.PreferredHeight);
1089 radio11.Size = new Size(150, 20);
1090 radio12.Size = new Size(150, 20);
1091 radio13.Size = new Size(150, 20);
1092 radio14.Size = new Size(150, 20);
1094 radio21.Size = new Size(150, 20);
1095 radio22.Size = new Size(150, 20);
1096 radio23.Size = new Size(150, 20);
1097 radio24.Size = new Size(150, 20);
1099 radio31.Size = new Size(150, 20);
1100 radio32.Size = new Size(150, 20);
1101 radio33.Size = new Size(150, 20);
1102 radio34.Size = new Size(150, 20);
1104 group1.Controls.Add(text1);
1106 group1.Controls.Add(radio11);
1107 group1.Controls.Add(radio12);
1108 group1.Controls.Add(radio13);
1109 group1.Controls.Add(radio14);
1111 group2.Controls.Add(radio21);
1112 group2.Controls.Add(radio22);
1113 group2.Controls.Add(radio23);
1114 group2.Controls.Add(radio24);
1116 group3.Controls.Add(radio31);
1117 group3.Controls.Add(radio32);
1118 group3.Controls.Add(radio33);
1119 group3.Controls.Add(radio34);
1121 form.Controls.Add(group1);
1122 form.Controls.Add(group2);
1123 group2.Controls.Add(group3);
1125 // Perform some tests, the TabIndex stuff below will alter the outcome
1126 Assert.AreEqual(null, Helper.TestControl(group2, radio34, true), "Tab8");
1127 Assert.AreEqual(31, group2.TabIndex, "Tab9");
1129 // Does the taborder of containers and non-selectable things change behaviour?
1130 label1.TabIndex = 5;
1131 label2.TabIndex = 4;
1132 group1.TabIndex = 3;
1133 group2.TabIndex = 1;
1135 // Start verification
1136 Assert.AreEqual(null, Helper.TestControl(group2, radio34, true), "Tab10");
1137 Assert.AreEqual(radio24.Text, Helper.TestControl(group2, group2, true), "Tab11");
1138 Assert.AreEqual(radio31.Text, Helper.TestControl(group2, group3, true), "Tab12");
1139 Assert.AreEqual(null, Helper.TestControl(group1, radio14, true), "Tab13");
1140 Assert.AreEqual(radio23.Text, Helper.TestControl(group2, radio24, true), "Tab14");
1141 Assert.AreEqual(group3.Text, Helper.TestControl(group2, radio21, true), "Tab15");
1142 Assert.AreEqual(radio13.Text, Helper.TestControl(form, radio12, true), "Tab16");
1143 Assert.AreEqual(label2.Text, Helper.TestControl(form, radio14, true), "Tab17");
1144 Assert.AreEqual(group1.Text, Helper.TestControl(form, radio34, true), "Tab18");
1145 Assert.AreEqual(radio23.Text, Helper.TestControl(group2, radio24, true), "Tab19");
1148 Assert.AreEqual(null, Helper.TestControl(radio11, radio21, true), "Tab20");
1149 Assert.AreEqual(text1.Text, Helper.TestControl(group1, radio21, true), "Tab21");
1151 Assert.AreEqual(radio14.Text, Helper.TestControl(form, label2, false), "Tab22");
1152 Assert.AreEqual(radio21.Text, Helper.TestControl(group2, group3, false), "Tab23");
1154 Assert.AreEqual(4, radio21.TabIndex, "Tab24");
1155 Assert.AreEqual(1, radio11.TabIndex, "Tab25");
1156 Assert.AreEqual(3, radio13.TabIndex, "Tab26");
1157 Assert.AreEqual(35, group3.TabIndex, "Tab27");
1158 Assert.AreEqual(1, group2.TabIndex, "Tab28");
1160 Assert.AreEqual(label1.Text, Helper.TestControl(form, form, false), "Tab29");
1161 Assert.AreEqual(radio14.Text, Helper.TestControl(group1, group1, false), "Tab30");
1162 Assert.AreEqual(radio34.Text, Helper.TestControl(group3, group3, false), "Tab31");
1164 Assert.AreEqual(null, Helper.TestControl(label1, label1, false), "Tab31");
1165 Assert.AreEqual(null, Helper.TestControl(radio11, radio21, false), "Tab32");
1170 public void ScaleTest()
1172 Control r1 = new Control();
1177 Assert.AreEqual(80, r1.Width, "Scale1");
1178 Assert.AreEqual(40, r1.Height, "Scale2");
1183 public void ScaleChildrenTest ()
1185 ScaleChildrenControl c = new ScaleChildrenControl ();
1186 Assert.AreEqual (true, c.PublicScaleChildren, "A1");
1189 private class ScaleChildrenControl : Control
1191 public bool PublicScaleChildren {
1192 get { return base.ScaleChildren; }
1197 public void ScaleControlTest ()
1199 ScaleControl c = new ScaleControl ();
1201 c.Location = new Point (5, 10);
1202 c.Size = new Size (15, 20);
1204 Assert.AreEqual (new Rectangle (5, 10, 15, 20), c.Bounds, "A1");
1206 c.PublicScaleControl (new SizeF (1.5f, 1.3f), BoundsSpecified.All);
1207 Assert.AreEqual (new Rectangle (8, 13, 22, 26), c.Bounds, "A2");
1209 c.PublicScaleControl (new SizeF (2f, 1.5f), BoundsSpecified.Location);
1210 Assert.AreEqual (new Rectangle (16, 20, 22, 26), c.Bounds, "A3");
1212 c.PublicScaleControl (new SizeF (1.5f, 2f), BoundsSpecified.Size);
1213 Assert.AreEqual (new Rectangle (16, 20, 33, 52), c.Bounds, "A4");
1215 c.PublicScaleControl (new SizeF (1.5f, 1.5f), BoundsSpecified.Width);
1216 Assert.AreEqual (new Rectangle (16, 20, 50, 52), c.Bounds, "A5");
1218 c.PublicScaleControl (new SizeF (1.5f, 1.3f), BoundsSpecified.None);
1219 Assert.AreEqual (new Rectangle (16, 20, 50, 52), c.Bounds, "A6");
1221 // Test with ScaleChildren
1222 c = new ScaleControl ();
1224 c.Location = new Point (5, 10);
1225 c.Size = new Size (50, 50);
1227 Control c2 = new Control ();
1228 c2.Location = new Point (15, 15);
1229 c2.Size = new Size (25, 25);
1230 c.Controls.Add (c2);
1232 Assert.AreEqual (new Rectangle (5, 10, 50, 50), c.Bounds, "B1");
1233 Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B2");
1235 c.scale_children = false;
1237 c.PublicScaleControl (new SizeF (2f, 2f), BoundsSpecified.All);
1238 Assert.AreEqual (new Rectangle (10, 20, 100, 100), c.Bounds, "B3");
1239 Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B4");
1241 c.scale_children = true;
1243 // Will not scale children in ScaleControl
1244 c.PublicScaleControl (new SizeF (2f, 2f), BoundsSpecified.All);
1245 Assert.AreEqual (new Rectangle (20, 40, 200, 200), c.Bounds, "B5");
1246 Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B6");
1248 // Does scale children in Scale
1249 c.Scale (new SizeF (2f, 2f));
1250 Assert.AreEqual (new Rectangle (40, 80, 400, 400), c.Bounds, "B7");
1251 Assert.AreEqual (new Rectangle (30, 30, 50, 50), c2.Bounds, "B8");
1255 public void GetScaledBoundsTest ()
1257 ScaleControl c = new ScaleControl ();
1259 Rectangle r = new Rectangle (10, 20, 30, 40);
1261 Assert.AreEqual (new Rectangle (20, 10, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A1");
1262 Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A2");
1263 Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A3");
1264 Assert.AreEqual (new Rectangle (10, 20, 30, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A4");
1265 Assert.AreEqual (new Rectangle (20, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A5");
1266 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A6");
1268 c.PublicSetTopLevel (true);
1270 Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A7");
1271 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A8");
1272 Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A9");
1273 Assert.AreEqual (new Rectangle (10, 20, 30, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A10");
1274 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A11");
1275 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A12");
1277 c = new ScaleControl ();
1278 c.PublicSetStyle (ControlStyles.FixedHeight, true);
1279 c.PublicSetStyle (ControlStyles.FixedWidth, true);
1281 Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A13");
1282 Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A14");
1283 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A15");
1284 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A16");
1285 Assert.AreEqual (new Rectangle (20, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A17");
1286 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A18");
1289 private class ScaleControl : Control
1291 public bool scale_children = true;
1293 public void PublicScaleControl (SizeF factor, BoundsSpecified specified)
1295 base.ScaleControl (factor, specified);
1298 public Rectangle PublicGetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
1300 return base.GetScaledBounds (bounds, factor, specified);
1303 public void PublicSetStyle (ControlStyles flag, bool value)
1305 base.SetStyle (flag, value);
1308 public void PublicSetTopLevel (bool value)
1310 base.SetTopLevel (value);
1313 protected override bool ScaleChildren {
1314 get { return scale_children; }
1319 class TestWindowTarget : IWindowTarget
1321 public void OnHandleChange (IntPtr newHandle) {
1324 public void OnMessage (ref Message m) {
1329 public void WindowTargetTest()
1331 Control c = new Control ();
1332 Assert.IsNotNull (c.WindowTarget, "WindowTarget1");
1333 c.WindowTarget = null;
1334 Assert.IsNull (c.WindowTarget, "WindowTarget2");
1336 IWindowTarget existing_target = c.WindowTarget;
1337 IWindowTarget new_target = new TestWindowTarget ();
1338 c.WindowTarget = new_target;
1339 Assert.AreSame (new_target, c.WindowTarget, "WindowTarget3");
1341 TestHelper.RemoveWarning (existing_target);
1345 public void TextTest()
1347 Control r1 = new Control();
1349 Assert.AreEqual("Hi" , r1.Text , "Text1");
1352 Assert.AreEqual("" , r1.Text , "Text2");
1356 public void PubMethodTest7()
1358 Control r1 = new Control();
1359 r1.RightToLeft = RightToLeft.Yes ;
1360 r1.ResetRightToLeft() ;
1361 Assert.AreEqual(RightToLeft.No , r1.RightToLeft , "#81");
1362 r1.ImeMode = ImeMode.Off ;
1363 r1.ResetImeMode () ;
1364 Assert.AreEqual(ImeMode.NoControl , r1.ImeMode , "#82");
1365 r1.ForeColor= SystemColors.GrayText ;
1366 r1.ResetForeColor() ;
1367 Assert.AreEqual(SystemColors.ControlText , r1.ForeColor , "#83");
1368 //r1.Font = Font.FromHdc();
1370 //Assert.AreEqual(FontFamily.GenericSansSerif , r1.Font , "#83");
1371 r1.Cursor = Cursors.Hand ;
1373 Assert.AreEqual(Cursors.Default , r1.Cursor , "#83");
1374 //r1.DataBindings = System.Windows.Forms.Binding ;
1375 //r1.ResetBindings() ;
1376 //Assert.AreEqual(ControlBindingsCollection , r1.DataBindings , "#83");
1377 r1.BackColor = Color.Black ;
1378 r1.ResetBackColor() ;
1379 Assert.AreEqual( SystemColors.Control , r1.BackColor , "#84");
1380 r1.BackColor = Color.Black ;
1382 Assert.AreEqual( null , r1.Region , "#85");
1383 Rectangle M = new Rectangle(10, 20, 30 ,40);
1384 r1.RectangleToScreen(M) ;
1385 Assert.AreEqual( null , r1.Region , "#86");
1389 public void ScreenClientCoords()
1400 p1 = new Point (10,10);
1401 p2 = l.PointToScreen(p1);
1402 p3 = l.PointToClient(p2);
1404 Assert.AreEqual (p1, p3, "SC1");
1408 public void ContainsTest ()
1410 Control t = new Control ();
1411 Control s = new Control ();
1415 Assert.AreEqual (true, t.Contains (s), "Con1");
1416 Assert.AreEqual (false, s.Contains (t), "Con2");
1417 Assert.AreEqual (false, s.Contains (null), "Con3");
1418 Assert.AreEqual (false, t.Contains (new Control ()), "Con4");
1422 public void IsHandleCreated_NotVisible ()
1424 Control c = new Control ();
1427 Form form = new Form ();
1428 form.ShowInTaskbar = false;
1429 form.Controls.Add (c);
1432 Assert.IsFalse (c.IsHandleCreated, "#1");
1434 Assert.IsTrue (c.IsHandleCreated, "#2");
1436 Assert.IsTrue (c.IsHandleCreated, "#3");
1440 class OnCreateControlTest : Control {
1441 public bool reached = false;
1442 protected override void OnCreateControl () {
1448 public void CreateControlVisibleTest ()
1450 OnCreateControlTest test = new OnCreateControlTest ();
1451 test.Visible = false;
1452 Assert.IsFalse (test.IsHandleCreated, "0");
1453 Assert.IsFalse (test.Visible, "1");
1454 test.Visible = true;
1455 Assert.IsTrue (test.Visible, "2");
1456 Assert.IsTrue (test.reached, "3");
1461 public void CreateGraphicsTest ()
1467 Control c = new Control ();
1468 c.SetBounds (0,0, 20, 20);
1469 g = c.CreateGraphics ();
1470 Assert.IsNotNull (g, "Graph1");
1479 bool delegateCalled = false;
1480 public delegate void TestDelegate ();
1482 public void delegate_call () {
1483 delegateCalled = true;
1485 TestHelper.RemoveWarning (delegateCalled);
1489 [ExpectedException(typeof(InvalidOperationException))]
1490 public void InvokeException1 () {
1491 Control c = new Control ();
1492 IAsyncResult result;
1494 result = c.BeginInvoke (new TestDelegate (delegate_call));
1495 c.EndInvoke (result);
1499 public void FindFormTest () {
1500 Form f = new Form ();
1502 f.ShowInTaskbar = false;
1507 f.Controls.Add (c = new Control ());
1508 Assert.AreEqual (f.Name, c.FindForm ().Name, "Find1");
1510 f.Controls.Remove (c);
1512 GroupBox g = new GroupBox ();
1517 Assert.AreEqual (f.Name, f.FindForm ().Name, "Find2");
1519 g.Controls.Remove (c);
1520 Assert.IsNull(c.FindForm (), "Find3");
1531 public void FocusTest ()
1534 Button c = null, d = null;
1538 f.ShowInTaskbar = false;
1548 Assert.IsTrue (c.CanFocus, "Focus1");
1549 Assert.IsFalse (c.Focused, "Focus2");
1551 Assert.IsTrue (c.Focused, "Focus3");
1553 Assert.IsFalse (d.Focused, "Focus4");
1557 Assert.IsTrue (d.Focused, "Focus5");
1558 Assert.IsFalse (c.Focused, "Focus6");
1561 Assert.IsFalse (c.Focused, "Focus7");
1573 public void FromHandleTest ()
1579 c1 = new Control ();
1580 c2 = new Control ();
1584 c1.Controls.Add(c2);
1587 Assert.AreEqual (c1.Name, Control.FromHandle (c1.Handle).Name, "Handle1");
1588 Assert.IsNull (Control.FromHandle (IntPtr.Zero), "Handle2");
1591 Assert.AreEqual (c1.Name, Control.FromChildHandle (c1.Handle).Name, "Handle3");
1592 Assert.IsNull (Control.FromChildHandle (IntPtr.Zero), "Handle4");
1605 public void GetChildAtPointTest ()
1607 Control c = null, d = null;
1608 TransparentControl e = null;
1613 c.SetBounds (0, 0, 100, 100);
1617 d.SetBounds (10, 10, 40, 40);
1620 e = new TransparentControl ();
1622 e.SetBounds (55, 55, 10, 10);
1624 Control l = c.GetChildAtPoint (new Point (15, 15));
1625 Assert.AreEqual (d.Name, l.Name, "Child1");
1626 Assert.IsFalse (e.Name == l.Name, "Child2");
1628 l = c.GetChildAtPoint (new Point (57, 57));
1629 Assert.AreEqual (null, l, "Child3");
1631 l = c.GetChildAtPoint (new Point (10, 10));
1632 Assert.AreEqual (d.Name, l.Name, "Child4");
1634 // GetChildAtPointSkip is not implemented and the following test is breaking for Net_2_0 profile
1638 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
1639 Assert.IsNull (l, "Child5");
1642 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
1643 Assert.AreSame (e.Name, l.Name, "Child6");
1646 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Disabled);
1647 Assert.IsNull (l, "Child7");
1650 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Disabled);
1651 Assert.AreSame (e.Name, l.Name, "Child8");
1654 e.BackColor = Color.Transparent;
1655 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Transparent);
1656 Assert.IsNull (l, "Child9");
1658 e.BackColor = Color.Green;
1659 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Transparent);
1660 Assert.AreSame (e.Name, l.Name, "Child10");
1671 private class TransparentControl : Control
1673 public TransparentControl ()
1675 SetStyle (ControlStyles.SupportsTransparentBackColor, true);
1678 protected override CreateParams CreateParams
1682 CreateParams cp = base.CreateParams;
1683 cp.ExStyle |= 0x00000020;
1690 public void ResetFontTest ()
1692 Control c = new Control ();
1693 c.Font = new Font (c.Font.FontFamily, 3, FontStyle.Italic);
1696 Assert.IsFalse (c.Font.Bold, "#1");
1697 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#2");
1698 Assert.IsFalse (c.Font.Italic, "#3");
1699 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#4");
1700 Assert.AreEqual (8.25, c.Font.Size, "#5");
1701 Assert.AreEqual (8.25, c.Font.SizeInPoints, "#6");
1702 Assert.IsFalse (c.Font.Strikeout, "#7");
1703 Assert.IsFalse (c.Font.Underline, "#8");
1704 Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#9");
1706 Assert.AreEqual (true, c.Font.IsSystemFont, "#10");
1710 public class LayoutTestControl : Control {
1711 public int LayoutCount;
1713 public LayoutTestControl () : base() {
1717 protected override void OnLayout(LayoutEventArgs levent) {
1719 base.OnLayout (levent);
1724 public void LayoutTest() {
1725 LayoutTestControl c;
1727 c = new LayoutTestControl();
1734 c.ResumeLayout(true);
1736 c.ResumeLayout(true);
1738 c.ResumeLayout(true);
1740 c.ResumeLayout(true);
1742 c.ResumeLayout(true);
1744 c.ResumeLayout(true);
1746 c.ResumeLayout(true);
1751 Assert.AreEqual(5, c.LayoutCount, "Layout Suspend/Resume locking does not bottom out at 0");
1755 [ExpectedException(typeof(ArgumentException))]
1756 public void TransparentBackgroundTest1() {
1760 c.BackColor = Color.Transparent;
1764 public void TransparentBackgroundTest2() {
1768 c.BackColor = Color.Transparent;
1769 Assert.AreEqual(Color.Transparent, c.BackColor, "Transparent background not set");
1773 public void TransparentBackgroundTest3() {
1777 c.BackColor = Color.Empty;
1778 Assert.AreEqual(Control.DefaultBackColor, c.BackColor, "Setting empty color failed");
1782 public void Dock_Value_Invalid ()
1784 Control c = new Control ();
1786 c.Dock = (DockStyle) 666;
1788 } catch (InvalidEnumArgumentException ex) {
1789 Assert.AreEqual (typeof (InvalidEnumArgumentException), ex.GetType (), "#2");
1790 Assert.IsNotNull (ex.Message, "#3");
1791 Assert.IsNotNull (ex.ParamName, "#4");
1792 Assert.AreEqual ("value", ex.ParamName, "#5");
1793 Assert.IsNull (ex.InnerException, "#6");
1798 public void EnabledTest1() {
1803 grandma = new Control();
1804 parent = new Control();
1805 child = new Control();
1807 grandma.Controls.Add(parent);
1808 parent.Controls.Add(child);
1809 grandma.Enabled = false;
1810 Assert.AreEqual(grandma.Enabled, child.Enabled, "Child did not inherit disabled state");
1813 int EnabledCalledCount = 0;
1814 private void EnabledTest2EnabledChanged(object sender, EventArgs e) {
1815 EnabledCalledCount++;
1819 public void EnabledTest2() {
1820 // Check nesting of enabled calls
1821 // OnEnabled is not called for disabled child controls
1826 EnabledCalledCount = 0;
1828 grandma = new Control();
1829 parent = new Control();
1830 child = new Control();
1831 child.EnabledChanged += new EventHandler(EnabledTest2EnabledChanged);
1833 grandma.Controls.Add(parent);
1834 parent.Controls.Add(child);
1835 grandma.Enabled = false;
1837 Assert.AreEqual(1, EnabledCalledCount, "Child Enabled Event not properly fired");
1838 grandma.Enabled = true;
1839 Assert.AreEqual(2, EnabledCalledCount, "Child Enabled Event not properly fired");
1840 child.Enabled = false;
1841 grandma.Enabled = false;
1842 Assert.AreEqual(3, EnabledCalledCount, "Child Enabled Event not properly fired");
1846 public void ControlsRemoveNullTest ()
1848 Control c = new Control ();
1849 c.Controls.Remove (null);
1853 public void ControlsAddNullTest ()
1855 Control c = new Control ();
1856 c.Controls.Add (null);
1860 [ExpectedException (typeof (ArgumentNullException))]
1861 public void ControlsSetChildIndexNullTest ()
1863 Control c = new Control ();
1864 c.Controls.SetChildIndex (null, 1);
1868 [ExpectedException (typeof (ArgumentNullException))]
1869 public void ControlsAddRangeNullTest ()
1871 Control c = new Control ();
1872 c.Controls.AddRange (null);
1876 public void ControlsAddRangeNullElementTest ()
1878 Control c = new Control ();
1879 Control[] subcontrols = new Control[2];
1880 subcontrols[0] = new Control ();
1881 subcontrols[1] = null;
1883 c.Controls.AddRange (subcontrols);
1887 public void RegionTest () {
1888 Form f = new Form ();
1889 f.ShowInTaskbar = false;
1890 Control c = new Control ();
1892 Assert.IsNull (c.Region, "#A1");
1894 Assert.IsNull (c.Region, "#A2");
1896 Assert.IsNull (c.Region, "#A3");
1899 Region region = new Region ();
1901 f.ShowInTaskbar = false;
1905 Assert.IsNotNull (c.Region, "#B1");
1906 Assert.AreSame (region, c.Region, "#B2");
1909 Assert.IsNull (c.Region, "#B3");
1914 [Test] // bug #80280
1915 public void Validated_Multiple_Containers ()
1917 Form form = new Form ();
1918 form.ShowInTaskbar = false;
1920 UserControl control1 = new UserControl();
1921 UserControl container1 = new UserControl();
1922 control1.Tag = true;
1923 control1.Validated += new EventHandler (Control_ValidatedHandler);
1924 container1.Controls.Add(control1);
1925 form.Controls.Add (container1);
1927 UserControl container2 = new UserControl();
1928 UserControl control2 = new UserControl();
1929 container2.Controls.Add(control2);
1930 form.Controls.Add (container2);
1932 Assert.IsTrue ((bool) control1.Tag, "#1");
1934 Assert.IsTrue ((bool) control1.Tag, "#2");
1936 Assert.IsFalse ((bool) control1.Tag, "#3");
1941 private void Control_ValidatedHandler (object sender, EventArgs e)
1943 ((Control) sender).Tag = false;
1948 public void UseWaitCursorTest ()
1950 Control c = new Control ();
1951 Assert.IsFalse (c.UseWaitCursor, "#1");
1952 c.Cursor = Cursors.Hand;
1953 c.UseWaitCursor = true;
1954 Assert.AreEqual (Cursors.WaitCursor, c.Cursor, "#2");
1955 c.UseWaitCursor = false;
1956 Assert.AreEqual (Cursors.Hand, c.Cursor, "#3");
1958 c.UseWaitCursor = true;
1959 c.Cursor = Cursors.Help;
1960 Assert.AreEqual (Cursors.WaitCursor, c.Cursor, "#4");
1961 Assert.AreEqual (true, c.UseWaitCursor, "#5");
1963 c.UseWaitCursor = false;
1964 Assert.AreEqual (Cursors.Help, c.Cursor, "#6");
1967 [Test] // bug #80621, #81125
1968 public void DontCallSizeFromClientSize ()
1970 SizeControl sc = new SizeControl ();
1972 Assert.AreEqual (0, sc.size_from_client_size_count, "A1");
1974 sc.ClientSize = new Size (300, 300);
1975 Assert.AreEqual (0, sc.size_from_client_size_count, "A2");
1977 SizeForm sf = new SizeForm ();
1978 sf.ShowInTaskbar = false;
1981 Assert.AreEqual (0, sc.size_from_client_size_count, "A3");
1983 sc.ClientSize = new Size (300, 300);
1984 Assert.AreEqual (0, sc.size_from_client_size_count, "A4");
1989 private class SizeControl : Control
1991 public int size_from_client_size_count = 0;
1993 protected override Size SizeFromClientSize (Size clientSize)
1995 size_from_client_size_count++;
1996 return base.SizeFromClientSize (clientSize);
2000 private class SizeForm : Form
2002 public int size_from_client_size_count = 0;
2004 protected override Size SizeFromClientSize (Size clientSize)
2006 size_from_client_size_count++;
2007 return base.SizeFromClientSize (clientSize);
2012 public class MockControl : Control
2014 public int font_height {
2015 get { return base.FontHeight; }
2016 set { base.FontHeight = value; }
2020 const int WM_KEYDOWN = 0x0100;
2021 const int WM_CHAR = 0x0102;
2022 const int WM_SYSCHAR = 0x0106;
2023 const int WM_KEYUP = 0x0101;
2027 public void MethodPreProcessControlMessage ()
2029 bool testing_callstack = false;
2031 MyControl c = new MyControl ();
2032 Message m = new Message ();
2035 m.WParam = (IntPtr)Keys.Down;
2036 m.LParam = IntPtr.Zero;
2038 if (testing_callstack) Console.WriteLine ("Start");
2039 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A1");
2040 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2042 c.SetState (State.OnPreviewKeyDown);
2043 if (testing_callstack) Console.WriteLine ("Start");
2044 Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A2");
2045 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2047 c.SetState (State.ProcessCmdKey);
2048 if (testing_callstack) Console.WriteLine ("Start");
2049 Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A3");
2050 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2052 c.SetState (State.IsInputKey);
2053 if (testing_callstack) Console.WriteLine ("Start");
2054 Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A4");
2055 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2057 c.SetState (State.ProcessDialogKey);
2058 if (testing_callstack) Console.WriteLine ("Start");
2059 Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A5");
2060 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2064 c.SetState (State.None);
2065 if (testing_callstack) Console.WriteLine ("Start");
2066 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A6");
2067 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2069 c.SetState (State.IsInputChar);
2070 if (testing_callstack) Console.WriteLine ("Start");
2071 Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A7");
2072 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2074 c.SetState (State.ProcessDialogChar);
2075 if (testing_callstack) Console.WriteLine ("Start");
2076 Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A8");
2077 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2081 c.SetState (State.None);
2082 if (testing_callstack) Console.WriteLine ("Start");
2083 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A9");
2084 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2086 c.SetState (State.IsInputChar);
2087 if (testing_callstack) Console.WriteLine ("Start");
2088 Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A10");
2089 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2091 c.SetState (State.ProcessDialogChar);
2092 if (testing_callstack) Console.WriteLine ("Start");
2093 Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A11");
2094 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2098 if (testing_callstack) Console.WriteLine ("Start");
2099 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A12");
2100 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2102 c.SetState (State.OnPreviewKeyDown);
2103 if (testing_callstack) Console.WriteLine ("Start");
2104 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A13");
2105 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2107 c.SetState (State.ProcessCmdKey);
2108 if (testing_callstack) Console.WriteLine ("Start");
2109 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A14");
2110 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2112 c.SetState (State.IsInputKey);
2113 if (testing_callstack) Console.WriteLine ("Start");
2114 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A15");
2115 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2117 c.SetState (State.ProcessDialogKey);
2118 if (testing_callstack) Console.WriteLine ("Start");
2119 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A16");
2120 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2125 public void MethodPreProcessMessage ()
2127 bool testing_callstack = false;
2129 MyControl c = new MyControl ();
2130 Message m = new Message ();
2133 m.WParam = (IntPtr)Keys.Down;
2134 m.LParam = IntPtr.Zero;
2136 if (testing_callstack) Console.WriteLine ("Start");
2137 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A1");
2138 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2140 c.SetState (State.OnPreviewKeyDown);
2141 if (testing_callstack) Console.WriteLine ("Start");
2142 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A2");
2143 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2145 c.SetState (State.ProcessCmdKey);
2146 if (testing_callstack) Console.WriteLine ("Start");
2147 Assert.AreEqual (true, c.PreProcessMessage (ref m), "A3");
2148 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2150 c.SetState (State.IsInputKey);
2151 if (testing_callstack) Console.WriteLine ("Start");
2152 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A4");
2153 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2155 c.SetState (State.ProcessDialogKey);
2156 if (testing_callstack) Console.WriteLine ("Start");
2157 Assert.AreEqual (true, c.PreProcessMessage (ref m), "A5");
2158 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2162 c.SetState (State.None);
2163 if (testing_callstack) Console.WriteLine ("Start");
2164 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A6");
2165 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2167 c.SetState (State.IsInputChar);
2168 if (testing_callstack) Console.WriteLine ("Start");
2169 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A7");
2170 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2172 c.SetState (State.ProcessDialogChar);
2173 if (testing_callstack) Console.WriteLine ("Start");
2174 Assert.AreEqual (true, c.PreProcessMessage (ref m), "A8");
2175 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2179 c.SetState (State.None);
2180 if (testing_callstack) Console.WriteLine ("Start");
2181 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A9");
2182 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2184 c.SetState (State.IsInputChar);
2185 if (testing_callstack) Console.WriteLine ("Start");
2186 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A10");
2187 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2189 c.SetState (State.ProcessDialogChar);
2190 if (testing_callstack) Console.WriteLine ("Start");
2191 Assert.AreEqual (true, c.PreProcessMessage (ref m), "A11");
2192 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2196 if (testing_callstack) Console.WriteLine ("Start");
2197 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A12");
2198 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2200 c.SetState (State.OnPreviewKeyDown);
2201 if (testing_callstack) Console.WriteLine ("Start");
2202 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A13");
2203 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2205 c.SetState (State.ProcessCmdKey);
2206 if (testing_callstack) Console.WriteLine ("Start");
2207 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A14");
2208 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2210 c.SetState (State.IsInputKey);
2211 if (testing_callstack) Console.WriteLine ("Start");
2212 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A15");
2213 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2215 c.SetState (State.ProcessDialogKey);
2216 if (testing_callstack) Console.WriteLine ("Start");
2217 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A16");
2218 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2232 private class MyControl : Control
2235 private State current_state;
2236 bool testing_callstack = false;
2238 public void SetState (State state)
2240 current_state = state;
2243 protected override bool ProcessCmdKey (ref Message msg, Keys keyData)
2245 if (testing_callstack) Console.Write ("ProcessCmdKey[");
2246 if (current_state == State.ProcessCmdKey) {
2247 if (testing_callstack) Console.WriteLine ("]");
2251 bool retval = base.ProcessCmdKey (ref msg, keyData);
2252 if (testing_callstack) Console.WriteLine ("]");
2257 protected override void OnPreviewKeyDown (PreviewKeyDownEventArgs e)
2259 if (testing_callstack) Console.Write ("OnPreviewKeyDown[");
2260 if (current_state == State.OnPreviewKeyDown) {
2261 e.IsInputKey = true;
2262 if (testing_callstack) Console.WriteLine ("]");
2266 base.OnPreviewKeyDown (e);
2267 if (testing_callstack) Console.WriteLine ("]");
2271 protected override bool IsInputChar (char charCode)
2273 if (testing_callstack) Console.Write ("IsInputChar[");
2274 if (current_state == State.IsInputChar) {
2275 if (testing_callstack) Console.WriteLine ("true]");
2279 bool retval = base.IsInputChar (charCode);
2280 if (testing_callstack) Console.WriteLine ("{0}]", retval.ToString ());
2284 protected override bool IsInputKey (Keys keyData)
2286 if (testing_callstack) Console.Write ("IsInputKey[");
2287 if (current_state == State.IsInputKey) {
2288 if (testing_callstack) Console.WriteLine ("]");
2292 bool retval = base.IsInputKey (keyData);
2293 if (testing_callstack) Console.WriteLine ("]");
2297 public override bool PreProcessMessage (ref Message msg)
2299 if (testing_callstack) Console.Write ("PreProcessMessage[");
2300 if (current_state == State.PreProcessMessage) {
2301 if (testing_callstack) Console.WriteLine ("]");
2305 bool retval = base.PreProcessMessage (ref msg);
2306 if (testing_callstack) Console.WriteLine ("]");
2310 protected override bool ProcessDialogKey (Keys keyData)
2312 if (testing_callstack) Console.Write ("ProcessDialogKey[");
2313 if (current_state == State.ProcessDialogKey) {
2314 if (testing_callstack) Console.WriteLine ("]");
2318 bool retval = base.ProcessDialogKey (keyData);
2319 if (testing_callstack) Console.WriteLine ("]");
2323 protected override bool ProcessDialogChar (char charCode)
2325 if (testing_callstack) Console.Write ("ProcessDialogChar[");
2326 if (current_state == State.ProcessDialogChar) {
2327 if (testing_callstack) Console.WriteLine ("]");
2331 bool retval = base.ProcessDialogChar (charCode);
2332 if (testing_callstack) Console.WriteLine ("]");
2338 public void MethodIsInputChar ()
2340 // Basically, show that this method always returns false
2341 InputCharControl m = new InputCharControl ();
2342 bool result = false;
2344 for (int i = 0; i < 256; i++)
2345 result |= m.PublicIsInputChar ((char)i);
2347 Assert.AreEqual (false, result, "I1");
2350 private class InputCharControl : Control
2352 public bool PublicIsInputChar (char charCode)
2354 return base.IsInputChar (charCode);
2359 [Test] // bug #81118, 81718
2360 public void VisibleTriggersLayout ()
2362 Form f = new Form ();
2363 f.ShowInTaskbar = false;
2365 Control c = new Control ();
2370 c.Dock = DockStyle.Fill;
2373 Assert.AreEqual (f.ClientSize.Width, c.Width, "L1");
2377 public void ResumeLayoutEffects ()
2379 Form f = new Form ();
2380 f.ShowInTaskbar = false;
2381 f.ClientSize = new Size (300, 300);
2383 Button button1 = new Button ();
2384 f.Controls.Add (button1);
2385 button1.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
2386 button1.Location = new Point (f.ClientSize.Width - button1.Width, f.ClientSize.Height - button1.Height);
2390 Assert.AreEqual (new Point (225, 277), button1.Location, "A1");
2394 f.ResumeLayout (false);
2397 Assert.AreEqual (new Point (225, 277), button1.Location, "A2");
2403 Assert.AreEqual (new Point (225, 287), button1.Location, "A3");
2409 public class ControlSetTopLevelTest
2411 class ControlPoker : Control {
2412 public void DoSetTopLevel ()
2416 public bool DoGetTopLevel ()
2418 return GetTopLevel ();
2423 public void TestControl ()
2425 ControlPoker c = new ControlPoker ();
2428 Assert.IsTrue (c.DoGetTopLevel (), "1");
2429 Assert.IsFalse (c.Visible, "2");
2433 [ExpectedException (typeof (ArgumentException))]
2434 public void TestChildControl ()
2436 Control c1 = new Control();
2437 ControlPoker c2 = new ControlPoker ();
2439 c1.Controls.Add (c2);
2440 c2.DoSetTopLevel ();
2444 [ExpectedException (typeof (ArgumentException))]
2445 public void TestTopLevelAdd () {
2446 Form f = new Form();
2447 Form f1 = new Form();
2451 [Category ("NotWorking")]
2453 public void TestForm ()
2455 Form f = new Form ();
2456 Assert.IsFalse (f.Visible, "3");
2458 Assert.IsFalse (f.Visible, "4");
2463 public class ControlResizeLayoutTest
2465 class ControlPoker : Control {
2466 public void DoOnResize ()
2468 OnResize (EventArgs.Empty);
2473 string child_affected_property;
2474 void ChildLayoutEvent (object sender, LayoutEventArgs e)
2477 child_affected_property = e.AffectedProperty;
2481 string parent_affected_property;
2482 void ParentLayoutEvent (object sender, LayoutEventArgs e)
2485 parent_affected_property = e.AffectedProperty;
2487 TestHelper.RemoveWarning (parent_affected_property);
2493 Panel p = new Panel ();
2494 ControlPoker c = new ControlPoker();
2498 p.Layout += new LayoutEventHandler (ParentLayoutEvent);
2499 c.Layout += new LayoutEventHandler (ChildLayoutEvent);
2503 Assert.AreEqual (1, child_event, "1");
2504 Assert.AreEqual ("Bounds", child_affected_property, "2");
2506 Assert.AreEqual (0, parent_event, "3");
2512 [Category ("NotWorking")]
2513 public class ControlInvokeTest {
2514 public delegate void TestDelegate ();
2519 ApplicationContext control_context;
2520 bool delegateCalled = false;
2521 bool threadDied = false;
2525 void CreateControl ()
2529 f.ShowInTaskbar = false;
2535 Console.WriteLine ("f.Handle = {0}", f.Handle);
2536 Console.WriteLine ("c.Handle = {0}", c.Handle);
2538 control_context = new ApplicationContext (f);
2541 Console.WriteLine ("pulsing");
2544 Console.WriteLine ("control thread running");
2545 Application.Run (control_context);
2547 Console.WriteLine ("dying");
2550 Console.WriteLine ("pulsing again");
2553 } catch (Exception e) { Console.WriteLine (e); }
2557 public void InvokeTest ()
2561 control_t = new Thread(new ThreadStart(CreateControl));
2567 Console.WriteLine ("waiting on monitor");
2570 Console.WriteLine ("making async call");
2572 IAsyncResult result;
2573 result = c.BeginInvoke (new TestDelegate (delegate_call));
2574 c.EndInvoke (result);
2576 Assert.IsTrue (delegateCalled, "Invoke1");
2579 Assert.IsTrue (threadDied, "Invoke2");
2582 public void delegate_call () {
2584 /* invoked on control_context's thread */
2585 delegateCalled = true;
2587 Console.WriteLine ("calling Application.Exit");
2588 control_context.ExitThread ();
2589 } catch (Exception e) { Console.WriteLine (e); }
2595 public class ControlWMTest
2598 public void WM_PARENTNOTIFY_Test ()
2604 tester = new WMTester ();
2605 child = new Control ();
2606 tester.Controls.Add (child);
2608 tester.Visible = true;
2609 child.Visible = true;
2611 child_handle = child.Handle.ToInt32 ();
2616 msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
2618 Assert.AreEqual (1, msgs.Count, "#1");
2620 m1 = (Message) msgs [0];
2621 Assert.AreEqual (WndMsg.WM_CREATE, ((WndMsg) LowOrder (m1.WParam)), "#2");
2622 //Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam), "#3");
2623 Assert.AreEqual (child_handle, m1.LParam.ToInt32 (), "#4");
2627 msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
2628 Assert.AreEqual (2, msgs.Count, "#5");
2629 m1 = (Message) msgs [1];
2631 Assert.AreEqual (WndMsg.WM_DESTROY, ((WndMsg) LowOrder (m1.WParam)), "#6");
2632 //Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam), "#7");
2633 Assert.AreEqual (child_handle, m1.LParam.ToInt32 (), "#8");
2638 internal static int LowOrder (int param)
2640 return ((int)(short)(param & 0xffff));
2643 internal static int HighOrder (int param)
2645 return ((int)(short)(param >> 16));
2648 internal static int LowOrder (IntPtr param)
2650 return ((int)(short)(param.ToInt32 () & 0xffff));
2653 internal static int HighOrder (IntPtr param)
2655 return ((int)(short)(param.ToInt32 () >> 16));
2658 internal class WMTester : Form
2660 internal ArrayList Messages = new ArrayList ();
2662 internal bool Contains (WndMsg msg)
2664 return Contains (msg, Messages);
2667 internal bool Contains (WndMsg msg, ArrayList list)
2669 foreach (Message m in Messages)
2671 if (m.Msg == (int) msg)
2677 internal ArrayList Find (WndMsg msg)
2679 ArrayList result = new ArrayList ();
2681 foreach (Message m in Messages)
2683 if (m.Msg == (int) msg)
2689 protected override void WndProc(ref Message m)
2691 Console.WriteLine ("WndProc: " + m.ToString ());
2693 base.WndProc (ref m);
2700 public class ControlLayoutTest
2703 public void SetUp ()
2708 [Test] // bug #80456
2709 public void LayoutTest ()
2711 MockLayoutEngine layoutEngine = new MockLayoutEngine ();
2712 MockControl c = new MockControl (layoutEngine);
2713 c.Layout += new LayoutEventHandler (LayoutEvent);
2714 Assert.IsFalse (layoutEngine.LayoutInvoked, "#A1");
2715 Assert.AreEqual (0, _layoutCount, "#A2");
2717 Assert.IsTrue (layoutEngine.LayoutInvoked, "#A3");
2718 Assert.AreEqual (1, _layoutCount, "#A4");
2720 layoutEngine.Reset ();
2721 c.OverrideOnLayout = true;
2722 Assert.IsFalse (layoutEngine.LayoutInvoked, "#B1");
2724 Assert.IsFalse (layoutEngine.LayoutInvoked, "#B2");
2725 Assert.AreEqual (1, _layoutCount, "#B3");
2728 void LayoutEvent (object sender, LayoutEventArgs e)
2733 private int _layoutCount;
2735 class MockControl : Control
2737 public MockControl (LayoutEngine layoutEngine)
2739 _layoutEngine = layoutEngine;
2742 public bool OverrideOnLayout
2744 get { return _overrideOnLayout; }
2745 set { _overrideOnLayout = value; }
2748 protected override void OnLayout (LayoutEventArgs levent)
2750 if (!OverrideOnLayout)
2751 base.OnLayout (levent);
2754 public override LayoutEngine LayoutEngine {
2756 if (_layoutEngine == null)
2757 return base.LayoutEngine;
2758 return _layoutEngine;
2762 private bool _overrideOnLayout;
2763 private LayoutEngine _layoutEngine;
2766 class MockLayoutEngine : LayoutEngine
2768 public bool LayoutInvoked {
2769 get { return _layoutInvoked; }
2772 public void Reset ()
2774 _layoutInvoked = false;
2777 public override bool Layout (object container, LayoutEventArgs args)
2779 _layoutInvoked = true;
2783 private bool _layoutInvoked;