if (isWin32)
AssertEquals ("#n11", @"\\myserver\mydir\mysubdir\myfile.ext", uri.LocalPath);
else
- AssertEquals ("#n11", "//myserver/mydir/mysubdir/myfile.ext", uri.LocalPath);
+ // myserver never could be the part of Unix path.
+ AssertEquals ("#n11", "/mydir/mysubdir/myfile.ext", uri.LocalPath);
AssertEquals ("#n12", "/mydir/mysubdir/myfile.ext", uri.PathAndQuery);
AssertEquals ("#n13", -1, uri.Port);
AssertEquals ("#6", "?q=r;.%20a", u.Query);
}
+ [Test]
+ [ExpectedException (typeof (UriFormatException))]
+ public void InvalidScheme ()
+ {
+ new Uri ("_:/");
+ }
+
[Test]
public void ConstructorsRejectRelativePath ()
{
if (isWin32)
AssertEquals ("#3b win32", "\\\\cygwin\\tmp\\hello.txt", uri.LocalPath);
else
- AssertEquals ("#3b *nix", "/cygwin/tmp/hello.txt", uri.LocalPath);
+ AssertEquals ("#3b *nix", "/tmp/hello.txt", uri.LocalPath);
AssertEquals ("#3c", "file", uri.Scheme);
AssertEquals ("#3d", "cygwin", uri.Host);
AssertEquals ("#3e", "/tmp/hello.txt", uri.AbsolutePath);
if (isWin32)
AssertEquals ("#4b win32", "\\\\mymachine\\cygwin\\tmp\\hello.txt", uri.LocalPath);
else
- AssertEquals ("#4b *nix", "/mymachine/cygwin/tmp/hello.txt", uri.LocalPath);
+ AssertEquals ("#4b *nix", "/cygwin/tmp/hello.txt", uri.LocalPath);
AssertEquals ("#4c", "file", uri.Scheme);
AssertEquals ("#4d", "mymachine", uri.Host);
AssertEquals ("#4e", "/cygwin/tmp/hello.txt", uri.AbsolutePath);
AssertEquals ("#5c", "file", uri.Scheme);
AssertEquals ("#5d", "", uri.Host);
AssertEquals ("#5e", "c:/cygwin/tmp/hello.txt", uri.AbsolutePath);
-
+ // Hmm, they should be regarded just as a host name, since all URIs are base on absolute path.
uri = new Uri("file://one_file.txt");
AssertEquals("#6a", "file://one_file.txt", uri.ToString());
if (isWin32)
AssertEquals("#6b", "\\\\one_file.txt", uri.LocalPath);
else
- AssertEquals("#6b", "/one_file.txt", uri.LocalPath);
+ AssertEquals("#6b", "/", uri.LocalPath);
AssertEquals("#6c", "file", uri.Scheme);
AssertEquals("#6d", "one_file.txt", uri.Host);
AssertEquals("#6e", "", uri.AbsolutePath);
Assert ("#8", !uri.IsUnc);
}
- [Test, ExpectedException (typeof (UriFormatException))]
+ [Test]
+ [Category("NotDotNet")]
public void UncFail ()
{
Uri uri = new Uri ("/home/user/dir/filename.ext");
Assert ("#7", !uri.IsUnc);
}
- [Test]
- [Ignore ("Known to fail under MS runtime")]
- public void Unc2 ()
- {
- try {
- Uri uri = new Uri ("file:/filename.ext");
- Assert ("#4", uri.IsUnc);
- } catch (UriFormatException) {
- Fail ("#5: known to fail with ms.net");
- }
- }
-
[Test]
public void FromHex ()
{
AssertEquals ("#24", "http://www.contoso.com:8080", uri.GetLeftPart (UriPartial.Authority));
AssertEquals ("#25", "http://www.contoso.com:8080/index.htm", uri.GetLeftPart (UriPartial.Path));
}
-
+
[Test]
- [Ignore("Known to fail under MS runtime")]
- public void GetLeftPart2 ()
+ public void NewsDefaultPort ()
{
- try {
- Uri uri = new Uri ("file:/filename.ext");
- AssertEquals ("#16", "file://", uri.GetLeftPart (UriPartial.Scheme));
- AssertEquals ("#17", "", uri.GetLeftPart (UriPartial.Authority));
- AssertEquals ("#18", "file:///filename.ext", uri.GetLeftPart (UriPartial.Path));
- } catch (UriFormatException) {
- Fail ("#19: known to fail with ms.net (it's their own example!)");
- }
+ Uri uri = new Uri("news://localhost:119/");
+ AssertEquals ("#1", uri.IsDefaultPort, true);
+ }
+
+ [Test]
+ public void FragmentEscape ()
+ {
+ Uri u = new Uri("http://localhost/index.asp#main#start", false);
+ AssertEquals ("#1", u.Fragment, "#main%23start");
+
+ u = new Uri("http://localhost/index.asp#main#start", true);
+ AssertEquals ("#2", u.Fragment, "#main#start");
+
+ // The other code path uses a BaseUri
+
+ Uri b = new Uri ("http://www.gnome.org");
+ Uri n = new Uri (b, "blah#main#start");
+ AssertEquals ("#3", n.Fragment, "#main%23start");
+
+ n = new Uri (b, "blah#main#start", true);
+ AssertEquals ("#3", n.Fragment, "#main#start");
+ }
+
+ [Test]
+ [ExpectedException(typeof(UriFormatException))]
+ public void IncompleteSchemeDelimiter ()
+ {
+ new Uri ("file:/filename.ext");
}
[Test]
- public void CheckHostName ()
+ [Category("NotDotNet")]
+ public void CheckHostName1 ()
+ {
+ // reported to MSDN Product Feedback Center (FDBK28671)
+ 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"));
+ }
+
+ [Test]
+ public void CheckHostName2 ()
{
AssertEquals ("#1", UriHostNameType.Unknown, Uri.CheckHostName (null));
AssertEquals ("#2", UriHostNameType.Unknown, Uri.CheckHostName (""));
AssertEquals ("#8", UriHostNameType.Dns, Uri.CheckHostName ("9001.002.03.4"));
AssertEquals ("#9", UriHostNameType.Dns, Uri.CheckHostName ("www.contoso.com"));
AssertEquals ("#10", UriHostNameType.Unknown, Uri.CheckHostName (".www.contoso.com"));
- AssertEquals ("#11: known to fail with ms.net: this is not a valid domain address", UriHostNameType.Unknown, Uri.CheckHostName ("www.contoso.com."));
+ AssertEquals ("#11", UriHostNameType.Dns, Uri.CheckHostName ("www.contoso.com."));
AssertEquals ("#12", UriHostNameType.Dns, Uri.CheckHostName ("www.con-toso.com"));
AssertEquals ("#13", UriHostNameType.Dns, Uri.CheckHostName ("www.con_toso.com"));
AssertEquals ("#14", UriHostNameType.Unknown, Uri.CheckHostName ("www.con,toso.com"));
AssertEquals ("#28", UriHostNameType.IPv6, Uri.CheckHostName ("::ffFF:169.32.14.5"));
AssertEquals ("#29", UriHostNameType.IPv6, Uri.CheckHostName ("2001:03A0::/35"));
AssertEquals ("#30", UriHostNameType.IPv6, Uri.CheckHostName ("[2001:03A0::/35]"));
+ AssertEquals ("#33", UriHostNameType.IPv6, Uri.CheckHostName ("2001::03A0:1.2.3.4"));
AssertEquals ("#31", UriHostNameType.Unknown, Uri.CheckHostName ("2001::03A0::/35"));
AssertEquals ("#32", UriHostNameType.Unknown, Uri.CheckHostName ("2001:03A0::/35a"));
- AssertEquals ("#33 known to fail with ms.net: this is not a valid IPv6 address.", UriHostNameType.Unknown, Uri.CheckHostName ("2001::03A0:1.2.3.4"));
AssertEquals ("#34", UriHostNameType.Unknown, Uri.CheckHostName ("::ffff:123.256.155.43"));
AssertEquals ("#35", UriHostNameType.Unknown, Uri.CheckHostName (":127.0.0.1"));
- 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"));
AssertEquals ("#37", UriHostNameType.Unknown, Uri.CheckHostName ("::11:22:33:44:55:66:77:88"));
AssertEquals ("#38", UriHostNameType.Unknown, Uri.CheckHostName ("11:22:33:44:55:66:77:88::"));
AssertEquals ("#39", UriHostNameType.Unknown, Uri.CheckHostName ("11:22:33:44:55:66:77:88:"));
uri = new Uri("http://[0:0:0:0::127.0.0.1]:8080");
AssertEquals ("#9", true, uri.IsLoopback);
uri = new Uri("http://[0:0:0:0::127.11.22.33]:8080");
- AssertEquals ("#10: known to fail with ms.net", true, uri.IsLoopback);
+ AssertEquals ("#10", false, uri.IsLoopback);
uri = new Uri("http://[::ffff:127.11.22.33]:8080");
- AssertEquals ("#11: known to fail with ms.net", true, uri.IsLoopback);
+ AssertEquals ("#11", false, uri.IsLoopback);
uri = new Uri("http://[::ff00:7f11:2233]:8080");
AssertEquals ("#12", false, uri.IsLoopback);
uri = new Uri("http://[1:0:0:0::1]:8080");
}
[Test]
- public void Equals ()
+ public void Equals1 ()
{
Uri uri1 = new Uri ("http://www.contoso.com/index.htm#main");
Uri uri2 = new Uri ("http://www.contoso.com/index.htm#fragment");
Assert ("#1", uri1.Equals (uri2));
- uri2 = new Uri ("http://www.contoso.com/index.htm?x=1");
- Assert ("#2 known to fail with ms.net", !uri1.Equals (uri2));
Assert ("#3", !uri2.Equals ("http://www.contoso.com/index.html?x=1"));
- Assert ("#4: known to fail with ms.net", !uri1.Equals ("http://www.contoso.com:8080/index.htm?x=1"));
+ Assert ("#4", !uri1.Equals ("http://www.contoso.com:8080/index.htm?x=1"));
+ }
+
+ [Test]
+#if !NET_2_0
+ [Category("NotDotNet")]
+#endif
+ public void Equals2 ()
+ {
+ Uri uri1 = new Uri ("http://www.contoso.com/index.htm#main");
+ Uri uri2 = new Uri ("http://www.contoso.com/index.htm?x=1");
+ Assert ("#2 known to fail with ms.net 1.x", !uri1.Equals (uri2));
}
[Test]
}
[Test]
- [ExpectedException (typeof (UriFormatException))]
- [Ignore ("MS throws an IndexOutOfRangeException. Bug?")]
+#if !NET_2_0
+ // MS.NET 1.x throws an IndexOutOfRangeException
+ [Category("NotDotNet")]
+#endif
+ [Ignore("Bug #74144")]
public void NoHostname2 ()
{
Uri uri = new Uri ("file://");
+ AssertEquals ("#1", true, uri.IsFile);
+ AssertEquals ("#2", false, uri.IsUnc);
+ AssertEquals ("#3", "file", uri.Scheme);
+ AssertEquals ("#4", "/", uri.LocalPath);
+ AssertEquals ("#5", string.Empty, uri.Query);
+ AssertEquals ("#6", "/", uri.AbsolutePath);
+ AssertEquals ("#7", "file:///", uri.AbsoluteUri);
+ AssertEquals ("#8", string.Empty, uri.Authority);
+ AssertEquals ("#9", string.Empty, uri.Host);
+ AssertEquals ("#10", UriHostNameType.Basic, uri.HostNameType);
+ AssertEquals ("#11", string.Empty, uri.Fragment);
+ AssertEquals ("#12", true, uri.IsDefaultPort);
+ AssertEquals ("#13", true, uri.IsLoopback);
+ AssertEquals ("#14", "/", uri.PathAndQuery);
+ AssertEquals ("#15", false, uri.UserEscaped);
+ AssertEquals ("#16", string.Empty, uri.UserInfo);
+ AssertEquals ("#17", "file://", uri.GetLeftPart (UriPartial.Authority));
+ AssertEquals ("#18", "file:///", uri.GetLeftPart (UriPartial.Path));
+ AssertEquals ("#19", "file://", uri.GetLeftPart (UriPartial.Scheme));
}
[Test]
AssertEquals ("#05", "foobar.htm", segments [3]);
}
+ [Test]
+ [ExpectedException (typeof (UriFormatException))]
+ public void UriStartingWithColon()
+ {
+ new Uri("://");
+ }
+
[Test]
[ExpectedException (typeof (UriFormatException))]
public void EmptyScheme ()
UriEx2 ex = new UriEx2 ("readme.txt");
}
+ [Test]
+ public void UnixLocalPath ()
+ {
+ // This works--the location is not part of the absolute path
+ string path = "file://localhost/tmp/foo/bar";
+ Uri fileUri = new Uri( path );
+ AssertEquals (path, "/tmp/foo/bar", fileUri.AbsolutePath);
+
+ // Empty path == localhost, in theory
+ path = "file:///c:/tmp/foo/bar";
+ fileUri = new Uri( path );
+ AssertEquals (path, "c:/tmp/foo/bar", fileUri.AbsolutePath);
+ }
+
+ // This test doesn't work on Linux, and arguably shouldn't work.
+ // new Uri("file:///tmp/foo/bar").AbsolutePath returns "/tmp/foo/bar"
+ // on Linux, as anyone sane would expect. It *doesn't* under .NET 1.1
+ // Apparently "tmp" is supposed to be a hostname (!)...
+ // Since "correct" behavior would confuse all Linux developers, and having
+ // an expected failure is evil, we'll just ignore this for now...
+ //
+ // Furthermore, Microsoft fixed this so it behaves sensibly in .NET 2.0.
+ //
+ // You are surrounded by conditional-compilation code, all alike.
+ // You are likely to be eaten by a Grue...
+ [Test]
+#if ONLY_1_1
+ [Category ("NotWorking")]
+#endif
+ public void UnixLocalPath_WTF ()
+ {
+ // Empty path == localhost, in theory
+ string path = "file:///tmp/foo/bar";
+ Uri fileUri = new Uri( path );
+#if NET_2_0
+ AssertEquals (path, "/tmp/foo/bar", fileUri.AbsolutePath);
+#else
+ AssertEquals (path, "/foo/bar", fileUri.AbsolutePath);
+#endif
+ }
public static void Print (Uri uri)
{