**** Merged from MCS ****
[mono-project.git] / mcs / class / System / Test / System.Collections.Specialized / StringCollectionTest.cs
blob483e0657f86e9a353c0d9dc9d8cde44416ea1db2
1 // System.Collections.Specialized.StringCollection.cs
2 //
3 // Authors:
4 // John Barnette (jbarn@httcb.net)
5 // Martin Willemoes Hansen (mwh@sysrq.dk)
6 //
7 // (C) Copyright 2001 John Barnette
8 // (C) Copyright 2003 Martin Willemoes Hansen
9 //
11 using NUnit.Framework;
12 using System.Collections.Specialized;
14 namespace MonoTests.System.Collections.Specialized {
16 [TestFixture]
17 public class StringCollectionTest {
19 private StringCollection sc;
20 string[] strings = {
21 "foo",
22 "bar",
23 "baz",
24 "john",
25 "paul",
26 "george",
27 "ringo"
30 [SetUp]
31 public void GetReady()
33 sc = new StringCollection();
34 sc.AddRange(strings);
37 // Simple Tests
38 [Test]
39 public void SimpleCount()
41 Assertion.Assert(sc.Count == 7);
44 [Test]
45 public void SimpleIsReadOnly()
47 Assertion.Assert(!sc.IsReadOnly);
50 [Test]
51 public void SimpleIsSynchronized()
53 Assertion.Assert(!sc.IsSynchronized);
56 [Test]
57 public void SimpleItemGet()
59 for(int i = 0; i < strings.Length; i++) {
60 Assertion.Assert(strings[i].Equals(sc[i]));
64 [Test]
65 public void SimpleItemSet()
67 sc[0] = "bob";
68 Assertion.Assert(sc[0].Equals("bob"));
71 [Test]
72 public void SimpleSyncRoot()
74 Assertion.Assert(sc.Equals(sc.SyncRoot));
77 [Test]
78 public void SimpleAdd()
80 int index = sc.Add("chuck");
81 Assertion.Assert(index == strings.Length);
82 Assertion.Assert(sc[strings.Length].Equals("chuck"));
86 [Test]
87 public void SimpleAddRange()
89 string[] newStrings = {
90 "peter",
91 "paul",
92 "mary"
95 int index = sc.Count;
96 sc.AddRange(newStrings);
98 Assertion.Assert(sc.Count == index + newStrings.Length);
100 for (int i = 0; i+index <= sc.Count-1; i++) {
101 Assertion.Assert(newStrings[i].Equals(sc[i+index]));
105 [Test]
106 public void SimpleClear()
108 sc.Clear();
109 Assertion.Assert(sc.Count == 0);
112 [Test]
113 public void SimpleContains()
115 Assertion.Assert(sc.Contains(strings[0]));
116 Assertion.Assert(!sc.Contains("NOT CONTAINED"));
119 [Test]
120 public void SimpleCopyTo()
122 string[] copyArray = new string[sc.Count];
123 sc.CopyTo(copyArray, 0);
124 for (int i = 0; i < copyArray.Length; i++) {
125 Assertion.Assert(copyArray[i] == sc[i]);
129 [Test]
130 public void SimpleGetEnumerator()
132 int index = 0;
133 foreach(string s in sc) {
134 Assertion.Assert(s.Equals(strings[index]));
135 index++;
139 [Test]
140 public void SimpleIndexOf()
142 Assertion.Assert(sc.IndexOf(strings[0]) == 0);
145 [Test]
146 public void SimpleInsert()
148 int index = 3;
149 int oldCount = sc.Count;
150 string before = sc[index - 1];
151 string current = sc[index];
152 string after = sc[index + 1];
153 string newStr = "paco";
155 sc.Insert(index, newStr);
157 Assertion.Assert(sc.Count == oldCount + 1);
158 Assertion.Assert(sc[index].Equals(newStr));
159 Assertion.Assert(sc[index-1].Equals(before));
160 Assertion.Assert(sc[index+1].Equals(current));
161 Assertion.Assert(sc[index+2].Equals(after));
164 [Test]
165 public void SimpleRemove()
167 int oldCount = sc.Count;
168 sc.Remove(strings[0]);
169 Assertion.Assert(oldCount == sc.Count + 1);
170 Assertion.Assert(!sc.Contains(strings[0]));
173 [Test]
174 public void SimpleRemoveAt()
176 int index = 3;
177 int oldCount = sc.Count;
178 string after = sc[index+1];
180 sc.RemoveAt(index);
181 Assertion.Assert(oldCount == sc.Count + 1);
182 Assertion.Assert(sc[index].Equals(after));