dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/tests/System.Xml TestXmlAttribute.cs,


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/tests/System.Xml TestXmlAttribute.cs,NONE,1.1 TestXmlCDataSection.cs,NONE,1.1 TestXmlText.cs,NONE,1.1 TestXml.cs,1.7,1.8 TestXmlDocument.cs,1.1,1.2
Date: Thu, 05 Dec 2002 23:58:35 -0500

Update of /cvsroot/dotgnu-pnet/pnetlib/tests/System.Xml
In directory subversions:/tmp/cvs-serv30516/tests/System.Xml

Modified Files:
        TestXml.cs TestXmlDocument.cs 
Added Files:
        TestXmlAttribute.cs TestXmlCDataSection.cs TestXmlText.cs 
Log Message:


Test cases and bug fixes for System.Xml.


--- NEW FILE ---
/*
 * TestXmlAttribute.cs - Tests for the "System.Xml.XmlAttribute" class.
 *
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

using CSUnit;
using System;
using System.Xml;

#if !ECMA_COMPAT

public class TestXmlAttribute : TestCase
{
        // Internal state.
        private XmlDocument doc;

        // Constructor.
        public TestXmlAttribute(String name)
                        : base(name)
                        {
                                // Nothing to do here.
                        }

        // Set up for the tests.
        protected override void Setup()
                        {
                                doc = new XmlDocument();
                        }

        // Clean up after the tests.
        protected override void Cleanup()
                        {
                                // Nothing to do here.
                        }

        // Check the properties on an attribute.
        private void CheckProperties(String msg, XmlAttribute attr,
                                                                 String prefix, 
String name, String ns,
                                                                 String value)
                        {
                                XmlNameTable nt = doc.NameTable;
                                prefix = nt.Add(prefix);
                                name = nt.Add(name);
                                ns = nt.Add(ns);
                                AssertSame(msg + " [1]", prefix, attr.Prefix);
                                AssertSame(msg + " [2]", name, attr.LocalName);
                                AssertSame(msg + " [3]", ns, attr.NamespaceURI);
                                if(prefix != String.Empty)
                                {
                                        String combined = nt.Add(prefix + ":" + 
name);
                                        AssertEquals(msg + " [4]", combined, 
attr.Name);
                                }
                                else
                                {
                                        AssertSame(msg + " [5]", name, 
attr.Name);
                                }
                                AssertEquals(msg + " [6]",
                                                         XmlNodeType.Attribute, 
attr.NodeType);
                                AssertEquals(msg + " [7]", doc, 
attr.OwnerDocument);
                                AssertNull(msg + " [8]", attr.OwnerElement);
                                AssertNull(msg + " [9]", attr.ParentNode);
                                AssertEquals(msg + " [10]", value, 
attr.InnerText);
                                AssertEquals(msg + " [11]", value, attr.Value);
                                Assert(msg + " [12]", attr.Specified);
                        }
        private void CheckProperties(String msg, XmlAttribute attr,
                                                                 String prefix, 
String name, String ns)
                        {
                                CheckProperties(msg, attr, prefix, name, ns, 
String.Empty);
                        }
        private void CheckProperties(String msg, XmlAttribute attr, String 
value)
                        {
                                CheckProperties(msg, attr, attr.Prefix, 
attr.LocalName,
                                                                
attr.NamespaceURI, value);
                        }

        // Test attribute construction.
        public void TestXmlAttributeConstruct()
                        {
                                XmlAttribute attr;

                                attr = doc.CreateAttribute("foo");
                                CheckProperties("Construct (1)", attr,
                                                                String.Empty, 
"foo", String.Empty);

                                attr = doc.CreateAttribute("prefix:foo");
                                CheckProperties("Construct (2)", attr,
                                                                "prefix", 
"foo", String.Empty);

                                attr = doc.CreateAttribute("foo", "uri");
                                CheckProperties("Construct (3)", attr,
                                                                String.Empty, 
"foo", "uri");

                                attr = doc.CreateAttribute("prefix:foo", "uri");
                                CheckProperties("Construct (4)", attr,
                                                                "prefix", 
"foo", "uri");

                                attr = 
doc.CreateAttribute("prefix1:prefix2:foo", "uri");
                                CheckProperties("Construct (5)", attr,
                                                                
"prefix1:prefix2", "foo", "uri");

                                attr = doc.CreateAttribute("prefix", "foo:bar", 
"uri");
                                CheckProperties("Construct (6)", attr,
                                                                "prefix", 
"foo:bar", "uri");
                        }

        // Test attribute property changes.
        public void TestXmlAttributeProperties()
                        {
                                XmlAttribute attr;

                                attr = doc.CreateAttribute("prefix", "foo", 
"uri");
                                CheckProperties("Properties (1)", attr, 
String.Empty);

                                attr.Value = "xyzzy";
                                CheckProperties("Properties (2)", attr, 
"xyzzy");

                                attr.Value = "&lt;hello&gt;";
                                CheckProperties("Properties (3)", attr, 
"&lt;hello&gt;");
                        }

        // Test attribute XML output.
        public void TestXmlAttributeToXml()
                        {
                                XmlAttribute attr;

                                attr = doc.CreateAttribute("prefix", "foo", 
String.Empty);
                                attr.Value = "xyzzy";

                                AssertEquals("ToXml (1)", "xyzzy", 
attr.InnerXml);
                                AssertEquals("ToXml (2)",
                                                         "foo=\"xyzzy\"", 
attr.OuterXml);

                                attr.Value = "&lt;hello&gt;\"";
                                AssertEquals("ToXml (3)", 
"&amp;lt;hello&amp;gt;\"",
                                                         attr.InnerXml);
                                AssertEquals("ToXml (4)",
                                                         
"foo=\"&amp;lt;hello&amp;gt;&quot;\"",
                                                         attr.OuterXml);
                        }

        // Test setting attributes via direct text node inserts.
        public void TestXmlAttributeInsert()
                        {
                                XmlAttribute attr;
                                attr = doc.CreateAttribute("prefix", "foo", 
"uri");

                                XmlText text1 = doc.CreateTextNode("hello");
                                XmlText text2 = doc.CreateTextNode(" and 
goodbye");

                                attr.AppendChild(text1);
                                AssertEquals("Insert (1)", "hello", attr.Value);
                                AssertEquals("Insert (2)", text1, 
attr.FirstChild);
                                AssertEquals("Insert (3)", text1, 
attr.LastChild);

                                attr.AppendChild(text2);
                                AssertEquals("Insert (4)", "hello and goodbye", 
attr.Value);
                                AssertEquals("Insert (5)", text1, 
attr.FirstChild);
                                AssertEquals("Insert (6)", text2, 
attr.LastChild);

                                // Entity references do not affect the combined 
value,
                                // but they do affect the XML.
                                XmlEntityReference entity = 
doc.CreateEntityReference("foo");
                                attr.AppendChild(entity);
                                AssertEquals("Insert (7)", "hello and goodbye", 
attr.Value);
                                AssertEquals("Insert (8)",
                                                         "hello and 
goodbye&foo;", attr.InnerXml);

                                // Cannot insert whitespace into attributes.
                                try
                                {
                                        attr.AppendChild(doc.CreateWhitespace(" 
  "));
                                        Fail("Insert (9)");
                                }
                                catch(InvalidOperationException)
                                {
                                        // Success
                                }
                                try
                                {
                                        
attr.AppendChild(doc.CreateSignificantWhitespace("   "));
                                        Fail("Insert (9)");
                                }
                                catch(InvalidOperationException)
                                {
                                        // Success
                                }
                        }

}; // class TestXmlAttribute

#endif // !ECMA_COMPAT

--- NEW FILE ---
/*
 * TestXmlCDataSection.cs - Tests for the "System.Xml.XmlCDataSection" class.
 *
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

using CSUnit;
using System;
using System.Xml;

#if !ECMA_COMPAT

public class TestXmlCDataSection : TestCase
{
        // Internal state.
        private XmlDocument doc;

        // Constructor.
        public TestXmlCDataSection(String name)
                        : base(name)
                        {
                                // Nothing to do here.
                        }

        // Set up for the tests.
        protected override void Setup()
                        {
                                doc = new XmlDocument();
                        }

        // Clean up after the tests.
        protected override void Cleanup()
                        {
                                // Nothing to do here.
                        }

        // Check the properties on a newly constructed CDATA section.
        private void CheckProperties(String msg, XmlCDataSection cdata,
                                                                 String value, 
bool failXml)
                        {
                                String temp;
                                AssertEquals(msg + " [1]", "#cdata-section", 
cdata.LocalName);
                                AssertEquals(msg + " [2]", "#cdata-section", 
cdata.Name);
                                AssertEquals(msg + " [3]", String.Empty, 
cdata.Prefix);
                                AssertEquals(msg + " [4]", String.Empty, 
cdata.NamespaceURI);
                                AssertEquals(msg + " [5]", XmlNodeType.CDATA, 
cdata.NodeType);
                                AssertEquals(msg + " [6]", value, cdata.Data);
                                AssertEquals(msg + " [7]", value, cdata.Value);
                                AssertEquals(msg + " [8]", value, 
cdata.InnerText);
                                AssertEquals(msg + " [9]", value.Length, 
cdata.Length);
                                AssertEquals(msg + " [10]", String.Empty, 
cdata.InnerXml);
                                if(failXml)
                                {
                                        try
                                        {
                                                temp = cdata.OuterXml;
                                                Fail(msg + " [11]");
                                        }
                                        catch(ArgumentException)
                                        {
                                                // Success
                                        }
                                }
                                else
                                {
                                        AssertEquals(msg + " [12]",
                                                                 "<![CDATA[" + 
value + "]]>",
                                                                 
cdata.OuterXml);
                                }
                        }

        // Test the construction of CDATA section nodes.
        public void TestXmlCDataSectionConstruct()
                        {
                                CheckProperties("Construct (1)",
                                                                
doc.CreateCDataSection(null),
                                                                String.Empty, 
false);
                                CheckProperties("Construct (2)",
                                                                
doc.CreateCDataSection(String.Empty),
                                                                String.Empty, 
false);
                                CheckProperties("Construct (3)",
                                                                
doc.CreateCDataSection("xyzzy"),
                                                                "xyzzy", false);
                                CheckProperties("Construct (4)",
                                                                
doc.CreateCDataSection("]]>"),
                                                                "]]>", true);
                                CheckProperties("Construct (5)",
                                                                
doc.CreateCDataSection("<&>"),
                                                                "<&>", false);
                        }

}; // class TestXmlCDataSection

#endif // !ECMA_COMPAT

--- NEW FILE ---
/*
 * TestXmlText.cs - Tests for the "System.Xml.TestXmlText" class.
 *
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

using CSUnit;
using System;
using System.Xml;

#if !ECMA_COMPAT

// Note: this class also tests the behaviour of "XmlCharacterData".

public class TestXmlText : TestCase
{
        // Internal state.
        private XmlDocument doc;
        private int changeBefore;
        private int changeAfter;
        private XmlNode expectedNode;
        private XmlNodeChangedEventHandler handleBefore;
        private XmlNodeChangedEventHandler handleAfter;

        // Constructor.
        public TestXmlText(String name)
                        : base(name)
                        {
                                // Nothing to do here.
                        }

        // Set up for the tests.
        protected override void Setup()
                        {
                                doc = new XmlDocument();
                                handleBefore = new 
XmlNodeChangedEventHandler(WatchBefore);
                                handleAfter = new 
XmlNodeChangedEventHandler(WatchAfter);
                        }

        // Clean up after the tests.
        protected override void Cleanup()
                        {
                                // Nothing to do here.
                        }

        // Check the properties on a newly constructed text node.
        private void CheckProperties(String msg, XmlText text,
                                                                 String value, 
String xmlValue)
                        {
                                String temp;
                                AssertEquals(msg + " [1]", "#text", 
text.LocalName);
                                AssertEquals(msg + " [2]", "#text", text.Name);
                                AssertEquals(msg + " [3]", String.Empty, 
text.Prefix);
                                AssertEquals(msg + " [4]", String.Empty, 
text.NamespaceURI);
                                AssertEquals(msg + " [5]", XmlNodeType.Text, 
text.NodeType);
                                AssertEquals(msg + " [6]", value, text.Data);
                                AssertEquals(msg + " [7]", value, text.Value);
                                AssertEquals(msg + " [8]", value, 
text.InnerText);
                                AssertEquals(msg + " [9]", value.Length, 
text.Length);
                                AssertEquals(msg + " [10]", String.Empty, 
text.InnerXml);
                                AssertEquals(msg + " [11]", xmlValue, 
text.OuterXml);
                        }
        private void CheckProperties(String msg, XmlText text, String value)
                        {
                                CheckProperties(msg, text, value, value);
                        }

        // Test the construction of text nodes.
        public void TestXmlTextConstruct()
                        {
                                CheckProperties("Construct (1)",
                                                                
doc.CreateTextNode(null),
                                                                String.Empty);
                                CheckProperties("Construct (2)",
                                                                
doc.CreateTextNode(String.Empty),
                                                                String.Empty);
                                CheckProperties("Construct (3)",
                                                                
doc.CreateTextNode("xyzzy"),
                                                                "xyzzy");
                                CheckProperties("Construct (4)",
                                                                
doc.CreateTextNode("<&>\"'"),
                                                                "<&>\"'", 
"&lt;&amp;&gt;\"'");
                        }

        // Watch for change events.
        private void WatchBefore(Object sender, XmlNodeChangedEventArgs args)
                        {
                                AssertEquals("Sender", 
expectedNode.OwnerDocument, sender);
                                AssertEquals
                                        ("Action", XmlNodeChangedAction.Change, 
args.Action);
                                AssertEquals("Node", expectedNode, args.Node);
                                AssertEquals("OldParent", 
expectedNode.ParentNode,
                                                         args.OldParent);
                                AssertEquals("NewParent", 
expectedNode.ParentNode,
                                                         args.NewParent);
                                ++changeBefore;
                        }
        private void WatchAfter(Object sender, XmlNodeChangedEventArgs args)
                        {
                                AssertEquals("Sender", 
expectedNode.OwnerDocument, sender);
                                AssertEquals
                                        ("Action", XmlNodeChangedAction.Change, 
args.Action);
                                AssertEquals("Node", expectedNode, args.Node);
                                AssertEquals("OldParent", 
expectedNode.ParentNode,
                                                         args.OldParent);
                                AssertEquals("NewParent", 
expectedNode.ParentNode,
                                                         args.NewParent);
                                ++changeAfter;
                        }

        // Register to watch for change events.
        private void RegisterWatchNeither(XmlNode node)
                        {
                                expectedNode = node;
                                changeBefore = 0;
                                changeAfter = 0;
                        }
        private void RegisterWatchBoth(XmlNode node)
                        {
                                doc.NodeChanging += handleBefore;
                                doc.NodeChanged += handleAfter;
                                expectedNode = node;
                                changeBefore = 0;
                                changeAfter = 0;
                        }
        private void RegisterWatchBefore(XmlNode node)
                        {
                                doc.NodeChanging += handleBefore;
                                expectedNode = node;
                                changeBefore = 0;
                                changeAfter = 0;
                        }
        private void RegisterWatchAfter(XmlNode node)
                        {
                                doc.NodeChanged += handleAfter;
                                expectedNode = node;
                                changeBefore = 0;
                                changeAfter = 0;
                        }

        // Check that change events were fired.
        private void CheckForChangeNeither()
                        {
                                doc.NodeChanging -= handleBefore;
                                doc.NodeChanged -= handleAfter;
                                AssertEquals("CheckForChange (Before)", 0, 
changeBefore);
                                AssertEquals("CheckForChange (After)", 0, 
changeAfter);
                        }
        private void CheckForChangeBoth()
                        {
                                doc.NodeChanging -= handleBefore;
                                doc.NodeChanged -= handleAfter;
                                AssertEquals("CheckForChange (Before)", 1, 
changeBefore);
                                AssertEquals("CheckForChange (After)", 1, 
changeAfter);
                        }
        private void CheckForChangeBefore()
                        {
                                doc.NodeChanging -= handleBefore;
                                doc.NodeChanged -= handleAfter;
                                AssertEquals("CheckForChange (Before)", 1, 
changeBefore);
                                AssertEquals("CheckForChange (After)", 0, 
changeAfter);
                        }
        private void CheckForChangeAfter()
                        {
                                doc.NodeChanging -= handleBefore;
                                doc.NodeChanged -= handleAfter;
                                AssertEquals("CheckForChange (Before)", 0, 
changeBefore);
                                AssertEquals("CheckForChange (After)", 1, 
changeAfter);
                        }

        // Test the appending of text data.
        public void TestXmlTextAppendData()
                        {
                                // Test simple appending.
                                XmlText text = doc.CreateTextNode("hello");
                                RegisterWatchNeither(text);
                                text.AppendData(" and goodbye");
                                CheckForChangeNeither();
                                AssertEquals("AppendData (1)", 17, text.Length);
                                AssertEquals("AppendData (2)", "hello and 
goodbye", text.Data);

                                // Test event handling.
                                RegisterWatchBoth(text);
                                text.AppendData("blah");
                                CheckForChangeBoth();

                                RegisterWatchBefore(text);
                                text.AppendData("blah2");
                                CheckForChangeBefore();

                                RegisterWatchAfter(text);
                                text.AppendData("blah3");
                                CheckForChangeAfter();

                                AssertEquals("AppendData (3)",
                                                         "hello and 
goodbyeblahblah2blah3", text.Data);
                        }

        // Test the deleting of text data.
        public void TestXmlTextDeleteData()
                        {
                                // Test simple deleting.
                                XmlText text = doc.CreateTextNode("hello");
                                RegisterWatchNeither(text);
                                text.DeleteData(1, 3);
                                AssertEquals("DeleteData (1)", 2, text.Length);
                                AssertEquals("DeleteData (2)", "ho", text.Data);

                                // Test out of range deletions.
                                text.DeleteData(-10, 3);
                                text.DeleteData(2, 30);
                                AssertEquals("DeleteData (3)", "ho", text.Data);
                                text.DeleteData(-1000, 4000);
                                AssertEquals("DeleteData (4)", String.Empty, 
text.Data);
                                CheckForChangeNeither();

                                // Test event handling.
                                text = doc.CreateTextNode("hello");
                                RegisterWatchBoth(text);
                                text.DeleteData(1, 3);
                                CheckForChangeBoth();

                                RegisterWatchBefore(text);
                                text.DeleteData(-5, 1);
                                CheckForChangeBefore();

                                RegisterWatchAfter(text);
                                text.DeleteData(0, 5);
                                CheckForChangeAfter();
                        }

        // Test the inserting of text data.
        public void TestXmlTextInsertData()
                        {
                                // Test simple insertions.
                                XmlText text = doc.CreateTextNode("hello");
                                RegisterWatchNeither(text);
                                text.InsertData(3, "lll");
                                AssertEquals("InsertData (1)", 8, text.Length);
                                AssertEquals("InsertData (2)", "helllllo", 
text.Data);
                                CheckForChangeNeither();

                                // Test out of range insertions.  The before 
event will
                                // fire, but not the after event, due to 
exceptions between.
                                RegisterWatchBoth(text);
                                try
                                {
                                        text.InsertData(-1, "x");
                                        Fail("InsertData (3)");
                                }
                                catch(ArgumentOutOfRangeException)
                                {
                                        // Success
                                }
                                CheckForChangeBefore();
                                RegisterWatchBoth(text);
                                try
                                {
                                        text.InsertData(9, "x");
                                        Fail("InsertData (4)");
                                }
                                catch(ArgumentOutOfRangeException)
                                {
                                        // Success
                                }
                                CheckForChangeBefore();

                                // Test event handling.
                                RegisterWatchBoth(text);
                                text.InsertData(8, "x");
                                AssertEquals("InsertData (5)", 9, text.Length);
                                AssertEquals("InsertData (6)", "helllllox", 
text.Data);
                                CheckForChangeBoth();

                                RegisterWatchBefore(text);
                                text.InsertData(8, "y");
                                AssertEquals("InsertData (7)", 10, text.Length);
                                AssertEquals("InsertData (8)", "hellllloyx", 
text.Data);
                                CheckForChangeBefore();

                                RegisterWatchBefore(text);
                                text.InsertData(8, "z");
                                AssertEquals("InsertData (9)", 11, text.Length);
                                AssertEquals("InsertData (10)", "helllllozyx", 
text.Data);
                                CheckForChangeBefore();
                        }

        // Test the inserting of text data.
        public void TestXmlTextReplaceData()
                        {
                                // Test simple replacing.
                                XmlText text = doc.CreateTextNode("hello");
                                RegisterWatchNeither(text);
                                text.ReplaceData(1, 3, "xyzzy");
                                AssertEquals("ReplaceData (1)", 7, text.Length);
                                AssertEquals("ReplaceData (2)", "hxyzzyo", 
text.Data);

                                // Test out of range replaces.
                                text.ReplaceData(-10, 3, "abc");
                                text.ReplaceData(10, 30, "def");
                                AssertEquals("ReplaceData (3)", 
"abchxyzzyodef", text.Data);
                                text.ReplaceData(-1000, 4000, "");
                                AssertEquals("ReplaceData (4)", String.Empty, 
text.Data);
                                CheckForChangeNeither();

                                // Test event handling.
                                text = doc.CreateTextNode("hello");
                                RegisterWatchBoth(text);
                                text.ReplaceData(1, 3, "blah");
                                CheckForChangeBoth();

                                RegisterWatchBefore(text);
                                text.ReplaceData(-5, 1, "blah2");
                                CheckForChangeBefore();

                                RegisterWatchAfter(text);
                                text.ReplaceData(0, 5, "blah3");
                                CheckForChangeAfter();
                        }

        // Test the setting of text data.
        public void TestXmlTextSetData()
                        {
                                // Test simple setting.
                                XmlText text = doc.CreateTextNode(null);
                                AssertEquals("SetData (1)", String.Empty, 
text.Data);
                                RegisterWatchNeither(text);
                                text.Data = "hello";
                                CheckForChangeNeither();
                                AssertEquals("SetData (2)", "hello", text.Data);
                                AssertEquals("SetData (3)", 5, text.Length);

                                // Test event handling.
                                RegisterWatchBoth(text);
                                text.Data = "blah";
                                CheckForChangeBoth();
                                AssertEquals("SetData (4)", "blah", text.Data);
                                AssertEquals("SetData (5)", 4, text.Length);

                                RegisterWatchBefore(text);
                                text.Data = "blah2";
                                CheckForChangeBefore();
                                AssertEquals("SetData (6)", "blah2", text.Data);
                                AssertEquals("SetData (7)", 5, text.Length);

                                RegisterWatchAfter(text);
                                text.Data = "blah3";
                                CheckForChangeAfter();
                                AssertEquals("SetData (8)", "blah3", text.Data);
                                AssertEquals("SetData (9)", 5, text.Length);
                        }

        // Test the splitting of text nodes.
        public void TestXmlTextSplitText()
                        {
                                // Perform simple splits at various points.
                                XmlAttribute attr = doc.CreateAttribute("foo");
                                XmlText text = doc.CreateTextNode("hello and 
goodbye");
                                RegisterWatchNeither(text);
                                attr.AppendChild(text);
                                XmlText split = text.SplitText(6);
                                CheckForChangeNeither();
                                Assert("SplitText (1)", text != split);
                                AssertEquals("SplitText (2)", "hello ", 
text.Value);
                                AssertEquals("SplitText (3)", "and goodbye", 
split.Value);

                                attr = doc.CreateAttribute("foo");
                                text = doc.CreateTextNode("hello and goodbye");
                                attr.AppendChild(text);
                                split = text.SplitText(-1);
                                Assert("SplitText (4)", text != split);
                                AssertEquals("SplitText (5)", "", text.Value);
                                AssertEquals("SplitText (6)", "hello and 
goodbye", split.Value);

                                attr = doc.CreateAttribute("foo");
                                text = doc.CreateTextNode("hello and goodbye");
                                attr.AppendChild(text);
                                split = text.SplitText(100);
                                Assert("SplitText (7)", text != split);
                                AssertEquals("SplitText (8)", "hello and 
goodbye", text.Value);
                                AssertEquals("SplitText (9)", "", split.Value);

                                // Test event handling.
                                attr = doc.CreateAttribute("foo");
                                text = doc.CreateTextNode("hello and goodbye");
                                attr.AppendChild(text);
                                RegisterWatchBoth(text);
                                text.SplitText(6);
                                CheckForChangeBoth();

                                attr = doc.CreateAttribute("foo");
                                text = doc.CreateTextNode("hello and goodbye");
                                attr.AppendChild(text);
                                RegisterWatchBefore(text);
                                text.SplitText(6);
                                CheckForChangeBefore();

                                attr = doc.CreateAttribute("foo");
                                text = doc.CreateTextNode("hello and goodbye");
                                attr.AppendChild(text);
                                RegisterWatchAfter(text);
                                text.SplitText(6);
                                CheckForChangeAfter();
                        }

        // Test the substring operator on text data.
        public void TestXmlTextSubstring()
                        {
                                XmlText text = doc.CreateTextNode("hello and 
goodbye");

                                RegisterWatchNeither(text);
                                AssertEquals("Substring (1)", String.Empty,
                                                         text.Substring(3, 0));
                                AssertEquals("Substring (2)", "ello",
                                                         text.Substring(1, 4));
                                AssertEquals("Substring (3)", "hello",
                                                         text.Substring(-1, 6));
                                AssertEquals("Substring (4)", "llo and goodbye",
                                                         text.Substring(2, 
2000));
                                CheckForChangeNeither();
                        }

}; // class TestXmlText

#endif // !ECMA_COMPAT

Index: TestXml.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/tests/System.Xml/TestXml.cs,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** TestXml.cs  3 Dec 2002 07:28:06 -0000       1.7
--- TestXml.cs  6 Dec 2002 04:58:32 -0000       1.8
***************
*** 44,48 ****
--- 44,51 ----
                        #if !ECMA_COMPAT
                                suite = new TestSuite("Node Tests");
+                               suite.AddTests(typeof(TestXmlAttribute));
+                               suite.AddTests(typeof(TestXmlCDataSection));
                                suite.AddTests(typeof(TestXmlDocument));
+                               suite.AddTests(typeof(TestXmlText));
                                fullSuite.AddTest(suite);
                        #endif

Index: TestXmlDocument.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/tests/System.Xml/TestXmlDocument.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** TestXmlDocument.cs  3 Dec 2002 07:28:06 -0000       1.1
--- TestXmlDocument.cs  6 Dec 2002 04:58:32 -0000       1.2
***************
*** 90,93 ****
--- 90,298 ----
                        }
  
+       // Test adding an XML declaration to the document.
+       public void TestXmlDocumentAddXmlDeclaration()
+                       {
+                               XmlDocument doc = new XmlDocument();
+ 
+                               // Add the declaration.
+                               XmlDeclaration decl =
+                                       doc.CreateXmlDeclaration("1.0", null, 
null);
+                               AssertNull("XmlDeclaration (1)", 
decl.ParentNode);
+                               AssertEquals("XmlDeclaration (2)", doc, 
decl.OwnerDocument);
+                               doc.AppendChild(decl);
+                               AssertEquals("XmlDeclaration (3)", doc, 
decl.ParentNode);
+                               AssertEquals("XmlDeclaration (4)", doc, 
decl.OwnerDocument);
+ 
+                               // Try to add it again, which should fail this 
time.
+                               try
+                               {
+                                       doc.AppendChild(decl);
+                                       Fail("adding XmlDeclaration node 
twice");
+                               }
+                               catch(InvalidOperationException)
+                               {
+                                       // Success
+                               }
+                               try
+                               {
+                                       doc.PrependChild(decl);
+                                       Fail("prepending XmlDeclaration node 
twice");
+                               }
+                               catch(InvalidOperationException)
+                               {
+                                       // Success
+                               }
+ 
+                               // Adding a document type before should fail.
+                               XmlDocumentType type =
+                                       doc.CreateDocumentType("foo", null, 
null, null);
+                               try
+                               {
+                                       doc.PrependChild(type);
+                                       Fail("prepending XmlDocumentType");
+                               }
+                               catch(InvalidOperationException)
+                               {
+                                       // Success
+                               }
+ 
+                               // Adding a document type after should succeed.
+                               doc.AppendChild(type);
+ 
+                               // Adding an element before should fail.
+                               XmlElement element = doc.CreateElement("foo");
+                               try
+                               {
+                                       doc.PrependChild(element);
+                                       Fail("prepending XmlElement");
+                               }
+                               catch(InvalidOperationException)
+                               {
+                                       // Success
+                               }
+ 
+                               // Adding the element between decl and type 
should fail.
+                               try
+                               {
+                                       doc.InsertAfter(element, decl);
+                                       Fail("inserting XmlElement between 
XmlDeclaration " +
+                                                "and XmlDocumentType");
+                               }
+                               catch(InvalidOperationException)
+                               {
+                                       // Success
+                               }
+                               try
+                               {
+                                       doc.InsertBefore(element, type);
+                                       Fail("inserting XmlElement between 
XmlDeclaration " +
+                                                "and XmlDocumentType (2)");
+                               }
+                               catch(InvalidOperationException)
+                               {
+                                       // Success
+                               }
+ 
+                               // Adding an element after should succeed.
+                               doc.AppendChild(element);
+                       }
+ 
+       // Test adding a document type to the document.
+       public void TestXmlDocumentAddDocumentType()
+                       {
+                               XmlDocument doc = new XmlDocument();
+ 
+                               // Add the document type.
+                               XmlDocumentType type =
+                                       doc.CreateDocumentType("foo", null, 
null, null);
+                               AssertNull("XmlDocumentType (1)", 
type.ParentNode);
+                               AssertEquals("XmlDocumentType (2)", doc, 
type.OwnerDocument);
+                               doc.AppendChild(type);
+                               AssertEquals("XmlDocumentType (3)", doc, 
type.ParentNode);
+                               AssertEquals("XmlDocumentType (4)", doc, 
type.OwnerDocument);
+ 
+                               // Try to add it again, which should fail this 
time.
+                               try
+                               {
+                                       doc.AppendChild(type);
+                                       Fail("adding XmlDocumentType node 
twice");
+                               }
+                               catch(InvalidOperationException)
+                               {
+                                       // Success
+                               }
+                               try
+                               {
+                                       doc.PrependChild(type);
+                                       Fail("prepending XmlDocumentType node 
twice");
+                               }
+                               catch(InvalidOperationException)
+                               {
+                                       // Success
+                               }
+ 
+                               // Adding an XmlDeclaration after should fail.
+                               XmlDeclaration decl =
+                                       doc.CreateXmlDeclaration("1.0", null, 
null);
+                               try
+                               {
+                                       doc.AppendChild(decl);
+                                       Fail("appending XmlDeclaration after 
XmlDocumentType");
+                               }
+                               catch(InvalidOperationException)
+                               {
+                                       // Success
+                               }
+ 
+                               // But adding XmlDeclaration before should 
succeed.
+                               doc.PrependChild(decl);
+                       }
+ 
+       // Test adding an element to the document.
+       public void TestXmlDocumentAddElement()
+                       {
+                               XmlDocument doc = new XmlDocument();
+ 
+                               // Add an element to the document.
+                               XmlElement element = doc.CreateElement("foo");
+                               AssertNull("XmlElement (1)", 
element.ParentNode);
+                               AssertEquals("XmlElement (2)", doc, 
element.OwnerDocument);
+                               doc.AppendChild(element);
+                               AssertEquals("XmlElement (3)", doc, 
element.ParentNode);
+                               AssertEquals("XmlElement (4)", doc, 
element.OwnerDocument);
+ 
+                               // Try to add it again, which should fail this 
time.
+                               try
+                               {
+                                       doc.AppendChild(element);
+                                       Fail("adding XmlElement node twice");
+                               }
+                               catch(InvalidOperationException)
+                               {
+                                       // Success
+                               }
+                               try
+                               {
+                                       doc.PrependChild(element);
+                                       Fail("prepending XmlElement node 
twice");
+                               }
+                               catch(InvalidOperationException)
+                               {
+                                       // Success
+                               }
+ 
+                               // Adding an XmlDeclaration after should fail.
+                               XmlDeclaration decl =
+                                       doc.CreateXmlDeclaration("1.0", null, 
null);
+                               try
+                               {
+                                       doc.AppendChild(decl);
+                                       Fail("appending XmlDeclaration after 
XmlElement");
+                               }
+                               catch(InvalidOperationException)
+                               {
+                                       // Success
+                               }
+ 
+                               // But adding XmlDeclaration before should 
succeed.
+                               doc.PrependChild(decl);
+ 
+                               // Adding a document type after should fail.
+                               XmlDocumentType type =
+                                       doc.CreateDocumentType("foo", null, 
null, null);
+                               try
+                               {
+                                       doc.AppendChild(type);
+                                       Fail("appending XmlDocumentType");
+                               }
+                               catch(InvalidOperationException)
+                               {
+                                       // Success
+                               }
+ 
+                               // Adding a document type before should succeed.
+                               doc.InsertBefore(type, element);
+                       }
+ 
  }; // class TestXmlDocument
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]