Merge pull request #3028 from lateralusX/jlorenss/threadpool_warning
[mono.git] / mcs / class / System / Test / System / UriParserTest.cs
1 //
2 // UriParserTest.cs - Unit tests for System.UriParser
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29
30 using NUnit.Framework;
31
32 using System;
33 using System.Text;
34
35 namespace MonoTests.System {
36
37         public class UnitTestUriParser: UriParser {
38
39                 private string scheme_name;
40                 private int default_port;
41                 private bool throw_on_register;
42                 private bool on_new_uri_called;
43
44                 public UnitTestUriParser ()
45                 {
46                 }
47
48                 public UnitTestUriParser (bool throwOnRegister)
49                 {
50                         throw_on_register = throwOnRegister;
51                 }
52
53                 public string SchemeName
54                 {
55                         get
56                         {
57                                 return scheme_name;
58                         }
59                 }
60
61                 public int DefaultPort
62                 {
63                         get
64                         {
65                                 return default_port;
66                         }
67                 }
68
69                 public bool OnNewUriCalled
70                 {
71                         get
72                         {
73                                 return on_new_uri_called;
74                         }
75                 }
76
77                 public string _GetComponents (Uri uri, UriComponents components, UriFormat format)
78                 {
79                         return base.GetComponents (uri, components, format);
80                 }
81
82                 public void _InitializeAndValidate (Uri uri, out UriFormatException parserError)
83                 {
84                         base.InitializeAndValidate (uri, out parserError);
85                 }
86
87                 public bool _IsBaseOf (Uri baseUri, Uri relativeUri)
88                 {
89                         return base.IsBaseOf (baseUri, relativeUri);
90                 }
91
92                 public bool _IsWellFormedOriginalString (Uri uri)
93                 {
94                         return base.IsWellFormedOriginalString (uri);
95                 }
96
97                 public UriParser _OnNewUri ()
98                 {
99                         return base.OnNewUri ();
100                 }
101
102                 public void _OnRegister (string schemeName, int defaultPort)
103                 {
104                         base.OnRegister (schemeName, defaultPort);
105                 }
106
107                 public string _Resolve (Uri baseUri, Uri relativeUri, out UriFormatException parserError)
108                 {
109                         return base.Resolve (baseUri, relativeUri, out parserError);
110                 }
111
112                 protected override UriParser OnNewUri ()
113                 {
114                         on_new_uri_called = true;
115                         return base.OnNewUri ();
116                 }
117
118                 protected override void OnRegister (string schemeName, int defaultPort)
119                 {
120                         if (throw_on_register)
121                                 throw new NotSupportedException ();
122                         scheme_name = schemeName;
123                         default_port = defaultPort;
124                         base.OnRegister (schemeName, defaultPort);
125                 }
126         }
127
128         [TestFixture]
129         public class UriParserTest {
130
131                 private const string full_http = "http://www.mono-project.com/Main_Page#FAQ?Edit";
132
133                 private string prefix;
134                 private Uri http;
135                 private Uri ftp, ftp2;
136
137                 [TestFixtureSetUp]
138                 public void FixtureSetUp ()
139                 {
140                         prefix = "unit.test.";
141                         http = new Uri (full_http);
142                         ftp = new Uri ("ftp://username:password@ftp.go-mono.com:21/with some spaces/mono.tgz");
143
144                         // Uses percent encoding on the username and password
145                         ftp2 = new Uri ("ftp://%75sername%3a%70assword@ftp.go-mono.com:21/with some spaces/mono.tgz");
146                 }
147
148                 public string Prefix
149                 {
150                         get
151                         {
152                                 return prefix;
153                         }
154                         set
155                         {
156                                 prefix = value;
157                         }
158                 }
159
160                 [Test]
161                 public void GetComponents ()
162                 {
163                         UnitTestUriParser p = new UnitTestUriParser ();
164                         Assert.AreEqual ("http", p._GetComponents (http, UriComponents.Scheme, UriFormat.SafeUnescaped), "http.Scheme");
165                         Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.UserInfo, UriFormat.SafeUnescaped), "http.UserInfo");
166                         Assert.AreEqual ("www.mono-project.com", p._GetComponents (http, UriComponents.Host, UriFormat.SafeUnescaped), "http.Host");
167                         Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.Port, UriFormat.SafeUnescaped), "http.Port");
168                         Assert.AreEqual ("Main_Page", p._GetComponents (http, UriComponents.Path, UriFormat.SafeUnescaped), "http.Path");
169                         Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.Query, UriFormat.SafeUnescaped), "http.Query");
170                         Assert.AreEqual ("FAQ?Edit", p._GetComponents (http, UriComponents.Fragment, UriFormat.SafeUnescaped), "http.Fragment");
171                         Assert.AreEqual ("80", p._GetComponents (http, UriComponents.StrongPort, UriFormat.SafeUnescaped), "http.StrongPort");
172                         Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.KeepDelimiter, UriFormat.SafeUnescaped), "http.KeepDelimiter");
173                         Assert.AreEqual ("www.mono-project.com:80", p._GetComponents (http, UriComponents.HostAndPort, UriFormat.SafeUnescaped), "http.HostAndPort");
174                         Assert.AreEqual ("www.mono-project.com:80", p._GetComponents (http, UriComponents.StrongAuthority, UriFormat.SafeUnescaped), "http.StrongAuthority");
175                         Assert.AreEqual (full_http, p._GetComponents (http, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped), "http.AbsoluteUri");
176                         Assert.AreEqual ("/Main_Page", p._GetComponents (http, UriComponents.PathAndQuery, UriFormat.SafeUnescaped), "http.PathAndQuery");
177                         Assert.AreEqual ("http://www.mono-project.com/Main_Page", p._GetComponents (http, UriComponents.HttpRequestUrl, UriFormat.SafeUnescaped), "http.HttpRequestUrl");
178                         Assert.AreEqual ("http://www.mono-project.com", p._GetComponents (http, UriComponents.SchemeAndServer, UriFormat.SafeUnescaped), "http.SchemeAndServer");
179                         Assert.AreEqual (full_http, p._GetComponents (http, UriComponents.SerializationInfoString, UriFormat.SafeUnescaped), "http.SerializationInfoString");
180                         // strange mixup
181                         Assert.AreEqual ("http://", p._GetComponents (http, UriComponents.Scheme | UriComponents.Port, UriFormat.SafeUnescaped), "http.Scheme+Port");
182                         Assert.AreEqual ("www.mono-project.com#FAQ?Edit", p._GetComponents (http, UriComponents.Host | UriComponents.Fragment, UriFormat.SafeUnescaped), "http.Scheme+Port");
183                         Assert.AreEqual ("/Main_Page", p._GetComponents (http, UriComponents.Port | UriComponents.Path, UriFormat.SafeUnescaped), "http.Scheme+Port");
184                         Assert.AreSame (p, p._OnNewUri (), "OnNewUri");
185                 }
186
187                 [Test]
188                 public void GetComponents_Ftp ()
189                 {
190                         UnitTestUriParser p = new UnitTestUriParser ();
191                         Assert.AreEqual ("ftp", p._GetComponents (ftp, UriComponents.Scheme, UriFormat.Unescaped), "ftp.Scheme");
192                         Assert.AreEqual ("username:password", p._GetComponents (ftp, UriComponents.UserInfo, UriFormat.Unescaped), "ftp.UserInfo");
193                         Assert.AreEqual ("ftp.go-mono.com", p._GetComponents (ftp, UriComponents.Host, UriFormat.Unescaped), "ftp.Host");
194                         Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.Port, UriFormat.Unescaped), "ftp.Port");
195                         Assert.AreEqual ("with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path, UriFormat.Unescaped), "ftp.Path");
196                         Assert.AreEqual ("with%20some%20spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path, UriFormat.UriEscaped), "ftp.Path-UriEscaped");
197                         Assert.AreEqual ("with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path, UriFormat.SafeUnescaped), "ftp.Path-SafeUnescaped");
198                         Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.Query, UriFormat.Unescaped), "ftp.Query");
199                         Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.Fragment, UriFormat.Unescaped), "ftp.Fragment");
200                         Assert.AreEqual ("21", p._GetComponents (ftp, UriComponents.StrongPort, UriFormat.Unescaped), "ftp.StrongPort");
201                         Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.KeepDelimiter, UriFormat.Unescaped), "http.KeepDelimiter");
202                         Assert.AreEqual ("ftp.go-mono.com:21", p._GetComponents (ftp, UriComponents.HostAndPort, UriFormat.Unescaped), "http.HostAndPort");
203                         Assert.AreEqual ("username:password@ftp.go-mono.com:21", p._GetComponents (ftp, UriComponents.StrongAuthority, UriFormat.Unescaped), "http.StrongAuthority");
204                         Assert.AreEqual ("ftp://username:password@ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.AbsoluteUri, UriFormat.Unescaped), "http.AbsoluteUri");
205                         Assert.AreEqual ("/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.PathAndQuery, UriFormat.Unescaped), "http.PathAndQuery");
206                         Assert.AreEqual ("ftp://ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.HttpRequestUrl, UriFormat.Unescaped), "http.HttpRequestUrl");
207                         Assert.AreEqual ("ftp://ftp.go-mono.com", p._GetComponents (ftp, UriComponents.SchemeAndServer, UriFormat.Unescaped), "http.SchemeAndServer");
208                         Assert.AreEqual ("ftp://username:password@ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.SerializationInfoString, UriFormat.Unescaped), "http.SerializationInfoString");
209                         Assert.AreSame (p, p._OnNewUri (), "OnNewUri");
210                         // strange mixup
211                         Assert.AreEqual ("ftp://username:password@", p._GetComponents (ftp, UriComponents.Scheme | UriComponents.UserInfo, UriFormat.Unescaped), "ftp.Scheme+UserInfo");
212                         Assert.AreEqual (":21/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path | UriComponents.StrongPort, UriFormat.Unescaped), "ftp.Path+StrongPort");
213                 }
214
215                 [Test]
216                 public void GetComponents_Ftp2 ()
217                 {
218                         UnitTestUriParser p = new UnitTestUriParser ();
219                         Assert.AreEqual ("ftp", p._GetComponents (ftp2, UriComponents.Scheme, UriFormat.Unescaped), "ftp.Scheme");
220                         Assert.AreEqual ("username:password", p._GetComponents (ftp2, UriComponents.UserInfo, UriFormat.Unescaped), "ftp.UserInfo");
221                         Assert.AreEqual ("ftp.go-mono.com", p._GetComponents (ftp2, UriComponents.Host, UriFormat.Unescaped), "ftp.Host");
222                         Assert.AreEqual (String.Empty, p._GetComponents (ftp2, UriComponents.Port, UriFormat.Unescaped), "ftp.Port");
223                         Assert.AreEqual ("with some spaces/mono.tgz", p._GetComponents (ftp2, UriComponents.Path, UriFormat.Unescaped), "ftp.Path");
224                         Assert.AreEqual ("with%20some%20spaces/mono.tgz", p._GetComponents (ftp2, UriComponents.Path, UriFormat.UriEscaped), "ftp.Path-UriEscaped");
225                         Assert.AreEqual ("with some spaces/mono.tgz", p._GetComponents (ftp2, UriComponents.Path, UriFormat.SafeUnescaped), "ftp.Path-SafeUnescaped");
226                         Assert.AreEqual (String.Empty, p._GetComponents (ftp2, UriComponents.Query, UriFormat.Unescaped), "ftp.Query");
227                         Assert.AreEqual (String.Empty, p._GetComponents (ftp2, UriComponents.Fragment, UriFormat.Unescaped), "ftp.Fragment");
228                         Assert.AreEqual ("21", p._GetComponents (ftp2, UriComponents.StrongPort, UriFormat.Unescaped), "ftp.StrongPort");
229                         Assert.AreEqual (String.Empty, p._GetComponents (ftp2, UriComponents.KeepDelimiter, UriFormat.Unescaped), "http.KeepDelimiter");
230                         Assert.AreEqual ("ftp.go-mono.com:21", p._GetComponents (ftp2, UriComponents.HostAndPort, UriFormat.Unescaped), "http.HostAndPort");
231                         Assert.AreEqual ("username:password@ftp.go-mono.com:21", p._GetComponents (ftp2, UriComponents.StrongAuthority, UriFormat.Unescaped), "http.StrongAuthority");
232                         Assert.AreEqual ("ftp://username:password@ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp2, UriComponents.AbsoluteUri, UriFormat.Unescaped), "http.AbsoluteUri");
233                         Assert.AreEqual ("/with some spaces/mono.tgz", p._GetComponents (ftp2, UriComponents.PathAndQuery, UriFormat.Unescaped), "http.PathAndQuery");
234                         Assert.AreEqual ("ftp://ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp2, UriComponents.HttpRequestUrl, UriFormat.Unescaped), "http.HttpRequestUrl");
235                         Assert.AreEqual ("ftp://ftp.go-mono.com", p._GetComponents (ftp2, UriComponents.SchemeAndServer, UriFormat.Unescaped), "http.SchemeAndServer");
236                         Assert.AreEqual ("ftp://username:password@ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp2, UriComponents.SerializationInfoString, UriFormat.Unescaped), "http.SerializationInfoString");
237                         Assert.AreSame (p, p._OnNewUri (), "OnNewUri");
238                         // strange mixup
239                         Assert.AreEqual ("ftp://username:password@", p._GetComponents (ftp2, UriComponents.Scheme | UriComponents.UserInfo, UriFormat.Unescaped), "ftp.Scheme+UserInfo");
240                         Assert.AreEqual (":21/with some spaces/mono.tgz", p._GetComponents (ftp2, UriComponents.Path | UriComponents.StrongPort, UriFormat.Unescaped), "ftp.Path+StrongPort");
241                 }
242
243                 // Test case for Xamarin#17665
244                 [Test]
245                 public void TestParseUserPath ()
246                 {
247                         var u = new Uri("https://a.net/1@1.msg");
248                         var result = u.GetComponents(UriComponents.Scheme | UriComponents.Host | UriComponents.Port | UriComponents.Path, UriFormat.UriEscaped);
249                         Assert.AreEqual (result, "https://a.net/1@1.msg", "parse@InUrl");
250                 }
251                 
252                 
253                 [Test]
254                 [ExpectedException (typeof (NullReferenceException))]
255                 public void GetComponents_Null ()
256                 {
257                         UnitTestUriParser p = new UnitTestUriParser ();
258                         p._GetComponents (null, UriComponents.Host, UriFormat.SafeUnescaped);
259                 }
260
261                 [Test]
262                 public void GetComponents_BadUriComponents ()
263                 {
264                         UnitTestUriParser p = new UnitTestUriParser ();
265                         Assert.AreEqual (full_http, p._GetComponents (http, (UriComponents) Int32.MinValue, UriFormat.SafeUnescaped), "http");
266                 }
267
268                 [Test]
269                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
270                 public void GetComponents_BadUriFormat ()
271                 {
272                         UnitTestUriParser p = new UnitTestUriParser ();
273                         p._GetComponents (http, UriComponents.Host, (UriFormat) Int32.MinValue);
274                 }
275
276                 [Test]
277                 public void InitializeAndValidate ()
278                 {
279                         UriFormatException error = null;
280                         UnitTestUriParser p = new UnitTestUriParser ();
281                         p._InitializeAndValidate (http, out error);
282                         Assert.IsNotNull (error, "out"); // authority/host couldn't be parsed ?!?!
283                 }
284
285                 [Test]
286                 [ExpectedException (typeof (NullReferenceException))]
287                 // oh man, this is a bad boy.It should be ArgumentNullException.
288                 public void InitializeAndValidate_Null ()
289                 {
290                         UriFormatException error = null;
291                         UnitTestUriParser p = new UnitTestUriParser ();
292                         p._InitializeAndValidate (null, out error);
293                 }
294
295                 [Test]
296                 public void IsBaseOf ()
297                 {
298                         UnitTestUriParser p = new UnitTestUriParser ();
299                         Assert.IsTrue (p._IsBaseOf (http, http), "http-http");
300
301                         Uri u = new Uri ("http://www.mono-project.com/Main_Page#FAQ");
302                         Assert.IsTrue (p._IsBaseOf (u, http), "http-1a");
303                         Assert.IsTrue (p._IsBaseOf (http, u), "http-1b");
304
305                         u = new Uri ("http://www.mono-project.com/Main_Page");
306                         Assert.IsTrue (p._IsBaseOf (u, http), "http-2a");
307                         Assert.IsTrue (p._IsBaseOf (http, u), "http-2b");
308
309                         u = new Uri ("http://www.mono-project.com/");
310                         Assert.IsTrue (p._IsBaseOf (u, http), "http-3a");
311                         Assert.IsTrue (p._IsBaseOf (http, u), "http-3b");
312
313                         u = new Uri ("http://www.mono-project.com/Main_Page/");
314                         Assert.IsFalse (p._IsBaseOf (u, http), "http-4a");
315                         Assert.IsTrue (p._IsBaseOf (http, u), "http-4b");
316
317                         // docs says the UserInfo isn't evaluated, but...
318                         u = new Uri ("http://username:password@www.mono-project.com/Main_Page");
319                         Assert.IsFalse (p._IsBaseOf (u, http), "http-5a");
320                         Assert.IsFalse (p._IsBaseOf (http, u), "http-5b");
321
322                         // scheme case sensitive ? no
323                         u = new Uri ("HTTP://www.mono-project.com/Main_Page");
324                         Assert.IsTrue (p._IsBaseOf (u, http), "http-6a");
325                         Assert.IsTrue (p._IsBaseOf (http, u), "http-6b");
326
327                         // host case sensitive ? no
328                         u = new Uri ("http://www.Mono-Project.com/Main_Page");
329                         Assert.IsTrue (p._IsBaseOf (u, http), "http-7a");
330                         Assert.IsTrue (p._IsBaseOf (http, u), "http-7b");
331
332                         // path case sensitive ? no
333                         u = new Uri ("http://www.Mono-Project.com/MAIN_Page");
334                         Assert.IsTrue (p._IsBaseOf (u, http), "http-8a");
335                         Assert.IsTrue (p._IsBaseOf (http, u), "http-8b");
336
337                         // different scheme
338                         u = new Uri ("ftp://www.mono-project.com/Main_Page");
339                         Assert.IsFalse (p._IsBaseOf (u, http), "http-9a");
340                         Assert.IsFalse (p._IsBaseOf (http, u), "http-9b");
341
342                         // different host
343                         u = new Uri ("http://www.go-mono.com/Main_Page");
344                         Assert.IsFalse (p._IsBaseOf (u, http), "http-10a");
345                         Assert.IsFalse (p._IsBaseOf (http, u), "http-10b");
346
347                         // different port
348                         u = new Uri ("http://www.mono-project.com:8080/");
349                         Assert.IsFalse (p._IsBaseOf (u, http), "http-11a");
350                         Assert.IsFalse (p._IsBaseOf (http, u), "http-11b");
351
352                         // specify default port
353                         u = new Uri ("http://www.mono-project.com:80/");
354                         Assert.IsTrue (p._IsBaseOf (u, http), "http-12a");
355                         Assert.IsTrue (p._IsBaseOf (http, u), "http-12b");
356                 }
357
358                 [Test]
359                 [ExpectedException (typeof (NullReferenceException))]
360                 public void IsBaseOf_UriNull ()
361                 {
362                         UnitTestUriParser p = new UnitTestUriParser ();
363                         p._IsBaseOf (http, null);
364                 }
365
366                 [Test]
367                 [ExpectedException (typeof (NullReferenceException))]
368                 public void IsBaseOf_NullUri ()
369                 {
370                         UnitTestUriParser p = new UnitTestUriParser ();
371                         p._IsBaseOf (null, http);
372                 }
373
374                 [Test]
375                 public void IsWellFormedOriginalString ()
376                 {
377                         UnitTestUriParser p = new UnitTestUriParser ();
378                         Assert.IsTrue (p._IsWellFormedOriginalString (http), "http");
379                 }
380
381                 [Test]
382                 [ExpectedException (typeof (NullReferenceException))]
383                 public void IsWellFormedOriginalString_Null ()
384                 {
385                         UnitTestUriParser p = new UnitTestUriParser ();
386                         p._IsWellFormedOriginalString (null);
387                 }
388
389                 [Test]
390                 public void OnNewUri ()
391                 {
392                         string scheme = prefix + "on.new.uri";
393                         Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
394
395                         UnitTestUriParser p = new UnitTestUriParser ();
396                         UriParser.Register (p, scheme, 1999);
397
398                         Assert.IsFalse (p.OnNewUriCalled, "!Called");
399                         Uri uri = new Uri (scheme + "://www.mono-project.com");
400                         Assert.IsTrue (p.OnNewUriCalled, "Called");
401                 }
402
403                 [Test]
404                 public void OnRegister ()
405                 {
406                         string scheme = prefix + "onregister";
407                         Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
408                         UnitTestUriParser p = new UnitTestUriParser ();
409                         try {
410                                 UriParser.Register (p, scheme, 2005);
411                         }
412                         catch (NotSupportedException) {
413                                 // special case / ordering
414                         }
415                         // if true then the registration is done before calling OnRegister
416                         Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
417                 }
418
419                 [Test]
420                 public void OnRegister2 ()
421                 {
422                         string scheme = prefix + "onregister2";
423                         Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
424                         UnitTestUriParser p = new UnitTestUriParser ();
425                         try {
426                                 UriParser.Register (p, scheme, 2005);
427                                 Uri uri = new Uri (scheme + "://foobar:2005");
428                                 Assert.AreEqual (scheme, uri.Scheme, "uri-prefix");
429                                 Assert.AreEqual (2005, uri.Port, "uri-port");
430                                 
431                                 Assert.AreEqual ("//foobar:2005", uri.LocalPath, "uri-localpath");
432                         }
433                         catch (NotSupportedException) {
434                                 // special case / ordering
435                         }
436                         // if true then the registration is done before calling OnRegister
437                         Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
438                 }
439
440                 [Test]
441                 public void Resolve ()
442                 {
443                         UriFormatException error = null;
444                         UnitTestUriParser p = new UnitTestUriParser ();
445                         Assert.AreEqual (full_http, p._Resolve (http, http, out error), "http-http");
446                 }
447
448                 [Test]
449                 public void Resolve_UriNull ()
450                 {
451                         UriFormatException error = null;
452                         UnitTestUriParser p = new UnitTestUriParser ();
453                         Assert.AreEqual (full_http, p._Resolve (http, null, out error), "http-http");
454                 }
455
456                 [Test]
457                 [ExpectedException (typeof (NullReferenceException))]
458                 public void Resolve_NullUri ()
459                 {
460                         UriFormatException error = null;
461                         UnitTestUriParser p = new UnitTestUriParser ();
462                         p._Resolve (null, http, out error);
463                         p._Resolve (http, null, out error);
464                 }
465
466                 [Test]
467                 public void IsKnownScheme_WellKnown ()
468                 {
469                         // from Uri.UriScheme* fields
470                         Assert.IsTrue (UriParser.IsKnownScheme ("file"), "file");
471                         Assert.IsTrue (UriParser.IsKnownScheme ("ftp"), "ftp");
472                         Assert.IsTrue (UriParser.IsKnownScheme ("gopher"), "gopher");
473                         Assert.IsTrue (UriParser.IsKnownScheme ("http"), "http");
474                         Assert.IsTrue (UriParser.IsKnownScheme ("https"), "https");
475                         Assert.IsTrue (UriParser.IsKnownScheme ("mailto"), "mailto");
476                         Assert.IsTrue (UriParser.IsKnownScheme ("net.pipe"), "net.pipe");
477                         Assert.IsTrue (UriParser.IsKnownScheme ("net.tcp"), "net.tcp");
478                         Assert.IsTrue (UriParser.IsKnownScheme ("news"), "news");
479                         Assert.IsTrue (UriParser.IsKnownScheme ("nntp"), "nntp");
480                         // inferred from class library
481                         Assert.IsTrue (UriParser.IsKnownScheme ("ldap"), "ldap");
482                         Assert.IsFalse (UriParser.IsKnownScheme ("ldaps"), "ldaps");
483                         // well known for not existing
484                         Assert.IsFalse (UriParser.IsKnownScheme ("unknown"), "unknown");
485
486                         // variations - mixed and upper case
487                         Assert.IsTrue (UriParser.IsKnownScheme ("FiLe"), "FiLe");
488                         Assert.IsTrue (UriParser.IsKnownScheme ("FTP"), "ftp");
489
490                         // see 496783
491                         Assert.IsFalse (UriParser.IsKnownScheme ("tcp"), "tcp");
492                 }
493
494                 [Test]
495                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
496                 public void IsKnownScheme_ExtraSpace ()
497                 {
498                         // same result for space before, inside or after the scheme
499                         UriParser.IsKnownScheme ("ht tp");
500                         // this is undocumented (and I hate exceptions in a boolean method)
501                 }
502
503                 [Test]
504                 [ExpectedException (typeof (ArgumentNullException))]
505                 public void IsKnownScheme_Null ()
506                 {
507                         UriParser.IsKnownScheme (null);
508                 }
509
510                 [Test]
511                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
512                 public void IsKnownScheme_Empty ()
513                 {
514                         UriParser.IsKnownScheme (String.Empty);
515                 }
516
517                 [Test]
518                 public void Register ()
519                 {
520                         string scheme = prefix + "register.mono";
521                         Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
522
523                         UnitTestUriParser p = new UnitTestUriParser ();
524                         UriParser.Register (p, scheme, 2005);
525                         Assert.AreEqual (scheme, p.SchemeName, "SchemeName");
526                         Assert.AreEqual (2005, p.DefaultPort, "DefaultPort");
527
528                         Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
529                 }
530
531                 [Test]
532                 [ExpectedException (typeof (ArgumentNullException))]
533                 public void Register_NullParser ()
534                 {
535                         UriParser.Register (null, prefix + "null.parser", 2006);
536                 }
537
538                 [Test]
539                 [ExpectedException (typeof (ArgumentNullException))]
540                 public void Register_NullScheme ()
541                 {
542                         UnitTestUriParser p = new UnitTestUriParser ();
543                         UriParser.Register (p, null, 2006);
544                 }
545
546                 [Test]
547                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
548                 public void Register_NegativePort ()
549                 {
550                         UnitTestUriParser p = new UnitTestUriParser ();
551                         UriParser.Register (p, prefix + "negative.port", -2);
552                 }
553
554                 [Test]
555                 public void Register_Minus1Port ()
556                 {
557                         UnitTestUriParser p = new UnitTestUriParser ();
558                         UriParser.Register (p, prefix + "minus1.port", -1);
559                 }
560
561                 [Test]
562                 public void Register_UInt16PortMinus1 ()
563                 {
564                         UnitTestUriParser p = new UnitTestUriParser ();
565                         UriParser.Register (p, prefix + "uint16.minus.1.port", UInt16.MaxValue - 1);
566                 }
567
568                 [Test]
569                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
570                 public void Register_TooBigPort ()
571                 {
572                         UnitTestUriParser p = new UnitTestUriParser ();
573                         UriParser.Register (p, prefix + "too.big.port", UInt16.MaxValue);
574                 }
575
576                 [Test]
577                 [ExpectedException (typeof (InvalidOperationException))]
578                 public void ReRegister ()
579                 {
580                         string scheme = prefix + "re.register.mono";
581                         Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
582                         UnitTestUriParser p = new UnitTestUriParser ();
583                         UriParser.Register (p, scheme, 2005);
584                         Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
585                         UriParser.Register (p, scheme, 2006);
586                 }
587         }
588 }
589