Author: atsushi
Date: 2005-12-13 07:09:02 -0500 (Tue, 13 Dec 2005)
New Revision: 54278

Added:
   trunk/mcs/class/System.XML/Test/System.Xml/XmlAssert.cs
Modified:
   trunk/mcs/class/System.XML/ChangeLog
   trunk/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog
   trunk/mcs/class/System.XML/Mono.Xml.XPath/XPathEditableDocument.cs
   trunk/mcs/class/System.XML/System.Xml.XPath/ChangeLog
   trunk/mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs
   trunk/mcs/class/System.XML/System.Xml_test.dll.sources
   trunk/mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog
   
trunk/mcs/class/System.XML/Test/System.Xml.XPath/XPathEditableNavigatorTests.cs
   trunk/mcs/class/System.XML/Test/System.Xml/ChangeLog
Log:
2005-12-13  Atsushi Enomoto <[EMAIL PROTECTED]>

        * 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().



Modified: trunk/mcs/class/System.XML/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/ChangeLog        2005-12-13 11:19:46 UTC (rev 
54277)
+++ trunk/mcs/class/System.XML/ChangeLog        2005-12-13 12:09:02 UTC (rev 
54278)
@@ -1,5 +1,9 @@
 2005-12-13  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * System.Xml_test.dll.sources: Added XmlAssert.cs.
+
+2005-12-13  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * System.Xml_test.dll.sources: Added XPathEditableNavigatorTests.cs.
 
 2005-12-08  Andrew Skiba  <[EMAIL PROTECTED]>

Modified: trunk/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog 2005-12-13 11:19:46 UTC 
(rev 54277)
+++ trunk/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog 2005-12-13 12:09:02 UTC 
(rev 54278)
@@ -1,5 +1,9 @@
 2005-12-13  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * XPathEditableDocument.cs : implement ReplaceSelf() here.
+
+2005-12-13  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * XPathEditableDocument.cs :
          - Now it does not append "written" nodes until Close() is invoked.
          - Use XmlDocumentFragment to store incomplete tree fragment.

Modified: trunk/mcs/class/System.XML/Mono.Xml.XPath/XPathEditableDocument.cs
===================================================================
--- trunk/mcs/class/System.XML/Mono.Xml.XPath/XPathEditableDocument.cs  
2005-12-13 11:19:46 UTC (rev 54277)
+++ trunk/mcs/class/System.XML/Mono.Xml.XPath/XPathEditableDocument.cs  
2005-12-13 12:09:02 UTC (rev 54278)
@@ -656,10 +656,50 @@
                        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 ();

Modified: trunk/mcs/class/System.XML/System.Xml.XPath/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.XPath/ChangeLog       2005-12-13 
11:19:46 UTC (rev 54277)
+++ trunk/mcs/class/System.XML/System.Xml.XPath/ChangeLog       2005-12-13 
12:09:02 UTC (rev 54278)
@@ -1,5 +1,10 @@
 2005-12-13  Atsushi Enomoto <[EMAIL PROTECTED]>
 
+       * XPathNavigator.cs : ReplaceSelf() should allow document fragment.
+         Moved implementation to XPathEditableDocument.
+
+2005-12-13  Atsushi Enomoto <[EMAIL PROTECTED]>
+
        * XPathNavigator.cs : PrependChild() should use AppendChild() when
          there is no child.
 

Modified: trunk/mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs       
2005-12-13 11:19:46 UTC (rev 54277)
+++ trunk/mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs       
2005-12-13 12:09:02 UTC (rev 54278)
@@ -1185,17 +1185,15 @@
                        }
                }
 
-               [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]

Modified: trunk/mcs/class/System.XML/System.Xml_test.dll.sources
===================================================================
--- trunk/mcs/class/System.XML/System.Xml_test.dll.sources      2005-12-13 
11:19:46 UTC (rev 54277)
+++ trunk/mcs/class/System.XML/System.Xml_test.dll.sources      2005-12-13 
12:09:02 UTC (rev 54278)
@@ -1,4 +1,5 @@
 System.Xml/NameTableTests.cs
+System.Xml/XmlAssert.cs
 System.Xml/XmlAttributeCollectionTests.cs
 System.Xml/XmlAttributeTests.cs
 System.Xml/XmlCDataSectionTests.cs

Modified: trunk/mcs/class/System.XML/Test/System.Xml/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/Test/System.Xml/ChangeLog        2005-12-13 
11:19:46 UTC (rev 54277)
+++ trunk/mcs/class/System.XML/Test/System.Xml/ChangeLog        2005-12-13 
12:09:02 UTC (rev 54278)
@@ -1,5 +1,9 @@
 2005-12-12  Atsushi Enomoto <[EMAIL PROTECTED]>
 
+       * XmlAssert.cs : new file.
+
+2005-12-12  Atsushi Enomoto <[EMAIL PROTECTED]>
+
        * XmlReaderCommonTests.cs : enabled MoveToNextSibling() tests.
 
 2005-12-12  Atsushi Enomoto <[EMAIL PROTECTED]>

Added: trunk/mcs/class/System.XML/Test/System.Xml/XmlAssert.cs
===================================================================
--- trunk/mcs/class/System.XML/Test/System.Xml/XmlAssert.cs     2005-12-13 
11:19:46 UTC (rev 54277)
+++ trunk/mcs/class/System.XML/Test/System.Xml/XmlAssert.cs     2005-12-13 
12:09:02 UTC (rev 54278)
@@ -0,0 +1,106 @@
+//
+// XPathEditableNavigatorTests.cs
+//
+// Author:
+//     Atsushi Enomoto  <[EMAIL PROTECTED]>
+//
+// 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");
+               }
+       }
+}


Property changes on: trunk/mcs/class/System.XML/Test/System.Xml/XmlAssert.cs
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: trunk/mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog  2005-12-13 
11:19:46 UTC (rev 54277)
+++ trunk/mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog  2005-12-13 
12:09:02 UTC (rev 54278)
@@ -1,5 +1,10 @@
 2005-12-13  Atsushi Enomoto <[EMAIL PROTECTED]>
 
+       * XPathEditableNavigatorTests.cs : added tests that passes empty
+         string to editor methods. Added tests for ReplaceSelf().
+
+2005-12-13  Atsushi Enomoto <[EMAIL PROTECTED]>
+
        * XPathEditableNavigatorTests.cs : added tests for PrependChild().
 
 2005-12-13  Atsushi Enomoto <[EMAIL PROTECTED]>

Modified: 
trunk/mcs/class/System.XML/Test/System.Xml.XPath/XPathEditableNavigatorTests.cs
===================================================================
--- 
trunk/mcs/class/System.XML/Test/System.Xml.XPath/XPathEditableNavigatorTests.cs 
    2005-12-13 11:19:46 UTC (rev 54277)
+++ 
trunk/mcs/class/System.XML/Test/System.Xml.XPath/XPathEditableNavigatorTests.cs 
    2005-12-13 12:09:02 UTC (rev 54278)
@@ -75,6 +75,15 @@
                }
 
                [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 @@
                }
 
                [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 @@
                }
 
                [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 @@
                        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
+               }
        }
 }
 

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

Reply via email to