| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- //
- // ContainerControl class testing unit
- //
- // Authors:
- // Sebastien Pouliot <[email protected]>
- //
- // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using System;
- using System.Security.Permissions;
- using System.Windows.Forms;
- using NUnit.Framework;
- namespace MonoTests.System.Windows.Forms {
- public class IContainerControlTest : Control, IContainerControl {
- public bool ActivateControl (Control active)
- {
- return true;
- }
- public Control ActiveControl {
- get { return null; }
- set { ; }
- }
- }
- [TestFixture]
- [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
- public class ContainerControlTest {
- [Test]
- public void GetContainerControl ()
- {
- ContainerControl cc = new ContainerControl ();
- Assert.IsTrue (Object.ReferenceEquals (cc, cc.GetContainerControl ()), "ContainerControl.GetContainerControl");
- Button b = new Button ();
- Assert.IsNull (b.GetContainerControl (), "Button.GetContainerControl/without parent");
- b.Parent = cc;
- Assert.IsTrue (Object.ReferenceEquals (cc, b.GetContainerControl ()), "Button.GetContainerControl");
- }
- [Test]
- public void GetContainerControl_WithoutStyle ()
- {
- IContainerControlTest cct = new IContainerControlTest ();
- Assert.IsNull (cct.GetContainerControl (), "IContainerControlTest.GetContainerControl");
- Button b = new Button ();
- b.Parent = cct;
- Assert.IsNull (b.GetContainerControl (), "Button.GetContainerControl/without parent");
- }
- [Test]
- [Category ("NotWorking")]
- public void ActiveControl ()
- {
- 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");
- }
- [Test] // bug #80411
- [Category ("NotWorking")]
- 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");
- }
- }
- [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");
- }
- [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");
- }
- [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");
- }
- }
- }
|