Merge pull request #1222 from LogosBible/uri-trycreate
[mono.git] / mcs / class / System / Test / System / UriTest3.cs
index 4667dff48c65dcf978987d360e8d6bac47c36cac..7ff8924d0daaed4c9091dbdcbba456fa6b3a0323 100644 (file)
@@ -181,6 +181,15 @@ namespace MonoTests.System
                        uri = new Uri ("http://dummy.com");
                        Assert.IsTrue (Uri.TryCreate (relative, UriKind.Relative, out uri), "relative-Relative");
                        Assert.AreEqual (relative, uri.OriginalString, "relative-RelativeOrAbsolute-OriginalString");
+
+                       Assert.IsTrue (Uri.TryCreate ("http://mono-project.com/☕", UriKind.Absolute, out uri), "highunicode-Absolute");
+                       Assert.AreEqual("http://mono-project.com/%E2%98%95", uri.AbsoluteUri, "highunicode-Absolute-AbsoluteUri");
+
+                       string mixedCaseUri = "http://mOnO-proJECT.com";
+                       uri = new Uri (mixedCaseUri);
+                       Uri uri2;
+                       Assert.IsTrue (Uri.TryCreate (mixedCaseUri, UriKind.Absolute, out uri2), "mixedcasehost-absolute");
+                       Assert.AreEqual (uri.AbsoluteUri, uri2.AbsoluteUri, "mixedcasehost-absoluteuri-absoluteuri");
                }
 
                [Test] // TryCreate (String, UriKind, Uri)
@@ -337,6 +346,13 @@ namespace MonoTests.System
                        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");
+                       Assert.AreEqual (1, Uri.Compare (u1, u2, UriComponents.AbsoluteUri, UriFormat.UriEscaped, StringComparison.CurrentCulture), "non-null - null");
+
+                       u1 = null;
+                       u2 = new Uri ("http://www.go-mono.com");
+                       Assert.AreEqual (-1, Uri.Compare (u1, u2, UriComponents.AbsoluteUri, UriFormat.UriEscaped, StringComparison.CurrentCulture), "null - non-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");
@@ -415,13 +431,8 @@ namespace MonoTests.System
                                http.IsBaseOf (null);
                                Assert.Fail ();
                        }
-#if NET_4_0
                        catch (ArgumentNullException) {
                        }
-#else
-                       catch (NullReferenceException) {
-                       }
-#endif
                }
 
                [Test] 
@@ -439,6 +450,9 @@ namespace MonoTests.System
                        Uri uri11 = new Uri ("mailto:xxx@xxx.com?subject=hola");
                        Uri uri12 = new Uri ("mailto:xxx@mail.xxx.com?subject=hola");
                        Uri uri13 = new Uri ("mailto:xxx@xxx.com/foo/bar");
+                       Uri uri14 = new Uri ("http://www.contoso.com/test1/");
+                       Uri uri15 = new Uri ("http://www.contoso.com/");
+                       Uri uri16 = new Uri ("http://www.contoso.com/test");
 
                        AssertRelativeUri ("foo/bar/index.htm#fragment", uri1, uri2, "#A");
                        AssertRelativeUri ("../../index.htm?x=2", uri2, uri1, "#B");
@@ -470,6 +484,61 @@ namespace MonoTests.System
                        Assert.IsTrue (relativeUri.IsAbsoluteUri, "#N1");
                        Assert.AreEqual (uri5.ToString (), relativeUri.ToString (), "#N2");
                        Assert.AreEqual (uri5.OriginalString, relativeUri.OriginalString, "#N3");
+
+                       AssertRelativeUri ("../", uri14, uri15, "#O");
+                       AssertRelativeUri ("./", uri16, uri15, "#P");
+
+                       Uri a1 = new Uri ("http://something/something2/test/");
+                       Uri a2 = new Uri ("http://something/something2/");
+                       Uri a3 = new Uri ("http://something/something2/test");
+                       Uri a4 = new Uri ("http://something/something2");
+
+                       AssertRelativeUri ("../", a1, a2, "Q1");
+                       AssertRelativeUri ("../../something2", a1, a4, "Q2");
+                       AssertRelativeUri ("./", a3, a2, "Q3");
+                       AssertRelativeUri ("../something2", a3, a4, "Q4");
+
+                       Uri b1 = new Uri ("http://something/test/");
+                       Uri b2 = new Uri ("http://something/");
+                       Uri b3 = new Uri ("http://something/test");
+                       Uri b4 = new Uri ("http://something");
+                       
+                       AssertRelativeUri ("../", b1, b2, "R1");
+                       AssertRelativeUri ("../", b1, b4, "R2");
+                       AssertRelativeUri ("./", b3, b2, "R3");
+                       AssertRelativeUri ("./", b3, b4, "R4");
+
+                       Uri c1 = new Uri ("C:\\something\\something2\\test\\");
+                       Uri c2 = new Uri ("C:\\something\\something2\\");
+                       Uri c3 = new Uri ("C:\\something\\something2\\test");
+                       Uri c4 = new Uri ("C:\\something\\something2");
+                       
+                       AssertRelativeUri ("../", c1, c2, "S1");
+                       AssertRelativeUri ("../../something2", c1, c4, "S2");
+                       AssertRelativeUri ("./", c3, c2, "S3");
+                       AssertRelativeUri ("../something2", c3, c4, "S4");
+
+                       Uri d1 = new Uri ("C:\\something\\test\\");
+                       Uri d2 = new Uri ("C:\\something\\");
+                       Uri d3 = new Uri ("C:\\something\\test");
+                       Uri d4 = new Uri ("C:\\something");
+                       
+                       AssertRelativeUri ("../", d1, d2, "T1");
+                       AssertRelativeUri ("../../something", d1, d4, "T2");
+                       AssertRelativeUri ("./", d3, d2, "T3");
+                       AssertRelativeUri ("../something", d3, d4, "T4");
+
+                       Uri e1 = new Uri ("C:\\something\\");
+                       Uri e2 = new Uri ("C:\\");
+                       Uri e3 = new Uri ("C:\\something");
+                       
+                       AssertRelativeUri ("../", e1, e2, "U1");
+                       AssertRelativeUri ("./", e3, e2, "U2");
+                       AssertRelativeUri ("", e1, e1, "U3");
+                       AssertRelativeUri ("", e3, e3, "U4");
+                       AssertRelativeUri ("../something", e1, e3, "U5");
+                       AssertRelativeUri ("something/", e3, e1, "U6");
+                       AssertRelativeUri ("something", e2, e3, "U7");
                }
 
                [Test]