X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.XML%2FTest%2FXmlElementTests.cs;h=734b36108dd49bb62642aa44a2361a4abe5a2979;hb=86ffcfbcd72febcdf6805025ac0e83b7343f3cea;hp=9dbe7c43498c803e74202a3e85f96dd0ef2497bd;hpb=b9e2f23ea54d7fc39449751427b1446ce72f685b;p=mono.git diff --git a/mcs/class/System.XML/Test/XmlElementTests.cs b/mcs/class/System.XML/Test/XmlElementTests.cs index 9dbe7c43498..734b36108dd 100644 --- a/mcs/class/System.XML/Test/XmlElementTests.cs +++ b/mcs/class/System.XML/Test/XmlElementTests.cs @@ -9,14 +9,16 @@ using System; using System.Xml; +using System.IO; +using System.Text; using NUnit.Framework; -namespace Ximian.Mono.Tests +namespace MonoTests.System.Xml { public class XmlElementTests : TestCase { - public XmlElementTests () : base ("Ximian.Mono.Tests.XmlElementTests testsuite") { } + public XmlElementTests () : base ("MonoTests.System.Xml.XmlElementTests testsuite") { } public XmlElementTests (string name) : base (name) { } private XmlDocument document; @@ -37,6 +39,30 @@ namespace Ximian.Mono.Tests //AssertEquals (attributesCount, element.Attributes.Count); } + public void TestCloneNode () + { + XmlElement element = document.CreateElement ("foo"); + XmlElement child = document.CreateElement ("bar"); + XmlElement grandson = document.CreateElement ("baz"); + + element.SetAttribute ("attr1", "val1"); + element.SetAttribute ("attr2", "val2"); + element.AppendChild (child); + child.SetAttribute ("attr3", "val3"); + child.AppendChild (grandson); + + document.AppendChild (element); + XmlNode deep = element.CloneNode (true); + // AssertEquals ("These should be the same", deep.OuterXml, element.OuterXml); + AssertNull ("This is not null", deep.ParentNode); + Assert ("Copies, not pointers", !Object.ReferenceEquals (element,deep)); + + XmlNode shallow = element.CloneNode (false); + AssertNull ("This is not null", shallow.ParentNode); + Assert ("Copies, not pointers", !Object.ReferenceEquals (element,shallow)); + AssertEquals ("Shallow clones shalt have no children!", false, shallow.HasChildNodes); + } + public void TestCreateElement1 () { XmlElement element = document.CreateElement ("name"); @@ -68,6 +94,40 @@ namespace Ximian.Mono.Tests AssertElement (element, "prefix", "localName", "namespaceURI", 0); } + public void TestCreateElement3WithNullNamespace () + { + // bug #26855, NamespaceURI should NEVER be null. + XmlElement element = document.CreateElement (null, "localName", null); + AssertElement (element, String.Empty, "localName", String.Empty, 0); + } + + public void TestInnerAndOuterXml () + { + XmlElement element; + XmlText text; + XmlComment comment; + + element = document.CreateElement ("foo"); + AssertEquals (String.Empty, element.InnerXml); + AssertEquals ("", element.OuterXml); + + text = document.CreateTextNode ("bar"); + element.AppendChild (text); + AssertEquals ("bar", element.InnerXml); + AssertEquals ("bar", element.OuterXml); + + element.SetAttribute ("baz", "quux"); + AssertEquals ("bar", element.InnerXml); + AssertEquals ("bar", element.OuterXml); + + comment = document.CreateComment ("squonk"); + element.AppendChild (comment); + AssertEquals ("bar", element.InnerXml); + AssertEquals ("bar", element.OuterXml); + + + } + public void TestSetGetAttribute () { XmlElement element = document.CreateElement ("foo"); @@ -77,28 +137,50 @@ namespace Ximian.Mono.Tests AssertEquals ("val2", element.GetAttribute ("attr2")); } - public void TestCloneNode () + public void TestGetElementsByTagNameNoNameSpace () { - XmlElement element = document.CreateElement ("foo"); - XmlElement child = document.CreateElement ("bar"); - XmlElement grandson = document.CreateElement ("baz"); + string xml = @"XML FunJohn Doe + 34.95Bear and the Dragon + Tom Clancy6.95 + Bourne IdentityRobert Ludlum + 9.95 + Bourne UltimatumRobert Ludlum + 9.95"; - element.SetAttribute ("attr1", "val1"); - element.SetAttribute ("attr2", "val2"); - element.AppendChild (child); - child.SetAttribute ("attr3", "val3"); - child.AppendChild (grandson); - - document.AppendChild (element); - XmlNode deep = element.CloneNode (true); - // AssertEquals ("These should be the same", deep.OuterXml, element.OuterXml); - AssertNull ("This is not null", deep.ParentNode); - Assert ("Copies, not pointers", !Object.ReferenceEquals (element,deep)); - - XmlNode shallow = element.CloneNode (false); - AssertNull ("This is not null", shallow.ParentNode); - Assert ("Copies, not pointers", !Object.ReferenceEquals (element,shallow)); - AssertEquals ("Shallow clones shalt have no children!", false, shallow.HasChildNodes); + MemoryStream memoryStream = new MemoryStream (Encoding.UTF8.GetBytes (xml)); + document = new XmlDocument (); + document.Load (memoryStream); + XmlNodeList bookList = document.GetElementsByTagName ("book"); + AssertEquals ("GetElementsByTagName (string) returned incorrect count.", 4, bookList.Count); + } + + public void TestGetElementsByTagNameUsingNameSpace () + { + StringBuilder xml = new StringBuilder (); + xml.Append (" "); + xml.Append ("XML Fun " ); + xml.Append ("John Doe " ); + xml.Append ("34.95 " ); + xml.Append (" " ); + xml.Append ("Bear and the Dragon " ); + xml.Append ("Tom Clancy " ); + xml.Append ("6.95 " ); + xml.Append ("Bourne Identity " ); + xml.Append ("Robert Ludlum " ); + xml.Append ("9.95"); + + MemoryStream memoryStream = new MemoryStream (Encoding.UTF8.GetBytes (xml.ToString ())); + document = new XmlDocument (); + document.Load (memoryStream); + XmlNodeList bookList = document.GetElementsByTagName ("book", "http://www.foo.com"); + AssertEquals ("GetElementsByTagName (string, uri) returned incorrect count.", 1, bookList.Count); } + + public void TestOuterXmlWithNamespace () + { + XmlElement element = document.CreateElement ("foo", "bar", "#foo"); + AssertEquals ("", element.OuterXml); + } } }