Browse Source

2005-12-12 Atsushi Enomoto <[email protected]>

	* XPathNavigator.cs : removed some MonoTODOs.

	* XPathNavigatorTests.cs : added tests for ValueAsXxx properties.


svn path=/trunk/mcs/; revision=54233
Atsushi Eno 20 years ago
parent
commit
79479e6643

+ 4 - 0
mcs/class/System.XML/System.Xml.XPath/ChangeLog

@@ -1,3 +1,7 @@
+2005-12-12  Atsushi Enomoto <[email protected]>
+
+	* XPathNavigator.cs : removed some MonoTODOs.
+
 2005-12-08  Atsushi Enomoto <[email protected]>
 
 	* XPathDocument.cs : garbage cleanup.

+ 0 - 12
mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs

@@ -957,32 +957,26 @@ namespace System.Xml.XPath
 			get { throw new NotImplementedException (); }
 		}
 
-		[MonoTODO]
 		public override bool ValueAsBoolean {
 			get { return XQueryConvert.StringToBoolean (Value); }
 		}
 
-		[MonoTODO]
 		public override DateTime ValueAsDateTime {
 			get { return XmlConvert.ToDateTime (Value); }
 		}
 
-		[MonoTODO]
 		public override double ValueAsDouble {
 			get { return XQueryConvert.StringToDouble (Value); }
 		}
 
-		[MonoTODO]
 		public override int ValueAsInt {
 			get { return XQueryConvert.StringToInt (Value); }
 		}
 
-		[MonoTODO]
 		public override long ValueAsLong {
 			get { return XQueryConvert.StringToInteger (Value); }
 		}
 
-		[MonoTODO]
 		public override Type ValueType {
 			get {
 				return SchemaInfo != null &&
@@ -1002,12 +996,6 @@ namespace System.Xml.XPath
 			}
 		}
 
-
-
-
-
-
-
 		private XmlReader CreateFragmentReader (string fragment)
 		{
 			return new XmlTextReader (fragment, XmlNodeType.Element, new XmlParserContext (NameTable, null, null, XmlSpace.None));

+ 4 - 0
mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog

@@ -1,3 +1,7 @@
+2005-12-12  Atsushi Enomoto <[email protected]>
+
+	* XPathNavigatorTests.cs : added tests for ValueAsXxx properties.
+
 2005-10-23  Atsushi Enomoto <[email protected]>
 
 	* XPathNavigatorCommonTests.cs, XPathNavigatorTests.cs,

+ 130 - 0
mcs/class/System.XML/Test/System.Xml.XPath/XPathNavigatorTests.cs

@@ -283,5 +283,135 @@ namespace MonoTests.System.Xml
 			AssertEquals ("#2", XPathNodeType.SignificantWhitespace,
 				nav.NodeType);
 		}
+
+#if NET_2_0
+		[Test]
+		public void ValueAsBoolean ()
+		{
+			string xml = "<root>1</root>";
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml (xml);
+			XPathNavigator nav = doc.CreateNavigator ();
+			nav.MoveToFirstChild ();
+			AssertEquals ("#1", true, nav.ValueAsBoolean);
+			nav.MoveToFirstChild ();
+			AssertEquals ("#2", true, nav.ValueAsBoolean);
+		}
+
+		[Test]
+		[ExpectedException (typeof (FormatException))]
+		public void ValueAsBooleanFail ()
+		{
+			string xml = "<root>1.0</root>";
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml (xml);
+			XPathNavigator nav = doc.CreateNavigator ();
+			nav.MoveToFirstChild ();
+			bool i = nav.ValueAsBoolean;
+		}
+
+		[Test]
+		public void ValueAsDateTime ()
+		{
+			DateTime time = new DateTime (2005, 12, 13);
+			string xml = "<root>2005-12-13</root>";
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml (xml);
+			XPathNavigator nav = doc.CreateNavigator ();
+			nav.MoveToFirstChild ();
+			AssertEquals ("#1", time, nav.ValueAsDateTime);
+			nav.MoveToFirstChild ();
+			AssertEquals ("#2", time, nav.ValueAsDateTime);
+		}
+
+		[Test]
+		[ExpectedException (typeof (FormatException))]
+		public void ValueAsDateTimeFail ()
+		{
+			string xml = "<root>dating time</root>";
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml (xml);
+			XPathNavigator nav = doc.CreateNavigator ();
+			nav.MoveToFirstChild ();
+			DateTime time = nav.ValueAsDateTime;
+		}
+
+		[Test]
+		public void ValueAsDouble ()
+		{
+			string xml = "<root>3.14159265359</root>";
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml (xml);
+			XPathNavigator nav = doc.CreateNavigator ();
+			nav.MoveToFirstChild ();
+			AssertEquals ("#1", 3.14159265359, nav.ValueAsDouble);
+			nav.MoveToFirstChild ();
+			AssertEquals ("#2", 3.14159265359, nav.ValueAsDouble);
+		}
+
+		[Test]
+		[ExpectedException (typeof (FormatException))]
+		public void ValueAsDoubleFail ()
+		{
+			string xml = "<root>Double Dealer</root>";
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml (xml);
+			XPathNavigator nav = doc.CreateNavigator ();
+			nav.MoveToFirstChild ();
+			Double dealer = nav.ValueAsDouble;
+		}
+
+		[Test]
+		public void ValueAsInt ()
+		{
+			string xml = "<root>1</root>";
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml (xml);
+			XPathNavigator nav = doc.CreateNavigator ();
+			nav.MoveToFirstChild ();
+			AssertEquals ("#1", 1, nav.ValueAsInt);
+			nav.MoveToFirstChild ();
+			AssertEquals ("#2", 1, nav.ValueAsInt);
+		}
+
+		[Test]
+		// Here, it seems to be using XQueryConvert (whatever was called)
+		[ExpectedException (typeof (FormatException))]
+		public void ValueAsIntFail ()
+		{
+			string xml = "<root>1.0</root>";
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml (xml);
+			XPathNavigator nav = doc.CreateNavigator ();
+			nav.MoveToFirstChild ();
+			int i = nav.ValueAsInt;
+		}
+
+		[Test]
+		public void ValueAsLong ()
+		{
+			string xml = "<root>10000000000000000</root>";
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml (xml);
+			XPathNavigator nav = doc.CreateNavigator ();
+			nav.MoveToFirstChild ();
+			AssertEquals ("#1", 10000000000000000, nav.ValueAsLong);
+			nav.MoveToFirstChild ();
+			AssertEquals ("#2", 10000000000000000, nav.ValueAsLong);
+		}
+
+		[Test]
+		// Here, it seems to be using XQueryConvert (whatever was called)
+		[ExpectedException (typeof (FormatException))]
+		public void ValueAsLongFail ()
+		{
+			string xml = "<root>0x10000000000000000</root>";
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml (xml);
+			XPathNavigator nav = doc.CreateNavigator ();
+			nav.MoveToFirstChild ();
+			long l = nav.ValueAsLong;
+		}
+#endif
 	}
 }