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