Author: atsushi
Date: 2005-12-09 02:52:09 -0500 (Fri, 09 Dec 2005)
New Revision: 54152

Modified:
   trunk/mcs/class/System.XML/System.Xml/ChangeLog
   trunk/mcs/class/System.XML/System.Xml/XmlReader.cs
   trunk/mcs/class/System.XML/Test/System.Xml/ChangeLog
   trunk/mcs/class/System.XML/Test/System.Xml/XmlReaderCommonTests.cs
Log:
2005-12-09  Atsushi Enomoto <[EMAIL PROTECTED]>

        * XmlReader.cs : ReadToDescendant() should work when its ReadState is
          Initial.

        * XmlReaderCommonTests.cs : added tests for ReadToDescendant() and
          ReadToFollowing().



Modified: trunk/mcs/class/System.XML/System.Xml/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/System.Xml/ChangeLog     2005-12-09 06:43:34 UTC 
(rev 54151)
+++ trunk/mcs/class/System.XML/System.Xml/ChangeLog     2005-12-09 07:52:09 UTC 
(rev 54152)
@@ -1,5 +1,10 @@
 2005-12-09  Atsushi Enomoto <[EMAIL PROTECTED]>
 
+       * XmlReader.cs : ReadToDescendant() should work when its ReadState is
+         Initial.
+
+2005-12-09  Atsushi Enomoto <[EMAIL PROTECTED]>
+
        * XmlChar.cs : removed incorrect comment.
        * XmlReader.cs : Create() clones XmlReaderSettings (if supplied).
          For wrapped XmlReader, check ConformanceLevel to be consistent.

Modified: trunk/mcs/class/System.XML/System.Xml/XmlReader.cs
===================================================================
--- trunk/mcs/class/System.XML/System.Xml/XmlReader.cs  2005-12-09 06:43:34 UTC 
(rev 54151)
+++ trunk/mcs/class/System.XML/System.Xml/XmlReader.cs  2005-12-09 07:52:09 UTC 
(rev 54152)
@@ -813,9 +813,13 @@
                        get { return typeof (string); }
                }
 
-               [MonoTODO]
                public virtual bool ReadToDescendant (string name)
                {
+                       if (ReadState == ReadState.Initial) {
+                               MoveToContent ();
+                               if (IsStartElement (name))
+                                       return true;
+                       }
                        if (NodeType != XmlNodeType.Element || IsEmptyElement)
                                return false;
                        int depth = Depth;
@@ -825,9 +829,13 @@
                        return false;
                }
 
-               [MonoTODO]
                public virtual bool ReadToDescendant (string localName, string 
namespaceURI)
                {
+                       if (ReadState == ReadState.Initial) {
+                               MoveToContent ();
+                               if (IsStartElement (localName, namespaceURI))
+                                       return true;
+                       }
                        if (NodeType != XmlNodeType.Element || IsEmptyElement)
                                return false;
                        int depth = Depth;
@@ -837,7 +845,6 @@
                        return false;
                }
 
-               [MonoTODO]
                public virtual bool ReadToFollowing (string name)
                {
                        while (Read ())
@@ -846,7 +853,6 @@
                        return false;
                }
 
-               [MonoTODO]
                public virtual bool ReadToFollowing (string localName, string 
namespaceURI)
                {
                        while (Read ())

Modified: trunk/mcs/class/System.XML/Test/System.Xml/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/Test/System.Xml/ChangeLog        2005-12-09 
06:43:34 UTC (rev 54151)
+++ trunk/mcs/class/System.XML/Test/System.Xml/ChangeLog        2005-12-09 
07:52:09 UTC (rev 54152)
@@ -1,5 +1,10 @@
 2005-12-09  Atsushi Enomoto <[EMAIL PROTECTED]>
 
+       * XmlReaderCommonTests.cs : added tests for ReadToDescendant() and
+         ReadToFollowing().
+
+2005-12-09  Atsushi Enomoto <[EMAIL PROTECTED]>
+
        * XmlReaderSettingsTests.cs : added some ConformanceLevel tests.
          Added CreateClonesSettings() to make sure XmlReader.Create() clones
          XmlReaderSettings.

Modified: trunk/mcs/class/System.XML/Test/System.Xml/XmlReaderCommonTests.cs
===================================================================
--- trunk/mcs/class/System.XML/Test/System.Xml/XmlReaderCommonTests.cs  
2005-12-09 06:43:34 UTC (rev 54151)
+++ trunk/mcs/class/System.XML/Test/System.Xml/XmlReaderCommonTests.cs  
2005-12-09 07:52:09 UTC (rev 54152)
@@ -1465,6 +1465,62 @@
                        XmlReader xr = XmlReader.Create 
("Test/XmlFiles/nested-dtd-test.xml");
                        xr.Read ();
                }
+
+               [Test]
+               public void ReadToDescendant ()
+               {
+                       string xml = @"<root><foo/><bar/><foo> test text 
<bar><bar></bar></bar></foo></root>";
+                       RunTest (xml, new TestMethod (ReadToDescendant));
+               }
+
+               public void ReadToDescendant (XmlReader xmlReader)
+               {
+                       // move to first <bar/>
+                       Assert ("#1", xmlReader.ReadToDescendant ("bar"));
+                       // no children in <bar/>. It is empty.
+                       Assert ("#2", !xmlReader.ReadToDescendant ("bar"));
+                       AssertEquals ("#2-2", "bar", xmlReader.Name);
+
+                       // move to the second <foo>
+                       xmlReader.Read ();
+                       // move to the second <bar>
+                       Assert ("#3", xmlReader.ReadToDescendant ("bar"));
+                       // move to <bar> inside <bar>...</bar>
+                       Assert ("#4", xmlReader.ReadToDescendant ("bar"));
+                       // the next is EndElement of </bar>, so no move.
+                       Assert ("#5", !xmlReader.ReadToDescendant ("bar"));
+                       AssertEquals ("#5-2", XmlNodeType.EndElement, 
xmlReader.NodeType);
+               }
+
+               [Test]
+               public void ReadToDescepdant2 ()
+               {
+                       string xml = "<root/>";
+                       RunTest (xml, new TestMethod (ReadToDescendant2));
+               }
+
+               public void ReadToDescendant2 (XmlReader xmlReader)
+               {
+                       // make sure that it works when the reader is at 
Initial state.
+                       Assert (xmlReader.ReadToDescendant ("root"));
+               }
+
+               [Test]
+               public void ReadToFollowing ()
+               {
+                       string xml = 
@"<root><foo/><bar/><foo><bar><bar></bar></bar></foo></root>";
+                       RunTest (xml, new TestMethod (ReadToFollowing));
+               }
+
+               public void ReadToFollowing (XmlReader xmlReader)
+               {
+                       Assert ("#1", xmlReader.ReadToFollowing ("bar"));
+                       Assert ("#2", xmlReader.ReadToFollowing ("bar"));
+                       AssertEquals ("#2-2", 2, xmlReader.Depth);
+                       Assert ("#3", xmlReader.ReadToFollowing ("bar"));
+                       AssertEquals ("#3-2", 3, xmlReader.Depth);
+                       Assert ("#4", !xmlReader.ReadToFollowing ("bar"));
+               }
 #endif
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to