[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / class / System / Test / System.Collections.Specialized / StringCollectionTest.cs
blobdcd65daf52ab08a74f83ef7125c8c33b17a9e921
1 // System.Collections.Specialized.StringCollection.cs
2 //
3 // Authors:
4 // John Barnette (jbarn@httcb.net)
5 // Martin Willemoes Hansen (mwh@sysrq.dk)
6 // Sebastien Pouliot <sebastien@ximian.com>
7 //
8 // (C) Copyright 2001 John Barnette
9 // (C) Copyright 2003 Martin Willemoes Hansen
10 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
13 using NUnit.Framework;
14 using System.Collections;
15 using System.Collections.Specialized;
17 namespace MonoTests.System.Collections.Specialized {
19 [TestFixture]
20 public class StringCollectionTest {
22 private StringCollection sc;
23 string[] strings = {
24 "foo",
25 "bar",
26 "baz",
27 "john",
28 "paul",
29 "george",
30 "ringo"
33 [SetUp]
34 public void GetReady()
36 sc = new StringCollection();
37 sc.AddRange(strings);
40 // Simple Tests
41 [Test]
42 public void SimpleCount()
44 Assert.AreEqual(7, sc.Count);
47 [Test]
48 public void SimpleIsReadOnly()
50 Assert.IsFalse(sc.IsReadOnly);
53 [Test]
54 public void SimpleIsSynchronized()
56 Assert.IsFalse(sc.IsSynchronized);
59 [Test]
60 public void SimpleItemGet()
62 for(int i = 0; i < strings.Length; i++) {
63 Assert.AreEqual(strings[i], sc[i]);
67 [Test]
68 public void SimpleItemSet()
70 sc[0] = "bob";
71 Assert.AreEqual("bob", sc[0]);
74 [Test]
75 public void SimpleSyncRoot()
77 Assert.AreNotSame(sc, sc.SyncRoot);
80 [Test]
81 public void SimpleAdd()
83 int index = sc.Add("chuck");
84 Assert.AreEqual(strings.Length, index);
85 Assert.AreEqual("chuck", sc[strings.Length]);
88 [Test]
89 public void SimpleAddRange()
91 string[] newStrings = {
92 "peter",
93 "paul",
94 "mary"
97 int index = sc.Count;
98 sc.AddRange(newStrings);
100 Assert.AreEqual(index + newStrings.Length, sc.Count);
102 for (int i = 0; i+index <= sc.Count-1; i++) {
103 Assert.AreEqual(newStrings[i], sc[i+index]);
107 [Test]
108 public void SimpleClear()
110 sc.Clear();
111 Assert.AreEqual(0, sc.Count);
114 [Test]
115 public void SimpleContains()
117 Assert.IsTrue(sc.Contains(strings[0]));
118 Assert.IsFalse(sc.Contains("NOT CONTAINED"));
121 [Test]
122 public void SimpleCopyTo()
124 string[] copyArray = new string[sc.Count];
125 sc.CopyTo(copyArray, 0);
126 for (int i = 0; i < copyArray.Length; i++) {
127 Assert.AreEqual(copyArray[i], sc[i]);
131 [Test]
132 public void SimpleGetEnumerator()
134 int index = 0;
135 foreach(string s in sc) {
136 Assert.AreEqual(s, strings[index]);
137 index++;
141 [Test]
142 public void SimpleIndexOf()
144 Assert.AreEqual(0, sc.IndexOf(strings[0]));
147 [Test]
148 public void SimpleInsert()
150 int index = 3;
151 int oldCount = sc.Count;
152 string before = sc[index - 1];
153 string current = sc[index];
154 string after = sc[index + 1];
155 string newStr = "paco";
157 sc.Insert(index, newStr);
159 Assert.AreEqual(oldCount + 1, sc.Count);
160 Assert.AreEqual(newStr, sc[index]);
161 Assert.AreEqual(before, sc[index-1]);
162 Assert.AreEqual(current, sc[index+1]);
163 Assert.AreEqual(after, sc[index+2]);
166 [Test]
167 public void SimpleRemove()
169 int oldCount = sc.Count;
170 sc.Remove(strings[0]);
171 Assert.AreEqual(sc.Count + 1, oldCount);
172 Assert.IsFalse(sc.Contains(strings[0]));
175 [Test]
176 public void SimpleRemoveAt()
178 int index = 3;
179 int oldCount = sc.Count;
180 string after = sc[index+1];
182 sc.RemoveAt(index);
183 Assert.AreEqual(sc.Count + 1, oldCount);
184 Assert.AreEqual(after, sc[index]);
187 [Test]
188 public void IList ()
190 IList list = (IList) new StringCollection ();
191 Assert.AreEqual (0, list.Count, "Count-0");
192 Assert.IsFalse (list.IsFixedSize, "IsFixedSize");
193 Assert.IsFalse (list.IsFixedSize, "IsReadOnly");
195 list.Add ("a");
196 Assert.AreEqual (1, list.Count, "Count-1");
197 Assert.IsTrue (list.Contains ("a"), "Contains(b)");
198 Assert.IsFalse (list.Contains ("b"), "Contains(b)");
200 Assert.AreEqual (0, list.IndexOf ("a"), "IndexOf(a)");
201 Assert.AreEqual (-1, list.IndexOf ("b"), "IndexOf(b)");
203 list.Insert (0, "b");
204 Assert.AreEqual (2, list.Count, "Count-2");
205 list.Remove ("b");
206 Assert.AreEqual (1, list.Count, "Count-3");
208 list.Add ("b");
209 list.RemoveAt (0);
210 Assert.AreEqual (1, list.Count, "Count-4");
212 list.Clear ();
213 Assert.AreEqual (0, list.Count, "Count-5");
216 [Test]
217 public void ICollection ()
219 ICollection coll = (ICollection) new StringCollection ();
220 Assert.AreEqual (0, coll.Count, "Count");
221 Assert.IsNotNull (coll.GetEnumerator (), "GetEnumerator");
222 coll.CopyTo (new string[0], 0);
223 Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
224 Assert.IsNotNull (coll.SyncRoot, "SyncRoot");
227 [Test]
228 public void IEnumerable ()
230 IEnumerable e = (IEnumerable) new StringCollection ();
231 Assert.IsNotNull (e.GetEnumerator (), "GetEnumerator");