3 using System.Windows.Forms;
4 using SystemDrawingNamespace = System.Drawing;
6 namespace MonoTests.System.Windows.Forms {
10 public class TreeNodeTest {
13 public void EmptyCtorTest ()
15 TreeNode tn = new TreeNode ();
16 Assert.AreEqual ("", tn.Text, "#1");
17 Assert.AreEqual (0, tn.Nodes.Count, "#2");
18 Assert.AreEqual (-1, tn.ImageIndex, "#3");
19 Assert.AreEqual (-1, tn.SelectedImageIndex, "#4");
21 // Set simple properties
23 Assert.AreEqual ("", tn.Text, "#5");
25 Assert.AreEqual (67, tn.ImageIndex, "#6");
26 tn.SelectedImageIndex = 99;
27 Assert.AreEqual (99, tn.SelectedImageIndex, "#7");
31 public void CtorTest () {
32 TreeNode tn = new TreeNode ("label1");
34 Assert.AreEqual ("label1", tn.Text);
35 Assert.AreEqual (0, tn.Nodes.Count);
36 Assert.AreEqual (-1, tn.ImageIndex, "II");
37 Assert.AreEqual (-1, tn.SelectedImageIndex, "SI");
39 Assert.IsNull (tn.FirstNode);
40 Assert.IsNull (tn.LastNode);
41 Assert.AreEqual ("", new TreeNode (null).Text);
45 public void CtorTest2 ()
47 TreeNode tn = new TreeNode ("a1", new TreeNode[] { new TreeNode ("aa1"), new TreeNode ("aa2") } );
49 Assert.AreEqual ("a1", tn.Text);
50 Assert.AreEqual (-1, tn.ImageIndex, "II");
51 Assert.AreEqual (-1, tn.SelectedImageIndex, "SI");
53 Assert.AreEqual ("aa1", tn.Nodes [0].Text, "#1");
54 Assert.AreEqual ("aa2", tn.Nodes [1].Text, "#2");
55 Assert.AreSame (tn.FirstNode, tn.Nodes [0], "#3");
56 Assert.AreSame (tn.LastNode, tn.Nodes [1], "#4");
60 public void CtorTest3 ()
62 TreeNode tn = new TreeNode ("a", 5, 9);
64 Assert.AreEqual ("a", tn.Text);
65 Assert.IsNotNull (tn.Nodes);
66 Assert.AreEqual (5, tn.ImageIndex);
67 Assert.AreEqual (9, tn.SelectedImageIndex);
68 Assert.AreEqual ("", new TreeNode (null, 0, 0).Text);
71 [Test, ExpectedException (typeof (ArgumentNullException))]
72 public void CtorException1 ()
74 new TreeNode ("", 1, 1, null);
77 [Test, ExpectedException (typeof (ArgumentNullException))]
78 public void CtorException2 () {
79 new TreeNode ("tt", null);
83 public void Traverse ()
85 TreeNode tn_1 = new TreeNode ("1");
86 TreeNode tn_2 = new TreeNode ("2");
87 TreeNode tn_3 = new TreeNode ("3");
88 TreeNode tn = new TreeNode ("lev1");
90 Assert.AreSame (tn, tn_1.Parent, "#1");
91 Assert.IsNull (tn_1.NextNode, "#2");
92 Assert.AreEqual (0, tn_1.Parent.Index, "#3");
94 Assert.IsNull (tn_1.NextNode.NextNode, "#33");
96 Assert.AreEqual (2, tn_3.Index, "#4");
98 Assert.AreEqual (3, tn.Nodes.Count, "#5");
99 Assert.AreSame (tn_2, tn_2.NextNode.PrevNode, "#6");
100 Assert.IsNull (tn_1.PrevNode, "#7");
103 [Test, ExpectedException (typeof (Exception))]
104 public void FullPathException ()
106 string s = new TreeNode ("").FullPath;
107 // Prevent CS0219, will never write anything
108 // due to previous statement throwing Exception
109 Console.WriteLine(s);
113 public void FullPathTest ()
115 TreeNode tn_1 = new TreeNode ("A");
116 TreeNode tn_2 = new TreeNode ("B");
117 tn_2.Nodes.Add (tn_1);
119 TreeView tv = new TreeView ();
121 tv.Nodes [0].Nodes.Add (tn_2);
123 Assert.AreEqual ("A", tn_1.FullPath, "#1");
124 Assert.AreEqual ("A", tv.Nodes[0].FullPath, "#2");
125 Assert.AreEqual (@"A\B", tn_2.FullPath, "#3");
126 tv.PathSeparator = "_separator_";
127 Assert.AreEqual ("A_separator_B", tn_2.FullPath, "#4");
131 public void CloneTest ()
133 TreeNode orig = new TreeNode ("text", 2, 3, new TreeNode [] { new TreeNode ("child", 22, 33) });
134 orig.Tag = FlatStyle.Flat;
136 orig.BackColor = SystemDrawingNamespace.Color.AliceBlue;
137 orig.ForeColor = SystemDrawingNamespace.Color.Beige;
139 TreeNode clone = (TreeNode)orig.Clone ();
140 Assert.AreEqual ("text", clone.Text, "#1");
141 Assert.AreEqual (2, clone.ImageIndex, "#2");
142 Assert.AreEqual (3, clone.SelectedImageIndex, "#3");
143 Assert.AreEqual (1, clone.Nodes.Count, "#4");
144 Assert.AreEqual (FlatStyle.Flat, clone.Tag, "#5");
145 Assert.IsTrue (clone.Checked, "#6");
146 Assert.AreEqual ("child", clone.Nodes [0].Text, "#10");
147 Assert.AreEqual (22, clone.Nodes [0].ImageIndex, "#11");
148 Assert.AreEqual (SystemDrawingNamespace.Color.AliceBlue, clone.BackColor, "#12");
149 Assert.AreEqual (SystemDrawingNamespace.Color.Beige, clone.ForeColor, "#13");
153 public void SingleNodeIndexTest ()
155 TreeNode tn_1 = new TreeNode ("A");
156 Assert.AreEqual (0, tn_1.Index, "#1");
157 TreeView tv = new TreeView ();
159 Assert.AreEqual (0, tn_1.Index, "#2");