2 // UriTest.cs - NUnit Test Cases for System.Uri
5 // Lawrence Pit (loz@cable.a2000.nl)
6 // Martin Willemoes Hansen (mwh@sysrq.dk)
7 // Ben Maurer (bmaurer@users.sourceforge.net)
9 // (C) 2003 Martin Willemoes Hansen
10 // (C) 2003 Ben Maurer
13 using NUnit.Framework;
18 namespace MonoTests.System
21 public class UriTest : Assertion
23 protected bool isWin32 = false;
26 public void GetReady ()
28 isWin32 = (Path.DirectorySeparatorChar == '\\');
32 public void Constructors ()
37 uri = new Uri ("http://www.ximian.com/foo" + ((char) 0xa9) + "/bar/index.cgi?a=1&b=" + ((char) 0xa9) + "left#fragm?ent2");
40 uri = new Uri ("http://www.ximian.com/foo/xxx\"()-._;<=>@{|}~-,.`_^]\\[xx/" + ((char) 0xa9) + "/bar/index.cgi#fra+\">=@[gg]~gment2");
43 uri = new Uri("http://11.22.33.588:9090");
46 uri = new Uri("http://[11:22:33::88]:9090");
49 uri = new Uri("http://[::127.11.22.33]:8080");
52 uri = new Uri("http://[abcde::127.11.22.33]:8080");
57 uri = new Uri ("http://www.contoso.com:1234/foo/bar/");
60 uri = new Uri ("http://www.contoso.com:1234/foo/bar");
63 uri = new Uri ("http://www.contoso.com:1234/");
66 uri = new Uri ("http://www.contoso.com:1234");
70 uri = new Uri(" \r \n http://test.com\r\n \r\r ");
71 AssertEquals ("#k0", "http://test.com/", uri.ToString());
73 uri = new Uri ("http://contoso.com?subject=uri");
74 AssertEquals ("#k1", "/", uri.AbsolutePath);
75 AssertEquals ("#k2", "http://contoso.com/?subject=uri", uri.AbsoluteUri);
76 AssertEquals ("#k3", "contoso.com", uri.Authority);
77 AssertEquals ("#k4", "", uri.Fragment);
78 AssertEquals ("#k5", "contoso.com", uri.Host);
79 AssertEquals ("#k6", UriHostNameType.Dns, uri.HostNameType);
80 AssertEquals ("#k7", true, uri.IsDefaultPort);
81 AssertEquals ("#k8", false, uri.IsFile);
82 AssertEquals ("#k9", false, uri.IsLoopback);
83 AssertEquals ("#k10", false, uri.IsUnc);
84 AssertEquals ("#k11", "/", uri.LocalPath);
85 AssertEquals ("#k12", "/?subject=uri", uri.PathAndQuery);
86 AssertEquals ("#k13", 80, uri.Port);
87 AssertEquals ("#k14", "?subject=uri", uri.Query);
88 AssertEquals ("#k15", "http", uri.Scheme);
89 AssertEquals ("#k16", false, uri.UserEscaped);
90 AssertEquals ("#k17", "", uri.UserInfo);
92 uri = new Uri ("mailto:user:pwd@contoso.com?subject=uri");
93 AssertEquals ("#m1", "", uri.AbsolutePath);
94 AssertEquals ("#m2", "mailto:user:pwd@contoso.com?subject=uri", uri.AbsoluteUri);
95 AssertEquals ("#m3", "contoso.com", uri.Authority);
96 AssertEquals ("#m4", "", uri.Fragment);
97 AssertEquals ("#m5", "contoso.com", uri.Host);
98 AssertEquals ("#m6", UriHostNameType.Dns, uri.HostNameType);
99 AssertEquals ("#m7", true, uri.IsDefaultPort);
100 AssertEquals ("#m8", false, uri.IsFile);
101 AssertEquals ("#m9", false, uri.IsLoopback);
102 AssertEquals ("#m10", false, uri.IsUnc);
103 AssertEquals ("#m11", "", uri.LocalPath);
104 AssertEquals ("#m12", "?subject=uri", uri.PathAndQuery);
105 AssertEquals ("#m13", 25, uri.Port);
106 AssertEquals ("#m14", "?subject=uri", uri.Query);
107 AssertEquals ("#m15", "mailto", uri.Scheme);
108 AssertEquals ("#m16", false, uri.UserEscaped);
109 AssertEquals ("#m17", "user:pwd", uri.UserInfo);
111 uri = new Uri("myscheme://127.0.0.1:5");
112 AssertEquals("#c1", "myscheme://127.0.0.1:5/", uri.ToString());
114 uri = new Uri (@"\\myserver\mydir\mysubdir\myfile.ext");
115 AssertEquals ("#n1", "/mydir/mysubdir/myfile.ext", uri.AbsolutePath);
116 AssertEquals ("#n2", "file://myserver/mydir/mysubdir/myfile.ext", uri.AbsoluteUri);
117 AssertEquals ("#n3", "myserver", uri.Authority);
118 AssertEquals ("#n4", "", uri.Fragment);
119 AssertEquals ("#n5", "myserver", uri.Host);
120 AssertEquals ("#n6", UriHostNameType.Dns, uri.HostNameType);
121 AssertEquals ("#n7", true, uri.IsDefaultPort);
122 AssertEquals ("#n8", true, uri.IsFile);
123 AssertEquals ("#n9", false, uri.IsLoopback);
124 AssertEquals ("#n10", true, uri.IsUnc);
127 AssertEquals ("#n11", @"\\myserver\mydir\mysubdir\myfile.ext", uri.LocalPath);
129 // myserver never could be the part of Unix path.
130 AssertEquals ("#n11", "/mydir/mysubdir/myfile.ext", uri.LocalPath);
132 AssertEquals ("#n12", "/mydir/mysubdir/myfile.ext", uri.PathAndQuery);
133 AssertEquals ("#n13", -1, uri.Port);
134 AssertEquals ("#n14", "", uri.Query);
135 AssertEquals ("#n15", "file", uri.Scheme);
136 AssertEquals ("#n16", false, uri.UserEscaped);
137 AssertEquals ("#n17", "", uri.UserInfo);
139 uri = new Uri (new Uri("http://www.contoso.com"), "Hello World.htm", true);
140 AssertEquals ("#rel1a", "http://www.contoso.com/Hello World.htm", uri.AbsoluteUri);
141 AssertEquals ("#rel1b", true, uri.UserEscaped);
142 uri = new Uri (new Uri("http://www.contoso.com"), "Hello World.htm", false);
143 AssertEquals ("#rel2a", "http://www.contoso.com/Hello%20World.htm", uri.AbsoluteUri);
144 AssertEquals ("#rel2b", false, uri.UserEscaped);
145 uri = new Uri (new Uri("http://www.contoso.com"), "http://www.xxx.com/Hello World.htm", false);
146 AssertEquals ("#rel3", "http://www.xxx.com/Hello%20World.htm", uri.AbsoluteUri);
148 uri = new Uri (new Uri("http://www.contoso.com"), "foo/bar/Hello World.htm?x=0:8", false);
149 AssertEquals ("#rel5", "http://www.contoso.com/foo/bar/Hello%20World.htm?x=0:8", uri.AbsoluteUri);
150 uri = new Uri (new Uri("http://www.contoso.com/xxx/yyy/index.htm"), "foo/bar/Hello World.htm?x=0:8", false);
151 AssertEquals ("#rel6", "http://www.contoso.com/xxx/yyy/foo/bar/Hello%20World.htm?x=0:8", uri.AbsoluteUri);
152 uri = new Uri (new Uri("http://www.contoso.com/xxx/yyy/index.htm"), "/foo/bar/Hello World.htm?x=0:8", false);
153 AssertEquals ("#rel7", "http://www.contoso.com/foo/bar/Hello%20World.htm?x=0:8", uri.AbsoluteUri);
154 uri = new Uri (new Uri("http://www.contoso.com/xxx/yyy/index.htm"), "../foo/bar/Hello World.htm?x=0:8", false);
155 AssertEquals ("#rel8", "http://www.contoso.com/xxx/foo/bar/Hello%20World.htm?x=0:8", uri.AbsoluteUri);
156 uri = new Uri (new Uri("http://www.contoso.com/xxx/yyy/index.htm"), "../../../foo/bar/Hello World.htm?x=0:8", false);
158 AssertEquals ("#rel9", "http://www.contoso.com/foo/bar/Hello%20World.htm?x=0:8", uri.AbsoluteUri);
160 AssertEquals ("#rel9", "http://www.contoso.com/../foo/bar/Hello%20World.htm?x=0:8", uri.AbsoluteUri);
162 uri = new Uri (new Uri("http://www.contoso.com/xxx/yyy/index.htm"), "./foo/bar/Hello World.htm?x=0:8", false);
163 AssertEquals ("#rel10", "http://www.contoso.com/xxx/yyy/foo/bar/Hello%20World.htm?x=0:8", uri.AbsoluteUri);
165 uri = new Uri (new Uri("http://www.contoso.com/foo/bar/index.html?x=0"), String.Empty, false);
166 AssertEquals("#22", "http://www.contoso.com/foo/bar/index.html?x=0", uri.ToString ());
168 uri = new Uri (new Uri("http://www.xxx.com"), "?x=0");
169 AssertEquals ("#rel30", "http://www.xxx.com/?x=0", uri.ToString());
170 uri = new Uri (new Uri("http://www.xxx.com/index.htm"), "?x=0");
171 AssertEquals ("#rel31", "http://www.xxx.com/?x=0", uri.ToString());
172 uri = new Uri (new Uri("http://www.xxx.com/index.htm"), "#here");
173 AssertEquals ("#rel32", "http://www.xxx.com/index.htm#here", uri.ToString());
175 uri = new Uri ("relative", UriKind.Relative);
176 uri = new Uri ("relative/abc", UriKind.Relative);
177 uri = new Uri ("relative", UriKind.RelativeOrAbsolute);
179 Assert ("#rel33", !uri.IsAbsoluteUri);
180 AssertEquals ("#rel34", uri.OriginalString, "relative");
181 Assert ("#rel35", !uri.UserEscaped);
186 public void Constructor_DualHostPort ()
188 string relative = "foo:8080/bar/Hello World.htm";
189 Uri uri = new Uri (new Uri("http://www.contoso.com"), relative, false);
190 AssertEquals ("AbsolutePath", "8080/bar/Hello%20World.htm", uri.AbsolutePath);
191 AssertEquals ("AbsoluteUri", "foo:8080/bar/Hello%20World.htm", uri.AbsoluteUri);
192 AssertEquals ("Authority", String.Empty, uri.Authority);
193 AssertEquals ("Fragment", String.Empty, uri.Fragment);
194 AssertEquals ("Host", String.Empty, uri.Host);
195 AssertEquals ("PathAndQuery", "8080/bar/Hello%20World.htm", uri.PathAndQuery);
196 AssertEquals ("Port", -1, uri.Port);
197 AssertEquals ("Query", String.Empty, uri.Query);
198 AssertEquals ("Scheme", "foo", uri.Scheme);
199 AssertEquals ("Query", String.Empty, uri.UserInfo);
201 AssertEquals ("Segments[0]", "8080/", uri.Segments[0]);
202 AssertEquals ("Segments[1]", "bar/", uri.Segments[1]);
203 AssertEquals ("Segments[2]", "Hello%20World.htm", uri.Segments[2]);
205 Assert ("IsDefaultPort", uri.IsDefaultPort);
206 Assert ("IsFile", !uri.IsFile);
207 Assert ("IsLoopback", !uri.IsLoopback);
208 Assert ("IsUnc", !uri.IsUnc);
209 Assert ("UserEscaped", !uri.UserEscaped);
211 AssertEquals ("HostNameType", UriHostNameType.Unknown, uri.HostNameType);
212 Assert ("IsAbsoluteUri", uri.IsAbsoluteUri);
213 AssertEquals ("OriginalString", relative, uri.OriginalString);
215 AssertEquals ("HostNameType", UriHostNameType.Basic, uri.HostNameType);
221 [ExpectedException (typeof (ArgumentNullException))]
223 [ExpectedException (typeof (NullReferenceException))]
225 public void Constructor_NullStringBool ()
227 new Uri (null, "http://www.contoso.com/index.htm", false);
232 [ExpectedException (typeof (NullReferenceException))]
234 public void Constructor_UriNullBool ()
236 new Uri (new Uri ("http://www.contoso.com"), null, false);
239 // regression for bug #47573
241 public void RelativeCtor ()
243 Uri b = new Uri ("http://a/b/c/d;p?q");
244 AssertEquals ("#1", "http://a/g", new Uri (b, "/g").ToString ());
245 AssertEquals ("#2", "http://g/", new Uri (b, "//g").ToString ());
246 AssertEquals ("#3", "http://a/b/c/?y", new Uri (b, "?y").ToString ());
247 Assert ("#4", new Uri (b, "#s").ToString ().EndsWith ("#s"));
249 Uri u = new Uri (b, "/g?q=r");
250 AssertEquals ("#5", "http://a/g?q=r", u.ToString ());
251 AssertEquals ("#6", "?q=r", u.Query);
253 u = new Uri (b, "/g?q=r;. a");
254 AssertEquals ("#5", "http://a/g?q=r;. a", u.ToString ());
255 AssertEquals ("#6", "?q=r;.%20a", u.Query);
260 [ExpectedException (typeof (UriFormatException))]
261 public void RelativeCtor_11_Crasher ()
263 Uri b = new Uri ("http://a/b/c/d;p?q");
264 // this causes crash under MS.NET 1.1
265 AssertEquals ("g:h", "g:h", new Uri (b, "g:h").ToString ());
270 [ExpectedException (typeof (UriFormatException))]
271 public void Bad_IPv6 ()
273 new Uri ("http://0:0:0:0::127.1.2.3]/");
278 [Category ("NotDotNet")]
280 public void LeadingSlashes_ShouldFailOn1x ()
282 // doesn't (but should) fail under 1.x
283 AssertEquals ("#1", "file:///", new Uri ("file:///").ToString ());
284 AssertEquals ("#2", "file:///", new Uri ("file://").ToString ());
289 [Category ("NotWorking")]
291 public void LeadingSlashes_BadResultsOn1x ()
293 // strange behaviours of 1.x - it's probably not worth to fix it
294 // on Mono as 2.0 has been fixed
295 Uri u = new Uri ("file:///foo/bar");
297 AssertEquals ("#3a", String.Empty, u.Host);
298 AssertEquals ("#3b", UriHostNameType.Basic, u.HostNameType);
299 AssertEquals ("#3c", "file:///foo/bar", u.ToString ());
300 AssertEquals ("#3d", false, u.IsUnc);
302 // 1.x misinterpret the first path element as the host name
303 AssertEquals ("#3a", "foo", u.Host);
304 AssertEquals ("#3b", UriHostNameType.Dns, u.HostNameType);
305 AssertEquals ("#3c", "file://foo/bar", u.ToString ());
306 AssertEquals ("#3d", true, u.IsUnc);
308 u = new Uri ("mailto:/foo");
310 AssertEquals ("#13a", String.Empty, u.Host);
311 AssertEquals ("#13b", UriHostNameType.Basic, u.HostNameType);
312 AssertEquals ("#13c", "mailto:/foo", u.ToString ());
314 // 1.x misinterpret the first path element as the host name
315 AssertEquals ("#13a", "foo", u.Host);
316 AssertEquals ("#13b", UriHostNameType.Dns, u.HostNameType);
317 AssertEquals ("#13c", "mailto:foo", u.ToString ());
319 u = new Uri ("mailto://foo");
321 AssertEquals ("#14a", String.Empty, u.Host);
322 AssertEquals ("#14b", UriHostNameType.Basic, u.HostNameType);
323 AssertEquals ("#14c", "mailto://foo", u.ToString ());
325 // 1.x misinterpret the first path element as the host name
326 AssertEquals ("#14a", "foo", u.Host);
327 AssertEquals ("#14b", UriHostNameType.Dns, u.HostNameType);
328 AssertEquals ("#14c", "mailto://foo/", u.ToString ());
330 u = new Uri ("news:/");
331 AssertEquals ("#18a", String.Empty, u.Host);
333 AssertEquals ("#18b", UriHostNameType.Unknown, u.HostNameType);
334 AssertEquals ("#18c", "news:/", u.ToString ());
335 AssertEquals ("#18d", "/", u.AbsolutePath);
336 AssertEquals ("#18e", "news:/", u.AbsoluteUri);
338 AssertEquals ("#18b", UriHostNameType.Basic, u.HostNameType);
339 AssertEquals ("#18c", "news:", u.ToString ());
340 AssertEquals ("#18d", String.Empty, u.AbsolutePath);
341 AssertEquals ("#18e", "news:", u.AbsoluteUri);
343 u = new Uri ("news:/foo");
344 AssertEquals ("#19a", String.Empty, u.Host);
346 AssertEquals ("#19b", UriHostNameType.Unknown, u.HostNameType);
347 AssertEquals ("#19c", "news:/foo", u.ToString ());
348 AssertEquals ("#19d", "/foo", u.AbsolutePath);
349 AssertEquals ("#19e", "news:/foo", u.AbsoluteUri);
351 AssertEquals ("#19b", UriHostNameType.Basic, u.HostNameType);
352 AssertEquals ("#19c", "news:foo", u.ToString ());
353 AssertEquals ("#19d", "foo", u.AbsolutePath);
354 AssertEquals ("#19e", "news:foo", u.AbsoluteUri);
356 u = new Uri ("news://foo");
358 AssertEquals ("#20a", String.Empty, u.Host);
359 AssertEquals ("#20b", UriHostNameType.Unknown, u.HostNameType);
360 AssertEquals ("#20c", "news://foo", u.ToString ());
361 AssertEquals ("#20d", "//foo", u.AbsolutePath);
362 AssertEquals ("#20e", "news://foo", u.AbsoluteUri);
364 AssertEquals ("#20a", "foo", u.Host);
365 AssertEquals ("#20b", UriHostNameType.Dns, u.HostNameType);
366 AssertEquals ("#20c", "news://foo/", u.ToString ());
367 AssertEquals ("#20d", "/", u.AbsolutePath);
368 AssertEquals ("#20e", "news://foo/", u.AbsoluteUri);
370 u = new Uri ("news://foo/bar");
372 AssertEquals ("#22a", String.Empty, u.Host);
373 AssertEquals ("#22b", UriHostNameType.Unknown, u.HostNameType);
374 AssertEquals ("#22c", "news://foo/bar", u.ToString ());
375 AssertEquals ("#22d", "//foo/bar", u.AbsolutePath);
376 AssertEquals ("#22e", "news://foo/bar", u.AbsoluteUri);
378 AssertEquals ("#22a", "foo", u.Host);
379 AssertEquals ("#22b", UriHostNameType.Dns, u.HostNameType);
380 AssertEquals ("#22c", "news://foo/bar", u.ToString ());
381 AssertEquals ("#22d", "/bar", u.AbsolutePath);
382 AssertEquals ("#22e", "news://foo/bar", u.AbsoluteUri);
388 [Category ("NotDotNet")] // does (but shouldn't) fail under 1.x
390 public void LeadingSlashes_FailOn1x ()
392 // 1.x throws an UriFormatException because it can't decode the host name
393 Uri u = new Uri ("mailto:");
394 AssertEquals ("#10a", String.Empty, u.Host);
395 AssertEquals ("#10b", UriHostNameType.Basic, u.HostNameType);
396 AssertEquals ("#10c", "mailto:", u.ToString ());
398 // 1.x throws an UriFormatException because it can't decode the host name
399 u = new Uri ("mailto:/");
400 AssertEquals ("#12a", String.Empty, u.Host);
401 AssertEquals ("#12b", UriHostNameType.Basic, u.HostNameType);
402 AssertEquals ("#12c", "mailto:/", u.ToString ());
404 // 1.x throws an UriFormatException because it cannot detect the format
405 u = new Uri ("mailto:///foo");
406 AssertEquals ("#15a", String.Empty, u.Host);
407 AssertEquals ("#15b", UriHostNameType.Basic, u.HostNameType);
408 AssertEquals ("#15c", "mailto:///foo", u.ToString ());
410 // 1.x throws an UriFormatException because it cannot detect the format
411 u = new Uri ("news:///foo");
412 AssertEquals ("#21a", String.Empty, u.Host);
414 AssertEquals ("#21b", UriHostNameType.Unknown, u.HostNameType);
416 AssertEquals ("#21b", UriHostNameType.Basic, u.HostNameType);
418 AssertEquals ("#21c", "news:///foo", u.ToString ());
419 AssertEquals ("#21d", "///foo", u.AbsolutePath);
420 AssertEquals ("#21e", "news:///foo", u.AbsoluteUri);
424 // some tests from bug 75144
425 public void LeadingSlashes ()
427 Uri u = new Uri ("file://foo/bar");
428 AssertEquals ("#5a", "foo", u.Host);
429 AssertEquals ("#5b", UriHostNameType.Dns, u.HostNameType);
430 AssertEquals ("#5c", "file://foo/bar", u.ToString ());
431 AssertEquals ("#5d", true, u.IsUnc);
433 u = new Uri ("file:////foo/bar");
434 AssertEquals ("#7a", "foo", u.Host);
435 AssertEquals ("#7b", UriHostNameType.Dns, u.HostNameType);
436 AssertEquals ("#7c", "file://foo/bar", u.ToString ());
437 AssertEquals ("#7d", true, u.IsUnc);
439 AssertEquals ("#9", "file://foo/bar", new Uri ("file://///foo/bar").ToString());
441 u = new Uri ("mailto:foo");
442 AssertEquals ("#11a", "foo", u.Host);
443 AssertEquals ("#11b", UriHostNameType.Dns, u.HostNameType);
444 AssertEquals ("#11c", "mailto:foo", u.ToString ());
446 u = new Uri ("news:");
447 AssertEquals ("#16a", String.Empty, u.Host);
449 AssertEquals ("#16b", UriHostNameType.Unknown, u.HostNameType);
451 AssertEquals ("#16b", UriHostNameType.Basic, u.HostNameType);
453 AssertEquals ("#16c", "news:", u.ToString ());
455 u = new Uri ("news:foo");
456 AssertEquals ("#17a", String.Empty, u.Host);
458 AssertEquals ("#17b", UriHostNameType.Unknown, u.HostNameType);
460 AssertEquals ("#17b", UriHostNameType.Basic, u.HostNameType);
462 AssertEquals ("#17c", "news:foo", u.ToString ());
463 AssertEquals ("#17d", "foo", u.AbsolutePath);
464 AssertEquals ("#17e", "news:foo", u.AbsoluteUri);
468 [ExpectedException (typeof (UriFormatException))]
469 public void HttpHostname1 ()
475 [ExpectedException (typeof (UriFormatException))]
477 [Category ("NotDotNet")] // doesn't fail under 1.x
479 public void HttpHostname2 ()
485 [ExpectedException (typeof (UriFormatException))]
486 public void HttpHostname3 ()
492 [ExpectedException (typeof (UriFormatException))]
494 [Category ("NotDotNet")] // doesn't fail under 1.x
496 public void HttpHostname4 ()
498 new Uri ("http:/foo");
502 [ExpectedException (typeof (UriFormatException))]
503 public void HttpHostname5 ()
509 [ExpectedException (typeof (UriFormatException))]
510 public void HttpHostname6 ()
512 new Uri ("http:///");
516 [ExpectedException (typeof (UriFormatException))]
517 public void HttpHostname7 ()
519 new Uri ("http:///foo");
523 [ExpectedException (typeof (UriFormatException))]
524 public void InvalidFile1 ()
530 [ExpectedException (typeof (UriFormatException))]
531 public void InvalidFile2 ()
537 [ExpectedException (typeof (UriFormatException))]
538 public void InvalidFile3 ()
540 new Uri ("file:/foo");
544 [ExpectedException (typeof (UriFormatException))]
545 public void InvalidScheme ()
551 public void ConstructorsRejectRelativePath ()
553 string [] reluris = new string [] {
555 "thisdir/childdir/file",
558 string [] winRelUris = new string [] {
562 for (int i = 0; i < reluris.Length; i++) {
564 new Uri (reluris [i]);
565 Fail ("Should be failed: " + reluris [i]);
566 } catch (UriFormatException) {
571 for (int i = 0; i < winRelUris.Length; i++) {
573 new Uri (winRelUris [i]);
574 Fail ("Should be failed: " + winRelUris [i]);
575 } catch (UriFormatException) {
582 public void LocalPath ()
584 Uri uri = new Uri ("c:\\tmp\\hello.txt");
585 AssertEquals ("#1a", "file:///c:/tmp/hello.txt", uri.ToString ());
586 AssertEquals ("#1b", "c:\\tmp\\hello.txt", uri.LocalPath);
587 AssertEquals ("#1c", "file", uri.Scheme);
588 AssertEquals ("#1d", "", uri.Host);
589 AssertEquals ("#1e", "c:/tmp/hello.txt", uri.AbsolutePath);
591 uri = new Uri ("file:////////cygwin/tmp/hello.txt");
592 AssertEquals ("#3a", "file://cygwin/tmp/hello.txt", uri.ToString ());
594 AssertEquals ("#3b win32", "\\\\cygwin\\tmp\\hello.txt", uri.LocalPath);
596 AssertEquals ("#3b *nix", "/tmp/hello.txt", uri.LocalPath);
597 AssertEquals ("#3c", "file", uri.Scheme);
598 AssertEquals ("#3d", "cygwin", uri.Host);
599 AssertEquals ("#3e", "/tmp/hello.txt", uri.AbsolutePath);
601 uri = new Uri ("file://mymachine/cygwin/tmp/hello.txt");
602 AssertEquals ("#4a", "file://mymachine/cygwin/tmp/hello.txt", uri.ToString ());
604 AssertEquals ("#4b win32", "\\\\mymachine\\cygwin\\tmp\\hello.txt", uri.LocalPath);
606 AssertEquals ("#4b *nix", "/cygwin/tmp/hello.txt", uri.LocalPath);
607 AssertEquals ("#4c", "file", uri.Scheme);
608 AssertEquals ("#4d", "mymachine", uri.Host);
609 AssertEquals ("#4e", "/cygwin/tmp/hello.txt", uri.AbsolutePath);
611 uri = new Uri ("file://///c:/cygwin/tmp/hello.txt");
612 AssertEquals ("#5a", "file:///c:/cygwin/tmp/hello.txt", uri.ToString ());
613 AssertEquals ("#5b", "c:\\cygwin\\tmp\\hello.txt", uri.LocalPath);
614 AssertEquals ("#5c", "file", uri.Scheme);
615 AssertEquals ("#5d", "", uri.Host);
616 AssertEquals ("#5e", "c:/cygwin/tmp/hello.txt", uri.AbsolutePath);
620 public void LocalPath_FileHost ()
622 // Hmm, they should be regarded just as a host name, since all URIs are base on absolute path.
623 Uri uri = new Uri("file://one_file.txt");
625 AssertEquals("#6a", "file://one_file.txt/", uri.ToString());
626 AssertEquals ("#6e", "/", uri.AbsolutePath);
627 AssertEquals ("#6f", "/", uri.PathAndQuery);
628 AssertEquals ("#6g", "file://one_file.txt/", uri.GetLeftPart (UriPartial.Path));
630 AssertEquals("#6a", "file://one_file.txt", uri.ToString());
631 AssertEquals("#6e", "", uri.AbsolutePath);
632 AssertEquals ("#6f", "", uri.PathAndQuery);
633 AssertEquals ("#6g", "file://one_file.txt", uri.GetLeftPart (UriPartial.Path));
636 AssertEquals("#6b", "\\\\one_file.txt", uri.LocalPath);
638 AssertEquals("#6b", "/", uri.LocalPath);
639 AssertEquals("#6c", "file", uri.Scheme);
640 AssertEquals("#6d", "one_file.txt", uri.Host);
642 // same tests - but original Uri is now ending with a '/'
644 uri = new Uri ("file://one_file.txt/");
645 AssertEquals ("#7a", "file://one_file.txt/", uri.ToString ());
646 AssertEquals ("#7e", "/", uri.AbsolutePath);
647 AssertEquals ("#7f", "/", uri.PathAndQuery);
648 AssertEquals ("#7g", "file://one_file.txt/", uri.GetLeftPart (UriPartial.Path));
651 AssertEquals ("#7b", "\\\\one_file.txt\\", uri.LocalPath);
653 AssertEquals ("#7b", "/", uri.LocalPath);
655 AssertEquals ("#7c", "file", uri.Scheme);
656 AssertEquals ("#7d", "one_file.txt", uri.Host);
660 public void LocalPath_Escape ()
663 Uri uri = new Uri ("file:///tmp/a%20a");
666 Assert ("#7a:" + uri.LocalPath, uri.LocalPath.EndsWith ("/tmp/a a"));
668 // actually MS.NET treats /// as \\ thus it fails here.
669 Assert ("#7a:" + uri.LocalPath, uri.LocalPath.EndsWith ("\\tmp\\a a"));
672 AssertEquals ("#7b", "/tmp/a a", uri.LocalPath);
674 uri = new Uri ("file:///tmp/foo%25bar");
677 Assert ("#8a:" + uri.LocalPath, uri.LocalPath.EndsWith ("/tmp/foo%bar"));
678 Assert ("#8c:" + uri.ToString (), uri.ToString ().EndsWith ("//tmp/foo%25bar"));
680 // actually MS.NET treats /// as \\ thus it fails here.
681 Assert ("#8a:" + uri.LocalPath, uri.LocalPath.EndsWith ("\\tmp\\foo%bar"));
682 // ditto, file://tmp/foo%25bar (bug in 1.x)
683 Assert ("#8c:" + uri.ToString (), uri.ToString ().EndsWith ("//tmp/foo%bar"));
686 AssertEquals ("#8b", "/tmp/foo%bar", uri.LocalPath);
687 AssertEquals ("#8d", "file:///tmp/foo%25bar", uri.ToString ());
690 uri = new Uri ("file:///foo%25bar");
693 Assert ("#9a:" + uri.LocalPath, uri.LocalPath.EndsWith ("/foo%bar"));
695 // actually MS.NET treats /// as \\ thus it fails here.
696 Assert ("#9a:" + uri.LocalPath, uri.LocalPath.EndsWith ("\\foo%25bar"));
698 // ditto, file://tmp/foo%25bar (bug in 1.x)
699 Assert ("#9c:" + uri.ToString (), uri.ToString ().EndsWith ("//foo%25bar"));
701 AssertEquals ("#9b", "/foo%bar", uri.LocalPath);
702 AssertEquals ("#9d", "file:///foo%25bar", uri.ToString ());
706 // Novell Bugzilla #320614
708 public void QueryEscape ()
710 Uri u1 = new Uri("http://localhost:8080/test.aspx?ReturnUrl=%2fSearchDoc%2fSearcher.aspx");
711 Uri u2 = new Uri("http://localhost:8080/test.aspx?ReturnUrl=%252fSearchDoc%252fSearcher.aspx");
713 AssertEquals ("QE1", u1.ToString (), "http://localhost:8080/test.aspx?ReturnUrl=/SearchDoc/Searcher.aspx");
714 AssertEquals ("QE2", u2.ToString (), "http://localhost:8080/test.aspx?ReturnUrl=%2fSearchDoc%2fSearcher.aspx");
718 public void UnixPath () {
720 AssertEquals ("#6a", "file:///cygwin/tmp/hello.txt", new Uri ("/cygwin/tmp/hello.txt").ToString ());
726 Uri uri = new Uri ("http://www.contoso.com");
727 Assert ("#1", !uri.IsUnc);
729 uri = new Uri ("news:123456@contoso.com");
730 Assert ("#2", !uri.IsUnc);
732 uri = new Uri ("file://server/filename.ext");
733 Assert ("#3", uri.IsUnc);
735 uri = new Uri (@"\\server\share\filename.ext");
736 Assert ("#6", uri.IsUnc);
738 uri = new Uri (@"a:\dir\filename.ext");
739 Assert ("#8", !uri.IsUnc);
743 [Category("NotDotNet")]
744 public void UncFail ()
746 Uri uri = new Uri ("/home/user/dir/filename.ext");
747 Assert ("#7", !uri.IsUnc);
751 public void FromHex ()
753 AssertEquals ("#1", 0, Uri.FromHex ('0'));
754 AssertEquals ("#2", 9, Uri.FromHex ('9'));
755 AssertEquals ("#3", 10, Uri.FromHex ('a'));
756 AssertEquals ("#4", 15, Uri.FromHex ('f'));
757 AssertEquals ("#5", 10, Uri.FromHex ('A'));
758 AssertEquals ("#6", 15, Uri.FromHex ('F'));
762 } catch (ArgumentException) {}
766 } catch (ArgumentException) {}
770 } catch (ArgumentException) {}
775 public UriEx (string s) : base (s)
779 public string UnescapeString (string s)
784 public static string UnescapeString (string uri, string target)
786 return new UriEx (uri).UnescapeString (target);
791 public void Unescape ()
793 AssertEquals ("#1", "#", UriEx.UnescapeString ("file://localhost/c#", "%23"));
794 AssertEquals ("#2", "c#", UriEx.UnescapeString ("file://localhost/c#", "c%23"));
795 AssertEquals ("#3", "\xA9", UriEx.UnescapeString ("file://localhost/c#", "%A9"));
796 AssertEquals ("#1", "#", UriEx.UnescapeString ("http://localhost/c#", "%23"));
797 AssertEquals ("#2", "c#", UriEx.UnescapeString ("http://localhost/c#", "c%23"));
798 AssertEquals ("#3", "\xA9", UriEx.UnescapeString ("http://localhost/c#", "%A9"));
802 public void HexEscape ()
804 AssertEquals ("#1","%20", Uri.HexEscape (' '));
805 AssertEquals ("#2","%A9", Uri.HexEscape ((char) 0xa9));
806 AssertEquals ("#3","%41", Uri.HexEscape ('A'));
808 Uri.HexEscape ((char) 0x0369);
810 } catch (ArgumentOutOfRangeException) {}
814 public void HexUnescape ()
817 AssertEquals ("#1", ' ', Uri.HexUnescape ("%20", ref i));
818 AssertEquals ("#2", 3, i);
820 AssertEquals ("#3", (char) 0xa9, Uri.HexUnescape ("test%a9test", ref i));
821 AssertEquals ("#4", 7, i);
822 AssertEquals ("#5", 't', Uri.HexUnescape ("test%a9test", ref i));
823 AssertEquals ("#6", 8, i);
825 AssertEquals ("#5", '%', Uri.HexUnescape ("test%a", ref i));
826 AssertEquals ("#6", 5, i);
827 AssertEquals ("#7", '%', Uri.HexUnescape ("testx%xx", ref i));
828 AssertEquals ("#8", 6, i);
830 // Tests from bug 74872 - don't handle multi-byte characters as multi-byte
832 AssertEquals ("#9", 227, (int) Uri.HexUnescape ("a%E3%81%8B", ref i));
833 AssertEquals ("#10", 4, i);
835 AssertEquals ("#11", 240, (int) Uri.HexUnescape ("a%F0%90%84%80", ref i));
836 AssertEquals ("#12", 4, i);
840 // These won't pass exactly with MS.NET 1.x, due to differences in the
841 // handling of backslashes/forwardslashes
842 [Category ("NotDotNet")]
845 public void HexUnescapeMultiByte ()
847 // Tests from bug 74872
848 // Note: These won't pass exactly with MS.NET, due to differences in the
849 // handling of backslashes/forwardslashes
854 uri = new Uri ("file:///foo/a%E3%81%8Bb", true);
855 path = uri.LocalPath;
856 AssertEquals ("#1", 8, path.Length);
857 AssertEquals ("#2", 0x304B, path [6]);
859 // 4-byte character which should be handled as a surrogate
860 uri = new Uri ("file:///foo/a%F3%A0%84%80b", true);
861 path = uri.LocalPath;
862 AssertEquals ("#3", 9, path.Length);
863 AssertEquals ("#4", 0xDB40, path [6]);
864 AssertEquals ("#5", 0xDD00, path [7]);
865 AssertEquals ("#6", 0x62, path [8]);
867 // 2-byte escape sequence, 2 individual characters
868 uri = new Uri ("file:///foo/a%C2%F8b", true);
869 path = uri.LocalPath;
870 AssertEquals ("#7", 9, path.Length);
871 AssertEquals ("#8", 0xC2, path [6]);
872 AssertEquals ("#9", 0xF8, path [7]);
876 public void IsHexDigit ()
878 Assert ("#1", Uri.IsHexDigit ('a'));
879 Assert ("#2", Uri.IsHexDigit ('f'));
880 Assert ("#3", !Uri.IsHexDigit ('g'));
881 Assert ("#4", Uri.IsHexDigit ('0'));
882 Assert ("#5", Uri.IsHexDigit ('9'));
883 Assert ("#6", Uri.IsHexDigit ('A'));
884 Assert ("#7", Uri.IsHexDigit ('F'));
885 Assert ("#8", !Uri.IsHexDigit ('G'));
889 public void IsHexEncoding ()
891 Assert ("#1", Uri.IsHexEncoding ("test%a9test", 4));
892 Assert ("#2", !Uri.IsHexEncoding ("test%a9test", 3));
893 Assert ("#3", Uri.IsHexEncoding ("test%a9", 4));
894 Assert ("#4", !Uri.IsHexEncoding ("test%a", 4));
898 public void GetLeftPart ()
900 Uri uri = new Uri ("http://www.contoso.com/index.htm#main");
901 AssertEquals ("#1", "http://", uri.GetLeftPart (UriPartial.Scheme));
902 AssertEquals ("#2", "http://www.contoso.com", uri.GetLeftPart (UriPartial.Authority));
903 AssertEquals ("#3", "http://www.contoso.com/index.htm", uri.GetLeftPart (UriPartial.Path));
905 uri = new Uri ("mailto:user@contoso.com?subject=uri");
906 AssertEquals ("#4", "mailto:", uri.GetLeftPart (UriPartial.Scheme));
907 AssertEquals ("#5", "", uri.GetLeftPart (UriPartial.Authority));
908 AssertEquals ("#6", "mailto:user@contoso.com", uri.GetLeftPart (UriPartial.Path));
910 uri = new Uri ("nntp://news.contoso.com/123456@contoso.com");
911 AssertEquals ("#7", "nntp://", uri.GetLeftPart (UriPartial.Scheme));
912 AssertEquals ("#8", "nntp://news.contoso.com", uri.GetLeftPart (UriPartial.Authority));
913 AssertEquals ("#9", "nntp://news.contoso.com/123456@contoso.com", uri.GetLeftPart (UriPartial.Path));
915 uri = new Uri ("news:123456@contoso.com");
916 AssertEquals ("#10", "news:", uri.GetLeftPart (UriPartial.Scheme));
917 AssertEquals ("#11", "", uri.GetLeftPart (UriPartial.Authority));
918 AssertEquals ("#12", "news:123456@contoso.com", uri.GetLeftPart (UriPartial.Path));
920 uri = new Uri ("file://server/filename.ext");
921 AssertEquals ("#13", "file://", uri.GetLeftPart (UriPartial.Scheme));
922 AssertEquals ("#14", "file://server", uri.GetLeftPart (UriPartial.Authority));
923 AssertEquals ("#15", "file://server/filename.ext", uri.GetLeftPart (UriPartial.Path));
925 uri = new Uri (@"\\server\share\filename.ext");
926 AssertEquals ("#20", "file://", uri.GetLeftPart (UriPartial.Scheme));
927 AssertEquals ("#21", "file://server", uri.GetLeftPart (UriPartial.Authority));
928 AssertEquals ("#22", "file://server/share/filename.ext", uri.GetLeftPart (UriPartial.Path));
930 uri = new Uri ("http://www.contoso.com:8080/index.htm#main");
931 AssertEquals ("#23", "http://", uri.GetLeftPart (UriPartial.Scheme));
932 AssertEquals ("#24", "http://www.contoso.com:8080", uri.GetLeftPart (UriPartial.Authority));
933 AssertEquals ("#25", "http://www.contoso.com:8080/index.htm", uri.GetLeftPart (UriPartial.Path));
937 public void NewsDefaultPort ()
939 Uri uri = new Uri("news://localhost:119/");
940 AssertEquals ("#1", uri.IsDefaultPort, true);
944 public void Fragment_Escape ()
946 Uri u = new Uri("http://localhost/index.asp#main#start", false);
947 AssertEquals ("#1", u.Fragment, "#main%23start");
949 u = new Uri("http://localhost/index.asp#main#start", true);
950 AssertEquals ("#2", u.Fragment, "#main#start");
952 // The other code path uses a BaseUri
954 Uri b = new Uri ("http://www.gnome.org");
955 Uri n = new Uri (b, "blah#main#start");
956 AssertEquals ("#3", n.Fragment, "#main%23start");
958 n = new Uri (b, "blah#main#start", true);
959 AssertEquals ("#4", n.Fragment, "#main#start");
964 public void Fragment_RelativeUri ()
966 Uri uri1 = new Uri ("http://www.contoso.com/index.htm?x=2");
967 Uri uri2 = new Uri ("http://www.contoso.com/foo/bar/index.htm#fragment");
968 Uri relativeUri = uri1.MakeRelativeUri (uri2);
971 string fragment = relativeUri.Fragment;
972 Fail ("#1: " + fragment);
973 } catch (InvalidOperationException ex) {
974 // This operation is not supported for a relative URI
975 AssertEquals ("#2", typeof (InvalidOperationException), ex.GetType ());
976 AssertNull ("#3", ex.InnerException);
977 AssertNotNull ("#4", ex.Message);
983 [ExpectedException(typeof(UriFormatException))]
984 public void IncompleteSchemeDelimiter ()
986 new Uri ("file:/filename.ext");
990 [Category("NotDotNet")]
991 public void CheckHostName1 ()
993 // reported to MSDN Product Feedback Center (FDBK28671)
994 AssertEquals ("#36 known to fail with ms.net: this is not a valid IPv6 address.", UriHostNameType.Unknown, Uri.CheckHostName (":11:22:33:44:55:66:77:88"));
998 public void CheckHostName2 ()
1000 AssertEquals ("#1", UriHostNameType.Unknown, Uri.CheckHostName (null));
1001 AssertEquals ("#2", UriHostNameType.Unknown, Uri.CheckHostName (""));
1002 AssertEquals ("#3", UriHostNameType.Unknown, Uri.CheckHostName ("^&()~`!@"));
1003 AssertEquals ("#4", UriHostNameType.Dns, Uri.CheckHostName ("x"));
1004 AssertEquals ("#5", UriHostNameType.IPv4, Uri.CheckHostName ("1.2.3.4"));
1005 AssertEquals ("#6", UriHostNameType.IPv4, Uri.CheckHostName ("0001.002.03.4"));
1006 AssertEquals ("#7", UriHostNameType.Dns, Uri.CheckHostName ("0001.002.03.256"));
1007 AssertEquals ("#8", UriHostNameType.Dns, Uri.CheckHostName ("9001.002.03.4"));
1008 AssertEquals ("#9", UriHostNameType.Dns, Uri.CheckHostName ("www.contoso.com"));
1009 AssertEquals ("#10", UriHostNameType.Unknown, Uri.CheckHostName (".www.contoso.com"));
1010 AssertEquals ("#11", UriHostNameType.Dns, Uri.CheckHostName ("www.contoso.com."));
1011 AssertEquals ("#12", UriHostNameType.Dns, Uri.CheckHostName ("www.con-toso.com"));
1012 AssertEquals ("#13", UriHostNameType.Dns, Uri.CheckHostName ("www.con_toso.com"));
1013 AssertEquals ("#14", UriHostNameType.Unknown, Uri.CheckHostName ("www.con,toso.com"));
1016 AssertEquals ("#15", UriHostNameType.IPv6, Uri.CheckHostName ("11:22:33:44:55:66:77:88"));
1017 AssertEquals ("#16", UriHostNameType.IPv6, Uri.CheckHostName ("11::33:44:55:66:77:88"));
1018 AssertEquals ("#17", UriHostNameType.IPv6, Uri.CheckHostName ("::22:33:44:55:66:77:88"));
1019 AssertEquals ("#18", UriHostNameType.IPv6, Uri.CheckHostName ("11:22:33:44:55:66:77::"));
1020 AssertEquals ("#19", UriHostNameType.IPv6, Uri.CheckHostName ("11::88"));
1021 AssertEquals ("#20", UriHostNameType.IPv6, Uri.CheckHostName ("11::77:88"));
1022 AssertEquals ("#21", UriHostNameType.IPv6, Uri.CheckHostName ("11:22::88"));
1023 AssertEquals ("#22", UriHostNameType.IPv6, Uri.CheckHostName ("11::"));
1024 AssertEquals ("#23", UriHostNameType.IPv6, Uri.CheckHostName ("::88"));
1025 AssertEquals ("#24", UriHostNameType.IPv6, Uri.CheckHostName ("::1"));
1026 AssertEquals ("#25", UriHostNameType.IPv6, Uri.CheckHostName ("::"));
1027 AssertEquals ("#26", UriHostNameType.IPv6, Uri.CheckHostName ("0:0:0:0:0:0:127.0.0.1"));
1028 AssertEquals ("#27", UriHostNameType.IPv6, Uri.CheckHostName ("::127.0.0.1"));
1029 AssertEquals ("#28", UriHostNameType.IPv6, Uri.CheckHostName ("::ffFF:169.32.14.5"));
1030 AssertEquals ("#29", UriHostNameType.IPv6, Uri.CheckHostName ("2001:03A0::/35"));
1031 AssertEquals ("#30", UriHostNameType.IPv6, Uri.CheckHostName ("[2001:03A0::/35]"));
1032 AssertEquals ("#33", UriHostNameType.IPv6, Uri.CheckHostName ("2001::03A0:1.2.3.4"));
1034 AssertEquals ("#31", UriHostNameType.Unknown, Uri.CheckHostName ("2001::03A0::/35"));
1035 AssertEquals ("#32", UriHostNameType.Unknown, Uri.CheckHostName ("2001:03A0::/35a"));
1036 AssertEquals ("#34", UriHostNameType.Unknown, Uri.CheckHostName ("::ffff:123.256.155.43"));
1037 AssertEquals ("#35", UriHostNameType.Unknown, Uri.CheckHostName (":127.0.0.1"));
1038 AssertEquals ("#37", UriHostNameType.Unknown, Uri.CheckHostName ("::11:22:33:44:55:66:77:88"));
1039 AssertEquals ("#38", UriHostNameType.Unknown, Uri.CheckHostName ("11:22:33:44:55:66:77:88::"));
1040 AssertEquals ("#39", UriHostNameType.Unknown, Uri.CheckHostName ("11:22:33:44:55:66:77:88:"));
1041 AssertEquals ("#40", UriHostNameType.Unknown, Uri.CheckHostName ("::acbde"));
1042 AssertEquals ("#41", UriHostNameType.Unknown, Uri.CheckHostName ("::abce:"));
1043 AssertEquals ("#42", UriHostNameType.Unknown, Uri.CheckHostName ("::abcg"));
1044 AssertEquals ("#43", UriHostNameType.Unknown, Uri.CheckHostName (":::"));
1045 AssertEquals ("#44", UriHostNameType.Unknown, Uri.CheckHostName (":"));
1047 AssertEquals ("#45", UriHostNameType.Unknown, Uri.CheckHostName ("*"));
1048 AssertEquals ("#46", UriHostNameType.Unknown, Uri.CheckHostName ("*.go-mono.com"));
1049 AssertEquals ("#47", UriHostNameType.Unknown, Uri.CheckHostName ("www*.go-mono.com"));
1053 public void IsLoopback ()
1055 Uri uri = new Uri("http://loopback:8080");
1056 AssertEquals ("#1", true, uri.IsLoopback);
1057 uri = new Uri("http://localhost:8080");
1058 AssertEquals ("#2", true, uri.IsLoopback);
1059 uri = new Uri("http://127.0.0.1:8080");
1060 AssertEquals ("#3", true, uri.IsLoopback);
1061 uri = new Uri("http://127.0.0.001:8080");
1062 AssertEquals ("#4", true, uri.IsLoopback);
1063 uri = new Uri("http://[::1]");
1064 AssertEquals ("#5", true, uri.IsLoopback);
1065 uri = new Uri("http://[::1]:8080");
1066 AssertEquals ("#6", true, uri.IsLoopback);
1067 uri = new Uri("http://[::0001]:8080");
1068 AssertEquals ("#7", true, uri.IsLoopback);
1069 uri = new Uri("http://[0:0:0:0::1]:8080");
1070 AssertEquals ("#8", true, uri.IsLoopback);
1071 uri = new Uri("http://[0:0:0:0::127.0.0.1]:8080");
1072 AssertEquals ("#9", true, uri.IsLoopback);
1073 uri = new Uri("http://[0:0:0:0::127.11.22.33]:8080");
1074 AssertEquals ("#10", false, uri.IsLoopback);
1075 uri = new Uri("http://[::ffff:127.11.22.33]:8080");
1076 AssertEquals ("#11", false, uri.IsLoopback);
1077 uri = new Uri("http://[::ff00:7f11:2233]:8080");
1078 AssertEquals ("#12", false, uri.IsLoopback);
1079 uri = new Uri("http://[1:0:0:0::1]:8080");
1080 AssertEquals ("#13", false, uri.IsLoopback);
1084 public void IsLoopback_File ()
1086 Uri uri = new Uri ("file:///index.html");
1088 Assert ("file", uri.IsLoopback);
1090 Assert ("file", !uri.IsLoopback);
1095 public void IsLoopback_Relative_Http ()
1097 string relative = "http:8080/bar/Hello World.htm";
1098 Uri uri = new Uri (new Uri ("http://www.contoso.com"), relative, false);
1099 Assert ("http", !uri.IsLoopback);
1103 public void IsLoopback_Relative_Unknown ()
1105 string relative = "foo:8080/bar/Hello World.htm";
1106 Uri uri = new Uri (new Uri ("http://www.contoso.com"), relative, false);
1107 Assert ("foo", !uri.IsLoopback);
1111 public void Equals1 ()
1113 Uri uri1 = new Uri ("http://www.contoso.com/index.htm#main");
1114 Uri uri2 = new Uri ("http://www.contoso.com/index.htm#fragment");
1115 Assert ("#1", uri1.Equals (uri2));
1116 Assert ("#3", !uri2.Equals ("http://www.contoso.com/index.html?x=1"));
1117 Assert ("#4", !uri1.Equals ("http://www.contoso.com:8080/index.htm?x=1"));
1122 [Category("NotDotNet")]
1124 public void Equals2 ()
1126 Uri uri1 = new Uri ("http://www.contoso.com/index.htm#main");
1127 Uri uri2 = new Uri ("http://www.contoso.com/index.htm?x=1");
1128 Assert ("#2 known to fail with ms.net 1.x", !uri1.Equals (uri2));
1132 public void Equals3 ()
1134 Uri uri1 = new Uri ("svn+ssh://atsushi@mono-cvs.ximian.com");
1135 Uri uri2 = new Uri ("svn+ssh://anonymous@mono-cvs.ximian.com");
1136 Assert (uri1.Equals (uri2));
1140 public void TestEquals2 ()
1142 Uri a = new Uri ("http://www.go-mono.com");
1143 Uri b = new Uri ("http://www.go-mono.com");
1145 AssertEquals ("#1", a, b);
1147 a = new Uri ("mailto:user:pwd@go-mono.com?subject=uri");
1148 b = new Uri ("MAILTO:USER:PWD@GO-MONO.COM?SUBJECT=URI");
1150 Assert ("#2", a != b);
1151 AssertEquals ("#2a", "mailto:user:pwd@go-mono.com?subject=uri", a.ToString ());
1152 AssertEquals ("#2b", "mailto:USER:PWD@go-mono.com?SUBJECT=URI", b.ToString ());
1154 AssertEquals ("#2", a, b);
1156 a = new Uri ("http://www.go-mono.com/ports/");
1157 b = new Uri ("http://www.go-mono.com/PORTS/");
1159 Assert ("#3", !a.Equals (b));
1163 public void CaseSensitivity ()
1165 Uri mailto = new Uri ("MAILTO:USER:PWD@GO-MONO.COM?SUBJECT=URI");
1166 AssertEquals ("#1", "mailto", mailto.Scheme);
1167 AssertEquals ("#2", "go-mono.com", mailto.Host);
1168 AssertEquals ("#3", "mailto:USER:PWD@go-mono.com?SUBJECT=URI", mailto.ToString ());
1170 Uri http = new Uri ("HTTP://GO-MONO.COM/INDEX.HTML");
1171 AssertEquals ("#4", "http", http.Scheme);
1172 AssertEquals ("#5", "go-mono.com", http.Host);
1173 AssertEquals ("#6", "http://go-mono.com/INDEX.HTML", http.ToString ());
1176 Uri ftp = new Uri ("FTP://[::ffFF:169.32.14.5]/");
1177 AssertEquals ("#7", "ftp", ftp.Scheme);
1178 AssertEquals ("#8", "[0000:0000:0000:0000:0000:FFFF:A920:0E05]", ftp.Host);
1179 AssertEquals ("#9", "ftp://[0000:0000:0000:0000:0000:FFFF:A920:0E05]/", ftp.ToString ());
1183 public void GetHashCodeTest ()
1185 Uri uri1 = new Uri ("http://www.contoso.com/index.htm#main");
1186 Uri uri2 = new Uri ("http://www.contoso.com/index.htm#fragment");
1187 AssertEquals ("#1", uri1.GetHashCode (), uri2.GetHashCode ());
1188 uri2 = new Uri ("http://www.contoso.com/index.htm?x=1");
1189 Assert ("#2", uri1.GetHashCode () != uri2.GetHashCode ());
1190 uri2 = new Uri ("http://www.contoso.com:80/index.htm");
1191 AssertEquals ("#3", uri1.GetHashCode (), uri2.GetHashCode ());
1192 uri2 = new Uri ("http://www.contoso.com:8080/index.htm");
1193 Assert ("#4", uri1.GetHashCode () != uri2.GetHashCode ());
1198 public void RelativeEqualsTest()
1200 Uri uri1 = new Uri ("foo/bar", UriKind.Relative);
1201 Uri uri2 = new Uri ("foo/bar", UriKind.Relative);
1202 Uri uri3 = new Uri ("bar/man", UriKind.Relative);
1203 Uri uri4 = new Uri ("BAR/MAN", UriKind.Relative);
1204 Assert ("#1a", uri1 == uri2);
1205 Assert ("#1b", uri1.Equals(uri2));
1206 Assert ("#2a", uri1 != uri3);
1207 Assert ("#2b", !uri1.Equals(uri3));
1208 Assert ("#3a", uri1 == uri2);
1209 Assert ("#3b", uri1.Equals(uri2));
1210 Assert ("#4a", uri1 != uri3);
1211 Assert ("#4b", !uri1.Equals(uri3));
1212 Assert ("#5a", uri3 != uri4);
1213 Assert ("#5b", !uri3.Equals(uri4));
1217 [ExpectedException(typeof(InvalidOperationException))]
1218 public void GetLeftPart_Partial1 ()
1220 Uri u = new Uri ("foo", UriKind.Relative);
1221 u.GetLeftPart (UriPartial.Scheme);
1224 [ExpectedException(typeof(InvalidOperationException))]
1226 public void GetLeftPart_Partial2 ()
1228 Uri u = new Uri ("foo", UriKind.Relative);
1229 u.GetLeftPart (UriPartial.Authority);
1232 [ExpectedException(typeof(InvalidOperationException))]
1234 public void GetLeftPart_Partial3 ()
1236 Uri u = new Uri ("foo", UriKind.Relative);
1237 u.GetLeftPart (UriPartial.Path);
1241 public void TestPartialToString ()
1243 AssertEquals ("#1", new Uri ("foo", UriKind.Relative).ToString (), "foo");
1244 AssertEquals ("#2", new Uri ("foo#aa", UriKind.Relative).ToString (), "foo#aa");
1245 AssertEquals ("#3", new Uri ("foo?aa", UriKind.Relative).ToString (), "foo?aa");
1246 AssertEquals ("#4", new Uri ("foo#dingus?aa", UriKind.Relative).ToString (), "foo#dingus?aa");
1247 AssertEquals ("#4", new Uri ("foo?dingus#aa", UriKind.Relative).ToString (), "foo?dingus#aa");
1251 public void RelativeGetHashCodeTest()
1253 Uri uri1 = new Uri ("foo/bar", UriKind.Relative);
1254 Uri uri2 = new Uri ("foo/bar", UriKind.Relative);
1255 Uri uri3 = new Uri ("bar/man", UriKind.Relative);
1256 AssertEquals ("#1", uri1.GetHashCode(), uri2.GetHashCode());
1257 Assert ("#2", uri1.GetHashCode() != uri3.GetHashCode());
1262 public void MakeRelative ()
1264 Uri uri1 = new Uri ("http://www.contoso.com/index.htm?x=2");
1265 Uri uri2 = new Uri ("http://www.contoso.com/foo/bar/index.htm#fragment");
1266 Uri uri3 = new Uri ("http://www.contoso.com/bar/foo/index.htm?y=1");
1267 Uri uri4 = new Uri ("http://www.contoso.com/bar/foo2/index.htm?x=0");
1268 Uri uri5 = new Uri ("https://www.contoso.com/bar/foo/index.htm?y=1");
1269 Uri uri6 = new Uri ("http://www.contoso2.com/bar/foo/index.htm?x=0");
1270 Uri uri7 = new Uri ("http://www.contoso2.com/bar/foo/foobar.htm?z=0&y=5");
1271 Uri uri8 = new Uri ("http://www.xxx.com/bar/foo/foobar.htm?z=0&y=5" + (char) 0xa9);
1273 AssertEquals ("#1", "foo/bar/index.htm", uri1.MakeRelative (uri2));
1274 AssertEquals ("#2", "../../index.htm", uri2.MakeRelative (uri1));
1276 AssertEquals ("#3", "../../bar/foo/index.htm", uri2.MakeRelative (uri3));
1277 AssertEquals ("#4", "../../foo/bar/index.htm", uri3.MakeRelative (uri2));
1279 AssertEquals ("#5", "../foo2/index.htm", uri3.MakeRelative (uri4));
1280 AssertEquals ("#6", "../foo/index.htm", uri4.MakeRelative (uri3));
1282 AssertEquals ("#7", "https://www.contoso.com/bar/foo/index.htm?y=1",
1283 uri4.MakeRelative (uri5));
1285 AssertEquals ("#8", "http://www.contoso2.com/bar/foo/index.htm?x=0",
1286 uri4.MakeRelative (uri6));
1288 AssertEquals ("#9", "", uri6.MakeRelative (uri6));
1289 AssertEquals ("#10", "foobar.htm", uri6.MakeRelative (uri7));
1291 Uri uri10 = new Uri ("mailto:xxx@xxx.com");
1292 Uri uri11 = new Uri ("mailto:xxx@xxx.com?subject=hola");
1293 AssertEquals ("#11", "", uri10.MakeRelative (uri11));
1295 Uri uri12 = new Uri ("mailto:xxx@mail.xxx.com?subject=hola");
1296 AssertEquals ("#12", "mailto:xxx@mail.xxx.com?subject=hola", uri10.MakeRelative (uri12));
1298 Uri uri13 = new Uri ("mailto:xxx@xxx.com/foo/bar");
1299 AssertEquals ("#13", "/foo/bar", uri10.MakeRelative (uri13));
1301 AssertEquals ("#14", "http://www.xxx.com/bar/foo/foobar.htm?z=0&y=5" + (char) 0xa9, uri1.MakeRelative (uri8));
1305 public void RelativeUri ()
1307 Uri u = new Uri("http://localhost/../../../a");
1309 AssertEquals ("http://localhost/a", u.ToString ());
1311 AssertEquals ("http://localhost/../../../a", u.ToString ());
1314 u = new Uri ("http://localhost/../c/b/../a");
1316 AssertEquals ("http://localhost/c/a", u.ToString ());
1318 AssertEquals ("http://localhost/../c/a", u.ToString ());
1323 public void RelativeUri2 ()
1325 AssertEquals ("#1", "hoge:ext", new Uri (new Uri ("hoge:foo:bar:baz"), "hoge:ext").ToString ());
1327 AssertEquals ("#2-w", "file:///d:/myhost/ext", new Uri (new Uri ("file:///c:/localhost/bar"), "file:///d:/myhost/ext").ToString ());
1328 AssertEquals ("#3-w", "file:///c:/localhost/myhost/ext", new Uri (new Uri ("file:///c:/localhost/bar"), "file:myhost/ext").ToString ());
1329 AssertEquals ("#4-w", "uuid:ext", new Uri (new Uri ("file:///c:/localhost/bar"), "uuid:ext").ToString ());
1330 AssertEquals ("#5-w", "file:///c:/localhost/ext", new Uri (new Uri ("file:///c:/localhost/bar"), "file:./ext").ToString ());
1332 AssertEquals ("#2-u", "file:///d/myhost/ext", new Uri (new Uri ("file:///c/localhost/bar"), "file:///d/myhost/ext").ToString ());
1333 AssertEquals ("#3-u", "file:///c/localhost/myhost/ext", new Uri (new Uri ("file:///c/localhost/bar"), "file:myhost/ext").ToString ());
1334 AssertEquals ("#4-u", "uuid:ext", new Uri (new Uri ("file:///c/localhost/bar"), "uuid:ext").ToString ());
1335 AssertEquals ("#5-u", "file:///c/localhost/ext", new Uri (new Uri ("file:///c/localhost/bar"), "file:./ext").ToString ());
1337 AssertEquals ("#6", "http://localhost/ext", new Uri (new Uri ("http://localhost/bar"), "http:./ext").ToString ());
1341 public void ToStringTest()
1343 Uri uri = new Uri ("dummy://xxx");
1344 AssertEquals ("#1", "dummy://xxx/", uri.ToString ());
1348 public void CheckSchemeName ()
1350 AssertEquals ("#01", false, Uri.CheckSchemeName (null));
1351 AssertEquals ("#02", false, Uri.CheckSchemeName (""));
1352 AssertEquals ("#03", true, Uri.CheckSchemeName ("http"));
1353 AssertEquals ("#04", true, Uri.CheckSchemeName ("http-"));
1354 AssertEquals ("#05", false, Uri.CheckSchemeName ("6http-"));
1355 AssertEquals ("#06", true, Uri.CheckSchemeName ("http6-"));
1356 AssertEquals ("#07", false, Uri.CheckSchemeName ("http6,"));
1357 AssertEquals ("#08", true, Uri.CheckSchemeName ("http6."));
1358 AssertEquals ("#09", false, Uri.CheckSchemeName ("+http"));
1359 AssertEquals ("#10", true, Uri.CheckSchemeName ("htt+p6"));
1360 // 0x00E1 -> ã
1362 Assert ("#11", !Uri.CheckSchemeName ("htt\u00E1+p6"));
1364 Assert ("#11", Uri.CheckSchemeName ("htt\u00E1+p6"));
1369 public void CheckSchemeName_FirstChar ()
1371 for (int i = 0; i < 256; i++) {
1372 string s = String.Format ("#{0}", i);
1374 bool b = Uri.CheckSchemeName (c.ToString ());
1376 bool valid = (((i >= 0x41) && (i <= 0x5A)) || ((i >= 0x61) && (i <= 0x7A)));
1377 AssertEquals (s, valid, b);
1379 AssertEquals (s, Char.IsLetter (c), b);
1385 public void CheckSchemeName_AnyOtherChar ()
1387 for (int i = 0; i < 256; i++) {
1388 string s = String.Format ("#{0}", i);
1390 string scheme = String.Format ("a+b-c.d{0}", c);
1391 bool b = Uri.CheckSchemeName (scheme);
1392 bool common = Char.IsDigit (c) || (c == '+') || (c == '-') || (c == '.');
1394 bool valid = (common || ((i >= 0x41) && (i <= 0x5A)) || ((i >= 0x61) && (i <= 0x7A)));
1395 AssertEquals (s, valid, b);
1397 AssertEquals (s, (Char.IsLetter (c) || common), b);
1403 [ExpectedException (typeof (UriFormatException))]
1404 public void NoHostname ()
1406 Uri uri = new Uri ("http://");
1411 // MS.NET 1.x throws an IndexOutOfRangeException
1412 [Category("NotDotNet")]
1414 public void NoHostname2 ()
1417 Uri uri = new Uri ("file://");
1418 AssertEquals ("#1", true, uri.IsFile);
1419 AssertEquals ("#2", false, uri.IsUnc);
1420 AssertEquals ("#3", "file", uri.Scheme);
1421 AssertEquals ("#4", "/", uri.LocalPath);
1422 AssertEquals ("#5", string.Empty, uri.Query);
1423 AssertEquals ("#6", "/", uri.AbsolutePath);
1424 AssertEquals ("#7", "file:///", uri.AbsoluteUri);
1425 AssertEquals ("#8", string.Empty, uri.Authority);
1426 AssertEquals ("#9", string.Empty, uri.Host);
1427 AssertEquals ("#10", UriHostNameType.Basic, uri.HostNameType);
1428 AssertEquals ("#11", string.Empty, uri.Fragment);
1429 AssertEquals ("#12", true, uri.IsDefaultPort);
1431 Assert ("#13", uri.IsLoopback);
1433 Assert ("#13", !uri.IsLoopback);
1435 AssertEquals ("#14", "/", uri.PathAndQuery);
1436 AssertEquals ("#15", false, uri.UserEscaped);
1437 AssertEquals ("#16", string.Empty, uri.UserInfo);
1438 AssertEquals ("#17", "file://", uri.GetLeftPart (UriPartial.Authority));
1439 AssertEquals ("#18", "file:///", uri.GetLeftPart (UriPartial.Path));
1440 AssertEquals ("#19", "file://", uri.GetLeftPart (UriPartial.Scheme));
1444 public void Segments1 ()
1446 Uri uri = new Uri ("http://localhost/");
1447 string [] segments = uri.Segments;
1448 AssertEquals ("#01", 1, segments.Length);
1449 AssertEquals ("#02", "/", segments [0]);
1453 public void Segments2 ()
1455 Uri uri = new Uri ("http://localhost/dir/dummypage.html");
1456 string [] segments = uri.Segments;
1457 AssertEquals ("#01", 3, segments.Length);
1458 AssertEquals ("#02", "/", segments [0]);
1459 AssertEquals ("#03", "dir/", segments [1]);
1460 AssertEquals ("#04", "dummypage.html", segments [2]);
1464 public void Segments3 ()
1466 Uri uri = new Uri ("http://localhost/dir/dummypage/");
1467 string [] segments = uri.Segments;
1468 AssertEquals ("#01", 3, segments.Length);
1469 AssertEquals ("#02", "/", segments [0]);
1470 AssertEquals ("#03", "dir/", segments [1]);
1471 AssertEquals ("#04", "dummypage/", segments [2]);
1476 [Category ("NotWorking")]
1478 public void Segments4 ()
1480 Uri uri = new Uri ("file:///c:/hello");
1481 string [] segments = uri.Segments;
1482 AssertEquals ("#01", 3, segments.Length);
1484 AssertEquals ("#02", "/", segments [0]);
1485 AssertEquals ("#03", "c:/", segments[1]);
1487 AssertEquals ("#02", "c:", segments [0]);
1488 AssertEquals ("#03", "/", segments [1]);
1490 AssertEquals ("#04", "hello", segments [2]);
1494 public void Segments5 ()
1496 Uri uri = new Uri ("http://www.xxx.com/bar/foo/foobar.htm?z=0&y=5" + (char) 0xa9);
1497 string [] segments = uri.Segments;
1498 AssertEquals ("#01", 4, segments.Length);
1499 AssertEquals ("#02", "/", segments [0]);
1500 AssertEquals ("#03", "bar/", segments [1]);
1501 AssertEquals ("#04", "foo/", segments [2]);
1502 AssertEquals ("#05", "foobar.htm", segments [3]);
1506 [ExpectedException (typeof (UriFormatException))]
1507 public void UriStartingWithColon()
1513 [ExpectedException (typeof (UriFormatException))]
1514 public void EmptyScheme ()
1520 // on .NET 2.0 a port number is limited to UInt16.MaxValue
1521 [ExpectedException (typeof (UriFormatException))]
1524 public void InvalidPort1 ()
1526 Uri uri = new Uri ("http://www.contoso.com:65536/foo/bar/");
1527 AssertEquals (65536, uri.Port);
1531 [ExpectedException (typeof (UriFormatException))]
1534 public void InvalidPort2 ()
1536 // UInt32.MaxValue gives port == -1 !!!
1537 Uri uri = new Uri ("http://www.contoso.com:4294967295/foo/bar/");
1538 AssertEquals (-1, uri.Port);
1542 [ExpectedException (typeof (UriFormatException))]
1545 public void InvalidPort3 ()
1547 // ((uint) Int32.MaxValue + (uint) 1) gives port == -2147483648 !!!
1548 Uri uri = new Uri ("http://www.contoso.com:2147483648/foo/bar/");
1549 AssertEquals (-2147483648, uri.Port);
1554 public void PortMax ()
1556 // on .NET 2.0 a port number is limited to UInt16.MaxValue
1557 Uri uri = new Uri ("http://www.contoso.com:65535/foo/bar/");
1558 AssertEquals (65535, uri.Port);
1564 public UriEx2 (string s) : base (s)
1568 protected override void Parse ()
1574 // Parse method is no longer used on .NET 2.0
1575 [ExpectedException (typeof (UriFormatException))]
1578 public void ParseOverride ()
1580 // If this does not override base's Parse(), it will
1581 // fail since this argument is not Absolute URI.
1582 UriEx2 ex = new UriEx2 ("readme.txt");
1586 public void UnixLocalPath ()
1588 // This works--the location is not part of the absolute path
1589 string path = "file://localhost/tmp/foo/bar";
1590 Uri fileUri = new Uri( path );
1591 AssertEquals (path, "/tmp/foo/bar", fileUri.AbsolutePath);
1593 // Empty path == localhost, in theory
1594 path = "file:///c:/tmp/foo/bar";
1595 fileUri = new Uri( path );
1596 AssertEquals (path, "c:/tmp/foo/bar", fileUri.AbsolutePath);
1601 public void TestEscapeDataString ()
1603 StringBuilder sb = new StringBuilder ();
1605 for (int i = 0; i < 128; i++)
1606 sb.Append ((char) i);
1608 AssertEquals ("%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",
1609 Uri.EscapeDataString (sb.ToString ()));
1611 AssertEquals ("%C3%A1", Uri.EscapeDataString ("á"));
1614 public void TestEscapeUriString ()
1616 StringBuilder sb = new StringBuilder ();
1617 for (int i = 0; i < 128; i++)
1618 sb.Append ((char) i);
1620 AssertEquals ("%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",
1621 Uri.EscapeUriString (sb.ToString ()));
1622 AssertEquals ("%C3%A1", Uri.EscapeDataString ("á"));
1626 // This test doesn't work on Linux, and arguably shouldn't work.
1627 // new Uri("file:///tmp/foo/bar").AbsolutePath returns "/tmp/foo/bar"
1628 // on Linux, as anyone sane would expect. It *doesn't* under .NET 1.1
1629 // Apparently "tmp" is supposed to be a hostname (!)...
1630 // Since "correct" behavior would confuse all Linux developers, and having
1631 // an expected failure is evil, we'll just ignore this for now...
1633 // Furthermore, Microsoft fixed this so it behaves sensibly in .NET 2.0.
1635 // You are surrounded by conditional-compilation code, all alike.
1636 // You are likely to be eaten by a Grue...
1639 [Category ("NotDotNet")]
1641 public void UnixLocalPath_WTF ()
1643 // Empty path == localhost, in theory
1644 string path = "file:///tmp/foo/bar";
1645 Uri fileUri = new Uri( path );
1647 AssertEquals (path, "/tmp/foo/bar", fileUri.AbsolutePath);
1649 // AssertEquals (path, "/foo/bar", fileUri.AbsolutePath);
1653 string path2 = "file:///foo%25bar";
1654 fileUri = new Uri (path2);
1655 AssertEquals (path2, "file:///foo%25bar", fileUri.ToString ());
1658 public static void Print (Uri uri)
1660 Console.WriteLine ("ToString: " + uri.ToString ());
1662 Console.WriteLine ("AbsolutePath: " + uri.AbsolutePath);
1663 Console.WriteLine ("AbsoluteUri: " + uri.AbsoluteUri);
1664 Console.WriteLine ("Authority: " + uri.Authority);
1665 Console.WriteLine ("Fragment: " + uri.Fragment);
1666 Console.WriteLine ("Host: " + uri.Host);
1667 Console.WriteLine ("HostNameType: " + uri.HostNameType);
1668 Console.WriteLine ("IsDefaultPort: " + uri.IsDefaultPort);
1669 Console.WriteLine ("IsFile: " + uri.IsFile);
1670 Console.WriteLine ("IsLoopback: " + uri.IsLoopback);
1671 Console.WriteLine ("IsUnc: " + uri.IsUnc);
1672 Console.WriteLine ("LocalPath: " + uri.LocalPath);
1673 Console.WriteLine ("PathAndQuery : " + uri.PathAndQuery);
1674 Console.WriteLine ("Port: " + uri.Port);
1675 Console.WriteLine ("Query: " + uri.Query);
1676 Console.WriteLine ("Scheme: " + uri.Scheme);
1677 Console.WriteLine ("UserEscaped: " + uri.UserEscaped);
1678 Console.WriteLine ("UserInfo: " + uri.UserInfo);
1680 Console.WriteLine ("Segments:");
1681 string [] segments = uri.Segments;
1682 if (segments == null)
1683 Console.WriteLine ("\tNo Segments");
1685 for (int i = 0; i < segments.Length; i++)
1686 Console.WriteLine ("\t" + segments[i]);
1687 Console.WriteLine ("");