[Mono-dev] Fix for failing TreeNode tests
Dieter Bremes
dbjobs at snafu.de
Sat Nov 26 14:55:40 EST 2005
Hi,
below are 2 fixes + an additional test for the TreeNode's FullPath and
Index properties.
I also added the namespace for TreeNodeTest but didn't update the
indentation because it would obscure the diff.
Dieter
* TreeNode.cs : Fixed bugs that caused FullPathTest + Traverse to fail.
* TreeNodeTest.cs : Added namespace + SingleNodeIndexTest.
Fixed warning CS0219.
Index: System.Windows.Forms/TreeNode.cs
===================================================================
--- System.Windows.Forms/TreeNode.cs (Revision 53205)
+++ System.Windows.Forms/TreeNode.cs (Arbeitskopie)
@@ -199,7 +199,7 @@
public string FullPath {
get {
- if (tree_view == null)
+ if (TreeView == null)
throw new Exception ("No TreeView associated");
StringBuilder builder = new StringBuilder ();
@@ -498,9 +498,10 @@
public int Index {
get {
- if (parent == null)
- return -1;
- return parent.Nodes.IndexOf (this);
+ if (parent != null)
+ return parent.Nodes.IndexOf (this);
+ else
+ return 0;
}
}
Index: Test/System.Windows.Forms/TreeNodeTest.cs
===================================================================
--- Test/System.Windows.Forms/TreeNodeTest.cs (Revision 53205)
+++ Test/System.Windows.Forms/TreeNodeTest.cs (Arbeitskopie)
@@ -1,7 +1,11 @@
using System;
using NUnit.Framework;
using System.Windows.Forms;
+using SystemDrawingNamespace = System.Drawing; // Prevent CS0234
+namespace MonoTests.System.Windows.Forms
+{
+
[TestFixture]
public class TreeNodeTest {
@@ -100,6 +104,9 @@
public void FullPathException ()
{
string s = new TreeNode ("").FullPath;
+ // Prevent CS0219, will never write anything
+ // due to previous statement throwing Exception
+ Console.WriteLine(s);
}
[Test]
@@ -126,8 +133,8 @@
TreeNode orig = new TreeNode ("text", 2, 3, new TreeNode [] { new
TreeNode ("child", 22, 33) });
orig.Tag = FlatStyle.Flat;
orig.Checked = true;
- orig.BackColor = System.Drawing.Color.AliceBlue;
- orig.ForeColor = System.Drawing.Color.Beige;
+ orig.BackColor = SystemDrawingNamespace.Color.AliceBlue;
+ orig.ForeColor = SystemDrawingNamespace.Color.Beige;
TreeNode clone = (TreeNode)orig.Clone ();
Assert.AreEqual ("text", clone.Text, "#1");
@@ -138,8 +145,20 @@
Assert.IsTrue (clone.Checked, "#6");
Assert.AreEqual ("child", clone.Nodes [0].Text, "#10");
Assert.AreEqual (22, clone.Nodes [0].ImageIndex, "#11");
- Assert.AreEqual (System.Drawing.Color.AliceBlue, clone.BackColor, "#12");
- Assert.AreEqual (System.Drawing.Color.Beige, clone.ForeColor, "#13");
+ Assert.AreEqual (SystemDrawingNamespace.Color.AliceBlue,
clone.BackColor, "#12");
+ Assert.AreEqual (SystemDrawingNamespace.Color.Beige, clone.ForeColor,
"#13");
}
+ [Test]
+ public void SingleNodeIndexTest ()
+ {
+ TreeNode tn_1 = new TreeNode ("A");
+ Assert.AreEqual (0, tn_1.Index, "#1");
+ TreeView tv = new TreeView ();
+ tv.Nodes.Add (tn_1);
+ Assert.AreEqual (0, tn_1.Index, "#2");
+ }
+
+}
+
}
\ No newline at end of file
More information about the Mono-devel-list
mailing list