New tests, updates
[mono.git] / mcs / class / System.XML / Test / System.Xml.XPath / XPathNavigatorCommonTests.cs
index 924499a4bae24a633c4c4e3234a88d99bdb8ab26..08afa61e3139382507aea42b1001f890c2e90557 100644 (file)
@@ -41,6 +41,13 @@ namespace MonoTests.System.Xml
                        return xpathDocument.CreateNavigator ();
                }
 
+               private XPathNavigator GetXPathDocumentNavigator (XmlNode node, XmlSpace space)
+               {
+                       XmlNodeReader xr = new XmlNodeReader (node);
+                       xpathDocument = new XPathDocument (xr, space);
+                       return xpathDocument.CreateNavigator ();
+               }
+
                private void AssertNavigator (string label, XPathNavigator nav, XPathNodeType type, string prefix, string localName, string ns, string name, string value, bool hasAttributes, bool hasChildren, bool isEmptyElement)
                {
                        label += nav.GetType ();
@@ -444,6 +451,42 @@ namespace MonoTests.System.Xml
 </one>";
                        AssertEquals (ret, nav.OuterXml.Replace ("\r\n", "\n"));
                }
+
+               [Test]
+               public void ReadSubtreeLookupNamespace ()
+               {
+                       string xml = "<x:foo xmlns:x='urn:x'><bar>x:val</bar></x:foo>";
+                       var doc = new XmlDocument ();
+                       doc.LoadXml (xml);
+                       XPathNavigator nav = doc.LastChild.LastChild.CreateNavigator ();
+                       var xr = nav.ReadSubtree ();
+                       xr.MoveToContent ();
+                       xr.Read (); // should be at x:val
+                       AssertEquals ("urn:x", xr.LookupNamespace ("x"));
+               }
 #endif
+
+               [Test]
+               public void GetNamespaceConsistentTree ()
+               {
+                       document.PreserveWhitespace = true;
+
+                       string xml = "<x:root xmlns:x='urn:x'>  <x:foo xmlns='ns1'> <x:bar /> </x:foo>  <x:foo xmlns:y='ns2'> <x:bar /> </x:foo></x:root>";
+                       nav = GetXmlDocumentNavigator (xml);
+                       GetNamespaceConsistentTree (nav);
+                       nav = GetXPathDocumentNavigator (document, XmlSpace.Preserve);
+                       GetNamespaceConsistentTree (nav);
+               }
+
+               private void GetNamespaceConsistentTree (XPathNavigator nav)
+               {
+                       nav.MoveToFirstChild ();
+                       nav.MoveToFirstChild ();
+                       nav.MoveToNext ();
+                       AssertEquals ("#1." + nav.GetType (), "ns1", nav.GetNamespace (""));
+                       nav.MoveToNext ();
+                       nav.MoveToNext ();
+                       AssertEquals ("#2." + nav.GetType (), "", nav.GetNamespace (""));
+               }
        }
-}
+}
\ No newline at end of file