[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / AutoCompleteStringCollectionTest.cs
1 //
2 //  AutoCompleteStringCollectionTest.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
29 using System;
30 using System.Windows.Forms;
31 using System.Drawing;
32 using System.Reflection;
33 using System.Collections;
34 using System.ComponentModel;
35 using NUnit.Framework;
36
37 namespace MonoTests.System.Windows.Forms
38 {
39         [TestFixture]
40         public class AutoCompleteStringCollectionTest : TestHelper
41         {
42                 AutoCompleteStringCollection autoCol = null;
43                 private int add_event = 0;
44                 private int refresh_event = 0;
45                 private int remove_event = 0;
46                 private string value_event = null;
47
48                 [SetUp]
49                 protected override void SetUp ()
50                 {
51                         autoCol = new AutoCompleteStringCollection ();
52                         autoCol.CollectionChanged += new CollectionChangeEventHandler (AutoColChanged);
53                         add_event = 0;
54                         refresh_event = 0;
55                         remove_event = 0;
56                         value_event = "unknown item";
57                         base.SetUp ();
58                 }
59
60                 private void AutoColChanged(object sender, CollectionChangeEventArgs e)
61                 {
62                         switch (e.Action)
63                         {
64                                 case CollectionChangeAction.Add:
65                                         add_event++;
66                                         value_event = (string)e.Element;
67                                         break;
68                                 case CollectionChangeAction.Refresh:
69                                         refresh_event++;
70                                         value_event = (string)e.Element;
71                                         break;
72                                 case CollectionChangeAction.Remove:
73                                         remove_event++;
74                                         value_event = (string)e.Element;
75                                         break;
76                         }
77                 }
78
79                 [Test]
80                 public void DefaultProperties ()
81                 {
82                         Assert.AreEqual (false, autoCol.IsReadOnly, "#A1");
83                         Assert.AreEqual (false, ((IList)autoCol).IsFixedSize, "#A2");
84                         Assert.AreEqual (false, autoCol.IsSynchronized, "#A3");
85                         Assert.AreEqual (autoCol, autoCol.SyncRoot, "#A4");
86                         Assert.AreEqual (0, autoCol.Count, "#A5");
87                 }
88         
89                 [Test]
90                 public void AddTest ()
91                 {
92                         int item1 = autoCol.Add ("Item1");
93                         Assert.AreEqual (1, add_event, "#B1");
94                         Assert.AreEqual ("Item1", value_event, "#B2");
95                         int item2 = autoCol.Add ("Item2");
96                         Assert.AreEqual (2, add_event, "#B3");
97                         Assert.AreEqual ("Item2", value_event, "#B4");
98
99                         Assert.AreEqual (2, autoCol.Count, "#B5");
100                         Assert.AreEqual ("Item1", autoCol[item1], "#B6");
101                         Assert.AreEqual ("Item2", autoCol[item2], "#B7");
102                 }
103         
104                 [Test]
105                 public void ClearTest ()
106                 {
107                         autoCol.Add ("Item1");
108                         autoCol.Add ("Item2");
109                         autoCol.Clear ();
110                         Assert.AreEqual (1, refresh_event, "#C1");
111                         Assert.AreEqual (null, value_event, "#C2");
112                         Assert.AreEqual (0, autoCol.Count, "#C3");
113                 }
114         
115                 [Test]
116                 public void ContainsTest ()
117                 {
118                         autoCol.Add ("Item1");
119                         Assert.AreEqual (true, autoCol.Contains("Item1"), "#D1");
120                         Assert.AreEqual (false, autoCol.Contains("Item2"), "#D2");
121                 }
122         
123                 [Test]
124                 public void IndexOfTest ()
125                 {
126                         autoCol.Add ("Item1");
127                         autoCol.Add ("Item2");
128                         Assert.AreEqual (1, autoCol.IndexOf("Item2"), "#E1");
129                 }
130         
131                 [Test]
132                 public void RemoveTest ()
133                 {
134                         autoCol.Add ("Item1");
135                         autoCol.Add ("Item2");
136                         autoCol.Remove ("Item1");
137                         Assert.AreEqual(1, remove_event, "#F1");
138                         Assert.AreEqual("Item1", value_event, "#F2");
139                         Assert.AreEqual (1, autoCol.Count, "#F3");
140                         Assert.AreEqual ("Item2", autoCol[0], "#F4");
141                 }
142         
143                 [Test]
144                 public void RemoveAtTest ()
145                 {
146                         autoCol.Add ("Item1");
147                         autoCol.Add ("Item2");
148                         autoCol.RemoveAt (0);
149                         Assert.AreEqual(1, remove_event, "#G1");
150                         Assert.AreEqual("Item1", value_event, "#G2");
151                         Assert.AreEqual (1, autoCol.Count, "#G3");
152                         Assert.AreEqual (true, autoCol.Contains("Item2"), "#G4");
153                 }
154         
155                 [Test]
156                 public void AddRangeTest ()
157                 {
158                         string[] values = new string[] { "Item1", "Item2", "Item3", "Item4" };
159                         autoCol.Add ("Item5");
160                         autoCol.AddRange (values);
161                         Assert.AreEqual(1, refresh_event, "#E1");
162                         Assert.AreEqual(null, value_event, "#E2");
163                         Assert.AreEqual (5, autoCol.Count, "#E3");
164                         Assert.AreEqual (true, autoCol.Contains("Item1"), "#E4");
165                         Assert.AreEqual (true, autoCol.Contains("Item2"), "#E5");
166                         Assert.AreEqual (true, autoCol.Contains("Item3"), "#E6");
167                         Assert.AreEqual (true, autoCol.Contains("Item4"), "#E7");
168                         Assert.AreEqual (true, autoCol.Contains("Item5"), "#E8");
169                 }
170
171                 [Test]
172                 [ExpectedException (typeof (ArgumentNullException))]
173                 public void AddRangeNullTest ()
174                 {
175                         string[] values = null;
176                         autoCol.AddRange (values);
177                 }
178
179                 [Test]
180                 public void AddTest_Junk ()
181                 {
182                         autoCol.Add (null);
183                         Assert.AreEqual (1, autoCol.Count, "#F1");
184                         autoCol.Add (null);
185                         Assert.AreEqual (2, autoCol.Count, "#F2");
186                         Assert.AreEqual (true, autoCol.Contains(null), "#F3");
187                         Assert.AreEqual (0, autoCol.IndexOf(null), "#F4");
188                         autoCol.Remove (null);
189                         Assert.AreEqual (1, autoCol.Count, "#F5");
190                         autoCol[0] = "Item1";
191                         autoCol[0] = null;
192                         Assert.AreEqual (null, autoCol[0], "#F6");
193                 }
194
195                 [Test]
196                 public void IndexerTest()
197                 {
198                         autoCol.Add("Item1");
199                         autoCol[0] = "NewItem1";
200
201                         Assert.AreEqual(1, remove_event, "#G1");
202                         Assert.AreEqual(2, add_event, "#G2");
203                 }
204         }
205 }