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