2 // ListViewGroupTest.cs
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 // Copyright (c) 2006 Daniel Nauck
26 // Daniel Nauck (dna(at)mono-project(dot)de)
31 using System.Windows.Forms;
33 using System.Reflection;
34 using System.Collections;
35 using NUnit.Framework;
37 namespace MonoTests.System.Windows.Forms
40 public class ListViewGroupTest : TestHelper
45 protected override void SetUp () {
51 public void DefaultProperties ()
53 //default ListView properties for groups
54 Assert.AreEqual (true, lv.ShowGroups, "#A1");
55 Assert.AreEqual (true, (lv.Groups != null), "#A2");
56 Assert.AreEqual (0, lv.Groups.Count, "#A3");
58 //default ListViewGroup properties
59 ListViewGroup lg1 = new ListViewGroup ();
60 Assert.AreEqual ("ListViewGroup", lg1.Header, "#A4");
61 Assert.AreEqual (null, lg1.Name, "#A5");
62 Assert.AreEqual (HorizontalAlignment.Left, lg1.HeaderAlignment, "#A6");
63 Assert.AreEqual (0, lg1.Items.Count, "#A7");
64 Assert.AreEqual (null, lg1.ListView, "#A8");
65 Assert.AreEqual (null, lg1.Tag, "#A9");
66 Assert.AreEqual (lg1.Header, lg1.ToString(), "#A10");
70 public void AddTest ()
72 ListViewGroup lg1 = new ListViewGroup ();
73 lg1.Items.Add ("Item1");
74 Assert.AreEqual (1, lg1.Items.Count, "#B1");
75 Assert.AreEqual (null, lg1.Items[0].ListView, "#B2");
78 Assert.AreEqual (null, lg1.Items[0].ListView, "#B3");
79 Assert.AreEqual (false, lv.Items.Contains(lg1.Items[0]), "#B4");
81 ListViewItem lvi = lg1.Items.Add ("Item1");
82 Assert.AreEqual (null, lvi.ListView, "#C1");
83 Assert.AreEqual (lg1, lvi.Group, "#C2");
87 public void RemoveTest ()
89 ListViewGroup lg1 = new ListViewGroup ();
90 lg1.Items.Add ("Item1");
92 lv.Groups.Remove (lg1);
94 Assert.AreEqual (1, lg1.Items.Count, "#C1");
95 Assert.AreEqual (0, lv.Items.Count, "#C2");
96 Assert.AreEqual (false, lv.Items.Contains (lg1.Items [0]), "#C3");
100 ListViewItem lvi = lv.Items.Add ("Item1");
103 Assert.AreEqual (1, lg1.Items.Count, "#D1");
104 Assert.AreEqual (1, lv.Items.Count, "#D2");
105 Assert.AreEqual (lv, lvi.ListView, "#D3");
106 Assert.AreEqual (lg1, lvi.Group, "#D4");
108 lg1.Items.Remove (lvi);
110 Assert.AreEqual (0, lg1.Items.Count, "#E1");
111 Assert.AreEqual (1, lv.Items.Count, "#E2");
112 Assert.AreEqual (lv, lvi.ListView, "#E3");
113 Assert.AreEqual (null, lvi.Group, "#E4");