2008-12-09 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.XML / Test / System.Xml.XPath / XPathNavigatorTests.cs
index a5d1b19e428d25509604a7def6c92b2d094e33a3..4dfe25a39c5307f8454c8a9a6b94c67acd8e3d29 100644 (file)
@@ -427,6 +427,22 @@ namespace MonoTests.System.Xml
                        AssertEquals ("#2", true, nav.Matches ("text()"));
                }
 
+               [Test]
+               public void Bug456103 ()
+               {
+                       XmlDocument doc = new XmlDocument ();
+                       doc.LoadXml ("<root><X/></root>");
+
+                       XPathNavigator nav = doc.DocumentElement.CreateNavigator ();
+                       // ".//*" does not reproduce the bug.
+                       var i = nav.Select ("descendant::*");
+
+                       // without this call to get_Count() the bug does not reproduce.
+                       AssertEquals ("#1", 1, i.Count);
+
+                       Assert ("#2", i.MoveNext ());
+               }
+
 #if NET_2_0
                [Test]
                public void ValueAsBoolean ()
@@ -640,6 +656,54 @@ namespace MonoTests.System.Xml
                        AssertEquals ("1", nav.ValueAs (typeof (string), null));
                        AssertEquals (1, nav.ValueAs (typeof (int), null));
                }
+
+               [Test]
+               public void MoveToFollowingNodeTypeAll ()
+               {
+                       XmlDocument doc = new XmlDocument ();
+                       doc.LoadXml ("<root><child/><child2/></root>");
+                       XPathNavigator nav = doc.CreateNavigator ();
+                       Assert ("#1", nav.MoveToFollowing (XPathNodeType.All));
+                       Assert ("#2", nav.MoveToFollowing (XPathNodeType.All));
+                       AssertEquals ("#3", "child", nav.LocalName);
+                       Assert ("#4", nav.MoveToNext (XPathNodeType.All));
+                       AssertEquals ("#5", "child2", nav.LocalName);
+               }
+
+               [Test] // bug #324606.
+               public void XPathDocumentFromSubtreeNodes ()
+               {
+                       string xml = "<root><child1><nest1><nest2>hello!</nest2></nest1></child1><child2/><child3/></root>";
+                       XmlReader r = new XmlTextReader (new StringReader (xml));
+                       while (r.Read ()) {
+                               if (r.Name == "child1")
+                                       break;
+                       }
+                       XPathDocument d = new XPathDocument (r);
+                       XPathNavigator n = d.CreateNavigator ();
+                       string result = @"<child1>
+  <nest1>
+    <nest2>hello!</nest2>
+  </nest1>
+</child1>
+<child2 />
+<child3 />";
+                       AssertEquals (result, n.OuterXml.Replace ("\r\n", "\n"));
+               }
+
+               [Test] // bug #376191
+               public void InnerXmlOnRoot ()
+               {
+                       XmlDocument document = new XmlDocument ();
+                       document.LoadXml (@"<test>
+                       <node>z</node>
+                       <node>a</node>
+                       <node>b</node>
+                       <node>q</node>
+                       </test>");
+                       XPathNavigator navigator = document.CreateNavigator();
+                       AssertEquals (navigator.OuterXml, navigator.InnerXml);
+               }
 #endif
        }
 }