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");
112 public class ControlAutoSizeTester : Control {
115 public ControlAutoSizeTester (Size customPrefSize, AutoSizeMode autoSizeMode)
117 custom_prefsize = customPrefSize;
118 AutoSizeMode = autoSizeMode;
121 public AutoSizeMode AutoSizeMode {
123 base.SetAutoSizeMode (value);
127 private bool use_custom_prefsize = false;
128 public bool UseCustomPrefSize {
130 use_custom_prefsize = value;
134 private Size custom_prefsize;
136 public Size CustomPrefSize {
138 return custom_prefsize;
141 custom_prefsize = value;
146 public override Size GetPreferredSize (Size proposedSize)
148 if (use_custom_prefsize) {
149 return custom_prefsize;
151 return base.GetPreferredSize(proposedSize);
159 public void InvokeTestParentHandle ()
161 Control child, parent;
163 parent = new Control ();
164 child = new Control ();
165 parent.Controls.Add (child);
166 parent.Visible = true;
167 parent.CreateControl ();
168 child.Invoke (new CrossAppDomainDelegate (dummy)) ;
175 public class ControlStylesTester : Control {
176 private WindowStyles style;
177 private WindowStyles ex_style;
178 private bool or_styles;
180 public ControlStylesTester (WindowStyles Style, WindowStyles ExStyle, bool OrStyles)
184 or_styles = OrStyles;
187 protected override CreateParams CreateParams {
189 CreateParams result = base.CreateParams;
191 result.Style |= (int) style;
192 result.ExStyle |= (int) ex_style;
194 result.Style = (int) style;
195 result.ExStyle = (int) ex_style;
203 public void ControlSizeTest ()
205 ControlStylesTester c = new ControlStylesTester (WindowStyles.WS_CHILD, 0, true);
206 Assert.AreEqual ("{X=0,Y=0}", c.Location.ToString (), "#L1");
207 Assert.AreEqual ("{Width=0, Height=0}", c.Size.ToString (), "#S1");
212 public void CaptureTest ()
214 Form frm = new Form ();
215 ControlOverrideLogger log = new ControlOverrideLogger ();
216 frm.Controls.Add (log);
220 log.BackColor = Color.Blue;
221 log.Size = new Size (100, 100);
224 Application.DoEvents ();
227 Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") > -1, "#01");
229 log = new ControlOverrideLogger ();
232 Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") > -1, "#02");
234 log = new ControlOverrideLogger ();
236 Assert.IsTrue (log.IsHandleCreated, "#03");
237 Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") == -1, "#04");
239 log = new ControlOverrideLogger ();
241 Assert.IsFalse (log.IsHandleCreated, "#05");
242 Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") == -1, "#06");
246 public class OnPaintTester : Form
250 ArrayList list = new ArrayList ();
251 public bool Recursive;
252 public bool TestRefresh;
253 public bool TestInvalidate;
254 public bool TestUpdate;
256 public new bool DoubleBuffered {
258 return base.DoubleBuffered;
261 base.DoubleBuffered = value;
265 protected override void OnPaint (PaintEventArgs pevent)
267 Assert.IsFalse (list.Contains (pevent.Graphics), "OnPaintTester.OnPaint: Got the same Graphics twice");
268 list.Add (pevent.Graphics);
272 Recursive = counter > 0 || Recursive;
277 else if (TestInvalidate)
283 base.OnPaint (pevent);
287 public new void Show ()
290 Application.DoEvents ();
295 public void ControlCollectionTest ()
297 Form frm = new Form ();
298 frm.IsMdiContainer = true;
299 Form child = new Form ();
300 Control.ControlCollection c = new Control.ControlCollection (frm);
301 child.MdiParent = frm;
306 [ExpectedException (typeof (ArgumentException))]
307 public void ControlCollectionExceptionTest ()
309 Form frm = new Form ();
310 frm.IsMdiContainer = true;
311 Form child = new Form ();
312 Control.ControlCollection c = new Control.ControlCollection (frm);
313 //child.MdiParent = frm;
318 [Category ("NotWorking")]
319 public void OnPaintTest ()
321 using (OnPaintTester t = new OnPaintTester ()) {
322 t.TestRefresh = true;
324 Assert.IsTrue (t.Recursive, "#1");
327 using (OnPaintTester t = new OnPaintTester ()) {
330 Assert.IsFalse (t.Recursive, "#2");
333 using (OnPaintTester t = new OnPaintTester ()) {
334 t.TestInvalidate = true;
336 Assert.IsFalse (t.Recursive, "#3");
341 [Category ("Interactive")]
342 public void OnPaintDoubleBufferedTest ()
344 using (OnPaintTester t = new OnPaintTester ()) {
345 t.DoubleBuffered = true;
346 t.TestRefresh = true;
348 Assert.IsTrue (t.Recursive, "#1");
351 using (OnPaintTester t = new OnPaintTester ()) {
352 t.DoubleBuffered = true;
355 Assert.IsFalse (t.Recursive, "#2");
358 using (OnPaintTester t = new OnPaintTester ()) {
359 t.DoubleBuffered = true;
360 t.TestInvalidate = true;
362 Assert.IsFalse (t.Recursive, "#3");
366 public class PaintEventForm : Form
368 public ArrayList overrides = new ArrayList ();
369 public ArrayList events = new ArrayList ();
371 public PaintEventForm ()
373 Paint += new PaintEventHandler (DoubleBufferEventForm_Paint);
375 public bool GetControlStyle (ControlStyles style)
377 return base.GetStyle (style);
380 public void SetControlStyle (ControlStyles style, bool value)
382 base.SetStyle (style, value);
385 void DoubleBufferEventForm_Paint (object sender, PaintEventArgs e)
390 protected override void OnPaintBackground (PaintEventArgs e)
392 base.OnPaintBackground (e);
393 overrides.Add("OnPaintBackground");
396 protected override void OnPaint (PaintEventArgs pevent)
398 base.OnPaint (pevent);
399 overrides.Add("OnPaint");
404 [Ignore ("Can't find a reliable way to generate a paint message on Windows.")]
405 public void EventStyleTest ()
408 using (PaintEventForm f = new PaintEventForm ()) {
410 f.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
412 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#A1");
413 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#A2");
414 Assert.IsTrue (f.events.Contains ("Paint"), "#A3");
417 using (PaintEventForm f = new PaintEventForm ()) {
419 f.SetControlStyle (ControlStyles.DoubleBuffer, true);
421 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#B1");
422 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#B2");
423 Assert.IsTrue (f.events.Contains ("Paint"), "#B3");
426 using (PaintEventForm f = new PaintEventForm ()) {
428 f.SetControlStyle (ControlStyles.AllPaintingInWmPaint, true);
430 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#C1");
431 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#C2");
432 Assert.IsTrue (f.events.Contains ("Paint"), "#C3");
435 using (PaintEventForm f = new PaintEventForm ()) {
437 f.SetControlStyle (ControlStyles.UserPaint, true);
439 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#D1");
440 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#D2");
441 Assert.IsTrue (f.events.Contains ("Paint"), "#D3");
444 using (PaintEventForm f = new PaintEventForm ()) {
446 f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
448 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#E1");
449 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#E2");
450 Assert.IsTrue (f.events.Contains ("Paint"), "#E3");
453 using (PaintEventForm f = new PaintEventForm ()) {
455 f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
457 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#F1");
458 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#F2");
459 Assert.IsTrue (f.events.Contains ("Paint"), "#F3");
462 using (PaintEventForm f = new PaintEventForm ()) {
464 f.SetControlStyle (ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
466 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#G1");
467 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#G2");
468 Assert.IsTrue (f.events.Contains ("Paint"), "#G3");
471 using (PaintEventForm f = new PaintEventForm ()) {
473 f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true);
475 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#H1");
476 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#H2");
477 Assert.IsTrue (f.events.Contains ("Paint"), "#H3");
481 public class DoubleBufferedForm : Form
485 public DoubleBufferedForm ()
487 this.DoubleBuffered = true;
490 protected override void OnPaint (PaintEventArgs e)
492 if (failed || painted)
497 e.Graphics.DrawString (Size.ToString (), Font, Brushes.AliceBlue, new Point (2, 2));
498 } catch (Exception exception) {
499 Console.WriteLine (exception.StackTrace);
505 public class DoubleBufferControl : Control
507 public bool IsDoubleBuffered
509 get { return base.DoubleBuffered; }
510 set { base.DoubleBuffered = value; }
513 public bool GetControlStyle (ControlStyles style)
515 return base.GetStyle (style);
518 public void SetControlStyle (ControlStyles style, bool value)
520 base.SetStyle (style, value);
525 [Ignore ("Can't find a reliable way to generate a paint message on Windows.")]
526 public void DoubleBufferTest ()
528 DoubleBufferedForm f = new DoubleBufferedForm ();
529 f.ShowInTaskbar = false;
533 Assert.IsFalse (f.failed, "#01");
534 Assert.IsTrue (f.painted, "The control was never painted, so please check the test");
539 public void DoubleBufferedTest ()
541 DoubleBufferControl c = new DoubleBufferControl ();
542 Assert.IsFalse (c.IsDoubleBuffered, "#A1");
543 Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#A2");
544 Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#A3");
545 Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#A4");
546 Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#A5");
548 c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
549 Assert.IsTrue (c.IsDoubleBuffered, "#B1");
550 Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#B2");
551 Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#B3");
552 Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#B4");
553 Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#A5");
555 c.SetControlStyle (ControlStyles.AllPaintingInWmPaint, false);
556 c.SetControlStyle (ControlStyles.UserPaint, false);
557 Assert.IsTrue (c.IsDoubleBuffered, "#C1");
558 Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#C2");
559 Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#C3");
560 Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#C4");
561 Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#C5");
563 c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, false);
564 Assert.IsFalse (c.IsDoubleBuffered, "#D1");
565 Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#D2");
566 Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#D3");
567 Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#D4");
568 Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#D5");
570 c.SetControlStyle (ControlStyles.DoubleBuffer, true);
571 Assert.IsFalse (c.IsDoubleBuffered, "#E1");
572 Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#E2");
573 Assert.IsTrue (c.GetControlStyle (ControlStyles.DoubleBuffer), "#E3");
574 Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#E4");
575 Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#E5");
577 c.SetControlStyle (ControlStyles.DoubleBuffer, false);
578 Assert.IsFalse (c.IsDoubleBuffered, "#F1");
579 Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#F2");
580 Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#F3");
581 Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#F4");
582 Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#F5");
584 c.IsDoubleBuffered = true;
585 Assert.IsTrue (c.IsDoubleBuffered, "#G1");
586 Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#G2");
587 Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#G3");
588 Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#G4");
589 Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#G5");
591 c.SetControlStyle (ControlStyles.AllPaintingInWmPaint, true);
592 c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
593 c.SetControlStyle (ControlStyles.DoubleBuffer, true);
594 c.SetControlStyle (ControlStyles.UserPaint, true);
595 c.IsDoubleBuffered = false;
596 Assert.IsFalse (c.IsDoubleBuffered, "#H1");
597 Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#H2");
598 Assert.IsTrue (c.GetControlStyle (ControlStyles.DoubleBuffer), "#H3");
599 Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#H4");
600 Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#H5");
604 public void DoubleBufferedStyleTest ()
606 DoubleBufferControl c = new DoubleBufferControl ();
607 TestControlStyle.CheckStyles (c, "#A1", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility);
609 c.IsDoubleBuffered = true;
610 TestControlStyle.CheckStyles (c, "#A2", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility, ControlStyles.OptimizedDoubleBuffer);
612 c.IsDoubleBuffered = false;
613 TestControlStyle.CheckStyles (c, "#A3", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility);
615 c = new DoubleBufferControl ();
616 foreach (ControlStyles style in Enum.GetValues (typeof(ControlStyles))) {
617 c.SetControlStyle (style, false);
620 TestControlStyle.CheckStyles (c, "#B1");
622 c.IsDoubleBuffered = true;
623 TestControlStyle.CheckStyles (c, "#B2", ControlStyles.OptimizedDoubleBuffer, ControlStyles.AllPaintingInWmPaint);
625 c.IsDoubleBuffered = false;
626 TestControlStyle.CheckStyles (c, "#B3", ControlStyles.AllPaintingInWmPaint);
632 public static void TestAccessibility(Control c, string Default, string Description, string Name, AccessibleRole Role)
634 Assert.IsNotNull (c.AccessibilityObject, "Acc1");
635 Assert.AreEqual (Default, c.AccessibleDefaultActionDescription, "Acc2");
636 Assert.AreEqual (Description, c.AccessibleDescription, "Acc3");
637 Assert.AreEqual (Name, c.AccessibleName, "Acc4");
638 Assert.AreEqual (Role, c.AccessibleRole, "Acc5");
641 public static string TestControl(Control container, Control start, bool forward) {
644 ctl = container.GetNextControl(start, forward);
655 public void CreatedTest ()
657 Control c = new Control ();
658 Assert.IsFalse (c.Created, "A1");
662 [Category ("NotWorking")]
663 public void CreatedAccessibilityTest ()
665 Control c = new Control ();
666 Assert.IsFalse (c.Created, "A1");
668 Helper.TestAccessibility(c, null, null, null, AccessibleRole.Default);
670 Assert.IsTrue (c.Created, "A2");
674 Assert.IsFalse (c.Created, "A3");
678 [Category ("NotWorking")]
679 public void BoundsTest ()
681 Control c = new Control ();
682 Assert.IsTrue (c.Bounds.IsEmpty, "A1");
683 Assert.IsTrue (c.Size.IsEmpty, "A2");
684 Assert.IsTrue (c.ClientSize.IsEmpty, "A3");
685 Assert.IsTrue (c.ClientRectangle.IsEmpty, "A4");
687 Assert.AreEqual (((IWin32Window)c).Handle, c.Handle, "A5");
689 /* this part fails on linux because we can't allocate X windows which are 0x0,
690 and the Control bounds directly reflect the size of the X window */
692 Assert.IsTrue (c.Bounds.IsEmpty, "A6");
693 Assert.IsTrue (c.Size.IsEmpty, "A7");
694 Assert.IsTrue (c.ClientSize.IsEmpty, "A8");
695 Assert.IsTrue (c.ClientRectangle.IsEmpty, "A9");
699 [Ignore ("Depends on specific DPI")]
700 public void FontHeightTest ()
702 MockControl c = new MockControl ();
703 Assert.AreEqual (13, c.font_height);
707 public void FontTest ()
709 Control c = new Control ();
710 Assert.IsFalse (c.Font.Bold, "#A1");
711 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#A2");
712 Assert.IsFalse (c.Font.Italic, "#A3");
713 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#A4");
714 Assert.AreEqual (8.25, c.Font.Size, "#A5");
715 Assert.AreEqual (8.25, c.Font.SizeInPoints, "#A6");
716 Assert.IsFalse (c.Font.Strikeout, "#A7");
717 Assert.IsFalse (c.Font.Underline, "#A8");
718 Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#A9");
720 Assert.IsTrue (c.Font.IsSystemFont, "#A10");
723 c.Font = new Font (c.Font.FontFamily, 3, FontStyle.Italic);
724 Assert.IsFalse (c.Font.Bold, "#B1");
725 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#B2");
726 Assert.IsTrue (c.Font.Italic, "#B3");
727 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#B4");
728 Assert.AreEqual (3, c.Font.Size, "#B5");
729 Assert.AreEqual (3, c.Font.SizeInPoints, "#B6");
730 Assert.IsFalse (c.Font.Strikeout, "#B7");
731 Assert.IsFalse (c.Font.Underline, "#B8");
732 Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#B9");
734 Assert.AreEqual (false, c.Font.IsSystemFont, "#B10");
739 [Category ("NotWorking")] // on Unix mapping is done to Bitstream Vera Sans
740 public void FontTest_Names ()
742 Control c = new Control ();
743 Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#1");
744 Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#2");
748 public void PubPropTest()
750 Control c = new Control();
752 Assert.IsFalse (c.AllowDrop , "A1");
753 Assert.AreEqual(AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "A2");
755 Assert.AreEqual ("Control", c.BackColor.Name , "B1");
756 Assert.IsNull (c.BackgroundImage, "B2");
757 Assert.IsNull (c.BindingContext, "B3");
759 Assert.AreEqual (ImageLayout.Tile, c.BackgroundImageLayout, "B4");
762 Assert.IsFalse (c.CanFocus, "C1");
763 Assert.IsTrue (c.CanSelect, "C2");
764 Assert.IsFalse (c.Capture, "C3");
765 Assert.IsTrue (c.CausesValidation, "C4");
767 Assert.IsNotNull (c.CompanyName, "C7");
768 Assert.IsNull (c.Container, "C8");
769 Assert.IsFalse (c.ContainsFocus, "C9");
770 Assert.IsNull (c.ContextMenu, "C10");
771 Assert.AreEqual (0, c.Controls.Count, "C11");
772 Assert.IsFalse (c.Created, "C12");
773 Assert.AreEqual (Cursors.Default, c.Cursor, "C13");
775 Assert.IsNotNull(c.DataBindings, "D1");
776 Assert.AreEqual("Control", Control.DefaultBackColor.Name, "D2");
777 Assert.AreEqual("ControlText", Control.DefaultForeColor.Name, "D3");
778 Assert.AreEqual(FontStyle.Regular, Control.DefaultFont.Style, "D4");
779 Assert.AreEqual (new Rectangle(0, 0, 0, 0), c.DisplayRectangle , "D5");
780 Assert.IsFalse (c.Disposing, "D6");
781 Assert.AreEqual(DockStyle.None, c.Dock, "D7");
783 Assert.IsTrue (c.Enabled, "E1");
785 Assert.IsFalse (c.Focused, "F1");
786 Assert.AreEqual (FontStyle.Regular, c.Font.Style, "F2");
787 Assert.AreEqual (SystemColors.ControlText, c.ForeColor, "F3");
789 Assert.IsFalse (c.HasChildren, "H2");
791 Assert.AreEqual (ImeMode.NoControl, c.ImeMode, "I1");
792 Assert.IsFalse (c.InvokeRequired, "I2");
793 Assert.IsFalse (c.IsAccessible, "I3");
794 Assert.IsFalse (c.IsDisposed, "I4");
795 Assert.IsFalse (c.IsHandleCreated, "I5");
797 Assert.AreEqual(Point.Empty, c.Location, "L2");
800 Assert.IsTrue(c.MaximumSize.IsEmpty);
801 Assert.IsTrue(c.MinimumSize.IsEmpty);
803 Assert.AreEqual (Keys.None, Control.ModifierKeys, "M1");
804 Assert.IsTrue (Control.MousePosition.X >= 0 && Control.MousePosition.Y >= 0, "M2");
805 Assert.AreEqual (MouseButtons.None, Control.MouseButtons, "M3");
807 Assert.AreEqual("", c.Name, "N1");
808 c.Name = "Control Name";
809 Assert.AreEqual("Control Name", c.Name, "N2");
811 Assert.IsNull (c.Parent, "P1");
812 Assert.IsNotNull (c.ProductName, "P2");
813 Assert.IsTrue (c.ProductName != "", "P3");
814 Assert.IsNotNull (c.ProductVersion, "P4");
815 Assert.IsTrue (c.ProductVersion != "", "P5");
817 Assert.IsFalse (c.RecreatingHandle, "R1");
818 Assert.IsNull (c.Region, "R2");
819 Assert.AreEqual (RightToLeft.No, c.RightToLeft, "R4");
821 Assert.IsNull (c.Site, "S1");
823 Assert.AreEqual (0, c.TabIndex , "T1");
824 Assert.IsTrue (c.TabStop, "T2");
825 Assert.IsNull (c.Tag, "T3");
826 Assert.AreEqual ("", c.Text, "T4");
828 Assert.IsTrue (c.Visible, "V1");
832 public void SizeChangeTest ()
834 Form f = new Form ();
835 Control c = new Control ();
838 c.Resize += new EventHandler(SizeChangedTest_ResizeHandler);
841 Assert.AreEqual (true, (bool) c.Tag, "#1");
845 private void SizeChangedTest_ResizeHandler (object sender, EventArgs e)
847 ((Control) sender).Tag = false;
851 public void NegativeHeightTest ()
853 Control c = new Control ();
854 IntPtr handle = c.Handle;
855 c.Resize += new EventHandler(NegativeHeightTest_ResizeHandler);
859 Assert.AreEqual (0, (int) c.Tag, "#1");
861 Assert.AreEqual (handle, handle, "Removes warning.");
864 private void NegativeHeightTest_ResizeHandler (object sender, EventArgs e)
866 Control c = (Control) sender;
871 public void TopLevelControlTest () {
872 Control c = new Control ();
874 Assert.AreEqual(null, c.TopLevelControl, "T1");
876 Panel p = new Panel ();
880 Assert.AreEqual(null, c.TopLevelControl, "T2");
882 Form f = new Form ();
883 f.ShowInTaskbar = false;
887 Assert.AreEqual (f, c.TopLevelControl, "T3");
888 Assert.AreEqual (f, f.TopLevelControl, "T4");
892 public void RelationTest() {
899 Assert.AreEqual(true , c1.Visible , "Rel1");
900 Assert.AreEqual(false, c1.Contains(c2) , "Rel2");
901 Assert.AreEqual("System.Windows.Forms.Control", c1.ToString() , "Rel3");
904 Assert.AreEqual(true , c2.Visible , "Rel4");
905 Assert.AreEqual(true, c1.Contains(c2) , "Rel5");
907 c1.Anchor = AnchorStyles.Top;
909 c1.Anchor = AnchorStyles.Left ;
911 Assert.AreEqual(AnchorStyles.Left , c1.Anchor, "Rel6");
913 c1.SetBounds(10, 20, 30, 40) ;
914 Assert.AreEqual(new Rectangle(10, 20, 30, 40), c1.Bounds, "Rel7");
916 Assert.AreEqual(c1, c2.Parent, "Rel8");
920 public void AnchorDockTest ()
922 Control c = new Control ();
924 Assert.AreEqual (DockStyle.None, c.Dock, "1");
925 Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "2");
927 c.Dock = DockStyle.Top;
928 Assert.AreEqual (DockStyle.Top, c.Dock, "3");
929 Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "4");
931 c.Anchor = AnchorStyles.Top;
932 Assert.AreEqual (DockStyle.None, c.Dock, "5");
933 Assert.AreEqual (AnchorStyles.Top, c.Anchor, "6");
937 [Category ("NotWorking")]
938 public void TabOrder()
943 Label label1 = new Label(); // To test non-tabstop items as well
944 Label label2 = new Label();
946 GroupBox group1 = new GroupBox();
947 GroupBox group2 = new GroupBox();
948 GroupBox group3 = new GroupBox();
950 TextBox text1 = new TextBox();
952 RadioButton radio11 = new RadioButton();
953 RadioButton radio12 = new RadioButton();
954 RadioButton radio13 = new RadioButton();
955 RadioButton radio14 = new RadioButton();
956 RadioButton radio21 = new RadioButton();
957 RadioButton radio22 = new RadioButton();
958 RadioButton radio23 = new RadioButton();
959 RadioButton radio24 = new RadioButton();
960 RadioButton radio31 = new RadioButton();
961 RadioButton radio32 = new RadioButton();
962 RadioButton radio33 = new RadioButton();
963 RadioButton radio34 = new RadioButton();
966 form.ShowInTaskbar = false;
968 form.ClientSize = new Size (520, 520);
969 Assert.AreEqual(new Size(520, 520), form.ClientSize, "Tab1");
971 form.Text = "SWF Taborder Test App Form";
972 Assert.AreEqual("SWF Taborder Test App Form", form.Text, "Tab2");
974 label1.Location = new Point(10, 10);
975 Assert.AreEqual(new Point(10, 10), label1.Location, "Tab3");
976 label1.Text = "Label1";
977 form.Controls.Add(label1);
979 label2.Location = new Point(200, 10);
980 label2.Text = "Label2";
981 form.Controls.Add(label2);
983 group1.Text = "Group1";
984 group2.Text = "Group2";
985 group3.Text = "Group3";
987 group1.Size = new Size(200, 400);
988 group2.Size = new Size(200, 400);
989 group3.Size = new Size(180, 180);
990 Assert.AreEqual(new Size(180, 180), group3.Size, "Tab4");
992 group1.Location = new Point(10, 40);
993 group2.Location = new Point(220, 40);
994 group3.Location = new Point(10, 210);
996 group1.TabIndex = 30;
997 Assert.AreEqual(30, group1.TabIndex, "Tab5");
998 group1.TabStop = true;
1000 // Don't assign, test automatic assignment
1001 //group2.TabIndex = 0;
1002 group2.TabStop = true;
1003 Assert.AreEqual(0, group2.TabIndex, "Tab6");
1005 group3.TabIndex = 35;
1006 group3.TabStop = true;
1008 // Test default tab index
1009 Assert.AreEqual(0, radio11.TabIndex, "Tab7");
1011 text1.Text = "Edit Control";
1013 radio11.Text = "Radio 1-1 [Tab1]";
1014 radio12.Text = "Radio 1-2 [Tab2]";
1015 radio13.Text = "Radio 1-3 [Tab3]";
1016 radio14.Text = "Radio 1-4 [Tab4]";
1018 radio21.Text = "Radio 2-1 [Tab4]";
1019 radio22.Text = "Radio 2-2 [Tab3]";
1020 radio23.Text = "Radio 2-3 [Tab2]";
1021 radio24.Text = "Radio 2-4 [Tab1]";
1023 radio31.Text = "Radio 3-1 [Tab1]";
1024 radio32.Text = "Radio 3-2 [Tab3]";
1025 radio33.Text = "Radio 3-3 [Tab2]";
1026 radio34.Text = "Radio 3-4 [Tab4]";
1028 // We don't assign TabIndex for radio1X; test automatic assignment
1029 text1.TabStop = true;
1030 radio11.TabStop = true;
1032 radio21.TabIndex = 4;
1033 radio22.TabIndex = 3;
1034 radio23.TabIndex = 2;
1035 radio24.TabIndex = 1;
1036 radio24.TabStop = true;
1038 radio31.TabIndex = 11;
1039 radio31.TabStop = true;
1040 radio32.TabIndex = 13;
1041 radio33.TabIndex = 12;
1042 radio34.TabIndex = 14;
1044 text1.Location = new Point(10, 100);
1046 radio11.Location = new Point(10, 20);
1047 radio12.Location = new Point(10, 40);
1048 radio13.Location = new Point(10, 60);
1049 radio14.Location = new Point(10, 80);
1051 radio21.Location = new Point(10, 20);
1052 radio22.Location = new Point(10, 40);
1053 radio23.Location = new Point(10, 60);
1054 radio24.Location = new Point(10, 80);
1056 radio31.Location = new Point(10, 20);
1057 radio32.Location = new Point(10, 40);
1058 radio33.Location = new Point(10, 60);
1059 radio34.Location = new Point(10, 80);
1061 text1.Size = new Size(150, text1.PreferredHeight);
1063 radio11.Size = new Size(150, 20);
1064 radio12.Size = new Size(150, 20);
1065 radio13.Size = new Size(150, 20);
1066 radio14.Size = new Size(150, 20);
1068 radio21.Size = new Size(150, 20);
1069 radio22.Size = new Size(150, 20);
1070 radio23.Size = new Size(150, 20);
1071 radio24.Size = new Size(150, 20);
1073 radio31.Size = new Size(150, 20);
1074 radio32.Size = new Size(150, 20);
1075 radio33.Size = new Size(150, 20);
1076 radio34.Size = new Size(150, 20);
1078 group1.Controls.Add(text1);
1080 group1.Controls.Add(radio11);
1081 group1.Controls.Add(radio12);
1082 group1.Controls.Add(radio13);
1083 group1.Controls.Add(radio14);
1085 group2.Controls.Add(radio21);
1086 group2.Controls.Add(radio22);
1087 group2.Controls.Add(radio23);
1088 group2.Controls.Add(radio24);
1090 group3.Controls.Add(radio31);
1091 group3.Controls.Add(radio32);
1092 group3.Controls.Add(radio33);
1093 group3.Controls.Add(radio34);
1095 form.Controls.Add(group1);
1096 form.Controls.Add(group2);
1097 group2.Controls.Add(group3);
1099 // Perform some tests, the TabIndex stuff below will alter the outcome
1100 Assert.AreEqual(null, Helper.TestControl(group2, radio34, true), "Tab8");
1101 Assert.AreEqual(31, group2.TabIndex, "Tab9");
1103 // Does the taborder of containers and non-selectable things change behaviour?
1104 label1.TabIndex = 5;
1105 label2.TabIndex = 4;
1106 group1.TabIndex = 3;
1107 group2.TabIndex = 1;
1109 // Start verification
1110 Assert.AreEqual(null, Helper.TestControl(group2, radio34, true), "Tab10");
1111 Assert.AreEqual(radio24.Text, Helper.TestControl(group2, group2, true), "Tab11");
1112 Assert.AreEqual(radio31.Text, Helper.TestControl(group2, group3, true), "Tab12");
1113 Assert.AreEqual(null, Helper.TestControl(group1, radio14, true), "Tab13");
1114 Assert.AreEqual(radio23.Text, Helper.TestControl(group2, radio24, true), "Tab14");
1115 Assert.AreEqual(group3.Text, Helper.TestControl(group2, radio21, true), "Tab15");
1116 Assert.AreEqual(radio13.Text, Helper.TestControl(form, radio12, true), "Tab16");
1117 Assert.AreEqual(label2.Text, Helper.TestControl(form, radio14, true), "Tab17");
1118 Assert.AreEqual(group1.Text, Helper.TestControl(form, radio34, true), "Tab18");
1119 Assert.AreEqual(radio23.Text, Helper.TestControl(group2, radio24, true), "Tab19");
1122 Assert.AreEqual(null, Helper.TestControl(radio11, radio21, true), "Tab20");
1123 Assert.AreEqual(text1.Text, Helper.TestControl(group1, radio21, true), "Tab21");
1125 Assert.AreEqual(radio14.Text, Helper.TestControl(form, label2, false), "Tab22");
1126 Assert.AreEqual(radio21.Text, Helper.TestControl(group2, group3, false), "Tab23");
1128 Assert.AreEqual(4, radio21.TabIndex, "Tab24");
1129 Assert.AreEqual(1, radio11.TabIndex, "Tab25");
1130 Assert.AreEqual(3, radio13.TabIndex, "Tab26");
1131 Assert.AreEqual(35, group3.TabIndex, "Tab27");
1132 Assert.AreEqual(1, group2.TabIndex, "Tab28");
1134 Assert.AreEqual(label1.Text, Helper.TestControl(form, form, false), "Tab29");
1135 Assert.AreEqual(radio14.Text, Helper.TestControl(group1, group1, false), "Tab30");
1136 Assert.AreEqual(radio34.Text, Helper.TestControl(group3, group3, false), "Tab31");
1138 Assert.AreEqual(null, Helper.TestControl(label1, label1, false), "Tab31");
1139 Assert.AreEqual(null, Helper.TestControl(radio11, radio21, false), "Tab32");
1144 public void ScaleTest()
1146 Control r1 = new Control();
1151 Assert.AreEqual(80, r1.Width, "Scale1");
1152 Assert.AreEqual(40, r1.Height, "Scale2");
1155 class TestWindowTarget : IWindowTarget
1157 public void OnHandleChange (IntPtr newHandle) {
1160 public void OnMessage (ref Message m) {
1165 public void WindowTargetTest()
1167 Control c = new Control ();
1168 Assert.IsNotNull (c.WindowTarget, "WindowTarget1");
1169 c.WindowTarget = null;
1170 Assert.IsNull (c.WindowTarget, "WindowTarget2");
1172 IWindowTarget existing_target = c.WindowTarget;
1173 IWindowTarget new_target = new TestWindowTarget ();
1174 c.WindowTarget = new_target;
1175 Assert.AreSame (new_target, c.WindowTarget, "WindowTarget3");
1177 TestHelper.RemoveWarning (existing_target);
1181 public void TextTest()
1183 Control r1 = new Control();
1185 Assert.AreEqual("Hi" , r1.Text , "Text1");
1188 Assert.AreEqual("" , r1.Text , "Text2");
1192 public void PubMethodTest7()
1194 Control r1 = new Control();
1195 r1.RightToLeft = RightToLeft.Yes ;
1196 r1.ResetRightToLeft() ;
1197 Assert.AreEqual(RightToLeft.No , r1.RightToLeft , "#81");
1198 r1.ImeMode = ImeMode.Off ;
1199 r1.ResetImeMode () ;
1200 Assert.AreEqual(ImeMode.NoControl , r1.ImeMode , "#82");
1201 r1.ForeColor= SystemColors.GrayText ;
1202 r1.ResetForeColor() ;
1203 Assert.AreEqual(SystemColors.ControlText , r1.ForeColor , "#83");
1204 //r1.Font = Font.FromHdc();
1206 //Assert.AreEqual(FontFamily.GenericSansSerif , r1.Font , "#83");
1207 r1.Cursor = Cursors.Hand ;
1209 Assert.AreEqual(Cursors.Default , r1.Cursor , "#83");
1210 //r1.DataBindings = System.Windows.Forms.Binding ;
1211 //r1.ResetBindings() ;
1212 //Assert.AreEqual(ControlBindingsCollection , r1.DataBindings , "#83");
1213 r1.BackColor = Color.Black ;
1214 r1.ResetBackColor() ;
1215 Assert.AreEqual( SystemColors.Control , r1.BackColor , "#84");
1216 r1.BackColor = Color.Black ;
1218 Assert.AreEqual( null , r1.Region , "#85");
1219 Rectangle M = new Rectangle(10, 20, 30 ,40);
1220 r1.RectangleToScreen(M) ;
1221 Assert.AreEqual( null , r1.Region , "#86");
1225 public void ScreenClientCoords()
1236 p1 = new Point (10,10);
1237 p2 = l.PointToScreen(p1);
1238 p3 = l.PointToClient(p2);
1240 Assert.AreEqual (p1, p3, "SC1");
1244 public void ContainsTest ()
1246 Control t = new Control ();
1247 Control s = new Control ();
1251 Assert.AreEqual (true, t.Contains (s), "Con1");
1252 Assert.AreEqual (false, s.Contains (t), "Con2");
1253 Assert.AreEqual (false, s.Contains (null), "Con3");
1254 Assert.AreEqual (false, t.Contains (new Control ()), "Con4");
1258 public void IsHandleCreated_NotVisible ()
1260 Control c = new Control ();
1263 Form form = new Form ();
1264 form.ShowInTaskbar = false;
1265 form.Controls.Add (c);
1268 Assert.IsFalse (c.IsHandleCreated, "#1");
1270 Assert.IsTrue (c.IsHandleCreated, "#2");
1272 Assert.IsTrue (c.IsHandleCreated, "#3");
1276 class OnCreateControlTest : Control {
1277 public bool reached = false;
1278 protected override void OnCreateControl () {
1284 public void CreateControlVisibleTest ()
1286 OnCreateControlTest test = new OnCreateControlTest ();
1287 test.Visible = false;
1288 Assert.IsFalse (test.IsHandleCreated, "0");
1289 Assert.IsFalse (test.Visible, "1");
1290 test.Visible = true;
1291 Assert.IsTrue (test.Visible, "2");
1292 Assert.IsTrue (test.reached, "3");
1297 public void CreateGraphicsTest ()
1303 Control c = new Control ();
1304 c.SetBounds (0,0, 20, 20);
1305 g = c.CreateGraphics ();
1306 Assert.IsNotNull (g, "Graph1");
1315 bool delegateCalled = false;
1316 public delegate void TestDelegate ();
1318 public void delegate_call () {
1319 delegateCalled = true;
1321 TestHelper.RemoveWarning (delegateCalled);
1325 [ExpectedException(typeof(InvalidOperationException))]
1326 public void InvokeException1 () {
1327 Control c = new Control ();
1328 IAsyncResult result;
1330 result = c.BeginInvoke (new TestDelegate (delegate_call));
1331 c.EndInvoke (result);
1335 public void FindFormTest () {
1336 Form f = new Form ();
1338 f.ShowInTaskbar = false;
1343 f.Controls.Add (c = new Control ());
1344 Assert.AreEqual (f.Name, c.FindForm ().Name, "Find1");
1346 f.Controls.Remove (c);
1348 GroupBox g = new GroupBox ();
1353 Assert.AreEqual (f.Name, f.FindForm ().Name, "Find2");
1355 g.Controls.Remove (c);
1356 Assert.IsNull(c.FindForm (), "Find3");
1367 public void FocusTest ()
1370 Button c = null, d = null;
1374 f.ShowInTaskbar = false;
1384 Assert.IsTrue (c.CanFocus, "Focus1");
1385 Assert.IsFalse (c.Focused, "Focus2");
1387 Assert.IsTrue (c.Focused, "Focus3");
1389 Assert.IsFalse (d.Focused, "Focus4");
1393 Assert.IsTrue (d.Focused, "Focus5");
1394 Assert.IsFalse (c.Focused, "Focus6");
1397 Assert.IsFalse (c.Focused, "Focus7");
1409 public void FromHandleTest ()
1415 c1 = new Control ();
1416 c2 = new Control ();
1420 c1.Controls.Add(c2);
1423 Assert.AreEqual (c1.Name, Control.FromHandle (c1.Handle).Name, "Handle1");
1424 Assert.IsNull (Control.FromHandle (IntPtr.Zero), "Handle2");
1427 Assert.AreEqual (c1.Name, Control.FromChildHandle (c1.Handle).Name, "Handle3");
1428 Assert.IsNull (Control.FromChildHandle (IntPtr.Zero), "Handle4");
1441 public void GetChildAtPointTest ()
1443 Control c = null, d = null;
1444 TransparentControl e = null;
1449 c.SetBounds (0, 0, 100, 100);
1453 d.SetBounds (10, 10, 40, 40);
1456 e = new TransparentControl ();
1458 e.SetBounds (55, 55, 10, 10);
1460 Control l = c.GetChildAtPoint (new Point (15, 15));
1461 Assert.AreEqual (d.Name, l.Name, "Child1");
1462 Assert.IsFalse (e.Name == l.Name, "Child2");
1464 l = c.GetChildAtPoint (new Point (57, 57));
1465 Assert.AreEqual (null, l, "Child3");
1467 l = c.GetChildAtPoint (new Point (10, 10));
1468 Assert.AreEqual (d.Name, l.Name, "Child4");
1470 // GetChildAtPointSkip is not implemented and the following test is breaking for Net_2_0 profile
1474 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
1475 Assert.IsNull (l, "Child5");
1478 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
1479 Assert.AreSame (e.Name, l.Name, "Child6");
1482 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Disabled);
1483 Assert.IsNull (l, "Child7");
1486 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Disabled);
1487 Assert.AreSame (e.Name, l.Name, "Child8");
1490 e.BackColor = Color.Transparent;
1491 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Transparent);
1492 Assert.IsNull (l, "Child9");
1494 e.BackColor = Color.Green;
1495 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Transparent);
1496 Assert.AreSame (e.Name, l.Name, "Child10");
1507 private class TransparentControl : Control
1509 public TransparentControl ()
1511 SetStyle (ControlStyles.SupportsTransparentBackColor, true);
1514 protected override CreateParams CreateParams
1518 CreateParams cp = base.CreateParams;
1519 cp.ExStyle |= 0x00000020;
1526 public void ResetFontTest ()
1528 Control c = new Control ();
1529 c.Font = new Font (c.Font.FontFamily, 3, FontStyle.Italic);
1532 Assert.IsFalse (c.Font.Bold, "#1");
1533 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#2");
1534 Assert.IsFalse (c.Font.Italic, "#3");
1535 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#4");
1536 Assert.AreEqual (8.25, c.Font.Size, "#5");
1537 Assert.AreEqual (8.25, c.Font.SizeInPoints, "#6");
1538 Assert.IsFalse (c.Font.Strikeout, "#7");
1539 Assert.IsFalse (c.Font.Underline, "#8");
1540 Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#9");
1542 Assert.AreEqual (true, c.Font.IsSystemFont, "#10");
1546 public class LayoutTestControl : Control {
1547 public int LayoutCount;
1549 public LayoutTestControl () : base() {
1553 protected override void OnLayout(LayoutEventArgs levent) {
1555 base.OnLayout (levent);
1560 public void LayoutTest() {
1561 LayoutTestControl c;
1563 c = new LayoutTestControl();
1570 c.ResumeLayout(true);
1572 c.ResumeLayout(true);
1574 c.ResumeLayout(true);
1576 c.ResumeLayout(true);
1578 c.ResumeLayout(true);
1580 c.ResumeLayout(true);
1582 c.ResumeLayout(true);
1587 Assert.AreEqual(5, c.LayoutCount, "Layout Suspend/Resume locking does not bottom out at 0");
1591 [ExpectedException(typeof(ArgumentException))]
1592 public void TransparentBackgroundTest1() {
1596 c.BackColor = Color.Transparent;
1600 public void TransparentBackgroundTest2() {
1604 c.BackColor = Color.Transparent;
1605 Assert.AreEqual(Color.Transparent, c.BackColor, "Transparent background not set");
1609 public void TransparentBackgroundTest3() {
1613 c.BackColor = Color.Empty;
1614 Assert.AreEqual(Control.DefaultBackColor, c.BackColor, "Setting empty color failed");
1618 public void Dock_Value_Invalid ()
1620 Control c = new Control ();
1622 c.Dock = (DockStyle) 666;
1624 } catch (InvalidEnumArgumentException ex) {
1625 Assert.AreEqual (typeof (InvalidEnumArgumentException), ex.GetType (), "#2");
1626 Assert.IsNotNull (ex.Message, "#3");
1627 Assert.IsNotNull (ex.ParamName, "#4");
1628 Assert.AreEqual ("value", ex.ParamName, "#5");
1629 Assert.IsNull (ex.InnerException, "#6");
1634 public void EnabledTest1() {
1639 grandma = new Control();
1640 parent = new Control();
1641 child = new Control();
1643 grandma.Controls.Add(parent);
1644 parent.Controls.Add(child);
1645 grandma.Enabled = false;
1646 Assert.AreEqual(grandma.Enabled, child.Enabled, "Child did not inherit disabled state");
1649 int EnabledCalledCount = 0;
1650 private void EnabledTest2EnabledChanged(object sender, EventArgs e) {
1651 EnabledCalledCount++;
1655 public void EnabledTest2() {
1656 // Check nesting of enabled calls
1657 // OnEnabled is not called for disabled child controls
1662 EnabledCalledCount = 0;
1664 grandma = new Control();
1665 parent = new Control();
1666 child = new Control();
1667 child.EnabledChanged += new EventHandler(EnabledTest2EnabledChanged);
1669 grandma.Controls.Add(parent);
1670 parent.Controls.Add(child);
1671 grandma.Enabled = false;
1673 Assert.AreEqual(1, EnabledCalledCount, "Child Enabled Event not properly fired");
1674 grandma.Enabled = true;
1675 Assert.AreEqual(2, EnabledCalledCount, "Child Enabled Event not properly fired");
1676 child.Enabled = false;
1677 grandma.Enabled = false;
1678 Assert.AreEqual(3, EnabledCalledCount, "Child Enabled Event not properly fired");
1682 public void ControlsRemoveNullTest ()
1684 Control c = new Control ();
1685 c.Controls.Remove (null);
1689 public void ControlsAddNullTest ()
1691 Control c = new Control ();
1692 c.Controls.Add (null);
1696 [ExpectedException (typeof (ArgumentNullException))]
1697 public void ControlsSetChildIndexNullTest ()
1699 Control c = new Control ();
1700 c.Controls.SetChildIndex (null, 1);
1704 [ExpectedException (typeof (ArgumentNullException))]
1705 public void ControlsAddRangeNullTest ()
1707 Control c = new Control ();
1708 c.Controls.AddRange (null);
1712 public void ControlsAddRangeNullElementTest ()
1714 Control c = new Control ();
1715 Control[] subcontrols = new Control[2];
1716 subcontrols[0] = new Control ();
1717 subcontrols[1] = null;
1719 c.Controls.AddRange (subcontrols);
1723 public void RegionTest () {
1724 Form f = new Form ();
1725 f.ShowInTaskbar = false;
1726 Control c = new Control ();
1728 Assert.IsNull (c.Region, "#A1");
1730 Assert.IsNull (c.Region, "#A2");
1732 Assert.IsNull (c.Region, "#A3");
1735 Region region = new Region ();
1737 f.ShowInTaskbar = false;
1741 Assert.IsNotNull (c.Region, "#B1");
1742 Assert.AreSame (region, c.Region, "#B2");
1745 Assert.IsNull (c.Region, "#B3");
1750 [Test] // bug #80280
1751 public void Validated_Multiple_Containers ()
1753 Form form = new Form ();
1754 form.ShowInTaskbar = false;
1756 UserControl control1 = new UserControl();
1757 UserControl container1 = new UserControl();
1758 control1.Tag = true;
1759 control1.Validated += new EventHandler (Control_ValidatedHandler);
1760 container1.Controls.Add(control1);
1761 form.Controls.Add (container1);
1763 UserControl container2 = new UserControl();
1764 UserControl control2 = new UserControl();
1765 container2.Controls.Add(control2);
1766 form.Controls.Add (container2);
1768 Assert.IsTrue ((bool) control1.Tag, "#1");
1770 Assert.IsTrue ((bool) control1.Tag, "#2");
1772 Assert.IsFalse ((bool) control1.Tag, "#3");
1777 private void Control_ValidatedHandler (object sender, EventArgs e)
1779 ((Control) sender).Tag = false;
1784 public void UseWaitCursorTest ()
1786 Control c = new Control ();
1787 Assert.IsFalse (c.UseWaitCursor, "#1");
1788 c.Cursor = Cursors.Hand;
1789 c.UseWaitCursor = true;
1790 Assert.AreEqual (Cursors.WaitCursor, c.Cursor, "#2");
1791 c.UseWaitCursor = false;
1792 Assert.AreEqual (Cursors.Hand, c.Cursor, "#3");
1794 c.UseWaitCursor = true;
1795 c.Cursor = Cursors.Help;
1796 Assert.AreEqual (Cursors.WaitCursor, c.Cursor, "#4");
1797 Assert.AreEqual (true, c.UseWaitCursor, "#5");
1799 c.UseWaitCursor = false;
1800 Assert.AreEqual (Cursors.Help, c.Cursor, "#6");
1803 [Test] // bug #80621, #81125
1804 public void DontCallSizeFromClientSize ()
1806 SizeControl sc = new SizeControl ();
1808 Assert.AreEqual (0, sc.size_from_client_size_count, "A1");
1810 sc.ClientSize = new Size (300, 300);
1811 Assert.AreEqual (0, sc.size_from_client_size_count, "A2");
1813 SizeForm sf = new SizeForm ();
1814 sf.ShowInTaskbar = false;
1817 Assert.AreEqual (0, sc.size_from_client_size_count, "A3");
1819 sc.ClientSize = new Size (300, 300);
1820 Assert.AreEqual (0, sc.size_from_client_size_count, "A4");
1825 private class SizeControl : Control
1827 public int size_from_client_size_count = 0;
1829 protected override Size SizeFromClientSize (Size clientSize)
1831 size_from_client_size_count++;
1832 return base.SizeFromClientSize (clientSize);
1836 private class SizeForm : Form
1838 public int size_from_client_size_count = 0;
1840 protected override Size SizeFromClientSize (Size clientSize)
1842 size_from_client_size_count++;
1843 return base.SizeFromClientSize (clientSize);
1848 public class MockControl : Control
1850 public int font_height {
1851 get { return base.FontHeight; }
1852 set { base.FontHeight = value; }
1856 const int WM_KEYDOWN = 0x0100;
1857 const int WM_CHAR = 0x0102;
1858 const int WM_SYSCHAR = 0x0106;
1859 const int WM_KEYUP = 0x0101;
1863 public void MethodPreProcessControlMessage ()
1865 bool testing_callstack = false;
1867 MyControl c = new MyControl ();
1868 Message m = new Message ();
1871 m.WParam = (IntPtr)Keys.Down;
1872 m.LParam = IntPtr.Zero;
1874 if (testing_callstack) Console.WriteLine ("Start");
1875 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A1");
1876 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1878 c.SetState (State.OnPreviewKeyDown);
1879 if (testing_callstack) Console.WriteLine ("Start");
1880 Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A2");
1881 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1883 c.SetState (State.ProcessCmdKey);
1884 if (testing_callstack) Console.WriteLine ("Start");
1885 Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A3");
1886 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1888 c.SetState (State.IsInputKey);
1889 if (testing_callstack) Console.WriteLine ("Start");
1890 Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A4");
1891 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1893 c.SetState (State.ProcessDialogKey);
1894 if (testing_callstack) Console.WriteLine ("Start");
1895 Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A5");
1896 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1900 c.SetState (State.None);
1901 if (testing_callstack) Console.WriteLine ("Start");
1902 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A6");
1903 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1905 c.SetState (State.IsInputChar);
1906 if (testing_callstack) Console.WriteLine ("Start");
1907 Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A7");
1908 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1910 c.SetState (State.ProcessDialogChar);
1911 if (testing_callstack) Console.WriteLine ("Start");
1912 Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A8");
1913 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1917 c.SetState (State.None);
1918 if (testing_callstack) Console.WriteLine ("Start");
1919 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A9");
1920 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1922 c.SetState (State.IsInputChar);
1923 if (testing_callstack) Console.WriteLine ("Start");
1924 Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A10");
1925 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1927 c.SetState (State.ProcessDialogChar);
1928 if (testing_callstack) Console.WriteLine ("Start");
1929 Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A11");
1930 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1934 if (testing_callstack) Console.WriteLine ("Start");
1935 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A12");
1936 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1938 c.SetState (State.OnPreviewKeyDown);
1939 if (testing_callstack) Console.WriteLine ("Start");
1940 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A13");
1941 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1943 c.SetState (State.ProcessCmdKey);
1944 if (testing_callstack) Console.WriteLine ("Start");
1945 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A14");
1946 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1948 c.SetState (State.IsInputKey);
1949 if (testing_callstack) Console.WriteLine ("Start");
1950 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A15");
1951 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1953 c.SetState (State.ProcessDialogKey);
1954 if (testing_callstack) Console.WriteLine ("Start");
1955 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A16");
1956 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1961 public void MethodPreProcessMessage ()
1963 bool testing_callstack = false;
1965 MyControl c = new MyControl ();
1966 Message m = new Message ();
1969 m.WParam = (IntPtr)Keys.Down;
1970 m.LParam = IntPtr.Zero;
1972 if (testing_callstack) Console.WriteLine ("Start");
1973 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A1");
1974 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1976 c.SetState (State.OnPreviewKeyDown);
1977 if (testing_callstack) Console.WriteLine ("Start");
1978 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A2");
1979 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1981 c.SetState (State.ProcessCmdKey);
1982 if (testing_callstack) Console.WriteLine ("Start");
1983 Assert.AreEqual (true, c.PreProcessMessage (ref m), "A3");
1984 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1986 c.SetState (State.IsInputKey);
1987 if (testing_callstack) Console.WriteLine ("Start");
1988 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A4");
1989 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1991 c.SetState (State.ProcessDialogKey);
1992 if (testing_callstack) Console.WriteLine ("Start");
1993 Assert.AreEqual (true, c.PreProcessMessage (ref m), "A5");
1994 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
1998 c.SetState (State.None);
1999 if (testing_callstack) Console.WriteLine ("Start");
2000 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A6");
2001 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2003 c.SetState (State.IsInputChar);
2004 if (testing_callstack) Console.WriteLine ("Start");
2005 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A7");
2006 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2008 c.SetState (State.ProcessDialogChar);
2009 if (testing_callstack) Console.WriteLine ("Start");
2010 Assert.AreEqual (true, c.PreProcessMessage (ref m), "A8");
2011 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2015 c.SetState (State.None);
2016 if (testing_callstack) Console.WriteLine ("Start");
2017 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A9");
2018 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2020 c.SetState (State.IsInputChar);
2021 if (testing_callstack) Console.WriteLine ("Start");
2022 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A10");
2023 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2025 c.SetState (State.ProcessDialogChar);
2026 if (testing_callstack) Console.WriteLine ("Start");
2027 Assert.AreEqual (true, c.PreProcessMessage (ref m), "A11");
2028 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2032 if (testing_callstack) Console.WriteLine ("Start");
2033 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A12");
2034 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2036 c.SetState (State.OnPreviewKeyDown);
2037 if (testing_callstack) Console.WriteLine ("Start");
2038 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A13");
2039 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2041 c.SetState (State.ProcessCmdKey);
2042 if (testing_callstack) Console.WriteLine ("Start");
2043 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A14");
2044 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2046 c.SetState (State.IsInputKey);
2047 if (testing_callstack) Console.WriteLine ("Start");
2048 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A15");
2049 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2051 c.SetState (State.ProcessDialogKey);
2052 if (testing_callstack) Console.WriteLine ("Start");
2053 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A16");
2054 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2068 private class MyControl : Control
2071 private State current_state;
2072 bool testing_callstack = false;
2074 public void SetState (State state)
2076 current_state = state;
2079 protected override bool ProcessCmdKey (ref Message msg, Keys keyData)
2081 if (testing_callstack) Console.Write ("ProcessCmdKey[");
2082 if (current_state == State.ProcessCmdKey) {
2083 if (testing_callstack) Console.WriteLine ("]");
2087 bool retval = base.ProcessCmdKey (ref msg, keyData);
2088 if (testing_callstack) Console.WriteLine ("]");
2093 protected override void OnPreviewKeyDown (PreviewKeyDownEventArgs e)
2095 if (testing_callstack) Console.Write ("OnPreviewKeyDown[");
2096 if (current_state == State.OnPreviewKeyDown) {
2097 e.IsInputKey = true;
2098 if (testing_callstack) Console.WriteLine ("]");
2102 base.OnPreviewKeyDown (e);
2103 if (testing_callstack) Console.WriteLine ("]");
2107 protected override bool IsInputChar (char charCode)
2109 if (testing_callstack) Console.Write ("IsInputChar[");
2110 if (current_state == State.IsInputChar) {
2111 if (testing_callstack) Console.WriteLine ("true]");
2115 bool retval = base.IsInputChar (charCode);
2116 if (testing_callstack) Console.WriteLine ("{0}]", retval.ToString ());
2120 protected override bool IsInputKey (Keys keyData)
2122 if (testing_callstack) Console.Write ("IsInputKey[");
2123 if (current_state == State.IsInputKey) {
2124 if (testing_callstack) Console.WriteLine ("]");
2128 bool retval = base.IsInputKey (keyData);
2129 if (testing_callstack) Console.WriteLine ("]");
2133 public override bool PreProcessMessage (ref Message msg)
2135 if (testing_callstack) Console.Write ("PreProcessMessage[");
2136 if (current_state == State.PreProcessMessage) {
2137 if (testing_callstack) Console.WriteLine ("]");
2141 bool retval = base.PreProcessMessage (ref msg);
2142 if (testing_callstack) Console.WriteLine ("]");
2146 protected override bool ProcessDialogKey (Keys keyData)
2148 if (testing_callstack) Console.Write ("ProcessDialogKey[");
2149 if (current_state == State.ProcessDialogKey) {
2150 if (testing_callstack) Console.WriteLine ("]");
2154 bool retval = base.ProcessDialogKey (keyData);
2155 if (testing_callstack) Console.WriteLine ("]");
2159 protected override bool ProcessDialogChar (char charCode)
2161 if (testing_callstack) Console.Write ("ProcessDialogChar[");
2162 if (current_state == State.ProcessDialogChar) {
2163 if (testing_callstack) Console.WriteLine ("]");
2167 bool retval = base.ProcessDialogChar (charCode);
2168 if (testing_callstack) Console.WriteLine ("]");
2174 public void MethodIsInputChar ()
2176 // Basically, show that this method always returns false
2177 InputCharControl m = new InputCharControl ();
2178 bool result = false;
2180 for (int i = 0; i < 256; i++)
2181 result |= m.PublicIsInputChar ((char)i);
2183 Assert.AreEqual (false, result, "I1");
2186 private class InputCharControl : Control
2188 public bool PublicIsInputChar (char charCode)
2190 return base.IsInputChar (charCode);
2198 public class ControlSetTopLevelTest
2200 class ControlPoker : Control {
2201 public void DoSetTopLevel ()
2205 public bool DoGetTopLevel ()
2207 return GetTopLevel ();
2212 public void TestControl ()
2214 ControlPoker c = new ControlPoker ();
2217 Assert.IsTrue (c.DoGetTopLevel (), "1");
2218 Assert.IsFalse (c.Visible, "2");
2222 [ExpectedException (typeof (ArgumentException))]
2223 public void TestChildControl ()
2225 Control c1 = new Control();
2226 ControlPoker c2 = new ControlPoker ();
2228 c1.Controls.Add (c2);
2229 c2.DoSetTopLevel ();
2233 [ExpectedException (typeof (ArgumentException))]
2234 public void TestTopLevelAdd () {
2235 Form f = new Form();
2236 Form f1 = new Form();
2240 [Category ("NotWorking")]
2242 public void TestForm ()
2244 Form f = new Form ();
2245 Assert.IsFalse (f.Visible, "3");
2247 Assert.IsFalse (f.Visible, "4");
2252 public class ControlResizeLayoutTest
2254 class ControlPoker : Control {
2255 public void DoOnResize ()
2257 OnResize (EventArgs.Empty);
2262 string child_affected_property;
2263 void ChildLayoutEvent (object sender, LayoutEventArgs e)
2266 child_affected_property = e.AffectedProperty;
2270 string parent_affected_property;
2271 void ParentLayoutEvent (object sender, LayoutEventArgs e)
2274 parent_affected_property = e.AffectedProperty;
2276 TestHelper.RemoveWarning (parent_affected_property);
2282 Panel p = new Panel ();
2283 ControlPoker c = new ControlPoker();
2287 p.Layout += new LayoutEventHandler (ParentLayoutEvent);
2288 c.Layout += new LayoutEventHandler (ChildLayoutEvent);
2292 Assert.AreEqual (1, child_event, "1");
2293 Assert.AreEqual ("Bounds", child_affected_property, "2");
2295 Assert.AreEqual (0, parent_event, "3");
2301 [Category ("NotWorking")]
2302 public class ControlInvokeTest {
2303 public delegate void TestDelegate ();
2308 ApplicationContext control_context;
2309 bool delegateCalled = false;
2310 bool threadDied = false;
2314 void CreateControl ()
2318 f.ShowInTaskbar = false;
2324 Console.WriteLine ("f.Handle = {0}", f.Handle);
2325 Console.WriteLine ("c.Handle = {0}", c.Handle);
2327 control_context = new ApplicationContext (f);
2330 Console.WriteLine ("pulsing");
2333 Console.WriteLine ("control thread running");
2334 Application.Run (control_context);
2336 Console.WriteLine ("dying");
2339 Console.WriteLine ("pulsing again");
2342 } catch (Exception e) { Console.WriteLine (e); }
2346 public void InvokeTest ()
2350 control_t = new Thread(new ThreadStart(CreateControl));
2356 Console.WriteLine ("waiting on monitor");
2359 Console.WriteLine ("making async call");
2361 IAsyncResult result;
2362 result = c.BeginInvoke (new TestDelegate (delegate_call));
2363 c.EndInvoke (result);
2365 Assert.IsTrue (delegateCalled, "Invoke1");
2368 Assert.IsTrue (threadDied, "Invoke2");
2371 public void delegate_call () {
2373 /* invoked on control_context's thread */
2374 delegateCalled = true;
2376 Console.WriteLine ("calling Application.Exit");
2377 control_context.ExitThread ();
2378 } catch (Exception e) { Console.WriteLine (e); }
2384 public class ControlWMTest
2387 public void WM_PARENTNOTIFY_Test ()
2393 tester = new WMTester ();
2394 child = new Control ();
2395 tester.Controls.Add (child);
2397 tester.Visible = true;
2398 child.Visible = true;
2400 child_handle = child.Handle.ToInt32 ();
2405 msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
2407 Assert.AreEqual (1, msgs.Count, "#1");
2409 m1 = (Message) msgs [0];
2410 Assert.AreEqual (WndMsg.WM_CREATE, ((WndMsg) LowOrder (m1.WParam)), "#2");
2411 //Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam), "#3");
2412 Assert.AreEqual (child_handle, m1.LParam.ToInt32 (), "#4");
2416 msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
2417 Assert.AreEqual (2, msgs.Count, "#5");
2418 m1 = (Message) msgs [1];
2420 Assert.AreEqual (WndMsg.WM_DESTROY, ((WndMsg) LowOrder (m1.WParam)), "#6");
2421 //Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam), "#7");
2422 Assert.AreEqual (child_handle, m1.LParam.ToInt32 (), "#8");
2427 internal static int LowOrder (int param)
2429 return ((int)(short)(param & 0xffff));
2432 internal static int HighOrder (int param)
2434 return ((int)(short)(param >> 16));
2437 internal static int LowOrder (IntPtr param)
2439 return ((int)(short)(param.ToInt32 () & 0xffff));
2442 internal static int HighOrder (IntPtr param)
2444 return ((int)(short)(param.ToInt32 () >> 16));
2447 internal class WMTester : Form
2449 internal ArrayList Messages = new ArrayList ();
2451 internal bool Contains (WndMsg msg)
2453 return Contains (msg, Messages);
2456 internal bool Contains (WndMsg msg, ArrayList list)
2458 foreach (Message m in Messages)
2460 if (m.Msg == (int) msg)
2466 internal ArrayList Find (WndMsg msg)
2468 ArrayList result = new ArrayList ();
2470 foreach (Message m in Messages)
2472 if (m.Msg == (int) msg)
2478 protected override void WndProc(ref Message m)
2480 Console.WriteLine ("WndProc: " + m.ToString ());
2482 base.WndProc (ref m);
2489 public class ControlLayoutTest
2492 public void SetUp ()
2497 [Test] // bug #80456
2498 public void LayoutTest ()
2500 MockLayoutEngine layoutEngine = new MockLayoutEngine ();
2501 MockControl c = new MockControl (layoutEngine);
2502 c.Layout += new LayoutEventHandler (LayoutEvent);
2503 Assert.IsFalse (layoutEngine.LayoutInvoked, "#A1");
2504 Assert.AreEqual (0, _layoutCount, "#A2");
2506 Assert.IsTrue (layoutEngine.LayoutInvoked, "#A3");
2507 Assert.AreEqual (1, _layoutCount, "#A4");
2509 layoutEngine.Reset ();
2510 c.OverrideOnLayout = true;
2511 Assert.IsFalse (layoutEngine.LayoutInvoked, "#B1");
2513 Assert.IsFalse (layoutEngine.LayoutInvoked, "#B2");
2514 Assert.AreEqual (1, _layoutCount, "#B3");
2517 void LayoutEvent (object sender, LayoutEventArgs e)
2522 private int _layoutCount;
2524 class MockControl : Control
2526 public MockControl (LayoutEngine layoutEngine)
2528 _layoutEngine = layoutEngine;
2531 public bool OverrideOnLayout
2533 get { return _overrideOnLayout; }
2534 set { _overrideOnLayout = value; }
2537 protected override void OnLayout (LayoutEventArgs levent)
2539 if (!OverrideOnLayout)
2540 base.OnLayout (levent);
2543 public override LayoutEngine LayoutEngine {
2545 if (_layoutEngine == null)
2546 return base.LayoutEngine;
2547 return _layoutEngine;
2551 private bool _overrideOnLayout;
2552 private LayoutEngine _layoutEngine;
2555 class MockLayoutEngine : LayoutEngine
2557 public bool LayoutInvoked {
2558 get { return _layoutInvoked; }
2561 public void Reset ()
2563 _layoutInvoked = false;
2566 public override bool Layout (object container, LayoutEventArgs args)
2568 _layoutInvoked = true;
2572 private bool _layoutInvoked;