Merge branch 'master' of github.com:mono/mono
[mono.git] / mcs / class / System / Test / System / UriTest.cs
1 //
2 // UriTest.cs - NUnit Test Cases for System.Uri
3 //
4 // Authors:
5 //   Lawrence Pit (loz@cable.a2000.nl)
6 //   Martin Willemoes Hansen (mwh@sysrq.dk)
7 //   Ben Maurer (bmaurer@users.sourceforge.net)
8 //
9 // (C) 2003 Martin Willemoes Hansen
10 // (C) 2003 Ben Maurer
11 //
12
13 using NUnit.Framework;
14 using System;
15 using System.IO;
16 using System.Text;
17
18 namespace MonoTests.System
19 {
20         [TestFixture]
21         public class UriTest
22         {
23                 protected bool isWin32 = false;
24
25                 [TestFixtureSetUp]
26                 public void GetReady ()
27                 {
28                         isWin32 = (Path.DirectorySeparatorChar == '\\');
29                 }
30
31                 [Test]
32                 public void Constructors ()
33                 {
34                         Uri uri = null;
35
36                         /*
37                         uri = new Uri ("http://www.ximian.com/foo" + ((char) 0xa9) + "/bar/index.cgi?a=1&b=" + ((char) 0xa9) + "left#fragm?ent2");
38                         Print (uri);
39
40                         uri = new Uri ("http://www.ximian.com/foo/xxx\"()-._;<=>@{|}~-,.`_^]\\[xx/" + ((char) 0xa9) + "/bar/index.cgi#fra+\">=@[gg]~gment2");
41                         Print (uri);
42
43                         uri = new Uri("http://11.22.33.588:9090");
44                         Print (uri);
45
46                         uri = new Uri("http://[11:22:33::88]:9090");
47                         Print (uri);
48
49                         uri = new Uri("http://[::127.11.22.33]:8080");
50                         Print (uri);
51
52                         uri = new Uri("http://[abcde::127.11.22.33]:8080");
53                         Print (uri);
54                         */
55
56                         /*
57                         uri = new Uri ("http://www.contoso.com:1234/foo/bar/");
58                         Print (uri);
59
60                         uri = new Uri ("http://www.contoso.com:1234/foo/bar");
61                         Print (uri);
62
63                         uri = new Uri ("http://www.contoso.com:1234/");
64                         Print (uri);
65
66                         uri = new Uri ("http://www.contoso.com:1234");
67                         Print (uri);
68                         */
69
70                         uri = new Uri("  \r  \n http://test.com\r\n \r\r  ");
71                         Assert.AreEqual ("http://test.com/", uri.ToString(), "#k0");
72                         Assert.AreEqual ("http", uri.GetComponents (UriComponents.Scheme, UriFormat.UriEscaped), "#k0-gc");
73
74                         uri = new Uri ("http://contoso.com?subject=uri");
75                         Assert.AreEqual ("/", uri.AbsolutePath, "#k1");
76                         Assert.AreEqual ("http://contoso.com/?subject=uri", uri.AbsoluteUri, "#k2");
77                         Assert.AreEqual ("contoso.com", uri.Authority, "#k3");
78                         Assert.AreEqual ("", uri.Fragment, "#k4");
79                         Assert.AreEqual ("contoso.com", uri.Host, "#k5");
80                         Assert.AreEqual (UriHostNameType.Dns, uri.HostNameType, "#k6");
81                         Assert.AreEqual (true, uri.IsDefaultPort, "#k7");
82                         Assert.AreEqual (false, uri.IsFile, "#k8");
83                         Assert.AreEqual (false, uri.IsLoopback, "#k9");
84                         Assert.AreEqual (false, uri.IsUnc, "#k10");
85                         Assert.AreEqual ("/", uri.LocalPath, "#k11");
86                         Assert.AreEqual ("/?subject=uri", uri.PathAndQuery, "#k12");
87                         Assert.AreEqual (80, uri.Port, "#k13");
88                         Assert.AreEqual ("?subject=uri", uri.Query, "#k14");
89                         Assert.AreEqual ("http", uri.Scheme, "#k15");
90                         Assert.AreEqual (false, uri.UserEscaped, "#k16");
91                         Assert.AreEqual ("", uri.UserInfo, "#k17");
92
93                         uri = new Uri ("mailto:user:pwd@contoso.com?subject=uri");
94                         Assert.AreEqual ("", uri.AbsolutePath, "#m1");
95                         Assert.AreEqual ("mailto:user:pwd@contoso.com?subject=uri", uri.AbsoluteUri, "#m2");
96                         Assert.AreEqual ("contoso.com", uri.Authority, "#m3");
97                         Assert.AreEqual ("", uri.Fragment, "#m4");
98                         Assert.AreEqual ("contoso.com", uri.Host, "#m5");
99                         Assert.AreEqual (UriHostNameType.Dns, uri.HostNameType, "#m6");
100                         Assert.AreEqual (true, uri.IsDefaultPort, "#m7");
101                         Assert.AreEqual (false, uri.IsFile, "#m8");
102                         Assert.AreEqual (false, uri.IsLoopback, "#m9");
103                         Assert.AreEqual (false, uri.IsUnc, "#m10");
104                         Assert.AreEqual ("", uri.LocalPath, "#m11");
105                         Assert.AreEqual ("?subject=uri", uri.PathAndQuery, "#m12");
106                         Assert.AreEqual (25, uri.Port, "#m13");
107                         Assert.AreEqual ("?subject=uri", uri.Query, "#m14");
108                         Assert.AreEqual ("mailto", uri.Scheme, "#m15");
109                         Assert.AreEqual (false, uri.UserEscaped, "#m16");
110                         Assert.AreEqual ("user:pwd", uri.UserInfo, "#m17");
111
112                         uri = new Uri("myscheme://127.0.0.1:5");
113                         Assert.AreEqual ("myscheme://127.0.0.1:5/", uri.ToString(), "#c1");
114
115                         uri = new Uri (@"\\myserver\mydir\mysubdir\myfile.ext");
116                         Assert.AreEqual ("/mydir/mysubdir/myfile.ext", uri.AbsolutePath, "#n1");
117                         Assert.AreEqual ("file://myserver/mydir/mysubdir/myfile.ext", uri.AbsoluteUri, "#n2");
118                         Assert.AreEqual ("myserver", uri.Authority, "#n3");
119                         Assert.AreEqual ("", uri.Fragment, "#n4");
120                         Assert.AreEqual ("myserver", uri.Host, "#n5");
121                         Assert.AreEqual (UriHostNameType.Dns, uri.HostNameType, "#n6");
122                         Assert.AreEqual (true, uri.IsDefaultPort, "#n7");
123                         Assert.AreEqual (true, uri.IsFile, "#n8");
124                         Assert.AreEqual (false, uri.IsLoopback, "#n9");
125                         Assert.AreEqual (true, uri.IsUnc, "#n10");
126
127                         if (isWin32)
128                                 Assert.AreEqual (@"\\myserver\mydir\mysubdir\myfile.ext", uri.LocalPath, "#n11");
129                         else
130                                 // myserver never could be the part of Unix path.
131                                 Assert.AreEqual ("/mydir/mysubdir/myfile.ext", uri.LocalPath, "#n11");
132
133                         Assert.AreEqual ("/mydir/mysubdir/myfile.ext", uri.PathAndQuery, "#n12");
134                         Assert.AreEqual (-1, uri.Port, "#n13");
135                         Assert.AreEqual ("", uri.Query, "#n14");
136                         Assert.AreEqual ("file", uri.Scheme, "#n15");
137                         Assert.AreEqual (false, uri.UserEscaped, "#n16");
138                         Assert.AreEqual ("", uri.UserInfo, "#n17");
139
140                         uri = new Uri (new Uri("http://www.contoso.com"), "Hello World.htm", true);
141                         Assert.AreEqual ("http://www.contoso.com/Hello World.htm", uri.AbsoluteUri, "#rel1a");
142                         Assert.AreEqual (true, uri.UserEscaped, "#rel1b");
143                         uri = new Uri (new Uri("http://www.contoso.com"), "Hello World.htm", false);
144                         Assert.AreEqual ("http://www.contoso.com/Hello%20World.htm", uri.AbsoluteUri, "#rel2a");
145                         Assert.AreEqual (false, uri.UserEscaped, "#rel2b");
146                         uri = new Uri (new Uri("http://www.contoso.com"), "http://www.xxx.com/Hello World.htm", false);
147                         Assert.AreEqual ("http://www.xxx.com/Hello%20World.htm", uri.AbsoluteUri, "#rel3");
148
149                         uri = new Uri (new Uri("http://www.contoso.com"), "foo/bar/Hello World.htm?x=0:8", false);
150                         Assert.AreEqual ("http://www.contoso.com/foo/bar/Hello%20World.htm?x=0:8", uri.AbsoluteUri, "#rel5");
151                         uri = new Uri (new Uri("http://www.contoso.com/xxx/yyy/index.htm"), "foo/bar/Hello World.htm?x=0:8", false);
152                         Assert.AreEqual ("http://www.contoso.com/xxx/yyy/foo/bar/Hello%20World.htm?x=0:8", uri.AbsoluteUri, "#rel6");
153                         uri = new Uri (new Uri("http://www.contoso.com/xxx/yyy/index.htm"), "/foo/bar/Hello World.htm?x=0:8", false);
154                         Assert.AreEqual ("http://www.contoso.com/foo/bar/Hello%20World.htm?x=0:8", uri.AbsoluteUri, "#rel7");
155                         uri = new Uri (new Uri("http://www.contoso.com/xxx/yyy/index.htm"), "../foo/bar/Hello World.htm?x=0:8", false);
156                         Assert.AreEqual ("http://www.contoso.com/xxx/foo/bar/Hello%20World.htm?x=0:8", uri.AbsoluteUri, "#rel8");
157                         uri = new Uri (new Uri("http://www.contoso.com/xxx/yyy/index.htm"), "../../../foo/bar/Hello World.htm?x=0:8", false);
158 #if NET_2_0
159                         Assert.AreEqual ("http://www.contoso.com/foo/bar/Hello%20World.htm?x=0:8", uri.AbsoluteUri, "#rel9");
160                         Assert.AreEqual ("/foo/bar/Hello%20World.htm", uri.AbsolutePath, "#rel9-path");
161 #else
162                         Assert.AreEqual ("http://www.contoso.com/../foo/bar/Hello%20World.htm?x=0:8", uri.AbsoluteUri, "#rel9");
163 #endif
164                         uri = new Uri (new Uri("http://www.contoso.com/xxx/yyy/index.htm"), "./foo/bar/Hello World.htm?x=0:8", false);
165                         Assert.AreEqual ("http://www.contoso.com/xxx/yyy/foo/bar/Hello%20World.htm?x=0:8", uri.AbsoluteUri, "#rel10");
166
167                         uri = new Uri (new Uri("http://www.contoso.com/foo/bar/index.html?x=0"), String.Empty, false);
168                         Assert.AreEqual ("http://www.contoso.com/foo/bar/index.html?x=0", uri.ToString (), "#22");
169
170                         uri = new Uri (new Uri("http://www.xxx.com"), "?x=0");
171                         Assert.AreEqual ("http://www.xxx.com/?x=0", uri.ToString(), "#rel30");
172 #if !NET_4_0
173                         uri = new Uri (new Uri("http://www.xxx.com/index.htm"), "?x=0");
174                         Assert.AreEqual ("http://www.xxx.com/?x=0", uri.ToString(), "#rel31");
175 #endif
176                         uri = new Uri (new Uri("http://www.xxx.com/index.htm"), "#here");
177                         Assert.AreEqual ("http://www.xxx.com/index.htm#here", uri.ToString(), "#rel32");
178 #if NET_2_0
179                         uri = new Uri ("relative", UriKind.Relative);
180                         uri = new Uri ("relative/abc", UriKind.Relative);
181                         uri = new Uri ("relative", UriKind.RelativeOrAbsolute);
182
183                         Assert.IsTrue (!uri.IsAbsoluteUri, "#rel33");
184                         Assert.AreEqual (uri.OriginalString, "relative", "#rel34");
185                         Assert.IsTrue (!uri.UserEscaped, "#rel35");
186 #endif
187                 }
188
189                 [Test]
190                 public void Constructor_DualHostPort ()
191                 {
192                         string relative = "foo:8080/bar/Hello World.htm";
193                         Uri uri = new Uri (new Uri("http://www.contoso.com"), relative, false);
194                         Assert.AreEqual ("8080/bar/Hello%20World.htm", uri.AbsolutePath, "AbsolutePath");
195                         Assert.AreEqual ("foo:8080/bar/Hello%20World.htm", uri.AbsoluteUri, "AbsoluteUri");
196                         Assert.AreEqual (String.Empty, uri.Authority, "Authority");
197                         Assert.AreEqual (String.Empty, uri.Fragment, "Fragment");
198                         Assert.AreEqual (String.Empty, uri.Host, "Host");
199                         Assert.AreEqual ("8080/bar/Hello%20World.htm", uri.PathAndQuery, "PathAndQuery");
200                         Assert.AreEqual (-1, uri.Port, "Port");
201                         Assert.AreEqual (String.Empty, uri.Query, "Query");
202                         Assert.AreEqual ("foo", uri.Scheme, "Scheme");
203                         Assert.AreEqual (String.Empty, uri.UserInfo, "Query");
204
205                         Assert.AreEqual ("8080/", uri.Segments[0], "Segments[0]");
206                         Assert.AreEqual ("bar/", uri.Segments[1], "Segments[1]");
207                         Assert.AreEqual ("Hello%20World.htm", uri.Segments[2], "Segments[2]");
208
209                         Assert.IsTrue (uri.IsDefaultPort, "IsDefaultPort");
210                         Assert.IsTrue (!uri.IsFile, "IsFile");
211                         Assert.IsTrue (!uri.IsLoopback, "IsLoopback");
212                         Assert.IsTrue (!uri.IsUnc, "IsUnc");
213                         Assert.IsTrue (!uri.UserEscaped, "UserEscaped");
214 #if NET_2_0
215                         Assert.AreEqual (UriHostNameType.Unknown, uri.HostNameType, "HostNameType");
216                         Assert.IsTrue (uri.IsAbsoluteUri, "IsAbsoluteUri");
217                         Assert.AreEqual (relative, uri.OriginalString, "OriginalString");
218 #else
219                         Assert.AreEqual (UriHostNameType.Basic, uri.HostNameType, "HostNameType");
220 #endif
221                 }
222
223                 [Test]
224 #if NET_2_0
225                 [ExpectedException (typeof (ArgumentNullException))]
226 #else
227                 [ExpectedException (typeof (NullReferenceException))]
228 #endif
229                 public void Constructor_NullStringBool ()
230                 {
231                         new Uri (null, "http://www.contoso.com/index.htm", false);
232                 }
233
234                 [Test]
235 #if ONLY_1_1
236                 [ExpectedException (typeof (NullReferenceException))]
237 #endif
238                 public void Constructor_UriNullBool ()
239                 {
240                         new Uri (new Uri ("http://www.contoso.com"), null, false);
241                 }
242
243                 // regression for bug #47573
244                 [Test]
245                 public void RelativeCtor ()
246                 {
247                         Uri b = new Uri ("http://a/b/c/d;p?q");
248                         Assert.AreEqual ("http://a/g", new Uri (b, "/g").ToString (), "#1");
249                         Assert.AreEqual ("http://g/", new Uri (b, "//g").ToString (), "#2");
250 #if !NET_4_0
251                         Assert.AreEqual ("http://a/b/c/?y", new Uri (b, "?y").ToString (), "#3");
252 #endif
253                         Assert.IsTrue (new Uri (b, "#s").ToString ().EndsWith ("#s"), "#4");
254
255                         Uri u = new Uri (b, "/g?q=r");
256                         Assert.AreEqual ("http://a/g?q=r", u.ToString (), "#5");
257                         Assert.AreEqual ("?q=r", u.Query, "#6");
258
259                         u = new Uri (b, "/g?q=r;. a");
260                         Assert.AreEqual ("http://a/g?q=r;. a", u.ToString (), "#5");
261                         Assert.AreEqual ("?q=r;.%20a", u.Query, "#6");
262                 }
263
264 #if NET_2_0
265                 [Test]
266                 [ExpectedException (typeof (UriFormatException))]
267                 public void RelativeCtor_11_Crasher ()
268                 {
269                         Uri b = new Uri ("http://a/b/c/d;p?q");
270                         // this causes crash under MS.NET 1.1
271                         Assert.AreEqual ("g:h", new Uri (b, "g:h").ToString (), "g:h");
272                 }
273 #endif
274
275                 [Test]
276                 [ExpectedException (typeof (UriFormatException))]
277                 public void Bad_IPv6 ()
278                 {
279                         new Uri ("http://0:0:0:0::127.1.2.3]/");
280                 }
281
282                 [Test]
283 #if ONLY_1_1
284                 [Category ("NotDotNet")]
285 #endif
286                 public void LeadingSlashes_ShouldFailOn1x ()
287                 {
288                         // doesn't (but should) fail under 1.x
289                         Assert.AreEqual ("file:///", new Uri ("file:///").ToString (), "#1");
290                         Assert.AreEqual ("file:///", new Uri ("file://").ToString (), "#2");
291                 }
292
293                 [Test]
294 #if ONLY_1_1
295                 [Category ("NotWorking")]
296 #endif
297                 public void LeadingSlashes_BadResultsOn1x ()
298                 {
299                         // strange behaviours of 1.x - it's probably not worth to fix it
300                         // on Mono as 2.0 has been fixed
301                         Uri u = new Uri ("file:///foo/bar");
302 #if NET_2_0
303                         Assert.AreEqual (String.Empty, u.Host, "#3a");
304                         Assert.AreEqual (UriHostNameType.Basic, u.HostNameType, "#3b");
305                         Assert.AreEqual ("file:///foo/bar", u.ToString (), "#3c");
306                         Assert.AreEqual (false, u.IsUnc, "#3d");
307 #else
308                         // 1.x misinterpret the first path element as the host name
309                         Assert.AreEqual ("foo", u.Host, "#3a");
310                         Assert.AreEqual (UriHostNameType.Dns, u.HostNameType, "#3b");
311                         Assert.AreEqual ("file://foo/bar", u.ToString (), "#3c");
312                         Assert.AreEqual (true, u.IsUnc, "#3d");
313 #endif
314                         u = new Uri ("mailto:/foo");
315 #if NET_2_0
316                         Assert.AreEqual (String.Empty, u.Host, "#13a");
317                         Assert.AreEqual (UriHostNameType.Basic, u.HostNameType, "#13b");
318                         Assert.AreEqual ("mailto:/foo", u.ToString (), "#13c");
319 #else
320                         // 1.x misinterpret the first path element as the host name
321                         Assert.AreEqual ("foo", u.Host, "#13a");
322                         Assert.AreEqual (UriHostNameType.Dns, u.HostNameType, "#13b");
323                         Assert.AreEqual ("mailto:foo", u.ToString (), "#13c");
324 #endif
325                         u = new Uri ("mailto://foo");
326 #if NET_2_0
327                         Assert.AreEqual (String.Empty, u.Host, "#14a");
328                         Assert.AreEqual (UriHostNameType.Basic, u.HostNameType, "#14b");
329                         Assert.AreEqual ("mailto://foo", u.ToString (), "#14c");
330 #else
331                         // 1.x misinterpret the first path element as the host name
332                         Assert.AreEqual ("foo", u.Host, "#14a");
333                         Assert.AreEqual (UriHostNameType.Dns, u.HostNameType, "#14b");
334                         Assert.AreEqual ("mailto://foo/", u.ToString (), "#14c");
335 #endif
336                         u = new Uri ("news:/");
337                         Assert.AreEqual (String.Empty, u.Host, "#18a");
338 #if NET_2_0
339                         Assert.AreEqual (UriHostNameType.Unknown, u.HostNameType, "#18b");
340                         Assert.AreEqual ("news:/", u.ToString (), "#18c");
341                         Assert.AreEqual ("/", u.AbsolutePath, "#18d");
342                         Assert.AreEqual ("news:/", u.AbsoluteUri, "#18e");
343 #else
344                         Assert.AreEqual (UriHostNameType.Basic, u.HostNameType, "#18b");
345                         Assert.AreEqual ("news:", u.ToString (), "#18c");
346                         Assert.AreEqual (String.Empty, u.AbsolutePath, "#18d");
347                         Assert.AreEqual ("news:", u.AbsoluteUri, "#18e");
348 #endif
349                         u = new Uri ("news:/foo");
350                         Assert.AreEqual (String.Empty, u.Host, "#19a");
351 #if NET_2_0
352                         Assert.AreEqual (UriHostNameType.Unknown, u.HostNameType, "#19b");
353                         Assert.AreEqual ("news:/foo", u.ToString (), "#19c");
354                         Assert.AreEqual ("/foo", u.AbsolutePath, "#19d");
355                         Assert.AreEqual ("news:/foo", u.AbsoluteUri, "#19e");
356 #else
357                         Assert.AreEqual (UriHostNameType.Basic, u.HostNameType, "#19b");
358                         Assert.AreEqual ("news:foo", u.ToString (), "#19c");
359                         Assert.AreEqual ("foo", u.AbsolutePath, "#19d");
360                         Assert.AreEqual ("news:foo", u.AbsoluteUri, "#19e");
361 #endif
362                         u = new Uri ("news://foo");
363 #if NET_2_0
364                         Assert.AreEqual (String.Empty, u.Host, "#20a");
365                         Assert.AreEqual (UriHostNameType.Unknown, u.HostNameType, "#20b");
366                         Assert.AreEqual ("news://foo", u.ToString (), "#20c");
367                         Assert.AreEqual ("//foo", u.AbsolutePath, "#20d");
368                         Assert.AreEqual ("news://foo", u.AbsoluteUri, "#20e");
369 #else
370                         Assert.AreEqual ("foo", u.Host, "#20a");
371                         Assert.AreEqual (UriHostNameType.Dns, u.HostNameType, "#20b");
372                         Assert.AreEqual ("news://foo/", u.ToString (), "#20c");
373                         Assert.AreEqual ("/", u.AbsolutePath, "#20d");
374                         Assert.AreEqual ("news://foo/", u.AbsoluteUri, "#20e");
375 #endif
376                         u = new Uri ("news://foo/bar");
377 #if NET_2_0
378                         Assert.AreEqual (String.Empty, u.Host, "#22a");
379                         Assert.AreEqual (UriHostNameType.Unknown, u.HostNameType, "#22b");
380                         Assert.AreEqual ("news://foo/bar", u.ToString (), "#22c");
381                         Assert.AreEqual ("//foo/bar", u.AbsolutePath, "#22d");
382                         Assert.AreEqual ("news://foo/bar", u.AbsoluteUri, "#22e");
383 #else
384                         Assert.AreEqual ("foo", u.Host, "#22a");
385                         Assert.AreEqual (UriHostNameType.Dns, u.HostNameType, "#22b");
386                         Assert.AreEqual ("news://foo/bar", u.ToString (), "#22c");
387                         Assert.AreEqual ("/bar", u.AbsolutePath, "#22d");
388                         Assert.AreEqual ("news://foo/bar", u.AbsoluteUri, "#22e");
389 #endif
390                 }
391
392                 [Test]
393 #if ONLY_1_1
394                 [Category ("NotDotNet")] // does (but shouldn't) fail under 1.x
395 #endif
396                 public void LeadingSlashes_FailOn1x ()
397                 {
398                         // 1.x throws an UriFormatException because it can't decode the host name
399                         Uri u = new Uri ("mailto:");
400                         Assert.AreEqual (String.Empty, u.Host, "#10a");
401                         Assert.AreEqual (UriHostNameType.Basic, u.HostNameType, "#10b");
402                         Assert.AreEqual ("mailto:", u.ToString (), "#10c");
403
404                         // 1.x throws an UriFormatException because it can't decode the host name
405                         u = new Uri ("mailto:/");
406                         Assert.AreEqual (String.Empty, u.Host, "#12a");
407                         Assert.AreEqual (UriHostNameType.Basic, u.HostNameType, "#12b");
408                         Assert.AreEqual ("mailto:/", u.ToString (), "#12c");
409
410                         // 1.x throws an UriFormatException because it cannot detect the format
411                         u = new Uri ("mailto:///foo");
412                         Assert.AreEqual (String.Empty, u.Host, "#15a");
413                         Assert.AreEqual (UriHostNameType.Basic, u.HostNameType, "#15b");
414                         Assert.AreEqual ("mailto:///foo", u.ToString (), "#15c");
415
416                         // 1.x throws an UriFormatException because it cannot detect the format
417                         u = new Uri ("news:///foo");
418                         Assert.AreEqual (String.Empty, u.Host, "#21a");
419 #if NET_2_0
420                         Assert.AreEqual (UriHostNameType.Unknown, u.HostNameType, "#21b");
421 #else
422                         Assert.AreEqual (UriHostNameType.Basic, u.HostNameType, "#21b");
423 #endif
424                         Assert.AreEqual ("news:///foo", u.ToString (), "#21c");
425                         Assert.AreEqual ("///foo", u.AbsolutePath, "#21d");
426                         Assert.AreEqual ("news:///foo", u.AbsoluteUri, "#21e");
427                 }
428
429                 [Test]
430                 // some tests from bug 75144
431                 public void LeadingSlashes ()
432                 {
433                         Uri u = new Uri ("file://foo/bar");
434                         Assert.AreEqual ("foo", u.Host, "#5a");
435                         Assert.AreEqual (UriHostNameType.Dns, u.HostNameType, "#5b");
436                         Assert.AreEqual ("file://foo/bar", u.ToString (), "#5c");
437                         Assert.AreEqual (true, u.IsUnc, "#5d");
438
439                         u = new Uri ("file:////foo/bar");
440                         Assert.AreEqual ("foo", u.Host, "#7a");
441                         Assert.AreEqual (UriHostNameType.Dns, u.HostNameType, "#7b");
442                         Assert.AreEqual ("file://foo/bar", u.ToString (), "#7c");
443                         Assert.AreEqual (true, u.IsUnc, "#7d");
444
445                         Assert.AreEqual ("file://foo/bar", new Uri ("file://///foo/bar").ToString(), "#9");
446
447                         u = new Uri ("mailto:foo");
448                         Assert.AreEqual ("foo", u.Host, "#11a");
449                         Assert.AreEqual (UriHostNameType.Dns, u.HostNameType, "#11b");
450                         Assert.AreEqual ("mailto:foo", u.ToString (), "#11c");
451
452                         u = new Uri ("news:");
453                         Assert.AreEqual (String.Empty, u.Host, "#16a");
454 #if NET_2_0
455                         Assert.AreEqual (UriHostNameType.Unknown, u.HostNameType, "#16b");
456 #else
457                         Assert.AreEqual (UriHostNameType.Basic, u.HostNameType, "#16b");
458 #endif
459                         Assert.AreEqual ("news:", u.ToString (), "#16c");
460
461                         u = new Uri ("news:foo");
462                         Assert.AreEqual (String.Empty, u.Host, "#17a");
463 #if NET_2_0
464                         Assert.AreEqual (UriHostNameType.Unknown, u.HostNameType, "#17b");
465 #else
466                         Assert.AreEqual (UriHostNameType.Basic, u.HostNameType, "#17b");
467 #endif
468                         Assert.AreEqual ("news:foo", u.ToString (), "#17c");
469                         Assert.AreEqual ("foo", u.AbsolutePath, "#17d");
470                         Assert.AreEqual ("news:foo", u.AbsoluteUri, "#17e");
471                 }
472
473                 [Test]
474                 [ExpectedException (typeof (UriFormatException))]
475                 public void HttpHostname1 ()
476                 {
477                         new Uri ("http:");
478                 }
479
480                 [Test]
481                 [ExpectedException (typeof (UriFormatException))]
482 #if ONLY_1_1
483                 [Category ("NotDotNet")] // doesn't fail under 1.x
484 #endif
485                 public void HttpHostname2 ()
486                 {
487                         new Uri ("http:a");
488                 }
489
490                 [Test]
491                 [ExpectedException (typeof (UriFormatException))]
492                 public void HttpHostname3 ()
493                 {
494                         new Uri ("http:/");
495                 }
496
497                 [Test]
498                 [ExpectedException (typeof (UriFormatException))]
499 #if ONLY_1_1
500                 [Category ("NotDotNet")] // doesn't fail under 1.x
501 #endif
502                 public void HttpHostname4 ()
503                 {
504                         new Uri ("http:/foo");
505                 }
506
507                 [Test]
508                 [ExpectedException (typeof (UriFormatException))]
509                 public void HttpHostname5 ()
510                 {
511                         new Uri ("http://");
512                 }
513
514                 [Test]
515                 [ExpectedException (typeof (UriFormatException))]
516                 public void HttpHostname6 ()
517                 {
518                         new Uri ("http:///");
519                 }
520
521                 [Test]
522                 [ExpectedException (typeof (UriFormatException))]
523                 public void HttpHostname7 ()
524                 {
525                         new Uri ("http:///foo");
526                 }
527
528                 [Test]
529                 [ExpectedException (typeof (UriFormatException))]
530                 public void InvalidFile1 ()
531                 {
532                         new Uri ("file:");
533                 }
534
535                 [Test]
536                 [ExpectedException (typeof (UriFormatException))]
537                 public void InvalidFile2 ()
538                 {
539                         new Uri ("file:/");
540                 }
541
542                 [Test]
543                 [ExpectedException (typeof (UriFormatException))]
544                 public void InvalidFile3 ()
545                 {
546                         new Uri ("file:/foo");
547                 }
548
549                 [Test]
550                 [ExpectedException (typeof (UriFormatException))]
551                 public void InvalidScheme ()
552                 {
553                         new Uri ("_:/");
554                 }
555
556                 [Test]
557                 public void ConstructorsRejectRelativePath ()
558                 {
559                         string [] reluris = new string [] {
560                                 "readme.txt",
561                                 "thisdir/childdir/file",
562                                 "./testfile"
563                         };
564                         string [] winRelUris = new string [] {
565                                 "c:readme.txt"
566                         };
567
568                         for (int i = 0; i < reluris.Length; i++) {
569                                 try {
570                                         new Uri (reluris [i]);
571                                         Assert.Fail ("Should be failed: " + reluris [i]);
572                                 } catch (UriFormatException) {
573                                 }
574                         }
575
576                         if (isWin32) {
577                                 for (int i = 0; i < winRelUris.Length; i++) {
578                                         try {
579                                                 new Uri (winRelUris [i]);
580                                                 Assert.Fail ("Should be failed: " + winRelUris [i]);
581                                         } catch (UriFormatException) {
582                                         }
583                                 }
584                         }
585                 }
586
587                 [Test]
588                 public void LocalPath ()
589                 {
590                         Uri uri = new Uri ("c:\\tmp\\hello.txt");
591                         Assert.AreEqual ("file:///c:/tmp/hello.txt", uri.ToString (), "#1a");
592                         Assert.AreEqual ("c:\\tmp\\hello.txt", uri.LocalPath, "#1b");
593                         Assert.AreEqual ("file", uri.Scheme, "#1c");
594                         Assert.AreEqual ("", uri.Host, "#1d");
595                         Assert.AreEqual ("c:/tmp/hello.txt", uri.AbsolutePath, "#1e");
596
597                         uri = new Uri ("file:////////cygwin/tmp/hello.txt");
598                         Assert.AreEqual ("file://cygwin/tmp/hello.txt", uri.ToString (), "#3a");
599                         if (isWin32)
600                                 Assert.AreEqual ("\\\\cygwin\\tmp\\hello.txt", uri.LocalPath, "#3b win32");
601                         else
602                                 Assert.AreEqual ("/tmp/hello.txt", uri.LocalPath, "#3b *nix");
603                         Assert.AreEqual ("file", uri.Scheme, "#3c");
604                         Assert.AreEqual ("cygwin", uri.Host, "#3d");
605                         Assert.AreEqual ("/tmp/hello.txt", uri.AbsolutePath, "#3e");
606
607                         uri = new Uri ("file://mymachine/cygwin/tmp/hello.txt");
608                         Assert.AreEqual ("file://mymachine/cygwin/tmp/hello.txt", uri.ToString (), "#4a");
609                         if (isWin32)
610                                 Assert.AreEqual ("\\\\mymachine\\cygwin\\tmp\\hello.txt", uri.LocalPath, "#4b win32");
611                         else
612                                 Assert.AreEqual ("/cygwin/tmp/hello.txt", uri.LocalPath, "#4b *nix");
613                         Assert.AreEqual ("file", uri.Scheme, "#4c");
614                         Assert.AreEqual ("mymachine", uri.Host, "#4d");
615                         Assert.AreEqual ("/cygwin/tmp/hello.txt", uri.AbsolutePath, "#4e");
616
617                         uri = new Uri ("file://///c:/cygwin/tmp/hello.txt");
618                         Assert.AreEqual ("file:///c:/cygwin/tmp/hello.txt", uri.ToString (), "#5a");
619                         Assert.AreEqual ("c:\\cygwin\\tmp\\hello.txt", uri.LocalPath, "#5b");
620                         Assert.AreEqual ("file", uri.Scheme, "#5c");
621                         Assert.AreEqual ("", uri.Host, "#5d");
622                         Assert.AreEqual ("c:/cygwin/tmp/hello.txt", uri.AbsolutePath, "#5e");
623                 }
624
625                 [Test]
626                 public void LocalPath_FileHost ()
627                 {
628                         // Hmm, they should be regarded just as a host name, since all URIs are base on absolute path.
629                         Uri uri = new Uri("file://one_file.txt");
630 #if NET_2_0
631                         Assert.AreEqual ("file://one_file.txt/", uri.ToString(), "#6a");
632                         Assert.AreEqual ("/", uri.AbsolutePath, "#6e");
633                         Assert.AreEqual ("/", uri.PathAndQuery, "#6f");
634                         Assert.AreEqual ("file://one_file.txt/", uri.GetLeftPart (UriPartial.Path), "#6g");
635 #else
636                         Assert.AreEqual ("file://one_file.txt", uri.ToString(), "#6a");
637                         Assert.AreEqual ("", uri.AbsolutePath, "#6e");
638                         Assert.AreEqual ("", uri.PathAndQuery, "#6f");
639                         Assert.AreEqual ("file://one_file.txt", uri.GetLeftPart (UriPartial.Path), "#6g");
640 #endif
641                         if (isWin32)
642                                 Assert.AreEqual ("\\\\one_file.txt", uri.LocalPath, "#6b");
643                         else
644                                 Assert.AreEqual ("/", uri.LocalPath, "#6b");
645                         Assert.AreEqual ("file", uri.Scheme, "#6c");
646                         Assert.AreEqual ("one_file.txt", uri.Host, "#6d");
647
648                         // same tests - but original Uri is now ending with a '/'
649
650                         uri = new Uri ("file://one_file.txt/");
651                         Assert.AreEqual ("file://one_file.txt/", uri.ToString (), "#7a");
652                         Assert.AreEqual ("/", uri.AbsolutePath, "#7e");
653                         Assert.AreEqual ("/", uri.PathAndQuery, "#7f");
654                         Assert.AreEqual ("file://one_file.txt/", uri.GetLeftPart (UriPartial.Path), "#7g");
655 #if !TARGET_JVM
656                         if (isWin32)
657                                 Assert.AreEqual ("\\\\one_file.txt\\", uri.LocalPath, "#7b");
658                         else
659                                 Assert.AreEqual ("/", uri.LocalPath, "#7b");
660 #endif
661                         Assert.AreEqual ("file", uri.Scheme, "#7c");
662                         Assert.AreEqual ("one_file.txt", uri.Host, "#7d");
663                 }
664
665                 [Test]
666                 public void LocalPath_Escape ()
667                 {
668                         // escape
669                         Uri uri = new Uri ("file:///tmp/a%20a");
670                         if (isWin32) {
671 #if NET_2_0
672                                 Assert.IsTrue (uri.LocalPath.EndsWith ("/tmp/a a"), "#7a:" + uri.LocalPath);
673 #else
674                                 // actually MS.NET treats /// as \\ thus it fails here.
675                                 Assert.IsTrue (uri.LocalPath.EndsWith ("\\tmp\\a a"), "#7a:" + uri.LocalPath);
676 #endif
677                         } else
678                                 Assert.AreEqual ("/tmp/a a", uri.LocalPath, "#7b");
679
680                         uri = new Uri ("file:///tmp/foo%25bar");
681                         if (isWin32) {
682 #if NET_2_0
683                                 Assert.IsTrue (uri.LocalPath.EndsWith ("/tmp/foo%bar"), "#8a:" + uri.LocalPath);
684                                 Assert.IsTrue (uri.ToString ().EndsWith ("//tmp/foo%25bar"), "#8c:" + uri.ToString ());
685 #else
686                                 // actually MS.NET treats /// as \\ thus it fails here.
687                                 Assert.IsTrue (uri.LocalPath.EndsWith ("\\tmp\\foo%bar"), "#8a:" + uri.LocalPath);
688                                 // ditto, file://tmp/foo%25bar (bug in 1.x)
689                                 Assert.IsTrue (uri.ToString ().EndsWith ("//tmp/foo%bar"), "#8c:" + uri.ToString ());
690 #endif
691                         } else {
692                                 Assert.AreEqual ("/tmp/foo%bar", uri.LocalPath, "#8b");
693                                 Assert.AreEqual ("file:///tmp/foo%25bar", uri.ToString (), "#8d");
694                         }
695                         // bug #76643
696                         uri = new Uri ("file:///foo%25bar");
697                         if (isWin32) {
698 #if NET_2_0
699                                 Assert.IsTrue (uri.LocalPath.EndsWith ("/foo%bar"), "#9a:" + uri.LocalPath);
700 #else
701                                 // actually MS.NET treats /// as \\ thus it fails here.
702                                 Assert.IsTrue (uri.LocalPath.EndsWith ("\\foo%25bar"), "#9a:" + uri.LocalPath);
703 #endif
704                                 // ditto, file://tmp/foo%25bar (bug in 1.x)
705                                 Assert.IsTrue (uri.ToString ().EndsWith ("//foo%25bar"), "#9c:" + uri.ToString ());
706                         } else {
707                                 Assert.AreEqual ("/foo%bar", uri.LocalPath, "#9b");
708                                 Assert.AreEqual ("file:///foo%25bar", uri.ToString (), "#9d");
709                         }
710                 }
711
712                 // Novell Bugzilla #320614
713                 [Test]
714                 public void QueryEscape ()
715                 {
716                         Uri u1 = new Uri("http://localhost:8080/test.aspx?ReturnUrl=%2fSearchDoc%2fSearcher.aspx");
717                         Uri u2 = new Uri("http://localhost:8080/test.aspx?ReturnUrl=%252fSearchDoc%252fSearcher.aspx");
718
719                         Assert.AreEqual ("http://localhost:8080/test.aspx?ReturnUrl=/SearchDoc/Searcher.aspx", u1.ToString (), "QE1");
720 #if NET_2_0
721                         Assert.AreEqual ("http://localhost:8080/test.aspx?ReturnUrl=%252fSearchDoc%252fSearcher.aspx", u2.ToString (), "QE2");
722 #else
723                         Assert.AreEqual ("http://localhost:8080/test.aspx?ReturnUrl=%2fSearchDoc%2fSearcher.aspx", u2.ToString (), "QE2");
724 #endif
725                 }
726
727                 [Test]
728                 public void UnixPath () {
729                         if (!isWin32)
730                                 Assert.AreEqual ("file:///cygwin/tmp/hello.txt", new Uri ("/cygwin/tmp/hello.txt").ToString (), "#6a");
731                 }
732
733                 [Test]
734                 public void Unc ()
735                 {
736                         Uri uri = new Uri ("http://www.contoso.com");
737                         Assert.IsTrue (!uri.IsUnc, "#1");
738
739                         uri = new Uri ("news:123456@contoso.com");
740                         Assert.IsTrue (!uri.IsUnc, "#2");
741
742                         uri = new Uri ("file://server/filename.ext");
743                         Assert.IsTrue (uri.IsUnc, "#3");
744
745                         uri = new Uri (@"\\server\share\filename.ext");
746                         Assert.IsTrue (uri.IsUnc, "#6");
747
748                         uri = new Uri (@"a:\dir\filename.ext");
749                         Assert.IsTrue (!uri.IsUnc, "#8");
750                 }
751
752                 [Test]
753                 [Category("NotDotNet")]
754                 public void UncFail ()
755                 {
756                         if (!isWin32) {
757                                 Uri uri = new Uri ("/home/user/dir/filename.ext");
758                                 Assert.IsTrue (!uri.IsUnc, "#7");
759                         }
760                 }
761
762                 [Test]
763                 public void FromHex ()
764                 {
765                         Assert.AreEqual (0, Uri.FromHex ('0'), "#1");
766                         Assert.AreEqual (9, Uri.FromHex ('9'), "#2");
767                         Assert.AreEqual (10, Uri.FromHex ('a'), "#3");
768                         Assert.AreEqual (15, Uri.FromHex ('f'), "#4");
769                         Assert.AreEqual (10, Uri.FromHex ('A'), "#5");
770                         Assert.AreEqual (15, Uri.FromHex ('F'), "#6");
771                         try {
772                                 Uri.FromHex ('G');
773                                 Assert.Fail ("#7");
774                         } catch (ArgumentException) {}
775                         try {
776                                 Uri.FromHex (' ');
777                                 Assert.Fail ("#8");
778                         } catch (ArgumentException) {}
779                         try {
780                                 Uri.FromHex ('%');
781                                 Assert.Fail ("#8");
782                         } catch (ArgumentException) {}
783                 }
784
785                 class UriEx : Uri
786                 {
787                         public UriEx (string s) : base (s)
788                         {
789                         }
790
791                         public string UnescapeString (string s)
792                         {
793                                 return Unescape (s);
794                         }
795
796                         public static string UnescapeString (string uri, string target)
797                         {
798                                 return new UriEx (uri).UnescapeString (target);
799                         }
800                 }
801
802                 [Test]
803                 public void Unescape ()
804                 {
805                         Assert.AreEqual ("#", UriEx.UnescapeString ("file://localhost/c#", "%23"), "#1");
806                         Assert.AreEqual ("c#", UriEx.UnescapeString ("file://localhost/c#", "c%23"), "#2");
807                         Assert.AreEqual ("\xA9", UriEx.UnescapeString ("file://localhost/c#", "%A9"), "#3");
808                         Assert.AreEqual ("#", UriEx.UnescapeString ("http://localhost/c#", "%23"), "#1");
809                         Assert.AreEqual ("c#", UriEx.UnescapeString ("http://localhost/c#", "c%23"), "#2");
810                         Assert.AreEqual ("\xA9", UriEx.UnescapeString ("http://localhost/c#", "%A9"), "#3");
811                 }
812
813                 [Test]
814                 public void HexEscape ()
815                 {
816                         Assert.AreEqual ("%20", Uri.HexEscape (' '), "#1");
817                         Assert.AreEqual ("%A9", Uri.HexEscape ((char) 0xa9), "#2");
818                         Assert.AreEqual ("%41", Uri.HexEscape ('A'), "#3");
819                         try {
820                                 Uri.HexEscape ((char) 0x0369);
821                                 Assert.Fail ("#4");
822                         } catch (ArgumentOutOfRangeException) {}
823                 }
824
825         [Test]
826         public void MoreHexEscape()
827         {
828             string url = "http://guyc-2003-sp/wiki/wiki%20document%20library/בד%20יקה.docx";
829             string escapedAbsolutePath = "/wiki/wiki%20document%20library/%D7%91%D7%93%20%D7%99%D7%A7%D7%94.docx";
830             Uri u = new Uri(url);
831             Assert.AreEqual (escapedAbsolutePath, u.AbsolutePath, "Escaped non-english combo");
832         }
833
834                 [Test]
835                 public void HexUnescape ()
836                 {
837                         int i = 0;
838                         Assert.AreEqual (' ', Uri.HexUnescape ("%20", ref i), "#1");
839                         Assert.AreEqual (3, i, "#2");
840                         i = 4;
841                         Assert.AreEqual ((char) 0xa9, Uri.HexUnescape ("test%a9test", ref i), "#3");
842                         Assert.AreEqual (7, i, "#4");
843                         Assert.AreEqual ('t', Uri.HexUnescape ("test%a9test", ref i), "#5");
844                         Assert.AreEqual (8, i, "#6");
845                         i = 4;
846                         Assert.AreEqual ('%', Uri.HexUnescape ("test%a", ref i), "#5");
847                         Assert.AreEqual (5, i, "#6");
848                         Assert.AreEqual ('%', Uri.HexUnescape ("testx%xx", ref i), "#7");
849                         Assert.AreEqual (6, i, "#8");
850
851                         // Tests from bug 74872 - don't handle multi-byte characters as multi-byte
852                         i = 1;
853                         Assert.AreEqual (227, (int) Uri.HexUnescape ("a%E3%81%8B", ref i), "#9");
854                         Assert.AreEqual (4, i, "#10");
855                         i = 1;
856                         Assert.AreEqual (240, (int) Uri.HexUnescape ("a%F0%90%84%80", ref i), "#11");
857                         Assert.AreEqual (4, i, "#12");
858                 }
859
860 #if !NET_2_0
861                 // These won't pass exactly with MS.NET 1.x, due to differences in the
862                 // handling of backslashes/forwardslashes
863                 [Category ("NotDotNet")]
864 #endif
865                 [Test]
866                 public void HexUnescapeMultiByte ()
867                 {
868                         // Tests from bug 74872
869                         // Note: These won't pass exactly with MS.NET, due to differences in the
870                         // handling of backslashes/forwardslashes
871                         Uri uri;
872                         string path;
873
874                         // 3-byte character
875                         uri = new Uri ("file:///foo/a%E3%81%8Bb", true);
876                         path = uri.LocalPath;
877                         Assert.AreEqual (8, path.Length, "#1");
878                         Assert.AreEqual (0x304B, path [6], "#2");
879
880                         // 4-byte character which should be handled as a surrogate
881                         uri = new Uri ("file:///foo/a%F3%A0%84%80b", true);
882                         path = uri.LocalPath;
883                         Assert.AreEqual (9, path.Length, "#3");
884                         Assert.AreEqual (0xDB40, path [6], "#4");
885                         Assert.AreEqual (0xDD00, path [7], "#5");
886                         Assert.AreEqual (0x62, path [8], "#6");
887
888                         // 2-byte escape sequence, 2 individual characters
889                         uri = new Uri ("file:///foo/a%C2%F8b", true);
890                         path = uri.LocalPath;
891                         Assert.AreEqual (9, path.Length, "#7");
892                         Assert.AreEqual (0xC2, path [6], "#8");
893                         Assert.AreEqual (0xF8, path [7], "#9");
894                 }
895
896                 [Test]
897                 public void IsHexDigit ()
898                 {
899                         Assert.IsTrue (Uri.IsHexDigit ('a'), "#1");
900                         Assert.IsTrue (Uri.IsHexDigit ('f'), "#2");
901                         Assert.IsTrue (!Uri.IsHexDigit ('g'), "#3");
902                         Assert.IsTrue (Uri.IsHexDigit ('0'), "#4");
903                         Assert.IsTrue (Uri.IsHexDigit ('9'), "#5");
904                         Assert.IsTrue (Uri.IsHexDigit ('A'), "#6");
905                         Assert.IsTrue (Uri.IsHexDigit ('F'), "#7");
906                         Assert.IsTrue (!Uri.IsHexDigit ('G'), "#8");
907                 }
908
909                 [Test]
910                 public void IsHexEncoding ()
911                 {
912                         Assert.IsTrue (Uri.IsHexEncoding ("test%a9test", 4), "#1");
913                         Assert.IsTrue (!Uri.IsHexEncoding ("test%a9test", 3), "#2");
914                         Assert.IsTrue (Uri.IsHexEncoding ("test%a9", 4), "#3");
915                         Assert.IsTrue (!Uri.IsHexEncoding ("test%a", 4), "#4");
916                 }
917
918                 [Test]
919                 public void GetLeftPart ()
920                 {
921                         Uri uri = new Uri ("http://www.contoso.com/index.htm#main");
922                         Assert.AreEqual ("http://", uri.GetLeftPart (UriPartial.Scheme), "#1");
923                         Assert.AreEqual ("http://www.contoso.com", uri.GetLeftPart (UriPartial.Authority), "#2");
924                         Assert.AreEqual ("http://www.contoso.com/index.htm", uri.GetLeftPart (UriPartial.Path), "#3");
925
926                         uri = new Uri ("mailto:user@contoso.com?subject=uri");
927                         Assert.AreEqual ("mailto:", uri.GetLeftPart (UriPartial.Scheme), "#4");
928                         Assert.AreEqual ("", uri.GetLeftPart (UriPartial.Authority), "#5");
929                         Assert.AreEqual ("mailto:user@contoso.com", uri.GetLeftPart (UriPartial.Path), "#6");
930
931                         uri = new Uri ("nntp://news.contoso.com/123456@contoso.com");
932                         Assert.AreEqual ("nntp://", uri.GetLeftPart (UriPartial.Scheme), "#7");
933                         Assert.AreEqual ("nntp://news.contoso.com", uri.GetLeftPart (UriPartial.Authority), "#8");
934                         Assert.AreEqual ("nntp://news.contoso.com/123456@contoso.com", uri.GetLeftPart (UriPartial.Path), "#9");
935
936                         uri = new Uri ("news:123456@contoso.com");
937                         Assert.AreEqual ("news:", uri.GetLeftPart (UriPartial.Scheme), "#10");
938                         Assert.AreEqual ("", uri.GetLeftPart (UriPartial.Authority), "#11");
939                         Assert.AreEqual ("news:123456@contoso.com", uri.GetLeftPart (UriPartial.Path), "#12");
940
941                         uri = new Uri ("file://server/filename.ext");
942                         Assert.AreEqual ("file://", uri.GetLeftPart (UriPartial.Scheme), "#13");
943                         Assert.AreEqual ("file://server", uri.GetLeftPart (UriPartial.Authority), "#14");
944                         Assert.AreEqual ("file://server/filename.ext", uri.GetLeftPart (UriPartial.Path), "#15");
945
946                         uri = new Uri (@"\\server\share\filename.ext");
947                         Assert.AreEqual ("file://", uri.GetLeftPart (UriPartial.Scheme), "#20");
948                         Assert.AreEqual ("file://server", uri.GetLeftPart (UriPartial.Authority), "#21");
949                         Assert.AreEqual ("file://server/share/filename.ext", uri.GetLeftPart (UriPartial.Path), "#22");
950
951                         uri = new Uri ("http://www.contoso.com:8080/index.htm#main");
952                         Assert.AreEqual ("http://", uri.GetLeftPart (UriPartial.Scheme), "#23");
953                         Assert.AreEqual ("http://www.contoso.com:8080", uri.GetLeftPart (UriPartial.Authority), "#24");
954                         Assert.AreEqual ("http://www.contoso.com:8080/index.htm", uri.GetLeftPart (UriPartial.Path), "#25");
955                 }
956
957                 [Test]
958                 public void NewsDefaultPort ()
959                 {
960                         Uri uri = new Uri("news://localhost:119/");
961                         Assert.AreEqual (uri.IsDefaultPort, true, "#1");
962                 }
963
964                 [Test]
965                 public void Fragment_Escape ()
966                 {
967                         Uri u = new Uri("http://localhost/index.asp#main#start", false);
968                         Assert.AreEqual (u.Fragment, "#main%23start", "#1");
969
970                         u = new Uri("http://localhost/index.asp#main#start", true);
971                         Assert.AreEqual (u.Fragment, "#main#start", "#2");
972
973                         // The other code path uses a BaseUri
974
975                         Uri b = new Uri ("http://www.gnome.org");
976                         Uri n = new Uri (b, "blah#main#start");
977                         Assert.AreEqual (n.Fragment, "#main%23start", "#3");
978
979                         n = new Uri (b, "blah#main#start", true);
980                         Assert.AreEqual (n.Fragment, "#main#start", "#4");
981                 }
982
983 #if NET_2_0
984                 [Test]
985                 public void Fragment_RelativeUri ()
986                 {
987                         Uri uri1 = new Uri ("http://www.contoso.com/index.htm?x=2");
988                         Uri uri2 = new Uri ("http://www.contoso.com/foo/bar/index.htm#fragment");
989                         Uri relativeUri = uri1.MakeRelativeUri (uri2);
990
991                         try {
992                                 string fragment = relativeUri.Fragment;
993                                 Assert.Fail ("#1: " + fragment);
994                         } catch (InvalidOperationException ex) {
995                                 // This operation is not supported for a relative URI
996                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
997                                 Assert.IsNull (ex.InnerException, "#3");
998                                 Assert.IsNotNull (ex.Message, "#4");
999                         }
1000                 }
1001 #endif
1002
1003                 [Test]
1004                 [ExpectedException(typeof(UriFormatException))]
1005                 public void IncompleteSchemeDelimiter ()
1006                 {
1007                         new Uri ("file:/filename.ext");
1008                 }
1009
1010                 [Test]
1011                 [Category("NotDotNet")]
1012                 public void CheckHostName1 ()
1013                 {
1014                         // reported to MSDN Product Feedback Center (FDBK28671)
1015                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName (":11:22:33:44:55:66:77:88"), "#36 known to fail with ms.net: this is not a valid IPv6 address.");
1016                 }
1017
1018                 [Test]
1019                 public void CheckHostName2 ()
1020                 {
1021                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName (null), "#1");
1022                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName (""), "#2");
1023                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName ("^&()~`!@"), "#3");
1024                         Assert.AreEqual (UriHostNameType.Dns, Uri.CheckHostName ("x"), "#4");
1025                         Assert.AreEqual (UriHostNameType.IPv4, Uri.CheckHostName ("1.2.3.4"), "#5");
1026                         Assert.AreEqual (UriHostNameType.IPv4, Uri.CheckHostName ("0001.002.03.4"), "#6");
1027                         Assert.AreEqual (UriHostNameType.Dns, Uri.CheckHostName ("0001.002.03.256"), "#7");
1028                         Assert.AreEqual (UriHostNameType.Dns, Uri.CheckHostName ("9001.002.03.4"), "#8");
1029                         Assert.AreEqual (UriHostNameType.Dns, Uri.CheckHostName ("www.contoso.com"), "#9");
1030                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName (".www.contoso.com"), "#10");
1031                         Assert.AreEqual (UriHostNameType.Dns, Uri.CheckHostName ("www.contoso.com."), "#11");
1032                         Assert.AreEqual (UriHostNameType.Dns, Uri.CheckHostName ("www.con-toso.com"), "#12");
1033                         Assert.AreEqual (UriHostNameType.Dns, Uri.CheckHostName ("www.con_toso.com"), "#13");
1034                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName ("www.con,toso.com"), "#14");
1035
1036                         // test IPv6
1037                         Assert.AreEqual (UriHostNameType.IPv6, Uri.CheckHostName ("11:22:33:44:55:66:77:88"), "#15");
1038                         Assert.AreEqual (UriHostNameType.IPv6, Uri.CheckHostName ("11::33:44:55:66:77:88"), "#16");
1039                         Assert.AreEqual (UriHostNameType.IPv6, Uri.CheckHostName ("::22:33:44:55:66:77:88"), "#17");
1040                         Assert.AreEqual (UriHostNameType.IPv6, Uri.CheckHostName ("11:22:33:44:55:66:77::"), "#18");
1041                         Assert.AreEqual (UriHostNameType.IPv6, Uri.CheckHostName ("11::88"), "#19");
1042                         Assert.AreEqual (UriHostNameType.IPv6, Uri.CheckHostName ("11::77:88"), "#20");
1043                         Assert.AreEqual (UriHostNameType.IPv6, Uri.CheckHostName ("11:22::88"), "#21");
1044                         Assert.AreEqual (UriHostNameType.IPv6, Uri.CheckHostName ("11::"), "#22");
1045                         Assert.AreEqual (UriHostNameType.IPv6, Uri.CheckHostName ("::88"), "#23");
1046                         Assert.AreEqual (UriHostNameType.IPv6, Uri.CheckHostName ("::1"), "#24");
1047                         Assert.AreEqual (UriHostNameType.IPv6, Uri.CheckHostName ("::"), "#25");
1048                         Assert.AreEqual (UriHostNameType.IPv6, Uri.CheckHostName ("0:0:0:0:0:0:127.0.0.1"), "#26");
1049                         Assert.AreEqual (UriHostNameType.IPv6, Uri.CheckHostName ("::127.0.0.1"), "#27");
1050                         Assert.AreEqual (UriHostNameType.IPv6, Uri.CheckHostName ("::ffFF:169.32.14.5"), "#28");
1051                         Assert.AreEqual (UriHostNameType.IPv6, Uri.CheckHostName ("2001:03A0::/35"), "#29");
1052                         Assert.AreEqual (UriHostNameType.IPv6, Uri.CheckHostName ("[2001:03A0::/35]"), "#30");
1053                         Assert.AreEqual (UriHostNameType.IPv6, Uri.CheckHostName ("2001::03A0:1.2.3.4"), "#33");
1054
1055                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName ("2001::03A0::/35"), "#31");
1056                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName ("2001:03A0::/35a"), "#32");
1057                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName ("::ffff:123.256.155.43"), "#34");
1058                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName (":127.0.0.1"), "#35");
1059                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName ("::11:22:33:44:55:66:77:88"), "#37");
1060                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName ("11:22:33:44:55:66:77:88::"), "#38");
1061                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName ("11:22:33:44:55:66:77:88:"), "#39");
1062                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName ("::acbde"), "#40");
1063                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName ("::abce:"), "#41");
1064                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName ("::abcg"), "#42");
1065                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName (":::"), "#43");
1066                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName (":"), "#44");
1067
1068                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName ("*"), "#45");
1069                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName ("*.go-mono.com"), "#46");
1070                         Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName ("www*.go-mono.com"), "#47");
1071                 }
1072
1073                 [Test]
1074                 public void IsLoopback ()
1075                 {
1076                         Uri uri = new Uri("http://loopback:8080");
1077                         Assert.AreEqual (true, uri.IsLoopback, "#1");
1078                         uri = new Uri("http://localhost:8080");
1079                         Assert.AreEqual (true, uri.IsLoopback, "#2");
1080                         uri = new Uri("http://127.0.0.1:8080");
1081                         Assert.AreEqual (true, uri.IsLoopback, "#3");
1082                         uri = new Uri("http://127.0.0.001:8080");
1083                         Assert.AreEqual (true, uri.IsLoopback, "#4");
1084                         uri = new Uri("http://[::1]");
1085                         Assert.AreEqual (true, uri.IsLoopback, "#5");
1086                         uri = new Uri("http://[::1]:8080");
1087                         Assert.AreEqual (true, uri.IsLoopback, "#6");
1088                         uri = new Uri("http://[::0001]:8080");
1089                         Assert.AreEqual (true, uri.IsLoopback, "#7");
1090                         uri = new Uri("http://[0:0:0:0::1]:8080");
1091                         Assert.AreEqual (true, uri.IsLoopback, "#8");
1092                         uri = new Uri("http://[0:0:0:0::127.0.0.1]:8080");
1093                         Assert.AreEqual (true, uri.IsLoopback, "#9");
1094                         uri = new Uri("http://[0:0:0:0::127.11.22.33]:8080");
1095                         Assert.AreEqual (false, uri.IsLoopback, "#10");
1096                         uri = new Uri("http://[::ffff:127.11.22.33]:8080");
1097                         Assert.AreEqual (false, uri.IsLoopback, "#11");
1098                         uri = new Uri("http://[::ff00:7f11:2233]:8080");
1099                         Assert.AreEqual (false, uri.IsLoopback, "#12");
1100                         uri = new Uri("http://[1:0:0:0::1]:8080");
1101                         Assert.AreEqual (false, uri.IsLoopback, "#13");
1102                 }
1103
1104                 [Test]
1105                 public void IsLoopback_File ()
1106                 {
1107                         Uri uri = new Uri ("file:///index.html");
1108 #if NET_2_0
1109                         Assert.IsTrue (uri.IsLoopback, "file");
1110 #else
1111                         Assert.IsTrue (!uri.IsLoopback, "file");
1112 #endif
1113                 }
1114
1115                 [Test]
1116                 public void IsLoopback_Relative_Http ()
1117                 {
1118                         string relative = "http:8080/bar/Hello World.htm";
1119                         Uri uri = new Uri (new Uri ("http://www.contoso.com"), relative, false);
1120                         Assert.IsTrue (!uri.IsLoopback, "http");
1121                 }
1122
1123                 [Test]
1124                 public void IsLoopback_Relative_Unknown ()
1125                 {
1126                         string relative = "foo:8080/bar/Hello World.htm";
1127                         Uri uri = new Uri (new Uri ("http://www.contoso.com"), relative, false);
1128                         Assert.IsTrue (!uri.IsLoopback, "foo");
1129                 }
1130
1131                 [Test]
1132                 public void Equals1 ()
1133                 {
1134                         Uri uri1 = new Uri ("http://www.contoso.com/index.htm#main");
1135                         Uri uri2 = new Uri ("http://www.contoso.com/index.htm#fragment");
1136                         Assert.IsTrue (uri1.Equals (uri2), "#1");
1137                         Assert.IsTrue (!uri2.Equals ("http://www.contoso.com/index.html?x=1"), "#3");
1138                         Assert.IsTrue (!uri1.Equals ("http://www.contoso.com:8080/index.htm?x=1"), "#4");
1139                 }
1140
1141                 [Test]
1142 #if !NET_2_0
1143                 [Category("NotDotNet")]
1144 #endif
1145                 public void Equals2 ()
1146                 {
1147                         Uri uri1 = new Uri ("http://www.contoso.com/index.htm#main");
1148                         Uri uri2 = new Uri ("http://www.contoso.com/index.htm?x=1");
1149                         Assert.IsTrue (!uri1.Equals (uri2), "#2 known to fail with ms.net 1.x");
1150                 }
1151
1152                 [Test]
1153                 public void Equals3 ()
1154                 {
1155                         Uri uri1 = new Uri ("svn+ssh://atsushi@mono-cvs.ximian.com");
1156                         Uri uri2 = new Uri ("svn+ssh://anonymous@mono-cvs.ximian.com");
1157                         Assert.IsTrue (uri1.Equals (uri2));
1158                 }
1159
1160                 [Test]
1161                 public void TestEquals2 ()
1162                 {
1163                         Uri a = new Uri ("http://www.go-mono.com");
1164                         Uri b = new Uri ("http://www.go-mono.com");
1165
1166                         Assert.AreEqual (a, b, "#1");
1167
1168                         a = new Uri ("mailto:user:pwd@go-mono.com?subject=uri");
1169                         b = new Uri ("MAILTO:USER:PWD@GO-MONO.COM?SUBJECT=URI");
1170 #if NET_2_0
1171                         Assert.IsTrue (a != b, "#2");
1172                         Assert.AreEqual ("mailto:user:pwd@go-mono.com?subject=uri", a.ToString (), "#2a");
1173                         Assert.AreEqual ("mailto:USER:PWD@go-mono.com?SUBJECT=URI", b.ToString (), "#2b");
1174 #else
1175                         Assert.AreEqual (a, b, "#2");
1176 #endif
1177                         a = new Uri ("http://www.go-mono.com/ports/");
1178                         b = new Uri ("http://www.go-mono.com/PORTS/");
1179
1180                         Assert.IsTrue (!a.Equals (b), "#3");
1181                 }
1182
1183                 [Test]
1184                 public void CaseSensitivity ()
1185                 {
1186                         Uri mailto = new Uri ("MAILTO:USER:PWD@GO-MONO.COM?SUBJECT=URI");
1187                         Assert.AreEqual ("mailto", mailto.Scheme, "#1");
1188                         Assert.AreEqual ("go-mono.com", mailto.Host, "#2");
1189                         Assert.AreEqual ("mailto:USER:PWD@go-mono.com?SUBJECT=URI", mailto.ToString (), "#3");
1190
1191                         Uri http = new Uri ("HTTP://GO-MONO.COM/INDEX.HTML");
1192                         Assert.AreEqual ("http", http.Scheme, "#4");
1193                         Assert.AreEqual ("go-mono.com", http.Host, "#5");
1194                         Assert.AreEqual ("http://go-mono.com/INDEX.HTML", http.ToString (), "#6");
1195
1196                         // IPv6 Address
1197                         Uri ftp = new Uri ("FTP://[::ffFF:169.32.14.5]/");
1198                         Assert.AreEqual ("ftp", ftp.Scheme, "#7");
1199                         Assert.AreEqual ("[0000:0000:0000:0000:0000:FFFF:A920:0E05]", ftp.Host, "#8");
1200                         Assert.AreEqual ("ftp://[0000:0000:0000:0000:0000:FFFF:A920:0E05]/", ftp.ToString (), "#9");
1201                 }
1202
1203                 [Test]
1204                 public void GetHashCodeTest ()
1205                 {
1206                         Uri uri1 = new Uri ("http://www.contoso.com/index.htm#main");
1207                         Uri uri2 = new Uri ("http://www.contoso.com/index.htm#fragment");
1208                         Assert.AreEqual (uri1.GetHashCode (), uri2.GetHashCode (), "#1");
1209                         uri2 = new Uri ("http://www.contoso.com/index.htm?x=1");
1210                         Assert.IsTrue (uri1.GetHashCode () != uri2.GetHashCode (), "#2");
1211                         uri2 = new Uri ("http://www.contoso.com:80/index.htm");
1212                         Assert.AreEqual (uri1.GetHashCode (), uri2.GetHashCode (), "#3");
1213                         uri2 = new Uri ("http://www.contoso.com:8080/index.htm");
1214                         Assert.IsTrue (uri1.GetHashCode () != uri2.GetHashCode (), "#4");
1215                 }
1216
1217 #if NET_2_0
1218                 [Test]
1219                 public void RelativeEqualsTest()
1220                 {
1221                         Uri uri1 = new Uri ("foo/bar", UriKind.Relative);
1222                         Uri uri2 = new Uri ("foo/bar", UriKind.Relative);
1223                         Uri uri3 = new Uri ("bar/man", UriKind.Relative);
1224                         Uri uri4 = new Uri ("BAR/MAN", UriKind.Relative);
1225                         Assert.IsTrue (uri1 == uri2, "#1a");
1226                         Assert.IsTrue (uri1.Equals(uri2), "#1b");
1227                         Assert.IsTrue (uri1 != uri3, "#2a");
1228                         Assert.IsTrue (!uri1.Equals(uri3), "#2b");
1229                         Assert.IsTrue (uri1 == uri2, "#3a");
1230                         Assert.IsTrue (uri1.Equals(uri2), "#3b");
1231                         Assert.IsTrue (uri1 != uri3, "#4a");
1232                         Assert.IsTrue (!uri1.Equals(uri3), "#4b");
1233                         Assert.IsTrue (uri3 != uri4, "#5a");
1234                         Assert.IsTrue (!uri3.Equals(uri4), "#5b");
1235                 }
1236
1237                 [Test]
1238                 [ExpectedException(typeof(InvalidOperationException))]
1239                 public void GetLeftPart_Partial1 ()
1240                 {
1241                         Uri u = new Uri ("foo", UriKind.Relative);
1242                         u.GetLeftPart (UriPartial.Scheme);
1243                 }
1244
1245                 [ExpectedException(typeof(InvalidOperationException))]
1246                 [Test]
1247                 public void GetLeftPart_Partial2 ()
1248                 {
1249                         Uri u = new Uri ("foo", UriKind.Relative);
1250                         u.GetLeftPart (UriPartial.Authority);
1251                 }
1252
1253                 [ExpectedException(typeof(InvalidOperationException))]
1254                 [Test]
1255                 public void GetLeftPart_Partial3 ()
1256                 {
1257                         Uri u = new Uri ("foo", UriKind.Relative);
1258                         u.GetLeftPart (UriPartial.Path);
1259                 }
1260
1261                 [Test]
1262                 public void TestPartialToString ()
1263                 {
1264                         Assert.AreEqual (new Uri ("foo", UriKind.Relative).ToString (), "foo", "#1");
1265                         Assert.AreEqual (new Uri ("foo#aa", UriKind.Relative).ToString (), "foo#aa", "#2");
1266                         Assert.AreEqual (new Uri ("foo?aa", UriKind.Relative).ToString (), "foo?aa", "#3");
1267                         Assert.AreEqual (new Uri ("foo#dingus?aa", UriKind.Relative).ToString (), "foo#dingus?aa", "#4");
1268                         Assert.AreEqual (new Uri ("foo?dingus#aa", UriKind.Relative).ToString (), "foo?dingus#aa", "#4");
1269                 }
1270
1271                 [Test]
1272                 public void RelativeGetHashCodeTest()
1273                 {
1274                         Uri uri1 = new Uri ("foo/bar", UriKind.Relative);
1275                         Uri uri2 = new Uri ("foo/bar", UriKind.Relative);
1276                         Uri uri3 = new Uri ("bar/man", UriKind.Relative);
1277                         Assert.AreEqual (uri1.GetHashCode(), uri2.GetHashCode(), "#1");
1278                         Assert.IsTrue (uri1.GetHashCode() != uri3.GetHashCode(), "#2");
1279                 }
1280 #endif
1281
1282                 [Test]
1283                 public void MakeRelative ()
1284                 {
1285                         Uri uri1 = new Uri ("http://www.contoso.com/index.htm?x=2");
1286                         Uri uri2 = new Uri ("http://www.contoso.com/foo/bar/index.htm#fragment");
1287                         Uri uri3 = new Uri ("http://www.contoso.com/bar/foo/index.htm?y=1");
1288                         Uri uri4 = new Uri ("http://www.contoso.com/bar/foo2/index.htm?x=0");
1289                         Uri uri5 = new Uri ("https://www.contoso.com/bar/foo/index.htm?y=1");
1290                         Uri uri6 = new Uri ("http://www.contoso2.com/bar/foo/index.htm?x=0");
1291                         Uri uri7 = new Uri ("http://www.contoso2.com/bar/foo/foobar.htm?z=0&y=5");
1292                         Uri uri8 = new Uri ("http://www.xxx.com/bar/foo/foobar.htm?z=0&y=5" + (char) 0xa9);
1293
1294                         Assert.AreEqual ("foo/bar/index.htm", uri1.MakeRelative (uri2), "#1");
1295                         Assert.AreEqual ("../../index.htm", uri2.MakeRelative (uri1), "#2");
1296
1297                         Assert.AreEqual ("../../bar/foo/index.htm", uri2.MakeRelative (uri3), "#3");
1298                         Assert.AreEqual ("../../foo/bar/index.htm", uri3.MakeRelative (uri2), "#4");
1299
1300                         Assert.AreEqual ("../foo2/index.htm", uri3.MakeRelative (uri4), "#5");
1301                         Assert.AreEqual ("../foo/index.htm", uri4.MakeRelative (uri3), "#6");
1302
1303                         Assert.AreEqual ("https://www.contoso.com/bar/foo/index.htm?y=1", uri4.MakeRelative (uri5), "#7");
1304
1305                         Assert.AreEqual ("http://www.contoso2.com/bar/foo/index.htm?x=0", uri4.MakeRelative (uri6), "#8");
1306
1307                         Assert.AreEqual ("", uri6.MakeRelative (uri6), "#9");
1308                         Assert.AreEqual ("foobar.htm", uri6.MakeRelative (uri7), "#10");
1309
1310                         Uri uri10 = new Uri ("mailto:xxx@xxx.com");
1311                         Uri uri11 = new Uri ("mailto:xxx@xxx.com?subject=hola");
1312                         Assert.AreEqual ("", uri10.MakeRelative (uri11), "#11");
1313
1314                         Uri uri12 = new Uri ("mailto:xxx@mail.xxx.com?subject=hola");
1315                         Assert.AreEqual ("mailto:xxx@mail.xxx.com?subject=hola", uri10.MakeRelative (uri12), "#12");
1316
1317                         Uri uri13 = new Uri ("mailto:xxx@xxx.com/foo/bar");
1318                         Assert.AreEqual ("/foo/bar", uri10.MakeRelative (uri13), "#13");
1319
1320                         Assert.AreEqual ("http://www.xxx.com/bar/foo/foobar.htm?z=0&y=5" + (char) 0xa9, uri1.MakeRelative (uri8), "#14");
1321                 }
1322
1323                 [Test]
1324                 public void RelativeUri ()
1325                 {
1326                         Uri u = new Uri("http://localhost/../../../a");
1327 #if NET_2_0
1328                         Assert.AreEqual ("http://localhost/a", u.ToString ());
1329 #else
1330                         Assert.AreEqual ("http://localhost/../../../a", u.ToString ());
1331 #endif
1332
1333                         u = new Uri ("http://localhost/../c/b/../a");
1334 #if NET_2_0
1335                         Assert.AreEqual ("http://localhost/c/a", u.ToString ());
1336 #else
1337                         Assert.AreEqual ("http://localhost/../c/a", u.ToString ());
1338 #endif
1339                 }
1340
1341                 [Test]
1342                 public void RelativeUri2 ()
1343                 {
1344                         Assert.AreEqual ("hoge:ext", new Uri (new Uri ("hoge:foo:bar:baz"), "hoge:ext").ToString (), "#1");
1345                         if (isWin32) {
1346                                 Assert.AreEqual ("file:///d:/myhost/ext", new Uri (new Uri ("file:///c:/localhost/bar"), "file:///d:/myhost/ext").ToString (), "#2-w");
1347                                 Assert.AreEqual ("file:///c:/localhost/myhost/ext", new Uri (new Uri ("file:///c:/localhost/bar"), "file:myhost/ext").ToString (), "#3-w");
1348                                 Assert.AreEqual ("uuid:ext", new Uri (new Uri ("file:///c:/localhost/bar"), "uuid:ext").ToString (), "#4-w");
1349                                 Assert.AreEqual ("file:///c:/localhost/ext", new Uri (new Uri ("file:///c:/localhost/bar"), "file:./ext").ToString (), "#5-w");
1350                         } else {
1351                                 Assert.AreEqual ("file:///d/myhost/ext", new Uri (new Uri ("file:///c/localhost/bar"), "file:///d/myhost/ext").ToString (), "#2-u");
1352                                 Assert.AreEqual ("file:///c/localhost/myhost/ext", new Uri (new Uri ("file:///c/localhost/bar"), "file:myhost/ext").ToString (), "#3-u");
1353                                 Assert.AreEqual ("uuid:ext", new Uri (new Uri ("file:///c/localhost/bar"), "uuid:ext").ToString (), "#4-u");
1354                                 Assert.AreEqual ("file:///c/localhost/ext", new Uri (new Uri ("file:///c/localhost/bar"), "file:./ext").ToString (), "#5-u");
1355                         }
1356                         Assert.AreEqual ("http://localhost/ext", new Uri (new Uri ("http://localhost/bar"), "http:./ext").ToString (), "#6");
1357                 }
1358
1359                 [Test]
1360                 public void ToStringTest()
1361                 {
1362                         Uri uri = new Uri ("dummy://xxx");
1363                         Assert.AreEqual ("dummy://xxx/", uri.ToString (), "#1");
1364                 }
1365
1366                 [Test]
1367                 public void CheckSchemeName ()
1368                 {
1369                         Assert.AreEqual (false, Uri.CheckSchemeName (null), "#01");
1370                         Assert.AreEqual (false, Uri.CheckSchemeName (""), "#02");
1371                         Assert.AreEqual (true, Uri.CheckSchemeName ("http"), "#03");
1372                         Assert.AreEqual (true, Uri.CheckSchemeName ("http-"), "#04");
1373                         Assert.AreEqual (false, Uri.CheckSchemeName ("6http-"), "#05");
1374                         Assert.AreEqual (true, Uri.CheckSchemeName ("http6-"), "#06");
1375                         Assert.AreEqual (false, Uri.CheckSchemeName ("http6,"), "#07");
1376                         Assert.AreEqual (true, Uri.CheckSchemeName ("http6."), "#08");
1377                         Assert.AreEqual (false, Uri.CheckSchemeName ("+http"), "#09");
1378                         Assert.AreEqual (true, Uri.CheckSchemeName ("htt+p6"), "#10");
1379                         // 0x00E1 -> &atilde;
1380 #if NET_2_0
1381                         Assert.IsTrue (!Uri.CheckSchemeName ("htt\u00E1+p6"), "#11");
1382 #else
1383                         Assert.IsTrue (Uri.CheckSchemeName ("htt\u00E1+p6"), "#11");
1384 #endif
1385                 }
1386
1387                 [Test]
1388                 public void CheckSchemeName_FirstChar ()
1389                 {
1390                         for (int i = 0; i < 256; i++) {
1391                                 string s = String.Format ("#{0}", i);
1392                                 char c = (char) i;
1393                                 bool b = Uri.CheckSchemeName (c.ToString ());
1394 #if NET_2_0
1395                                 bool valid = (((i >= 0x41) && (i <= 0x5A)) || ((i >= 0x61) && (i <= 0x7A)));
1396                                 Assert.AreEqual (valid, b, s);
1397 #else
1398                                 Assert.AreEqual (Char.IsLetter (c), b, s);
1399 #endif
1400                         }
1401                 }
1402
1403                 [Test]
1404                 public void CheckSchemeName_AnyOtherChar ()
1405                 {
1406                         for (int i = 0; i < 256; i++) {
1407                                 string s = String.Format ("#{0}", i);
1408                                 char c = (char) i;
1409                                 string scheme = String.Format ("a+b-c.d{0}", c);
1410                                 bool b = Uri.CheckSchemeName (scheme);
1411                                 bool common = Char.IsDigit (c) || (c == '+') || (c == '-') || (c == '.');
1412 #if NET_2_0
1413                                 bool valid = (common || ((i >= 0x41) && (i <= 0x5A)) || ((i >= 0x61) && (i <= 0x7A)));
1414                                 Assert.AreEqual (valid, b, s);
1415 #else
1416                                 Assert.AreEqual ((Char.IsLetter (c) || common), b, s);
1417 #endif
1418                         }
1419                 }
1420
1421                 [Test]
1422                 [ExpectedException (typeof (UriFormatException))]
1423                 public void NoHostname ()
1424                 {
1425                         Uri uri = new Uri ("http://");
1426                 }
1427
1428                 [Test]
1429 #if !NET_2_0
1430                 // MS.NET 1.x throws an IndexOutOfRangeException
1431                 [Category("NotDotNet")]
1432 #endif
1433                 public void NoHostname2 ()
1434                 {
1435                         // bug 75144
1436                         Uri uri = new Uri ("file://");
1437                         Assert.AreEqual (true, uri.IsFile, "#1");
1438                         Assert.AreEqual (false, uri.IsUnc, "#2");
1439                         Assert.AreEqual ("file", uri.Scheme, "#3");
1440                         Assert.AreEqual ("/", uri.LocalPath, "#4");
1441                         Assert.AreEqual (string.Empty, uri.Query, "#5");
1442                         Assert.AreEqual ("/", uri.AbsolutePath, "#6");
1443                         Assert.AreEqual ("file:///", uri.AbsoluteUri, "#7");
1444                         Assert.AreEqual (string.Empty, uri.Authority, "#8");
1445                         Assert.AreEqual (string.Empty, uri.Host, "#9");
1446                         Assert.AreEqual (UriHostNameType.Basic, uri.HostNameType, "#10");
1447                         Assert.AreEqual (string.Empty, uri.Fragment, "#11");
1448                         Assert.AreEqual (true, uri.IsDefaultPort, "#12");
1449 #if NET_2_0
1450                         Assert.IsTrue (uri.IsLoopback, "#13");
1451 #else
1452                         Assert.IsTrue (!uri.IsLoopback, "#13");
1453 #endif
1454                         Assert.AreEqual ("/", uri.PathAndQuery, "#14");
1455                         Assert.AreEqual (false, uri.UserEscaped, "#15");
1456                         Assert.AreEqual (string.Empty, uri.UserInfo, "#16");
1457                         Assert.AreEqual ("file://", uri.GetLeftPart (UriPartial.Authority), "#17");
1458                         Assert.AreEqual ("file:///", uri.GetLeftPart (UriPartial.Path), "#18");
1459                         Assert.AreEqual ("file://", uri.GetLeftPart (UriPartial.Scheme), "#19");
1460                 }
1461
1462                 [Test]
1463                 public void Segments1 ()
1464                 {
1465                         Uri uri = new Uri ("http://localhost/");
1466                         string [] segments = uri.Segments;
1467                         Assert.AreEqual (1, segments.Length, "#01");
1468                         Assert.AreEqual ("/", segments [0], "#02");
1469                 }
1470
1471                 [Test]
1472                 public void Segments2 ()
1473                 {
1474                         Uri uri = new Uri ("http://localhost/dir/dummypage.html");
1475                         string [] segments = uri.Segments;
1476                         Assert.AreEqual (3, segments.Length, "#01");
1477                         Assert.AreEqual ("/", segments [0], "#02");
1478                         Assert.AreEqual ("dir/", segments [1], "#03");
1479                         Assert.AreEqual ("dummypage.html", segments [2], "#04");
1480                 }
1481
1482                 [Test]
1483                 public void CachingSegments ()
1484                 {
1485                         Uri uri = new Uri ("http://localhost/dir/dummypage.html");
1486                         uri.Segments [0] = uri.Segments [1] = uri.Segments [2] = "*";
1487                         string [] segments = uri.Segments;
1488                         Assert.AreEqual (3, segments.Length, "#01");
1489                         Assert.AreEqual ("/", segments [0], "#02");
1490                         Assert.AreEqual ("dir/", segments [1], "#03");
1491                         Assert.AreEqual ("dummypage.html", segments [2], "#04");
1492                 }
1493
1494                 [Test]
1495                 public void Segments3 ()
1496                 {
1497                         Uri uri = new Uri ("http://localhost/dir/dummypage/");
1498                         string [] segments = uri.Segments;
1499                         Assert.AreEqual (3, segments.Length, "#01");
1500                         Assert.AreEqual ("/", segments [0], "#02");
1501                         Assert.AreEqual ("dir/", segments [1], "#03");
1502                         Assert.AreEqual ("dummypage/", segments [2], "#04");
1503                 }
1504
1505                 [Test]
1506                 public void Segments4 ()
1507                 {
1508                         Uri uri = new Uri ("file:///c:/hello");
1509
1510                         Assert.AreEqual ("c:/hello", uri.AbsolutePath, "AbsolutePath");
1511                         Assert.AreEqual ("c:\\hello", uri.LocalPath, "LocalPath");
1512
1513                         string [] segments = uri.Segments;
1514                         Assert.AreEqual (3, segments.Length, "#01");
1515                         Assert.AreEqual ("/", segments [0], "#02");
1516                         Assert.AreEqual ("c:/", segments[1], "#03");
1517                         Assert.AreEqual ("hello", segments [2], "#04");
1518                 }
1519
1520                 [Test]
1521                 public void Segments5 ()
1522                 {
1523                         Uri uri = new Uri ("http://www.xxx.com/bar/foo/foobar.htm?z=0&y=5" + (char) 0xa9);
1524                         string [] segments = uri.Segments;
1525                         Assert.AreEqual (4, segments.Length, "#01");
1526                         Assert.AreEqual ("/", segments [0], "#02");
1527                         Assert.AreEqual ("bar/", segments [1], "#03");
1528                         Assert.AreEqual ("foo/", segments [2], "#04");
1529                         Assert.AreEqual ("foobar.htm", segments [3], "#05");
1530                 }
1531
1532                 [Test]
1533                 [ExpectedException (typeof (UriFormatException))]
1534                 public void UriStartingWithColon()
1535                 {
1536                         new Uri("://");
1537                 }
1538
1539                 [Test]
1540                 [ExpectedException (typeof (UriFormatException))]
1541                 public void EmptyScheme ()
1542                 {
1543                         new Uri ("hey");
1544                 }
1545
1546 #if NET_2_0
1547                 // on .NET 2.0 a port number is limited to UInt16.MaxValue
1548                 [ExpectedException (typeof (UriFormatException))]
1549 #endif
1550                 [Test]
1551                 public void InvalidPort1 ()
1552                 {
1553                         Uri uri = new Uri ("http://www.contoso.com:65536/foo/bar/");
1554                         Assert.AreEqual (65536, uri.Port);
1555                 }
1556
1557 #if NET_2_0
1558                 [ExpectedException (typeof (UriFormatException))]
1559 #endif
1560                 [Test]
1561                 public void InvalidPort2 ()
1562                 {
1563                         // UInt32.MaxValue gives port == -1 !!!
1564                         Uri uri = new Uri ("http://www.contoso.com:4294967295/foo/bar/");
1565                         Assert.AreEqual (-1, uri.Port);
1566                 }
1567
1568 #if NET_2_0
1569                 [ExpectedException (typeof (UriFormatException))]
1570 #endif
1571                 [Test]
1572                 public void InvalidPort3 ()
1573                 {
1574                         // ((uint) Int32.MaxValue + (uint) 1) gives port == -2147483648 !!!
1575                         Uri uri = new Uri ("http://www.contoso.com:2147483648/foo/bar/");
1576                         Assert.AreEqual (-2147483648, uri.Port);
1577                 }
1578
1579 #if NET_2_0
1580                 [Test]
1581                 public void PortMax ()
1582                 {
1583                         // on .NET 2.0 a port number is limited to UInt16.MaxValue
1584                         Uri uri = new Uri ("http://www.contoso.com:65535/foo/bar/");
1585                         Assert.AreEqual (65535, uri.Port);
1586                 }
1587 #endif
1588
1589                 class UriEx2 : Uri
1590                 {
1591                         public UriEx2 (string s) : base (s)
1592                         {
1593                         }
1594
1595                         protected override void Parse ()
1596                         {
1597                         }
1598                 }
1599
1600 #if NET_2_0
1601                 // Parse method is no longer used on .NET 2.0
1602                 [ExpectedException (typeof (UriFormatException))]
1603 #endif
1604                 [Test]
1605                 public void ParseOverride ()
1606                 {
1607                         // If this does not override base's Parse(), it will
1608                         // fail since this argument is not Absolute URI.
1609                         UriEx2 ex = new UriEx2 ("readme.txt");
1610                 }
1611
1612                 [Test]
1613                 public void UnixLocalPath ()
1614                 {
1615                         // This works--the location is not part of the absolute path
1616                         string path = "file://localhost/tmp/foo/bar";
1617                         Uri fileUri = new Uri( path );
1618                         Assert.AreEqual ("/tmp/foo/bar", fileUri.AbsolutePath, path);
1619
1620                         // Empty path == localhost, in theory
1621                         path = "file:///c:/tmp/foo/bar";
1622                         fileUri = new Uri( path );
1623                         Assert.AreEqual ("c:/tmp/foo/bar", fileUri.AbsolutePath, path);
1624                 }
1625
1626                 [Test]
1627                 public void WindowsLocalPath ()
1628                 {
1629                         new Uri (@"file:///J:\Wrldwide\MSFin\Flash\FLASH.xls");
1630                 }
1631
1632 #if NET_2_0
1633                 [Test]
1634                 public void TestEscapeDataString ()
1635                 {
1636                         StringBuilder sb = new StringBuilder ();
1637
1638                         for (int i = 0; i < 128; i++)
1639                                 sb.Append ((char) i);
1640
1641                         Assert.AreEqual ("%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%20!%22%23%24%25%26'()*%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~%7F",
1642                                       Uri.EscapeDataString (sb.ToString ()));
1643
1644                         Assert.AreEqual ("%C3%A1", Uri.EscapeDataString ("á"));
1645                 }
1646                 [Test]
1647                 public void TestEscapeUriString ()
1648                 {
1649                         StringBuilder sb = new StringBuilder ();
1650                         for (int i = 0; i < 128; i++)
1651                                 sb.Append ((char) i);
1652
1653                         Assert.AreEqual ("%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%20!%22#$%25&'()*+,-./0123456789:;%3C=%3E?@ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~%7F",
1654                                 Uri.EscapeUriString (sb.ToString ()));
1655                         Assert.AreEqual ("%C3%A1", Uri.EscapeDataString ("á"));
1656                 }
1657 #endif
1658
1659                 //bnc #363320
1660                 [Test]
1661                 public void TestUTF8Strings ()
1662                 {
1663                         string [] tests = {
1664                                 "file:///tmp/x (%232).jpg",
1665                                 "file:///tmp/ü (%232).jpg" };
1666
1667                         foreach (string test in tests) {
1668                                 Uri uri = new Uri (test);
1669                                 Assert.IsFalse (uri.IsWellFormedOriginalString (), "IsWellFormedOriginalString/" + test);
1670                                 Assert.AreEqual (test, uri.OriginalString, "OriginalString/" + test);
1671                                 Assert.AreEqual (test, uri.ToString (), "ToString/" + test);
1672                         }
1673                 }
1674
1675                 // This test doesn't work on Linux, and arguably shouldn't work.
1676                 // new Uri("file:///tmp/foo/bar").AbsolutePath returns "/tmp/foo/bar"
1677                 // on Linux, as anyone sane would expect.  It *doesn't* under .NET 1.1
1678                 // Apparently "tmp" is supposed to be a hostname (!)...
1679                 // Since "correct" behavior would confuse all Linux developers, and having
1680                 // an expected failure is evil, we'll just ignore this for now...
1681                 //
1682                 // Furthermore, Microsoft fixed this so it behaves sensibly in .NET 2.0.
1683                 //
1684                 // You are surrounded by conditional-compilation code, all alike.
1685                 // You are likely to be eaten by a Grue...
1686                 [Test]
1687 #if !NET_2_0
1688                 [Category ("NotDotNet")]
1689 #endif
1690                 public void UnixLocalPath_WTF ()
1691                 {
1692                         // Empty path == localhost, in theory
1693                         string path = "file:///tmp/foo/bar";
1694                         Uri fileUri = new Uri( path );
1695 //#if NET_2_0
1696                         Assert.AreEqual ("/tmp/foo/bar", fileUri.AbsolutePath, path);
1697 //#else
1698 //                      Assert.AreEqual ("/foo/bar", fileUri.AbsolutePath, path);
1699 //#endif
1700
1701                         // bug #76643
1702                         string path2 = "file:///foo%25bar";
1703                         fileUri = new Uri (path2);
1704                         Assert.AreEqual ("file:///foo%25bar", fileUri.ToString (), path2);
1705                 }
1706
1707                 public static void Print (Uri uri)
1708                 {
1709                         Console.WriteLine ("ToString: " + uri.ToString ());
1710
1711                         Console.WriteLine ("AbsolutePath: " + uri.AbsolutePath);
1712                         Console.WriteLine ("AbsoluteUri: " + uri.AbsoluteUri);
1713                         Console.WriteLine ("Authority: " + uri.Authority);
1714                         Console.WriteLine ("Fragment: " + uri.Fragment);
1715                         Console.WriteLine ("Host: " + uri.Host);
1716                         Console.WriteLine ("HostNameType: " + uri.HostNameType);
1717                         Console.WriteLine ("IsDefaultPort: " + uri.IsDefaultPort);
1718                         Console.WriteLine ("IsFile: " + uri.IsFile);
1719                         Console.WriteLine ("IsLoopback: " + uri.IsLoopback);
1720                         Console.WriteLine ("IsUnc: " + uri.IsUnc);
1721                         Console.WriteLine ("LocalPath: " + uri.LocalPath);
1722                         Console.WriteLine ("PathAndQuery        : " + uri.PathAndQuery);
1723                         Console.WriteLine ("Port: " + uri.Port);
1724                         Console.WriteLine ("Query: " + uri.Query);
1725                         Console.WriteLine ("Scheme: " + uri.Scheme);
1726                         Console.WriteLine ("UserEscaped: " + uri.UserEscaped);
1727                         Console.WriteLine ("UserInfo: " + uri.UserInfo);
1728
1729                         Console.WriteLine ("Segments:");
1730                         string [] segments = uri.Segments;
1731                         if (segments == null)
1732                                 Console.WriteLine ("\tNo Segments");
1733                         else
1734                                 for (int i = 0; i < segments.Length; i++)
1735                                         Console.WriteLine ("\t" + segments[i]);
1736                         Console.WriteLine ("");
1737                 }
1738
1739                 [Test]
1740                 public void FtpRootPath ()
1741                 {
1742                         Uri u = new Uri ("ftp://a.b/%2fabc/def");
1743                         string p = u.PathAndQuery;
1744                         Assert.AreEqual ("/%2fabc/def", p);
1745                         p = Uri.UnescapeDataString (p).Substring (1);
1746                         Assert.AreEqual ("/abc/def", p);
1747                         u = new Uri (new Uri ("ftp://a.b/c/d/e/f"), p);
1748                         Assert.AreEqual ("/abc/def", u.PathAndQuery);
1749                 }
1750
1751 //BNC#533572
1752 #if NET_2_0
1753                 [Test]
1754                 public void LocalPath_FileNameWithAtSign1 ()
1755                 {
1756                         string path = "/some/path/file_with_an_@_sign.mp3";
1757                         string fullpath = "http://thehost" + path;
1758                         Uri fileUri = new Uri (fullpath);
1759
1760                         Assert.AreEqual (fileUri.UserInfo, String.Empty, "LocalPath_FileNameWithAtSign UserInfo");
1761                         Assert.AreEqual (fileUri.Host, "thehost", "LocalPath_FileNameWithAtSign Host");
1762                         Assert.IsFalse (fileUri.IsFile, "LocalPath_FileNameWithAtSign IsFile");
1763                         Assert.IsTrue (fileUri.IsAbsoluteUri, "LocalPath_FileNameWithAtSign IsAbsUri");
1764                         Assert.IsFalse (fileUri.IsUnc, "LocalPath_FileNameWithAtSign IsUnc");
1765
1766                         Assert.AreEqual (fullpath, fileUri.OriginalString, "LocalPath_FileNameWithAtSign OriginalString");
1767                         Assert.AreEqual (path, new DerivedUri (fullpath).TestUnescape (path), "LocalPath_FileNameWithAtSign ProtectedUnescape");
1768                         Assert.AreEqual (path, fileUri.AbsolutePath, "LocalPath_FileNameWithAtSign AbsPath");
1769                         Assert.AreEqual (path, fileUri.LocalPath, "LocalPath_FileNameWithAtSign LocalPath");
1770                 }
1771
1772                 [Test]
1773                 public void LocalPath_FileNameWithAtSign2 ()
1774                 {
1775                         string path = "/some/path/file_with_an_@_sign.mp3";
1776                         string fullpath = "http://user:password@thehost" + path;
1777                         Uri fileUri = new Uri (fullpath);
1778
1779                         Assert.AreEqual (fileUri.UserInfo, "user:password", "LocalPath_FileNameWithAtSign UserInfo");
1780                         Assert.AreEqual (fileUri.Host, "thehost", "LocalPath_FileNameWithAtSign Host");
1781                         Assert.IsFalse (fileUri.IsFile, "LocalPath_FileNameWithAtSign IsFile");
1782                         Assert.IsTrue (fileUri.IsAbsoluteUri, "LocalPath_FileNameWithAtSign IsAbsUri");
1783                         Assert.IsFalse (fileUri.IsUnc, "LocalPath_FileNameWithAtSign IsUnc");
1784
1785                         Assert.AreEqual (fullpath, fileUri.OriginalString, "LocalPath_FileNameWithAtSign OriginalString");
1786                         Assert.AreEqual (path, new DerivedUri (fullpath).TestUnescape (path), "LocalPath_FileNameWithAtSign ProtectedUnescape");
1787                         Assert.AreEqual (path, fileUri.AbsolutePath, "LocalPath_FileNameWithAtSign AbsPath");
1788                         Assert.AreEqual (path, fileUri.LocalPath, "LocalPath_FileNameWithAtSign LocalPath");
1789                 }
1790
1791                 [Test]
1792                 public void LocalPath_FileNameWithAtSign3 ()
1793                 {
1794                         string path = "/some/path/file_with_an_@_sign.mp3";
1795                         string fullpath = "file://" + path;
1796                         Uri fileUri = new Uri (fullpath);
1797
1798                         Assert.AreEqual (fileUri.UserInfo, String.Empty, "LocalPath_FileNameWithAtSign UserInfo");
1799                         Assert.AreEqual (fileUri.Host, String.Empty, "LocalPath_FileNameWithAtSign Host");
1800                         Assert.IsTrue (fileUri.IsFile, "LocalPath_FileNameWithAtSign IsFile");
1801                         Assert.IsTrue (fileUri.IsAbsoluteUri, "LocalPath_FileNameWithAtSign IsAbsUri");
1802                         Assert.IsFalse (fileUri.IsUnc, "LocalPath_FileNameWithAtSign IsUnc");
1803
1804                         Assert.AreEqual (fullpath, fileUri.OriginalString, "LocalPath_FileNameWithAtSign OriginalString");
1805                         Assert.AreEqual (path, new DerivedUri (fullpath).TestUnescape (path), "LocalPath_FileNameWithAtSign ProtectedUnescape");
1806                         Assert.AreEqual (path, fileUri.AbsolutePath, "LocalPath_FileNameWithAtSign AbsPath");
1807                         Assert.AreEqual (path, fileUri.LocalPath, "LocalPath_FileNameWithAtSign LocalPath");
1808                 }
1809
1810                 [Test]
1811                 public void LocalPath_FileNameWithAtSign4 ()
1812                 {
1813                         string path = "/some/path/file_with_an_@_sign.mp3";
1814                         string fullpath = "file://localhost" + path;
1815                         Uri fileUri = new Uri (fullpath);
1816
1817                         Assert.AreEqual (fileUri.UserInfo, String.Empty, "LocalPath_FileNameWithAtSign UserInfo");
1818                         Assert.AreEqual (fileUri.Host, "localhost", "LocalPath_FileNameWithAtSign Host");
1819                         Assert.IsTrue (fileUri.IsFile, "LocalPath_FileNameWithAtSign IsFile");
1820                         Assert.IsTrue (fileUri.IsAbsoluteUri, "LocalPath_FileNameWithAtSign IsAbsUri");
1821                         Assert.IsTrue (fileUri.IsUnc, "LocalPath_FileNameWithAtSign IsUnc");
1822
1823                         Assert.AreEqual (fullpath, fileUri.OriginalString, "LocalPath_FileNameWithAtSign OriginalString");
1824                         Assert.AreEqual (path, new DerivedUri (fullpath).TestUnescape (path), "LocalPath_FileNameWithAtSign ProtectedUnescape");
1825                         Assert.AreEqual (path, fileUri.AbsolutePath, "LocalPath_FileNameWithAtSign AbsPath");
1826                         //this test is marked as NotWorking below:
1827                         //Assert.AreEqual ("\\\\localhost" + path.Replace ("/", "\\"), fileUri.LocalPath, "LocalPath_FileNameWithAtSign LocalPath");
1828                 }
1829
1830                 [Test]
1831                 [Category ("NotWorking")]
1832                 public void LocalPath_FileNameWithAtSign5 ()
1833                 {
1834                         string path = "/some/path/file_with_an_@_sign.mp3";
1835                         string fullpath = "file://localhost" + path;
1836                         Uri fileUri = new Uri (fullpath);
1837
1838                         Assert.AreEqual ("\\\\localhost" + path.Replace ("/", "\\"), fileUri.LocalPath, "LocalPath_FileNameWithAtSign LocalPath");
1839                 }
1840
1841                 [Test]
1842                 [ExpectedException (typeof (UriFormatException))]
1843                 public void LocalPath_FileNameWithAtSign6 ()
1844                 {
1845                         string path = "/some/path/file_with_an_@_sign.mp3";
1846                         string fullpath = "file://user:password@localhost" + path;
1847                         Uri fileUri = new Uri (fullpath);
1848                 }
1849
1850                 [Test]
1851                 [Category ("NotDotNet")]
1852                 public void UnixAbsoluteFilePath_WithSpecialChars1 ()
1853                 {
1854                         Uri unixuri = new Uri ("/home/user/a@b");
1855                         Assert.AreEqual ("file", unixuri.Scheme, "UnixAbsoluteFilePath_WithSpecialChars #1");
1856                 }
1857
1858                 [Test]
1859                 [Category ("NotDotNet")]
1860                 public void UnixAbsoluteFilePath_WithSpecialChars2 ()
1861                 {
1862                         Uri unixuri = new Uri ("/home/user/a:b");
1863                         Assert.AreEqual ("file", unixuri.Scheme, "UnixAbsoluteFilePath_WithSpecialChars #2");
1864                 }
1865
1866                 [Test]
1867                 public void RelativeUriWithColons ()
1868                 {
1869                         string s = @"Transform?args=[{""__type"":""Record:#Nostr"",""Code"":""%22test%22SomeGloss"",""ID"":""1"",""Table"":""Glossary""},{""__type"":""Record:#Nostr"",""Code"":""%22test%22All"",""ID"":""2"",""Table"":""GlossView""}, {""__type"":""Record:#Nostr"",""Code"":""%22test%22Q"",""ID"":""3"",""Table"":""Glossary""}]"; // with related to bug #573795
1870                         new Uri (s, UriKind.Relative);
1871                         new Uri (":", UriKind.Relative);
1872                         new Uri ("1:", UriKind.Relative);
1873                 }
1874
1875                 [Test]
1876                 public void ConsecutiveSlashes ()
1877                 {
1878                         Uri uri = new Uri ("http://media.libsyn.com/bounce/http://cdn4.libsyn.com/nerdist/somestuff.txt");
1879                         Assert.AreEqual ("http://media.libsyn.com/bounce/http://cdn4.libsyn.com/nerdist/somestuff.txt", uri.ToString ());
1880                 }
1881
1882                 public class DerivedUri : Uri {
1883                         public DerivedUri (string uriString)
1884                                 : base (uriString)
1885                         {
1886                         }
1887
1888                         internal string TestUnescape (string path)
1889                         {
1890                                 return base.Unescape (path);
1891                         }
1892                 }
1893 #endif
1894         }
1895 }