Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAtsushi Eno <atsushieno@gmail.com>2005-12-13 15:09:02 +0300
committerAtsushi Eno <atsushieno@gmail.com>2005-12-13 15:09:02 +0300
commit9af8eedec3d7b6e6a0ec30f136bf08542eb883ab (patch)
tree1c08150ef7ecd33ae13ed8095390c3b43336a585 /mcs/class/System.XML
parentd3f0d5ba2845546e61363264656b59eece93f7b8 (diff)
2005-12-13 Atsushi Enomoto <atsushi@ximian.com>
* XPathNavigator.cs : ReplaceSelf() should allow document fragment. Moved implementation to XPathEditableDocument. * XPathEditableDocument.cs : implement ReplaceSelf() here. * System.Xml_test.dll.sources: Added XmlAssert.cs. * XmlAssert.cs : new file. * XPathEditableNavigatorTests.cs : added tests that passes empty string to editor methods. Added tests for ReplaceSelf(). svn path=/trunk/mcs/; revision=54278
Diffstat (limited to 'mcs/class/System.XML')
-rw-r--r--mcs/class/System.XML/ChangeLog4
-rw-r--r--mcs/class/System.XML/Mono.Xml.XPath/ChangeLog4
-rw-r--r--mcs/class/System.XML/Mono.Xml.XPath/XPathEditableDocument.cs42
-rw-r--r--mcs/class/System.XML/System.Xml.XPath/ChangeLog5
-rw-r--r--mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs8
-rw-r--r--mcs/class/System.XML/System.Xml_test.dll.sources1
-rw-r--r--mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog5
-rw-r--r--mcs/class/System.XML/Test/System.Xml.XPath/XPathEditableNavigatorTests.cs158
-rw-r--r--mcs/class/System.XML/Test/System.Xml/ChangeLog4
-rw-r--r--mcs/class/System.XML/Test/System.Xml/XmlAssert.cs106
10 files changed, 331 insertions, 6 deletions
diff --git a/mcs/class/System.XML/ChangeLog b/mcs/class/System.XML/ChangeLog
index 094edd3e4bb..f3070f79e1a 100644
--- a/mcs/class/System.XML/ChangeLog
+++ b/mcs/class/System.XML/ChangeLog
@@ -1,5 +1,9 @@
2005-12-13 Atsushi Enomoto <atsushi@ximian.com>
+ * System.Xml_test.dll.sources: Added XmlAssert.cs.
+
+2005-12-13 Atsushi Enomoto <atsushi@ximian.com>
+
* System.Xml_test.dll.sources: Added XPathEditableNavigatorTests.cs.
2005-12-08 Andrew Skiba <andrews@mainsoft.com>
diff --git a/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog b/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog
index 09280a3c2c4..279c95f0f78 100644
--- a/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog
+++ b/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog
@@ -1,5 +1,9 @@
2005-12-13 Atsushi Enomoto <atsushi@ximian.com>
+ * XPathEditableDocument.cs : implement ReplaceSelf() here.
+
+2005-12-13 Atsushi Enomoto <atsushi@ximian.com>
+
* XPathEditableDocument.cs :
- Now it does not append "written" nodes until Close() is invoked.
- Use XmlDocumentFragment to store incomplete tree fragment.
diff --git a/mcs/class/System.XML/Mono.Xml.XPath/XPathEditableDocument.cs b/mcs/class/System.XML/Mono.Xml.XPath/XPathEditableDocument.cs
index 0146a0724ed..7665b090a91 100644
--- a/mcs/class/System.XML/Mono.Xml.XPath/XPathEditableDocument.cs
+++ b/mcs/class/System.XML/Mono.Xml.XPath/XPathEditableDocument.cs
@@ -656,10 +656,50 @@ namespace Mono.Xml.XPath
if (!navigator.MoveToNext ())
navigator.MoveToParent ();
if (n.ParentNode == null)
- throw new InvalidOperationException ("This not cannot be removed since it has no parent.");
+ throw new InvalidOperationException ("This node cannot be removed since it has no parent.");
n.ParentNode.RemoveChild (n);
}
+ public override void ReplaceSelf (XmlReader reader)
+ {
+ XmlNode n = ((IHasXmlNode) navigator).GetNode ();
+ XmlNode p = n.ParentNode;
+ if (p == null)
+ throw new InvalidOperationException ("This node cannot be removed since it has no parent.");
+
+ bool movenext = false;
+ if (!MoveToPrevious ())
+ MoveToParent ();
+ else
+ movenext = true;
+
+ XmlDocument doc = p.NodeType == XmlNodeType.Document ?
+ p as XmlDocument : p.OwnerDocument;
+ bool error = false;
+ if (reader.ReadState == ReadState.Initial) {
+ reader.Read ();
+ if (reader.EOF)
+ error = true;
+ else
+ while (!reader.EOF)
+ p.AppendChild (doc.ReadNode (reader));
+ } else {
+ if (reader.EOF)
+ error = true;
+ else
+ p.AppendChild (doc.ReadNode (reader));
+ }
+ if (error)
+ throw new InvalidOperationException ("Content is required in argument XmlReader to replace current node.");
+
+ p.RemoveChild (n);
+
+ if (movenext)
+ MoveToNext ();
+ else
+ MoveToFirstChild ();
+ }
+
public override void SetValue (string value)
{
XmlNode n = ((IHasXmlNode) navigator).GetNode ();
diff --git a/mcs/class/System.XML/System.Xml.XPath/ChangeLog b/mcs/class/System.XML/System.Xml.XPath/ChangeLog
index a28c683ca28..c640d57f1a2 100644
--- a/mcs/class/System.XML/System.Xml.XPath/ChangeLog
+++ b/mcs/class/System.XML/System.Xml.XPath/ChangeLog
@@ -1,5 +1,10 @@
2005-12-13 Atsushi Enomoto <atsushi@ximian.com>
+ * XPathNavigator.cs : ReplaceSelf() should allow document fragment.
+ Moved implementation to XPathEditableDocument.
+
+2005-12-13 Atsushi Enomoto <atsushi@ximian.com>
+
* XPathNavigator.cs : PrependChild() should use AppendChild() when
there is no child.
diff --git a/mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs b/mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs
index e32ad8fe78c..85a6f781158 100644
--- a/mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs
+++ b/mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs
@@ -1185,17 +1185,15 @@ namespace System.Xml.XPath
}
}
- [MonoTODO]
public virtual void ReplaceSelf (string xmlFragment)
{
- ReplaceSelf (XmlReader.Create (new StringReader (xmlFragment)));
+ ReplaceSelf (CreateFragmentReader (xmlFragment));
}
- [MonoTODO]
+ // must override it.
public virtual void ReplaceSelf (XmlReader reader)
{
- InsertBefore (reader);
- DeleteSelf ();
+ throw new NotSupportedException ();
}
[MonoTODO]
diff --git a/mcs/class/System.XML/System.Xml_test.dll.sources b/mcs/class/System.XML/System.Xml_test.dll.sources
index 56254ef1e57..2298eed97f4 100644
--- a/mcs/class/System.XML/System.Xml_test.dll.sources
+++ b/mcs/class/System.XML/System.Xml_test.dll.sources
@@ -1,4 +1,5 @@
System.Xml/NameTableTests.cs
+System.Xml/XmlAssert.cs
System.Xml/XmlAttributeCollectionTests.cs
System.Xml/XmlAttributeTests.cs
System.Xml/XmlCDataSectionTests.cs
diff --git a/mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog b/mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog
index 6861a21a445..dae544e70c2 100644
--- a/mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog
+++ b/mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog
@@ -1,5 +1,10 @@
2005-12-13 Atsushi Enomoto <atsushi@ximian.com>
+ * XPathEditableNavigatorTests.cs : added tests that passes empty
+ string to editor methods. Added tests for ReplaceSelf().
+
+2005-12-13 Atsushi Enomoto <atsushi@ximian.com>
+
* XPathEditableNavigatorTests.cs : added tests for PrependChild().
2005-12-13 Atsushi Enomoto <atsushi@ximian.com>
diff --git a/mcs/class/System.XML/Test/System.Xml.XPath/XPathEditableNavigatorTests.cs b/mcs/class/System.XML/Test/System.Xml.XPath/XPathEditableNavigatorTests.cs
index 00501807e00..9538938fba4 100644
--- a/mcs/class/System.XML/Test/System.Xml.XPath/XPathEditableNavigatorTests.cs
+++ b/mcs/class/System.XML/Test/System.Xml.XPath/XPathEditableNavigatorTests.cs
@@ -75,6 +75,15 @@ namespace MonoTests.System.Xml.XPath
}
[Test]
+ // empty content is allowed.
+ public void AppendChildEmptyString ()
+ {
+ XPathNavigator nav = GetInstance ("<root/>");
+ nav.MoveToFirstChild (); // root
+ nav.AppendChild (String.Empty);
+ }
+
+ [Test]
public void AppendChildElement ()
{
XPathNavigator nav = GetInstance ("<root/>");
@@ -245,6 +254,15 @@ namespace MonoTests.System.Xml.XPath
}
[Test]
+ // empty content is allowed.
+ public void InsertAfterEmptyString ()
+ {
+ XPathNavigator nav = GetInstance ("<root/>");
+ nav.MoveToFirstChild (); // root
+ nav.InsertAfter (String.Empty);
+ }
+
+ [Test]
public void InsertBefore ()
{
XPathNavigator nav = GetInstance ("<root>test</root>");
@@ -328,6 +346,15 @@ namespace MonoTests.System.Xml.XPath
}
[Test]
+ // empty content is allowed.
+ public void InsertBeforeEmptyString ()
+ {
+ XPathNavigator nav = GetInstance ("<root/>");
+ nav.MoveToFirstChild (); // root
+ nav.InsertBefore (String.Empty);
+ }
+
+ [Test]
public void DeleteRange ()
{
XPathNavigator nav = GetInstance ("<root><foo><bar/><baz/></foo><next>child<tmp/></next>final</root>");
@@ -544,6 +571,137 @@ namespace MonoTests.System.Xml.XPath
w.WriteEndAttribute ();
w.Close ();
}
+
+ [Test]
+ // empty content is allowed.
+ public void PrependChildEmptyString ()
+ {
+ XPathNavigator nav = GetInstance ("<root><foo/><bar/><baz/></root>");
+ nav.MoveToFirstChild ();
+ nav.MoveToFirstChild (); // foo
+ nav.MoveToNext (); // bar
+ nav.PrependChild (String.Empty);
+
+ AssertNavigator ("#1", nav,
+ XPathNodeType.Element,
+ String.Empty, // Prefix
+ "bar", // LocalName
+ String.Empty, // NamespaceURI
+ "bar", // Name
+ String.Empty, // Value
+ false, // HasAttributes
+ false, // HasChildren
+ true); // IsEmptyElement
+
+ Assert.IsTrue (nav.MoveToFirst (), "#1-2");
+
+ AssertNavigator ("#2", nav,
+ XPathNodeType.Element,
+ String.Empty, // Prefix
+ "foo", // LocalName
+ String.Empty, // NamespaceURI
+ "foo", // Name
+ String.Empty, // Value
+ false, // HasAttributes
+ false, // HasChildren
+ true); // IsEmptyElement
+ }
+
+ [Test]
+ public void ReplaceSelf ()
+ {
+ XPathNavigator nav = GetInstance ("<root><foo>existing_child</foo></root>");
+ nav.MoveToFirstChild ();
+ nav.MoveToFirstChild (); // foo
+
+ nav.ReplaceSelf ("<hijacker>hah, hah</hijacker><next/>");
+
+ AssertNavigator ("#1", nav,
+ XPathNodeType.Element,
+ String.Empty, // Prefix
+ "hijacker", // LocalName
+ String.Empty, // NamespaceURI
+ "hijacker", // Name
+ "hah, hah", // Value
+ false, // HasAttributes
+ true, // HasChildren
+ false); // IsEmptyElement
+
+ Assert.IsTrue (nav.MoveToNext (), "#1-2");
+
+ AssertNavigator ("#2", nav,
+ XPathNodeType.Element,
+ String.Empty, // Prefix
+ "next", // LocalName
+ String.Empty, // NamespaceURI
+ "next", // Name
+ String.Empty, // Value
+ false, // HasAttributes
+ false, // HasChildren
+ true); // IsEmptyElement
+ }
+
+ [Test]
+ // possible internal behavior difference e.g. due to ReadNode()
+ public void ReplaceSelfXmlReaderInteractive ()
+ {
+ XPathNavigator nav = GetInstance ("<root><foo>existing_child</foo></root>");
+ nav.MoveToFirstChild ();
+ nav.MoveToFirstChild (); // foo
+
+ XmlReader xr = new XmlTextReader (
+ "<hijacker>hah, hah</hijacker><next/>",
+ XmlNodeType.Element,
+ null);
+ xr.MoveToContent ();
+ nav.ReplaceSelf (xr);
+
+ AssertNavigator ("#1", nav,
+ XPathNodeType.Element,
+ String.Empty, // Prefix
+ "hijacker", // LocalName
+ String.Empty, // NamespaceURI
+ "hijacker", // Name
+ "hah, hah", // Value
+ false, // HasAttributes
+ true, // HasChildren
+ false); // IsEmptyElement
+
+ Assert.IsFalse (nav.MoveToNext (), "#1-2");
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ // empty content is not allowed
+ public void ReplaceSelfEmptyString ()
+ {
+ XPathNavigator nav = GetInstance ("<root><foo>existing_child</foo></root>");
+ nav.MoveToFirstChild ();
+ nav.MoveToFirstChild (); // foo
+
+ nav.ReplaceSelf (String.Empty);
+ }
+
+ [Test]
+ public void SetValueEmptyString ()
+ {
+ XPathNavigator nav = GetInstance ("<root><foo>existing_child</foo></root>");
+ nav.MoveToFirstChild ();
+ nav.MoveToFirstChild (); // foo
+
+ nav.SetValue (String.Empty);
+
+ AssertNavigator ("#1", nav,
+ XPathNodeType.Element,
+ String.Empty, // Prefix
+ "foo", // LocalName
+ String.Empty, // NamespaceURI
+ "foo", // Name
+ String.Empty, // Value
+ false, // HasAttributes
+ true, // HasChildren
+ false); // IsEmptyElement
+ }
}
}
diff --git a/mcs/class/System.XML/Test/System.Xml/ChangeLog b/mcs/class/System.XML/Test/System.Xml/ChangeLog
index 47e1ef9a6ac..9db1ea71a9a 100644
--- a/mcs/class/System.XML/Test/System.Xml/ChangeLog
+++ b/mcs/class/System.XML/Test/System.Xml/ChangeLog
@@ -1,5 +1,9 @@
2005-12-12 Atsushi Enomoto <atsushi@ximian.com>
+ * XmlAssert.cs : new file.
+
+2005-12-12 Atsushi Enomoto <atsushi@ximian.com>
+
* XmlReaderCommonTests.cs : enabled MoveToNextSibling() tests.
2005-12-12 Atsushi Enomoto <atsushi@ximian.com>
diff --git a/mcs/class/System.XML/Test/System.Xml/XmlAssert.cs b/mcs/class/System.XML/Test/System.Xml/XmlAssert.cs
new file mode 100644
index 00000000000..a1b12587523
--- /dev/null
+++ b/mcs/class/System.XML/Test/System.Xml/XmlAssert.cs
@@ -0,0 +1,106 @@
+//
+// XPathEditableNavigatorTests.cs
+//
+// Author:
+// Atsushi Enomoto <atsushi@ximian.com>
+//
+// Copyright (C) 2005 Novell, Inc. http://www.novell.com
+//
+
+using System;
+using System.Xml;
+using System.Xml.XPath;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+ public class XmlAssert
+ {
+ // copy from XmlTextReaderTests
+ public static void AssertStartDocument (XmlReader xmlReader,
+ string label)
+ {
+ Assert.AreEqual (ReadState.Initial, xmlReader.ReadState, label + ".ReadState");
+ Assert.AreEqual (XmlNodeType.None, xmlReader.NodeType, label + ".NodeType");
+ Assert.AreEqual (0, xmlReader.Depth, label + ".Depth");
+ Assert.IsFalse (xmlReader.EOF, label + ".EOF");
+ }
+
+ public static void AssertNode (
+ string label,
+ XmlReader xmlReader,
+ XmlNodeType nodeType,
+ int depth,
+ bool isEmptyElement,
+ string name,
+ string prefix,
+ string localName,
+ string namespaceURI,
+ string value,
+ bool hasValue,
+ int attributeCount,
+ bool hasAttributes)
+ {
+ label = String.Concat (label, "(", xmlReader.GetType ().Name, ")");
+ Assert.AreEqual (nodeType, xmlReader.NodeType, label + ".NodeType");
+ Assert.AreEqual (isEmptyElement, xmlReader.IsEmptyElement,
+ label + ".IsEmptyElement");
+
+ Assert.AreEqual (name, xmlReader.Name, label + ".Name");
+
+ Assert.AreEqual (prefix, xmlReader.Prefix, label + ".Prefix");
+
+ Assert.AreEqual (localName, xmlReader.LocalName, label + ".LocalName");
+
+ Assert.AreEqual (namespaceURI, xmlReader.NamespaceURI, label + ".NamespaceURI");
+
+ Assert.AreEqual (depth, xmlReader.Depth, label + ".Depth");
+
+ Assert.AreEqual (hasValue, xmlReader.HasValue, label + ".HasValue");
+
+ Assert.AreEqual (value, xmlReader.Value, label + ".Value");
+
+ Assert.AreEqual (hasAttributes, xmlReader.HasAttributes,
+ label + "HasAttributes");
+
+ Assert.AreEqual (attributeCount, xmlReader.AttributeCount,
+ label + ".AttributeCount");
+ }
+
+ public static void AssertAttribute (
+ string label,
+ XmlReader xmlReader,
+ string name,
+ string prefix,
+ string localName,
+ string namespaceURI,
+ string value)
+ {
+ Assert.AreEqual (value, xmlReader [name], label + " [name]");
+
+ Assert.AreEqual (value, xmlReader.GetAttribute (name),
+ label + ".GetAttribute(name)");
+
+ if (namespaceURI != String.Empty) {
+ Assert.AreEqual (value, xmlReader [localName, namespaceURI], label + " [name]");
+ Assert.AreEqual (value, xmlReader.GetAttribute (localName, namespaceURI), label + ".GetAttribute(localName,namespaceURI)");
+ }
+ }
+
+ public static void AssertEndDocument (XmlReader xmlReader, string label)
+ {
+ Assert.IsFalse (!xmlReader.Read (), label + ".Read()");
+ Assert.AreEqual (XmlNodeType.None, xmlReader.NodeType,
+ label + ".NodeType is not XmlNodeType.None");
+ Assert.AreEqual (0, xmlReader.Depth, label + ".Depth is not 0");
+ Assert.AreEqual (ReadState.EndOfFile, xmlReader.ReadState,
+ label + "ReadState is not ReadState.EndOfFile");
+ Assert.IsTrue (xmlReader.EOF, label + ".EOF");
+
+ xmlReader.Close ();
+ Assert.AreEqual (ReadState.Closed, xmlReader.ReadState,
+ label + ".ReadState is not ReadState.Cosed");
+ }
+ }
+}