2 // Copyright (c) 2005 Novell, Inc.
5 // Ritvik Mayank (mritvik@novell.com)
6 // Stefan Noack (noackstefan@googlemail.com)
10 using System.Collections;
11 using System.ComponentModel;
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;
22 using CategoryAttribute = NUnit.Framework.CategoryAttribute;
24 namespace MonoTests.System.Windows.Forms
27 public class ControlTest : TestHelper
30 public void Constructor1 ()
32 MockControl c = new MockControl ();
34 Assert.AreEqual (0, c.OnLocationChangedCount, "OnLocationChangedCount");
35 Assert.AreEqual (0, c.OnResizeCount, "OnResizeCount");
36 Assert.AreEqual (0, c.OnSizeChangedCount, "OnSizeChangedCount");
37 Assert.AreEqual (0, c.Height, "Height");
38 Assert.AreEqual (0, c.Left, "Left");
39 Assert.AreEqual (string.Empty, c.Name, "Name");
40 Assert.IsNull (c.Parent, "Parent");
41 Assert.AreEqual (string.Empty, c.Text, "#A:Text");
42 Assert.AreEqual (0, c.Top, "Top");
43 Assert.AreEqual (0, c.Width, "Width");
46 [Test] // .ctor (String)
47 public void Constructor2 ()
49 MockControl c = new MockControl ((string) null);
51 Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
52 Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
53 Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
54 Assert.AreEqual (0, c.Height, "#A:Height");
55 Assert.AreEqual (0, c.Left, "#A:Left");
56 Assert.AreEqual (string.Empty, c.Name, "#A:Name");
57 Assert.IsNull (c.Parent, "#A:Parent");
58 Assert.AreEqual (string.Empty, c.Text, "#A:Text");
59 Assert.AreEqual (0, c.Top, "#A:Top");
60 Assert.AreEqual (0, c.Width, "#A:Width");
62 c = new MockControl ("child");
64 Assert.AreEqual (0, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
65 Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
66 Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
67 Assert.AreEqual (0, c.Height, "#B:Height");
68 Assert.AreEqual (0, c.Left, "#B:Left");
69 Assert.AreEqual (string.Empty, c.Name, "#B:Name");
70 Assert.IsNull (c.Parent, "#B:Parent");
71 Assert.AreEqual ("child", c.Text, "#B:Text");
72 Assert.AreEqual (0, c.Top, "#B:Top");
73 Assert.AreEqual (0, c.Width, "#B:Width");
76 [Test] // .ctor (Control, String)
77 public void Constructor3 ()
79 Control parent = new Control ("parent");
80 MockControl c = new MockControl ((Control) null, (string) null);
82 Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
83 Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
84 Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
85 Assert.AreEqual (0, c.Height, "#A:Height");
86 Assert.AreEqual (0, c.Left, "#A:Left");
87 Assert.AreEqual (string.Empty, c.Name, "#A:Name");
88 Assert.IsNull (c.Parent, "#A:Parent");
89 Assert.AreEqual (string.Empty, c.Text, "#A:Text");
90 Assert.AreEqual (0, c.Top, "#A:Top");
91 Assert.AreEqual (0, c.Width, "#A:Width");
93 c = new MockControl ((Control) null, "child");
95 Assert.AreEqual (0, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
96 Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
97 Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
98 Assert.AreEqual (0, c.Height, "#B:Height");
99 Assert.AreEqual (0, c.Left, "#B:Left");
100 Assert.AreEqual (string.Empty, c.Name, "#B:Name");
101 Assert.IsNull (c.Parent, "#B:Parent");
102 Assert.AreEqual ("child", c.Text, "#B:Text");
103 Assert.AreEqual (0, c.Top, "#B:Top");
104 Assert.AreEqual (0, c.Width, "#B:Width");
106 c = new MockControl (parent, (string) null);
108 Assert.AreEqual (0, c.OnLocationChangedCount, "#C:OnLocationChangedCount");
109 Assert.AreEqual (0, c.OnResizeCount, "#C:OnResizeCount");
110 Assert.AreEqual (0, c.OnSizeChangedCount, "#C:OnSizeChangedCount");
111 Assert.AreEqual (0, c.Height, "#C:Height");
112 Assert.AreEqual (0, c.Left, "#C:Left");
113 Assert.AreEqual (string.Empty, c.Name, "#C:Name");
114 Assert.AreSame (parent, c.Parent, "#C:Parent");
115 Assert.AreEqual (string.Empty, c.Text, "#C:Text");
116 Assert.AreEqual (0, c.Top, "#C:Top");
117 Assert.AreEqual (0, c.Width, "#C:Width");
119 c = new MockControl (parent, "child");
121 Assert.AreEqual (0, c.OnLocationChangedCount, "#D:OnLocationChangedCount");
122 Assert.AreEqual (0, c.OnResizeCount, "#D:OnResizeCount");
123 Assert.AreEqual (0, c.OnSizeChangedCount, "#D:OnSizeChangedCount");
124 Assert.AreEqual (0, c.Height, "#D:Height");
125 Assert.AreEqual (0, c.Left, "#D:Left");
126 Assert.AreEqual (string.Empty, c.Name, "#D:Name");
127 Assert.AreSame (parent, c.Parent, "#D:Parent");
128 Assert.AreEqual ("child", c.Text, "#D:Text");
129 Assert.AreEqual (0, c.Top, "#D:Top");
130 Assert.AreEqual (0, c.Width, "#D:Width");
133 [Test] // .ctor (String, Int32, Int32, Int32, Int32)
134 public void Constructor4 ()
136 MockControl c = new MockControl ((string) null, 0, 0, 0, 0);
138 Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
139 Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
140 Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
141 Assert.AreEqual (0, c.Height, "#A:Height");
142 Assert.AreEqual (0, c.Left, "#A:Left");
143 Assert.AreEqual (string.Empty, c.Name, "#A:Name");
144 Assert.IsNull (c.Parent, "#A:Parent");
145 Assert.AreEqual (string.Empty, c.Text, "#A:Text");
146 Assert.AreEqual (0, c.Top, "#A:Top");
147 Assert.AreEqual (0, c.Width, "#A:Width");
149 c = new MockControl ((string) null, 1, 0, 0, 0);
151 Assert.AreEqual (1, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
152 Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
153 Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
154 Assert.AreEqual (0, c.Height, "#B:Height");
155 Assert.AreEqual (1, c.Left, "#B:Left");
156 Assert.AreEqual (string.Empty, c.Name, "#B:Name");
157 Assert.IsNull (c.Parent, "#B:Parent");
158 Assert.AreEqual (string.Empty, c.Text, "#B:Text");
159 Assert.AreEqual (0, c.Top, "#B:Top");
160 Assert.AreEqual (0, c.Width, "#B:Width");
162 c = new MockControl ("child", 0, 1, 0, 0);
164 Assert.AreEqual (1, c.OnLocationChangedCount, "#C:OnLocationChangedCount");
165 Assert.AreEqual (0, c.OnResizeCount, "#C:OnResizeCount");
166 Assert.AreEqual (0, c.OnSizeChangedCount, "#C:OnSizeChangedCount");
167 Assert.AreEqual (0, c.Height, "#C:Height");
168 Assert.AreEqual (0, c.Left, "#C:Left");
169 Assert.AreEqual (string.Empty, c.Name, "#C:Name");
170 Assert.IsNull (c.Parent, "#C:Parent");
171 Assert.AreEqual ("child", c.Text, "#C:Text");
172 Assert.AreEqual (1, c.Top, "#C:Top");
173 Assert.AreEqual (0, c.Width, "#C:Width");
175 c = new MockControl ("child", 0, 0, 1, 0);
177 Assert.AreEqual (0, c.OnLocationChangedCount, "#D:OnLocationChangedCount");
178 Assert.AreEqual (1, c.OnResizeCount, "#D:OnResizeCount");
179 Assert.AreEqual (1, c.OnSizeChangedCount, "#D:OnSizeChangedCount");
180 Assert.AreEqual (0, c.Height, "#D:Height");
181 Assert.AreEqual (0, c.Left, "#D:Left");
182 Assert.AreEqual (string.Empty, c.Name, "#D:Name");
183 Assert.IsNull (c.Parent, "#D:Parent");
184 Assert.AreEqual ("child", c.Text, "#D:Text");
185 Assert.AreEqual (0, c.Top, "#D:Top");
186 Assert.AreEqual (1, c.Width, "#D:Width");
188 c = new MockControl ("child", 0, 0, 0, 1);
190 Assert.AreEqual (0, c.OnLocationChangedCount, "#E:OnLocationChangedCount");
191 Assert.AreEqual (1, c.OnResizeCount, "#E:OnResizeCount");
192 Assert.AreEqual (1, c.OnSizeChangedCount, "#E:OnSizeChangedCount");
193 Assert.AreEqual (1, c.Height, "#E:Height");
194 Assert.AreEqual (0, c.Left, "#E:Left");
195 Assert.AreEqual (string.Empty, c.Name, "#E:Name");
196 Assert.IsNull (c.Parent, "#E:Parent");
197 Assert.AreEqual ("child", c.Text, "#E:Text");
198 Assert.AreEqual (0, c.Top, "#E:Top");
199 Assert.AreEqual (0, c.Width, "#E:Width");
201 c = new MockControl ("child", 1, 0, 1, 0);
203 Assert.AreEqual (1, c.OnLocationChangedCount, "#F:OnLocationChangedCount");
204 Assert.AreEqual (1, c.OnResizeCount, "#F:OnResizeCount");
205 Assert.AreEqual (1, c.OnSizeChangedCount, "#F:OnSizeChangedCount");
206 Assert.AreEqual (0, c.Height, "#F:Height");
207 Assert.AreEqual (1, c.Left, "#F:Left");
208 Assert.AreEqual (string.Empty, c.Name, "#F:Name");
209 Assert.IsNull (c.Parent, "#F:Parent");
210 Assert.AreEqual ("child", c.Text, "#F:Text");
211 Assert.AreEqual (0, c.Top, "#F:Top");
212 Assert.AreEqual (1, c.Width, "#F:Width");
214 c = new MockControl ("child", 0, 1, 0, 1);
216 Assert.AreEqual (1, c.OnLocationChangedCount, "#G:OnLocationChangedCount");
217 Assert.AreEqual (1, c.OnResizeCount, "#G:OnResizeCount");
218 Assert.AreEqual (1, c.OnSizeChangedCount, "#G:OnSizeChangedCount");
219 Assert.AreEqual (1, c.Height, "#G:Height");
220 Assert.AreEqual (0, c.Left, "#G:Left");
221 Assert.AreEqual (string.Empty, c.Name, "#G:Name");
222 Assert.IsNull (c.Parent, "#G:Parent");
223 Assert.AreEqual ("child", c.Text, "#G:Text");
224 Assert.AreEqual (1, c.Top, "#G:Top");
225 Assert.AreEqual (0, c.Width, "#G:Width");
228 [Test] // .ctor (Control, String, Int32, Int32, Int32, Int32)
229 public void Constructor5 ()
231 Control parent = new Control ("parent");
232 MockControl c = new MockControl ((Control) null,
233 (string) null, 0, 0, 0, 0);
235 Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
236 Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
237 Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
238 Assert.AreEqual (0, c.Height, "#A:Height");
239 Assert.AreEqual (0, c.Left, "#A:Left");
240 Assert.AreEqual (string.Empty, c.Name, "#A:Name");
241 Assert.IsNull (c.Parent, "#A:Parent");
242 Assert.AreEqual (string.Empty, c.Text, "#A:Text");
243 Assert.AreEqual (0, c.Top, "#A:Top");
244 Assert.AreEqual (0, c.Width, "#A:Width");
246 c = new MockControl (parent, (string) null, 1, 0, 0, 0);
248 Assert.AreEqual (1, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
249 Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
250 Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
251 Assert.AreEqual (0, c.Height, "#B:Height");
252 Assert.AreEqual (1, c.Left, "#B:Left");
253 Assert.AreEqual (string.Empty, c.Name, "#B:Name");
254 Assert.AreSame (parent, c.Parent, "#B:Parent");
255 Assert.AreEqual (string.Empty, c.Text, "#B:Text");
256 Assert.AreEqual (0, c.Top, "#B:Top");
257 Assert.AreEqual (0, c.Width, "#B:Width");
259 c = new MockControl ((Control) null, "child", 0, 1, 0, 0);
261 Assert.AreEqual (1, c.OnLocationChangedCount, "#C:OnLocationChangedCount");
262 Assert.AreEqual (0, c.OnResizeCount, "#C:OnResizeCount");
263 Assert.AreEqual (0, c.OnSizeChangedCount, "#C:OnSizeChangedCount");
264 Assert.AreEqual (0, c.Height, "#C:Height");
265 Assert.AreEqual (0, c.Left, "#C:Left");
266 Assert.AreEqual (string.Empty, c.Name, "#C:Name");
267 Assert.IsNull (c.Parent, "#C:Parent");
268 Assert.AreEqual ("child", c.Text, "#C:Text");
269 Assert.AreEqual (1, c.Top, "#C:Top");
270 Assert.AreEqual (0, c.Width, "#C:Width");
272 c = new MockControl (parent, "child", 0, 0, 1, 0);
274 Assert.AreEqual (0, c.OnLocationChangedCount, "#D:OnLocationChangedCount");
275 Assert.AreEqual (1, c.OnResizeCount, "#D:OnResizeCount");
276 Assert.AreEqual (1, c.OnSizeChangedCount, "#D:OnSizeChangedCount");
277 Assert.AreEqual (0, c.Height, "#D:Height");
278 Assert.AreEqual (0, c.Left, "#D:Left");
279 Assert.AreEqual (string.Empty, c.Name, "#D:Name");
280 Assert.AreSame (parent, c.Parent, "#D:Parent");
281 Assert.AreEqual ("child", c.Text, "#D:Text");
282 Assert.AreEqual (0, c.Top, "#D:Top");
283 Assert.AreEqual (1, c.Width, "#D:Width");
285 c = new MockControl (parent, "child", 0, 0, 0, 1);
287 Assert.AreEqual (0, c.OnLocationChangedCount, "#E:OnLocationChangedCount");
288 Assert.AreEqual (1, c.OnResizeCount, "#E:OnResizeCount");
289 Assert.AreEqual (1, c.OnSizeChangedCount, "#E:OnSizeChangedCount");
290 Assert.AreEqual (1, c.Height, "#E:Height");
291 Assert.AreEqual (0, c.Left, "#E:Left");
292 Assert.AreEqual (string.Empty, c.Name, "#E:Name");
293 Assert.AreSame (parent, c.Parent, "#E:Parent");
294 Assert.AreEqual ("child", c.Text, "#E:Text");
295 Assert.AreEqual (0, c.Top, "#E:Top");
296 Assert.AreEqual (0, c.Width, "#E:Width");
298 c = new MockControl (parent, "child", 1, 0, 1, 0);
300 Assert.AreEqual (1, c.OnLocationChangedCount, "#F:OnLocationChangedCount");
301 Assert.AreEqual (1, c.OnResizeCount, "#F:OnResizeCount");
302 Assert.AreEqual (1, c.OnSizeChangedCount, "#F:OnSizeChangedCount");
303 Assert.AreEqual (0, c.Height, "#F:Height");
304 Assert.AreEqual (1, c.Left, "#F:Left");
305 Assert.AreEqual (string.Empty, c.Name, "#F:Name");
306 Assert.AreSame (parent, c.Parent, "#F:Parent");
307 Assert.AreEqual ("child", c.Text, "#F:Text");
308 Assert.AreEqual (0, c.Top, "#F:Top");
309 Assert.AreEqual (1, c.Width, "#F:Width");
311 c = new MockControl (parent, "child", 0, 1, 0, 1);
313 Assert.AreEqual (1, c.OnLocationChangedCount, "#G:OnLocationChangedCount");
314 Assert.AreEqual (1, c.OnResizeCount, "#G:OnResizeCount");
315 Assert.AreEqual (1, c.OnSizeChangedCount, "#G:OnSizeChangedCount");
316 Assert.AreEqual (1, c.Height, "#G:Height");
317 Assert.AreEqual (0, c.Left, "#G:Left");
318 Assert.AreEqual (string.Empty, c.Name, "#G:Name");
319 Assert.AreSame (parent, c.Parent, "#G:Parent");
320 Assert.AreEqual ("child", c.Text, "#G:Text");
321 Assert.AreEqual (1, c.Top, "#G:Top");
322 Assert.AreEqual (0, c.Width, "#G:Width");
326 public void DisposeTest ()
328 ControlDisposeTester control = new ControlDisposeTester ();
329 control.Visible = true;
333 control.CreateControl ();
334 } catch (ObjectDisposedException ex) {
335 Console.WriteLine (ex);
338 Assert.IsFalse (control.IsHandleCreated, "#2");
340 // The control remains Visible until WM_DESTROY is received.
341 Assert.IsTrue (control.Visible, "#3");
344 control.InvokeCreateHandle ();
346 } catch (ObjectDisposedException ex) {
347 //Console.WriteLine (ex);
351 private class ControlDisposeTester : Control
353 public void InvokeCreateHandle ()
360 public void AutoSizeTest ()
362 ControlAutoSizeTester c = new ControlAutoSizeTester (new Size (23, 17), AutoSizeMode.GrowAndShrink);
365 f.Size = new Size (200, 200);
369 Size s = new Size (42, 42);
372 Point l = new Point (10, 10);
375 //Check wether normal size setting is OK
376 Assert.AreEqual (s, c.Size, "#S1");
378 //Check wether size remains without GetPreferredSize implemented even when AutoSize turned on.
381 Assert.AreEqual (s, c.Size, "#S2");
383 //Simulate a Control implementing GetPreferredSize
384 c.UseCustomPrefSize = true;
387 //Check wether size shrinks to preferred size
388 Assert.AreEqual (c.CustomPrefSize, c.Size, "#S3");
389 //Check wether Location stays constant
390 Assert.AreEqual (l, c.Location, "#L1");
392 //Check wether Dock is respected
393 c.Dock = DockStyle.Bottom;
394 Assert.AreEqual (f.ClientSize.Width, c.Width, "#D1");
396 //Check wether size shrinks to preferred size again
397 c.Dock = DockStyle.None;
398 Assert.AreEqual (c.CustomPrefSize, c.Size, "#S4");
400 //Check wether Anchor is respected for adjusting Locatioon
401 c.Anchor = AnchorStyles.Bottom;
403 Assert.AreEqual (l.Y + 50, c.Top, "#A1");
404 //Check wether size is still OK
405 Assert.AreEqual (c.CustomPrefSize, c.Size, "#S5");
409 c.Anchor = AnchorStyles.Top | AnchorStyles.Left;
412 //Check wether shrinking to zero is possible
413 c.CustomPrefSize = new Size (0, 0);
415 Assert.AreEqual (c.CustomPrefSize, c.Size, "#S6");
417 //Check wether MinimumSize is honored
418 c.MinimumSize = new Size (10, 12);
419 c.CustomPrefSize = new Size (5, 5);
421 Assert.AreEqual (c.MinimumSize, c.Size, "#S7");
422 c.MinimumSize = new Size (0, 0);
424 //Check wether MaximumSize is honored
425 c.MaximumSize = new Size (100, 120);
426 c.CustomPrefSize = new Size (500, 500);
428 Assert.AreEqual (c.MaximumSize, c.Size, "#S8");
430 //Check wether shrinking does not happen when GrowOnly
432 s = new Size (23, 23);
434 c.CustomPrefSize = new Size (5, 5);
435 c.AutoSizeMode = AutoSizeMode.GrowOnly;
438 Assert.AreEqual (s, c.Size, "#S9");
442 public class ControlAutoSizeTester : Control {
445 public ControlAutoSizeTester (Size customPrefSize, AutoSizeMode autoSizeMode)
447 custom_prefsize = customPrefSize;
448 AutoSizeMode = autoSizeMode;
451 public AutoSizeMode AutoSizeMode {
453 base.SetAutoSizeMode (value);
457 private bool use_custom_prefsize = false;
458 public bool UseCustomPrefSize {
460 use_custom_prefsize = value;
464 private Size custom_prefsize;
466 public Size CustomPrefSize {
468 return custom_prefsize;
471 custom_prefsize = value;
476 public override Size GetPreferredSize (Size proposedSize)
478 if (use_custom_prefsize) {
479 return custom_prefsize;
481 return base.GetPreferredSize(proposedSize);
489 public void Bug82748 ()
491 Form f = new Form ();
492 f.ShowInTaskbar = false;
494 Control c = new Control ();
495 c.Size = new Size (100, 100);
497 Control c2 = new Control ();
501 c.Anchor = AnchorStyles.Right;
507 Assert.AreEqual (0, c.Left, "A1");
514 public void InvokeTestParentHandle ()
516 Control child, parent;
518 parent = new Control ();
519 child = new Control ();
520 parent.Controls.Add (child);
521 parent.Visible = true;
522 parent.CreateControl ();
523 child.Invoke (new CrossAppDomainDelegate (dummy)) ;
530 public class ControlStylesTester : Control {
531 private WindowStyles style;
532 private WindowStyles ex_style;
533 private bool or_styles;
535 public ControlStylesTester (WindowStyles Style, WindowStyles ExStyle, bool OrStyles)
539 or_styles = OrStyles;
542 protected override CreateParams CreateParams {
544 CreateParams result = base.CreateParams;
546 result.Style |= (int) style;
547 result.ExStyle |= (int) ex_style;
549 result.Style = (int) style;
550 result.ExStyle = (int) ex_style;
558 public void ControlSizeTest ()
560 ControlStylesTester c = new ControlStylesTester (WindowStyles.WS_CHILD, 0, true);
561 Assert.AreEqual ("{X=0,Y=0}", c.Location.ToString (), "#L1");
562 Assert.AreEqual ("{Width=0, Height=0}", c.Size.ToString (), "#S1");
567 public void CaptureTest ()
569 Form frm = new Form ();
570 ControlOverrideLogger log = new ControlOverrideLogger ();
571 frm.Controls.Add (log);
575 log.BackColor = Color.Blue;
576 log.Size = new Size (100, 100);
579 Application.DoEvents ();
582 Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") > -1, "#01");
584 log = new ControlOverrideLogger ();
587 Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") > -1, "#02");
589 log = new ControlOverrideLogger ();
591 Assert.IsTrue (log.IsHandleCreated, "#03");
592 Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") == -1, "#04");
594 log = new ControlOverrideLogger ();
596 Assert.IsFalse (log.IsHandleCreated, "#05");
597 Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") == -1, "#06");
601 public class OnPaintTester : Form
605 ArrayList list = new ArrayList ();
606 public bool Recursive;
607 public bool TestRefresh;
608 public bool TestInvalidate;
609 public bool TestUpdate;
611 public new bool DoubleBuffered {
613 return base.DoubleBuffered;
616 base.DoubleBuffered = value;
620 protected override void OnPaint (PaintEventArgs pevent)
622 Assert.IsFalse (list.Contains (pevent.Graphics), "OnPaintTester.OnPaint: Got the same Graphics twice");
623 list.Add (pevent.Graphics);
627 Recursive = counter > 0 || Recursive;
632 else if (TestInvalidate)
638 base.OnPaint (pevent);
642 public new void Show ()
645 Application.DoEvents ();
650 public void ControlCollectionTest ()
652 Form frm = new Form ();
653 frm.IsMdiContainer = true;
654 Form child = new Form ();
655 Control.ControlCollection c = new Control.ControlCollection (frm);
656 child.MdiParent = frm;
664 [ExpectedException (typeof (ArgumentException))]
665 public void ControlCollectionExceptionTest ()
667 Form frm = new Form ();
668 frm.IsMdiContainer = true;
669 Form child = new Form ();
670 Control.ControlCollection c = new Control.ControlCollection (frm);
671 //child.MdiParent = frm;
679 [Category ("NotWorking")]
680 public void OnPaintTest ()
682 using (OnPaintTester t = new OnPaintTester ()) {
683 t.TestRefresh = true;
685 Assert.IsTrue (t.Recursive, "#1");
688 using (OnPaintTester t = new OnPaintTester ()) {
691 Assert.IsFalse (t.Recursive, "#2");
694 using (OnPaintTester t = new OnPaintTester ()) {
695 t.TestInvalidate = true;
697 Assert.IsFalse (t.Recursive, "#3");
702 [Category ("Interactive")]
703 public void OnPaintDoubleBufferedTest ()
705 using (OnPaintTester t = new OnPaintTester ()) {
706 t.DoubleBuffered = true;
707 t.TestRefresh = true;
709 Assert.IsTrue (t.Recursive, "#1");
712 using (OnPaintTester t = new OnPaintTester ()) {
713 t.DoubleBuffered = true;
716 Assert.IsFalse (t.Recursive, "#2");
719 using (OnPaintTester t = new OnPaintTester ()) {
720 t.DoubleBuffered = true;
721 t.TestInvalidate = true;
723 Assert.IsFalse (t.Recursive, "#3");
727 public class PaintEventForm : Form
729 public ArrayList overrides = new ArrayList ();
730 public ArrayList events = new ArrayList ();
732 public PaintEventForm ()
734 Paint += new PaintEventHandler (DoubleBufferEventForm_Paint);
736 public bool GetControlStyle (ControlStyles style)
738 return base.GetStyle (style);
741 public void SetControlStyle (ControlStyles style, bool value)
743 base.SetStyle (style, value);
746 void DoubleBufferEventForm_Paint (object sender, PaintEventArgs e)
751 protected override void OnPaintBackground (PaintEventArgs e)
753 base.OnPaintBackground (e);
754 overrides.Add("OnPaintBackground");
757 protected override void OnPaint (PaintEventArgs pevent)
759 base.OnPaint (pevent);
760 overrides.Add("OnPaint");
765 [Ignore ("Can't find a reliable way to generate a paint message on Windows.")]
766 public void EventStyleTest ()
769 using (PaintEventForm f = new PaintEventForm ()) {
771 f.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
773 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#A1");
774 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#A2");
775 Assert.IsTrue (f.events.Contains ("Paint"), "#A3");
778 using (PaintEventForm f = new PaintEventForm ()) {
780 f.SetControlStyle (ControlStyles.DoubleBuffer, true);
782 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#B1");
783 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#B2");
784 Assert.IsTrue (f.events.Contains ("Paint"), "#B3");
787 using (PaintEventForm f = new PaintEventForm ()) {
789 f.SetControlStyle (ControlStyles.AllPaintingInWmPaint, true);
791 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#C1");
792 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#C2");
793 Assert.IsTrue (f.events.Contains ("Paint"), "#C3");
796 using (PaintEventForm f = new PaintEventForm ()) {
798 f.SetControlStyle (ControlStyles.UserPaint, true);
800 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#D1");
801 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#D2");
802 Assert.IsTrue (f.events.Contains ("Paint"), "#D3");
805 using (PaintEventForm f = new PaintEventForm ()) {
807 f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
809 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#E1");
810 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#E2");
811 Assert.IsTrue (f.events.Contains ("Paint"), "#E3");
814 using (PaintEventForm f = new PaintEventForm ()) {
816 f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
818 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#F1");
819 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#F2");
820 Assert.IsTrue (f.events.Contains ("Paint"), "#F3");
823 using (PaintEventForm f = new PaintEventForm ()) {
825 f.SetControlStyle (ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
827 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#G1");
828 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#G2");
829 Assert.IsTrue (f.events.Contains ("Paint"), "#G3");
832 using (PaintEventForm f = new PaintEventForm ()) {
834 f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true);
836 Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#H1");
837 Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#H2");
838 Assert.IsTrue (f.events.Contains ("Paint"), "#H3");
842 public class DoubleBufferedForm : Form
846 public DoubleBufferedForm ()
848 this.DoubleBuffered = true;
851 protected override void OnPaint (PaintEventArgs e)
853 if (failed || painted)
858 e.Graphics.DrawString (Size.ToString (), Font, Brushes.AliceBlue, new Point (2, 2));
859 } catch (Exception exception) {
860 Console.WriteLine (exception.StackTrace);
866 public class DoubleBufferControl : Control
868 public bool IsDoubleBuffered
870 get { return base.DoubleBuffered; }
871 set { base.DoubleBuffered = value; }
874 public bool GetControlStyle (ControlStyles style)
876 return base.GetStyle (style);
879 public void SetControlStyle (ControlStyles style, bool value)
881 base.SetStyle (style, value);
886 [Ignore ("Can't find a reliable way to generate a paint message on Windows.")]
887 public void DoubleBufferTest ()
889 DoubleBufferedForm f = new DoubleBufferedForm ();
890 f.ShowInTaskbar = false;
894 Assert.IsFalse (f.failed, "#01");
895 Assert.IsTrue (f.painted, "The control was never painted, so please check the test");
900 public void DoubleBufferedTest ()
902 DoubleBufferControl c = new DoubleBufferControl ();
903 Assert.IsFalse (c.IsDoubleBuffered, "#A1");
904 Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#A2");
905 Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#A3");
906 Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#A4");
907 Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#A5");
909 c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
910 Assert.IsTrue (c.IsDoubleBuffered, "#B1");
911 Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#B2");
912 Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#B3");
913 Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#B4");
914 Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#A5");
916 c.SetControlStyle (ControlStyles.AllPaintingInWmPaint, false);
917 c.SetControlStyle (ControlStyles.UserPaint, false);
918 Assert.IsTrue (c.IsDoubleBuffered, "#C1");
919 Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#C2");
920 Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#C3");
921 Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#C4");
922 Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#C5");
924 c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, false);
925 Assert.IsFalse (c.IsDoubleBuffered, "#D1");
926 Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#D2");
927 Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#D3");
928 Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#D4");
929 Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#D5");
931 c.SetControlStyle (ControlStyles.DoubleBuffer, true);
932 Assert.IsFalse (c.IsDoubleBuffered, "#E1");
933 Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#E2");
934 Assert.IsTrue (c.GetControlStyle (ControlStyles.DoubleBuffer), "#E3");
935 Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#E4");
936 Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#E5");
938 c.SetControlStyle (ControlStyles.DoubleBuffer, false);
939 Assert.IsFalse (c.IsDoubleBuffered, "#F1");
940 Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#F2");
941 Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#F3");
942 Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#F4");
943 Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#F5");
945 c.IsDoubleBuffered = true;
946 Assert.IsTrue (c.IsDoubleBuffered, "#G1");
947 Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#G2");
948 Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#G3");
949 Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#G4");
950 Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#G5");
952 c.SetControlStyle (ControlStyles.AllPaintingInWmPaint, true);
953 c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
954 c.SetControlStyle (ControlStyles.DoubleBuffer, true);
955 c.SetControlStyle (ControlStyles.UserPaint, true);
956 c.IsDoubleBuffered = false;
957 Assert.IsFalse (c.IsDoubleBuffered, "#H1");
958 Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#H2");
959 Assert.IsTrue (c.GetControlStyle (ControlStyles.DoubleBuffer), "#H3");
960 Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#H4");
961 Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#H5");
965 public void DoubleBufferedStyleTest ()
967 DoubleBufferControl c = new DoubleBufferControl ();
968 TestControlStyle.CheckStyles (c, "#A1", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility);
970 c.IsDoubleBuffered = true;
971 TestControlStyle.CheckStyles (c, "#A2", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility, ControlStyles.OptimizedDoubleBuffer);
973 c.IsDoubleBuffered = false;
974 TestControlStyle.CheckStyles (c, "#A3", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility);
976 c = new DoubleBufferControl ();
977 foreach (ControlStyles style in Enum.GetValues (typeof(ControlStyles))) {
978 c.SetControlStyle (style, false);
981 TestControlStyle.CheckStyles (c, "#B1");
983 c.IsDoubleBuffered = true;
984 TestControlStyle.CheckStyles (c, "#B2", ControlStyles.OptimizedDoubleBuffer, ControlStyles.AllPaintingInWmPaint);
986 c.IsDoubleBuffered = false;
987 TestControlStyle.CheckStyles (c, "#B3", ControlStyles.AllPaintingInWmPaint);
993 public static void TestAccessibility(Control c, string Default, string Description, string Name, AccessibleRole Role)
995 Assert.IsNotNull (c.AccessibilityObject, "Acc1");
996 Assert.AreEqual (Default, c.AccessibleDefaultActionDescription, "Acc2");
997 Assert.AreEqual (Description, c.AccessibleDescription, "Acc3");
998 Assert.AreEqual (Name, c.AccessibleName, "Acc4");
999 Assert.AreEqual (Role, c.AccessibleRole, "Acc5");
1002 public static string TestControl(Control container, Control start, bool forward) {
1005 ctl = container.GetNextControl(start, forward);
1016 public void CreatedTest ()
1018 Control c = new Control ();
1019 Assert.IsFalse (c.Created, "A1");
1023 [Category ("NotWorking")]
1024 public void CreatedAccessibilityTest ()
1026 Control c = new Control ();
1027 Assert.IsFalse (c.Created, "A1");
1029 Helper.TestAccessibility(c, null, null, null, AccessibleRole.Default);
1031 Assert.IsTrue (c.Created, "A2");
1035 Assert.IsFalse (c.Created, "A3");
1039 [Category ("NotWorking")]
1040 public void BoundsTest ()
1042 Control c = new Control ();
1043 Assert.IsTrue (c.Bounds.IsEmpty, "A1");
1044 Assert.IsTrue (c.Size.IsEmpty, "A2");
1045 Assert.IsTrue (c.ClientSize.IsEmpty, "A3");
1046 Assert.IsTrue (c.ClientRectangle.IsEmpty, "A4");
1048 Assert.AreEqual (((IWin32Window)c).Handle, c.Handle, "A5");
1050 /* this part fails on linux because we can't allocate X windows which are 0x0,
1051 and the Control bounds directly reflect the size of the X window */
1053 Assert.IsTrue (c.Bounds.IsEmpty, "A6");
1054 Assert.IsTrue (c.Size.IsEmpty, "A7");
1055 Assert.IsTrue (c.ClientSize.IsEmpty, "A8");
1056 Assert.IsTrue (c.ClientRectangle.IsEmpty, "A9");
1060 [Ignore ("Depends on specific DPI")]
1061 public void FontHeightTest ()
1063 MockControl c = new MockControl ();
1064 Assert.AreEqual (13, c.font_height);
1068 public void FontTest ()
1070 Control c = new Control ();
1071 Assert.IsFalse (c.Font.Bold, "#A1");
1072 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#A2");
1073 Assert.IsFalse (c.Font.Italic, "#A3");
1074 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#A4");
1075 Assert.AreEqual (8.25, c.Font.Size, "#A5");
1076 Assert.AreEqual (8.25, c.Font.SizeInPoints, "#A6");
1077 Assert.IsFalse (c.Font.Strikeout, "#A7");
1078 Assert.IsFalse (c.Font.Underline, "#A8");
1079 Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#A9");
1081 Assert.IsTrue (c.Font.IsSystemFont, "#A10");
1084 c.Font = new Font (c.Font.FontFamily, 3, FontStyle.Italic);
1085 Assert.IsFalse (c.Font.Bold, "#B1");
1086 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#B2");
1087 Assert.IsTrue (c.Font.Italic, "#B3");
1088 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#B4");
1089 Assert.AreEqual (3, c.Font.Size, "#B5");
1090 Assert.AreEqual (3, c.Font.SizeInPoints, "#B6");
1091 Assert.IsFalse (c.Font.Strikeout, "#B7");
1092 Assert.IsFalse (c.Font.Underline, "#B8");
1093 Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#B9");
1095 Assert.AreEqual (false, c.Font.IsSystemFont, "#B10");
1100 [Category ("NotWorking")] // on Unix mapping is done to Bitstream Vera Sans
1101 public void FontTest_Names ()
1103 Control c = new Control ();
1104 Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#1");
1105 Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#2");
1109 public void PubPropTest()
1111 Control c = new Control();
1113 Assert.IsFalse (c.AllowDrop , "A1");
1114 Assert.AreEqual(AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "A2");
1116 Assert.AreEqual ("Control", c.BackColor.Name , "B1");
1117 Assert.IsNull (c.BackgroundImage, "B2");
1118 Assert.IsNull (c.BindingContext, "B3");
1120 Assert.AreEqual (ImageLayout.Tile, c.BackgroundImageLayout, "B4");
1123 Assert.IsFalse (c.CanFocus, "C1");
1124 Assert.IsTrue (c.CanSelect, "C2");
1125 Assert.IsFalse (c.Capture, "C3");
1126 Assert.IsTrue (c.CausesValidation, "C4");
1128 Assert.IsNotNull (c.CompanyName, "C7");
1129 Assert.IsNull (c.Container, "C8");
1130 Assert.IsFalse (c.ContainsFocus, "C9");
1131 Assert.IsNull (c.ContextMenu, "C10");
1132 Assert.AreEqual (0, c.Controls.Count, "C11");
1133 Assert.IsFalse (c.Created, "C12");
1134 Assert.AreEqual (Cursors.Default, c.Cursor, "C13");
1136 Assert.IsNotNull(c.DataBindings, "D1");
1137 Assert.AreEqual("Control", Control.DefaultBackColor.Name, "D2");
1138 Assert.AreEqual("ControlText", Control.DefaultForeColor.Name, "D3");
1139 Assert.AreEqual(FontStyle.Regular, Control.DefaultFont.Style, "D4");
1140 Assert.AreEqual (new Rectangle(0, 0, 0, 0), c.DisplayRectangle , "D5");
1141 Assert.IsFalse (c.Disposing, "D6");
1142 Assert.AreEqual(DockStyle.None, c.Dock, "D7");
1144 Assert.IsTrue (c.Enabled, "E1");
1146 Assert.IsFalse (c.Focused, "F1");
1147 Assert.AreEqual (FontStyle.Regular, c.Font.Style, "F2");
1148 Assert.AreEqual (SystemColors.ControlText, c.ForeColor, "F3");
1150 Assert.IsFalse (c.HasChildren, "H2");
1152 Assert.AreEqual (ImeMode.NoControl, c.ImeMode, "I1");
1153 Assert.IsFalse (c.InvokeRequired, "I2");
1154 Assert.IsFalse (c.IsAccessible, "I3");
1155 Assert.IsFalse (c.IsDisposed, "I4");
1156 Assert.IsFalse (c.IsHandleCreated, "I5");
1158 Assert.AreEqual(Point.Empty, c.Location, "L2");
1161 Assert.IsTrue(c.MaximumSize.IsEmpty);
1162 Assert.IsTrue(c.MinimumSize.IsEmpty);
1164 Assert.AreEqual (Keys.None, Control.ModifierKeys, "M1");
1165 Assert.IsTrue (Control.MousePosition.X >= 0 && Control.MousePosition.Y >= 0, "M2");
1166 Assert.AreEqual (MouseButtons.None, Control.MouseButtons, "M3");
1168 Assert.AreEqual("", c.Name, "N1");
1169 c.Name = "Control Name";
1170 Assert.AreEqual("Control Name", c.Name, "N2");
1172 Assert.IsNull (c.Parent, "P1");
1173 Assert.IsNotNull (c.ProductName, "P2");
1174 Assert.IsTrue (c.ProductName != "", "P3");
1175 Assert.IsNotNull (c.ProductVersion, "P4");
1176 Assert.IsTrue (c.ProductVersion != "", "P5");
1178 Assert.IsFalse (c.RecreatingHandle, "R1");
1179 Assert.IsNull (c.Region, "R2");
1180 Assert.AreEqual (RightToLeft.No, c.RightToLeft, "R4");
1182 Assert.IsNull (c.Site, "S1");
1184 Assert.AreEqual (0, c.TabIndex , "T1");
1185 Assert.IsTrue (c.TabStop, "T2");
1186 Assert.IsNull (c.Tag, "T3");
1187 Assert.AreEqual ("", c.Text, "T4");
1189 Assert.IsTrue (c.Visible, "V1");
1193 public void SizeChangeTest ()
1195 Form f = new Form ();
1196 Control c = new Control ();
1199 c.Resize += new EventHandler(SizeChangedTest_ResizeHandler);
1202 Assert.AreEqual (true, (bool) c.Tag, "#1");
1206 private void SizeChangedTest_ResizeHandler (object sender, EventArgs e)
1208 ((Control) sender).Tag = false;
1212 public void NegativeHeightTest ()
1214 Control c = new Control ();
1215 IntPtr handle = c.Handle;
1216 c.Resize += new EventHandler(NegativeHeightTest_ResizeHandler);
1220 Assert.AreEqual (0, (int) c.Tag, "#1");
1222 Assert.AreEqual (handle, handle, "Removes warning.");
1225 private void NegativeHeightTest_ResizeHandler (object sender, EventArgs e)
1227 Control c = (Control) sender;
1232 public void TopLevelControlTest () {
1233 Control c = new Control ();
1235 Assert.AreEqual(null, c.TopLevelControl, "T1");
1237 Panel p = new Panel ();
1241 Assert.AreEqual(null, c.TopLevelControl, "T2");
1243 Form f = new Form ();
1244 f.ShowInTaskbar = false;
1248 Assert.AreEqual (f, c.TopLevelControl, "T3");
1249 Assert.AreEqual (f, f.TopLevelControl, "T4");
1255 public void RelationTest() {
1262 Assert.AreEqual(true , c1.Visible , "Rel1");
1263 Assert.AreEqual(false, c1.Contains(c2) , "Rel2");
1264 Assert.AreEqual("System.Windows.Forms.Control", c1.ToString() , "Rel3");
1266 c1.Controls.Add(c2);
1267 Assert.AreEqual(true , c2.Visible , "Rel4");
1268 Assert.AreEqual(true, c1.Contains(c2) , "Rel5");
1270 c1.Anchor = AnchorStyles.Top;
1271 c1.SuspendLayout ();
1272 c1.Anchor = AnchorStyles.Left ;
1274 Assert.AreEqual(AnchorStyles.Left , c1.Anchor, "Rel6");
1276 c1.SetBounds(10, 20, 30, 40) ;
1277 Assert.AreEqual(new Rectangle(10, 20, 30, 40), c1.Bounds, "Rel7");
1279 Assert.AreEqual(c1, c2.Parent, "Rel8");
1283 public void AnchorDockTest ()
1285 Control c = new Control ();
1287 Assert.AreEqual (DockStyle.None, c.Dock, "1");
1288 Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "2");
1290 c.Dock = DockStyle.Top;
1291 Assert.AreEqual (DockStyle.Top, c.Dock, "3");
1292 Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "4");
1294 c.Anchor = AnchorStyles.Top;
1295 Assert.AreEqual (DockStyle.None, c.Dock, "5");
1296 Assert.AreEqual (AnchorStyles.Top, c.Anchor, "6");
1300 [Category ("NotWorking")]
1301 public void TabOrder()
1306 Label label1 = new Label(); // To test non-tabstop items as well
1307 Label label2 = new Label();
1309 GroupBox group1 = new GroupBox();
1310 GroupBox group2 = new GroupBox();
1311 GroupBox group3 = new GroupBox();
1313 TextBox text1 = new TextBox();
1315 RadioButton radio11 = new RadioButton();
1316 RadioButton radio12 = new RadioButton();
1317 RadioButton radio13 = new RadioButton();
1318 RadioButton radio14 = new RadioButton();
1319 RadioButton radio21 = new RadioButton();
1320 RadioButton radio22 = new RadioButton();
1321 RadioButton radio23 = new RadioButton();
1322 RadioButton radio24 = new RadioButton();
1323 RadioButton radio31 = new RadioButton();
1324 RadioButton radio32 = new RadioButton();
1325 RadioButton radio33 = new RadioButton();
1326 RadioButton radio34 = new RadioButton();
1329 form.ShowInTaskbar = false;
1331 form.ClientSize = new Size (520, 520);
1332 Assert.AreEqual(new Size(520, 520), form.ClientSize, "Tab1");
1334 form.Text = "SWF Taborder Test App Form";
1335 Assert.AreEqual("SWF Taborder Test App Form", form.Text, "Tab2");
1337 label1.Location = new Point(10, 10);
1338 Assert.AreEqual(new Point(10, 10), label1.Location, "Tab3");
1339 label1.Text = "Label1";
1340 form.Controls.Add(label1);
1342 label2.Location = new Point(200, 10);
1343 label2.Text = "Label2";
1344 form.Controls.Add(label2);
1346 group1.Text = "Group1";
1347 group2.Text = "Group2";
1348 group3.Text = "Group3";
1350 group1.Size = new Size(200, 400);
1351 group2.Size = new Size(200, 400);
1352 group3.Size = new Size(180, 180);
1353 Assert.AreEqual(new Size(180, 180), group3.Size, "Tab4");
1355 group1.Location = new Point(10, 40);
1356 group2.Location = new Point(220, 40);
1357 group3.Location = new Point(10, 210);
1359 group1.TabIndex = 30;
1360 Assert.AreEqual(30, group1.TabIndex, "Tab5");
1361 group1.TabStop = true;
1363 // Don't assign, test automatic assignment
1364 //group2.TabIndex = 0;
1365 group2.TabStop = true;
1366 Assert.AreEqual(0, group2.TabIndex, "Tab6");
1368 group3.TabIndex = 35;
1369 group3.TabStop = true;
1371 // Test default tab index
1372 Assert.AreEqual(0, radio11.TabIndex, "Tab7");
1374 text1.Text = "Edit Control";
1376 radio11.Text = "Radio 1-1 [Tab1]";
1377 radio12.Text = "Radio 1-2 [Tab2]";
1378 radio13.Text = "Radio 1-3 [Tab3]";
1379 radio14.Text = "Radio 1-4 [Tab4]";
1381 radio21.Text = "Radio 2-1 [Tab4]";
1382 radio22.Text = "Radio 2-2 [Tab3]";
1383 radio23.Text = "Radio 2-3 [Tab2]";
1384 radio24.Text = "Radio 2-4 [Tab1]";
1386 radio31.Text = "Radio 3-1 [Tab1]";
1387 radio32.Text = "Radio 3-2 [Tab3]";
1388 radio33.Text = "Radio 3-3 [Tab2]";
1389 radio34.Text = "Radio 3-4 [Tab4]";
1391 // We don't assign TabIndex for radio1X; test automatic assignment
1392 text1.TabStop = true;
1393 radio11.TabStop = true;
1395 radio21.TabIndex = 4;
1396 radio22.TabIndex = 3;
1397 radio23.TabIndex = 2;
1398 radio24.TabIndex = 1;
1399 radio24.TabStop = true;
1401 radio31.TabIndex = 11;
1402 radio31.TabStop = true;
1403 radio32.TabIndex = 13;
1404 radio33.TabIndex = 12;
1405 radio34.TabIndex = 14;
1407 text1.Location = new Point(10, 100);
1409 radio11.Location = new Point(10, 20);
1410 radio12.Location = new Point(10, 40);
1411 radio13.Location = new Point(10, 60);
1412 radio14.Location = new Point(10, 80);
1414 radio21.Location = new Point(10, 20);
1415 radio22.Location = new Point(10, 40);
1416 radio23.Location = new Point(10, 60);
1417 radio24.Location = new Point(10, 80);
1419 radio31.Location = new Point(10, 20);
1420 radio32.Location = new Point(10, 40);
1421 radio33.Location = new Point(10, 60);
1422 radio34.Location = new Point(10, 80);
1424 text1.Size = new Size(150, text1.PreferredHeight);
1426 radio11.Size = new Size(150, 20);
1427 radio12.Size = new Size(150, 20);
1428 radio13.Size = new Size(150, 20);
1429 radio14.Size = new Size(150, 20);
1431 radio21.Size = new Size(150, 20);
1432 radio22.Size = new Size(150, 20);
1433 radio23.Size = new Size(150, 20);
1434 radio24.Size = new Size(150, 20);
1436 radio31.Size = new Size(150, 20);
1437 radio32.Size = new Size(150, 20);
1438 radio33.Size = new Size(150, 20);
1439 radio34.Size = new Size(150, 20);
1441 group1.Controls.Add(text1);
1443 group1.Controls.Add(radio11);
1444 group1.Controls.Add(radio12);
1445 group1.Controls.Add(radio13);
1446 group1.Controls.Add(radio14);
1448 group2.Controls.Add(radio21);
1449 group2.Controls.Add(radio22);
1450 group2.Controls.Add(radio23);
1451 group2.Controls.Add(radio24);
1453 group3.Controls.Add(radio31);
1454 group3.Controls.Add(radio32);
1455 group3.Controls.Add(radio33);
1456 group3.Controls.Add(radio34);
1458 form.Controls.Add(group1);
1459 form.Controls.Add(group2);
1460 group2.Controls.Add(group3);
1462 // Perform some tests, the TabIndex stuff below will alter the outcome
1463 Assert.AreEqual(null, Helper.TestControl(group2, radio34, true), "Tab8");
1464 Assert.AreEqual(31, group2.TabIndex, "Tab9");
1466 // Does the taborder of containers and non-selectable things change behaviour?
1467 label1.TabIndex = 5;
1468 label2.TabIndex = 4;
1469 group1.TabIndex = 3;
1470 group2.TabIndex = 1;
1472 // Start verification
1473 Assert.AreEqual(null, Helper.TestControl(group2, radio34, true), "Tab10");
1474 Assert.AreEqual(radio24.Text, Helper.TestControl(group2, group2, true), "Tab11");
1475 Assert.AreEqual(radio31.Text, Helper.TestControl(group2, group3, true), "Tab12");
1476 Assert.AreEqual(null, Helper.TestControl(group1, radio14, true), "Tab13");
1477 Assert.AreEqual(radio23.Text, Helper.TestControl(group2, radio24, true), "Tab14");
1478 Assert.AreEqual(group3.Text, Helper.TestControl(group2, radio21, true), "Tab15");
1479 Assert.AreEqual(radio13.Text, Helper.TestControl(form, radio12, true), "Tab16");
1480 Assert.AreEqual(label2.Text, Helper.TestControl(form, radio14, true), "Tab17");
1481 Assert.AreEqual(group1.Text, Helper.TestControl(form, radio34, true), "Tab18");
1482 Assert.AreEqual(radio23.Text, Helper.TestControl(group2, radio24, true), "Tab19");
1485 Assert.AreEqual(null, Helper.TestControl(radio11, radio21, true), "Tab20");
1486 Assert.AreEqual(text1.Text, Helper.TestControl(group1, radio21, true), "Tab21");
1488 Assert.AreEqual(radio14.Text, Helper.TestControl(form, label2, false), "Tab22");
1489 Assert.AreEqual(radio21.Text, Helper.TestControl(group2, group3, false), "Tab23");
1491 Assert.AreEqual(4, radio21.TabIndex, "Tab24");
1492 Assert.AreEqual(1, radio11.TabIndex, "Tab25");
1493 Assert.AreEqual(3, radio13.TabIndex, "Tab26");
1494 Assert.AreEqual(35, group3.TabIndex, "Tab27");
1495 Assert.AreEqual(1, group2.TabIndex, "Tab28");
1497 Assert.AreEqual(label1.Text, Helper.TestControl(form, form, false), "Tab29");
1498 Assert.AreEqual(radio14.Text, Helper.TestControl(group1, group1, false), "Tab30");
1499 Assert.AreEqual(radio34.Text, Helper.TestControl(group3, group3, false), "Tab31");
1501 Assert.AreEqual(null, Helper.TestControl(label1, label1, false), "Tab31");
1502 Assert.AreEqual(null, Helper.TestControl(radio11, radio21, false), "Tab32");
1507 public void ScaleTest()
1509 Control r1 = new Control();
1514 Assert.AreEqual(80, r1.Width, "Scale1");
1515 Assert.AreEqual(40, r1.Height, "Scale2");
1520 public void ScaleChildrenTest ()
1522 ScaleChildrenControl c = new ScaleChildrenControl ();
1523 Assert.AreEqual (true, c.PublicScaleChildren, "A1");
1526 private class ScaleChildrenControl : Control
1528 public bool PublicScaleChildren {
1529 get { return base.ScaleChildren; }
1534 public void ScaleControlTest ()
1536 ScaleControl c = new ScaleControl ();
1538 c.Location = new Point (5, 10);
1539 c.Size = new Size (15, 20);
1541 Assert.AreEqual (new Rectangle (5, 10, 15, 20), c.Bounds, "A1");
1543 c.PublicScaleControl (new SizeF (1.5f, 1.3f), BoundsSpecified.All);
1544 Assert.AreEqual (new Rectangle (8, 13, 22, 26), c.Bounds, "A2");
1546 c.PublicScaleControl (new SizeF (2f, 1.5f), BoundsSpecified.Location);
1547 Assert.AreEqual (new Rectangle (16, 20, 22, 26), c.Bounds, "A3");
1549 c.PublicScaleControl (new SizeF (1.5f, 2f), BoundsSpecified.Size);
1550 Assert.AreEqual (new Rectangle (16, 20, 33, 52), c.Bounds, "A4");
1552 c.PublicScaleControl (new SizeF (1.5f, 1.5f), BoundsSpecified.Width);
1553 Assert.AreEqual (new Rectangle (16, 20, 50, 52), c.Bounds, "A5");
1555 c.PublicScaleControl (new SizeF (1.5f, 1.3f), BoundsSpecified.None);
1556 Assert.AreEqual (new Rectangle (16, 20, 50, 52), c.Bounds, "A6");
1558 // Test with ScaleChildren
1559 c = new ScaleControl ();
1561 c.Location = new Point (5, 10);
1562 c.Size = new Size (50, 50);
1564 Control c2 = new Control ();
1565 c2.Location = new Point (15, 15);
1566 c2.Size = new Size (25, 25);
1567 c.Controls.Add (c2);
1569 Assert.AreEqual (new Rectangle (5, 10, 50, 50), c.Bounds, "B1");
1570 Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B2");
1572 c.scale_children = false;
1574 c.PublicScaleControl (new SizeF (2f, 2f), BoundsSpecified.All);
1575 Assert.AreEqual (new Rectangle (10, 20, 100, 100), c.Bounds, "B3");
1576 Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B4");
1578 c.scale_children = true;
1580 // Will not scale children in ScaleControl
1581 c.PublicScaleControl (new SizeF (2f, 2f), BoundsSpecified.All);
1582 Assert.AreEqual (new Rectangle (20, 40, 200, 200), c.Bounds, "B5");
1583 Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B6");
1585 // Does scale children in Scale
1586 c.Scale (new SizeF (2f, 2f));
1587 Assert.AreEqual (new Rectangle (40, 80, 400, 400), c.Bounds, "B7");
1588 Assert.AreEqual (new Rectangle (30, 30, 50, 50), c2.Bounds, "B8");
1592 public void GetScaledBoundsTest ()
1594 ScaleControl c = new ScaleControl ();
1596 Rectangle r = new Rectangle (10, 20, 30, 40);
1598 Assert.AreEqual (new Rectangle (20, 10, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A1");
1599 Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A2");
1600 Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A3");
1601 Assert.AreEqual (new Rectangle (10, 20, 30, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A4");
1602 Assert.AreEqual (new Rectangle (20, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A5");
1603 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A6");
1605 c.PublicSetTopLevel (true);
1607 Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A7");
1608 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A8");
1609 Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A9");
1610 Assert.AreEqual (new Rectangle (10, 20, 30, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A10");
1611 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A11");
1612 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A12");
1614 c = new ScaleControl ();
1615 c.PublicSetStyle (ControlStyles.FixedHeight, true);
1616 c.PublicSetStyle (ControlStyles.FixedWidth, true);
1618 Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A13");
1619 Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A14");
1620 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A15");
1621 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A16");
1622 Assert.AreEqual (new Rectangle (20, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A17");
1623 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A18");
1626 private class ScaleControl : Control
1628 public bool scale_children = true;
1630 public void PublicScaleControl (SizeF factor, BoundsSpecified specified)
1632 base.ScaleControl (factor, specified);
1635 public Rectangle PublicGetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
1637 return base.GetScaledBounds (bounds, factor, specified);
1640 public void PublicSetStyle (ControlStyles flag, bool value)
1642 base.SetStyle (flag, value);
1645 public void PublicSetTopLevel (bool value)
1647 base.SetTopLevel (value);
1650 protected override bool ScaleChildren {
1651 get { return scale_children; }
1656 [Test] // Bug #347282
1657 public void ScaleHierarchy ()
1659 Form f = new Form ();
1660 Panel p = new Panel ();
1661 Button b = new Button ();
1663 f.ClientSize = new Size (300, 300);
1668 f.AutoScaleBaseSize = new Size (3, 11);
1671 // Due to font differences, all we can guarantee is that
1672 // the button is larger that the default.
1673 Assert.IsTrue (b.Width > 75, "A1");
1674 Assert.IsTrue (b.Height > 23, "A2");
1679 class TestWindowTarget : IWindowTarget
1681 public void OnHandleChange (IntPtr newHandle) {
1684 public void OnMessage (ref Message m) {
1689 public void WindowTargetTest()
1691 Control c = new Control ();
1692 Assert.IsNotNull (c.WindowTarget, "WindowTarget1");
1693 c.WindowTarget = null;
1694 Assert.IsNull (c.WindowTarget, "WindowTarget2");
1696 IWindowTarget existing_target = c.WindowTarget;
1697 IWindowTarget new_target = new TestWindowTarget ();
1698 c.WindowTarget = new_target;
1699 Assert.AreSame (new_target, c.WindowTarget, "WindowTarget3");
1701 TestHelper.RemoveWarning (existing_target);
1705 public void TextTest()
1707 Control r1 = new Control();
1709 Assert.AreEqual("Hi" , r1.Text , "Text1");
1712 Assert.AreEqual("" , r1.Text , "Text2");
1716 public void PubMethodTest7()
1718 Control r1 = new Control();
1719 r1.RightToLeft = RightToLeft.Yes ;
1720 r1.ResetRightToLeft() ;
1721 Assert.AreEqual(RightToLeft.No , r1.RightToLeft , "#81");
1722 r1.ImeMode = ImeMode.Off ;
1723 r1.ResetImeMode () ;
1724 Assert.AreEqual(ImeMode.NoControl , r1.ImeMode , "#82");
1725 r1.ForeColor= SystemColors.GrayText ;
1726 r1.ResetForeColor() ;
1727 Assert.AreEqual(SystemColors.ControlText , r1.ForeColor , "#83");
1728 //r1.Font = Font.FromHdc();
1730 //Assert.AreEqual(FontFamily.GenericSansSerif , r1.Font , "#83");
1731 r1.Cursor = Cursors.Hand ;
1733 Assert.AreEqual(Cursors.Default , r1.Cursor , "#83");
1734 //r1.DataBindings = System.Windows.Forms.Binding ;
1735 //r1.ResetBindings() ;
1736 //Assert.AreEqual(ControlBindingsCollection , r1.DataBindings , "#83");
1737 r1.BackColor = Color.Black ;
1738 r1.ResetBackColor() ;
1739 Assert.AreEqual( SystemColors.Control , r1.BackColor , "#84");
1740 r1.BackColor = Color.Black ;
1742 Assert.AreEqual( null , r1.Region , "#85");
1743 Rectangle M = new Rectangle(10, 20, 30 ,40);
1744 r1.RectangleToScreen(M) ;
1745 Assert.AreEqual( null , r1.Region , "#86");
1749 public void ScreenClientCoords()
1760 p1 = new Point (10,10);
1761 p2 = l.PointToScreen(p1);
1762 p3 = l.PointToClient(p2);
1764 Assert.AreEqual (p1, p3, "SC1");
1768 public void ContainsTest ()
1770 Control t = new Control ();
1771 Control s = new Control ();
1775 Assert.AreEqual (true, t.Contains (s), "Con1");
1776 Assert.AreEqual (false, s.Contains (t), "Con2");
1777 Assert.AreEqual (false, s.Contains (null), "Con3");
1778 Assert.AreEqual (false, t.Contains (new Control ()), "Con4");
1782 public void IsHandleCreated_NotVisible ()
1784 Control c = new Control ();
1787 Form form = new Form ();
1788 form.ShowInTaskbar = false;
1789 form.Controls.Add (c);
1792 Assert.IsFalse (c.IsHandleCreated, "#1");
1794 Assert.IsTrue (c.IsHandleCreated, "#2");
1796 Assert.IsTrue (c.IsHandleCreated, "#3");
1800 class OnCreateControlTest : Control {
1801 public bool reached = false;
1802 protected override void OnCreateControl () {
1808 public void CreateControlVisibleTest ()
1810 OnCreateControlTest test = new OnCreateControlTest ();
1811 test.Visible = false;
1812 Assert.IsFalse (test.IsHandleCreated, "0");
1813 Assert.IsFalse (test.Visible, "1");
1814 test.Visible = true;
1815 Assert.IsTrue (test.Visible, "2");
1816 Assert.IsTrue (test.reached, "3");
1821 public void CreateGraphicsTest ()
1827 Control c = new Control ();
1828 c.SetBounds (0,0, 20, 20);
1829 g = c.CreateGraphics ();
1830 Assert.IsNotNull (g, "Graph1");
1839 bool delegateCalled = false;
1840 public delegate void TestDelegate ();
1842 public void delegate_call () {
1843 delegateCalled = true;
1845 TestHelper.RemoveWarning (delegateCalled);
1849 [ExpectedException(typeof(InvalidOperationException))]
1850 public void InvokeException1 () {
1851 Control c = new Control ();
1852 IAsyncResult result;
1854 result = c.BeginInvoke (new TestDelegate (delegate_call));
1855 c.EndInvoke (result);
1859 public void FindFormTest () {
1860 Form f = new Form ();
1862 f.ShowInTaskbar = false;
1867 f.Controls.Add (c = new Control ());
1868 Assert.AreEqual (f.Name, c.FindForm ().Name, "Find1");
1870 f.Controls.Remove (c);
1872 GroupBox g = new GroupBox ();
1877 Assert.AreEqual (f.Name, f.FindForm ().Name, "Find2");
1879 g.Controls.Remove (c);
1880 Assert.IsNull(c.FindForm (), "Find3");
1891 public void FocusTest ()
1894 Button c = null, d = null;
1898 f.ShowInTaskbar = false;
1908 Assert.IsTrue (c.CanFocus, "Focus1");
1909 Assert.IsFalse (c.Focused, "Focus2");
1911 Assert.IsTrue (c.Focused, "Focus3");
1913 Assert.IsFalse (d.Focused, "Focus4");
1917 Assert.IsTrue (d.Focused, "Focus5");
1918 Assert.IsFalse (c.Focused, "Focus6");
1921 Assert.IsFalse (c.Focused, "Focus7");
1933 public void FromHandleTest ()
1939 c1 = new Control ();
1940 c2 = new Control ();
1944 c1.Controls.Add(c2);
1947 Assert.AreEqual (c1.Name, Control.FromHandle (c1.Handle).Name, "Handle1");
1948 Assert.IsNull (Control.FromHandle (IntPtr.Zero), "Handle2");
1951 Assert.AreEqual (c1.Name, Control.FromChildHandle (c1.Handle).Name, "Handle3");
1952 Assert.IsNull (Control.FromChildHandle (IntPtr.Zero), "Handle4");
1965 public void GetChildAtPointTest ()
1967 Control c = null, d = null;
1968 TransparentControl e = null;
1973 c.SetBounds (0, 0, 100, 100);
1977 d.SetBounds (10, 10, 40, 40);
1980 e = new TransparentControl ();
1982 e.SetBounds (55, 55, 10, 10);
1984 Control l = c.GetChildAtPoint (new Point (15, 15));
1985 Assert.AreEqual (d.Name, l.Name, "Child1");
1986 Assert.IsFalse (e.Name == l.Name, "Child2");
1988 l = c.GetChildAtPoint (new Point (57, 57));
1989 Assert.AreEqual (null, l, "Child3");
1991 l = c.GetChildAtPoint (new Point (10, 10));
1992 Assert.AreEqual (d.Name, l.Name, "Child4");
1994 // GetChildAtPointSkip is not implemented and the following test is breaking for Net_2_0 profile
1998 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
1999 Assert.IsNull (l, "Child5");
2002 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
2003 Assert.AreSame (e.Name, l.Name, "Child6");
2006 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Disabled);
2007 Assert.IsNull (l, "Child7");
2010 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Disabled);
2011 Assert.AreSame (e.Name, l.Name, "Child8");
2014 e.BackColor = Color.Transparent;
2015 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Transparent);
2016 Assert.IsNull (l, "Child9");
2018 e.BackColor = Color.Green;
2019 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Transparent);
2020 Assert.AreSame (e.Name, l.Name, "Child10");
2031 private class TransparentControl : Control
2033 public TransparentControl ()
2035 SetStyle (ControlStyles.SupportsTransparentBackColor, true);
2038 protected override CreateParams CreateParams
2042 CreateParams cp = base.CreateParams;
2043 cp.ExStyle |= 0x00000020;
2050 public void ResetFontTest ()
2052 Control c = new Control ();
2053 c.Font = new Font (c.Font.FontFamily, 3, FontStyle.Italic);
2056 Assert.IsFalse (c.Font.Bold, "#1");
2057 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#2");
2058 Assert.IsFalse (c.Font.Italic, "#3");
2059 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#4");
2060 Assert.AreEqual (8.25, c.Font.Size, "#5");
2061 Assert.AreEqual (8.25, c.Font.SizeInPoints, "#6");
2062 Assert.IsFalse (c.Font.Strikeout, "#7");
2063 Assert.IsFalse (c.Font.Underline, "#8");
2064 Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#9");
2066 Assert.AreEqual (true, c.Font.IsSystemFont, "#10");
2070 public class LayoutTestControl : Control {
2071 public int LayoutCount;
2073 public LayoutTestControl () : base() {
2077 protected override void OnLayout(LayoutEventArgs levent) {
2079 base.OnLayout (levent);
2084 public void LayoutTest() {
2085 LayoutTestControl c;
2087 c = new LayoutTestControl();
2094 c.ResumeLayout(true);
2096 c.ResumeLayout(true);
2098 c.ResumeLayout(true);
2100 c.ResumeLayout(true);
2102 c.ResumeLayout(true);
2104 c.ResumeLayout(true);
2106 c.ResumeLayout(true);
2111 Assert.AreEqual(5, c.LayoutCount, "Layout Suspend/Resume locking does not bottom out at 0");
2115 [ExpectedException(typeof(ArgumentException))]
2116 public void TransparentBackgroundTest1() {
2120 c.BackColor = Color.Transparent;
2124 public void TransparentBackgroundTest2() {
2128 c.BackColor = Color.Transparent;
2129 Assert.AreEqual(Color.Transparent, c.BackColor, "Transparent background not set");
2133 public void TransparentBackgroundTest3() {
2137 c.BackColor = Color.Empty;
2138 Assert.AreEqual(Control.DefaultBackColor, c.BackColor, "Setting empty color failed");
2142 public void Dock_Value_Invalid ()
2144 Control c = new Control ();
2146 c.Dock = (DockStyle) 666;
2148 } catch (InvalidEnumArgumentException ex) {
2149 Assert.AreEqual (typeof (InvalidEnumArgumentException), ex.GetType (), "#2");
2150 Assert.IsNotNull (ex.Message, "#3");
2151 Assert.IsNotNull (ex.ParamName, "#4");
2152 Assert.AreEqual ("value", ex.ParamName, "#5");
2153 Assert.IsNull (ex.InnerException, "#6");
2158 public void EnabledTest1() {
2163 grandma = new Control();
2164 parent = new Control();
2165 child = new Control();
2167 grandma.Controls.Add(parent);
2168 parent.Controls.Add(child);
2169 grandma.Enabled = false;
2170 Assert.AreEqual(grandma.Enabled, child.Enabled, "Child did not inherit disabled state");
2173 int EnabledCalledCount = 0;
2174 private void EnabledTest2EnabledChanged(object sender, EventArgs e) {
2175 EnabledCalledCount++;
2179 public void EnabledTest2() {
2180 // Check nesting of enabled calls
2181 // OnEnabled is not called for disabled child controls
2186 EnabledCalledCount = 0;
2188 grandma = new Control();
2189 parent = new Control();
2190 child = new Control();
2191 child.EnabledChanged += new EventHandler(EnabledTest2EnabledChanged);
2193 grandma.Controls.Add(parent);
2194 parent.Controls.Add(child);
2195 grandma.Enabled = false;
2197 Assert.AreEqual(1, EnabledCalledCount, "Child Enabled Event not properly fired");
2198 grandma.Enabled = true;
2199 Assert.AreEqual(2, EnabledCalledCount, "Child Enabled Event not properly fired");
2200 child.Enabled = false;
2201 grandma.Enabled = false;
2202 Assert.AreEqual(3, EnabledCalledCount, "Child Enabled Event not properly fired");
2206 public void ControlsRemoveNullTest ()
2208 Control c = new Control ();
2209 c.Controls.Remove (null);
2213 public void ControlsAddNullTest ()
2215 Control c = new Control ();
2216 c.Controls.Add (null);
2220 [ExpectedException (typeof (ArgumentNullException))]
2221 public void ControlsSetChildIndexNullTest ()
2223 Control c = new Control ();
2224 c.Controls.SetChildIndex (null, 1);
2228 [ExpectedException (typeof (ArgumentNullException))]
2229 public void ControlsAddRangeNullTest ()
2231 Control c = new Control ();
2232 c.Controls.AddRange (null);
2236 public void ControlsAddRangeNullElementTest ()
2238 Control c = new Control ();
2239 Control[] subcontrols = new Control[2];
2240 subcontrols[0] = new Control ();
2241 subcontrols[1] = null;
2243 c.Controls.AddRange (subcontrols);
2247 public void RegionTest () {
2248 Form f = new Form ();
2249 f.ShowInTaskbar = false;
2250 Control c = new Control ();
2252 Assert.IsNull (c.Region, "#A1");
2254 Assert.IsNull (c.Region, "#A2");
2256 Assert.IsNull (c.Region, "#A3");
2259 Region region = new Region ();
2261 f.ShowInTaskbar = false;
2265 Assert.IsNotNull (c.Region, "#B1");
2266 Assert.AreSame (region, c.Region, "#B2");
2269 Assert.IsNull (c.Region, "#B3");
2274 [Test] // bug #330501
2275 public void OnValidating_Parent_Close ()
2277 MockControl control = new MockControl ();
2279 Form f = new Form ();
2280 f.Controls.Add (control);
2281 f.ShowInTaskbar = false;
2284 Assert.AreEqual (0, control.OnValidatingCount, "#A1");
2286 Assert.AreEqual (1, control.OnValidatingCount, "#A2");
2290 [Test] // bug #80280
2291 public void Validated_Multiple_Containers ()
2293 Form form = new Form ();
2294 form.ShowInTaskbar = false;
2296 UserControl control1 = new UserControl();
2297 UserControl container1 = new UserControl();
2298 control1.Tag = true;
2299 control1.Validated += new EventHandler (Control_ValidatedHandler);
2300 container1.Controls.Add(control1);
2301 form.Controls.Add (container1);
2303 UserControl container2 = new UserControl();
2304 UserControl control2 = new UserControl();
2305 container2.Controls.Add(control2);
2306 form.Controls.Add (container2);
2308 Assert.IsTrue ((bool) control1.Tag, "#1");
2310 Assert.IsTrue ((bool) control1.Tag, "#2");
2312 Assert.IsFalse ((bool) control1.Tag, "#3");
2317 private void Control_ValidatedHandler (object sender, EventArgs e)
2319 ((Control) sender).Tag = false;
2323 public void ControlReparentLocationTest ()
2325 Form form = new Form ();
2326 Label l = new Label ();
2327 l.Location = new Point (0, 0);
2328 form.Controls.Add (l);
2330 Assert.AreEqual (0, l.Left, "#A1");
2331 Assert.AreEqual (0, l.Top, "#A2");
2333 form.Controls.Remove (l);
2335 form.Controls.Add (l);
2336 Assert.AreEqual (0, l.Left, "#A3");
2337 Assert.AreEqual (0, l.Top, "#A4");
2344 public void UseWaitCursorTest ()
2346 Control c = new Control ();
2347 Assert.IsFalse (c.UseWaitCursor, "#1");
2348 c.Cursor = Cursors.Hand;
2349 c.UseWaitCursor = true;
2350 Assert.AreEqual (Cursors.WaitCursor, c.Cursor, "#2");
2351 c.UseWaitCursor = false;
2352 Assert.AreEqual (Cursors.Hand, c.Cursor, "#3");
2354 c.UseWaitCursor = true;
2355 c.Cursor = Cursors.Help;
2356 Assert.AreEqual (Cursors.WaitCursor, c.Cursor, "#4");
2357 Assert.AreEqual (true, c.UseWaitCursor, "#5");
2359 c.UseWaitCursor = false;
2360 Assert.AreEqual (Cursors.Help, c.Cursor, "#6");
2363 [Test] // bug #80621, #81125
2364 public void DontCallSizeFromClientSize ()
2366 SizeControl sc = new SizeControl ();
2368 Assert.AreEqual (0, sc.size_from_client_size_count, "A1");
2370 sc.ClientSize = new Size (300, 300);
2371 Assert.AreEqual (0, sc.size_from_client_size_count, "A2");
2373 SizeForm sf = new SizeForm ();
2374 sf.ShowInTaskbar = false;
2377 Assert.AreEqual (0, sc.size_from_client_size_count, "A3");
2379 sc.ClientSize = new Size (300, 300);
2380 Assert.AreEqual (0, sc.size_from_client_size_count, "A4");
2385 private class SizeControl : Control
2387 public int size_from_client_size_count = 0;
2389 protected override Size SizeFromClientSize (Size clientSize)
2391 size_from_client_size_count++;
2392 return base.SizeFromClientSize (clientSize);
2396 private class SizeForm : Form
2398 public int size_from_client_size_count = 0;
2400 protected override Size SizeFromClientSize (Size clientSize)
2402 size_from_client_size_count++;
2403 return base.SizeFromClientSize (clientSize);
2408 public class MockControl : Control
2410 public int OnValidatingCount;
2411 public int OnSizeChangedCount;
2412 public int OnResizeCount;
2413 public int OnLocationChangedCount;
2415 public MockControl ()
2419 public MockControl (string text)
2424 public MockControl (Control parent, string text)
2425 : base (parent, text)
2429 public MockControl (string text, int left, int top, int width, int height)
2430 : base (text, left, top, width, height)
2434 public MockControl (Control parent, string text, int left, int top, int width, int height)
2435 : base (parent, text, left, top, width, height)
2439 public int font_height
2441 get { return base.FontHeight; }
2442 set { base.FontHeight = value; }
2445 protected override void OnLocationChanged (EventArgs e)
2447 OnLocationChangedCount++;
2448 base.OnLocationChanged (e);
2451 protected override void OnSizeChanged (EventArgs e)
2453 OnSizeChangedCount++;
2454 base.OnSizeChanged (e);
2457 protected override void OnResize (EventArgs e)
2463 protected override void OnValidating (CancelEventArgs e)
2465 OnValidatingCount++;
2469 const int WM_KEYDOWN = 0x0100;
2470 const int WM_CHAR = 0x0102;
2471 const int WM_SYSCHAR = 0x0106;
2472 const int WM_KEYUP = 0x0101;
2476 public void MethodPreProcessControlMessage ()
2478 bool testing_callstack = false;
2480 MyControl c = new MyControl ();
2481 Message m = new Message ();
2484 m.WParam = (IntPtr)Keys.Down;
2485 m.LParam = IntPtr.Zero;
2487 if (testing_callstack) Console.WriteLine ("Start");
2488 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A1");
2489 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2491 c.SetState (State.OnPreviewKeyDown);
2492 if (testing_callstack) Console.WriteLine ("Start");
2493 Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A2");
2494 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2496 c.SetState (State.ProcessCmdKey);
2497 if (testing_callstack) Console.WriteLine ("Start");
2498 Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A3");
2499 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2501 c.SetState (State.IsInputKey);
2502 if (testing_callstack) Console.WriteLine ("Start");
2503 Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A4");
2504 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2506 c.SetState (State.ProcessDialogKey);
2507 if (testing_callstack) Console.WriteLine ("Start");
2508 Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A5");
2509 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2513 c.SetState (State.None);
2514 if (testing_callstack) Console.WriteLine ("Start");
2515 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A6");
2516 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2518 c.SetState (State.IsInputChar);
2519 if (testing_callstack) Console.WriteLine ("Start");
2520 Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A7");
2521 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2523 c.SetState (State.ProcessDialogChar);
2524 if (testing_callstack) Console.WriteLine ("Start");
2525 Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A8");
2526 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2530 c.SetState (State.None);
2531 if (testing_callstack) Console.WriteLine ("Start");
2532 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A9");
2533 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2535 c.SetState (State.IsInputChar);
2536 if (testing_callstack) Console.WriteLine ("Start");
2537 Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A10");
2538 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2540 c.SetState (State.ProcessDialogChar);
2541 if (testing_callstack) Console.WriteLine ("Start");
2542 Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A11");
2543 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2547 if (testing_callstack) Console.WriteLine ("Start");
2548 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A12");
2549 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2551 c.SetState (State.OnPreviewKeyDown);
2552 if (testing_callstack) Console.WriteLine ("Start");
2553 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A13");
2554 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2556 c.SetState (State.ProcessCmdKey);
2557 if (testing_callstack) Console.WriteLine ("Start");
2558 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A14");
2559 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2561 c.SetState (State.IsInputKey);
2562 if (testing_callstack) Console.WriteLine ("Start");
2563 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A15");
2564 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2566 c.SetState (State.ProcessDialogKey);
2567 if (testing_callstack) Console.WriteLine ("Start");
2568 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A16");
2569 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2574 public void MethodPreProcessMessage ()
2576 bool testing_callstack = false;
2578 MyControl c = new MyControl ();
2579 Message m = new Message ();
2582 m.WParam = (IntPtr)Keys.Down;
2583 m.LParam = IntPtr.Zero;
2585 if (testing_callstack) Console.WriteLine ("Start");
2586 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A1");
2587 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2589 c.SetState (State.OnPreviewKeyDown);
2590 if (testing_callstack) Console.WriteLine ("Start");
2591 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A2");
2592 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2594 c.SetState (State.ProcessCmdKey);
2595 if (testing_callstack) Console.WriteLine ("Start");
2596 Assert.AreEqual (true, c.PreProcessMessage (ref m), "A3");
2597 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2599 c.SetState (State.IsInputKey);
2600 if (testing_callstack) Console.WriteLine ("Start");
2601 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A4");
2602 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2604 c.SetState (State.ProcessDialogKey);
2605 if (testing_callstack) Console.WriteLine ("Start");
2606 Assert.AreEqual (true, c.PreProcessMessage (ref m), "A5");
2607 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2611 c.SetState (State.None);
2612 if (testing_callstack) Console.WriteLine ("Start");
2613 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A6");
2614 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2616 c.SetState (State.IsInputChar);
2617 if (testing_callstack) Console.WriteLine ("Start");
2618 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A7");
2619 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2621 c.SetState (State.ProcessDialogChar);
2622 if (testing_callstack) Console.WriteLine ("Start");
2623 Assert.AreEqual (true, c.PreProcessMessage (ref m), "A8");
2624 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2628 c.SetState (State.None);
2629 if (testing_callstack) Console.WriteLine ("Start");
2630 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A9");
2631 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2633 c.SetState (State.IsInputChar);
2634 if (testing_callstack) Console.WriteLine ("Start");
2635 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A10");
2636 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2638 c.SetState (State.ProcessDialogChar);
2639 if (testing_callstack) Console.WriteLine ("Start");
2640 Assert.AreEqual (true, c.PreProcessMessage (ref m), "A11");
2641 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2645 if (testing_callstack) Console.WriteLine ("Start");
2646 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A12");
2647 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2649 c.SetState (State.OnPreviewKeyDown);
2650 if (testing_callstack) Console.WriteLine ("Start");
2651 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A13");
2652 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2654 c.SetState (State.ProcessCmdKey);
2655 if (testing_callstack) Console.WriteLine ("Start");
2656 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A14");
2657 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2659 c.SetState (State.IsInputKey);
2660 if (testing_callstack) Console.WriteLine ("Start");
2661 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A15");
2662 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2664 c.SetState (State.ProcessDialogKey);
2665 if (testing_callstack) Console.WriteLine ("Start");
2666 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A16");
2667 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2681 private class MyControl : Control
2684 private State current_state;
2685 bool testing_callstack = false;
2687 public void SetState (State state)
2689 current_state = state;
2692 protected override bool ProcessCmdKey (ref Message msg, Keys keyData)
2694 if (testing_callstack) Console.Write ("ProcessCmdKey[");
2695 if (current_state == State.ProcessCmdKey) {
2696 if (testing_callstack) Console.WriteLine ("]");
2700 bool retval = base.ProcessCmdKey (ref msg, keyData);
2701 if (testing_callstack) Console.WriteLine ("]");
2706 protected override void OnPreviewKeyDown (PreviewKeyDownEventArgs e)
2708 if (testing_callstack) Console.Write ("OnPreviewKeyDown[");
2709 if (current_state == State.OnPreviewKeyDown) {
2710 e.IsInputKey = true;
2711 if (testing_callstack) Console.WriteLine ("]");
2715 base.OnPreviewKeyDown (e);
2716 if (testing_callstack) Console.WriteLine ("]");
2720 protected override bool IsInputChar (char charCode)
2722 if (testing_callstack) Console.Write ("IsInputChar[");
2723 if (current_state == State.IsInputChar) {
2724 if (testing_callstack) Console.WriteLine ("true]");
2728 bool retval = base.IsInputChar (charCode);
2729 if (testing_callstack) Console.WriteLine ("{0}]", retval.ToString ());
2733 protected override bool IsInputKey (Keys keyData)
2735 if (testing_callstack) Console.Write ("IsInputKey[");
2736 if (current_state == State.IsInputKey) {
2737 if (testing_callstack) Console.WriteLine ("]");
2741 bool retval = base.IsInputKey (keyData);
2742 if (testing_callstack) Console.WriteLine ("]");
2746 public override bool PreProcessMessage (ref Message msg)
2748 if (testing_callstack) Console.Write ("PreProcessMessage[");
2749 if (current_state == State.PreProcessMessage) {
2750 if (testing_callstack) Console.WriteLine ("]");
2754 bool retval = base.PreProcessMessage (ref msg);
2755 if (testing_callstack) Console.WriteLine ("]");
2759 protected override bool ProcessDialogKey (Keys keyData)
2761 if (testing_callstack) Console.Write ("ProcessDialogKey[");
2762 if (current_state == State.ProcessDialogKey) {
2763 if (testing_callstack) Console.WriteLine ("]");
2767 bool retval = base.ProcessDialogKey (keyData);
2768 if (testing_callstack) Console.WriteLine ("]");
2772 protected override bool ProcessDialogChar (char charCode)
2774 if (testing_callstack) Console.Write ("ProcessDialogChar[");
2775 if (current_state == State.ProcessDialogChar) {
2776 if (testing_callstack) Console.WriteLine ("]");
2780 bool retval = base.ProcessDialogChar (charCode);
2781 if (testing_callstack) Console.WriteLine ("]");
2787 public void MethodIsInputChar ()
2789 // Basically, show that this method always returns false
2790 InputCharControl m = new InputCharControl ();
2791 bool result = false;
2793 for (int i = 0; i < 256; i++)
2794 result |= m.PublicIsInputChar ((char)i);
2796 Assert.AreEqual (false, result, "I1");
2799 private class InputCharControl : Control
2801 public bool PublicIsInputChar (char charCode)
2803 return base.IsInputChar (charCode);
2808 [Test] // bug #81118, 81718
2809 public void VisibleTriggersLayout ()
2811 Form f = new Form ();
2812 f.ShowInTaskbar = false;
2814 Control c = new Control ();
2819 c.Dock = DockStyle.Fill;
2822 Assert.AreEqual (f.ClientSize.Width, c.Width, "L1");
2828 public void ResumeLayoutEffects ()
2830 Form f = new Form ();
2831 f.ShowInTaskbar = false;
2832 f.ClientSize = new Size (300, 300);
2834 Button button1 = new Button ();
2835 f.Controls.Add (button1);
2836 button1.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
2837 button1.Location = new Point (f.ClientSize.Width - button1.Width, f.ClientSize.Height - button1.Height);
2841 Assert.AreEqual (new Point (225, 277), button1.Location, "A1");
2845 f.ResumeLayout (false);
2848 Assert.AreEqual (new Point (225, 277), button1.Location, "A2");
2854 Assert.AreEqual (new Point (225, 287), button1.Location, "A3");
2859 public void DisposeEnumerator ()
2861 // We can modify the collection while looping through it without crashing
2862 Control c = new Control ();
2864 c.Controls.Add (new Control ());
2865 c.Controls.Add (new Control ());
2867 foreach (Control c1 in c.Controls)
2868 c.Controls.Remove (c1);
2872 public void MethodSetBounds ()
2874 Control myControl = new Control();
2875 myControl.SetBounds(10, 20, 30, 40);
2876 myControl.SetBounds(50, 60, 70, 70, BoundsSpecified.Location);
2878 Assert.AreEqual (new Rectangle (50, 60, 30, 40), myControl.Bounds, "A1");
2882 public void Bug386450 ()
2884 // Should not crash. We have to check for the font object
2885 // being different, not just if they represent the same font.
2886 Form f = new Form ();
2887 Label l = new Label ();
2890 Font f1 = new Font ("Arial", 12);
2891 Font f2 = new Font ("Arial", 12);
2905 public class ControlSetTopLevelTest : TestHelper
2907 class ControlPoker : Control {
2908 public void DoSetTopLevel ()
2912 public bool DoGetTopLevel ()
2914 return GetTopLevel ();
2919 public void TestControl ()
2921 ControlPoker c = new ControlPoker ();
2924 Assert.IsTrue (c.DoGetTopLevel (), "1");
2925 Assert.IsFalse (c.Visible, "2");
2929 [ExpectedException (typeof (ArgumentException))]
2930 public void TestChildControl ()
2932 Control c1 = new Control();
2933 ControlPoker c2 = new ControlPoker ();
2935 c1.Controls.Add (c2);
2936 c2.DoSetTopLevel ();
2940 [ExpectedException (typeof (ArgumentException))]
2941 public void TestTopLevelAdd () {
2942 Form f = new Form();
2943 Form f1 = new Form();
2948 [Category ("NotWorking")]
2949 public void TestForm ()
2951 Form f = new Form ();
2952 Assert.IsFalse (f.Visible, "3");
2954 Assert.IsFalse (f.Visible, "4");
2961 public class ControlResizeLayoutTest : TestHelper
2963 class ControlPoker : Control {
2964 public void DoOnResize ()
2966 OnResize (EventArgs.Empty);
2971 string child_affected_property;
2972 void ChildLayoutEvent (object sender, LayoutEventArgs e)
2975 child_affected_property = e.AffectedProperty;
2979 string parent_affected_property;
2980 void ParentLayoutEvent (object sender, LayoutEventArgs e)
2983 parent_affected_property = e.AffectedProperty;
2985 TestHelper.RemoveWarning (parent_affected_property);
2991 Panel p = new Panel ();
2992 ControlPoker c = new ControlPoker();
2996 p.Layout += new LayoutEventHandler (ParentLayoutEvent);
2997 c.Layout += new LayoutEventHandler (ChildLayoutEvent);
3001 Assert.AreEqual (1, child_event, "1");
3002 Assert.AreEqual ("Bounds", child_affected_property, "2");
3004 Assert.AreEqual (0, parent_event, "3");
3010 [Category ("NotWorking")]
3011 public class ControlInvokeTest : TestHelper {
3014 protected override void TearDown ()
3016 if (f != null && !f.IsDisposed)
3022 public delegate void TestDelegate ();
3027 ApplicationContext control_context;
3028 bool delegateCalled = false;
3029 bool threadDied = false;
3033 void CreateControl ()
3037 f.ShowInTaskbar = false;
3043 Console.WriteLine ("f.Handle = {0}", f.Handle);
3044 Console.WriteLine ("c.Handle = {0}", c.Handle);
3046 control_context = new ApplicationContext (f);
3049 Console.WriteLine ("pulsing");
3052 Console.WriteLine ("control thread running");
3053 Application.Run (control_context);
3055 Console.WriteLine ("dying");
3058 Console.WriteLine ("pulsing again");
3061 } catch (Exception e) { Console.WriteLine (e); }
3065 public void InvokeTest ()
3069 control_t = new Thread(new ThreadStart(CreateControl));
3075 Console.WriteLine ("waiting on monitor");
3078 Console.WriteLine ("making async call");
3080 IAsyncResult result;
3081 result = c.BeginInvoke (new TestDelegate (delegate_call));
3082 c.EndInvoke (result);
3084 Assert.IsTrue (delegateCalled, "Invoke1");
3087 Assert.IsTrue (threadDied, "Invoke2");
3090 public void delegate_call () {
3092 /* invoked on control_context's thread */
3093 delegateCalled = true;
3095 Console.WriteLine ("calling Application.Exit");
3096 control_context.ExitThread ();
3097 } catch (Exception e) { Console.WriteLine (e); }
3103 public class ControlWMTest : TestHelper
3106 public void WM_PARENTNOTIFY_Test ()
3112 tester = new WMTester ();
3113 child = new Control ();
3114 tester.Controls.Add (child);
3116 tester.Visible = true;
3117 child.Visible = true;
3119 child_handle = child.Handle.ToInt32 ();
3124 msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
3126 Assert.AreEqual (1, msgs.Count, "#1");
3128 m1 = (Message) msgs [0];
3129 Assert.AreEqual (WndMsg.WM_CREATE, ((WndMsg) LowOrder (m1.WParam)), "#2");
3130 //Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam), "#3");
3131 Assert.AreEqual (child_handle, m1.LParam.ToInt32 (), "#4");
3135 msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
3136 Assert.AreEqual (2, msgs.Count, "#5");
3137 m1 = (Message) msgs [1];
3139 Assert.AreEqual (WndMsg.WM_DESTROY, ((WndMsg) LowOrder (m1.WParam)), "#6");
3140 //Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam), "#7");
3141 Assert.AreEqual (child_handle, m1.LParam.ToInt32 (), "#8");
3146 internal static int LowOrder (int param)
3148 return ((int)(short)(param & 0xffff));
3151 internal static int HighOrder (int param)
3153 return ((int)(short)(param >> 16));
3156 internal static int LowOrder (IntPtr param)
3158 return ((int)(short)(param.ToInt32 () & 0xffff));
3161 internal static int HighOrder (IntPtr param)
3163 return ((int)(short)(param.ToInt32 () >> 16));
3166 internal class WMTester : Form
3168 internal ArrayList Messages = new ArrayList ();
3170 internal bool Contains (WndMsg msg)
3172 return Contains (msg, Messages);
3175 internal bool Contains (WndMsg msg, ArrayList list)
3177 foreach (Message m in Messages)
3179 if (m.Msg == (int) msg)
3185 internal ArrayList Find (WndMsg msg)
3187 ArrayList result = new ArrayList ();
3189 foreach (Message m in Messages)
3191 if (m.Msg == (int) msg)
3197 protected override void WndProc(ref Message m)
3199 Console.WriteLine ("WndProc: " + m.ToString ());
3201 base.WndProc (ref m);
3208 public class ControlLayoutTest : TestHelper
3211 protected override void SetUp ()
3217 [Test] // bug #80456
3218 public void LayoutTest ()
3220 MockLayoutEngine layoutEngine = new MockLayoutEngine ();
3221 MockControl c = new MockControl (layoutEngine);
3222 c.Layout += new LayoutEventHandler (LayoutEvent);
3223 Assert.IsFalse (layoutEngine.LayoutInvoked, "#A1");
3224 Assert.AreEqual (0, _layoutCount, "#A2");
3226 Assert.IsTrue (layoutEngine.LayoutInvoked, "#A3");
3227 Assert.AreEqual (1, _layoutCount, "#A4");
3229 layoutEngine.Reset ();
3230 c.OverrideOnLayout = true;
3231 Assert.IsFalse (layoutEngine.LayoutInvoked, "#B1");
3233 Assert.IsFalse (layoutEngine.LayoutInvoked, "#B2");
3234 Assert.AreEqual (1, _layoutCount, "#B3");
3237 void LayoutEvent (object sender, LayoutEventArgs e)
3242 private int _layoutCount;
3244 class MockControl : Control
3246 public MockControl (LayoutEngine layoutEngine)
3248 _layoutEngine = layoutEngine;
3251 public bool OverrideOnLayout
3253 get { return _overrideOnLayout; }
3254 set { _overrideOnLayout = value; }
3257 protected override void OnLayout (LayoutEventArgs levent)
3259 if (!OverrideOnLayout)
3260 base.OnLayout (levent);
3263 public override LayoutEngine LayoutEngine {
3265 if (_layoutEngine == null)
3266 return base.LayoutEngine;
3267 return _layoutEngine;
3271 private bool _overrideOnLayout;
3272 private LayoutEngine _layoutEngine;
3275 class MockLayoutEngine : LayoutEngine
3277 public bool LayoutInvoked {
3278 get { return _layoutInvoked; }
3281 public void Reset ()
3283 _layoutInvoked = false;
3286 public override bool Layout (object container, LayoutEventArgs args)
3288 _layoutInvoked = true;
3292 private bool _layoutInvoked;