2005-11-25 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Fri, 25 Nov 2005 15:39:15 +0000 (15:39 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Fri, 25 Nov 2005 15:39:15 +0000 (15:39 -0000)
* UriBuilderCas.cs: Fixed line endings.
* UriBuilderTest.cs: Fixed line endings and added some comments about
some NotWorking stuff.
* UriParserTest.cs: Added test cases for default parser.
* UriTest3.cs: Added more test cases for new 2.0 features.

svn path=/trunk/mcs/; revision=53479

mcs/class/System/Test/System/ChangeLog
mcs/class/System/Test/System/UriBuilderCas.cs
mcs/class/System/Test/System/UriBuilderTest.cs
mcs/class/System/Test/System/UriParserTest.cs
mcs/class/System/Test/System/UriTest3.cs

index b5c16f2ea42215198467da9b7b89d56dab611929..51719d1ae52c6ed484d2fddb470c1d5df3ce5db7 100644 (file)
@@ -1,3 +1,11 @@
+2005-11-25  Sebastien Pouliot  <sebastien@ximian.com> 
+
+       * UriBuilderCas.cs: Fixed line endings.
+       * UriBuilderTest.cs: Fixed line endings and added some comments about 
+       some NotWorking stuff.
+       * UriParserTest.cs: Added test cases for default parser.
+       * UriTest3.cs: Added more test cases for new 2.0 features.
+
 2005-11-15  Sebastien Pouliot  <sebastien@ximian.com> 
  
        * UriTest2.cs: Added some new test cases for old (and now fixed) Uri
index 8290ac32079f6fd50c3d6faa02d9a55095e21ca7..18be4dd03bc7ceda716abdbf0af5d26e900834b7 100644 (file)
@@ -1,4 +1,4 @@
-//\r
+//
 // UriBuilderCas.cs - CAS unit tests for System
 //
 // Author:
 
 using NUnit.Framework;
 
-using System;\r
+using System;
 using System.Reflection;
 using System.Security;
-using System.Security.Permissions;\r
-using Microsoft.Win32;\r
-\r
-using MonoTests.System;\r
+using System.Security.Permissions;
+using Microsoft.Win32;
+
+using MonoTests.System;
+
+namespace MonoCasTests.System {
+
+       [TestFixture]
+       [Category ("CAS")]
+       public class UriBuilderCas {
+
+               [SetUp]
+               public virtual void SetUp ()
+               {
+                       if (!SecurityManager.SecurityEnabled)
+                               Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
+               }
+
+               [Test]
+               [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
+               public void UnitTestReuse ()
+               {
+                       UriBuilderTest unit = new UriBuilderTest ();
+                       unit.Constructor_Empty ();
+                       unit.Constructor_5 ();
+                       unit.Equals ();
+                       unit.EmptyQuery ();
+
+                       unit.GetReady ();
+                       unit.Path ();
+                       unit.Query ();
+                       unit.Fragment ();
+                       unit.Scheme ();
+
+                       unit.GetReady ();
+                       unit.ToStringTest ();
+#if NET_2_0
+                       unit.GetReady ();
+                       unit.DefaultPort ();
+#endif
+               }
 
-namespace MonoCasTests.System {\r
-\r
-       [TestFixture]\r
-       [Category ("CAS")]\r
-       public class UriBuilderCas {\r
-\r
-               [SetUp]\r
-               public virtual void SetUp ()\r
-               {\r
-                       if (!SecurityManager.SecurityEnabled)\r
-                               Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");\r
-               }\r
-\r
-               [Test]\r
-               [PermissionSet (SecurityAction.Deny, Unrestricted = true)]\r
-               public void UnitTestReuse ()\r
-               {\r
-                       UriBuilderTest unit = new UriBuilderTest ();\r
-                       unit.Constructor_Empty ();\r
-                       unit.Constructor_5 ();\r
-                       unit.Equals ();\r
-                       unit.EmptyQuery ();\r
-\r
-                       unit.GetReady ();\r
-                       unit.Path ();\r
-                       unit.Query ();\r
-                       unit.Fragment ();\r
-                       unit.Scheme ();\r
-\r
-                       unit.GetReady ();\r
-                       unit.ToStringTest ();\r
-#if NET_2_0\r
-                       unit.GetReady ();\r
-                       unit.DefaultPort ();\r
-#endif\r
-               }\r
-\r
-               [Test]\r
-               [PermissionSet (SecurityAction.Deny, Unrestricted = true)]\r
-               public void LinkDemand_Deny_Unrestricted ()\r
-               {\r
-                       ConstructorInfo ci = typeof (UriBuilder).GetConstructor (new Type [0]);\r
-                       Assert.IsNotNull (ci, "default .ctor");\r
-                       Assert.IsNotNull (ci.Invoke (null), "invoke");\r
-               }\r
-       }\r
-}\r
+               [Test]
+               [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
+               public void LinkDemand_Deny_Unrestricted ()
+               {
+                       ConstructorInfo ci = typeof (UriBuilder).GetConstructor (new Type [0]);
+                       Assert.IsNotNull (ci, "default .ctor");
+                       Assert.IsNotNull (ci.Invoke (null), "invoke");
+               }
+       }
+}
index 4ae713ecc53c730a1158c97133a723aeeb515701..4ca030fd0ec93668e20c6d683a816528325b0da7 100644 (file)
-//\r
-// UriBuilderTest.cs - NUnit Test Cases for System.UriBuilder\r
-//\r
-// Authors:\r
-//   Lawrence Pit (loz@cable.a2000.nl)\r
-//   Martin Willemoes Hansen (mwh@sysrq.dk)\r
-//\r
-// (C) 2003 Martin Willemoes Hansen\r
-//\r
-\r
-using NUnit.Framework;\r
-using System;\r
-\r
-namespace MonoTests.System\r
-{\r
-       [TestFixture]\r
-       public class UriBuilderTest : Assertion\r
-       {\r
-               private UriBuilder b, b2, b3;\r
-               \r
-               [SetUp]\r
-               public void GetReady()\r
-               {\r
-                       b = new UriBuilder ("http", "www.ximian.com", 80, "foo/bar/index.html");\r
-               }\r
-\r
-               [Test]\r
-               public void Constructor_Empty ()\r
-               {\r
-                       b = new UriBuilder ();\r
-                       AssertEquals ("#1", "http", b.Scheme);\r
-#if NET_2_0\r
-                       AssertEquals ("#2", "localhost", b.Host);\r
-#else\r
-                       AssertEquals ("#2", "loopback", b.Host);\r
-#endif\r
-                       AssertEquals ("#3", -1, b.Port);\r
-               }\r
-\r
-               [Test]\r
-               public void Constructor_5 ()\r
-               {\r
-                       b = new UriBuilder ("http", "www.ximian.com", 80, "foo/bar/index.html", "#extras");\r
-               }\r
-\r
-               [Test]\r
-               [ExpectedException (typeof (ArgumentException))]\r
-               public void Constructor_5_BadExtraValue ()\r
-               {\r
-                       b = new UriBuilder ("http", "www.ximian.com", 80, "foo/bar/index.html", "extras");\r
-                       // should have thrown an ArgumentException because extraValue must start with '?' or '#' character.\r
-               }\r
-               \r
-               [Test]\r
-               // This test does not make sense, will fix soon\r
-               [Category ("NotWorking")] // bug #75144\r
-               public void UserInfo ()\r
-               {                       \r
-                       b = new UriBuilder ("mailto://myname:mypwd@contoso.com?subject=hello");\r
-#if NET_2_0\r
-                       AssertEquals ("#1", String.Empty, b.UserName);\r
-                       AssertEquals ("#2", String.Empty, b.Password);\r
-#else\r
-                       AssertEquals ("#1", "myname", b.UserName);\r
-                       AssertEquals ("#2", "mypwd", b.Password);\r
-#endif                 \r
-                       b = new UriBuilder ("mailto", "contoso.com");\r
-                       b.UserName = "myname";\r
-                       b.Password = "mypwd";\r
-                       AssertEquals ("#3", "myname:mypwd", b.Uri.UserInfo);\r
-               }\r
-\r
-               [Test]\r
-               public void Path ()\r
-               {                       \r
-                       b.Path = ((char) 0xa9) + " 2002";\r
-                       AssertEquals ("#1", "%C2%A9%202002", b.Path);                   \r
-               }       \r
-               \r
-               [Test]\r
-               [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
-               public void BadPort1 ()\r
-               {\r
-                       b.Port = -12345;\r
-               }\r
-#if NET_2_0\r
-               [Test]\r
-               public void DefaultPort ()\r
-               {\r
-                       b.Port = -1;\r
-                       AssertEquals ("Port", -1, b.Port);\r
-                       AssertEquals ("ToString", "http://www.ximian.com/foo/bar/index.html", b.ToString ());\r
-               }\r
-#else\r
-               [Test]\r
-               [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
-               public void BadPort3 ()\r
-               {\r
-                       b.Port = -1;\r
-               }\r
-#endif\r
-               [Test]\r
-               public void Query ()\r
-               {\r
-                       b.Query = ((char) 0xa9) + " 2002";\r
-                       AssertEquals ("#1", "?\xA9 2002", b.Query);                     \r
-                       AssertEquals ("#2", String.Empty, b.Fragment);\r
-                       b.Query = "?test";\r
-                       AssertEquals ("#3", "??test", b.Query);\r
-                       b.Query = null;\r
-                       AssertEquals ("#4", String.Empty, b.Query);\r
-               }\r
-               \r
-               [Test]\r
-               public void Fragment ()\r
-               {\r
-                       b.Fragment = ((char) 0xa9) + " 2002";\r
-                       AssertEquals ("#1", "#\xA9 2002", b.Fragment);\r
-                       AssertEquals ("#2", String.Empty, b.Query);\r
-                       b.Fragment = "#test";\r
-                       AssertEquals ("#3", "##test", b.Fragment);\r
-                       b.Fragment = null;\r
-                       AssertEquals ("#4", String.Empty, b.Fragment);\r
-               }\r
-               \r
-               [Test]\r
-               public void Scheme ()\r
-               {\r
-                       b.Scheme = "http";\r
-                       AssertEquals ("#1", b.Scheme, "http");\r
-                       b.Scheme = "http:";\r
-                       AssertEquals ("#2", b.Scheme, "http");\r
-                       b.Scheme = "http://";\r
-                       AssertEquals ("#3", b.Scheme, "http");\r
-                       b.Scheme = "http://foo/bar";\r
-                       AssertEquals ("#4", b.Scheme, "http");\r
-                       b.Scheme = "mailto:";\r
-                       AssertEquals ("#5", b.Scheme, "mailto");\r
-                       b.Scheme = "unknown";\r
-                       AssertEquals ("#6", b.Scheme, "unknown");\r
-                       b.Scheme = "unknown://";\r
-                       AssertEquals ("#7", b.Scheme, "unknown");\r
-               }\r
-               \r
-               [Test]\r
-#if NET_2_0\r
-               [Category ("NotWorking")] // equals changed in 2.0\r
-#endif\r
-               public void Equals ()\r
-               {\r
-                       b = new UriBuilder ("http://", "www.ximian.com", 80, "foo/bar/index.html?item=1");\r
-                       b2 = new UriBuilder ("http", "www.ximian.com", 80, "/foo/bar/index.html", "?item=1");\r
-                       b3 = new UriBuilder (new Uri ("http://www.ximian.com/foo/bar/index.html?item=1"));\r
-#if NET_2_0\r
-                       Assert ("#1", !b.Equals (b2));\r
-                       Assert ("#2", !b.Uri.Equals (b2.Uri));\r
-                       Assert ("#3", !b.Equals (b3));\r
-                       Assert ("#5", !b3.Equals (b));\r
-#else\r
-                       Assert ("#1", b.Equals (b2));\r
-                       Assert ("#2", b.Uri.Equals (b2.Uri));\r
-                       Assert ("#3", b.Equals (b3));\r
-                       Assert ("#5", b3.Equals (b));\r
-#endif\r
-                       Assert ("#4", b2.Equals (b3));\r
-               }\r
-               \r
-               [Test]\r
-               public void ToStringTest ()\r
-               {\r
-                       AssertEquals ("ToString ()", "http://www.ximian.com:80/foo/bar/index.html", b.ToString ());\r
-                       AssertEquals ("Uri.ToString ()", "http://www.ximian.com/foo/bar/index.html", b.Uri.ToString ());\r
-               }\r
-\r
-               [Test]\r
-               public void EmptyQuery () // bug 57082\r
-               {\r
-                       b = new UriBuilder ("http", "www.ximian.com", 80, "/lalala/lelele.aspx", null);\r
-                       string noquery = "http://www.ximian.com/lalala/lelele.aspx";\r
-                       AssertEquals ("#01", b.Uri.ToString (), noquery);\r
-                       b = new UriBuilder ("http", "www.ximian.com", 80, "/lalala/lelele.aspx", "?");\r
-                       AssertEquals ("#02", b.Uri.ToString (), noquery);\r
-                       b = new UriBuilder ("http", "www.ximian.com", 80, "/lalala/lelele.aspx", "??");\r
-                       AssertEquals ("#03", b.Uri.ToString (), noquery + "??");\r
-                       b = new UriBuilder ("http", "www.ximian.com", 80, "/lalala/lelele.aspx", "?something");\r
-                       AssertEquals ("#04", b.Uri.ToString (), noquery + "?something");\r
-               }\r
-\r
-               [Test] // bug #76501\r
-               public void TestToString76501 ()\r
-               {\r
-                       UriBuilder ub = new UriBuilder (\r
-                               "http://mondomaine/trucmuche/login.aspx");\r
-                       ub.Query = ub.Query.TrimStart (new char [] {'?'}) + "&ticket=bla";\r
-                       Assert (ub.ToString ().IndexOf ("80//") < 0);\r
-               }\r
-       }\r
-}\r
-\r
+//
+// UriBuilderTest.cs - NUnit Test Cases for System.UriBuilder
+//
+// Authors:
+//   Lawrence Pit (loz@cable.a2000.nl)
+//   Martin Willemoes Hansen (mwh@sysrq.dk)
+//
+// (C) 2003 Martin Willemoes Hansen
+//
+
+using NUnit.Framework;
+using System;
+
+namespace MonoTests.System
+{
+       [TestFixture]
+       public class UriBuilderTest : Assertion
+       {
+               private UriBuilder b, b2, b3;
+               
+               [SetUp]
+               public void GetReady()
+               {
+                       b = new UriBuilder ("http", "www.ximian.com", 80, "foo/bar/index.html");
+               }
+
+               [Test]
+               public void Constructor_Empty ()
+               {
+                       b = new UriBuilder ();
+                       AssertEquals ("#1", "http", b.Scheme);
+#if NET_2_0
+                       AssertEquals ("#2", "localhost", b.Host);
+#else
+                       AssertEquals ("#2", "loopback", b.Host);
+#endif
+                       AssertEquals ("#3", -1, b.Port);
+               }
+
+               [Test]
+               public void Constructor_5 ()
+               {
+                       b = new UriBuilder ("http", "www.ximian.com", 80, "foo/bar/index.html", "#extras");
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void Constructor_5_BadExtraValue ()
+               {
+                       b = new UriBuilder ("http", "www.ximian.com", 80, "foo/bar/index.html", "extras");
+                       // should have thrown an ArgumentException because extraValue must start with '?' or '#' character.
+               }
+               
+               [Test]
+               // This test does not make sense, will fix soon
+               [Category ("NotWorking")] // bug #75144
+               public void UserInfo ()
+               {                       
+                       b = new UriBuilder ("mailto://myname:mypwd@contoso.com?subject=hello");
+#if NET_2_0
+                       AssertEquals ("#1", String.Empty, b.UserName);
+                       AssertEquals ("#2", String.Empty, b.Password);
+#else
+                       // NotWorking here for 1.x (bad behaviour in 1.x - may not be worth fixing)
+                       AssertEquals ("#1", "myname", b.UserName);
+                       AssertEquals ("#2", "mypwd", b.Password);
+#endif                 
+                       b = new UriBuilder ("mailto", "contoso.com");
+                       b.UserName = "myname";
+                       b.Password = "mypwd";
+                       // NotWorking here for 2.0 - worth fixing
+                       AssertEquals ("#3", "myname:mypwd", b.Uri.UserInfo);
+               }
+
+               [Test]
+               public void Path ()
+               {                       
+                       b.Path = ((char) 0xa9) + " 2002";
+                       AssertEquals ("#1", "%C2%A9%202002", b.Path);                   
+               }       
+               
+               [Test]
+               [ExpectedException (typeof (ArgumentOutOfRangeException))]
+               public void BadPort1 ()
+               {
+                       b.Port = -12345;
+               }
+#if NET_2_0
+               [Test]
+               public void DefaultPort ()
+               {
+                       b.Port = -1;
+                       AssertEquals ("Port", -1, b.Port);
+                       AssertEquals ("ToString", "http://www.ximian.com/foo/bar/index.html", b.ToString ());
+               }
+#else
+               [Test]
+               [ExpectedException (typeof (ArgumentOutOfRangeException))]
+               public void BadPort3 ()
+               {
+                       b.Port = -1;
+               }
+#endif
+               [Test]
+               public void Query ()
+               {
+                       b.Query = ((char) 0xa9) + " 2002";
+                       AssertEquals ("#1", "?\xA9 2002", b.Query);                     
+                       AssertEquals ("#2", String.Empty, b.Fragment);
+                       b.Query = "?test";
+                       AssertEquals ("#3", "??test", b.Query);
+                       b.Query = null;
+                       AssertEquals ("#4", String.Empty, b.Query);
+               }
+               
+               [Test]
+               public void Fragment ()
+               {
+                       b.Fragment = ((char) 0xa9) + " 2002";
+                       AssertEquals ("#1", "#\xA9 2002", b.Fragment);
+                       AssertEquals ("#2", String.Empty, b.Query);
+                       b.Fragment = "#test";
+                       AssertEquals ("#3", "##test", b.Fragment);
+                       b.Fragment = null;
+                       AssertEquals ("#4", String.Empty, b.Fragment);
+               }
+               
+               [Test]
+               public void Scheme ()
+               {
+                       b.Scheme = "http";
+                       AssertEquals ("#1", b.Scheme, "http");
+                       b.Scheme = "http:";
+                       AssertEquals ("#2", b.Scheme, "http");
+                       b.Scheme = "http://";
+                       AssertEquals ("#3", b.Scheme, "http");
+                       b.Scheme = "http://foo/bar";
+                       AssertEquals ("#4", b.Scheme, "http");
+                       b.Scheme = "mailto:";
+                       AssertEquals ("#5", b.Scheme, "mailto");
+                       b.Scheme = "unknown";
+                       AssertEquals ("#6", b.Scheme, "unknown");
+                       b.Scheme = "unknown://";
+                       AssertEquals ("#7", b.Scheme, "unknown");
+               }
+               
+               [Test]
+#if NET_2_0
+               [Category ("NotWorking")] // equals changed in 2.0
+#endif
+               public void Equals ()
+               {
+                       b = new UriBuilder ("http://", "www.ximian.com", 80, "foo/bar/index.html?item=1");
+                       b2 = new UriBuilder ("http", "www.ximian.com", 80, "/foo/bar/index.html", "?item=1");
+                       b3 = new UriBuilder (new Uri ("http://www.ximian.com/foo/bar/index.html?item=1"));
+#if NET_2_0
+                       Assert ("#1", !b.Equals (b2));
+                       Assert ("#2", !b.Uri.Equals (b2.Uri));
+                       Assert ("#3", !b.Equals (b3));
+                       Assert ("#5", !b3.Equals (b));
+#else
+                       Assert ("#1", b.Equals (b2));
+                       Assert ("#2", b.Uri.Equals (b2.Uri));
+                       Assert ("#3", b.Equals (b3));
+                       Assert ("#5", b3.Equals (b));
+#endif
+                       Assert ("#4", b2.Equals (b3));
+               }
+               
+               [Test]
+               public void ToStringTest ()
+               {
+                       AssertEquals ("ToString ()", "http://www.ximian.com:80/foo/bar/index.html", b.ToString ());
+                       AssertEquals ("Uri.ToString ()", "http://www.ximian.com/foo/bar/index.html", b.Uri.ToString ());
+               }
+
+               [Test]
+               public void EmptyQuery () // bug 57082
+               {
+                       b = new UriBuilder ("http", "www.ximian.com", 80, "/lalala/lelele.aspx", null);
+                       string noquery = "http://www.ximian.com/lalala/lelele.aspx";
+                       AssertEquals ("#01", b.Uri.ToString (), noquery);
+                       b = new UriBuilder ("http", "www.ximian.com", 80, "/lalala/lelele.aspx", "?");
+                       AssertEquals ("#02", b.Uri.ToString (), noquery);
+                       b = new UriBuilder ("http", "www.ximian.com", 80, "/lalala/lelele.aspx", "??");
+                       AssertEquals ("#03", b.Uri.ToString (), noquery + "??");
+                       b = new UriBuilder ("http", "www.ximian.com", 80, "/lalala/lelele.aspx", "?something");
+                       AssertEquals ("#04", b.Uri.ToString (), noquery + "?something");
+               }
+
+               [Test] // bug #76501
+               public void TestToString76501 ()
+               {
+                       UriBuilder ub = new UriBuilder (
+                               "http://mondomaine/trucmuche/login.aspx");
+                       ub.Query = ub.Query.TrimStart (new char [] {'?'}) + "&ticket=bla";
+                       Assert (ub.ToString ().IndexOf ("80//") < 0);
+               }
+       }
+}
+
index b525fc56249f83c4d0b4d585dbd7af7a407e0b78..8dba8d1cb9bf2eabf4e2fb51bbc3a063f0ab68c3 100644 (file)
@@ -35,7 +35,7 @@ using System.Text;
 
 namespace MonoTests.System {
 
-       public class UnitTestUriParser : UriParser {
+       public class UnitTestUriParser: UriParser {
 
                private string scheme_name;
                private int default_port;
@@ -51,16 +51,28 @@ namespace MonoTests.System {
                        throw_on_register = throwOnRegister;
                }
 
-               public string SchemeName {
-                       get { return scheme_name; }
+               public string SchemeName
+               {
+                       get
+                       {
+                               return scheme_name;
+                       }
                }
 
-               public int DefaultPort {
-                       get { return default_port; }
+               public int DefaultPort
+               {
+                       get
+                       {
+                               return default_port;
+                       }
                }
 
-               public bool OnNewUriCalled {
-                       get { return on_new_uri_called; }
+               public bool OnNewUriCalled
+               {
+                       get
+                       {
+                               return on_new_uri_called;
+                       }
                }
 
                public string _GetComponents (Uri uri, UriComponents components, UriFormat format)
@@ -117,33 +129,89 @@ namespace MonoTests.System {
        [TestFixture]
        public class UriParserTest {
 
+               private const string full_http = "http://www.mono-project.com/Main_Page#FAQ?Edit";
+
                private string prefix;
                private Uri http;
+               private Uri ftp;
 
                [TestFixtureSetUp]
                public void FixtureSetUp ()
                {
                        prefix = "unit.test.";
-                       http = new Uri ("http://www.mono-project.com");
+                       http = new Uri (full_http);
+                       ftp = new Uri ("ftp://username:password@ftp.go-mono.com:21/with some spaces/mono.tgz");
                }
 
-               public string Prefix {
-                       get { return prefix; }
-                       set { prefix = value; }
+               public string Prefix
+               {
+                       get
+                       {
+                               return prefix;
+                       }
+                       set
+                       {
+                               prefix = value;
+                       }
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void GetComponents ()
                {
                        UnitTestUriParser p = new UnitTestUriParser ();
-                       Assert.AreEqual ("www.mono-project.com", p._GetComponents (http, UriComponents.Host, UriFormat.SafeUnescaped), "http");
+                       Assert.AreEqual ("http", p._GetComponents (http, UriComponents.Scheme, UriFormat.SafeUnescaped), "http.Scheme");
+                       Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.UserInfo, UriFormat.SafeUnescaped), "http.UserInfo");
+                       Assert.AreEqual ("www.mono-project.com", p._GetComponents (http, UriComponents.Host, UriFormat.SafeUnescaped), "http.Host");
+                       Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.Port, UriFormat.SafeUnescaped), "http.Port");
+                       Assert.AreEqual ("Main_Page", p._GetComponents (http, UriComponents.Path, UriFormat.SafeUnescaped), "http.Path");
+                       Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.Query, UriFormat.SafeUnescaped), "http.Query");
+                       Assert.AreEqual ("FAQ?Edit", p._GetComponents (http, UriComponents.Fragment, UriFormat.SafeUnescaped), "http.Fragment");
+                       Assert.AreEqual ("80", p._GetComponents (http, UriComponents.StrongPort, UriFormat.SafeUnescaped), "http.StrongPort");
+                       Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.KeepDelimiter, UriFormat.SafeUnescaped), "http.KeepDelimiter");
+                       Assert.AreEqual ("www.mono-project.com:80", p._GetComponents (http, UriComponents.HostAndPort, UriFormat.SafeUnescaped), "http.HostAndPort");
+                       Assert.AreEqual ("www.mono-project.com:80", p._GetComponents (http, UriComponents.StrongAuthority, UriFormat.SafeUnescaped), "http.StrongAuthority");
+                       Assert.AreEqual (full_http, p._GetComponents (http, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped), "http.AbsoluteUri");
+                       Assert.AreEqual ("/Main_Page", p._GetComponents (http, UriComponents.PathAndQuery, UriFormat.SafeUnescaped), "http.PathAndQuery");
+                       Assert.AreEqual ("http://www.mono-project.com/Main_Page", p._GetComponents (http, UriComponents.HttpRequestUrl, UriFormat.SafeUnescaped), "http.HttpRequestUrl");
+                       Assert.AreEqual ("http://www.mono-project.com", p._GetComponents (http, UriComponents.SchemeAndServer, UriFormat.SafeUnescaped), "http.SchemeAndServer");
+                       Assert.AreEqual (full_http, p._GetComponents (http, UriComponents.SerializationInfoString, UriFormat.SafeUnescaped), "http.SerializationInfoString");
+                       // strange mixup
+                       Assert.AreEqual ("http://", p._GetComponents (http, UriComponents.Scheme | UriComponents.Port, UriFormat.SafeUnescaped), "http.Scheme+Port");
+                       Assert.AreEqual ("www.mono-project.com#FAQ?Edit", p._GetComponents (http, UriComponents.Host | UriComponents.Fragment, UriFormat.SafeUnescaped), "http.Scheme+Port");
+                       Assert.AreEqual ("/Main_Page", p._GetComponents (http, UriComponents.Port | UriComponents.Path, UriFormat.SafeUnescaped), "http.Scheme+Port");
+                       Assert.AreSame (p, p._OnNewUri (), "OnNewUri");
+               }
+
+               [Test]
+               public void GetComponents_Ftp ()
+               {
+                       UnitTestUriParser p = new UnitTestUriParser ();
+                       Assert.AreEqual ("ftp", p._GetComponents (ftp, UriComponents.Scheme, UriFormat.Unescaped), "ftp.Scheme");
+                       Assert.AreEqual ("username:password", p._GetComponents (ftp, UriComponents.UserInfo, UriFormat.Unescaped), "ftp.UserInfo");
+                       Assert.AreEqual ("ftp.go-mono.com", p._GetComponents (ftp, UriComponents.Host, UriFormat.Unescaped), "ftp.Host");
+                       Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.Port, UriFormat.Unescaped), "ftp.Port");
+                       Assert.AreEqual ("with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path, UriFormat.Unescaped), "ftp.Path");
+                       Assert.AreEqual ("with%20some%20spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path, UriFormat.UriEscaped), "ftp.Path-UriEscaped");
+                       Assert.AreEqual ("with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path, UriFormat.SafeUnescaped), "ftp.Path-SafeUnescaped");
+                       Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.Query, UriFormat.Unescaped), "ftp.Query");
+                       Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.Fragment, UriFormat.Unescaped), "ftp.Fragment");
+                       Assert.AreEqual ("21", p._GetComponents (ftp, UriComponents.StrongPort, UriFormat.Unescaped), "ftp.StrongPort");
+                       Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.KeepDelimiter, UriFormat.Unescaped), "http.KeepDelimiter");
+                       Assert.AreEqual ("ftp.go-mono.com:21", p._GetComponents (ftp, UriComponents.HostAndPort, UriFormat.Unescaped), "http.HostAndPort");
+                       Assert.AreEqual ("username:password@ftp.go-mono.com:21", p._GetComponents (ftp, UriComponents.StrongAuthority, UriFormat.Unescaped), "http.StrongAuthority");
+                       Assert.AreEqual ("ftp://username:password@ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.AbsoluteUri, UriFormat.Unescaped), "http.AbsoluteUri");
+                       Assert.AreEqual ("/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.PathAndQuery, UriFormat.Unescaped), "http.PathAndQuery");
+                       Assert.AreEqual ("ftp://ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.HttpRequestUrl, UriFormat.Unescaped), "http.HttpRequestUrl");
+                       Assert.AreEqual ("ftp://ftp.go-mono.com", p._GetComponents (ftp, UriComponents.SchemeAndServer, UriFormat.Unescaped), "http.SchemeAndServer");
+                       Assert.AreEqual ("ftp://username:password@ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.SerializationInfoString, UriFormat.Unescaped), "http.SerializationInfoString");
                        Assert.AreSame (p, p._OnNewUri (), "OnNewUri");
+                       // strange mixup
+                       Assert.AreEqual ("ftp://username:password@", p._GetComponents (ftp, UriComponents.Scheme | UriComponents.UserInfo, UriFormat.Unescaped), "ftp.Scheme+UserInfo");
+                       Assert.AreEqual (":21/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path | UriComponents.StrongPort, UriFormat.Unescaped), "ftp.Path+StrongPort");
                }
 
                [Test]
                [ExpectedException (typeof (NullReferenceException))]
-               [Category ("NotWorking")]
                public void GetComponents_Null ()
                {
                        UnitTestUriParser p = new UnitTestUriParser ();
@@ -151,11 +219,10 @@ namespace MonoTests.System {
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void GetComponents_BadUriComponents ()
                {
                        UnitTestUriParser p = new UnitTestUriParser ();
-                       Assert.AreEqual ("http://www.mono-project.com/", p._GetComponents (http, (UriComponents) Int32.MinValue, UriFormat.SafeUnescaped), "http");
+                       Assert.AreEqual (full_http, p._GetComponents (http, (UriComponents) Int32.MinValue, UriFormat.SafeUnescaped), "http");
                }
 
                [Test]
@@ -163,7 +230,7 @@ namespace MonoTests.System {
                public void GetComponents_BadUriFormat ()
                {
                        UnitTestUriParser p = new UnitTestUriParser ();
-                       p._GetComponents (http, UriComponents.Host, (UriFormat)Int32.MinValue);
+                       p._GetComponents (http, UriComponents.Host, (UriFormat) Int32.MinValue);
                }
 
                [Test]
@@ -187,16 +254,70 @@ namespace MonoTests.System {
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void IsBaseOf ()
                {
                        UnitTestUriParser p = new UnitTestUriParser ();
                        Assert.IsTrue (p._IsBaseOf (http, http), "http-http");
+
+                       Uri u = new Uri ("http://www.mono-project.com/Main_Page#FAQ");
+                       Assert.IsTrue (p._IsBaseOf (u, http), "http-1a");
+                       Assert.IsTrue (p._IsBaseOf (http, u), "http-1b");
+
+                       u = new Uri ("http://www.mono-project.com/Main_Page");
+                       Assert.IsTrue (p._IsBaseOf (u, http), "http-2a");
+                       Assert.IsTrue (p._IsBaseOf (http, u), "http-2b");
+
+                       u = new Uri ("http://www.mono-project.com/");
+                       Assert.IsTrue (p._IsBaseOf (u, http), "http-3a");
+                       Assert.IsTrue (p._IsBaseOf (http, u), "http-3b");
+
+                       u = new Uri ("http://www.mono-project.com/Main_Page/");
+                       Assert.IsFalse (p._IsBaseOf (u, http), "http-4a");
+                       Assert.IsTrue (p._IsBaseOf (http, 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 (p._IsBaseOf (u, http), "http-5a");
+                       Assert.IsFalse (p._IsBaseOf (http, u), "http-5b");
+
+                       // scheme case sensitive ? no
+                       u = new Uri ("HTTP://www.mono-project.com/Main_Page");
+                       Assert.IsTrue (p._IsBaseOf (u, http), "http-6a");
+                       Assert.IsTrue (p._IsBaseOf (http, u), "http-6b");
+
+                       // host case sensitive ? no
+                       u = new Uri ("http://www.Mono-Project.com/Main_Page");
+                       Assert.IsTrue (p._IsBaseOf (u, http), "http-7a");
+                       Assert.IsTrue (p._IsBaseOf (http, u), "http-7b");
+
+                       // path case sensitive ? no
+                       u = new Uri ("http://www.Mono-Project.com/MAIN_Page");
+                       Assert.IsTrue (p._IsBaseOf (u, http), "http-8a");
+                       Assert.IsTrue (p._IsBaseOf (http, u), "http-8b");
+
+                       // different scheme
+                       u = new Uri ("ftp://www.mono-project.com/Main_Page");
+                       Assert.IsFalse (p._IsBaseOf (u, http), "http-9a");
+                       Assert.IsFalse (p._IsBaseOf (http, u), "http-9b");
+
+                       // different host
+                       u = new Uri ("http://www.go-mono.com/Main_Page");
+                       Assert.IsFalse (p._IsBaseOf (u, http), "http-10a");
+                       Assert.IsFalse (p._IsBaseOf (http, u), "http-10b");
+
+                       // different port
+                       u = new Uri ("http://www.mono-project.com:8080/");
+                       Assert.IsFalse (p._IsBaseOf (u, http), "http-11a");
+                       Assert.IsFalse (p._IsBaseOf (http, u), "http-11b");
+
+                       // specify default port
+                       u = new Uri ("http://www.mono-project.com:80/");
+                       Assert.IsTrue (p._IsBaseOf (u, http), "http-12a");
+                       Assert.IsTrue (p._IsBaseOf (http, u), "http-12b");
                }
 
                [Test]
                [ExpectedException (typeof (NullReferenceException))]
-               [Category ("NotWorking")]
                public void IsBaseOf_UriNull ()
                {
                        UnitTestUriParser p = new UnitTestUriParser ();
@@ -205,7 +326,6 @@ namespace MonoTests.System {
 
                [Test]
                [ExpectedException (typeof (NullReferenceException))]
-               [Category ("NotWorking")]
                public void IsBaseOf_NullUri ()
                {
                        UnitTestUriParser p = new UnitTestUriParser ();
@@ -266,7 +386,7 @@ namespace MonoTests.System {
                {
                        UriFormatException error = null;
                        UnitTestUriParser p = new UnitTestUriParser ();
-                       Assert.AreEqual ("http://www.mono-project.com", p._Resolve (http, http, out error), "http-http");
+                       Assert.AreEqual (full_http, p._Resolve (http, http, out error), "http-http");
                }
 
                [Test]
@@ -275,7 +395,7 @@ namespace MonoTests.System {
                {
                        UriFormatException error = null;
                        UnitTestUriParser p = new UnitTestUriParser ();
-                       Assert.AreEqual ("http://www.mono-project.com", p._Resolve (http, null, out error), "http-http");
+                       Assert.AreEqual (full_http, p._Resolve (http, null, out error), "http-http");
                }
 
                [Test]
@@ -411,4 +531,4 @@ namespace MonoTests.System {
        }
 }
 
-#endif
\ No newline at end of file
+#endif
index b649601cecf192573a79bb591919da231efc7506..267730525dac222147fde4cd4cd1d6bd05e49962 100644 (file)
@@ -169,6 +169,112 @@ 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);
+               }
        }
 }