2 // Copyright (c) 2005 Novell, Inc.
5 // Ritvik Mayank (mritvik@novell.com)
9 using System.Collections;
10 using InvalidEnumArgumentException = System.ComponentModel.InvalidEnumArgumentException;
12 using System.Reflection;
13 using System.Runtime.Remoting;
14 using System.Threading;
15 using System.Windows.Forms;
17 using NUnit.Framework;
19 namespace MonoTests.System.Windows.Forms
22 public class ControlTest
25 public static void TestAccessibility(Control c, string Default, string Description, string Name, AccessibleRole Role)
27 Assert.IsNotNull (c.AccessibilityObject, "Acc1");
28 Assert.AreEqual (Default, c.AccessibleDefaultActionDescription, "Acc2");
29 Assert.AreEqual (Description, c.AccessibleDescription, "Acc3");
30 Assert.AreEqual (Name, c.AccessibleName, "Acc4");
31 Assert.AreEqual (Role, c.AccessibleRole, "Acc5");
34 public static string TestControl(Control container, Control start, bool forward) {
37 ctl = container.GetNextControl(start, forward);
48 public void CreatedTest ()
50 Control c = new Control ();
51 Assert.IsFalse (c.Created, "A1");
55 [Category ("NotWorking")]
56 public void CreatedAccessibilityTest ()
58 Control c = new Control ();
59 Assert.IsFalse (c.Created, "A1");
61 Helper.TestAccessibility(c, null, null, null, AccessibleRole.Default);
63 Assert.IsTrue (c.Created, "A2");
67 Assert.IsFalse (c.Created, "A3");
71 [Category ("NotWorking")]
72 public void BoundsTest ()
74 Control c = new Control ();
75 Assert.IsTrue (c.Bounds.IsEmpty, "A1");
76 Assert.IsTrue (c.Size.IsEmpty, "A2");
77 Assert.IsTrue (c.ClientSize.IsEmpty, "A3");
78 Assert.IsTrue (c.ClientRectangle.IsEmpty, "A4");
80 Assert.AreEqual (((IWin32Window)c).Handle, c.Handle, "A5");
82 /* this part fails on linux because we can't allocate X windows which are 0x0,
83 and the Control bounds directly reflect the size of the X window */
85 Assert.IsTrue (c.Bounds.IsEmpty, "A6");
86 Assert.IsTrue (c.Size.IsEmpty, "A7");
87 Assert.IsTrue (c.ClientSize.IsEmpty, "A8");
88 Assert.IsTrue (c.ClientRectangle.IsEmpty, "A9");
92 public void PubPropTest()
94 Control c = new Control();
96 Assert.IsFalse (c.AllowDrop , "A1");
97 Assert.AreEqual(AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "A2");
99 Assert.AreEqual ("Control", c.BackColor.Name , "B1");
100 Assert.IsNull (c.BackgroundImage, "B2");
101 Assert.IsNull (c.BindingContext, "B3");
103 Assert.IsFalse (c.CanFocus, "C1");
104 Assert.IsTrue (c.CanSelect, "C2");
105 Assert.IsFalse (c.Capture, "C3");
106 Assert.IsTrue (c.CausesValidation, "C4");
108 Assert.IsNotNull (c.CompanyName, "C7");
109 Assert.IsNull (c.Container, "C8");
110 Assert.IsFalse (c.ContainsFocus, "C9");
111 Assert.IsNull (c.ContextMenu, "C10");
112 Assert.AreEqual (0, c.Controls.Count, "C11");
113 Assert.IsFalse (c.Created, "C12");
114 Assert.AreEqual (Cursors.Default, c.Cursor, "C13");
116 Assert.IsNotNull(c.DataBindings, "D1");
117 Assert.AreEqual("Control", Control.DefaultBackColor.Name, "D2");
118 Assert.AreEqual("ControlText", Control.DefaultForeColor.Name, "D3");
119 Assert.AreEqual(FontStyle.Regular, Control.DefaultFont.Style, "D4");
120 Assert.AreEqual (new Rectangle(0, 0, 0, 0), c.DisplayRectangle , "D5");
121 Assert.IsFalse (c.Disposing, "D6");
122 Assert.AreEqual(DockStyle.None, c.Dock, "D7");
124 Assert.IsTrue (c.Enabled, "E1");
126 Assert.IsFalse (c.Focused, "F1");
127 Assert.AreEqual (FontStyle.Regular, c.Font.Style, "F2");
128 Assert.AreEqual (SystemColors.ControlText, c.ForeColor, "F3");
130 Assert.IsFalse (c.HasChildren, "H2");
132 Assert.AreEqual (ImeMode.NoControl, c.ImeMode, "I1");
133 Assert.IsFalse (c.InvokeRequired, "I2");
134 Assert.IsFalse (c.IsAccessible, "I3");
135 Assert.IsFalse (c.IsDisposed, "I4");
136 Assert.IsFalse (c.IsHandleCreated, "I5");
138 Assert.AreEqual(Point.Empty, c.Location, "L2");
141 Assert.IsTrue(c.MaximumSize.IsEmpty);
142 Assert.IsTrue(c.MinimumSize.IsEmpty);
144 Assert.AreEqual (Keys.None, Control.ModifierKeys, "M1");
145 Assert.IsFalse (Control.MousePosition.IsEmpty, "M2");
146 Assert.AreEqual (MouseButtons.None, Control.MouseButtons, "M3");
148 Assert.AreEqual("", c.Name, "N1");
149 c.Name = "Control Name";
150 Assert.AreEqual("Control Name", c.Name, "N2");
152 Assert.IsNull (c.Parent, "P1");
153 Assert.IsNotNull (c.ProductName, "P2");
154 Assert.IsTrue (c.ProductName != "", "P3");
155 Assert.IsNotNull (c.ProductVersion, "P4");
156 Assert.IsTrue (c.ProductVersion != "", "P5");
158 Assert.IsFalse (c.RecreatingHandle, "R1");
159 Assert.IsNull (c.Region, "R2");
160 Assert.AreEqual (RightToLeft.No, c.RightToLeft, "R4");
162 Assert.IsNull (c.Site, "S1");
164 Assert.AreEqual (0, c.TabIndex , "T1");
165 Assert.IsTrue (c.TabStop, "T2");
166 Assert.IsNull (c.Tag, "T3");
167 Assert.AreEqual ("", c.Text, "T4");
169 Assert.IsTrue (c.Visible, "V1");
173 public void SizeChangeTest ()
175 Form f = new Form ();
176 Control c = new Control ();
179 c.Resize += new EventHandler(SizeChangedTest_ResizeHandler);
182 Assert.AreEqual (true, (bool) c.Tag, "#1");
186 private void SizeChangedTest_ResizeHandler (object sender, EventArgs e)
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");
202 Assert.AreEqual (handle, handle, "Removes warning.");
205 private void NegativeHeightTest_ResizeHandler (object sender, EventArgs e)
207 Control c = (Control) sender;
212 public void TopLevelControlTest () {
213 Control c = new Control ();
215 Assert.AreEqual(null, c.TopLevelControl, "T1");
217 Panel p = new Panel ();
221 Assert.AreEqual(null, c.TopLevelControl, "T2");
223 Form f = new Form ();
224 f.ShowInTaskbar = false;
228 Assert.AreEqual (f, c.TopLevelControl, "T3");
229 Assert.AreEqual (f, f.TopLevelControl, "T4");
233 public void RelationTest() {
240 Assert.AreEqual(true , c1.Visible , "Rel1");
241 Assert.AreEqual(false, c1.Contains(c2) , "Rel2");
242 Assert.AreEqual("System.Windows.Forms.Control", c1.ToString() , "Rel3");
245 Assert.AreEqual(true , c2.Visible , "Rel4");
246 Assert.AreEqual(true, c1.Contains(c2) , "Rel5");
248 c1.Anchor = AnchorStyles.Top;
250 c1.Anchor = AnchorStyles.Left ;
252 Assert.AreEqual(AnchorStyles.Left , c1.Anchor, "Rel6");
254 c1.SetBounds(10, 20, 30, 40) ;
255 Assert.AreEqual(new Rectangle(10, 20, 30, 40), c1.Bounds, "Rel7");
257 Assert.AreEqual(c1, c2.Parent, "Rel8");
261 [Category ("NotWorking")]
262 public void TabOrder() {
266 Label label1 = new Label(); // To test non-tabstop items as well
267 Label label2 = new Label();
269 GroupBox group1 = new GroupBox();
270 GroupBox group2 = new GroupBox();
271 GroupBox group3 = new GroupBox();
273 TextBox text1 = new TextBox();
275 RadioButton radio11 = new RadioButton();
276 RadioButton radio12 = new RadioButton();
277 RadioButton radio13 = new RadioButton();
278 RadioButton radio14 = new RadioButton();
279 RadioButton radio21 = new RadioButton();
280 RadioButton radio22 = new RadioButton();
281 RadioButton radio23 = new RadioButton();
282 RadioButton radio24 = new RadioButton();
283 RadioButton radio31 = new RadioButton();
284 RadioButton radio32 = new RadioButton();
285 RadioButton radio33 = new RadioButton();
286 RadioButton radio34 = new RadioButton();
289 form.ShowInTaskbar = false;
291 form.ClientSize = new Size (520, 520);
292 Assert.AreEqual(new Size(520, 520), form.ClientSize, "Tab1");
294 form.Text = "SWF Taborder Test App Form";
295 Assert.AreEqual("SWF Taborder Test App Form", form.Text, "Tab2");
297 label1.Location = new Point(10, 10);
298 Assert.AreEqual(new Point(10, 10), label1.Location, "Tab3");
299 label1.Text = "Label1";
300 form.Controls.Add(label1);
302 label2.Location = new Point(200, 10);
303 label2.Text = "Label2";
304 form.Controls.Add(label2);
306 group1.Text = "Group1";
307 group2.Text = "Group2";
308 group3.Text = "Group3";
310 group1.Size = new Size(200, 400);
311 group2.Size = new Size(200, 400);
312 group3.Size = new Size(180, 180);
313 Assert.AreEqual(new Size(180, 180), group3.Size, "Tab4");
315 group1.Location = new Point(10, 40);
316 group2.Location = new Point(220, 40);
317 group3.Location = new Point(10, 210);
319 group1.TabIndex = 30;
320 Assert.AreEqual(30, group1.TabIndex, "Tab5");
321 group1.TabStop = true;
323 // Don't assign, test automatic assignment
324 //group2.TabIndex = 0;
325 group2.TabStop = true;
326 Assert.AreEqual(0, group2.TabIndex, "Tab6");
328 group3.TabIndex = 35;
329 group3.TabStop = true;
331 // Test default tab index
332 Assert.AreEqual(0, radio11.TabIndex, "Tab7");
334 text1.Text = "Edit Control";
336 radio11.Text = "Radio 1-1 [Tab1]";
337 radio12.Text = "Radio 1-2 [Tab2]";
338 radio13.Text = "Radio 1-3 [Tab3]";
339 radio14.Text = "Radio 1-4 [Tab4]";
341 radio21.Text = "Radio 2-1 [Tab4]";
342 radio22.Text = "Radio 2-2 [Tab3]";
343 radio23.Text = "Radio 2-3 [Tab2]";
344 radio24.Text = "Radio 2-4 [Tab1]";
346 radio31.Text = "Radio 3-1 [Tab1]";
347 radio32.Text = "Radio 3-2 [Tab3]";
348 radio33.Text = "Radio 3-3 [Tab2]";
349 radio34.Text = "Radio 3-4 [Tab4]";
351 // We don't assign TabIndex for radio1X; test automatic assignment
352 text1.TabStop = true;
353 radio11.TabStop = true;
355 radio21.TabIndex = 4;
356 radio22.TabIndex = 3;
357 radio23.TabIndex = 2;
358 radio24.TabIndex = 1;
359 radio24.TabStop = true;
361 radio31.TabIndex = 11;
362 radio31.TabStop = true;
363 radio32.TabIndex = 13;
364 radio33.TabIndex = 12;
365 radio34.TabIndex = 14;
367 text1.Location = new Point(10, 100);
369 radio11.Location = new Point(10, 20);
370 radio12.Location = new Point(10, 40);
371 radio13.Location = new Point(10, 60);
372 radio14.Location = new Point(10, 80);
374 radio21.Location = new Point(10, 20);
375 radio22.Location = new Point(10, 40);
376 radio23.Location = new Point(10, 60);
377 radio24.Location = new Point(10, 80);
379 radio31.Location = new Point(10, 20);
380 radio32.Location = new Point(10, 40);
381 radio33.Location = new Point(10, 60);
382 radio34.Location = new Point(10, 80);
384 text1.Size = new Size(150, text1.PreferredHeight);
386 radio11.Size = new Size(150, 20);
387 radio12.Size = new Size(150, 20);
388 radio13.Size = new Size(150, 20);
389 radio14.Size = new Size(150, 20);
391 radio21.Size = new Size(150, 20);
392 radio22.Size = new Size(150, 20);
393 radio23.Size = new Size(150, 20);
394 radio24.Size = new Size(150, 20);
396 radio31.Size = new Size(150, 20);
397 radio32.Size = new Size(150, 20);
398 radio33.Size = new Size(150, 20);
399 radio34.Size = new Size(150, 20);
401 group1.Controls.Add(text1);
403 group1.Controls.Add(radio11);
404 group1.Controls.Add(radio12);
405 group1.Controls.Add(radio13);
406 group1.Controls.Add(radio14);
408 group2.Controls.Add(radio21);
409 group2.Controls.Add(radio22);
410 group2.Controls.Add(radio23);
411 group2.Controls.Add(radio24);
413 group3.Controls.Add(radio31);
414 group3.Controls.Add(radio32);
415 group3.Controls.Add(radio33);
416 group3.Controls.Add(radio34);
418 form.Controls.Add(group1);
419 form.Controls.Add(group2);
420 group2.Controls.Add(group3);
422 // Perform some tests, the TabIndex stuff below will alter the outcome
423 Assert.AreEqual(null, Helper.TestControl(group2, radio34, true), "Tab8");
424 Assert.AreEqual(31, group2.TabIndex, "Tab9");
426 // Does the taborder of containers and non-selectable things change behaviour?
432 // Start verification
433 Assert.AreEqual(null, Helper.TestControl(group2, radio34, true), "Tab10");
434 Assert.AreEqual(radio24.Text, Helper.TestControl(group2, group2, true), "Tab11");
435 Assert.AreEqual(radio31.Text, Helper.TestControl(group2, group3, true), "Tab12");
436 Assert.AreEqual(null, Helper.TestControl(group1, radio14, true), "Tab13");
437 Assert.AreEqual(radio23.Text, Helper.TestControl(group2, radio24, true), "Tab14");
438 Assert.AreEqual(group3.Text, Helper.TestControl(group2, radio21, true), "Tab15");
439 Assert.AreEqual(radio13.Text, Helper.TestControl(form, radio12, true), "Tab16");
440 Assert.AreEqual(label2.Text, Helper.TestControl(form, radio14, true), "Tab17");
441 Assert.AreEqual(group1.Text, Helper.TestControl(form, radio34, true), "Tab18");
442 Assert.AreEqual(radio23.Text, Helper.TestControl(group2, radio24, true), "Tab19");
445 Assert.AreEqual(null, Helper.TestControl(radio11, radio21, true), "Tab20");
446 Assert.AreEqual(text1.Text, Helper.TestControl(group1, radio21, true), "Tab21");
448 Assert.AreEqual(radio14.Text, Helper.TestControl(form, label2, false), "Tab22");
449 Assert.AreEqual(radio21.Text, Helper.TestControl(group2, group3, false), "Tab23");
451 Assert.AreEqual(4, radio21.TabIndex, "Tab24");
452 Assert.AreEqual(1, radio11.TabIndex, "Tab25");
453 Assert.AreEqual(3, radio13.TabIndex, "Tab26");
454 Assert.AreEqual(35, group3.TabIndex, "Tab27");
455 Assert.AreEqual(1, group2.TabIndex, "Tab28");
457 Assert.AreEqual(label1.Text, Helper.TestControl(form, form, false), "Tab29");
458 Assert.AreEqual(radio14.Text, Helper.TestControl(group1, group1, false), "Tab30");
459 Assert.AreEqual(radio34.Text, Helper.TestControl(group3, group3, false), "Tab31");
461 Assert.AreEqual(null, Helper.TestControl(label1, label1, false), "Tab31");
462 Assert.AreEqual(null, Helper.TestControl(radio11, radio21, false), "Tab32");
467 public void ScaleTest()
469 Control r1 = new Control();
474 Assert.AreEqual(80, r1.Width, "Scale1");
475 Assert.AreEqual(40, r1.Height, "Scale2");
479 public void TextTest()
481 Control r1 = new Control();
483 Assert.AreEqual("Hi" , r1.Text , "Text1");
486 Assert.AreEqual("" , r1.Text , "Text2");
490 public void PubMethodTest7()
492 Control r1 = new Control();
493 r1.RightToLeft = RightToLeft.Yes ;
494 r1.ResetRightToLeft() ;
495 Assert.AreEqual(RightToLeft.No , r1.RightToLeft , "#81");
496 r1.ImeMode = ImeMode.Off ;
498 Assert.AreEqual(ImeMode.NoControl , r1.ImeMode , "#82");
499 r1.ForeColor= SystemColors.GrayText ;
500 r1.ResetForeColor() ;
501 Assert.AreEqual(SystemColors.ControlText , r1.ForeColor , "#83");
502 //r1.Font = Font.FromHdc();
504 //Assert.AreEqual(FontFamily.GenericSansSerif , r1.Font , "#83");
505 r1.Cursor = Cursors.Hand ;
507 Assert.AreEqual(Cursors.Default , r1.Cursor , "#83");
508 //r1.DataBindings = System.Windows.Forms.Binding ;
509 //r1.ResetBindings() ;
510 //Assert.AreEqual(ControlBindingsCollection , r1.DataBindings , "#83");
511 r1.BackColor = Color.Black ;
512 r1.ResetBackColor() ;
513 Assert.AreEqual( SystemColors.Control , r1.BackColor , "#84");
514 r1.BackColor = Color.Black ;
516 Assert.AreEqual( null , r1.Region , "#85");
517 Rectangle M = new Rectangle(10, 20, 30 ,40);
518 r1.RectangleToScreen(M) ;
519 Assert.AreEqual( null , r1.Region , "#86");
524 public void ScreenClientCoords()
535 p1 = new Point (10,10);
536 p2 = l.PointToScreen(p1);
537 p3 = l.PointToClient(p2);
539 Assert.AreEqual (p1, p3, "SC1");
543 public void ContainsTest ()
545 Control t = new Control ();
546 Control s = new Control ();
550 Assert.AreEqual (true, t.Contains (s), "Con1");
551 Assert.AreEqual (false, s.Contains (t), "Con2");
552 Assert.AreEqual (false, s.Contains (null), "Con3");
553 Assert.AreEqual (false, t.Contains (new Control ()), "Con4");
557 public void CreateHandleTest ()
566 parent = new Control ();
567 child = new Control ();
569 parent.Visible = true;
570 parent.Controls.Add (child);
572 Assert.IsFalse (parent.IsHandleCreated, "CH1");
573 Assert.IsFalse (child.IsHandleCreated, "CH2");
575 parent.CreateControl ();
576 Assert.IsNotNull (parent.Handle, "CH3");
577 Assert.IsNotNull (child.Handle, "CH4");
578 Assert.IsTrue (parent.IsHandleCreated, "CH5");
579 Assert.IsTrue (child.IsHandleCreated, "CH6");
587 // Accessing Handle Property creates the handle
589 parent = new Control ();
590 parent.Visible = true;
591 child = new Control ();
592 parent.Controls.Add (child);
593 Assert.IsFalse (parent.IsHandleCreated, "CH7");
594 Assert.IsFalse (child.IsHandleCreated, "CH8");
595 Assert.IsNotNull (parent.Handle, "CH9");
596 Assert.IsTrue (parent.IsHandleCreated, "CH10");
597 Assert.IsTrue (child.IsHandleCreated, "CH11");
607 [Category ("NotWorking")]
608 public void CreateHandleTest2 ()
610 // This should eventually test all operations
611 // that can be performed on a control (within
613 Control c = new Control ();
615 Assert.IsFalse (c.IsHandleCreated, "0");
618 Assert.IsFalse (c.IsHandleCreated, "1");
621 Assert.IsFalse (c.IsHandleCreated, "2");
624 Assert.IsFalse (c.IsHandleCreated, "3");
627 Assert.IsFalse (c.IsHandleCreated, "5");
630 Assert.IsFalse (c.IsHandleCreated, "6");
632 c.Location = new Point (1,1);
633 Assert.IsFalse (c.IsHandleCreated, "7");
635 c.Region = new Region ();
636 Assert.IsFalse (c.IsHandleCreated, "8");
638 c.Size = new Size (100, 100);
639 Assert.IsFalse (c.IsHandleCreated, "9");
642 Assert.IsFalse (c.IsHandleCreated, "10");
644 c.Visible = !c.Visible;
645 Assert.IsFalse (c.IsHandleCreated, "11");
649 public void CreateGraphicsTest ()
655 Control c = new Control ();
656 c.SetBounds (0,0, 20, 20);
657 g = c.CreateGraphics ();
658 Assert.IsNotNull (g, "Graph1");
667 bool delegateCalled = false;
668 public delegate void TestDelegate ();
670 public void delegate_call () {
671 delegateCalled = true;
675 [ExpectedException(typeof(InvalidOperationException))]
676 public void InvokeException1 () {
677 Control c = new Control ();
680 result = c.BeginInvoke (new TestDelegate (delegate_call));
681 c.EndInvoke (result);
685 public void FindFormTest () {
686 Form f = new Form ();
688 f.ShowInTaskbar = false;
693 f.Controls.Add (c = new Control ());
694 Assert.AreEqual (f.Name, c.FindForm ().Name, "Find1");
696 f.Controls.Remove (c);
698 GroupBox g = new GroupBox ();
703 Assert.AreEqual (f.Name, f.FindForm ().Name, "Find2");
705 g.Controls.Remove (c);
706 Assert.IsNull(c.FindForm (), "Find3");
717 public void FocusTest ()
720 Button c = null, d = null;
724 f.ShowInTaskbar = false;
734 Assert.IsTrue (c.CanFocus, "Focus1");
735 Assert.IsFalse (c.Focused, "Focus2");
737 Assert.IsTrue (c.Focused, "Focus3");
739 Assert.IsFalse (d.Focused, "Focus4");
743 Assert.IsTrue (d.Focused, "Focus5");
744 Assert.IsFalse (c.Focused, "Focus6");
747 Assert.IsFalse (c.Focused, "Focus7");
759 public void FromHandleTest ()
773 Assert.AreEqual (c1.Name, Control.FromHandle (c1.Handle).Name, "Handle1");
774 Assert.IsNull (Control.FromHandle (IntPtr.Zero), "Handle2");
777 Assert.AreEqual (c1.Name, Control.FromChildHandle (c1.Handle).Name, "Handle3");
778 Assert.IsNull (Control.FromChildHandle (IntPtr.Zero), "Handle4");
791 public void GetChildAtPointTest ()
793 Control c = null, d = null, e = null;
798 c.SetBounds (0, 0, 100, 100);
802 d.SetBounds (10, 10, 40, 40);
807 e.SetBounds (55, 55, 10, 10);
809 Control l = c.GetChildAtPoint (new Point (15, 15));
810 Assert.AreEqual (d.Name, l.Name, "Child1");
811 Assert.IsFalse (e.Name == l.Name, "Child2");
813 l = c.GetChildAtPoint (new Point (57, 57));
814 Assert.IsNull (l, "Child3");
816 l = c.GetChildAtPoint (new Point (10, 10));
817 Assert.AreEqual (d.Name, l.Name, "Child4");
819 // GetChildAtPointSkip is not implemented and the following test is breaking for Net_2_0 profile
821 // c.Controls.Add (e);
822 // e.Visible = false;
823 // l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
824 // Assert.IsNull (l, "Child5");
827 // l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
828 // Assert.AreSame (e.Name, l.Name, "Child6");
839 public class LayoutTestControl : Control {
840 public int LayoutCount;
842 public LayoutTestControl () : base() {
846 protected override void OnLayout(LayoutEventArgs levent) {
848 base.OnLayout (levent);
853 public void LayoutTest() {
856 c = new LayoutTestControl();
863 c.ResumeLayout(true);
865 c.ResumeLayout(true);
867 c.ResumeLayout(true);
869 c.ResumeLayout(true);
871 c.ResumeLayout(true);
873 c.ResumeLayout(true);
875 c.ResumeLayout(true);
880 Assert.AreEqual(5, c.LayoutCount, "Layout Suspend/Resume locking does not bottom out at 0");
884 [ExpectedException(typeof(ArgumentException))]
885 public void TransparentBackgroundTest1() {
889 c.BackColor = Color.Transparent;
893 public void TransparentBackgroundTest2() {
897 c.BackColor = Color.Transparent;
898 Assert.AreEqual(Color.Transparent, c.BackColor, "Transparent background not set");
902 public void TransparentBackgroundTest3() {
906 c.BackColor = Color.Empty;
907 Assert.AreEqual(Control.DefaultBackColor, c.BackColor, "Setting empty color failed");
911 public void Dock_Value_Invalid ()
913 Control c = new Control ();
915 c.Dock = (DockStyle) 666;
917 } catch (InvalidEnumArgumentException ex) {
918 Assert.AreEqual (typeof (InvalidEnumArgumentException), ex.GetType (), "#2");
919 Assert.IsNotNull (ex.Message, "#3");
920 Assert.IsNotNull (ex.ParamName, "#4");
921 Assert.AreEqual ("value", ex.ParamName, "#5");
922 Assert.IsNull (ex.InnerException, "#6");
927 public void EnabledTest1() {
932 grandma = new Control();
933 parent = new Control();
934 child = new Control();
936 grandma.Controls.Add(parent);
937 parent.Controls.Add(child);
938 grandma.Enabled = false;
939 Assert.AreEqual(grandma.Enabled, child.Enabled, "Child did not inherit disabled state");
942 int EnabledCalledCount = 0;
943 private void EnabledTest2EnabledChanged(object sender, EventArgs e) {
944 EnabledCalledCount++;
948 public void EnabledTest2() {
949 // Check nesting of enabled calls
950 // OnEnabled is not called for disabled child controls
955 EnabledCalledCount = 0;
957 grandma = new Control();
958 parent = new Control();
959 child = new Control();
960 child.EnabledChanged += new EventHandler(EnabledTest2EnabledChanged);
962 grandma.Controls.Add(parent);
963 parent.Controls.Add(child);
964 grandma.Enabled = false;
966 Assert.AreEqual(1, EnabledCalledCount, "Child Enabled Event not properly fired");
967 grandma.Enabled = true;
968 Assert.AreEqual(2, EnabledCalledCount, "Child Enabled Event not properly fired");
969 child.Enabled = false;
970 grandma.Enabled = false;
971 Assert.AreEqual(3, EnabledCalledCount, "Child Enabled Event not properly fired");
975 public void ControlsRemoveNullTest ()
977 Control c = new Control ();
978 c.Controls.Remove (null);
982 public void ControlsAddNullTest ()
984 Control c = new Control ();
985 c.Controls.Add (null);
989 [ExpectedException (typeof (ArgumentNullException))]
990 public void ControlsSetChildIndexNullTest ()
992 Control c = new Control ();
993 c.Controls.SetChildIndex (null, 1);
997 [ExpectedException (typeof (ArgumentNullException))]
998 public void ControlsAddRangeNullTest ()
1000 Control c = new Control ();
1001 c.Controls.AddRange (null);
1005 public void ControlsAddRangeNullElementTest ()
1007 Control c = new Control ();
1008 Control[] subcontrols = new Control[2];
1009 subcontrols[0] = new Control ();
1010 subcontrols[1] = null;
1012 c.Controls.AddRange (subcontrols);
1016 public void RegionTest () {
1017 Form f = new Form ();
1018 f.ShowInTaskbar = false;
1019 Control c = new Control ();
1021 Assert.IsNull (c.Region, "#A1");
1023 Assert.IsNull (c.Region, "#A2");
1025 Assert.IsNull (c.Region, "#A3");
1028 Region region = new Region ();
1030 f.ShowInTaskbar = false;
1034 Assert.IsNotNull (c.Region, "#B1");
1035 Assert.AreSame (region, c.Region, "#B2");
1038 Assert.IsNull (c.Region, "#B3");
1043 [Test] // bug #80280
1044 [Category ("NotWorking")]
1045 public void Validated_Multiple_Containers ()
1047 Form form = new Form ();
1048 form.ShowInTaskbar = false;
1050 UserControl control1 = new UserControl();
1051 UserControl container1 = new UserControl();
1052 control1.Tag = true;
1053 control1.Validated += new EventHandler (Control_ValidatedHandler);
1054 container1.Controls.Add(control1);
1055 form.Controls.Add (container1);
1057 UserControl container2 = new UserControl();
1058 UserControl control2 = new UserControl();
1059 container2.Controls.Add(control2);
1060 form.Controls.Add (container2);
1062 Assert.IsTrue ((bool) control1.Tag, "#1");
1064 Assert.IsTrue ((bool) control1.Tag, "#2");
1066 Assert.IsFalse ((bool) control1.Tag, "#3");
1071 private void Control_ValidatedHandler (object sender, EventArgs e)
1073 ((Control) sender).Tag = false;
1078 public class ControlInvokeTest {
1079 public delegate void TestDelegate ();
1084 ApplicationContext control_context;
1085 bool delegateCalled = false;
1089 void CreateControl ()
1092 f.ShowInTaskbar = false;
1098 Console.WriteLine ("f.Handle = {0}", f.Handle);
1099 Console.WriteLine ("c.Handle = {0}", c.Handle);
1101 control_context = new ApplicationContext (f);
1104 Console.WriteLine ("pulsing");
1107 Console.WriteLine ("control thread running");
1108 Application.Run (control_context);
1113 public void InvokeTest ()
1117 control_t = new Thread(new ThreadStart(CreateControl));
1123 Console.WriteLine ("waiting on monitor");
1126 Console.WriteLine ("making async call");
1128 IAsyncResult result;
1129 result = c.BeginInvoke (new TestDelegate (delegate_call));
1130 c.EndInvoke (result);
1132 Assert.AreEqual (true, delegateCalled, "Invoke1");
1135 public void delegate_call () {
1136 /* invoked on control_context's thread */
1137 delegateCalled = true;
1139 Application.Exit ();
1145 public class ControlWMTest
1148 public void WM_PARENTNOTIFY_Test ()
1154 tester = new WMTester ();
1155 child = new Control ();
1156 tester.Controls.Add (child);
1158 tester.Visible = true;
1159 child.Visible = true;
1161 child_handle = child.Handle.ToInt32 ();
1166 msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
1168 Assert.AreEqual (1, msgs.Count, "#1");
1170 m1 = (Message) msgs [0];
1171 Assert.AreEqual (WndMsg.WM_CREATE, ((WndMsg) LowOrder (m1.WParam)), "#2");
1172 //Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam), "#3");
1173 Assert.AreEqual (child_handle, m1.LParam.ToInt32 (), "#4");
1177 msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
1178 Assert.AreEqual (2, msgs.Count, "#5");
1179 m1 = (Message) msgs [1];
1181 Assert.AreEqual (WndMsg.WM_DESTROY, ((WndMsg) LowOrder (m1.WParam)), "#6");
1182 //Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam), "#7");
1183 Assert.AreEqual (child_handle, m1.LParam.ToInt32 (), "#8");
1188 internal static int LowOrder (int param)
1190 return ((int)(short)(param & 0xffff));
1193 internal static int HighOrder (int param)
1195 return ((int)(short)(param >> 16));
1198 internal static int LowOrder (IntPtr param)
1200 return ((int)(short)(param.ToInt32 () & 0xffff));
1203 internal static int HighOrder (IntPtr param)
1205 return ((int)(short)(param.ToInt32 () >> 16));
1208 internal class WMTester : Form
1210 internal ArrayList Messages = new ArrayList ();
1212 internal bool Contains (WndMsg msg)
1214 return Contains (msg, Messages);
1217 internal bool Contains (WndMsg msg, ArrayList list)
1219 foreach (Message m in Messages)
1221 if (m.Msg == (int) msg)
1227 internal ArrayList Find (WndMsg msg)
1229 ArrayList result = new ArrayList ();
1231 foreach (Message m in Messages)
1233 if (m.Msg == (int) msg)
1239 protected override void WndProc(ref Message m)
1241 Console.WriteLine ("WndProc: " + m.ToString ());
1243 base.WndProc (ref m);