2006-12-19 Daniel Nauck <dna@mono-project.de>
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ListViewGroupCollectionTest.cs
1 //
2 //  ListViewGroupCollectionTest.cs
3 //
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:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
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.
22 //
23 // Copyright (c) 2006 Daniel Nauck
24 //
25 // Author:
26 //      Daniel Nauck    (dna(at)mono-project(dot)de)
27
28 #if NET_2_0
29
30 using System;
31 using System.Windows.Forms;
32 using System.Drawing;
33 using System.Reflection;
34 using System.Collections;
35 using NUnit.Framework;
36
37 namespace MonoTests.System.Windows.Forms
38 {
39         [TestFixture]
40         public class ListViewGroupCollectionTest
41         {
42                 ListViewGroupCollection grpCol = null;
43
44                 [SetUp]
45                 public void SetUp()
46                 {
47                         ListView lv = new ListView ();
48                         grpCol = lv.Groups;
49                 }
50
51                 [Test]
52                 public void DefaultProperties ()
53                 {
54                         Assert.AreEqual (false, ((IList)grpCol).IsReadOnly, "#A1");
55                         Assert.AreEqual (false, ((IList)grpCol).IsFixedSize, "#A2");
56                         Assert.AreEqual (true, ((ICollection)grpCol).IsSynchronized, "#A3");
57                         Assert.AreEqual (grpCol, ((ICollection)grpCol).SyncRoot, "#A4");
58                         Assert.AreEqual (0, grpCol.Count, "#A5");
59                 }
60
61                 [Test]
62                 public void AddTest ()
63                 {
64                         grpCol.Add (new ListViewGroup ("Item1"));
65                         grpCol.Add (new ListViewGroup ("Item2"));
66                         Assert.AreEqual (2, grpCol.Count, "#B1");
67                 }
68
69                 [Test]
70                 public void ClearTest ()
71                 {
72                         grpCol.Add (new ListViewGroup ("Item1"));
73                         grpCol.Add (new ListViewGroup ("Item2"));
74                         grpCol.Clear ();
75                         Assert.AreEqual (0, grpCol.Count, "#C1");
76                 }
77
78                 [Test]
79                 public void ContainsTest ()
80                 {
81                         ListViewGroup obj = new ListViewGroup ("Item1");
82                         ListViewGroup obj2 = new ListViewGroup ("Item2");
83                         grpCol.Add (obj);
84                         Assert.AreEqual (true, grpCol.Contains (obj), "#D1");
85                         Assert.AreEqual (false, grpCol.Contains (obj2), "#D2");
86                 }
87
88                 [Test]
89                 public void IndexOfTest ()
90                 {
91                         ListViewGroup obj = new ListViewGroup ("Item1");
92                         ListViewGroup obj2 = new ListViewGroup ("Item2");
93                         grpCol.Add (obj);
94                         grpCol.Add (obj2);
95                         Assert.AreEqual (1, grpCol.IndexOf (obj2), "#E1");
96                 }
97
98                 [Test]
99                 public void RemoveTest ()
100                 {
101                         ListViewGroup obj = new ListViewGroup ("Item1");
102                         ListViewGroup obj2 = new ListViewGroup ("Item2");
103                         grpCol.Add (obj);
104                         grpCol.Add (obj2);
105                         grpCol.Remove (obj);
106                         Assert.AreEqual (1, grpCol.Count, "#F1");
107                 }
108
109                 [Test]
110                 public void RemoveAtTest ()
111                 {
112                         ListViewGroup obj = new ListViewGroup ("Item1");
113                         ListViewGroup obj2 = new ListViewGroup ("Item2");
114                         grpCol.Add (obj);
115                         grpCol.Add (obj2);
116                         grpCol.RemoveAt (0);
117                         Assert.AreEqual (1, grpCol.Count, "#G1");
118                         Assert.AreEqual (true, grpCol.Contains (obj2), "#G2");
119                 }
120
121                 [Test]
122                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
123                 public void IndexerOutOfRangeTest ()
124                 {
125                         grpCol.Add (new ListViewGroup ("Item1"));
126                         grpCol[10] = null;
127                 }
128
129                 [Test]
130                 public void IndexerOutOfRangeTest2()
131                 {   //.NET 2.0 don't throw a exception here
132                         grpCol.Add (new ListViewGroup ("Item1"));
133                         grpCol["TestItemThatDoesNotExist"] = null;
134                 }
135         }
136 }
137 #endif