2 // Copyright (c) 2005 Novell, Inc.
5 // Ritvik Mayank (mritvik@novell.com)
9 using InvalidEnumArgumentException
= System
.ComponentModel
.InvalidEnumArgumentException
;
11 using System
.Reflection
;
12 using System
.Runtime
.Remoting
;
13 using System
.Threading
;
14 using System
.Windows
.Forms
;
16 using NUnit
.Framework
;
18 namespace MonoTests
.System
.Windows
.Forms
21 public class ControlTest
24 public static void TestAccessibility(Control c
, string Default
, string Description
, string Name
, AccessibleRole Role
)
26 Assert
.IsNotNull (c
.AccessibilityObject
, "Acc1");
27 Assert
.AreEqual (Default
, c
.AccessibleDefaultActionDescription
, "Acc2");
28 Assert
.AreEqual (Description
, c
.AccessibleDescription
, "Acc3");
29 Assert
.AreEqual (Name
, c
.AccessibleName
, "Acc4");
30 Assert
.AreEqual (Role
, c
.AccessibleRole
, "Acc5");
33 public static string TestControl(Control container
, Control start
, bool forward
) {
36 ctl
= container
.GetNextControl(start
, forward
);
47 public void CreatedTest ()
49 Control c
= new Control ();
50 Assert
.IsFalse (c
.Created
, "A1");
54 [Category ("NotWorking")]
55 public void CreatedAccessibilityTest ()
57 Control c
= new Control ();
58 Assert
.IsFalse (c
.Created
, "A1");
60 Helper
.TestAccessibility(c
, null, null, null, AccessibleRole
.Default
);
62 Assert
.IsTrue (c
.Created
, "A2");
66 Assert
.IsFalse (c
.Created
, "A3");
70 [Category ("NotWorking")]
71 public void BoundsTest ()
73 Control c
= new Control ();
74 Assert
.IsTrue (c
.Bounds
.IsEmpty
, "A1");
75 Assert
.IsTrue (c
.Size
.IsEmpty
, "A2");
76 Assert
.IsTrue (c
.ClientSize
.IsEmpty
, "A3");
77 Assert
.IsTrue (c
.ClientRectangle
.IsEmpty
, "A4");
79 Assert
.AreEqual (((IWin32Window
)c
).Handle
, c
.Handle
, "A5");
81 /* this part fails on linux because we can't allocate X windows which are 0x0,
82 and the Control bounds directly reflect the size of the X window */
84 Assert
.IsTrue (c
.Bounds
.IsEmpty
, "A6");
85 Assert
.IsTrue (c
.Size
.IsEmpty
, "A7");
86 Assert
.IsTrue (c
.ClientSize
.IsEmpty
, "A8");
87 Assert
.IsTrue (c
.ClientRectangle
.IsEmpty
, "A9");
91 public void PubPropTest()
93 Control c
= new Control();
95 Assert
.IsFalse (c
.AllowDrop
, "A1");
96 Assert
.AreEqual(AnchorStyles
.Top
| AnchorStyles
.Left
, c
.Anchor
, "A2");
98 Assert
.AreEqual ("Control", c
.BackColor
.Name
, "B1");
99 Assert
.IsNull (c
.BackgroundImage
, "B2");
100 Assert
.IsNull (c
.BindingContext
, "B3");
102 Assert
.IsFalse (c
.CanFocus
, "C1");
103 Assert
.IsTrue (c
.CanSelect
, "C2");
104 Assert
.IsFalse (c
.Capture
, "C3");
105 Assert
.IsTrue (c
.CausesValidation
, "C4");
107 Assert
.IsNotNull (c
.CompanyName
, "C7");
108 Assert
.IsNull (c
.Container
, "C8");
109 Assert
.IsFalse (c
.ContainsFocus
, "C9");
110 Assert
.IsNull (c
.ContextMenu
, "C10");
111 Assert
.AreEqual (0, c
.Controls
.Count
, "C11");
112 Assert
.IsFalse (c
.Created
, "C12");
113 Assert
.AreEqual (Cursors
.Default
, c
.Cursor
, "C13");
115 Assert
.IsNotNull(c
.DataBindings
, "D1");
116 Assert
.AreEqual("Control", Control
.DefaultBackColor
.Name
, "D2");
117 Assert
.AreEqual("ControlText", Control
.DefaultForeColor
.Name
, "D3");
118 Assert
.AreEqual(FontStyle
.Regular
, Control
.DefaultFont
.Style
, "D4");
119 Assert
.AreEqual (new Rectangle(0, 0, 0, 0), c
.DisplayRectangle
, "D5");
120 Assert
.IsFalse (c
.Disposing
, "D6");
121 Assert
.AreEqual(DockStyle
.None
, c
.Dock
, "D7");
123 Assert
.IsTrue (c
.Enabled
, "E1");
125 Assert
.IsFalse (c
.Focused
, "F1");
126 Assert
.AreEqual (FontStyle
.Regular
, c
.Font
.Style
, "F2");
127 Assert
.AreEqual (SystemColors
.ControlText
, c
.ForeColor
, "F3");
129 Assert
.IsFalse (c
.HasChildren
, "H2");
131 Assert
.AreEqual (ImeMode
.NoControl
, c
.ImeMode
, "I1");
132 Assert
.IsFalse (c
.InvokeRequired
, "I2");
133 Assert
.IsFalse (c
.IsAccessible
, "I3");
134 Assert
.IsFalse (c
.IsDisposed
, "I4");
135 Assert
.IsFalse (c
.IsHandleCreated
, "I5");
137 Assert
.AreEqual(Point
.Empty
, c
.Location
, "L2");
140 Assert
.IsTrue(c
.MaximumSize
.IsEmpty
);
141 Assert
.IsTrue(c
.MinimumSize
.IsEmpty
);
143 Assert
.AreEqual (Keys
.None
, Control
.ModifierKeys
, "M1");
144 Assert
.IsFalse (Control
.MousePosition
.IsEmpty
, "M2");
145 Assert
.AreEqual (MouseButtons
.None
, Control
.MouseButtons
, "M3");
147 Assert
.AreEqual("", c
.Name
, "N1");
148 c
.Name
= "Control Name";
149 Assert
.AreEqual("Control Name", c
.Name
, "N2");
151 Assert
.IsNull (c
.Parent
, "P1");
152 Assert
.IsNotNull (c
.ProductName
, "P2");
153 Assert
.IsTrue (c
.ProductName
!= "", "P3");
154 Assert
.IsNotNull (c
.ProductVersion
, "P4");
155 Assert
.IsTrue (c
.ProductVersion
!= "", "P5");
157 Assert
.IsFalse (c
.RecreatingHandle
, "R1");
158 Assert
.IsNull (c
.Region
, "R2");
159 Assert
.AreEqual (RightToLeft
.No
, c
.RightToLeft
, "R4");
161 Assert
.IsNull (c
.Site
, "S1");
163 Assert
.AreEqual (0, c
.TabIndex
, "T1");
164 Assert
.IsTrue (c
.TabStop
, "T2");
165 Assert
.IsNull (c
.Tag
, "T3");
166 Assert
.AreEqual ("", c
.Text
, "T4");
168 Assert
.IsTrue (c
.Visible
, "V1");
172 public void SizeChangeTest ()
174 Form f
= new Form ();
175 Control c
= new Control ();
178 c
.Resize
+= new EventHandler(SizeChangedTest_ResizeHandler
);
181 Assert
.AreEqual (true, (bool) c
.Tag
, "#1");
185 private void SizeChangedTest_ResizeHandler (object sender
, EventArgs e
)
187 Console
.WriteLine("Resized");
188 ((Control
) sender
).Tag
= false;
192 public void NegativeHeightTest ()
194 Control c
= new Control ();
195 IntPtr handle
= c
.Handle
;
196 c
.Resize
+= new EventHandler(NegativeHeightTest_ResizeHandler
);
200 Assert
.AreEqual (0, (int) c
.Tag
, "#1");
204 private void NegativeHeightTest_ResizeHandler (object sender
, EventArgs e
)
206 Control c
= (Control
) sender
;
211 public void TopLevelControlTest () {
212 Control c
= new Control ();
214 Assert
.AreEqual(null, c
.TopLevelControl
, "T1");
216 Panel p
= new Panel ();
220 Assert
.AreEqual(null, c
.TopLevelControl
, "T2");
222 Form f
= new Form ();
223 f
.ShowInTaskbar
= false;
227 Assert
.AreEqual (f
, c
.TopLevelControl
, "T3");
228 Assert
.AreEqual (f
, f
.TopLevelControl
, "T4");
232 public void RelationTest() {
239 Assert
.AreEqual(true , c1
.Visible
, "Rel1");
240 Assert
.AreEqual(false, c1
.Contains(c2
) , "Rel2");
241 Assert
.AreEqual("System.Windows.Forms.Control", c1
.ToString() , "Rel3");
244 Assert
.AreEqual(true , c2
.Visible
, "Rel4");
245 Assert
.AreEqual(true, c1
.Contains(c2
) , "Rel5");
247 c1
.Anchor
= AnchorStyles
.Top
;
249 c1
.Anchor
= AnchorStyles
.Left
;
251 Assert
.AreEqual(AnchorStyles
.Left
, c1
.Anchor
, "Rel6");
253 c1
.SetBounds(10, 20, 30, 40) ;
254 Assert
.AreEqual(new Rectangle(10, 20, 30, 40), c1
.Bounds
, "Rel7");
256 Assert
.AreEqual(c1
, c2
.Parent
, "Rel8");
260 [Category ("NotWorking")]
261 public void TabOrder() {
265 Label label1
= new Label(); // To test non-tabstop items as well
266 Label label2
= new Label();
268 GroupBox group1
= new GroupBox();
269 GroupBox group2
= new GroupBox();
270 GroupBox group3
= new GroupBox();
272 TextBox text1
= new TextBox();
274 RadioButton radio11
= new RadioButton();
275 RadioButton radio12
= new RadioButton();
276 RadioButton radio13
= new RadioButton();
277 RadioButton radio14
= new RadioButton();
278 RadioButton radio21
= new RadioButton();
279 RadioButton radio22
= new RadioButton();
280 RadioButton radio23
= new RadioButton();
281 RadioButton radio24
= new RadioButton();
282 RadioButton radio31
= new RadioButton();
283 RadioButton radio32
= new RadioButton();
284 RadioButton radio33
= new RadioButton();
285 RadioButton radio34
= new RadioButton();
288 form
.ShowInTaskbar
= false;
290 form
.ClientSize
= new Size (520, 520);
291 Assert
.AreEqual(new Size(520, 520), form
.ClientSize
, "Tab1");
293 form
.Text
= "SWF Taborder Test App Form";
294 Assert
.AreEqual("SWF Taborder Test App Form", form
.Text
, "Tab2");
296 label1
.Location
= new Point(10, 10);
297 Assert
.AreEqual(new Point(10, 10), label1
.Location
, "Tab3");
298 label1
.Text
= "Label1";
299 form
.Controls
.Add(label1
);
301 label2
.Location
= new Point(200, 10);
302 label2
.Text
= "Label2";
303 form
.Controls
.Add(label2
);
305 group1
.Text
= "Group1";
306 group2
.Text
= "Group2";
307 group3
.Text
= "Group3";
309 group1
.Size
= new Size(200, 400);
310 group2
.Size
= new Size(200, 400);
311 group3
.Size
= new Size(180, 180);
312 Assert
.AreEqual(new Size(180, 180), group3
.Size
, "Tab4");
314 group1
.Location
= new Point(10, 40);
315 group2
.Location
= new Point(220, 40);
316 group3
.Location
= new Point(10, 210);
318 group1
.TabIndex
= 30;
319 Assert
.AreEqual(30, group1
.TabIndex
, "Tab5");
320 group1
.TabStop
= true;
322 // Don't assign, test automatic assignment
323 //group2.TabIndex = 0;
324 group2
.TabStop
= true;
325 Assert
.AreEqual(0, group2
.TabIndex
, "Tab6");
327 group3
.TabIndex
= 35;
328 group3
.TabStop
= true;
330 // Test default tab index
331 Assert
.AreEqual(0, radio11
.TabIndex
, "Tab7");
333 text1
.Text
= "Edit Control";
335 radio11
.Text
= "Radio 1-1 [Tab1]";
336 radio12
.Text
= "Radio 1-2 [Tab2]";
337 radio13
.Text
= "Radio 1-3 [Tab3]";
338 radio14
.Text
= "Radio 1-4 [Tab4]";
340 radio21
.Text
= "Radio 2-1 [Tab4]";
341 radio22
.Text
= "Radio 2-2 [Tab3]";
342 radio23
.Text
= "Radio 2-3 [Tab2]";
343 radio24
.Text
= "Radio 2-4 [Tab1]";
345 radio31
.Text
= "Radio 3-1 [Tab1]";
346 radio32
.Text
= "Radio 3-2 [Tab3]";
347 radio33
.Text
= "Radio 3-3 [Tab2]";
348 radio34
.Text
= "Radio 3-4 [Tab4]";
350 // We don't assign TabIndex for radio1X; test automatic assignment
351 text1
.TabStop
= true;
352 radio11
.TabStop
= true;
354 radio21
.TabIndex
= 4;
355 radio22
.TabIndex
= 3;
356 radio23
.TabIndex
= 2;
357 radio24
.TabIndex
= 1;
358 radio24
.TabStop
= true;
360 radio31
.TabIndex
= 11;
361 radio31
.TabStop
= true;
362 radio32
.TabIndex
= 13;
363 radio33
.TabIndex
= 12;
364 radio34
.TabIndex
= 14;
366 text1
.Location
= new Point(10, 100);
368 radio11
.Location
= new Point(10, 20);
369 radio12
.Location
= new Point(10, 40);
370 radio13
.Location
= new Point(10, 60);
371 radio14
.Location
= new Point(10, 80);
373 radio21
.Location
= new Point(10, 20);
374 radio22
.Location
= new Point(10, 40);
375 radio23
.Location
= new Point(10, 60);
376 radio24
.Location
= new Point(10, 80);
378 radio31
.Location
= new Point(10, 20);
379 radio32
.Location
= new Point(10, 40);
380 radio33
.Location
= new Point(10, 60);
381 radio34
.Location
= new Point(10, 80);
383 text1
.Size
= new Size(150, text1
.PreferredHeight
);
385 radio11
.Size
= new Size(150, 20);
386 radio12
.Size
= new Size(150, 20);
387 radio13
.Size
= new Size(150, 20);
388 radio14
.Size
= new Size(150, 20);
390 radio21
.Size
= new Size(150, 20);
391 radio22
.Size
= new Size(150, 20);
392 radio23
.Size
= new Size(150, 20);
393 radio24
.Size
= new Size(150, 20);
395 radio31
.Size
= new Size(150, 20);
396 radio32
.Size
= new Size(150, 20);
397 radio33
.Size
= new Size(150, 20);
398 radio34
.Size
= new Size(150, 20);
400 group1
.Controls
.Add(text1
);
402 group1
.Controls
.Add(radio11
);
403 group1
.Controls
.Add(radio12
);
404 group1
.Controls
.Add(radio13
);
405 group1
.Controls
.Add(radio14
);
407 group2
.Controls
.Add(radio21
);
408 group2
.Controls
.Add(radio22
);
409 group2
.Controls
.Add(radio23
);
410 group2
.Controls
.Add(radio24
);
412 group3
.Controls
.Add(radio31
);
413 group3
.Controls
.Add(radio32
);
414 group3
.Controls
.Add(radio33
);
415 group3
.Controls
.Add(radio34
);
417 form
.Controls
.Add(group1
);
418 form
.Controls
.Add(group2
);
419 group2
.Controls
.Add(group3
);
421 // Perform some tests, the TabIndex stuff below will alter the outcome
422 Assert
.AreEqual(null, Helper
.TestControl(group2
, radio34
, true), "Tab8");
423 Assert
.AreEqual(31, group2
.TabIndex
, "Tab9");
425 // Does the taborder of containers and non-selectable things change behaviour?
431 // Start verification
432 Assert
.AreEqual(null, Helper
.TestControl(group2
, radio34
, true), "Tab10");
433 Assert
.AreEqual(radio24
.Text
, Helper
.TestControl(group2
, group2
, true), "Tab11");
434 Assert
.AreEqual(radio31
.Text
, Helper
.TestControl(group2
, group3
, true), "Tab12");
435 Assert
.AreEqual(null, Helper
.TestControl(group1
, radio14
, true), "Tab13");
436 Assert
.AreEqual(radio23
.Text
, Helper
.TestControl(group2
, radio24
, true), "Tab14");
437 Assert
.AreEqual(group3
.Text
, Helper
.TestControl(group2
, radio21
, true), "Tab15");
438 Assert
.AreEqual(radio13
.Text
, Helper
.TestControl(form
, radio12
, true), "Tab16");
439 Assert
.AreEqual(label2
.Text
, Helper
.TestControl(form
, radio14
, true), "Tab17");
440 Assert
.AreEqual(group1
.Text
, Helper
.TestControl(form
, radio34
, true), "Tab18");
441 Assert
.AreEqual(radio23
.Text
, Helper
.TestControl(group2
, radio24
, true), "Tab19");
444 Assert
.AreEqual(null, Helper
.TestControl(radio11
, radio21
, true), "Tab20");
445 Assert
.AreEqual(text1
.Text
, Helper
.TestControl(group1
, radio21
, true), "Tab21");
447 Assert
.AreEqual(radio14
.Text
, Helper
.TestControl(form
, label2
, false), "Tab22");
448 Assert
.AreEqual(radio21
.Text
, Helper
.TestControl(group2
, group3
, false), "Tab23");
450 Assert
.AreEqual(4, radio21
.TabIndex
, "Tab24");
451 Assert
.AreEqual(1, radio11
.TabIndex
, "Tab25");
452 Assert
.AreEqual(3, radio13
.TabIndex
, "Tab26");
453 Assert
.AreEqual(35, group3
.TabIndex
, "Tab27");
454 Assert
.AreEqual(1, group2
.TabIndex
, "Tab28");
456 Assert
.AreEqual(label1
.Text
, Helper
.TestControl(form
, form
, false), "Tab29");
457 Assert
.AreEqual(radio14
.Text
, Helper
.TestControl(group1
, group1
, false), "Tab30");
458 Assert
.AreEqual(radio34
.Text
, Helper
.TestControl(group3
, group3
, false), "Tab31");
460 Assert
.AreEqual(null, Helper
.TestControl(label1
, label1
, false), "Tab31");
461 Assert
.AreEqual(null, Helper
.TestControl(radio11
, radio21
, false), "Tab32");
466 public void ScaleTest()
468 Control r1
= new Control();
473 Assert
.AreEqual(80, r1
.Width
, "Scale1");
474 Assert
.AreEqual(40, r1
.Height
, "Scale2");
478 public void TextTest()
480 Control r1
= new Control();
482 Assert
.AreEqual("Hi" , r1
.Text
, "Text1");
485 Assert
.AreEqual("" , r1
.Text
, "Text2");
489 public void PubMethodTest7()
491 Control r1
= new Control();
492 r1
.RightToLeft
= RightToLeft
.Yes
;
493 r1
.ResetRightToLeft() ;
494 Assert
.AreEqual(RightToLeft
.No
, r1
.RightToLeft
, "#81");
495 r1
.ImeMode
= ImeMode
.Off
;
497 Assert
.AreEqual(ImeMode
.NoControl
, r1
.ImeMode
, "#82");
498 r1
.ForeColor
= SystemColors
.GrayText
;
499 r1
.ResetForeColor() ;
500 Assert
.AreEqual(SystemColors
.ControlText
, r1
.ForeColor
, "#83");
501 //r1.Font = Font.FromHdc();
503 //Assert.AreEqual(FontFamily.GenericSansSerif , r1.Font , "#83");
504 r1
.Cursor
= Cursors
.Hand
;
506 Assert
.AreEqual(Cursors
.Default
, r1
.Cursor
, "#83");
507 //r1.DataBindings = System.Windows.Forms.Binding ;
508 //r1.ResetBindings() ;
509 //Assert.AreEqual(ControlBindingsCollection , r1.DataBindings , "#83");
510 r1
.BackColor
= Color
.Black
;
511 r1
.ResetBackColor() ;
512 Assert
.AreEqual( SystemColors
.Control
, r1
.BackColor
, "#84");
513 r1
.BackColor
= Color
.Black
;
515 Assert
.AreEqual( null , r1
.Region
, "#85");
516 Rectangle M
= new Rectangle(10, 20, 30 ,40);
517 r1
.RectangleToScreen(M
) ;
518 Assert
.AreEqual( null , r1
.Region
, "#86");
523 public void ScreenClientCoords()
534 p1
= new Point (10,10);
535 p2
= l
.PointToScreen(p1
);
536 p3
= l
.PointToClient(p2
);
538 Assert
.AreEqual (p1
, p3
, "SC1");
542 public void ContainsTest ()
544 Control t
= new Control ();
545 Control s
= new Control ();
549 Assert
.AreEqual (true, t
.Contains (s
), "Con1");
550 Assert
.AreEqual (false, s
.Contains (t
), "Con2");
551 Assert
.AreEqual (false, s
.Contains (null), "Con3");
552 Assert
.AreEqual (false, t
.Contains (new Control ()), "Con4");
556 public void CreateHandleTest ()
565 parent
= new Control ();
566 child
= new Control ();
568 parent
.Visible
= true;
569 parent
.Controls
.Add (child
);
571 Assert
.IsFalse (parent
.IsHandleCreated
, "CH1");
572 Assert
.IsFalse (child
.IsHandleCreated
, "CH2");
574 parent
.CreateControl ();
575 Assert
.IsNotNull (parent
.Handle
, "CH3");
576 Assert
.IsNotNull (child
.Handle
, "CH4");
577 Assert
.IsTrue (parent
.IsHandleCreated
, "CH5");
578 Assert
.IsTrue (child
.IsHandleCreated
, "CH6");
586 // Accessing Handle Property creates the handle
588 parent
= new Control ();
589 parent
.Visible
= true;
590 child
= new Control ();
591 parent
.Controls
.Add (child
);
592 Assert
.IsFalse (parent
.IsHandleCreated
, "CH7");
593 Assert
.IsFalse (child
.IsHandleCreated
, "CH8");
594 Assert
.IsNotNull (parent
.Handle
, "CH9");
595 Assert
.IsTrue (parent
.IsHandleCreated
, "CH10");
596 Assert
.IsTrue (child
.IsHandleCreated
, "CH11");
606 [Category ("NotWorking")]
607 public void CreateHandleTest2 ()
609 // This should eventually test all operations
610 // that can be performed on a control (within
612 Control c
= new Control ();
614 Assert
.IsFalse (c
.IsHandleCreated
, "0");
617 Assert
.IsFalse (c
.IsHandleCreated
, "1");
620 Assert
.IsFalse (c
.IsHandleCreated
, "2");
623 Assert
.IsFalse (c
.IsHandleCreated
, "3");
626 Assert
.IsFalse (c
.IsHandleCreated
, "5");
629 Assert
.IsFalse (c
.IsHandleCreated
, "6");
631 c
.Location
= new Point (1,1);
632 Assert
.IsFalse (c
.IsHandleCreated
, "7");
634 c
.Region
= new Region ();
635 Assert
.IsFalse (c
.IsHandleCreated
, "8");
637 c
.Size
= new Size (100, 100);
638 Assert
.IsFalse (c
.IsHandleCreated
, "9");
641 Assert
.IsFalse (c
.IsHandleCreated
, "10");
643 c
.Visible
= !c
.Visible
;
644 Assert
.IsFalse (c
.IsHandleCreated
, "11");
648 public void CreateGraphicsTest ()
654 Control c
= new Control ();
655 c
.SetBounds (0,0, 20, 20);
656 g
= c
.CreateGraphics ();
657 Assert
.IsNotNull (g
, "Graph1");
666 bool delegateCalled
= false;
667 public delegate void TestDelegate ();
669 public void delegate_call () {
670 delegateCalled
= true;
674 [ExpectedException(typeof(InvalidOperationException
))]
675 public void InvokeException1 () {
676 Control c
= new Control ();
679 result
= c
.BeginInvoke (new TestDelegate (delegate_call
));
680 c
.EndInvoke (result
);
684 public void FindFormTest () {
685 Form f
= new Form ();
687 f
.ShowInTaskbar
= false;
692 f
.Controls
.Add (c
= new Control ());
693 Assert
.AreEqual (f
.Name
, c
.FindForm ().Name
, "Find1");
695 f
.Controls
.Remove (c
);
697 GroupBox g
= new GroupBox ();
702 Assert
.AreEqual (f
.Name
, f
.FindForm ().Name
, "Find2");
704 g
.Controls
.Remove (c
);
705 Assert
.IsNull(c
.FindForm (), "Find3");
716 public void FocusTest ()
719 Button c
= null, d
= null;
723 f
.ShowInTaskbar
= false;
733 Assert
.IsTrue (c
.CanFocus
, "Focus1");
734 Assert
.IsFalse (c
.Focused
, "Focus2");
736 Assert
.IsTrue (c
.Focused
, "Focus3");
738 Assert
.IsFalse (d
.Focused
, "Focus4");
742 Assert
.IsTrue (d
.Focused
, "Focus5");
743 Assert
.IsFalse (c
.Focused
, "Focus6");
746 Assert
.IsFalse (c
.Focused
, "Focus7");
758 public void FromHandleTest ()
772 Assert
.AreEqual (c1
.Name
, Control
.FromHandle (c1
.Handle
).Name
, "Handle1");
773 Assert
.IsNull (Control
.FromHandle (IntPtr
.Zero
), "Handle2");
776 Assert
.AreEqual (c1
.Name
, Control
.FromChildHandle (c1
.Handle
).Name
, "Handle3");
777 Assert
.IsNull (Control
.FromChildHandle (IntPtr
.Zero
), "Handle4");
790 public void GetChildAtPointTest ()
792 Control c
= null, d
= null, e
= null;
797 c
.SetBounds (0, 0, 100, 100);
801 d
.SetBounds (10, 10, 40, 40);
806 e
.SetBounds (55, 55, 10, 10);
808 Control l
= c
.GetChildAtPoint (new Point (15, 15));
809 Assert
.AreEqual (d
.Name
, l
.Name
, "Child1");
810 Assert
.IsFalse (e
.Name
== l
.Name
, "Child2");
812 l
= c
.GetChildAtPoint (new Point (57, 57));
813 Assert
.IsNull (l
, "Child3");
815 l
= c
.GetChildAtPoint (new Point (10, 10));
816 Assert
.AreEqual (d
.Name
, l
.Name
, "Child4");
818 // GetChildAtPointSkip is not implemented and the following test is breaking for Net_2_0 profile
820 // c.Controls.Add (e);
821 // e.Visible = false;
822 // l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
823 // Assert.IsNull (l, "Child5");
826 // l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
827 // Assert.AreSame (e.Name, l.Name, "Child6");
838 public class LayoutTestControl
: Control
{
839 public int LayoutCount
;
841 public LayoutTestControl () : base() {
845 protected override void OnLayout(LayoutEventArgs levent
) {
847 base.OnLayout (levent
);
852 public void LayoutTest() {
855 c
= new LayoutTestControl();
862 c
.ResumeLayout(true);
864 c
.ResumeLayout(true);
866 c
.ResumeLayout(true);
868 c
.ResumeLayout(true);
870 c
.ResumeLayout(true);
872 c
.ResumeLayout(true);
874 c
.ResumeLayout(true);
879 Assert
.AreEqual(5, c
.LayoutCount
, "Layout Suspend/Resume locking does not bottom out at 0");
883 [ExpectedException(typeof(ArgumentException
))]
884 public void TransparentBackgroundTest1() {
888 c
.BackColor
= Color
.Transparent
;
892 public void TransparentBackgroundTest2() {
896 c
.BackColor
= Color
.Transparent
;
897 Assert
.AreEqual(Color
.Transparent
, c
.BackColor
, "Transparent background not set");
901 public void TransparentBackgroundTest3() {
905 c
.BackColor
= Color
.Empty
;
906 Assert
.AreEqual(Control
.DefaultBackColor
, c
.BackColor
, "Setting empty color failed");
910 public void Dock_Value_Invalid ()
912 Control c
= new Control ();
914 c
.Dock
= (DockStyle
) 666;
916 } catch (InvalidEnumArgumentException ex
) {
917 Assert
.AreEqual (typeof (InvalidEnumArgumentException
), ex
.GetType (), "#2");
918 Assert
.IsNotNull (ex
.Message
, "#3");
919 Assert
.IsNotNull (ex
.ParamName
, "#4");
920 Assert
.AreEqual ("value", ex
.ParamName
, "#5");
921 Assert
.IsNull (ex
.InnerException
, "#6");
926 public void EnabledTest1() {
931 grandma
= new Control();
932 parent
= new Control();
933 child
= new Control();
935 grandma
.Controls
.Add(parent
);
936 parent
.Controls
.Add(child
);
937 grandma
.Enabled
= false;
938 Assert
.AreEqual(grandma
.Enabled
, child
.Enabled
, "Child did not inherit disabled state");
941 int EnabledCalledCount
= 0;
942 private void EnabledTest2EnabledChanged(object sender
, EventArgs e
) {
943 EnabledCalledCount
++;
947 public void EnabledTest2() {
948 // Check nesting of enabled calls
949 // OnEnabled is not called for disabled child controls
954 EnabledCalledCount
= 0;
956 grandma
= new Control();
957 parent
= new Control();
958 child
= new Control();
959 child
.EnabledChanged
+= new EventHandler(EnabledTest2EnabledChanged
);
961 grandma
.Controls
.Add(parent
);
962 parent
.Controls
.Add(child
);
963 grandma
.Enabled
= false;
965 Assert
.AreEqual(1, EnabledCalledCount
, "Child Enabled Event not properly fired");
966 grandma
.Enabled
= true;
967 Assert
.AreEqual(2, EnabledCalledCount
, "Child Enabled Event not properly fired");
968 child
.Enabled
= false;
969 grandma
.Enabled
= false;
970 Assert
.AreEqual(3, EnabledCalledCount
, "Child Enabled Event not properly fired");
974 public void ControlsRemoveNullTest ()
976 Control c
= new Control ();
977 c
.Controls
.Remove (null);
981 public void ControlsAddNullTest ()
983 Control c
= new Control ();
984 c
.Controls
.Add (null);
988 [ExpectedException (typeof (ArgumentNullException
))]
989 public void ControlsSetChildIndexNullTest ()
991 Control c
= new Control ();
992 c
.Controls
.SetChildIndex (null, 1);
996 [ExpectedException (typeof (ArgumentNullException
))]
997 public void ControlsAddRangeNullTest ()
999 Control c
= new Control ();
1000 c
.Controls
.AddRange (null);
1004 public void ControlsAddRangeNullElementTest ()
1006 Control c
= new Control ();
1007 Control
[] subcontrols
= new Control
[2];
1008 subcontrols
[0] = new Control ();
1009 subcontrols
[1] = null;
1011 c
.Controls
.AddRange (subcontrols
);
1016 public class ControlInvokeTest
{
1017 public delegate void TestDelegate ();
1022 ApplicationContext control_context
;
1023 bool delegateCalled
= false;
1027 void CreateControl ()
1030 f
.ShowInTaskbar
= false;
1036 Console
.WriteLine ("f.Handle = {0}", f
.Handle
);
1037 Console
.WriteLine ("c.Handle = {0}", c
.Handle
);
1039 control_context
= new ApplicationContext (f
);
1042 Console
.WriteLine ("pulsing");
1045 Console
.WriteLine ("control thread running");
1046 Application
.Run (control_context
);
1051 public void InvokeTest ()
1055 control_t
= new Thread(new ThreadStart(CreateControl
));
1061 Console
.WriteLine ("waiting on monitor");
1064 Console
.WriteLine ("making async call");
1066 IAsyncResult result
;
1067 result
= c
.BeginInvoke (new TestDelegate (delegate_call
));
1068 c
.EndInvoke (result
);
1070 Assert
.AreEqual (true, delegateCalled
, "Invoke1");
1073 public void delegate_call () {
1074 /* invoked on control_context's thread */
1075 delegateCalled
= true;
1077 Application
.Exit ();