Переглянути джерело

2007-08-01 Atsushi Enomoto <[email protected]>

	* Uri.cs, UriParser.cs : implemented InitializeAndValidate() and
	  IsWellFormedOriginalString().
	  IsWellFormedUriString() is already implemented.

	* UriParserTest.cs, UriTest3.cs, HttpStyleUriParserTest.cs :
	  for IsWellFormedOriginalString() and InitializeAndValidate(),
	  removed some NotWorking and added some more tests.


svn path=/trunk/mcs/; revision=83155
Atsushi Eno 18 роки тому
батько
коміт
a2dd5f1c19

+ 6 - 0
mcs/class/System/System/ChangeLog

@@ -1,3 +1,9 @@
+2007-08-01  Atsushi Enomoto  <[email protected]>
+
+	* Uri.cs, UriParser.cs : implemented InitializeAndValidate() and
+	  IsWellFormedOriginalString().
+	  IsWellFormedUriString() is already implemented.
+
 2007-07-06  Alan McGovern  <[email protected]>
 
 	* Uri.cs : The URI string should be whitespace trimmed before

+ 2 - 3
mcs/class/System/System/Uri.cs

@@ -1756,10 +1756,10 @@ namespace System {
 			return Parser.IsBaseOf (this, uri);
 		}
 
-		[MonoNotSupported ("IsWellFormedOriginalString is not supported")]
 		public bool IsWellFormedOriginalString ()
 		{
-			return Parser.IsWellFormedOriginalString (this);
+			// funny, but it does not use the Parser's IsWellFormedOriginalString().
+			return EscapeString (OriginalString) == OriginalString;
 		}
 
 		// static methods
@@ -1867,7 +1867,6 @@ namespace System {
 			return sb.ToString ();
 		}
 
-		[MonoNotSupported ("IsWellFormedUriString is not supported")]
 		public static bool IsWellFormedUriString (string uriString, UriKind uriKind)
 		{
 			if (uriString == null)

+ 9 - 4
mcs/class/System/System/UriParser.cs

@@ -118,10 +118,14 @@ namespace System {
 			return Format (sb.ToString (), format);
 		}
 
-		[MonoTODO]
 		protected internal virtual void InitializeAndValidate (Uri uri, out UriFormatException parsingError)
 		{
-			throw new NotImplementedException ();
+			// bad boy, it should check null arguments.
+			if (uri.Scheme != scheme_name)
+				// Here .NET seems to return "The Authority/Host could not be parsed", but it does not make sense.
+				parsingError = new UriFormatException ("The argument Uri's scheme does not match");
+			else
+				parsingError = null;
 		}
 
 		protected internal virtual bool IsBaseOf (Uri baseUri, Uri relativeUri)
@@ -135,12 +139,13 @@ namespace System {
 			return (String.Compare (base_string, 0, relativeUri.LocalPath, 0, last_slash, StringComparison.InvariantCultureIgnoreCase) == 0);
 		}
 
-		[MonoTODO]
 		protected internal virtual bool IsWellFormedOriginalString (Uri uri)
 		{
 			// well formed according to RFC2396 and RFC2732
 			// see Uri.IsWellFormedOriginalString for some docs
-			throw new NotImplementedException ();
+
+			// Though this class does not seem to do anything. Even null arguments aren't checked :/
+			return uri.IsWellFormedOriginalString ();
 		}
 
 		protected internal virtual UriParser OnNewUri ()

+ 6 - 0
mcs/class/System/Test/System/ChangeLog

@@ -1,3 +1,9 @@
+2007-08-01  Atsushi Enomoto  <[email protected]>
+
+	* UriParserTest.cs, UriTest3.cs, HttpStyleUriParserTest.cs :
+	  for IsWellFormedOriginalString() and InitializeAndValidate(),
+	  removed some NotWorking and added some more tests.
+
 2007-04-16  Atsushi Enomoto  <[email protected]>
 
 	* UriTest.cs : added relative .ctor() test where the relativeUris

+ 54 - 4
mcs/class/System/Test/System/HttpStyleUriParserTest.cs

@@ -43,16 +43,28 @@ namespace MonoTests.System {
 			get { return registered; }
 		}
 
+		public void _InitializeAndValidate (Uri uri, out UriFormatException parsingError)
+		{
+			InitializeAndValidate (uri, out parsingError);
+		}
+
+		public bool _IsWellFormedOriginalString (Uri uri)
+		{
+			// note that "this" version of this method is overriden.
+			return base.IsWellFormedOriginalString (uri);
+		}
+
 		protected override string GetComponents (Uri uri, UriComponents components, UriFormat format)
 		{
 			throw new UriFormatException ();
-			// return components.ToString ();
 		}
 
 		protected override void InitializeAndValidate (Uri uri, out UriFormatException parsingError)
 		{
-			throw new NotImplementedException ();
-			// base.InitializeAndValidate (uri, out parsingError);
+			if (uri.Scheme == "httpx")
+				parsingError = null;
+			else
+				base.InitializeAndValidate (uri, out parsingError);
 		}
 
 		protected override bool IsBaseOf (Uri baseUri, Uri relativeUri)
@@ -114,7 +126,6 @@ namespace MonoTests.System {
 		}
 
 		[Test]
-		[Category ("NotWorking")]
 		public void Httpx_Methods ()
 		{
 			Uri uri = new Uri ("httpx://www.mono-project.com/CAS");
@@ -131,6 +142,45 @@ namespace MonoTests.System {
 			Assert.AreEqual (-1, uri.Port, "Port");
 			// OnRegister cannot be used to change the registering informations
 		}
+
+		[Test]
+		public void InitializeAndValidate ()
+		{
+			Assert.IsTrue (UriParser.IsKnownScheme ("httpx"), "premise1");
+
+			Uri uri = new Uri ("httpx://localhost");
+			UriFormatException error;
+			parser._InitializeAndValidate (uri, out error);
+			Assert.AreEqual (null, error);
+		}
+
+		[Test]
+		public void InitializeAndValidate2 ()
+		{
+			Assert.IsTrue (UriParser.IsKnownScheme ("httpx"), "premise1");
+
+			Uri uri = new Uri ("file:///usr/local/bin");
+			// It results in UriFormatException since it tries
+			// to parse file URI with http Uri parser.
+			UriFormatException error;
+			parser._InitializeAndValidate (uri, out error);
+			Assert.IsNotNull (error);
+		}
+
+		[Test]
+		[ExpectedException (typeof (NullReferenceException))] // hmm, bad boy
+		public void IsWellFormedOriginalStringNull ()
+		{
+			Assert.IsTrue (parser._IsWellFormedOriginalString (null));
+		}
+
+		[Test]
+		public void IsWellFormedOriginalString ()
+		{
+			// hmm, it does not seem to check scheme.
+			Assert.IsTrue (parser._IsWellFormedOriginalString (new Uri ("file:///usr/local/src")));
+			Assert.IsFalse (parser._IsWellFormedOriginalString (new Uri ("file:///usr/local/src dst")));
+		}
 	}
 }
 

+ 23 - 2
mcs/class/System/Test/System/UriParserTest.cs

@@ -234,7 +234,6 @@ namespace MonoTests.System {
 		}
 
 		[Test]
-		[Category ("NotWorking")]
 		public void InitializeAndValidate ()
 		{
 			UriFormatException error = null;
@@ -245,7 +244,7 @@ namespace MonoTests.System {
 
 		[Test]
 		[ExpectedException (typeof (NullReferenceException))]
-		[Category ("NotWorking")]
+		// oh man, this is a bad boy.It should be ArgumentNullException.
 		public void InitializeAndValidate_Null ()
 		{
 			UriFormatException error = null;
@@ -380,6 +379,28 @@ namespace MonoTests.System {
 			Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
 		}
 
+		[Test]
+		[Category ("NotWorking")]
+		public void OnRegister2 ()
+		{
+			string scheme = prefix + "onregister2";
+			Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
+			UnitTestUriParser p = new UnitTestUriParser ();
+			try {
+				UriParser.Register (p, scheme, 2005);
+				Uri uri = new Uri (scheme + "://foobar:2005");
+				Assert.AreEqual (scheme, uri.Scheme, "uri-prefix");
+				Assert.AreEqual (2005, uri.Port, "uri-port");
+				
+				Assert.AreEqual ("//foobar:2005", uri.LocalPath, "uri-localpath");
+			}
+			catch (NotSupportedException) {
+				// special case / ordering
+			}
+			// if true then the registration is done before calling OnRegister
+			Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
+		}
+
 		[Test]
 		[Category ("NotWorking")]
 		public void Resolve ()

+ 0 - 1
mcs/class/System/Test/System/UriTest3.cs

@@ -175,7 +175,6 @@ namespace MonoTests.System {
 		}
 
 		[Test]
-		[Category ("NotWorking")]
 		public void IsWellFormedUriString_Http ()
 		{
 			Assert.IsFalse (Uri.IsWellFormedUriString ("http://www.go-mono.com/Main Page", UriKind.Absolute), "http/space");