X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FManaged.Windows.Forms%2FTest%2FSystem.Windows.Forms%2FTreeViewTest.cs;h=e812db6bab059484d5e97a1a268717dd7689ab08;hb=788c933c5194f7f600ef6d0bbc2d98a660e7984c;hp=2b83bbfa3039ccfc771cedab32cbb14289dee94c;hpb=53e266903ec6b2d822cf5b0c566f6374df5307a4;p=mono.git diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/TreeViewTest.cs b/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/TreeViewTest.cs index 2b83bbfa303..e812db6bab0 100644 --- a/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/TreeViewTest.cs +++ b/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/TreeViewTest.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Drawing; +using System.Globalization; using System.Windows.Forms; using NUnit.Framework; @@ -10,6 +11,14 @@ namespace MonoTests.System.Windows.Forms [TestFixture] public class TreeViewTest { + [Test] // bug #80620 + public void ClientRectangle_Borders () + { + TreeView tv = new TreeView (); + tv.CreateControl (); + Assert.AreEqual (tv.ClientRectangle, new TreeView ().ClientRectangle); + } + [Test] public void DefaultCtor () { @@ -54,6 +63,151 @@ namespace MonoTests.System.Windows.Forms Assert.AreEqual (al [1], tv.Nodes [1], "A2"); Assert.AreEqual (al [2], tv.Nodes [2], "A3"); } + + [Test] + public void ExpandAll_Flat_Created () + { + TreeView tv = new TreeView (); + tv.Size = new Size (300, 100); + + for (int i = 0; i <= 100; i++) + tv.Nodes.Add (i.ToString (CultureInfo.InvariantCulture)); + + Form form = new Form (); + form.ShowInTaskbar = false; + form.Controls.Add (tv); + form.Show (); + + Assert.IsFalse (tv.Nodes [0].IsExpanded, "#A1"); + Assert.IsFalse (tv.Nodes [99].IsExpanded, "#A2"); + + Assert.IsTrue (tv.Nodes [0].IsVisible, "#B1"); + Assert.IsFalse (tv.Nodes [99].IsVisible, "#B2"); + + tv.ExpandAll (); + + Assert.IsFalse (tv.Nodes [0].IsExpanded, "#C1"); + Assert.IsFalse (tv.Nodes [99].IsExpanded, "#C2"); + + Assert.IsTrue (tv.Nodes [0].IsVisible, "#D1"); + Assert.IsFalse (tv.Nodes [99].IsVisible, "#D2"); + + form.Close (); + } + + [Test] + public void ExpandAll_Tree_Created () + { + TreeView tv = new TreeView (); + tv.Size = new Size (300, 100); + + for (int i = 0; i <= 100; i++) { + TreeNode node = tv.Nodes.Add (i.ToString (CultureInfo.InvariantCulture)); + node.Nodes.Add ("child"); + } + + Form form = new Form (); + form.ShowInTaskbar = false; + form.Controls.Add (tv); + form.Show (); + + Assert.IsFalse (tv.Nodes [0].IsExpanded, "#A1"); + Assert.IsFalse (tv.Nodes [99].IsExpanded, "#A2"); + + Assert.IsTrue (tv.Nodes [0].IsVisible, "#B1"); + Assert.IsFalse (tv.Nodes [99].IsVisible, "#B2"); + + tv.ExpandAll (); + + Assert.IsTrue (tv.Nodes [0].IsExpanded, "#C1"); + Assert.IsTrue (tv.Nodes [99].IsExpanded, "#C2"); + + Assert.IsFalse (tv.Nodes [0].IsVisible, "#D1"); + Assert.IsTrue (tv.Nodes [99].IsVisible, "#D2"); + + form.Close (); + } + + [Test] + public void ExpandAll_Flat_NotCreated () + { + TreeView tv = new TreeView (); + tv.Size = new Size (300, 100); + + for (int i = 0; i <= 100; i++) + tv.Nodes.Add (i.ToString (CultureInfo.InvariantCulture)); + + Assert.IsFalse (tv.Nodes [0].IsExpanded, "#A1"); + Assert.IsFalse (tv.Nodes [99].IsExpanded, "#A2"); + + Assert.IsFalse (tv.Nodes [0].IsVisible, "#B1"); + Assert.IsFalse (tv.Nodes [99].IsVisible, "#B2"); + + tv.ExpandAll (); + + Assert.IsTrue (tv.Nodes [0].IsExpanded, "#C1"); + Assert.IsTrue (tv.Nodes [99].IsExpanded, "#C2"); + + Assert.IsFalse (tv.Nodes [0].IsVisible, "#D1"); + Assert.IsFalse (tv.Nodes [99].IsVisible, "#D2"); + + Form form = new Form (); + form.ShowInTaskbar = false; + form.Controls.Add (tv); + form.Show (); + + Assert.IsFalse (tv.Nodes [0].IsExpanded, "#E1"); + Assert.IsFalse (tv.Nodes [99].IsExpanded, "#E2"); + + Assert.IsTrue (tv.Nodes [0].IsVisible, "#F1"); + Assert.IsFalse (tv.Nodes [99].IsVisible, "#F2"); + + form.Dispose (); + } + + [Test] // bug #80284 + public void ExpandAll_Tree_NotCreated () + { + TreeView tv = new TreeView (); + tv.Size = new Size (300, 100); + + for (int i = 0; i <= 100; i++) { + TreeNode node = tv.Nodes.Add (i.ToString (CultureInfo.InvariantCulture)); + node.Nodes.Add ("child"); + } + + Assert.IsFalse (tv.Nodes [0].IsExpanded, "#A1"); + Assert.IsFalse (tv.Nodes [99].IsExpanded, "#A2"); + + Assert.IsFalse (tv.Nodes [0].IsVisible, "#B1"); + Assert.IsFalse (tv.Nodes [99].IsVisible, "#B2"); + + tv.ExpandAll (); + + Assert.IsTrue (tv.Nodes [0].IsExpanded, "#C1"); + Assert.IsTrue (tv.Nodes [99].IsExpanded, "#C2"); + + Assert.IsFalse (tv.Nodes [0].IsVisible, "#D1"); + Assert.IsFalse (tv.Nodes [99].IsVisible, "#D2"); + + Form form = new Form (); + form.ShowInTaskbar = false; + form.Controls.Add (tv); + form.Show (); + + Assert.IsTrue (tv.Nodes [0].IsExpanded, "#E1"); + Assert.IsTrue (tv.Nodes [99].IsExpanded, "#E2"); + +#if NET_2_0 + Assert.IsTrue (tv.Nodes [0].IsVisible, "#F1"); + Assert.IsFalse (tv.Nodes [99].IsVisible, "#F2"); +#else + Assert.IsFalse (tv.Nodes [0].IsVisible, "#F1"); + Assert.IsTrue (tv.Nodes [99].IsVisible, "#F2"); +#endif + + form.Dispose (); + } } [TestFixture] @@ -118,7 +272,6 @@ namespace MonoTests.System.Windows.Forms } [Test] - [Category ("NotWorking")] public void SelectBeforeCreationOfHandle () { TreeView tvw = new TreeView (); @@ -152,10 +305,10 @@ namespace MonoTests.System.Windows.Forms Assert.IsFalse (nodeA.IsSelected, "#C5"); Assert.IsTrue (nodeB.IsSelected, "#C6"); Assert.AreSame (nodeB, tvw.SelectedNode, "#C7"); + form.Close (); } [Test] - [Category ("NotWorking")] public void CancelAfterCreationOfHandle () { TreeView tvw = new TreeView (); @@ -186,6 +339,7 @@ namespace MonoTests.System.Windows.Forms Assert.AreSame (nodeB, cancelEventArgs.Node, "#B5"); Assert.IsFalse (nodeB.IsSelected, "#B6"); Assert.IsNull (tvw.SelectedNode, "#B7"); + form.Close (); } [Test] @@ -221,4 +375,181 @@ namespace MonoTests.System.Windows.Forms Assert.AreSame (nodeB, tvw.SelectedNode, "#B7"); } } + + [TestFixture] + public class AfterSelectEvent + { + [SetUp] + public void SetUp () + { + afterSelect = 0; + } + + [Test] // bug #81319 + [Category ("NotWorking")] + public void SelectedNode_Created () + { + TreeView tv = new TreeView (); + tv.AfterSelect += new TreeViewEventHandler (TreeView_AfterSelect); + TreeNode one = new TreeNode ("one"); + TreeNode two = new TreeNode ("two"); + + tv.Nodes.Add (one); + tv.Nodes.Add (two); + + Form form = new Form (); + form.ShowInTaskbar = false; + form.Controls.Add (tv); + form.Show (); + + Assert.IsNotNull (tv.SelectedNode, "#A1"); + Assert.AreSame (one, tv.SelectedNode, "#A2"); + Assert.IsTrue (one.IsSelected, "#A3"); + Assert.IsFalse (two.IsSelected, "#A4"); + Assert.AreEqual (1, afterSelect, "#A5"); + + tv.SelectedNode = null; + Assert.IsNull (tv.SelectedNode, "#C1"); + Assert.IsFalse (one.IsSelected, "#C2"); + Assert.IsFalse (two.IsSelected, "#C3"); + Assert.AreEqual (1, afterSelect, "#C4"); + + tv.SelectedNode = two; + Assert.IsNotNull (tv.SelectedNode, "#D1"); + Assert.AreSame (two, tv.SelectedNode, "#D2"); + Assert.IsFalse (one.IsSelected, "#D3"); + Assert.IsTrue (two.IsSelected, "#D4"); + Assert.AreEqual (2, afterSelect, "#D5"); + + form.Dispose (); + } + + [Test] + public void SelectedNode_NotCreated () + { + TreeView tv = new TreeView (); + tv.AfterSelect += new TreeViewEventHandler (TreeView_AfterSelect); + TreeNode one = new TreeNode ("one"); + TreeNode two = new TreeNode ("two"); + + tv.Nodes.Add (one); + tv.Nodes.Add (two); + + Assert.IsNull (tv.SelectedNode, "#A1"); + Assert.IsFalse (one.IsSelected, "#A2"); + Assert.IsFalse (two.IsSelected, "#A3"); + Assert.AreEqual (0, afterSelect, "#A4"); + + tv.SelectedNode = two; + Assert.IsNotNull (tv.SelectedNode, "#B1"); + Assert.AreSame (two, tv.SelectedNode, "#B2"); + Assert.IsFalse (one.IsSelected, "#B3"); + Assert.IsFalse (two.IsSelected, "#B4"); + Assert.AreEqual (0, afterSelect, "#B5"); + + tv.SelectedNode = null; + Assert.IsNull (tv.SelectedNode, "#C1"); + Assert.IsFalse (one.IsSelected, "#C2"); + Assert.IsFalse (two.IsSelected, "#C3"); + Assert.AreEqual (0, afterSelect, "#C4"); + + tv.SelectedNode = one; + Assert.IsNotNull (tv.SelectedNode, "#D1"); + Assert.AreSame (one, tv.SelectedNode, "#D2"); + Assert.IsFalse (one.IsSelected, "#D3"); + Assert.IsFalse (two.IsSelected, "#D4"); + Assert.AreEqual (0, afterSelect, "#D5"); + } + + void TreeView_AfterSelect (object sender, TreeViewEventArgs e) + { + afterSelect++; + } + + int afterSelect; + } + +#if NET_2_0 + [TestFixture] + public class TreeViewNodeSorterTest { + static bool node_sorter_called; + + [Test] + public void SortedAfterTreeViewNodeSorterIsSetToSomething() { + TreeView t = new TreeView(); + t.TreeViewNodeSorter = new NodeSorter(); + Assert.IsTrue(t.Sorted); + } + + [Test] + public void SortedAfterTreeViewNodeSorterIsSetToNull() { + TreeView t = new TreeView(); + t.TreeViewNodeSorter = null; + Assert.IsFalse(t.Sorted); + } + + [Test] + public void NormalTreeViewNodeSorter() { + TreeView t = new TreeView(); + t.Nodes.Add("2"); + t.Nodes.Add("1"); + node_sorter_called = false; + t.TreeViewNodeSorter = new NodeSorter(); + Assert.IsTrue(node_sorter_called, "Node sorter called"); + Assert.IsTrue(t.Nodes[0].Text == "2", "Order"); + } + + [Test] + public void NormalSorted() { + TreeView t = new TreeView(); + t.Nodes.Add("2"); + t.Nodes.Add("1"); + t.Sorted = true; + Assert.IsTrue(t.Nodes[0].Text == "1", "Order"); + } + + [Test] + public void SortedDoesNotSortWhenTreeViewNodeSorterIsSet() { + TreeView t = new TreeView(); + t.Nodes.Add("2"); + t.Nodes.Add("1"); + t.TreeViewNodeSorter = new NodeSorter(); + t.Sorted = false; + t.Sorted = true; + Assert.IsTrue(t.Nodes[0].Text == "2", "Order"); + } + + [Test] + public void SortedDoesNotSortWhenItIsAlreadyTrue() { + TreeView t = new TreeView(); + t.Nodes.Add("2"); + t.Nodes.Add("1"); + t.TreeViewNodeSorter = new NodeSorter(); + t.TreeViewNodeSorter = null; + t.Sorted = true; + Assert.IsTrue(t.Nodes[0].Text == "2", "Order"); + } + + [Test] + public void SortedSorts() { + TreeView t = new TreeView(); + t.Nodes.Add("2"); + t.Nodes.Add("1"); + t.TreeViewNodeSorter = new NodeSorter(); + t.TreeViewNodeSorter = null; + t.Sorted = false; + t.Sorted = true; + Assert.IsTrue(t.Nodes[0].Text == "1", "Order"); + } + + class NodeSorter : IComparer { + public int Compare(object x, object y) { + node_sorter_called = true; + if (x == y) + return 0; + return ((TreeNode)x).Text == "2" ? -1 : 1; + } + } + } +#endif }