Mark tests as not working under TARGET_JVM
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / FocusTest.cs
index e54b9c2fa0d22525a9c863c982307dd38533ae75..b4319928abd22b3e2e876175d3c5c8c9f7f1ea6a 100644 (file)
@@ -6,8 +6,12 @@
 //
 
 using System;
+using System.Text;
 using System.Windows.Forms;
 
+using CancelEventArgs = System.ComponentModel.CancelEventArgs;
+using CancelEventHandler = System.ComponentModel.CancelEventHandler;
+
 using NUnit.Framework;
 
 namespace MonoTests.System.Windows.Forms {
@@ -95,7 +99,12 @@ namespace MonoTests.System.Windows.Forms {
                [Test]
                public void ControlSelectNextFlatTest ()
                {
+                       if (RunningOnUnix) {
+                               Assert.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
+                       }
+
                        Form form = new Form ();
+                       form.ShowInTaskbar = false;
 
                        form.Controls.AddRange (flat_controls);
                        form.Show ();
@@ -127,12 +136,14 @@ namespace MonoTests.System.Windows.Forms {
                        Assert.IsFalse (flat_controls [1].Focused, "A14");
                        Assert.IsFalse (flat_controls [2].Focused, "A15");
                        Assert.AreEqual (flat_controls [0], form.ActiveControl, "A16");
+                       form.Dispose ();
                }
 
                [Test]
                public void SelectNextControlNullTest ()
                {
                        Form form = new Form ();
+                       form.ShowInTaskbar = false;
 
                        form.Show ();
                        form.Controls.AddRange (flat_controls);
@@ -148,12 +159,14 @@ namespace MonoTests.System.Windows.Forms {
                        Assert.IsFalse (flat_controls [1].Focused, "A6");
                        Assert.IsFalse (flat_controls [2].Focused, "A7");
                        Assert.AreEqual (flat_controls [0], form.ActiveControl, "A8");
+                       form.Dispose ();
                }
 
                [Test]
                public void SelectControlTest ()
                {
                        Form form = new Form ();
+                       form.ShowInTaskbar = false;
 
                        form.Show ();
                        form.Controls.AddRange (flat_controls);
@@ -166,24 +179,28 @@ namespace MonoTests.System.Windows.Forms {
 
                        flat_controls [0]._Select (true, true);
                        Assert.AreEqual (flat_controls [0], form.ActiveControl, "A3");
+                       form.Dispose ();
                }
 
                [Test]
                public void EnsureDirectedSelectUsed ()
                {
                        Form form = new Form ();
+                       form.ShowInTaskbar = false;
 
                        form.Show ();
                        form.Controls.AddRange (flat_controls);
 
                        form.SelectNextControl (null, true, false, false, false);
                        Assert.IsTrue (flat_controls [0].directed_select_called, "A1");
+                       form.Dispose ();
                }
 
                [Test]
                public void ContainerSelectDirectedForward ()
                {
                        Form form = new Form ();
+                       form.ShowInTaskbar = false;
                        ContainerPoker cp = new ContainerPoker ("container-a");
                        
                        form.Show ();
@@ -205,12 +222,14 @@ namespace MonoTests.System.Windows.Forms {
                        Assert.IsFalse (flat_controls [2].Focused, "A8");
                        Assert.AreEqual (flat_controls [0], cp.ActiveControl, "A9");
                        Assert.AreEqual (cp, form.ActiveControl, "A10");
+                       form.Dispose ();
                }
 
                [Test]
                public void ContainerSelectDirectedBackward ()
                {
                        Form form = new Form ();
+                       form.ShowInTaskbar = false;
                        ContainerPoker cp = new ContainerPoker ("container-a");
                        
                        form.Show ();
@@ -232,12 +251,15 @@ namespace MonoTests.System.Windows.Forms {
                        Assert.IsTrue (flat_controls [2].Focused, "A8");
                        Assert.AreEqual (flat_controls [2], cp.ActiveControl, "A9");
                        Assert.AreEqual (cp, form.ActiveControl, "A10");
+                       form.Dispose ();
                }
 
                [Test]
+               [Category ("NotWorking")]
                public void ContainerSelectUndirectedForward ()
                {
                        Form form = new Form ();
+                       form.ShowInTaskbar = false;
                        ContainerPoker cp = new ContainerPoker ("container-a");
                        
                        form.Show ();
@@ -245,18 +267,21 @@ namespace MonoTests.System.Windows.Forms {
 
                        cp.Controls.AddRange (flat_controls);
 
+                       Assert.IsFalse (flat_controls [0].Focused, "A0");
                        cp._Select (false, true);
                        Assert.IsFalse (flat_controls [0].Focused, "A1");
                        Assert.IsFalse (flat_controls [1].Focused, "A2");
                        Assert.IsFalse (flat_controls [2].Focused, "A3");
                        Assert.AreEqual (null, cp.ActiveControl, "A4");
                        Assert.AreEqual (cp, form.ActiveControl, "A5");
+                       form.Dispose ();
                }
 
                [Test]
                public void GetNextControlFromForm ()
                {
                        Form form = new Form ();
+                       form.ShowInTaskbar = false;
                        ContainerPoker con_a = new ContainerPoker ("container-a");
                        ContainerPoker con_b = new ContainerPoker ("container-b");
                        ContainerPoker con_c = new ContainerPoker ("container-c");
@@ -281,6 +306,9 @@ namespace MonoTests.System.Windows.Forms {
                        form.Show ();
 
                        // top level movement, 
+                       Assert.AreEqual (form.GetNextControl (null, true), con_a, "null-1");
+                       Assert.AreEqual (form.GetNextControl (null, false), con_c, "null-2");
+
                        Assert.AreEqual (form.GetNextControl (form, true), con_a, "form-1");
                        Assert.AreEqual (form.GetNextControl (form, false), con_c, "form-2");
                        
@@ -311,12 +339,14 @@ namespace MonoTests.System.Windows.Forms {
                        Assert.AreEqual (form.GetNextControl (ctrls_c [1], false), ctrls_c [0], "ctrls-c-4");
                        Assert.AreEqual (form.GetNextControl (ctrls_c [2], true), null, "ctrls-c-5");
                        Assert.AreEqual (form.GetNextControl (ctrls_c [2], false), ctrls_c [1], "ctrls-c-6");
+                       form.Dispose ();
                }
 
                [Test]
                public void GetNextControlFromContainerA ()
                {
                        Form form = new Form ();
+                       form.ShowInTaskbar = false;
                        ContainerPoker con_a = new ContainerPoker ("container-a");
                        ContainerPoker con_b = new ContainerPoker ("container-b");
                        ContainerPoker con_c = new ContainerPoker ("container-c");
@@ -341,6 +371,9 @@ namespace MonoTests.System.Windows.Forms {
                        form.Show ();
 
                        // top level movement, 
+                       Assert.AreEqual (con_a.GetNextControl (null, true), ctrls_a [0], "null-1");
+                       Assert.AreEqual (con_a.GetNextControl (null, false), ctrls_a [2], "null-2");
+
                        Assert.AreEqual (con_a.GetNextControl (form, true), ctrls_a [0], "form-1");
                        Assert.AreEqual (con_a.GetNextControl (form, false), ctrls_a [2], "form-2");
                        
@@ -371,12 +404,14 @@ namespace MonoTests.System.Windows.Forms {
                        Assert.AreEqual (con_a.GetNextControl (ctrls_c [1], false), ctrls_a [2], "ctrls-c-4");
                        Assert.AreEqual (con_a.GetNextControl (ctrls_c [2], true), ctrls_a [0], "ctrls-c-5");
                        Assert.AreEqual (con_a.GetNextControl (ctrls_c [2], false), ctrls_a [2], "ctrls-c-6");
+                       form.Dispose ();
                }
 
                [Test]
                public void GetNextControlFromContainerB ()
                {
                        Form form = new Form ();
+                       form.ShowInTaskbar = false;
                        ContainerPoker con_a = new ContainerPoker ("container-a");
                        ContainerPoker con_b = new ContainerPoker ("container-b");
                        ContainerPoker con_c = new ContainerPoker ("container-c");
@@ -401,6 +436,9 @@ namespace MonoTests.System.Windows.Forms {
                        form.Show ();
 
                        // top level movement
+                       Assert.AreEqual (con_b.GetNextControl (null, true), ctrls_b [0], "null-1");
+                       Assert.AreEqual (con_b.GetNextControl (null, false), ctrls_b [2], "null-2");
+
                        Assert.AreEqual (con_b.GetNextControl (form, true), ctrls_b [0], "form-1");
                        Assert.AreEqual (con_b.GetNextControl (form, false), ctrls_b [2], "form-2");
                        
@@ -431,12 +469,14 @@ namespace MonoTests.System.Windows.Forms {
                        Assert.AreEqual (con_b.GetNextControl (ctrls_c [1], false), ctrls_b [2], "ctrls-c-4");
                        Assert.AreEqual (con_b.GetNextControl (ctrls_c [2], true), ctrls_b [0], "ctrls-c-5");
                        Assert.AreEqual (con_b.GetNextControl (ctrls_c [2], false), ctrls_b [2], "ctrls-c-6");
+                       form.Dispose ();
                }
 
                [Test]
                public void GetNextControlFromContainerC ()
                {
                        Form form = new Form ();
+                       form.ShowInTaskbar = false;
                        ContainerPoker con_a = new ContainerPoker ("container-a");
                        ContainerPoker con_b = new ContainerPoker ("container-b");
                        ContainerPoker con_c = new ContainerPoker ("container-c");
@@ -461,6 +501,9 @@ namespace MonoTests.System.Windows.Forms {
                        form.Show ();
 
                        // top level movement, 
+                       Assert.AreEqual (con_c.GetNextControl (null, true), ctrls_c [0], "null-1");
+                       Assert.AreEqual (con_c.GetNextControl (null, false), ctrls_c [2], "null-2");
+
                        Assert.AreEqual (con_c.GetNextControl (form, true), ctrls_c [0], "form-1");
                        Assert.AreEqual (con_c.GetNextControl (form, false), ctrls_c [2], "form-2");
                        
@@ -491,15 +534,20 @@ namespace MonoTests.System.Windows.Forms {
                        Assert.AreEqual (con_c.GetNextControl (ctrls_c [1], false), ctrls_c [0], "ctrls-c-4");
                        Assert.AreEqual (con_c.GetNextControl (ctrls_c [2], true), null, "ctrls-c-5");
                        Assert.AreEqual (con_c.GetNextControl (ctrls_c [2], false), ctrls_c [1], "ctrls-c-6");
+                       form.Dispose ();
                }
 
                [Test]
                public void GetNextControl2FromForm ()
                {
                        Form form = new Form ();
+                       form.ShowInTaskbar = false;
                        ContainerPoker con_a = new ContainerPoker ("container-a");
                        ContainerPoker con_b = new ContainerPoker ("container-b");
                        ContainerPoker con_c = new ContainerPoker ("container-c");
+                       
+                       TestHelper.RemoveWarning (con_b, con_c);
+                       
                        ControlPoker [] ctrls_a = new ControlPoker [] {
                                new ControlPoker ("ctrls-a-0"), new ControlPoker ("ctrls-a-1"), new ControlPoker ("ctrls-a-2")
                        };
@@ -513,6 +561,9 @@ namespace MonoTests.System.Windows.Forms {
                        form.Show ();
 
                        // top level movement, 
+                       Assert.AreEqual (form.GetNextControl (null, true), con_a, "null-1");
+                       Assert.AreEqual (form.GetNextControl (null, false), ctrl_b, "null-2");
+
                        Assert.AreEqual (form.GetNextControl (form, true), con_a, "form-1");
                        Assert.AreEqual (form.GetNextControl (form, false), ctrl_b, "form-2");
 
@@ -528,13 +579,14 @@ namespace MonoTests.System.Windows.Forms {
                        Assert.AreEqual (form.GetNextControl (ctrls_a [1], false), ctrls_a [0], "ctrl-a-2");
                        Assert.AreEqual (form.GetNextControl (ctrls_a [2], true), ctrl_b, "ctrl-a-1");
                        Assert.AreEqual (form.GetNextControl (ctrls_a [2], false), ctrls_a [1], "ctrl-a-2");
-
+                       form.Dispose();
                }
 
                [Test]
                public void GetNextControlFlat ()
                {
                        Form form = new Form ();
+                       form.ShowInTaskbar = false;
 
                        form.Controls.AddRange (flat_controls);
                        form.Show ();
@@ -557,12 +609,14 @@ namespace MonoTests.System.Windows.Forms {
                        Assert.AreEqual (flat_controls [0].GetNextControl (flat_controls [1], false), null, "ctrls-0-6");
                        Assert.AreEqual (flat_controls [0].GetNextControl (flat_controls [2], true), null, "ctrls-0-7");
                        Assert.AreEqual (flat_controls [0].GetNextControl (flat_controls [2], false), null,"ctrls-0-8");
+                       form.Dispose ();
                }
 
                [Test]
                public void GetNextGroupBoxControlFlat ()
                {
                        Form form = new Form ();
+                       form.ShowInTaskbar = false;
                        GroupBoxPoker gbp = new GroupBoxPoker ("group-box");
 
                        gbp.Controls.AddRange (flat_controls);
@@ -579,12 +633,28 @@ namespace MonoTests.System.Windows.Forms {
                        Assert.AreEqual (gbp.GetNextControl (null, false), flat_controls [2], "gb-4");
                        Assert.AreEqual (gbp.GetNextControl (gbp, true), flat_controls [0], "gb-5");
                        Assert.AreEqual (gbp.GetNextControl (gbp, false), flat_controls [2], "gb-6");
+
+                       Assert.AreEqual (form.GetNextControl (flat_controls [0], true), flat_controls [1], "form-ctrls-0-forward");
+                       Assert.AreEqual (form.GetNextControl (flat_controls [0], false), gbp, "form-ctrls-0-backward");
+                       Assert.AreEqual (form.GetNextControl (flat_controls [1], true), flat_controls [2], "form-ctrls-1-forward");
+                       Assert.AreEqual (form.GetNextControl (flat_controls [1], false), flat_controls [0], "form-ctrls-1-backward");
+                       Assert.AreEqual (form.GetNextControl (flat_controls [2], true), null, "form-ctrls-2-forward");
+                       Assert.AreEqual (form.GetNextControl (flat_controls [2], false), flat_controls [1],"form-ctrls-2-backward");
+
+                       Assert.AreEqual (gbp.GetNextControl (flat_controls [0], true), flat_controls [1], "gbp-ctrls-0-forward");
+                       Assert.AreEqual (gbp.GetNextControl (flat_controls [0], false), null, "gbp-ctrls-0-backward");
+                       Assert.AreEqual (gbp.GetNextControl (flat_controls [1], true), flat_controls [2], "gbp-ctrls-1-forward");
+                       Assert.AreEqual (gbp.GetNextControl (flat_controls [1], false), flat_controls [0], "gbp-ctrls-1-backward");
+                       Assert.AreEqual (gbp.GetNextControl (flat_controls [2], true), null, "gbp-ctrls-2-forward");
+                       Assert.AreEqual (gbp.GetNextControl (flat_controls [2], false), flat_controls [1],"gbp-ctrls-2-backward");              
+                       form.Dispose ();
                }
 
                [Test]
                public void GetNextControlFromTabControl ()
                {
                        Form form = new Form ();
+                       form.ShowInTaskbar = false;
                        TabControl tab = new TabControl ();
                        TabPage page1 = new TabPage ("page one");
                        TabPage page2 = new TabPage ("page two");
@@ -606,12 +676,62 @@ namespace MonoTests.System.Windows.Forms {
 
                        Assert.AreEqual (form.GetNextControl (page2, true), null, "page-two-1");
                        Assert.AreEqual (form.GetNextControl (page2, false), page1, "page-two-2");
+                       form.Dispose ();
+               }
+
+               [Test]
+               public void GetNextControlFromTabControl2 () {
+                       Form form = new Form ();
+                       form.ShowInTaskbar = false;
+                       TabControl tab = new TabControl ();
+                       
+                       TabPage page1 = new TabPage ("page one");
+                       page1.Controls.AddRange (flat_controls);
+
+                       TabPage page2 = new TabPage ("page two");
+
+                       tab.TabPages.Add (page1);
+
+                       tab.TabPages.Add (page2);
+
+                       form.Controls.Add (tab);
+                       form.Show ();
+
+                       Assert.AreEqual (form.GetNextControl (null, true), tab, "form-1");
+                       Assert.AreEqual (form.GetNextControl (null, false), page2, "form-2");
+
+                       Assert.AreEqual (form.GetNextControl (tab, true), page1, "tab-1");
+                       Assert.AreEqual (form.GetNextControl (tab, false), null, "tab-2");
+
+                       Assert.AreEqual (form.GetNextControl (page1, true), flat_controls [0], "page-one-1");
+                       Assert.AreEqual (form.GetNextControl (page1, false), tab, "page-one-2");
+
+                       Assert.AreEqual (form.GetNextControl (page2, true), null, "page-two-1");
+                       Assert.AreEqual (form.GetNextControl (page2, false), flat_controls [2], "page-two-2");
+
+                       Assert.AreEqual (form.GetNextControl (flat_controls [0], false), page1, "form-ctrls-0-backward");
+                       Assert.AreEqual (form.GetNextControl (flat_controls [2], true), page2, "form-ctrls-2-forward");
+
+                       Assert.AreEqual (tab.GetNextControl (null, true), page1, "tab-null-forward");
+                       Assert.AreEqual (tab.GetNextControl (page1, false), null, "tab-page1-backward");
+
+                       Assert.AreEqual (tab.GetNextControl (flat_controls [0], false), page1, "tab-ctrls-0-backward");
+                       Assert.AreEqual (tab.GetNextControl (flat_controls [2], true), page2, "tab-ctrls-2-forward");
+
+                       Assert.AreEqual (page1.GetNextControl (flat_controls [0], true), flat_controls [1], "page1-ctrls-0-forward");
+                       Assert.AreEqual (page1.GetNextControl (flat_controls [0], false), null, "page1-ctrls-0-backward");
+                       Assert.AreEqual (page1.GetNextControl (flat_controls [1], true), flat_controls [2], "page1-ctrls-1-forward");
+                       Assert.AreEqual (page1.GetNextControl (flat_controls [1], false), flat_controls [0], "page1-ctrls-1-backward");
+                       Assert.AreEqual (page1.GetNextControl (flat_controls [2], true), null, "page1-ctrls-2-forward");
+                       Assert.AreEqual (page1.GetNextControl (flat_controls [2], false), flat_controls [1],"page1-ctrls-2-backward");
+                       form.Dispose ();
                }
 
                [Test]
                public void GetNextControlTabIndex ()
                {
                        Form form = new Form ();
+                       form.ShowInTaskbar = false;
                        ControlPoker [] ctrls = new ControlPoker [5];
 
                        for (int i = 0; i < 5; i++) {
@@ -641,12 +761,14 @@ namespace MonoTests.System.Windows.Forms {
                        Assert.AreEqual (form.GetNextControl (ctrls [4], true), null, "A11");
                        Assert.AreEqual (form.GetNextControl (ctrls [4], false), ctrls [3], "A12");
 
+                       form.Dispose ();
                }
 
                [Test]
                public void GetNextControlDuplicateTabIndex ()
                {
                        Form form = new Form ();
+                       form.ShowInTaskbar = false;
                        ControlPoker [] ctrls = new ControlPoker [5];
 
                        for (int i = 0; i < 5; i++) {
@@ -678,12 +800,14 @@ namespace MonoTests.System.Windows.Forms {
                        Assert.AreEqual (form.GetNextControl (ctrls [4], true), null, "A11");
                        Assert.AreEqual (form.GetNextControl (ctrls [4], false), ctrls [3], "A12");
 
+                       form.Dispose ();
                }
 
                [Test]
                public void GetNextControlComposite ()
                {
                        Form form = new Form ();
+                       form.ShowInTaskbar = false;
                        ControlPoker a = new ControlPoker ("a");
                        ControlPoker b = new ControlPoker ("b");
                        ControlPoker c = new ControlPoker ("c");
@@ -696,12 +820,19 @@ namespace MonoTests.System.Windows.Forms {
 
                        Assert.AreEqual (form.GetNextControl (a, true), b, "form-1");
                        Assert.AreEqual (form.GetNextControl (a, false), null, "form-2");
+
+                       form.Dispose ();
                }
 
                [Test]
-               public void FocusSetsActive ()
+               public void ActiveControl ()
                {
+                       if (RunningOnUnix) {
+                               Assert.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
+                       }
+
                        Form form = new Form ();
+                       form.ShowInTaskbar = false;
 
                        form.Controls.AddRange (flat_controls);
                        form.Show ();
@@ -711,8 +842,368 @@ namespace MonoTests.System.Windows.Forms {
                        flat_controls [1].Focus ();
 
                        Assert.AreEqual (form.ActiveControl, flat_controls [1], "A2");
+
+                       form.Dispose ();
                }
-       }
 
-}
+               [Test]
+               [Category ("NotWorking")]
+               public void ActiveControl2 () {
+                       ContainerControl cc = new ContainerControl ();
+                       Control c1 = new Control ();
+                       cc.Controls.Add (c1);
+                       Control c2 = new Control ();
+                       cc.Controls.Add (c2);
+                       Control c3 = new Control ();
+                       cc.Controls.Add (c3);
+                       Assert.IsFalse (c1.Focused, "#A1");
+                       Assert.IsFalse (c2.Focused, "#A2");
+                       Assert.IsFalse (c3.Focused, "#A3");
+                       Assert.IsNull (cc.ActiveControl);
+
+                       cc.ActiveControl = c1;
+                       Assert.IsFalse (c1.Focused, "#B1");
+                       Assert.IsFalse (c2.Focused, "#B2");
+                       Assert.IsFalse (c3.Focused, "#B3");
+                       Assert.AreSame (c1, cc.ActiveControl, "#B4");
+
+                       cc.ActiveControl = c2;
+                       Assert.IsFalse (c1.Focused, "#C1");
+                       Assert.IsFalse (c2.Focused, "#C2");
+                       Assert.IsFalse (c3.Focused, "#C3");
+                       Assert.AreSame (c2, cc.ActiveControl, "#C4");
+
+                       c1.Focus ();
+                       Assert.IsFalse (c1.Focused, "#D1");
+                       Assert.IsFalse (c2.Focused, "#D2");
+                       Assert.IsFalse (c3.Focused, "#D3");
+                       Assert.AreSame (c2, cc.ActiveControl, "#D4");
+
+                       cc.ActiveControl = c2;
+                       Assert.IsFalse (c1.Focused, "#E1");
+                       Assert.IsFalse (c2.Focused, "#E2");
+                       Assert.IsFalse (c3.Focused, "#E3");
+                       Assert.AreSame (c2, cc.ActiveControl, "#E4");
+
+                       cc.Controls.Remove (c2);
+                       Assert.IsFalse (c1.Focused, "#F1");
+                       Assert.IsFalse (c2.Focused, "#F2");
+                       Assert.IsFalse (c3.Focused, "#F3");
+                       Assert.AreSame (c1, cc.ActiveControl, "#F3");
+
+                       cc.ActiveControl = c3;
+                       Assert.IsFalse (c1.Focused, "#G1");
+                       Assert.IsFalse (c2.Focused, "#G2");
+                       Assert.IsFalse (c3.Focused, "#G3");
+                       Assert.AreSame (c3, cc.ActiveControl, "#G4");
+
+                       Form form = new Form ();
+                       form.ShowInTaskbar = false;
+                       form.Controls.Add (cc);
+                       form.Show ();
+
+                       Assert.IsTrue (c1.Focused, "#H1");
+                       Assert.IsFalse (c2.Focused, "#H2");
+                       Assert.IsFalse (c3.Focused, "#H3");
+                       Assert.AreSame (c1, cc.ActiveControl, "#H4");
+
+                       cc.ActiveControl = c3;
+                       Assert.IsFalse (c1.Focused, "#I1");
+                       Assert.IsFalse (c2.Focused, "#I2");
+                       Assert.IsTrue (c3.Focused, "#I3");
+                       Assert.AreSame (c3, cc.ActiveControl, "#I4");
+
+                       c1.Focus ();
+                       Assert.IsTrue (c1.Focused, "#J1");
+                       Assert.IsFalse (c2.Focused, "#J2");
+                       Assert.IsFalse (c3.Focused, "#J3");
+                       Assert.AreSame (c1, cc.ActiveControl, "#J4");
+
+                       form.Dispose ();
+               }
 
+               [Test] // bug #80411
+               public void ActiveControl_NoChild () {
+                       ContainerControl cc = new ContainerControl ();
+                       try {
+                               cc.ActiveControl = new Control ();
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException ex) {
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                               Assert.IsNotNull (ex.Message, "#3");
+                               Assert.IsNull (ex.ParamName, "#4");
+                               Assert.IsNull (ex.InnerException, "#5");
+                       }
+               }
+
+
+               StringBuilder sb;
+               void enter(object sender, EventArgs e) {
+                       sb.Append(String.Format("OnEnter: {0} {1}", ((Control)sender).Name, sender));
+                       sb.Append("\n");
+               }
+
+               void leave(object sender, EventArgs e) {
+                       sb.Append(String.Format("OnLeave: {0} {1}", ((Control)sender).Name, sender));
+                       sb.Append("\n");
+               }
+
+               void gotfocus(object sender, EventArgs e) {
+                       sb.Append(String.Format("OnGotFocus: {0} {1}", ((Control)sender).Name, sender));
+                       sb.Append("\n");
+               }
+
+               void lostfocus(object sender, EventArgs e) {
+                       sb.Append(String.Format("OnLostFocus: {0} {1}", ((Control)sender).Name, sender));
+                       sb.Append("\n");
+               }
+
+               void validating(object sender, CancelEventArgs e) {
+                       sb.Append(String.Format("OnValidating: {0} {1}", ((Control)sender).Name, sender));
+                       sb.Append("\n");
+               }
+
+               void validated(object sender, EventArgs e) {
+                       sb.Append(String.Format("OnValidated: {0} {1}", ((Control)sender).Name, sender));
+                       sb.Append("\n");
+               }
+
+               void connect(Control c) {
+                       c.Enter += new EventHandler(enter);
+                       c.Leave += new EventHandler(leave);
+                       c.GotFocus += new EventHandler(gotfocus);
+                       c.LostFocus += new EventHandler(lostfocus);
+                       c.Validating += new CancelEventHandler(validating);
+                       c.Validated += new EventHandler(validated);
+               }
+
+               [Test]
+               public void EnterLeaveFocusEventTest ()
+               {
+                       if (RunningOnUnix) {
+                               Assert.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
+                       }
+
+                       Form f = new Form();
+                       f.ShowInTaskbar = false;
+
+                       f.Name = "Form1";
+                       ContainerControl cc0 = new ContainerControl();
+                       cc0.Name = "ContainerControl 0";
+                       ContainerControl cc1 = new ContainerControl();
+                       cc1.Name = "ContainerControl 1";
+                       ContainerControl cc2 = new ContainerControl();
+                       cc2.Name = "ContainerControl 2";
+                       Control c1 = new Control();
+                       c1.Name = "Control 1";
+                       Control c2 = new Control();
+                       c2.Name = "Control 2";
+
+                       connect(f);
+                       connect(cc0);
+                       connect(cc1);
+                       connect(cc2);
+                       connect(c1);
+                       connect(c2);
+
+                       cc0.Controls.Add(cc1);
+                       cc0.Controls.Add(cc2);
+                       cc1.Controls.Add(c1);
+                       cc2.Controls.Add(c2);
+
+                       f.Controls.Add(cc0);
+
+                       sb = new StringBuilder ();
+                       f.Show ();
+                       c1.Select();
+
+                       Assert.AreEqual (@"OnEnter: ContainerControl 0 System.Windows.Forms.ContainerControl
+OnEnter: ContainerControl 1 System.Windows.Forms.ContainerControl
+OnEnter: Control 1 System.Windows.Forms.Control
+OnGotFocus: Control 1 System.Windows.Forms.Control
+",
+                                        sb.ToString (), "1");
+
+                       sb.Length = 0;
+                       c2.Select();
+                       Assert.AreEqual (@"OnLeave: Control 1 System.Windows.Forms.Control
+OnLeave: ContainerControl 1 System.Windows.Forms.ContainerControl
+OnValidating: Control 1 System.Windows.Forms.Control
+OnValidated: Control 1 System.Windows.Forms.Control
+OnValidating: ContainerControl 1 System.Windows.Forms.ContainerControl
+OnValidated: ContainerControl 1 System.Windows.Forms.ContainerControl
+OnEnter: ContainerControl 2 System.Windows.Forms.ContainerControl
+OnEnter: Control 2 System.Windows.Forms.Control
+OnLostFocus: Control 1 System.Windows.Forms.Control
+OnGotFocus: Control 2 System.Windows.Forms.Control
+",
+                                        sb.ToString (), "2");
+
+                       sb.Length = 0;
+                       cc1.Select();
+                       Assert.AreEqual (@"OnLeave: Control 2 System.Windows.Forms.Control
+OnLeave: ContainerControl 2 System.Windows.Forms.ContainerControl
+OnValidating: Control 2 System.Windows.Forms.Control
+OnValidated: Control 2 System.Windows.Forms.Control
+OnValidating: ContainerControl 2 System.Windows.Forms.ContainerControl
+OnValidated: ContainerControl 2 System.Windows.Forms.ContainerControl
+OnEnter: ContainerControl 1 System.Windows.Forms.ContainerControl
+OnLostFocus: Control 2 System.Windows.Forms.Control
+OnGotFocus: ContainerControl 1 System.Windows.Forms.ContainerControl
+",
+                                        sb.ToString (), "3");
+
+                       sb.Length = 0;
+                       cc2.Select();
+                       Assert.AreEqual (@"OnLeave: ContainerControl 1 System.Windows.Forms.ContainerControl
+OnValidating: ContainerControl 1 System.Windows.Forms.ContainerControl
+OnValidated: ContainerControl 1 System.Windows.Forms.ContainerControl
+OnEnter: ContainerControl 2 System.Windows.Forms.ContainerControl
+OnLostFocus: ContainerControl 1 System.Windows.Forms.ContainerControl
+OnGotFocus: ContainerControl 2 System.Windows.Forms.ContainerControl
+",
+                                        sb.ToString (), "4");
+
+                       Assert.IsNull (cc2.ActiveControl, "5");
+
+                       sb.Length = 0;
+                       c2.Select();
+                       Assert.AreEqual (@"OnEnter: Control 2 System.Windows.Forms.Control
+OnLostFocus: ContainerControl 2 System.Windows.Forms.ContainerControl
+OnGotFocus: Control 2 System.Windows.Forms.Control
+",
+                                        sb.ToString (), "6");
+
+                       sb.Length = 0;
+                       cc1.Select();
+                       Assert.AreEqual (@"OnLeave: Control 2 System.Windows.Forms.Control
+OnLeave: ContainerControl 2 System.Windows.Forms.ContainerControl
+OnValidating: Control 2 System.Windows.Forms.Control
+OnValidated: Control 2 System.Windows.Forms.Control
+OnValidating: ContainerControl 2 System.Windows.Forms.ContainerControl
+OnValidated: ContainerControl 2 System.Windows.Forms.ContainerControl
+OnEnter: ContainerControl 1 System.Windows.Forms.ContainerControl
+OnLostFocus: Control 2 System.Windows.Forms.Control
+OnGotFocus: ContainerControl 1 System.Windows.Forms.ContainerControl
+",
+                                        sb.ToString (), "7");
+
+                       sb.Length = 0;
+                       f.Select();
+                       Assert.AreEqual ("", sb.ToString (), "8");
+
+                       f.Dispose ();
+               }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void ActiveControl_Invisible () {
+                       ContainerControl cc = new ContainerControl ();
+                       Control c1 = new Control ();
+                       c1.Visible = false;
+                       cc.Controls.Add (c1);
+                       Control c2 = new Control ();
+                       cc.Controls.Add (c2);
+                       cc.ActiveControl = c1;
+                       Assert.IsFalse (c1.Focused, "#A1");
+                       Assert.IsFalse (c2.Focused, "#A2");
+                       Assert.AreSame (c1, cc.ActiveControl, "#A3");
+
+                       Form form = new Form ();
+                       form.ShowInTaskbar = false;
+                       form.Controls.Add (cc);
+                       form.Show ();
+
+                       Assert.IsFalse (c1.Focused, "#B1");
+                       Assert.IsTrue (c2.Focused, "#B2");
+                       Assert.AreSame (c2, cc.ActiveControl, "#B3");
+
+                       cc.ActiveControl = c1;
+                       Assert.IsFalse (c1.Focused, "#C1");
+                       Assert.IsFalse (c2.Focused, "#C2");
+                       Assert.AreSame (c1, cc.ActiveControl, "#C3");
+
+                       form.Dispose ();
+               }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void ActiveControl_Disabled () {
+                       ContainerControl cc = new ContainerControl ();
+                       Control c1 = new Control ();
+                       c1.Enabled = false;
+                       cc.Controls.Add (c1);
+                       Control c2 = new Control ();
+                       cc.Controls.Add (c2);
+                       cc.ActiveControl = c1;
+                       Assert.IsFalse (c1.Focused, "#A1");
+                       Assert.IsFalse (c2.Focused, "#A2");
+                       Assert.AreSame (c1, cc.ActiveControl, "#A3");
+
+                       Form form = new Form ();
+                       form.ShowInTaskbar = false;
+                       form.Controls.Add (cc);
+                       form.Show ();
+
+                       Assert.IsFalse (c1.Focused, "#B1");
+                       Assert.IsTrue (c2.Focused, "#B2");
+                       Assert.AreSame (c2, cc.ActiveControl, "#B3");
+
+                       cc.ActiveControl = c1;
+                       Assert.IsFalse (c1.Focused, "#C1");
+                       Assert.IsTrue (c2.Focused, "#C2");
+                       Assert.AreSame (c1, cc.ActiveControl, "#C3");
+
+                       form.Dispose ();
+               }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void ActiveControl_Null () {
+                       ContainerControl cc = new ContainerControl ();
+                       Control c1 = new Control ();
+                       cc.Controls.Add (c1);
+                       Control c2 = new Control ();
+                       cc.Controls.Add (c2);
+                       cc.ActiveControl = c1;
+                       Assert.IsFalse (c1.Focused, "#A1");
+                       Assert.IsFalse (c2.Focused, "#A2");
+                       Assert.AreSame (c1, cc.ActiveControl, "#A3");
+
+                       cc.ActiveControl = null;
+                       Assert.IsFalse (c1.Focused, "#B1");
+                       Assert.IsFalse (c2.Focused, "#B2");
+                       Assert.IsNull (cc.ActiveControl, "#B3");
+
+                       Form form = new Form ();
+                       form.ShowInTaskbar = false;
+                       form.Controls.Add (cc);
+                       form.Show ();
+
+                       Assert.IsTrue (c1.Focused, "#C1");
+                       Assert.IsFalse (c2.Focused, "#C2");
+                       Assert.AreSame (c1, cc.ActiveControl, "#C3");
+
+                       cc.ActiveControl = c2;
+                       Assert.IsFalse (c1.Focused, "#D1");
+                       Assert.IsTrue (c2.Focused, "#D2");
+                       Assert.AreSame (c2, cc.ActiveControl, "#D3");
+
+                       cc.ActiveControl = null;
+                       Assert.IsFalse (c1.Focused, "#E1");
+                       Assert.IsFalse (c2.Focused, "#E2");
+                       Assert.IsNull (cc.ActiveControl, "#E3");
+
+                       form.Dispose ();
+               }
+
+               private bool RunningOnUnix {
+                       get {
+                               // check for Unix platforms - see FAQ for more details
+                               // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
+                               int platform = (int) Environment.OSVersion.Platform;
+                               return ((platform == 4) || (platform == 128));
+                       }
+               }
+       }
+}