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");
1022 class CustomA11yEnabledControl : Control {
1023 public CustomA11yEnabledControl () : base() { }
1024 protected override AccessibleObject CreateAccessibilityInstance () { return new CustomAccessibleObject (this); }
1026 class CustomAccessibleObject : ControlAccessibleObject {
1027 public CustomAccessibleObject (CustomA11yEnabledControl control) : base(control) { }
1028 public override string Name { get { return "custom name"; } }
1029 public override string DefaultAction { get { return "custom default action"; } }
1030 public override string Description { get { return "custom description"; } }
1031 public override AccessibleRole Role { get { return AccessibleRole.Alert; } }
1036 public void CreatedAccessibilityTest ()
1038 CustomA11yEnabledControl c = new CustomA11yEnabledControl ();
1039 Assert.IsFalse(c.Created, "A1");
1041 // Tests default values
1043 Assert.AreEqual (null, c.AccessibleDefaultActionDescription, "A2.0");
1044 Assert.IsFalse(c.IsHandleCreated, "A2.1");
1046 Assert.AreEqual (null, c.AccessibleDescription, "A3.0");
1047 Assert.IsFalse(c.IsHandleCreated, "A3.1");
1049 Assert.AreEqual (null, c.AccessibleName, "A4.0");
1050 Assert.IsFalse(c.IsHandleCreated, "A4.1");
1052 Assert.AreEqual (AccessibleRole.Default, c.AccessibleRole, "A5.0");
1053 Assert.IsFalse(c.IsHandleCreated, "A5.1");
1055 object o = c.AccessibilityObject;
1056 Assert.IsTrue(c.IsHandleCreated, "A6");
1058 // Tests to confirm that:
1059 // - calling Control.AccessibleXXXXX is not returning AccessibleObject.XXXXX
1060 // - Handle is not Created when calling Control.AccessibleXXXXX
1061 c = new CustomA11yEnabledControl ();
1063 string accessibleDefaultActionDescription = "default action description";
1064 c.AccessibleDefaultActionDescription = accessibleDefaultActionDescription;
1065 Assert.IsFalse (c.IsHandleCreated, "A7.0");
1066 Assert.AreEqual (accessibleDefaultActionDescription, c.AccessibleDefaultActionDescription, "A7.1");
1068 string accessibleDescription = "accessible description";
1069 c.AccessibleDescription = accessibleDescription;
1070 Assert.IsFalse (c.IsHandleCreated, "A8.0");
1071 Assert.AreEqual (accessibleDescription, c.AccessibleDescription, "A8.1");
1073 string accessibleName = "accessible name";
1074 c.AccessibleName = accessibleName;
1075 Assert.IsFalse (c.IsHandleCreated, "A9.0");
1076 Assert.AreEqual (accessibleName, c.AccessibleName, "A9.1");
1078 AccessibleRole accessibleRole = AccessibleRole.Diagram;
1079 c.AccessibleRole = accessibleRole;
1080 Assert.AreEqual (accessibleRole, c.AccessibleRole, "A10.0");
1081 Assert.IsFalse (c.IsHandleCreated, "A10.1");
1084 Assert.IsFalse (c.Created, "A11");
1088 [Category ("NotWorking")]
1089 public void BoundsTest ()
1091 Control c = new Control ();
1092 Assert.IsTrue (c.Bounds.IsEmpty, "A1");
1093 Assert.IsTrue (c.Size.IsEmpty, "A2");
1094 Assert.IsTrue (c.ClientSize.IsEmpty, "A3");
1095 Assert.IsTrue (c.ClientRectangle.IsEmpty, "A4");
1097 Assert.AreEqual (((IWin32Window)c).Handle, c.Handle, "A5");
1099 /* this part fails on linux because we can't allocate X windows which are 0x0,
1100 and the Control bounds directly reflect the size of the X window */
1102 Assert.IsTrue (c.Bounds.IsEmpty, "A6");
1103 Assert.IsTrue (c.Size.IsEmpty, "A7");
1104 Assert.IsTrue (c.ClientSize.IsEmpty, "A8");
1105 Assert.IsTrue (c.ClientRectangle.IsEmpty, "A9");
1109 [Ignore ("Depends on specific DPI")]
1110 public void FontHeightTest ()
1112 MockControl c = new MockControl ();
1113 Assert.AreEqual (13, c.font_height);
1117 public void FontTest ()
1119 Control c = new Control ();
1120 Assert.IsFalse (c.Font.Bold, "#A1");
1121 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#A2");
1122 Assert.IsFalse (c.Font.Italic, "#A3");
1123 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#A4");
1124 Assert.AreEqual (8.25, c.Font.Size, "#A5");
1125 Assert.AreEqual (8.25, c.Font.SizeInPoints, "#A6");
1126 Assert.IsFalse (c.Font.Strikeout, "#A7");
1127 Assert.IsFalse (c.Font.Underline, "#A8");
1128 Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#A9");
1130 Assert.IsTrue (c.Font.IsSystemFont, "#A10");
1133 c.Font = new Font (c.Font.FontFamily, 3, FontStyle.Italic);
1134 Assert.IsFalse (c.Font.Bold, "#B1");
1135 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#B2");
1136 Assert.IsTrue (c.Font.Italic, "#B3");
1137 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#B4");
1138 Assert.AreEqual (3, c.Font.Size, "#B5");
1139 Assert.AreEqual (3, c.Font.SizeInPoints, "#B6");
1140 Assert.IsFalse (c.Font.Strikeout, "#B7");
1141 Assert.IsFalse (c.Font.Underline, "#B8");
1142 Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#B9");
1144 Assert.AreEqual (false, c.Font.IsSystemFont, "#B10");
1149 [Category ("NotWorking")] // on Unix mapping is done to Bitstream Vera Sans
1150 public void FontTest_Names ()
1152 Control c = new Control ();
1153 Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#1");
1154 Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#2");
1158 public void PubPropTest()
1160 Control c = new Control();
1162 Assert.IsFalse (c.AllowDrop , "A1");
1163 Assert.AreEqual(AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "A2");
1165 Assert.AreEqual ("Control", c.BackColor.Name , "B1");
1166 Assert.IsNull (c.BackgroundImage, "B2");
1167 Assert.IsNull (c.BindingContext, "B3");
1169 Assert.AreEqual (ImageLayout.Tile, c.BackgroundImageLayout, "B4");
1172 Assert.IsFalse (c.CanFocus, "C1");
1173 Assert.IsTrue (c.CanSelect, "C2");
1174 Assert.IsFalse (c.Capture, "C3");
1175 Assert.IsTrue (c.CausesValidation, "C4");
1177 Assert.IsNotNull (c.CompanyName, "C7");
1178 Assert.IsNull (c.Container, "C8");
1179 Assert.IsFalse (c.ContainsFocus, "C9");
1180 Assert.IsNull (c.ContextMenu, "C10");
1181 Assert.AreEqual (0, c.Controls.Count, "C11");
1182 Assert.IsFalse (c.Created, "C12");
1183 Assert.AreEqual (Cursors.Default, c.Cursor, "C13");
1185 Assert.IsNotNull(c.DataBindings, "D1");
1186 Assert.AreEqual("Control", Control.DefaultBackColor.Name, "D2");
1187 Assert.AreEqual("ControlText", Control.DefaultForeColor.Name, "D3");
1188 Assert.AreEqual(FontStyle.Regular, Control.DefaultFont.Style, "D4");
1189 Assert.AreEqual (new Rectangle(0, 0, 0, 0), c.DisplayRectangle , "D5");
1190 Assert.IsFalse (c.Disposing, "D6");
1191 Assert.AreEqual(DockStyle.None, c.Dock, "D7");
1193 Assert.IsTrue (c.Enabled, "E1");
1195 Assert.IsFalse (c.Focused, "F1");
1196 Assert.AreEqual (FontStyle.Regular, c.Font.Style, "F2");
1197 Assert.AreEqual (SystemColors.ControlText, c.ForeColor, "F3");
1199 Assert.IsFalse (c.HasChildren, "H2");
1201 Assert.AreEqual (ImeMode.NoControl, c.ImeMode, "I1");
1202 Assert.IsFalse (c.InvokeRequired, "I2");
1203 Assert.IsFalse (c.IsAccessible, "I3");
1204 Assert.IsFalse (c.IsDisposed, "I4");
1205 Assert.IsFalse (c.IsHandleCreated, "I5");
1207 Assert.AreEqual(Point.Empty, c.Location, "L2");
1210 Assert.IsTrue(c.MaximumSize.IsEmpty);
1211 Assert.IsTrue(c.MinimumSize.IsEmpty);
1213 Assert.AreEqual (Keys.None, Control.ModifierKeys, "M1");
1214 Assert.IsTrue (Control.MousePosition.X >= 0 && Control.MousePosition.Y >= 0, "M2");
1215 Assert.AreEqual (MouseButtons.None, Control.MouseButtons, "M3");
1217 Assert.AreEqual("", c.Name, "N1");
1218 c.Name = "Control Name";
1219 Assert.AreEqual("Control Name", c.Name, "N2");
1221 Assert.IsNull (c.Parent, "P1");
1222 Assert.IsNotNull (c.ProductName, "P2");
1223 Assert.IsTrue (c.ProductName != "", "P3");
1224 Assert.IsNotNull (c.ProductVersion, "P4");
1225 Assert.IsTrue (c.ProductVersion != "", "P5");
1227 Assert.IsFalse (c.RecreatingHandle, "R1");
1228 Assert.IsNull (c.Region, "R2");
1229 Assert.AreEqual (RightToLeft.No, c.RightToLeft, "R4");
1231 Assert.IsNull (c.Site, "S1");
1233 Assert.AreEqual (0, c.TabIndex , "T1");
1234 Assert.IsTrue (c.TabStop, "T2");
1235 Assert.IsNull (c.Tag, "T3");
1236 Assert.AreEqual ("", c.Text, "T4");
1238 Assert.IsTrue (c.Visible, "V1");
1242 public void SizeChangeTest ()
1244 Form f = new Form ();
1245 Control c = new Control ();
1248 c.Resize += new EventHandler(SizeChangedTest_ResizeHandler);
1251 Assert.AreEqual (true, (bool) c.Tag, "#1");
1255 private void SizeChangedTest_ResizeHandler (object sender, EventArgs e)
1257 ((Control) sender).Tag = false;
1261 public void NegativeHeightTest ()
1263 Control c = new Control ();
1264 IntPtr handle = c.Handle;
1265 c.Resize += new EventHandler(NegativeHeightTest_ResizeHandler);
1269 Assert.AreEqual (0, (int) c.Tag, "#1");
1271 Assert.AreEqual (handle, handle, "Removes warning.");
1274 private void NegativeHeightTest_ResizeHandler (object sender, EventArgs e)
1276 Control c = (Control) sender;
1281 public void TopLevelControlTest () {
1282 Control c = new Control ();
1284 Assert.AreEqual(null, c.TopLevelControl, "T1");
1286 Panel p = new Panel ();
1290 Assert.AreEqual(null, c.TopLevelControl, "T2");
1292 Form f = new Form ();
1293 f.ShowInTaskbar = false;
1297 Assert.AreEqual (f, c.TopLevelControl, "T3");
1298 Assert.AreEqual (f, f.TopLevelControl, "T4");
1304 public void RelationTest() {
1311 Assert.AreEqual(true , c1.Visible , "Rel1");
1312 Assert.AreEqual(false, c1.Contains(c2) , "Rel2");
1313 Assert.AreEqual("System.Windows.Forms.Control", c1.ToString() , "Rel3");
1315 c1.Controls.Add(c2);
1316 Assert.AreEqual(true , c2.Visible , "Rel4");
1317 Assert.AreEqual(true, c1.Contains(c2) , "Rel5");
1319 c1.Anchor = AnchorStyles.Top;
1320 c1.SuspendLayout ();
1321 c1.Anchor = AnchorStyles.Left ;
1323 Assert.AreEqual(AnchorStyles.Left , c1.Anchor, "Rel6");
1325 c1.SetBounds(10, 20, 30, 40) ;
1326 Assert.AreEqual(new Rectangle(10, 20, 30, 40), c1.Bounds, "Rel7");
1328 Assert.AreEqual(c1, c2.Parent, "Rel8");
1332 public void AnchorDockTest ()
1334 Control c = new Control ();
1336 Assert.AreEqual (DockStyle.None, c.Dock, "1");
1337 Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "2");
1339 c.Dock = DockStyle.Top;
1340 Assert.AreEqual (DockStyle.Top, c.Dock, "3");
1341 Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "4");
1343 c.Anchor = AnchorStyles.Top;
1344 Assert.AreEqual (DockStyle.None, c.Dock, "5");
1345 Assert.AreEqual (AnchorStyles.Top, c.Anchor, "6");
1349 [Category ("NotWorking")]
1350 public void TabOrder()
1355 Label label1 = new Label(); // To test non-tabstop items as well
1356 Label label2 = new Label();
1358 GroupBox group1 = new GroupBox();
1359 GroupBox group2 = new GroupBox();
1360 GroupBox group3 = new GroupBox();
1362 TextBox text1 = new TextBox();
1364 RadioButton radio11 = new RadioButton();
1365 RadioButton radio12 = new RadioButton();
1366 RadioButton radio13 = new RadioButton();
1367 RadioButton radio14 = new RadioButton();
1368 RadioButton radio21 = new RadioButton();
1369 RadioButton radio22 = new RadioButton();
1370 RadioButton radio23 = new RadioButton();
1371 RadioButton radio24 = new RadioButton();
1372 RadioButton radio31 = new RadioButton();
1373 RadioButton radio32 = new RadioButton();
1374 RadioButton radio33 = new RadioButton();
1375 RadioButton radio34 = new RadioButton();
1378 form.ShowInTaskbar = false;
1380 form.ClientSize = new Size (520, 520);
1381 Assert.AreEqual(new Size(520, 520), form.ClientSize, "Tab1");
1383 form.Text = "SWF Taborder Test App Form";
1384 Assert.AreEqual("SWF Taborder Test App Form", form.Text, "Tab2");
1386 label1.Location = new Point(10, 10);
1387 Assert.AreEqual(new Point(10, 10), label1.Location, "Tab3");
1388 label1.Text = "Label1";
1389 form.Controls.Add(label1);
1391 label2.Location = new Point(200, 10);
1392 label2.Text = "Label2";
1393 form.Controls.Add(label2);
1395 group1.Text = "Group1";
1396 group2.Text = "Group2";
1397 group3.Text = "Group3";
1399 group1.Size = new Size(200, 400);
1400 group2.Size = new Size(200, 400);
1401 group3.Size = new Size(180, 180);
1402 Assert.AreEqual(new Size(180, 180), group3.Size, "Tab4");
1404 group1.Location = new Point(10, 40);
1405 group2.Location = new Point(220, 40);
1406 group3.Location = new Point(10, 210);
1408 group1.TabIndex = 30;
1409 Assert.AreEqual(30, group1.TabIndex, "Tab5");
1410 group1.TabStop = true;
1412 // Don't assign, test automatic assignment
1413 //group2.TabIndex = 0;
1414 group2.TabStop = true;
1415 Assert.AreEqual(0, group2.TabIndex, "Tab6");
1417 group3.TabIndex = 35;
1418 group3.TabStop = true;
1420 // Test default tab index
1421 Assert.AreEqual(0, radio11.TabIndex, "Tab7");
1423 text1.Text = "Edit Control";
1425 radio11.Text = "Radio 1-1 [Tab1]";
1426 radio12.Text = "Radio 1-2 [Tab2]";
1427 radio13.Text = "Radio 1-3 [Tab3]";
1428 radio14.Text = "Radio 1-4 [Tab4]";
1430 radio21.Text = "Radio 2-1 [Tab4]";
1431 radio22.Text = "Radio 2-2 [Tab3]";
1432 radio23.Text = "Radio 2-3 [Tab2]";
1433 radio24.Text = "Radio 2-4 [Tab1]";
1435 radio31.Text = "Radio 3-1 [Tab1]";
1436 radio32.Text = "Radio 3-2 [Tab3]";
1437 radio33.Text = "Radio 3-3 [Tab2]";
1438 radio34.Text = "Radio 3-4 [Tab4]";
1440 // We don't assign TabIndex for radio1X; test automatic assignment
1441 text1.TabStop = true;
1442 radio11.TabStop = true;
1444 radio21.TabIndex = 4;
1445 radio22.TabIndex = 3;
1446 radio23.TabIndex = 2;
1447 radio24.TabIndex = 1;
1448 radio24.TabStop = true;
1450 radio31.TabIndex = 11;
1451 radio31.TabStop = true;
1452 radio32.TabIndex = 13;
1453 radio33.TabIndex = 12;
1454 radio34.TabIndex = 14;
1456 text1.Location = new Point(10, 100);
1458 radio11.Location = new Point(10, 20);
1459 radio12.Location = new Point(10, 40);
1460 radio13.Location = new Point(10, 60);
1461 radio14.Location = new Point(10, 80);
1463 radio21.Location = new Point(10, 20);
1464 radio22.Location = new Point(10, 40);
1465 radio23.Location = new Point(10, 60);
1466 radio24.Location = new Point(10, 80);
1468 radio31.Location = new Point(10, 20);
1469 radio32.Location = new Point(10, 40);
1470 radio33.Location = new Point(10, 60);
1471 radio34.Location = new Point(10, 80);
1473 text1.Size = new Size(150, text1.PreferredHeight);
1475 radio11.Size = new Size(150, 20);
1476 radio12.Size = new Size(150, 20);
1477 radio13.Size = new Size(150, 20);
1478 radio14.Size = new Size(150, 20);
1480 radio21.Size = new Size(150, 20);
1481 radio22.Size = new Size(150, 20);
1482 radio23.Size = new Size(150, 20);
1483 radio24.Size = new Size(150, 20);
1485 radio31.Size = new Size(150, 20);
1486 radio32.Size = new Size(150, 20);
1487 radio33.Size = new Size(150, 20);
1488 radio34.Size = new Size(150, 20);
1490 group1.Controls.Add(text1);
1492 group1.Controls.Add(radio11);
1493 group1.Controls.Add(radio12);
1494 group1.Controls.Add(radio13);
1495 group1.Controls.Add(radio14);
1497 group2.Controls.Add(radio21);
1498 group2.Controls.Add(radio22);
1499 group2.Controls.Add(radio23);
1500 group2.Controls.Add(radio24);
1502 group3.Controls.Add(radio31);
1503 group3.Controls.Add(radio32);
1504 group3.Controls.Add(radio33);
1505 group3.Controls.Add(radio34);
1507 form.Controls.Add(group1);
1508 form.Controls.Add(group2);
1509 group2.Controls.Add(group3);
1511 // Perform some tests, the TabIndex stuff below will alter the outcome
1512 Assert.AreEqual(null, Helper.TestControl(group2, radio34, true), "Tab8");
1513 Assert.AreEqual(31, group2.TabIndex, "Tab9");
1515 // Does the taborder of containers and non-selectable things change behaviour?
1516 label1.TabIndex = 5;
1517 label2.TabIndex = 4;
1518 group1.TabIndex = 3;
1519 group2.TabIndex = 1;
1521 // Start verification
1522 Assert.AreEqual(null, Helper.TestControl(group2, radio34, true), "Tab10");
1523 Assert.AreEqual(radio24.Text, Helper.TestControl(group2, group2, true), "Tab11");
1524 Assert.AreEqual(radio31.Text, Helper.TestControl(group2, group3, true), "Tab12");
1525 Assert.AreEqual(null, Helper.TestControl(group1, radio14, true), "Tab13");
1526 Assert.AreEqual(radio23.Text, Helper.TestControl(group2, radio24, true), "Tab14");
1527 Assert.AreEqual(group3.Text, Helper.TestControl(group2, radio21, true), "Tab15");
1528 Assert.AreEqual(radio13.Text, Helper.TestControl(form, radio12, true), "Tab16");
1529 Assert.AreEqual(label2.Text, Helper.TestControl(form, radio14, true), "Tab17");
1530 Assert.AreEqual(group1.Text, Helper.TestControl(form, radio34, true), "Tab18");
1531 Assert.AreEqual(radio23.Text, Helper.TestControl(group2, radio24, true), "Tab19");
1534 Assert.AreEqual(null, Helper.TestControl(radio11, radio21, true), "Tab20");
1535 Assert.AreEqual(text1.Text, Helper.TestControl(group1, radio21, true), "Tab21");
1537 Assert.AreEqual(radio14.Text, Helper.TestControl(form, label2, false), "Tab22");
1538 Assert.AreEqual(radio21.Text, Helper.TestControl(group2, group3, false), "Tab23");
1540 Assert.AreEqual(4, radio21.TabIndex, "Tab24");
1541 Assert.AreEqual(1, radio11.TabIndex, "Tab25");
1542 Assert.AreEqual(3, radio13.TabIndex, "Tab26");
1543 Assert.AreEqual(35, group3.TabIndex, "Tab27");
1544 Assert.AreEqual(1, group2.TabIndex, "Tab28");
1546 Assert.AreEqual(label1.Text, Helper.TestControl(form, form, false), "Tab29");
1547 Assert.AreEqual(radio14.Text, Helper.TestControl(group1, group1, false), "Tab30");
1548 Assert.AreEqual(radio34.Text, Helper.TestControl(group3, group3, false), "Tab31");
1550 Assert.AreEqual(null, Helper.TestControl(label1, label1, false), "Tab31");
1551 Assert.AreEqual(null, Helper.TestControl(radio11, radio21, false), "Tab32");
1556 public void ScaleTest()
1558 Control r1 = new Control();
1563 Assert.AreEqual(80, r1.Width, "Scale1");
1564 Assert.AreEqual(40, r1.Height, "Scale2");
1569 public void ScaleChildrenTest ()
1571 ScaleChildrenControl c = new ScaleChildrenControl ();
1572 Assert.AreEqual (true, c.PublicScaleChildren, "A1");
1575 private class ScaleChildrenControl : Control
1577 public bool PublicScaleChildren {
1578 get { return base.ScaleChildren; }
1583 public void ScaleControlTest ()
1585 ScaleControl c = new ScaleControl ();
1587 c.Location = new Point (5, 10);
1588 c.Size = new Size (15, 20);
1590 Assert.AreEqual (new Rectangle (5, 10, 15, 20), c.Bounds, "A1");
1592 c.PublicScaleControl (new SizeF (1.5f, 1.3f), BoundsSpecified.All);
1593 Assert.AreEqual (new Rectangle (8, 13, 22, 26), c.Bounds, "A2");
1595 c.PublicScaleControl (new SizeF (2f, 1.5f), BoundsSpecified.Location);
1596 Assert.AreEqual (new Rectangle (16, 20, 22, 26), c.Bounds, "A3");
1598 c.PublicScaleControl (new SizeF (1.5f, 2f), BoundsSpecified.Size);
1599 Assert.AreEqual (new Rectangle (16, 20, 33, 52), c.Bounds, "A4");
1601 c.PublicScaleControl (new SizeF (1.5f, 1.5f), BoundsSpecified.Width);
1602 Assert.AreEqual (new Rectangle (16, 20, 50, 52), c.Bounds, "A5");
1604 c.PublicScaleControl (new SizeF (1.5f, 1.3f), BoundsSpecified.None);
1605 Assert.AreEqual (new Rectangle (16, 20, 50, 52), c.Bounds, "A6");
1607 // Test with ScaleChildren
1608 c = new ScaleControl ();
1610 c.Location = new Point (5, 10);
1611 c.Size = new Size (50, 50);
1613 Control c2 = new Control ();
1614 c2.Location = new Point (15, 15);
1615 c2.Size = new Size (25, 25);
1616 c.Controls.Add (c2);
1618 Assert.AreEqual (new Rectangle (5, 10, 50, 50), c.Bounds, "B1");
1619 Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B2");
1621 c.scale_children = false;
1623 c.PublicScaleControl (new SizeF (2f, 2f), BoundsSpecified.All);
1624 Assert.AreEqual (new Rectangle (10, 20, 100, 100), c.Bounds, "B3");
1625 Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B4");
1627 c.scale_children = true;
1629 // Will not scale children in ScaleControl
1630 c.PublicScaleControl (new SizeF (2f, 2f), BoundsSpecified.All);
1631 Assert.AreEqual (new Rectangle (20, 40, 200, 200), c.Bounds, "B5");
1632 Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B6");
1634 // Does scale children in Scale
1635 c.Scale (new SizeF (2f, 2f));
1636 Assert.AreEqual (new Rectangle (40, 80, 400, 400), c.Bounds, "B7");
1637 Assert.AreEqual (new Rectangle (30, 30, 50, 50), c2.Bounds, "B8");
1641 public void GetScaledBoundsTest ()
1643 ScaleControl c = new ScaleControl ();
1645 Rectangle r = new Rectangle (10, 20, 30, 40);
1647 Assert.AreEqual (new Rectangle (20, 10, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A1");
1648 Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A2");
1649 Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A3");
1650 Assert.AreEqual (new Rectangle (10, 20, 30, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A4");
1651 Assert.AreEqual (new Rectangle (20, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A5");
1652 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A6");
1654 c.PublicSetTopLevel (true);
1656 Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A7");
1657 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A8");
1658 Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A9");
1659 Assert.AreEqual (new Rectangle (10, 20, 30, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A10");
1660 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A11");
1661 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A12");
1663 c = new ScaleControl ();
1664 c.PublicSetStyle (ControlStyles.FixedHeight, true);
1665 c.PublicSetStyle (ControlStyles.FixedWidth, true);
1667 Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A13");
1668 Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A14");
1669 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A15");
1670 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A16");
1671 Assert.AreEqual (new Rectangle (20, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A17");
1672 Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A18");
1675 private class ScaleControl : Control
1677 public bool scale_children = true;
1679 public void PublicScaleControl (SizeF factor, BoundsSpecified specified)
1681 base.ScaleControl (factor, specified);
1684 public Rectangle PublicGetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
1686 return base.GetScaledBounds (bounds, factor, specified);
1689 public void PublicSetStyle (ControlStyles flag, bool value)
1691 base.SetStyle (flag, value);
1694 public void PublicSetTopLevel (bool value)
1696 base.SetTopLevel (value);
1699 protected override bool ScaleChildren {
1700 get { return scale_children; }
1705 [Test] // Bug #347282
1706 public void ScaleHierarchy ()
1708 Form f = new Form ();
1709 Panel p = new Panel ();
1710 Button b = new Button ();
1712 f.ClientSize = new Size (300, 300);
1717 f.AutoScaleBaseSize = new Size (3, 11);
1720 // Due to font differences, all we can guarantee is that
1721 // the button is larger that the default.
1722 Assert.IsTrue (b.Width > 75, "A1");
1723 Assert.IsTrue (b.Height > 23, "A2");
1728 class TestWindowTarget : IWindowTarget
1730 public void OnHandleChange (IntPtr newHandle) {
1733 public void OnMessage (ref Message m) {
1738 public void WindowTargetTest()
1740 Control c = new Control ();
1741 Assert.IsNotNull (c.WindowTarget, "WindowTarget1");
1742 c.WindowTarget = null;
1743 Assert.IsNull (c.WindowTarget, "WindowTarget2");
1745 IWindowTarget existing_target = c.WindowTarget;
1746 IWindowTarget new_target = new TestWindowTarget ();
1747 c.WindowTarget = new_target;
1748 Assert.AreSame (new_target, c.WindowTarget, "WindowTarget3");
1750 TestHelper.RemoveWarning (existing_target);
1754 public void TextTest()
1756 Control r1 = new Control();
1758 Assert.AreEqual("Hi" , r1.Text , "Text1");
1761 Assert.AreEqual("" , r1.Text , "Text2");
1765 public void PubMethodTest7()
1767 Control r1 = new Control();
1768 r1.RightToLeft = RightToLeft.Yes ;
1769 r1.ResetRightToLeft() ;
1770 Assert.AreEqual(RightToLeft.No , r1.RightToLeft , "#81");
1771 r1.ImeMode = ImeMode.Off ;
1772 r1.ResetImeMode () ;
1773 Assert.AreEqual(ImeMode.NoControl , r1.ImeMode , "#82");
1774 r1.ForeColor= SystemColors.GrayText ;
1775 r1.ResetForeColor() ;
1776 Assert.AreEqual(SystemColors.ControlText , r1.ForeColor , "#83");
1777 //r1.Font = Font.FromHdc();
1779 //Assert.AreEqual(FontFamily.GenericSansSerif , r1.Font , "#83");
1780 r1.Cursor = Cursors.Hand ;
1782 Assert.AreEqual(Cursors.Default , r1.Cursor , "#83");
1783 //r1.DataBindings = System.Windows.Forms.Binding ;
1784 //r1.ResetBindings() ;
1785 //Assert.AreEqual(ControlBindingsCollection , r1.DataBindings , "#83");
1786 r1.BackColor = Color.Black ;
1787 r1.ResetBackColor() ;
1788 Assert.AreEqual( SystemColors.Control , r1.BackColor , "#84");
1789 r1.BackColor = Color.Black ;
1791 Assert.AreEqual( null , r1.Region , "#85");
1792 Rectangle M = new Rectangle(10, 20, 30 ,40);
1793 r1.RectangleToScreen(M) ;
1794 Assert.AreEqual( null , r1.Region , "#86");
1798 public void ScreenClientCoords()
1809 p1 = new Point (10,10);
1810 p2 = l.PointToScreen(p1);
1811 p3 = l.PointToClient(p2);
1813 Assert.AreEqual (p1, p3, "SC1");
1817 public void ContainsTest ()
1819 Control t = new Control ();
1820 Control s = new Control ();
1824 Assert.AreEqual (true, t.Contains (s), "Con1");
1825 Assert.AreEqual (false, s.Contains (t), "Con2");
1826 Assert.AreEqual (false, s.Contains (null), "Con3");
1827 Assert.AreEqual (false, t.Contains (new Control ()), "Con4");
1831 public void IsHandleCreated_NotVisible ()
1833 Control c = new Control ();
1836 Form form = new Form ();
1837 form.ShowInTaskbar = false;
1838 form.Controls.Add (c);
1841 Assert.IsFalse (c.IsHandleCreated, "#1");
1843 Assert.IsTrue (c.IsHandleCreated, "#2");
1845 Assert.IsTrue (c.IsHandleCreated, "#3");
1849 class OnCreateControlTest : Control {
1850 public bool reached = false;
1851 protected override void OnCreateControl () {
1857 public void CreateControlVisibleTest ()
1859 OnCreateControlTest test = new OnCreateControlTest ();
1860 test.Visible = false;
1861 Assert.IsFalse (test.IsHandleCreated, "0");
1862 Assert.IsFalse (test.Visible, "1");
1863 test.Visible = true;
1864 Assert.IsTrue (test.Visible, "2");
1865 Assert.IsTrue (test.reached, "3");
1870 public void CreateGraphicsTest ()
1876 Control c = new Control ();
1877 c.SetBounds (0,0, 20, 20);
1878 g = c.CreateGraphics ();
1879 Assert.IsNotNull (g, "Graph1");
1888 bool delegateCalled = false;
1889 public delegate void TestDelegate ();
1891 public void delegate_call () {
1892 delegateCalled = true;
1894 TestHelper.RemoveWarning (delegateCalled);
1898 [ExpectedException(typeof(InvalidOperationException))]
1899 public void InvokeException1 () {
1900 Control c = new Control ();
1901 IAsyncResult result;
1903 result = c.BeginInvoke (new TestDelegate (delegate_call));
1904 c.EndInvoke (result);
1908 public void FindFormTest () {
1909 Form f = new Form ();
1911 f.ShowInTaskbar = false;
1916 f.Controls.Add (c = new Control ());
1917 Assert.AreEqual (f.Name, c.FindForm ().Name, "Find1");
1919 f.Controls.Remove (c);
1921 GroupBox g = new GroupBox ();
1926 Assert.AreEqual (f.Name, f.FindForm ().Name, "Find2");
1928 g.Controls.Remove (c);
1929 Assert.IsNull(c.FindForm (), "Find3");
1940 public void FocusTest ()
1943 Button c = null, d = null;
1947 f.ShowInTaskbar = false;
1957 Assert.IsTrue (c.CanFocus, "Focus1");
1958 Assert.IsFalse (c.Focused, "Focus2");
1960 Assert.IsTrue (c.Focused, "Focus3");
1962 Assert.IsFalse (d.Focused, "Focus4");
1966 Assert.IsTrue (d.Focused, "Focus5");
1967 Assert.IsFalse (c.Focused, "Focus6");
1970 Assert.IsFalse (c.Focused, "Focus7");
1982 public void FromHandleTest ()
1988 c1 = new Control ();
1989 c2 = new Control ();
1993 c1.Controls.Add(c2);
1996 Assert.AreEqual (c1.Name, Control.FromHandle (c1.Handle).Name, "Handle1");
1997 Assert.IsNull (Control.FromHandle (IntPtr.Zero), "Handle2");
2000 Assert.AreEqual (c1.Name, Control.FromChildHandle (c1.Handle).Name, "Handle3");
2001 Assert.IsNull (Control.FromChildHandle (IntPtr.Zero), "Handle4");
2014 public void GetChildAtPointTest ()
2016 Control c = null, d = null;
2017 TransparentControl e = null;
2022 c.SetBounds (0, 0, 100, 100);
2026 d.SetBounds (10, 10, 40, 40);
2029 e = new TransparentControl ();
2031 e.SetBounds (55, 55, 10, 10);
2033 Control l = c.GetChildAtPoint (new Point (15, 15));
2034 Assert.AreEqual (d.Name, l.Name, "Child1");
2035 Assert.IsFalse (e.Name == l.Name, "Child2");
2037 l = c.GetChildAtPoint (new Point (57, 57));
2038 Assert.AreEqual (null, l, "Child3");
2040 l = c.GetChildAtPoint (new Point (10, 10));
2041 Assert.AreEqual (d.Name, l.Name, "Child4");
2043 // GetChildAtPointSkip is not implemented and the following test is breaking for Net_2_0 profile
2047 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
2048 Assert.IsNull (l, "Child5");
2051 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
2052 Assert.AreSame (e.Name, l.Name, "Child6");
2055 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Disabled);
2056 Assert.IsNull (l, "Child7");
2059 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Disabled);
2060 Assert.AreSame (e.Name, l.Name, "Child8");
2063 e.BackColor = Color.Transparent;
2064 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Transparent);
2065 Assert.IsNull (l, "Child9");
2067 e.BackColor = Color.Green;
2068 l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Transparent);
2069 Assert.AreSame (e.Name, l.Name, "Child10");
2080 private class TransparentControl : Control
2082 public TransparentControl ()
2084 SetStyle (ControlStyles.SupportsTransparentBackColor, true);
2087 protected override CreateParams CreateParams
2091 CreateParams cp = base.CreateParams;
2092 cp.ExStyle |= 0x00000020;
2099 public void ResetFontTest ()
2101 Control c = new Control ();
2102 c.Font = new Font (c.Font.FontFamily, 3, FontStyle.Italic);
2105 Assert.IsFalse (c.Font.Bold, "#1");
2106 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#2");
2107 Assert.IsFalse (c.Font.Italic, "#3");
2108 //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#4");
2109 Assert.AreEqual (8.25, c.Font.Size, "#5");
2110 Assert.AreEqual (8.25, c.Font.SizeInPoints, "#6");
2111 Assert.IsFalse (c.Font.Strikeout, "#7");
2112 Assert.IsFalse (c.Font.Underline, "#8");
2113 Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#9");
2115 Assert.AreEqual (true, c.Font.IsSystemFont, "#10");
2119 public class LayoutTestControl : Control {
2120 public int LayoutCount;
2122 public LayoutTestControl () : base() {
2126 protected override void OnLayout(LayoutEventArgs levent) {
2128 base.OnLayout (levent);
2133 public void LayoutTest() {
2134 LayoutTestControl c;
2136 c = new LayoutTestControl();
2143 c.ResumeLayout(true);
2145 c.ResumeLayout(true);
2147 c.ResumeLayout(true);
2149 c.ResumeLayout(true);
2151 c.ResumeLayout(true);
2153 c.ResumeLayout(true);
2155 c.ResumeLayout(true);
2160 Assert.AreEqual(5, c.LayoutCount, "Layout Suspend/Resume locking does not bottom out at 0");
2164 [ExpectedException(typeof(ArgumentException))]
2165 public void TransparentBackgroundTest1() {
2169 c.BackColor = Color.Transparent;
2173 public void TransparentBackgroundTest2() {
2177 c.BackColor = Color.Transparent;
2178 Assert.AreEqual(Color.Transparent, c.BackColor, "Transparent background not set");
2182 public void TransparentBackgroundTest3() {
2186 c.BackColor = Color.Empty;
2187 Assert.AreEqual(Control.DefaultBackColor, c.BackColor, "Setting empty color failed");
2191 public void Dock_Value_Invalid ()
2193 Control c = new Control ();
2195 c.Dock = (DockStyle) 666;
2197 } catch (InvalidEnumArgumentException ex) {
2198 Assert.AreEqual (typeof (InvalidEnumArgumentException), ex.GetType (), "#2");
2199 Assert.IsNotNull (ex.Message, "#3");
2200 Assert.IsNotNull (ex.ParamName, "#4");
2201 Assert.AreEqual ("value", ex.ParamName, "#5");
2202 Assert.IsNull (ex.InnerException, "#6");
2207 public void EnabledTest1() {
2212 grandma = new Control();
2213 parent = new Control();
2214 child = new Control();
2216 grandma.Controls.Add(parent);
2217 parent.Controls.Add(child);
2218 grandma.Enabled = false;
2219 Assert.AreEqual(grandma.Enabled, child.Enabled, "Child did not inherit disabled state");
2222 int EnabledCalledCount = 0;
2223 private void EnabledTest2EnabledChanged(object sender, EventArgs e) {
2224 EnabledCalledCount++;
2228 public void EnabledTest2() {
2229 // Check nesting of enabled calls
2230 // OnEnabled is not called for disabled child controls
2235 EnabledCalledCount = 0;
2237 grandma = new Control();
2238 parent = new Control();
2239 child = new Control();
2240 child.EnabledChanged += new EventHandler(EnabledTest2EnabledChanged);
2242 grandma.Controls.Add(parent);
2243 parent.Controls.Add(child);
2244 grandma.Enabled = false;
2246 Assert.AreEqual(1, EnabledCalledCount, "Child Enabled Event not properly fired");
2247 grandma.Enabled = true;
2248 Assert.AreEqual(2, EnabledCalledCount, "Child Enabled Event not properly fired");
2249 child.Enabled = false;
2250 grandma.Enabled = false;
2251 Assert.AreEqual(3, EnabledCalledCount, "Child Enabled Event not properly fired");
2255 public void ControlsRemoveNullTest ()
2257 Control c = new Control ();
2258 c.Controls.Remove (null);
2262 public void ControlsAddNullTest ()
2264 Control c = new Control ();
2265 c.Controls.Add (null);
2269 [ExpectedException (typeof (ArgumentNullException))]
2270 public void ControlsSetChildIndexNullTest ()
2272 Control c = new Control ();
2273 c.Controls.SetChildIndex (null, 1);
2277 [ExpectedException (typeof (ArgumentNullException))]
2278 public void ControlsAddRangeNullTest ()
2280 Control c = new Control ();
2281 c.Controls.AddRange (null);
2285 public void ControlsAddRangeNullElementTest ()
2287 Control c = new Control ();
2288 Control[] subcontrols = new Control[2];
2289 subcontrols[0] = new Control ();
2290 subcontrols[1] = null;
2292 c.Controls.AddRange (subcontrols);
2296 public void RegionTest () {
2297 Form f = new Form ();
2298 f.ShowInTaskbar = false;
2299 Control c = new Control ();
2301 Assert.IsNull (c.Region, "#A1");
2303 Assert.IsNull (c.Region, "#A2");
2305 Assert.IsNull (c.Region, "#A3");
2308 Region region = new Region ();
2310 f.ShowInTaskbar = false;
2314 Assert.IsNotNull (c.Region, "#B1");
2315 Assert.AreSame (region, c.Region, "#B2");
2318 Assert.IsNull (c.Region, "#B3");
2323 [Test] // bug #330501
2324 public void OnValidating_Parent_Close ()
2326 MockControl control = new MockControl ();
2328 Form f = new Form ();
2329 f.Controls.Add (control);
2330 f.ShowInTaskbar = false;
2333 Assert.AreEqual (0, control.OnValidatingCount, "#A1");
2335 Assert.AreEqual (1, control.OnValidatingCount, "#A2");
2339 [Test] // bug #80280
2340 public void Validated_Multiple_Containers ()
2342 Form form = new Form ();
2343 form.ShowInTaskbar = false;
2345 UserControl control1 = new UserControl();
2346 UserControl container1 = new UserControl();
2347 control1.Tag = true;
2348 control1.Validated += new EventHandler (Control_ValidatedHandler);
2349 container1.Controls.Add(control1);
2350 form.Controls.Add (container1);
2352 UserControl container2 = new UserControl();
2353 UserControl control2 = new UserControl();
2354 container2.Controls.Add(control2);
2355 form.Controls.Add (container2);
2357 Assert.IsTrue ((bool) control1.Tag, "#1");
2359 Assert.IsTrue ((bool) control1.Tag, "#2");
2361 Assert.IsFalse ((bool) control1.Tag, "#3");
2366 private void Control_ValidatedHandler (object sender, EventArgs e)
2368 ((Control) sender).Tag = false;
2372 public void ControlReparentLocationTest ()
2374 Form form = new Form ();
2375 Label l = new Label ();
2376 l.Location = new Point (0, 0);
2377 form.Controls.Add (l);
2379 Assert.AreEqual (0, l.Left, "#A1");
2380 Assert.AreEqual (0, l.Top, "#A2");
2382 form.Controls.Remove (l);
2384 form.Controls.Add (l);
2385 Assert.AreEqual (0, l.Left, "#A3");
2386 Assert.AreEqual (0, l.Top, "#A4");
2393 public void UseWaitCursorTest ()
2395 Control c = new Control ();
2396 Assert.IsFalse (c.UseWaitCursor, "#1");
2397 c.Cursor = Cursors.Hand;
2398 c.UseWaitCursor = true;
2399 Assert.AreEqual (Cursors.WaitCursor, c.Cursor, "#2");
2400 c.UseWaitCursor = false;
2401 Assert.AreEqual (Cursors.Hand, c.Cursor, "#3");
2403 c.UseWaitCursor = true;
2404 c.Cursor = Cursors.Help;
2405 Assert.AreEqual (Cursors.WaitCursor, c.Cursor, "#4");
2406 Assert.AreEqual (true, c.UseWaitCursor, "#5");
2408 c.UseWaitCursor = false;
2409 Assert.AreEqual (Cursors.Help, c.Cursor, "#6");
2412 [Test] // bug #80621, #81125
2413 public void DontCallSizeFromClientSize ()
2415 SizeControl sc = new SizeControl ();
2417 Assert.AreEqual (0, sc.size_from_client_size_count, "A1");
2419 sc.ClientSize = new Size (300, 300);
2420 Assert.AreEqual (0, sc.size_from_client_size_count, "A2");
2422 SizeForm sf = new SizeForm ();
2423 sf.ShowInTaskbar = false;
2426 Assert.AreEqual (0, sc.size_from_client_size_count, "A3");
2428 sc.ClientSize = new Size (300, 300);
2429 Assert.AreEqual (0, sc.size_from_client_size_count, "A4");
2434 private class SizeControl : Control
2436 public int size_from_client_size_count = 0;
2438 protected override Size SizeFromClientSize (Size clientSize)
2440 size_from_client_size_count++;
2441 return base.SizeFromClientSize (clientSize);
2445 private class SizeForm : Form
2447 public int size_from_client_size_count = 0;
2449 protected override Size SizeFromClientSize (Size clientSize)
2451 size_from_client_size_count++;
2452 return base.SizeFromClientSize (clientSize);
2457 public class MockControl : Control
2459 public int OnValidatingCount;
2460 public int OnSizeChangedCount;
2461 public int OnResizeCount;
2462 public int OnLocationChangedCount;
2464 public MockControl ()
2468 public MockControl (string text)
2473 public MockControl (Control parent, string text)
2474 : base (parent, text)
2478 public MockControl (string text, int left, int top, int width, int height)
2479 : base (text, left, top, width, height)
2483 public MockControl (Control parent, string text, int left, int top, int width, int height)
2484 : base (parent, text, left, top, width, height)
2488 public int font_height
2490 get { return base.FontHeight; }
2491 set { base.FontHeight = value; }
2494 protected override void OnLocationChanged (EventArgs e)
2496 OnLocationChangedCount++;
2497 base.OnLocationChanged (e);
2500 protected override void OnSizeChanged (EventArgs e)
2502 OnSizeChangedCount++;
2503 base.OnSizeChanged (e);
2506 protected override void OnResize (EventArgs e)
2512 protected override void OnValidating (CancelEventArgs e)
2514 OnValidatingCount++;
2518 const int WM_KEYDOWN = 0x0100;
2519 const int WM_CHAR = 0x0102;
2520 const int WM_SYSCHAR = 0x0106;
2521 const int WM_KEYUP = 0x0101;
2525 public void MethodPreProcessControlMessage ()
2527 bool testing_callstack = false;
2529 MyControl c = new MyControl ();
2530 Message m = new Message ();
2533 m.WParam = (IntPtr)Keys.Down;
2534 m.LParam = IntPtr.Zero;
2536 if (testing_callstack) Console.WriteLine ("Start");
2537 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A1");
2538 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2540 c.SetState (State.OnPreviewKeyDown);
2541 if (testing_callstack) Console.WriteLine ("Start");
2542 Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A2");
2543 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2545 c.SetState (State.ProcessCmdKey);
2546 if (testing_callstack) Console.WriteLine ("Start");
2547 Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A3");
2548 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2550 c.SetState (State.IsInputKey);
2551 if (testing_callstack) Console.WriteLine ("Start");
2552 Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A4");
2553 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2555 c.SetState (State.ProcessDialogKey);
2556 if (testing_callstack) Console.WriteLine ("Start");
2557 Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A5");
2558 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2562 c.SetState (State.None);
2563 if (testing_callstack) Console.WriteLine ("Start");
2564 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A6");
2565 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2567 c.SetState (State.IsInputChar);
2568 if (testing_callstack) Console.WriteLine ("Start");
2569 Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A7");
2570 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2572 c.SetState (State.ProcessDialogChar);
2573 if (testing_callstack) Console.WriteLine ("Start");
2574 Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A8");
2575 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2579 c.SetState (State.None);
2580 if (testing_callstack) Console.WriteLine ("Start");
2581 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A9");
2582 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2584 c.SetState (State.IsInputChar);
2585 if (testing_callstack) Console.WriteLine ("Start");
2586 Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A10");
2587 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2589 c.SetState (State.ProcessDialogChar);
2590 if (testing_callstack) Console.WriteLine ("Start");
2591 Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A11");
2592 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2596 if (testing_callstack) Console.WriteLine ("Start");
2597 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A12");
2598 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2600 c.SetState (State.OnPreviewKeyDown);
2601 if (testing_callstack) Console.WriteLine ("Start");
2602 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A13");
2603 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2605 c.SetState (State.ProcessCmdKey);
2606 if (testing_callstack) Console.WriteLine ("Start");
2607 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A14");
2608 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2610 c.SetState (State.IsInputKey);
2611 if (testing_callstack) Console.WriteLine ("Start");
2612 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A15");
2613 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2615 c.SetState (State.ProcessDialogKey);
2616 if (testing_callstack) Console.WriteLine ("Start");
2617 Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A16");
2618 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2623 public void MethodPreProcessMessage ()
2625 bool testing_callstack = false;
2627 MyControl c = new MyControl ();
2628 Message m = new Message ();
2631 m.WParam = (IntPtr)Keys.Down;
2632 m.LParam = IntPtr.Zero;
2634 if (testing_callstack) Console.WriteLine ("Start");
2635 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A1");
2636 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2638 c.SetState (State.OnPreviewKeyDown);
2639 if (testing_callstack) Console.WriteLine ("Start");
2640 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A2");
2641 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2643 c.SetState (State.ProcessCmdKey);
2644 if (testing_callstack) Console.WriteLine ("Start");
2645 Assert.AreEqual (true, c.PreProcessMessage (ref m), "A3");
2646 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2648 c.SetState (State.IsInputKey);
2649 if (testing_callstack) Console.WriteLine ("Start");
2650 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A4");
2651 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2653 c.SetState (State.ProcessDialogKey);
2654 if (testing_callstack) Console.WriteLine ("Start");
2655 Assert.AreEqual (true, c.PreProcessMessage (ref m), "A5");
2656 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2660 c.SetState (State.None);
2661 if (testing_callstack) Console.WriteLine ("Start");
2662 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A6");
2663 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2665 c.SetState (State.IsInputChar);
2666 if (testing_callstack) Console.WriteLine ("Start");
2667 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A7");
2668 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2670 c.SetState (State.ProcessDialogChar);
2671 if (testing_callstack) Console.WriteLine ("Start");
2672 Assert.AreEqual (true, c.PreProcessMessage (ref m), "A8");
2673 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2677 c.SetState (State.None);
2678 if (testing_callstack) Console.WriteLine ("Start");
2679 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A9");
2680 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2682 c.SetState (State.IsInputChar);
2683 if (testing_callstack) Console.WriteLine ("Start");
2684 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A10");
2685 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2687 c.SetState (State.ProcessDialogChar);
2688 if (testing_callstack) Console.WriteLine ("Start");
2689 Assert.AreEqual (true, c.PreProcessMessage (ref m), "A11");
2690 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2694 if (testing_callstack) Console.WriteLine ("Start");
2695 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A12");
2696 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2698 c.SetState (State.OnPreviewKeyDown);
2699 if (testing_callstack) Console.WriteLine ("Start");
2700 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A13");
2701 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2703 c.SetState (State.ProcessCmdKey);
2704 if (testing_callstack) Console.WriteLine ("Start");
2705 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A14");
2706 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2708 c.SetState (State.IsInputKey);
2709 if (testing_callstack) Console.WriteLine ("Start");
2710 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A15");
2711 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2713 c.SetState (State.ProcessDialogKey);
2714 if (testing_callstack) Console.WriteLine ("Start");
2715 Assert.AreEqual (false, c.PreProcessMessage (ref m), "A16");
2716 if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
2730 private class MyControl : Control
2733 private State current_state;
2734 bool testing_callstack = false;
2736 public void SetState (State state)
2738 current_state = state;
2741 protected override bool ProcessCmdKey (ref Message msg, Keys keyData)
2743 if (testing_callstack) Console.Write ("ProcessCmdKey[");
2744 if (current_state == State.ProcessCmdKey) {
2745 if (testing_callstack) Console.WriteLine ("]");
2749 bool retval = base.ProcessCmdKey (ref msg, keyData);
2750 if (testing_callstack) Console.WriteLine ("]");
2755 protected override void OnPreviewKeyDown (PreviewKeyDownEventArgs e)
2757 if (testing_callstack) Console.Write ("OnPreviewKeyDown[");
2758 if (current_state == State.OnPreviewKeyDown) {
2759 e.IsInputKey = true;
2760 if (testing_callstack) Console.WriteLine ("]");
2764 base.OnPreviewKeyDown (e);
2765 if (testing_callstack) Console.WriteLine ("]");
2769 protected override bool IsInputChar (char charCode)
2771 if (testing_callstack) Console.Write ("IsInputChar[");
2772 if (current_state == State.IsInputChar) {
2773 if (testing_callstack) Console.WriteLine ("true]");
2777 bool retval = base.IsInputChar (charCode);
2778 if (testing_callstack) Console.WriteLine ("{0}]", retval.ToString ());
2782 protected override bool IsInputKey (Keys keyData)
2784 if (testing_callstack) Console.Write ("IsInputKey[");
2785 if (current_state == State.IsInputKey) {
2786 if (testing_callstack) Console.WriteLine ("]");
2790 bool retval = base.IsInputKey (keyData);
2791 if (testing_callstack) Console.WriteLine ("]");
2795 public override bool PreProcessMessage (ref Message msg)
2797 if (testing_callstack) Console.Write ("PreProcessMessage[");
2798 if (current_state == State.PreProcessMessage) {
2799 if (testing_callstack) Console.WriteLine ("]");
2803 bool retval = base.PreProcessMessage (ref msg);
2804 if (testing_callstack) Console.WriteLine ("]");
2808 protected override bool ProcessDialogKey (Keys keyData)
2810 if (testing_callstack) Console.Write ("ProcessDialogKey[");
2811 if (current_state == State.ProcessDialogKey) {
2812 if (testing_callstack) Console.WriteLine ("]");
2816 bool retval = base.ProcessDialogKey (keyData);
2817 if (testing_callstack) Console.WriteLine ("]");
2821 protected override bool ProcessDialogChar (char charCode)
2823 if (testing_callstack) Console.Write ("ProcessDialogChar[");
2824 if (current_state == State.ProcessDialogChar) {
2825 if (testing_callstack) Console.WriteLine ("]");
2829 bool retval = base.ProcessDialogChar (charCode);
2830 if (testing_callstack) Console.WriteLine ("]");
2836 public void MethodIsInputChar ()
2838 // Basically, show that this method always returns false
2839 InputCharControl m = new InputCharControl ();
2840 bool result = false;
2842 for (int i = 0; i < 256; i++)
2843 result |= m.PublicIsInputChar ((char)i);
2845 Assert.AreEqual (false, result, "I1");
2848 private class InputCharControl : Control
2850 public bool PublicIsInputChar (char charCode)
2852 return base.IsInputChar (charCode);
2857 [Test] // bug #81118, 81718
2858 public void VisibleTriggersLayout ()
2860 Form f = new Form ();
2861 f.ShowInTaskbar = false;
2863 Control c = new Control ();
2868 c.Dock = DockStyle.Fill;
2871 Assert.AreEqual (f.ClientSize.Width, c.Width, "L1");
2877 public void ResumeLayoutEffects ()
2879 Form f = new Form ();
2880 f.ShowInTaskbar = false;
2881 f.ClientSize = new Size (300, 300);
2883 Button button1 = new Button ();
2884 f.Controls.Add (button1);
2885 button1.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
2886 button1.Location = new Point (f.ClientSize.Width - button1.Width, f.ClientSize.Height - button1.Height);
2890 Assert.AreEqual (new Point (225, 277), button1.Location, "A1");
2894 f.ResumeLayout (false);
2897 Assert.AreEqual (new Point (225, 277), button1.Location, "A2");
2903 Assert.AreEqual (new Point (225, 287), button1.Location, "A3");
2908 public void DisposeEnumerator ()
2910 // We can modify the collection while looping through it without crashing
2911 Control c = new Control ();
2913 c.Controls.Add (new Control ());
2914 c.Controls.Add (new Control ());
2916 foreach (Control c1 in c.Controls)
2917 c.Controls.Remove (c1);
2921 public void MethodSetBounds ()
2923 Control myControl = new Control();
2924 myControl.SetBounds(10, 20, 30, 40);
2925 myControl.SetBounds(50, 60, 70, 70, BoundsSpecified.Location);
2927 Assert.AreEqual (new Rectangle (50, 60, 30, 40), myControl.Bounds, "A1");
2931 public void Bug386450 ()
2933 // Should not crash. We have to check for the font object
2934 // being different, not just if they represent the same font.
2935 Form f = new Form ();
2936 Label l = new Label ();
2939 Font f1 = new Font ("Arial", 12);
2940 Font f2 = new Font ("Arial", 12);
2954 public class ControlSetTopLevelTest : TestHelper
2956 class ControlPoker : Control {
2957 public void DoSetTopLevel ()
2961 public bool DoGetTopLevel ()
2963 return GetTopLevel ();
2968 public void TestControl ()
2970 ControlPoker c = new ControlPoker ();
2973 Assert.IsTrue (c.DoGetTopLevel (), "1");
2974 Assert.IsFalse (c.Visible, "2");
2978 [ExpectedException (typeof (ArgumentException))]
2979 public void TestChildControl ()
2981 Control c1 = new Control();
2982 ControlPoker c2 = new ControlPoker ();
2984 c1.Controls.Add (c2);
2985 c2.DoSetTopLevel ();
2989 [ExpectedException (typeof (ArgumentException))]
2990 public void TestTopLevelAdd () {
2991 Form f = new Form();
2992 Form f1 = new Form();
2997 [Category ("NotWorking")]
2998 public void TestForm ()
3000 Form f = new Form ();
3001 Assert.IsFalse (f.Visible, "3");
3003 Assert.IsFalse (f.Visible, "4");
3010 public class ControlResizeLayoutTest : TestHelper
3012 class ControlPoker : Control {
3013 public void DoOnResize ()
3015 OnResize (EventArgs.Empty);
3020 string child_affected_property;
3021 void ChildLayoutEvent (object sender, LayoutEventArgs e)
3024 child_affected_property = e.AffectedProperty;
3028 string parent_affected_property;
3029 void ParentLayoutEvent (object sender, LayoutEventArgs e)
3032 parent_affected_property = e.AffectedProperty;
3034 TestHelper.RemoveWarning (parent_affected_property);
3040 Panel p = new Panel ();
3041 ControlPoker c = new ControlPoker();
3045 p.Layout += new LayoutEventHandler (ParentLayoutEvent);
3046 c.Layout += new LayoutEventHandler (ChildLayoutEvent);
3050 Assert.AreEqual (1, child_event, "1");
3051 Assert.AreEqual ("Bounds", child_affected_property, "2");
3053 Assert.AreEqual (0, parent_event, "3");
3059 [Category ("NotWorking")]
3060 public class ControlInvokeTest : TestHelper {
3063 protected override void TearDown ()
3065 if (f != null && !f.IsDisposed)
3071 public delegate void TestDelegate ();
3076 ApplicationContext control_context;
3077 bool delegateCalled = false;
3078 bool threadDied = false;
3082 void CreateControl ()
3086 f.ShowInTaskbar = false;
3092 Console.WriteLine ("f.Handle = {0}", f.Handle);
3093 Console.WriteLine ("c.Handle = {0}", c.Handle);
3095 control_context = new ApplicationContext (f);
3098 Console.WriteLine ("pulsing");
3101 Console.WriteLine ("control thread running");
3102 Application.Run (control_context);
3104 Console.WriteLine ("dying");
3107 Console.WriteLine ("pulsing again");
3110 } catch (Exception e) { Console.WriteLine (e); }
3114 public void InvokeTest ()
3118 control_t = new Thread(new ThreadStart(CreateControl));
3124 Console.WriteLine ("waiting on monitor");
3127 Console.WriteLine ("making async call");
3129 IAsyncResult result;
3130 result = c.BeginInvoke (new TestDelegate (delegate_call));
3131 c.EndInvoke (result);
3133 Assert.IsTrue (delegateCalled, "Invoke1");
3136 Assert.IsTrue (threadDied, "Invoke2");
3139 public void delegate_call () {
3141 /* invoked on control_context's thread */
3142 delegateCalled = true;
3144 Console.WriteLine ("calling Application.Exit");
3145 control_context.ExitThread ();
3146 } catch (Exception e) { Console.WriteLine (e); }
3152 public class ControlWMTest : TestHelper
3155 public void WM_PARENTNOTIFY_Test ()
3161 tester = new WMTester ();
3162 child = new Control ();
3163 tester.Controls.Add (child);
3165 tester.Visible = true;
3166 child.Visible = true;
3168 child_handle = child.Handle.ToInt32 ();
3173 msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
3175 Assert.AreEqual (1, msgs.Count, "#1");
3177 m1 = (Message) msgs [0];
3178 Assert.AreEqual (WndMsg.WM_CREATE, ((WndMsg) LowOrder (m1.WParam)), "#2");
3179 //Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam), "#3");
3180 Assert.AreEqual (child_handle, m1.LParam.ToInt32 (), "#4");
3184 msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
3185 Assert.AreEqual (2, msgs.Count, "#5");
3186 m1 = (Message) msgs [1];
3188 Assert.AreEqual (WndMsg.WM_DESTROY, ((WndMsg) LowOrder (m1.WParam)), "#6");
3189 //Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam), "#7");
3190 Assert.AreEqual (child_handle, m1.LParam.ToInt32 (), "#8");
3195 internal static int LowOrder (int param)
3197 return ((int)(short)(param & 0xffff));
3200 internal static int HighOrder (int param)
3202 return ((int)(short)(param >> 16));
3205 internal static int LowOrder (IntPtr param)
3207 return ((int)(short)(param.ToInt32 () & 0xffff));
3210 internal static int HighOrder (IntPtr param)
3212 return ((int)(short)(param.ToInt32 () >> 16));
3215 internal class WMTester : Form
3217 internal ArrayList Messages = new ArrayList ();
3219 internal bool Contains (WndMsg msg)
3221 return Contains (msg, Messages);
3224 internal bool Contains (WndMsg msg, ArrayList list)
3226 foreach (Message m in Messages)
3228 if (m.Msg == (int) msg)
3234 internal ArrayList Find (WndMsg msg)
3236 ArrayList result = new ArrayList ();
3238 foreach (Message m in Messages)
3240 if (m.Msg == (int) msg)
3246 protected override void WndProc(ref Message m)
3248 Console.WriteLine ("WndProc: " + m.ToString ());
3250 base.WndProc (ref m);
3257 public class ControlLayoutTest : TestHelper
3260 protected override void SetUp ()
3266 [Test] // bug #80456
3267 public void LayoutTest ()
3269 MockLayoutEngine layoutEngine = new MockLayoutEngine ();
3270 MockControl c = new MockControl (layoutEngine);
3271 c.Layout += new LayoutEventHandler (LayoutEvent);
3272 Assert.IsFalse (layoutEngine.LayoutInvoked, "#A1");
3273 Assert.AreEqual (0, _layoutCount, "#A2");
3275 Assert.IsTrue (layoutEngine.LayoutInvoked, "#A3");
3276 Assert.AreEqual (1, _layoutCount, "#A4");
3278 layoutEngine.Reset ();
3279 c.OverrideOnLayout = true;
3280 Assert.IsFalse (layoutEngine.LayoutInvoked, "#B1");
3282 Assert.IsFalse (layoutEngine.LayoutInvoked, "#B2");
3283 Assert.AreEqual (1, _layoutCount, "#B3");
3286 void LayoutEvent (object sender, LayoutEventArgs e)
3291 private int _layoutCount;
3293 class MockControl : Control
3295 public MockControl (LayoutEngine layoutEngine)
3297 _layoutEngine = layoutEngine;
3300 public bool OverrideOnLayout
3302 get { return _overrideOnLayout; }
3303 set { _overrideOnLayout = value; }
3306 protected override void OnLayout (LayoutEventArgs levent)
3308 if (!OverrideOnLayout)
3309 base.OnLayout (levent);
3312 public override LayoutEngine LayoutEngine {
3314 if (_layoutEngine == null)
3315 return base.LayoutEngine;
3316 return _layoutEngine;
3320 private bool _overrideOnLayout;
3321 private LayoutEngine _layoutEngine;
3324 class MockLayoutEngine : LayoutEngine
3326 public bool LayoutInvoked {
3327 get { return _layoutInvoked; }
3330 public void Reset ()
3332 _layoutInvoked = false;
3335 public override bool Layout (object container, LayoutEventArgs args)
3337 _layoutInvoked = true;
3341 private bool _layoutInvoked;