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