Excluded the tests, which are not working under Grasshopper (all changes under 'TARGE...
[mono.git] / mcs / class / System / Test / System.Net / HttpListenerPrefixCollectionTest.cs
1 //
2 // HttpListenerPrefixCollectionTest.cs
3 //      - Unit tests for System.Net.HttpListenePrefixCollection
4 //
5 // Author:
6 //      Gonzalo Paniagua Javier (gonzalo@novell.com)
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 #if NET_2_0
30 using System;
31 using System.Net;
32 using NUnit.Framework;
33 using HLPC=System.Net.HttpListenerPrefixCollection;
34
35 namespace MonoTests.System.Net {
36         [TestFixture]
37 #if TARGET_JVM
38         [Ignore ("The class System.Net.HttpListenerPrefixCollection - is not supported")]
39 #endif
40         public class HttpListenerPrefixCollectionTest {
41                 // NL -> Not listening -> tests when listener.IsListening == false
42                 [Test]
43                 public void NL_DefaultProperties ()
44                 {
45                         HttpListener listener = new HttpListener ();
46                         HLPC coll = listener.Prefixes;
47                         Assert.AreEqual (0, coll.Count, "Count");
48                         Assert.IsFalse (coll.IsReadOnly, "IsReadOnly");
49                         Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
50                 }
51
52                 [Test]
53                 public void DefaultProperties ()
54                 {
55                         HttpListener listener = new HttpListener ();
56                         HLPC coll = listener.Prefixes;
57                         coll.Add ("http://127.0.0.1:8181/");
58                         Assert.AreEqual (1, coll.Count, "Count");
59                         Assert.IsFalse (coll.IsReadOnly, "IsReadOnly");
60                         Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
61                 }
62
63                 [Test]
64                 public void AddOne ()
65                 {
66                         HttpListener listener = new HttpListener ();
67                         HLPC coll = listener.Prefixes;
68                         listener.Start ();
69                         coll.Add ("http://127.0.0.1:8181/");
70                         Assert.AreEqual (1, coll.Count, "Count");
71                         Assert.IsFalse (coll.IsReadOnly, "IsReadOnly");
72                         Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
73                         listener.Stop ();
74                 }
75
76                 [Test]
77                 public void Duplicate ()
78                 {
79                         HttpListener listener = new HttpListener ();
80                         HLPC coll = listener.Prefixes;
81                         coll.Add ("http://127.0.0.1:8181/");
82                         coll.Add ("http://127.0.0.1:8181/");
83                         listener.Start ();
84                         Assert.AreEqual (1, coll.Count, "Count");
85                         Assert.IsFalse (coll.IsReadOnly, "IsReadOnly");
86                         Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
87                         listener.Stop ();
88                 }
89
90                 [Test]
91                 public void EndsWithSlash ()
92                 {
93                         HttpListener listener = new HttpListener ();
94                         listener.Prefixes.Add ("http://127.0.0.1:7777/");
95                 }
96
97                 [Test]
98                 public void DifferentPath ()
99                 {
100                         HttpListener listener = new HttpListener ();
101                         listener.Prefixes.Add ("http://127.0.0.1:7777/");
102                         listener.Prefixes.Add ("http://127.0.0.1:7777/hola/");
103                         Assert.AreEqual (2, listener.Prefixes.Count, "#01");
104                 }
105
106                 [Test]
107                 public void NL_Clear ()
108                 {
109                         HttpListener listener = new HttpListener ();
110                         HLPC coll = listener.Prefixes;
111                         coll.Clear ();
112                 }
113
114                 [Test]
115                 public void NL_Remove ()
116                 {
117                         HttpListener listener = new HttpListener ();
118                         HLPC coll = listener.Prefixes;
119                         Assert.IsFalse (coll.Remove ("http://127.0.0.1:8181/"));
120                 }
121
122                 [Test]
123                 public void NL_RemoveBadUri ()
124                 {
125                         HttpListener listener = new HttpListener ();
126                         HLPC coll = listener.Prefixes;
127                         Assert.IsFalse (coll.Remove ("httpblah://127.0.0.1:8181/"));
128                 }
129
130                 [Test]
131                 [ExpectedException (typeof (ArgumentException))]
132                 public void NL_AddBadUri ()
133                 {
134                         HttpListener listener = new HttpListener ();
135                         HLPC coll = listener.Prefixes;
136                         coll.Add ("httpblah://127.0.0.1:8181/");
137                 }
138
139                 [Test]
140                 [ExpectedException (typeof (ArgumentException))]
141                 public void NoHostInUrl ()
142                 {
143                         HttpListener listener = new HttpListener ();
144                         listener.Prefixes.Add ("http://:7777/hola/");
145                 }
146
147                 [Test]
148                 public void MultipleSlashes ()
149                 {
150                         // this one throws on Start(), not when adding it.
151                         // See same test name in HttpListenerTest.
152                         HttpListener listener = new HttpListener ();
153                         HLPC coll = listener.Prefixes;
154                         coll.Add ("http://localhost:7777/hola////");
155                         string [] strs = new string [1];
156                         coll.CopyTo (strs, 0);
157                         Assert.AreEqual ("http://localhost:7777/hola////", strs [0]);
158                 }
159
160                 [Test]
161                 public void PercentSign ()
162                 {
163                         HttpListener listener = new HttpListener ();
164                         HLPC coll = listener.Prefixes;
165                         // this one throws on Start(), not when adding it.
166                         // See same test name in HttpListenerTest.
167                         coll.Add ("http://localhost:7777/hola%3E/");
168                         string [] strs = new string [1];
169                         coll.CopyTo (strs, 0);
170                         Assert.AreEqual ("http://localhost:7777/hola%3E/", strs [0]);
171                 }
172
173                 [Test]
174                 public void Disposed1 ()
175                 {
176                         HttpListener listener = new HttpListener ();
177                         HLPC coll = listener.Prefixes;
178                         listener.Close ();
179                         Assert.AreEqual (0, coll.Count, "Count");
180                         Assert.IsFalse (coll.IsReadOnly, "IsReadOnly");
181                         Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
182                 }
183
184                 [Test]
185                 [ExpectedException (typeof (ObjectDisposedException))]
186                 public void Disposed2 ()
187                 {
188                         HttpListener listener = new HttpListener ();
189                         HLPC coll = listener.Prefixes;
190                         listener.Close ();
191                         coll.Add ("http://localhost:7777/hola/");
192                 }
193
194                 [Test]
195                 [ExpectedException (typeof (ObjectDisposedException))]
196                 public void Disposed3 ()
197                 {
198                         HttpListener listener = new HttpListener ();
199                         HLPC coll = listener.Prefixes;
200                         listener.Close ();
201                         coll.Clear ();
202                 }
203
204                 [Test]
205                 [ExpectedException (typeof (ObjectDisposedException))]
206                 public void Disposed4 ()
207                 {
208                         HttpListener listener = new HttpListener ();
209                         HLPC coll = listener.Prefixes;
210                         listener.Close ();
211                         coll.Remove ("http://localhost:7777/hola/");
212                 }
213
214                 [Test]
215                 [ExpectedException (typeof (ObjectDisposedException))]
216                 public void Disposed5 ()
217                 {
218                         HttpListener listener = new HttpListener ();
219                         HLPC coll = listener.Prefixes;
220                         listener.Close ();
221                         string [] strs = new string [0];
222                         coll.CopyTo (strs, 0);
223                 }
224
225                 [Test]
226                 public void Disposed6 ()
227                 {
228                         HttpListener listener = new HttpListener ();
229                         HLPC coll = listener.Prefixes;
230                         listener.Close ();
231                         string a = null;
232                         foreach (string s in coll) {
233                                 a = s; // just to make the compiler happy
234                         }
235                         Assert.IsNull (a);
236                 }
237
238                 [Test]
239                 public void Disposed7 ()
240                 {
241                         HttpListener listener = new HttpListener ();
242                         HLPC coll = listener.Prefixes;
243                         coll.Add ("http://127.0.0.1/");
244                         listener.Close ();
245                         int items = 0;
246                         foreach (string s in coll) {
247                                 items++;
248                                 Assert.AreEqual (s, "http://127.0.0.1/");
249                         }
250                         Assert.AreEqual (items, 1);
251                 }
252         }
253 }
254 #endif
255