Author: gert
Date: 2006-11-05 09:09:18 -0500 (Sun, 05 Nov 2006)
New Revision: 67376

Added:
   
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/TreeNodeCollectionTest.cs
Modified:
   trunk/mcs/class/Managed.Windows.Forms/ChangeLog
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
   
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNodeCollection.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms_test.dll.sources
   trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
Log:
* TreeNodeCollection.cs: To match MS, in 1.0 profile throw
NullReferenceException when attempting to remove node that is not in
collection. Throw NullReferenceException when null is passed to
Remove. Allow first element of the collection to be removed. Fixes
bug #79831.  In GetEnumerator ().Current return null if positioned
before the first element of the collection. In GetEnumerator ().Reset,
position before first element of the collection.
* TreeNodeCollectionTest.cs: Added tests for TreeNodeCollection.
* System.Windows.Forms_test.dll.sources: Added TreeNodeCollectionTest.cs.


Modified: trunk/mcs/class/Managed.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/ChangeLog     2006-11-05 14:02:13 UTC 
(rev 67375)
+++ trunk/mcs/class/Managed.Windows.Forms/ChangeLog     2006-11-05 14:09:18 UTC 
(rev 67376)
@@ -1,3 +1,8 @@
+2006-11-04  Gert Driesen  <[EMAIL PROTECTED]>
+
+       * System.Windows.Forms_test.dll.sources: Added 
+       TreeNodeCollectionTest.cs.
+
 2006-10-30  Jonathan Pobst  <[EMAIL PROTECTED]>
        * System.Windows.Forms.dll.sources: Add ToolStripDropDown.cs,
          ToolStripItemEventType.cs, ToolStripMenuTracker.cs.

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-11-05 14:02:13 UTC (rev 67375)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-11-05 14:09:18 UTC (rev 67376)
@@ -1,5 +1,15 @@
 2006-11-04  Gert Driesen  <[EMAIL PROTECTED]>
 
+       * TreeNodeCollection.cs: To match MS, in 1.0 profile throw 
+       NullReferenceException when attempting to remove node that is not in
+       collection. Throw NullReferenceException when null is passed to 
+       Remove. Allow first element of the collection to be removed. Fixes
+       bug #79831.  In GetEnumerator ().Current return null if positioned 
+       before the first element of the collection. In GetEnumerator ().Reset,
+       position before first element of the collection.
+
+2006-11-04  Gert Driesen  <[EMAIL PROTECTED]>
+
        * PropertyGrid.cs: To match MS, remove default title and description
        for panel. Fixed tooltips for Categorized and Alphabetic toolbar
        buttons.

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNodeCollection.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNodeCollection.cs
    2006-11-05 14:02:13 UTC (rev 67375)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNodeCollection.cs
    2006-11-05 14:09:18 UTC (rev 67376)
@@ -193,9 +193,16 @@
 
                public void Remove (TreeNode node)
                {
+                       if (node == null)
+                               throw new NullReferenceException ();
+
                        int index = IndexOf (node);
-                       if (index > 0)
+                       if (index != -1)
                                RemoveAt (index);
+#if ONLY_1_1
+                       else
+                               throw new NullReferenceException ();
+#endif
                }
 
                public virtual void RemoveAt (int index)
@@ -210,7 +217,7 @@
                        TreeNode new_selected = null;
                        bool visible = removed.IsVisible;
 
-                        TreeView tree_view = null;
+                       TreeView tree_view = null;
                        if (owner != null)
                                tree_view = owner.TreeView;
 
@@ -399,7 +406,11 @@
                        }
 
                        public object Current {
-                               get { return collection [index]; }
+                               get {
+                                       if (index == -1)
+                                               return null;
+                                       return collection [index];
+                               }
                        }
 
                        public bool MoveNext ()
@@ -412,7 +423,7 @@
 
                        public void Reset ()
                        {
-                               index = 0;
+                               index = -1;
                        }
                }
 

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms_test.dll.sources
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms_test.dll.sources 
2006-11-05 14:02:13 UTC (rev 67375)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms_test.dll.sources 
2006-11-05 14:09:18 UTC (rev 67376)
@@ -66,6 +66,7 @@
 System.Windows.Forms/ToolBarButtonTest.cs
 System.Windows.Forms/ToolTipTest.cs
 System.Windows.Forms/TrackBarTest.cs
+System.Windows.Forms/TreeNodeCollectionTest.cs
 System.Windows.Forms/TreeNodeTest.cs
 System.Windows.Forms/TreeViewTest.cs
 System.Windows.Forms/UpDownTest.cs

Modified: 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog   
2006-11-05 14:02:13 UTC (rev 67375)
+++ trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog   
2006-11-05 14:09:18 UTC (rev 67376)
@@ -16,6 +16,10 @@
 
 2006-11-04  Gert Driesen  <[EMAIL PROTECTED]>
 
+       * TreeNodeCollectionTest.cs: Added tests for TreeNodeCollection.
+
+2006-11-04  Gert Driesen  <[EMAIL PROTECTED]>
+
        * ComboBoxTests.cs: Moved to correct namespace. Added test for bug
        #79812. Added (NotWorking) SelectedText tests.
 

Added: 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/TreeNodeCollectionTest.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/TreeNodeCollectionTest.cs
   2006-11-05 14:02:13 UTC (rev 67375)
+++ 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/TreeNodeCollectionTest.cs
   2006-11-05 14:09:18 UTC (rev 67376)
@@ -0,0 +1,115 @@
+using System;
+using System.Collections;
+using System.Drawing;
+using System.Windows.Forms;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Windows.Forms
+{
+       [TestFixture]
+       public class TreeNodeCollectionTest
+       {
+               [Test]
+               public void Remove ()
+               {
+                       TreeView tv = new TreeView ();
+                       TreeNode nodeA = tv.Nodes.Add ("A");
+                       TreeNode nodeB = tv.Nodes.Add ("B");
+                       TreeNode nodeC = tv.Nodes.Add ("C");
+                       Assert.AreEqual (3, tv.Nodes.Count, "#A1");
+                       Assert.AreSame (nodeA, tv.Nodes [0], "#A2");
+                       Assert.AreSame (nodeB, tv.Nodes [1], "#A3");
+                       Assert.AreSame (nodeC, tv.Nodes [2], "#A3");
+                       tv.Nodes.Remove (nodeB);
+                       Assert.AreEqual (2, tv.Nodes.Count, "#B1");
+                       Assert.AreSame (nodeA, tv.Nodes [0], "#B2");
+                       Assert.AreSame (nodeC, tv.Nodes [1], "#B3");
+                       tv.Nodes.Remove (nodeA);
+                       Assert.AreEqual (1, tv.Nodes.Count, "#C1");
+                       Assert.AreSame (nodeC, tv.Nodes [0], "#C2");
+                       tv.Nodes.Remove (nodeC);
+                       Assert.AreEqual (0, tv.Nodes.Count, "#D1");
+               }
+
+               [Test]
+#if ONLY_1_1
+               [ExpectedException (typeof (NullReferenceException))]
+#endif
+               public void Remove_NotInCollection ()
+               {
+                       TreeView tv = new TreeView ();
+                       TreeNode nodeA = tv.Nodes.Add ("A");
+                       tv.Nodes.Remove (nodeA);
+                       tv.Nodes.Remove (nodeA);
+               }
+
+               [Test]
+               [ExpectedException (typeof (NullReferenceException))]
+               public void Remove_Null ()
+               {
+                       TreeView tv = new TreeView ();
+                       tv.Nodes.Remove (null);
+               }
+
+               [Test]
+               public void Enumerator_Reset ()
+               {
+                       TreeView tv = new TreeView ();
+                       TreeNode nodeA = tv.Nodes.Add ("A");
+                       IEnumerator enumerator = tv.Nodes.GetEnumerator ();
+                       Assert.IsNull (enumerator.Current, "#A1");
+                       Assert.IsTrue (enumerator.MoveNext (), "#A2");
+                       Assert.IsNotNull (enumerator.Current, "#A3");
+                       Assert.AreSame (nodeA, enumerator.Current, "#A4");
+                       Assert.IsFalse (enumerator.MoveNext (), "#A5");
+                       enumerator.Reset ();
+                       Assert.IsNull (enumerator.Current, "#B1");
+                       Assert.IsTrue (enumerator.MoveNext (), "#B2");
+                       Assert.IsNotNull (enumerator.Current, "#B3");
+                       Assert.AreSame (nodeA, enumerator.Current, "#B4");
+                       Assert.IsFalse (enumerator.MoveNext (), "#B5");
+               }
+
+               [Test]
+               public void Enumerator_MoveNext ()
+               {
+                       TreeView tv = new TreeView ();
+                       TreeNode nodeA = tv.Nodes.Add ("A");
+                       IEnumerator enumerator = tv.Nodes.GetEnumerator ();
+                       Assert.IsTrue (enumerator.MoveNext (), "#A1");
+                       Assert.IsFalse (enumerator.MoveNext (), "#A2");
+                       Assert.IsFalse (enumerator.MoveNext (), "#A3");
+
+                       tv = new TreeView ();
+                       enumerator = tv.Nodes.GetEnumerator ();
+                       Assert.IsFalse (enumerator.MoveNext (), "#B1");
+                       Assert.IsFalse (enumerator.MoveNext (), "#B2");
+               }
+
+               [Test]
+               public void Enumerator_Current ()
+               {
+                       TreeView tv = new TreeView ();
+                       TreeNode nodeA = tv.Nodes.Add ("A");
+                       TreeNode nodeB = tv.Nodes.Add ("B");
+                       IEnumerator enumerator = tv.Nodes.GetEnumerator ();
+                       Assert.IsNull (enumerator.Current, "#A1");
+                       enumerator.MoveNext ();
+                       Assert.IsNotNull (enumerator.Current, "#A2");
+                       Assert.AreSame (nodeA, enumerator.Current, "#A3");
+                       enumerator.MoveNext ();
+                       Assert.IsNotNull (enumerator.Current, "#A4");
+                       Assert.AreSame (nodeB, enumerator.Current, "#A5");
+                       enumerator.MoveNext ();
+                       Assert.IsNotNull (enumerator.Current, "#A6");
+                       Assert.AreSame (nodeB, enumerator.Current, "#A7");
+
+                       tv = new TreeView ();
+                       enumerator = tv.Nodes.GetEnumerator ();
+                       Assert.IsNull (enumerator.Current, "#B1");
+                       enumerator.MoveNext ();
+                       Assert.IsNull (enumerator.Current, "#B2");
+               }
+       }
+}


Property changes on: 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/TreeNodeCollectionTest.cs
___________________________________________________________________
Name: svn:eol-style
   + native

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to