* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System / Test / System / UriTest3.cs
index b649601cecf192573a79bb591919da231efc7506..a85037c848263e60bf8e31292ca3768fafdc0008 100644 (file)
@@ -50,7 +50,6 @@ namespace MonoTests.System {
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void Relative_UriKind_Relative ()
                {
                        Uri uri = new Uri (relative, UriKind.Relative);
@@ -69,7 +68,6 @@ namespace MonoTests.System {
 
                [Test]
                [ExpectedException (typeof (UriFormatException))]
-               [Category ("NotWorking")]
                public void Absolute_UriKind_Relative ()
                {
                        new Uri (absolute, UriKind.Relative);
@@ -169,6 +167,136 @@ namespace MonoTests.System {
                        Uri uri = null;
                        Uri.TryCreate (new Uri (absolute), (Uri) null, out uri);
                }
+
+               [Test]
+               public void IsWellFormedUriString_Null ()
+               {
+                       Assert.IsFalse (Uri.IsWellFormedUriString (null, UriKind.Absolute), "null");
+               }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void IsWellFormedUriString_Http ()
+               {
+                       Assert.IsFalse (Uri.IsWellFormedUriString ("http://www.go-mono.com/Main Page", UriKind.Absolute), "http/space");
+                       Assert.IsTrue (Uri.IsWellFormedUriString ("http://www.go-mono.com/Main%20Page", UriKind.Absolute), "http/%20");
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void IsWellFormedUriString_BadUriKind ()
+               {
+                       Uri.IsWellFormedUriString ("http://www.go-mono.com/Main Page", (UriKind)Int32.MinValue);
+               }
+
+               [Test]
+               public void Compare ()
+               {
+                       Uri u1 = null;
+                       Uri u2 = null;
+                       Assert.AreEqual (0, Uri.Compare (u1, u2, UriComponents.AbsoluteUri, UriFormat.UriEscaped, StringComparison.CurrentCulture), "null-null");
+
+                       u1 = new Uri ("http://www.go-mono.com/Main Page");
+                       u2 = new Uri ("http://www.go-mono.com/Main%20Page");
+                       Assert.AreEqual (0, Uri.Compare (u1, u2, UriComponents.AbsoluteUri, UriFormat.Unescaped, StringComparison.CurrentCulture), "http/space-http/%20-unescaped");
+                       Assert.AreEqual (0, Uri.Compare (u1, u2, UriComponents.AbsoluteUri, UriFormat.UriEscaped, StringComparison.CurrentCulture), "http/space-http/%20-escaped");
+                       Assert.AreEqual (0, Uri.Compare (u1, u2, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.CurrentCulture), "http/space-http/%20-safe");
+               }
+
+               [Test]
+               public void IsBaseOf ()
+               {
+                       Uri http = new Uri ("http://www.mono-project.com/Main_Page#FAQ?Edit");
+                       Assert.IsTrue (http.IsBaseOf (http), "http-http");
+
+                       Uri u = new Uri ("http://www.mono-project.com/Main_Page#FAQ");
+                       Assert.IsTrue (u.IsBaseOf (http), "http-1a");
+                       Assert.IsTrue (http.IsBaseOf (u), "http-1b");
+
+                       u = new Uri ("http://www.mono-project.com/Main_Page");
+                       Assert.IsTrue (u.IsBaseOf (http), "http-2a");
+                       Assert.IsTrue (http.IsBaseOf (u), "http-2b");
+
+                       u = new Uri ("http://www.mono-project.com/");
+                       Assert.IsTrue (u.IsBaseOf (http), "http-3a");
+                       Assert.IsTrue (http.IsBaseOf (u), "http-3b");
+
+                       u = new Uri ("http://www.mono-project.com/Main_Page/");
+                       Assert.IsFalse (u.IsBaseOf (http), "http-4a");
+                       Assert.IsTrue (http.IsBaseOf (u), "http-4b");
+
+                       // docs says the UserInfo isn't evaluated, but...
+                       u = new Uri ("http://username:password@www.mono-project.com/Main_Page");
+                       Assert.IsFalse (u.IsBaseOf (http), "http-5a");
+                       Assert.IsFalse (http.IsBaseOf (u), "http-5b");
+
+                       // scheme case sensitive ? no
+                       u = new Uri ("HTTP://www.mono-project.com/Main_Page");
+                       Assert.IsTrue (u.IsBaseOf (http), "http-6a");
+                       Assert.IsTrue (http.IsBaseOf (u), "http-6b");
+
+                       // host case sensitive ? no
+                       u = new Uri ("http://www.Mono-Project.com/Main_Page");
+                       Assert.IsTrue (u.IsBaseOf (http), "http-7a");
+                       Assert.IsTrue (http.IsBaseOf (u), "http-7b");
+
+                       // path case sensitive ? no
+                       u = new Uri ("http://www.Mono-Project.com/MAIN_Page");
+                       Assert.IsTrue (u.IsBaseOf (http), "http-8a");
+                       Assert.IsTrue (http.IsBaseOf (u), "http-8b");
+
+                       // different scheme
+                       u = new Uri ("ftp://www.mono-project.com/Main_Page");
+                       Assert.IsFalse (u.IsBaseOf (http), "http-9a");
+                       Assert.IsFalse (http.IsBaseOf (u), "http-9b");
+
+                       // different host
+                       u = new Uri ("http://www.go-mono.com/Main_Page");
+                       Assert.IsFalse (u.IsBaseOf (http), "http-10a");
+                       Assert.IsFalse (http.IsBaseOf (u), "http-10b");
+
+                       // different port
+                       u = new Uri ("http://www.mono-project.com:8080/");
+                       Assert.IsFalse (u.IsBaseOf (http), "http-11a");
+                       Assert.IsFalse (http.IsBaseOf (u), "http-11b");
+
+                       // specify default port
+                       u = new Uri ("http://www.mono-project.com:80/");
+                       Assert.IsTrue (u.IsBaseOf (http), "http-12a");
+                       Assert.IsTrue (http.IsBaseOf (u), "http-12b");
+               }
+
+               [Test]
+               [ExpectedException (typeof (NullReferenceException))]
+               public void IsBaseOf_Null ()
+               {
+                       Uri http = new Uri ("http://www.mono-project.com/Main_Page#FAQ?Edit");
+                       http.IsBaseOf (null);
+               }
+
+               [Test]
+               // LAMESPEC: see bug #78374.
+               public void OriginalStringRelative ()
+               {
+                       Uri k1 = new Uri ("http://www.mono-project.com");
+                       Uri k2 = new Uri (k1, "docs");
+                       Assert.AreEqual ("http://www.mono-project.com/docs", k2.OriginalString, "#1");
+
+                       Uri a = new Uri ("http://www.mono-project.com:808/foo");
+                       Uri b = new Uri (a, "../docs?queryyy#% %20%23%25bar");
+
+                       // it won't work.
+                       // Assert.AreEqual ("http://www.mono-project.com:808/docs?queryyy#% %20%23%25bar", b.OriginalString, "#2");
+
+                       Uri c = new Uri ("http://www.mono-project.com:909");
+                       Uri d = new Uri (c, "http://www.mono-project.com:606/docs");
+                       Assert.AreEqual ("http://www.mono-project.com:606/docs", d.OriginalString, "#3");
+
+                       Uri e = new Uri ("http://www.mono-project.com:303/foo");
+                       Uri f = new Uri (e, "?query");
+                       // it doesn't work. MS.NET also returns incorrect URI: ..303/?query
+                       // Assert.AreEqual ("http://www.mono-project.com:303/foo?query", e.OriginalString, "#4");
+               }
        }
 }