From a9c4d880d1ff59f7c813e4973dee61b67352770f Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Mon, 11 Dec 2006 20:00:28 +0000 Subject: [PATCH] In System.Windows.Forms: 2006-12-11 Chris Toshok * Control.cs: ControlCollection.Remove should return if the arg is null, and ControlCollection.SetChildIndex should raise a ANE. In Test/System.Windows.Forms: 2006-12-11 Chris Toshok * ControlTest.cs: add some unit tests for null parameters to some of the ControlCollection methods. svn path=/trunk/mcs/; revision=69355 --- .../System.Windows.Forms/ChangeLog | 5 +++ .../System.Windows.Forms/Control.cs | 6 ++++ .../Test/System.Windows.Forms/ChangeLog | 5 +++ .../Test/System.Windows.Forms/ControlTest.cs | 41 ++++++++++++++++++++++ 4 files changed, 57 insertions(+) diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog index 35f1e8211b0..99b17c979af 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog @@ -1,3 +1,8 @@ +2006-12-11 Chris Toshok + + * Control.cs: ControlCollection.Remove should return if the arg is + null, and ControlCollection.SetChildIndex should raise a ANE. + 2006-12-11 Gert Driesen * Control.cs: Verify value set for Dock property. Code formatting diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs index 8ddd72cbf41..39fc3e1e908 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs @@ -539,6 +539,9 @@ namespace System.Windows.Forms } public virtual void Remove(Control value) { + if (value == null) + return; + owner.PerformLayout(value, "Parent"); owner.OnControlRemoved(new ControlEventArgs(value)); @@ -570,6 +573,9 @@ namespace System.Windows.Forms } public void SetChildIndex(Control child, int newIndex) { + if (child == null) + throw new ArgumentNullException ("child"); + int old_index; old_index=list.IndexOf(child); diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog b/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog index 03a1c99e41c..feb5443ec8b 100644 --- a/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog +++ b/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog @@ -1,3 +1,8 @@ +2006-12-11 Chris Toshok + + * ControlTest.cs: add some unit tests for null parameters to some + of the ControlCollection methods. + 2006-12-11 Gert Driesen * ControlTest.cs: Added test for invalid Dock value. diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ControlTest.cs b/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ControlTest.cs index fde93e3e885..1b9584c078b 100644 --- a/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ControlTest.cs +++ b/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ControlTest.cs @@ -969,6 +969,47 @@ namespace MonoTests.System.Windows.Forms grandma.Enabled = false; Assert.AreEqual(3, EnabledCalledCount, "Child Enabled Event not properly fired"); } + + [Test] + public void ControlsRemoveNullTest () + { + Control c = new Control (); + c.Controls.Remove (null); + } + + [Test] + public void ControlsAddNullTest () + { + Control c = new Control (); + c.Controls.Add (null); + } + + [Test] + [ExpectedException (typeof (ArgumentNullException))] + public void ControlsSetChildIndexNullTest () + { + Control c = new Control (); + c.Controls.SetChildIndex (null, 1); + } + + [Test] + [ExpectedException (typeof (ArgumentNullException))] + public void ControlsAddRangeNullTest () + { + Control c = new Control (); + c.Controls.AddRange (null); + } + + [Test] + public void ControlsAddRangeNullElementTest () + { + Control c = new Control (); + Control[] subcontrols = new Control[2]; + subcontrols[0] = new Control (); + subcontrols[1] = null; + + c.Controls.AddRange (subcontrols); + } } [TestFixture] -- 2.11.4.GIT