3 using System.Windows.Forms;
6 public class TreeNodeTest {
9 public void EmptyCtorTest ()
11 TreeNode tn = new TreeNode ();
12 Assert.AreEqual ("", tn.Text, "#1");
13 Assert.AreEqual (0, tn.Nodes.Count, "#2");
14 Assert.AreEqual (-1, tn.ImageIndex, "#3");
15 Assert.AreEqual (-1, tn.SelectedImageIndex, "#4");
17 // Set simple properties
19 Assert.AreEqual ("", tn.Text, "#5");
21 Assert.AreEqual (67, tn.ImageIndex, "#6");
22 tn.SelectedImageIndex = 99;
23 Assert.AreEqual (99, tn.SelectedImageIndex, "#7");
27 public void CtorTest () {
28 TreeNode tn = new TreeNode ("label1");
30 Assert.AreEqual ("label1", tn.Text);
31 Assert.AreEqual (0, tn.Nodes.Count);
32 Assert.AreEqual (-1, tn.ImageIndex, "II");
33 Assert.AreEqual (-1, tn.SelectedImageIndex, "SI");
35 Assert.IsNull (tn.FirstNode);
36 Assert.IsNull (tn.LastNode);
37 Assert.AreEqual ("", new TreeNode (null).Text);
41 public void CtorTest2 ()
43 TreeNode tn = new TreeNode ("a1", new TreeNode[] { new TreeNode ("aa1"), new TreeNode ("aa2") } );
45 Assert.AreEqual ("a1", tn.Text);
46 Assert.AreEqual (-1, tn.ImageIndex, "II");
47 Assert.AreEqual (-1, tn.SelectedImageIndex, "SI");
49 Assert.AreEqual ("aa1", tn.Nodes [0].Text, "#1");
50 Assert.AreEqual ("aa2", tn.Nodes [1].Text, "#2");
51 Assert.AreSame (tn.FirstNode, tn.Nodes [0], "#3");
52 Assert.AreSame (tn.LastNode, tn.Nodes [1], "#4");
56 public void CtorTest3 ()
58 TreeNode tn = new TreeNode ("a", 5, 9);
60 Assert.AreEqual ("a", tn.Text);
61 Assert.IsNotNull (tn.Nodes);
62 Assert.AreEqual (5, tn.ImageIndex);
63 Assert.AreEqual (9, tn.SelectedImageIndex);
64 Assert.AreEqual ("", new TreeNode (null, 0, 0).Text);
67 [Test, ExpectedException (typeof (ArgumentNullException))]
68 public void CtorException1 ()
70 new TreeNode ("", 1, 1, null);
73 [Test, ExpectedException (typeof (ArgumentNullException))]
74 public void CtorException2 () {
75 new TreeNode ("tt", null);
79 public void Traverse ()
81 TreeNode tn_1 = new TreeNode ("1");
82 TreeNode tn_2 = new TreeNode ("2");
83 TreeNode tn_3 = new TreeNode ("3");
84 TreeNode tn = new TreeNode ("lev1");
86 Assert.AreSame (tn, tn_1.Parent, "#1");
87 Assert.IsNull (tn_1.NextNode, "#2");
88 Assert.AreEqual (0, tn_1.Parent.Index, "#3");
90 Assert.IsNull (tn_1.NextNode.NextNode, "#33");
92 Assert.AreEqual (2, tn_3.Index, "#4");
94 Assert.AreEqual (3, tn.Nodes.Count, "#5");
95 Assert.AreSame (tn_2, tn_2.NextNode.PrevNode, "#6");
96 Assert.IsNull (tn_1.PrevNode, "#7");
99 [Test, ExpectedException (typeof (Exception))]
100 public void FullPathException ()
102 string s = new TreeNode ("").FullPath;
106 public void FullPathTest ()
108 TreeNode tn_1 = new TreeNode ("A");
109 TreeNode tn_2 = new TreeNode ("B");
110 tn_2.Nodes.Add (tn_1);
112 TreeView tv = new TreeView ();
114 tv.Nodes [0].Nodes.Add (tn_2);
116 Assert.AreEqual ("A", tn_1.FullPath, "#1");
117 Assert.AreEqual ("A", tv.Nodes[0].FullPath, "#2");
118 Assert.AreEqual (@"A\B", tn_2.FullPath, "#3");
119 tv.PathSeparator = "_separator_";
120 Assert.AreEqual ("A_separator_B", tn_2.FullPath, "#4");
124 public void CloneTest ()
126 TreeNode orig = new TreeNode ("text", 2, 3, new TreeNode [] { new TreeNode ("child", 22, 33) });
127 orig.Tag = FlatStyle.Flat;
129 orig.BackColor = System.Drawing.Color.AliceBlue;
130 orig.ForeColor = System.Drawing.Color.Beige;
132 TreeNode clone = (TreeNode)orig.Clone ();
133 Assert.AreEqual ("text", clone.Text, "#1");
134 Assert.AreEqual (2, clone.ImageIndex, "#2");
135 Assert.AreEqual (3, clone.SelectedImageIndex, "#3");
136 Assert.AreEqual (1, clone.Nodes.Count, "#4");
137 Assert.AreEqual (FlatStyle.Flat, clone.Tag, "#5");
138 Assert.IsTrue (clone.Checked, "#6");
139 Assert.AreEqual ("child", clone.Nodes [0].Text, "#10");
140 Assert.AreEqual (22, clone.Nodes [0].ImageIndex, "#11");
141 Assert.AreEqual (System.Drawing.Color.AliceBlue, clone.BackColor, "#12");
142 Assert.AreEqual (System.Drawing.Color.Beige, clone.ForeColor, "#13");