2010-04-06 Jb Evain <jbevain@novell.com>
[mcs.git] / class / Managed.Windows.Forms / Test / System.Windows.Forms / AutoCompleteStringCollectionTest.cs
blobac38f5e6666f511eb4acb9ecc2cef68ac0d27442
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.
23 // Copyright (c) 2006 Daniel Nauck
25 // Author:
26 // Daniel Nauck (dna(at)mono-project(dot)de)
28 #if NET_2_0
30 using System;
31 using System.Windows.Forms;
32 using System.Drawing;
33 using System.Reflection;
34 using System.Collections;
35 using System.ComponentModel;
36 using NUnit.Framework;
38 namespace MonoTests.System.Windows.Forms
40 [TestFixture]
41 public class AutoCompleteStringCollectionTest : TestHelper
43 AutoCompleteStringCollection autoCol = null;
44 private int add_event = 0;
45 private int refresh_event = 0;
46 private int remove_event = 0;
47 private string value_event = null;
49 [SetUp]
50 protected override void SetUp ()
52 autoCol = new AutoCompleteStringCollection ();
53 autoCol.CollectionChanged += new CollectionChangeEventHandler (AutoColChanged);
54 add_event = 0;
55 refresh_event = 0;
56 remove_event = 0;
57 value_event = "unknown item";
58 base.SetUp ();
61 private void AutoColChanged(object sender, CollectionChangeEventArgs e)
63 switch (e.Action)
65 case CollectionChangeAction.Add:
66 add_event++;
67 value_event = (string)e.Element;
68 break;
69 case CollectionChangeAction.Refresh:
70 refresh_event++;
71 value_event = (string)e.Element;
72 break;
73 case CollectionChangeAction.Remove:
74 remove_event++;
75 value_event = (string)e.Element;
76 break;
80 [Test]
81 public void DefaultProperties ()
83 Assert.AreEqual (false, autoCol.IsReadOnly, "#A1");
84 Assert.AreEqual (false, ((IList)autoCol).IsFixedSize, "#A2");
85 Assert.AreEqual (false, autoCol.IsSynchronized, "#A3");
86 Assert.AreEqual (autoCol, autoCol.SyncRoot, "#A4");
87 Assert.AreEqual (0, autoCol.Count, "#A5");
90 [Test]
91 public void AddTest ()
93 int item1 = autoCol.Add ("Item1");
94 Assert.AreEqual (1, add_event, "#B1");
95 Assert.AreEqual ("Item1", value_event, "#B2");
96 int item2 = autoCol.Add ("Item2");
97 Assert.AreEqual (2, add_event, "#B3");
98 Assert.AreEqual ("Item2", value_event, "#B4");
100 Assert.AreEqual (2, autoCol.Count, "#B5");
101 Assert.AreEqual ("Item1", autoCol[item1], "#B6");
102 Assert.AreEqual ("Item2", autoCol[item2], "#B7");
105 [Test]
106 public void ClearTest ()
108 autoCol.Add ("Item1");
109 autoCol.Add ("Item2");
110 autoCol.Clear ();
111 Assert.AreEqual (1, refresh_event, "#C1");
112 Assert.AreEqual (null, value_event, "#C2");
113 Assert.AreEqual (0, autoCol.Count, "#C3");
116 [Test]
117 public void ContainsTest ()
119 autoCol.Add ("Item1");
120 Assert.AreEqual (true, autoCol.Contains("Item1"), "#D1");
121 Assert.AreEqual (false, autoCol.Contains("Item2"), "#D2");
124 [Test]
125 public void IndexOfTest ()
127 autoCol.Add ("Item1");
128 autoCol.Add ("Item2");
129 Assert.AreEqual (1, autoCol.IndexOf("Item2"), "#E1");
132 [Test]
133 public void RemoveTest ()
135 autoCol.Add ("Item1");
136 autoCol.Add ("Item2");
137 autoCol.Remove ("Item1");
138 Assert.AreEqual(1, remove_event, "#F1");
139 Assert.AreEqual("Item1", value_event, "#F2");
140 Assert.AreEqual (1, autoCol.Count, "#F3");
141 Assert.AreEqual ("Item2", autoCol[0], "#F4");
144 [Test]
145 public void RemoveAtTest ()
147 autoCol.Add ("Item1");
148 autoCol.Add ("Item2");
149 autoCol.RemoveAt (0);
150 Assert.AreEqual(1, remove_event, "#G1");
151 Assert.AreEqual("Item1", value_event, "#G2");
152 Assert.AreEqual (1, autoCol.Count, "#G3");
153 Assert.AreEqual (true, autoCol.Contains("Item2"), "#G4");
156 [Test]
157 public void AddRangeTest ()
159 string[] values = new string[] { "Item1", "Item2", "Item3", "Item4" };
160 autoCol.Add ("Item5");
161 autoCol.AddRange (values);
162 Assert.AreEqual(1, refresh_event, "#E1");
163 Assert.AreEqual(null, value_event, "#E2");
164 Assert.AreEqual (5, autoCol.Count, "#E3");
165 Assert.AreEqual (true, autoCol.Contains("Item1"), "#E4");
166 Assert.AreEqual (true, autoCol.Contains("Item2"), "#E5");
167 Assert.AreEqual (true, autoCol.Contains("Item3"), "#E6");
168 Assert.AreEqual (true, autoCol.Contains("Item4"), "#E7");
169 Assert.AreEqual (true, autoCol.Contains("Item5"), "#E8");
172 [Test]
173 [ExpectedException (typeof (ArgumentNullException))]
174 public void AddRangeNullTest ()
176 string[] values = null;
177 autoCol.AddRange (values);
180 [Test]
181 public void AddTest_Junk ()
183 autoCol.Add (null);
184 Assert.AreEqual (1, autoCol.Count, "#F1");
185 autoCol.Add (null);
186 Assert.AreEqual (2, autoCol.Count, "#F2");
187 Assert.AreEqual (true, autoCol.Contains(null), "#F3");
188 Assert.AreEqual (0, autoCol.IndexOf(null), "#F4");
189 autoCol.Remove (null);
190 Assert.AreEqual (1, autoCol.Count, "#F5");
191 autoCol[0] = "Item1";
192 autoCol[0] = null;
193 Assert.AreEqual (null, autoCol[0], "#F6");
196 [Test]
197 public void IndexerTest()
199 autoCol.Add("Item1");
200 autoCol[0] = "NewItem1";
202 Assert.AreEqual(1, remove_event, "#G1");
203 Assert.AreEqual(2, add_event, "#G2");
207 #endif