2 // ListViewGroupCollectionTest.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)
27 // Carlos Alberto Cortez <calberto.cortez@gmail.com>
32 using System.Windows.Forms;
34 using System.Reflection;
35 using System.Collections;
36 using NUnit.Framework;
38 namespace MonoTests.System.Windows.Forms
41 public class ListViewGroupCollectionTest : TestHelper
43 ListViewGroupCollection grpCol = null;
47 protected override void SetUp () {
54 public void DefaultProperties ()
56 Assert.AreEqual (false, ((IList)grpCol).IsReadOnly, "#A1");
57 Assert.AreEqual (false, ((IList)grpCol).IsFixedSize, "#A2");
58 Assert.AreEqual (true, ((ICollection)grpCol).IsSynchronized, "#A3");
59 Assert.AreEqual (grpCol, ((ICollection)grpCol).SyncRoot, "#A4");
60 Assert.AreEqual (0, grpCol.Count, "#A5");
64 public void AddTest ()
66 ListViewGroup group1 = new ListViewGroup ("Item1");
67 ListViewGroup group2 = new ListViewGroup ("Item2");
71 Assert.AreEqual (2, grpCol.Count, "#B1");
72 Assert.AreEqual (lv, group1.ListView, "#B2");
73 Assert.AreEqual (lv, group2.ListView, "#B2");
77 public void ClearTest ()
79 ListViewGroup group1 = new ListViewGroup ("Item1");
80 ListViewGroup group2 = new ListViewGroup ("Item2");
85 Assert.AreEqual (0, grpCol.Count, "#C1");
86 Assert.AreEqual (null, group1.ListView, "#C2");
87 Assert.AreEqual (null, group2.ListView, "#C3");
91 public void ContainsTest ()
93 ListViewGroup obj = new ListViewGroup ("Item1");
94 ListViewGroup obj2 = new ListViewGroup ("Item2");
96 Assert.AreEqual (true, grpCol.Contains (obj), "#D1");
97 Assert.AreEqual (false, grpCol.Contains (obj2), "#D2");
101 public void IndexOfTest ()
103 ListViewGroup obj = new ListViewGroup ("Item1");
104 ListViewGroup obj2 = new ListViewGroup ("Item2");
107 Assert.AreEqual (1, grpCol.IndexOf (obj2), "#E1");
111 public void RemoveTest ()
113 ListViewGroup obj = new ListViewGroup ("Item1");
114 ListViewGroup obj2 = new ListViewGroup ("Item2");
118 Assert.AreEqual (1, grpCol.Count, "#F1");
119 Assert.AreEqual (null, obj.ListView, "#F2");
120 Assert.AreEqual (lv, obj2.ListView, "#F3");
124 public void RemoveAtTest ()
126 ListViewGroup obj = new ListViewGroup ("Item1");
127 ListViewGroup obj2 = new ListViewGroup ("Item2");
131 Assert.AreEqual (1, grpCol.Count, "#G1");
132 Assert.AreEqual (true, grpCol.Contains (obj2), "#G2");
133 Assert.AreEqual (null, obj.ListView, "#G3");
134 Assert.AreEqual (lv, obj2.ListView, "#G4");
138 public void IndexerTest ()
140 ListViewGroup group1 = new ListViewGroup ("Item1");
143 Assert.AreEqual (group1, grpCol [0], "#A1");
144 Assert.AreEqual (lv, group1.ListView, "#A2");
145 Assert.AreEqual (1, grpCol.Count, "#A3");
148 Assert.AreEqual (null, grpCol [0], "#A4");
149 Assert.AreEqual (1, grpCol.Count, "#A5");
151 ListViewGroup group2 = new ListViewGroup ("Item2");
153 Assert.AreEqual (group2, grpCol [0], "#A6");
154 Assert.AreEqual (null, group2.ListView, "#A7");
155 Assert.AreEqual (1, grpCol.Count, "#A8");
159 public void IndexerNullTest ()
161 ListViewGroup group1 = new ListViewGroup ("Item1");
165 Assert.AreEqual (null, grpCol [0], "#A1");
166 Assert.AreEqual (1, grpCol.Count, "#A2");
169 /* There's an inconsistency between other collections using
170 * Key methods and the impl of this collection */
172 public void IndexerKeyTest ()
174 ListViewGroup group1 = new ListViewGroup ("Item1");
175 ListViewGroup group2 = new ListViewGroup ("Item2");
176 ListViewGroup group3 = new ListViewGroup ("Item3");
181 group1.Name = String.Empty;
185 Assert.AreEqual (group1, grpCol [String.Empty], "#A1"); /* Inconsistent */
186 Assert.AreEqual (null, grpCol [null], "#A2");
187 Assert.AreEqual (group2, grpCol ["A"], "#A3");
188 Assert.AreEqual (null, grpCol ["a"], "#A4"); /* Inconsistent, again */
190 ListViewGroup group4 = new ListViewGroup ("Item4");
193 grpCol [String.Empty] = group4;
194 Assert.AreEqual (group4, grpCol [0], "#A5"); /* First position */
195 Assert.AreEqual (group4, grpCol ["A"], "#A6");
196 Assert.AreEqual (null, group4.ListView, "#A7");
199 Assert.AreEqual (null, grpCol [0], "#A8");
203 [ExpectedException (typeof (ArgumentOutOfRangeException))]
204 public void IndexerOutOfRangeTest ()
206 grpCol.Add (new ListViewGroup ("Item1"));
211 public void IndexerOutOfRangeTest2()
212 { //.NET 2.0 don't throw a exception here
213 grpCol.Add (new ListViewGroup ("Item1"));
214 grpCol["TestItemThatDoesNotExist"] = null;
215 Assert.IsNotNull (grpCol [0], "#A1");