Merge pull request #2396 from akoeplinger/flaky-osx-socket-test
[mono.git] / mcs / class / System / Test / System.CodeDom / CodeTypeDeclarationCollectionTest.cs
1 //
2 // CodeTypeDeclarationCollectionTest.cs 
3 //      - Unit tests for System.CodeDom.CodeTypeDeclarationCollection
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 CodeTypeDeclarationCollectionTest {
39                 [Test]
40                 public void Constructor0 ()
41                 {
42                         CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection ();
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                         CodeTypeDeclaration td1 = new CodeTypeDeclaration ();
54                         CodeTypeDeclaration td2 = new CodeTypeDeclaration ();
55
56                         CodeTypeDeclaration[] declarations = new CodeTypeDeclaration[] { td1, td2 };
57                         CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection (
58                                 declarations);
59
60                         Assert.AreEqual (2, coll.Count, "#1");
61                         Assert.AreEqual (0, coll.IndexOf (td1), "#2");
62                         Assert.AreEqual (1, coll.IndexOf (td2), "#3");
63                 }
64
65                 [Test]
66                 [ExpectedException (typeof (ArgumentNullException))]
67                 public void Constructor1_NullItem ()
68                 {
69                         CodeTypeDeclaration[] declarations = new CodeTypeDeclaration[] { 
70                                 new CodeTypeDeclaration (), null };
71
72                         CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection (
73                                 declarations);
74                 }
75
76                 [Test]
77                 [ExpectedException (typeof (ArgumentNullException))]
78                 public void Constructor1_Null () {
79                         CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection (
80                                 (CodeTypeDeclaration[]) null);
81                 }
82
83                 [Test]
84                 public void Constructor2 ()
85                 {
86                         CodeTypeDeclaration td1 = new CodeTypeDeclaration ();
87                         CodeTypeDeclaration td2 = new CodeTypeDeclaration ();
88
89                         CodeTypeDeclarationCollection c = new CodeTypeDeclarationCollection ();
90                         c.Add (td1);
91                         c.Add (td2);
92
93                         CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection (c);
94                         Assert.AreEqual (2, coll.Count, "#1");
95                         Assert.AreEqual (0, coll.IndexOf (td1), "#2");
96                         Assert.AreEqual (1, coll.IndexOf (td2), "#3");
97                 }
98
99                 [Test]
100                 [ExpectedException (typeof (ArgumentNullException))]
101                 public void Constructor2_Null ()
102                 {
103                         CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection (
104                                 (CodeTypeDeclarationCollection) null);
105                 }
106
107                 [Test]
108                 public void Add ()
109                 {
110                         CodeTypeDeclaration td1 = new CodeTypeDeclaration ();
111                         CodeTypeDeclaration td2 = new CodeTypeDeclaration ();
112
113                         CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection ();
114                         Assert.AreEqual (0, coll.Add (td1), "#1");
115                         Assert.AreEqual (1, coll.Count, "#2");
116                         Assert.AreEqual (0, coll.IndexOf (td1), "#3");
117
118                         Assert.AreEqual (1, coll.Add (td2), "#4");
119                         Assert.AreEqual (2, coll.Count, "#5");
120                         Assert.AreEqual (1, coll.IndexOf (td2), "#6");
121                 }
122
123                 [Test]
124                 [ExpectedException (typeof (ArgumentNullException))]
125                 public void Add_Null () {
126                         CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection ();
127                         coll.Add ((CodeTypeDeclaration) null);
128                 }
129
130                 [Test]
131                 public void Insert ()
132                 {
133                         CodeTypeDeclaration td1 = new CodeTypeDeclaration ();
134                         CodeTypeDeclaration td2 = new CodeTypeDeclaration ();
135
136                         CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection ();
137                         coll.Add (td1);
138                         Assert.AreEqual (1, coll.Count, "#1");
139                         Assert.AreEqual (0, coll.IndexOf (td1), "#2");
140                         coll.Insert (0, td2);
141                         Assert.AreEqual (2, coll.Count, "#3");
142                         Assert.AreEqual (1, coll.IndexOf (td1), "#4");
143                         Assert.AreEqual (0, coll.IndexOf (td2), "#5");
144                 }
145
146                 [Test]
147                 [ExpectedException (typeof (ArgumentNullException))]
148                 public void Insert_Null ()
149                 {
150                         CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection ();
151                         coll.Insert (0, (CodeTypeDeclaration) null);
152                 }
153
154                 [Test]
155                 public void AddRange ()
156                 {
157                         CodeTypeDeclaration td1 = new CodeTypeDeclaration ();
158                         CodeTypeDeclaration td2 = new CodeTypeDeclaration ();
159                         CodeTypeDeclaration td3 = new CodeTypeDeclaration ();
160
161                         CodeTypeDeclarationCollection coll1 = new CodeTypeDeclarationCollection ();
162                         coll1.Add (td1);
163                         coll1.Add (td2);
164
165                         CodeTypeDeclarationCollection coll2 = new CodeTypeDeclarationCollection ();
166                         coll2.Add (td3);
167                         coll2.AddRange (coll1);
168                         Assert.AreEqual (3, coll2.Count, "#1");
169                         Assert.AreEqual (1, coll2.IndexOf (td1), "#2");
170                         Assert.AreEqual (2, coll2.IndexOf (td2), "#3");
171                         Assert.AreEqual (0, coll2.IndexOf (td3), "#4");
172
173                         CodeTypeDeclarationCollection coll3 = new CodeTypeDeclarationCollection ();
174                         coll3.Add (td3);
175                         coll3.AddRange (new CodeTypeDeclaration[] { td1, td2 });
176                         Assert.AreEqual (3, coll2.Count, "#5");
177                         Assert.AreEqual (1, coll2.IndexOf (td1), "#6");
178                         Assert.AreEqual (2, coll2.IndexOf (td2), "#7");
179                         Assert.AreEqual (0, coll2.IndexOf (td3), "#8");
180                 }
181
182                 [Test]
183                 [ExpectedException (typeof (ArgumentNullException))]
184                 public void AddRange_Null_Array ()
185                 {
186                         CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection ();
187                         coll.AddRange ((CodeTypeDeclaration[]) null);
188                 }
189
190                 [Test]
191                 [ExpectedException (typeof (ArgumentNullException))]
192                 public void AddRange_Null_Item ()
193                 {
194                         CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection ();
195                         coll.AddRange (new CodeTypeDeclaration[] { null });
196                 }
197
198                 [Test]
199                 [ExpectedException (typeof (ArgumentNullException))]
200                 public void AddRange_Null_Collection ()
201                 {
202                         CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection ();
203                         coll.AddRange ((CodeTypeDeclarationCollection) null);
204                 }
205
206                 [Test]
207                 public void AddRange_Self ()
208                 {
209                         CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection ();
210                         coll.Add (new CodeTypeDeclaration ());
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                         CodeTypeDeclaration td1 = new CodeTypeDeclaration ();
220                         CodeTypeDeclaration td2 = new CodeTypeDeclaration ();
221
222                         CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection ();
223                         coll.Add (td1);
224                         coll.Add (td2);
225                         Assert.AreEqual (2, coll.Count, "#1");
226                         Assert.AreEqual (0, coll.IndexOf (td1), "#2");
227                         Assert.AreEqual (1, coll.IndexOf (td2), "#3");
228                         coll.Remove (td1);
229                         Assert.AreEqual (1, coll.Count, "#4");
230                         Assert.AreEqual (-1, coll.IndexOf (td1), "#5");
231                         Assert.AreEqual (0, coll.IndexOf (td2), "#6");
232                 }
233
234                 [Test]
235                 [ExpectedException (typeof (ArgumentException))]
236                 public void Remove_NotInCollection ()
237                 {
238                         CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection ();
239                         coll.Remove (new CodeTypeDeclaration ());
240                 }
241
242                 [Test]
243                 [ExpectedException (typeof (ArgumentNullException))]
244                 public void Remove_Null ()
245                 {
246                         CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection ();
247                         coll.Remove ((CodeTypeDeclaration) null);
248                 }
249         }
250 }