Merge pull request #2396 from akoeplinger/flaky-osx-socket-test
[mono.git] / mcs / class / System / Test / System.CodeDom / CodeCommentStatementCollectionTest.cs
1 //
2 // CodeCommentStatementCollectionTest.cs 
3 //      - Unit tests for System.CodeDom.CodeCommentStatementCollection
4 //
5 // Author:
6 //      Gert Driesen  <drieseng@users.sourceforge.net>
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using NUnit.Framework;
31
32 using System;
33 using System.Collections;
34 using System.CodeDom;
35
36 namespace MonoTests.System.CodeDom {
37         [TestFixture]
38         public class CodeCommentStatementCollectionTest {
39                 [Test]
40                 public void Constructor0 ()
41                 {
42                         CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
43                         Assert.IsFalse (((IList) coll).IsFixedSize, "#1");
44                         Assert.IsFalse (((IList) coll).IsReadOnly, "#2");
45                         Assert.AreEqual (0, coll.Count, "#3");
46                         Assert.IsFalse (((ICollection) coll).IsSynchronized, "#4");
47                         Assert.IsNotNull (((ICollection) coll).SyncRoot, "#5");
48                 }
49
50                 [Test]
51                 public void Constructor1 ()
52                 {
53                         CodeCommentStatement ccs1 = new CodeCommentStatement ();
54                         CodeCommentStatement ccs2 = new CodeCommentStatement ();
55
56                         CodeCommentStatement[] statements = new CodeCommentStatement[] { ccs1, ccs2 };
57                         CodeCommentStatementCollection coll = new CodeCommentStatementCollection (
58                                 statements);
59
60                         Assert.AreEqual (2, coll.Count, "#1");
61                         Assert.AreEqual (0, coll.IndexOf (ccs1), "#2");
62                         Assert.AreEqual (1, coll.IndexOf (ccs2), "#3");
63                 }
64
65                 [Test]
66                 [ExpectedException (typeof (ArgumentNullException))]
67                 public void Constructor1_NullItem ()
68                 {
69                         CodeCommentStatement[] statements = new CodeCommentStatement[] { 
70                                 new CodeCommentStatement (), null };
71
72                         CodeCommentStatementCollection coll = new CodeCommentStatementCollection (
73                                 statements);
74                 }
75
76                 [Test]
77                 [ExpectedException (typeof (ArgumentNullException))]
78                 public void Constructor1_Null () {
79                         CodeCommentStatementCollection coll = new CodeCommentStatementCollection (
80                                 (CodeCommentStatement[]) null);
81                 }
82
83                 [Test]
84                 public void Constructor2 ()
85                 {
86                         CodeCommentStatement ccs1 = new CodeCommentStatement ();
87                         CodeCommentStatement ccs2 = new CodeCommentStatement ();
88
89                         CodeCommentStatementCollection c = new CodeCommentStatementCollection ();
90                         c.Add (ccs1);
91                         c.Add (ccs2);
92
93                         CodeCommentStatementCollection coll = new CodeCommentStatementCollection (c);
94                         Assert.AreEqual (2, coll.Count, "#1");
95                         Assert.AreEqual (0, coll.IndexOf (ccs1), "#2");
96                         Assert.AreEqual (1, coll.IndexOf (ccs2), "#3");
97                 }
98
99                 [Test]
100                 [ExpectedException (typeof (ArgumentNullException))]
101                 public void Constructor2_Null ()
102                 {
103                         CodeCommentStatementCollection coll = new CodeCommentStatementCollection (
104                                 (CodeCommentStatementCollection) null);
105                 }
106
107                 [Test]
108                 public void Add ()
109                 {
110                         CodeCommentStatement ccs1 = new CodeCommentStatement ();
111                         CodeCommentStatement ccs2 = new CodeCommentStatement ();
112
113                         CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
114                         Assert.AreEqual (0, coll.Add (ccs1), "#1");
115                         Assert.AreEqual (1, coll.Count, "#2");
116                         Assert.AreEqual (0, coll.IndexOf (ccs1), "#3");
117
118                         Assert.AreEqual (1, coll.Add (ccs2), "#4");
119                         Assert.AreEqual (2, coll.Count, "#5");
120                         Assert.AreEqual (1, coll.IndexOf (ccs2), "#6");
121                 }
122
123                 [Test]
124                 [ExpectedException (typeof (ArgumentNullException))]
125                 public void Add_Null () {
126                         CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
127                         coll.Add ((CodeCommentStatement) null);
128                 }
129
130                 [Test]
131                 public void Insert ()
132                 {
133                         CodeCommentStatement ccs1 = new CodeCommentStatement ();
134                         CodeCommentStatement ccs2 = new CodeCommentStatement ();
135
136                         CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
137                         coll.Add (ccs1);
138                         Assert.AreEqual (1, coll.Count, "#1");
139                         Assert.AreEqual (0, coll.IndexOf (ccs1), "#2");
140                         coll.Insert (0, ccs2);
141                         Assert.AreEqual (2, coll.Count, "#3");
142                         Assert.AreEqual (1, coll.IndexOf (ccs1), "#4");
143                         Assert.AreEqual (0, coll.IndexOf (ccs2), "#5");
144                 }
145
146                 [Test]
147                 [ExpectedException (typeof (ArgumentNullException))]
148                 public void Insert_Null ()
149                 {
150                         CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
151                         coll.Insert (0, (CodeCommentStatement) null);
152                 }
153
154                 [Test]
155                 public void AddRange ()
156                 {
157                         CodeCommentStatement ccs1 = new CodeCommentStatement ();
158                         CodeCommentStatement ccs2 = new CodeCommentStatement ();
159                         CodeCommentStatement ccs3 = new CodeCommentStatement ();
160
161                         CodeCommentStatementCollection coll1 = new CodeCommentStatementCollection ();
162                         coll1.Add (ccs1);
163                         coll1.Add (ccs2);
164
165                         CodeCommentStatementCollection coll2 = new CodeCommentStatementCollection ();
166                         coll2.Add (ccs3);
167                         coll2.AddRange (coll1);
168                         Assert.AreEqual (3, coll2.Count, "#1");
169                         Assert.AreEqual (1, coll2.IndexOf (ccs1), "#2");
170                         Assert.AreEqual (2, coll2.IndexOf (ccs2), "#3");
171                         Assert.AreEqual (0, coll2.IndexOf (ccs3), "#4");
172
173                         CodeCommentStatementCollection coll3 = new CodeCommentStatementCollection ();
174                         coll3.Add (ccs3);
175                         coll3.AddRange (new CodeCommentStatement[] { ccs1, ccs2 });
176                         Assert.AreEqual (3, coll2.Count, "#5");
177                         Assert.AreEqual (1, coll2.IndexOf (ccs1), "#6");
178                         Assert.AreEqual (2, coll2.IndexOf (ccs2), "#7");
179                         Assert.AreEqual (0, coll2.IndexOf (ccs3), "#8");
180                 }
181
182                 [Test]
183                 [ExpectedException (typeof (ArgumentNullException))]
184                 public void AddRange_Null_Array ()
185                 {
186                         CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
187                         coll.AddRange ((CodeCommentStatement[]) null);
188                 }
189
190                 [Test]
191                 [ExpectedException (typeof (ArgumentNullException))]
192                 public void AddRange_Null_Item ()
193                 {
194                         CodeNamespaceCollection coll = new CodeNamespaceCollection ();
195                         coll.AddRange (new CodeNamespace[] { null });
196                 }
197
198                 [Test]
199                 [ExpectedException (typeof (ArgumentNullException))]
200                 public void AddRange_Null_Collection ()
201                 {
202                         CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
203                         coll.AddRange ((CodeCommentStatementCollection) null);
204                 }
205
206                 [Test]
207                 public void AddRange_Self ()
208                 {
209                         CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
210                         coll.Add (new CodeCommentStatement ());
211                         Assert.AreEqual (1, coll.Count, "#1");
212                         coll.AddRange (coll);
213                         Assert.AreEqual (2, coll.Count, "#2");
214                 }
215
216                 [Test]
217                 public void Remove ()
218                 {
219                         CodeCommentStatement ccs1 = new CodeCommentStatement ();
220                         CodeCommentStatement ccs2 = new CodeCommentStatement ();
221
222                         CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
223                         coll.Add (ccs1);
224                         coll.Add (ccs2);
225                         Assert.AreEqual (2, coll.Count, "#1");
226                         Assert.AreEqual (0, coll.IndexOf (ccs1), "#2");
227                         Assert.AreEqual (1, coll.IndexOf (ccs2), "#3");
228                         coll.Remove (ccs1);
229                         Assert.AreEqual (1, coll.Count, "#4");
230                         Assert.AreEqual (-1, coll.IndexOf (ccs1), "#5");
231                         Assert.AreEqual (0, coll.IndexOf (ccs2), "#6");
232                 }
233
234                 [Test]
235                 [ExpectedException (typeof (ArgumentException))]
236                 public void Remove_NotInCollection ()
237                 {
238                         CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
239                         coll.Remove (new CodeCommentStatement ());
240                 }
241
242                 [Test]
243                 [ExpectedException (typeof (ArgumentNullException))]
244                 public void Remove_Null ()
245                 {
246                         CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
247                         coll.Remove ((CodeCommentStatement) null);
248                 }
249         }
250 }