diff options
Diffstat (limited to 'mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs')
-rw-r--r-- | mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs | 146 |
1 files changed, 44 insertions, 102 deletions
diff --git a/mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs b/mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs index 5f1240cc16f..783a8ffe718 100644 --- a/mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs +++ b/mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs @@ -250,27 +250,16 @@ namespace MonoTests.System.Xml } [Test] + [Category ("NotDotNet")] public void AttributeNamespacesXmlnsXmlns () { xtw.WriteStartElement ("foo"); - // If XmlTextWriter conforms to "Namespaces in XML" - // when namespaceURI argument is null, then this - // is not allowed (http://www.w3.org/TR/REC-xml-names/ - // Namespace Constraint: Prefix Declared), but seems - // like XmlTextWriter just ignores XML namespace - // constraints when namespaceURI argument is null. - xtw.WriteAttributeString ("xmlns", "xmlns", null, "http://abc.def"); - //Assert.Fail ("A prefix must not start with \"xml\"."); - } - - [Test] - public void AttributeNamespacesXmlnsXmlns2 () - { - // It is split from AttributeNamespacesXmlnsXmlns() - // because depending on XmlWriter it is likely to cause - // duplicate attribute error (XmlTextWriter is pretty - // hacky, so it does not raise such errors). - xtw.WriteStartElement ("foo"); + try { + xtw.WriteAttributeString ("xmlns", "xmlns", null, "http://abc.def"); + // This should not be allowed, even though MS.NET doesn't treat as an error. + // See http://www.w3.org/TR/REC-xml-names/ Namespace Constraint: Prefix Declared + Assert.Fail ("any prefix which name starts from \"xml\" must not be allowed."); + } catch (ArgumentException) {} xtw.WriteAttributeString ("", "xmlns", null, "http://abc.def"); } @@ -822,16 +811,16 @@ namespace MonoTests.System.Xml Assert.AreEqual ("<foo>bar</foo>", StringWriterText, "WriteElementString has incorrect output."); xtw.WriteElementString ("baz", ""); - Assert.AreEqual ("<foo>bar</foo><baz />", StringWriterText, "#2"); + Assert.AreEqual ("<foo>bar</foo><baz />", StringWriterText); xtw.WriteElementString ("quux", null); - Assert.AreEqual ("<foo>bar</foo><baz /><quux />", StringWriterText, "#3"); + Assert.AreEqual ("<foo>bar</foo><baz /><quux />", StringWriterText); xtw.WriteElementString ("", "quuux"); - Assert.AreEqual ("<foo>bar</foo><baz /><quux /><>quuux</>", StringWriterText, "#4"); + Assert.AreEqual ("<foo>bar</foo><baz /><quux /><>quuux</>", StringWriterText); xtw.WriteElementString (null, "quuuux"); - Assert.AreEqual ("<foo>bar</foo><baz /><quux /><>quuux</><>quuuux</>", StringWriterText, "#5"); + Assert.AreEqual ("<foo>bar</foo><baz /><quux /><>quuux</><>quuuux</>", StringWriterText); } [Test] @@ -882,18 +871,18 @@ namespace MonoTests.System.Xml xtw.WriteStartElement ("one"); xtw.WriteAttributeString ("xmlns", "foo", null, "http://abc.def"); xtw.WriteAttributeString ("xmlns", "bar", null, "http://ghi.jkl"); - Assert.AreEqual ("foo", xtw.LookupPrefix ("http://abc.def"), "#1"); - Assert.AreEqual ("bar", xtw.LookupPrefix ("http://ghi.jkl"), "#2"); + Assert.AreEqual ("foo", xtw.LookupPrefix ("http://abc.def")); + Assert.AreEqual ("bar", xtw.LookupPrefix ("http://ghi.jkl")); xtw.WriteEndElement (); xtw.WriteStartElement ("two"); xtw.WriteAttributeString ("xmlns", "baz", null, "http://mno.pqr"); xtw.WriteString("quux"); - Assert.AreEqual ("baz", xtw.LookupPrefix ("http://mno.pqr"), "#3"); - Assert.IsNull (xtw.LookupPrefix ("http://abc.def"), "#4"); - Assert.IsNull (xtw.LookupPrefix ("http://ghi.jkl"), "#5"); + Assert.AreEqual ("baz", xtw.LookupPrefix ("http://mno.pqr")); + Assert.IsNull (xtw.LookupPrefix ("http://abc.def")); + Assert.IsNull (xtw.LookupPrefix ("http://ghi.jkl")); - Assert.IsNull (xtw.LookupPrefix ("http://bogus"), "#6"); + Assert.IsNull (xtw.LookupPrefix ("http://bogus")); } [Test] @@ -1287,9 +1276,6 @@ namespace MonoTests.System.Xml xtw.WriteRaw(""); Assert.AreEqual ("&<>\"'", StringWriterText); - - // bug #77623 - xtw.WriteRaw ("{0}{1}"); } [Test] @@ -1323,7 +1309,6 @@ namespace MonoTests.System.Xml xtw.WriteStartDocument (); try { xtw.WriteString("foo"); - Assert.Fail ("should raise an error."); } catch (InvalidOperationException) {} } @@ -1437,22 +1422,22 @@ namespace MonoTests.System.Xml public void XmlSpaceTest () { xtw.WriteStartElement ("foo"); - Assert.AreEqual (XmlSpace.None, xtw.XmlSpace, "#1"); + Assert.AreEqual (XmlSpace.None, xtw.XmlSpace); xtw.WriteStartElement ("bar"); xtw.WriteAttributeString ("xml", "space", null, "preserve"); - Assert.AreEqual (XmlSpace.Preserve, xtw.XmlSpace, "#2"); - Assert.AreEqual ("<foo><bar xml:space='preserve'", StringWriterText, "#3"); + Assert.AreEqual (XmlSpace.Preserve, xtw.XmlSpace); + Assert.AreEqual ("<foo><bar xml:space='preserve'", StringWriterText); xtw.WriteStartElement ("baz"); xtw.WriteAttributeString ("xml", "space", null, "preserve"); - Assert.AreEqual (XmlSpace.Preserve, xtw.XmlSpace, "#4"); - Assert.AreEqual ("<foo><bar xml:space='preserve'><baz xml:space='preserve'", StringWriterText, "#5"); + Assert.AreEqual (XmlSpace.Preserve, xtw.XmlSpace); + Assert.AreEqual ("<foo><bar xml:space='preserve'><baz xml:space='preserve'", StringWriterText); xtw.WriteStartElement ("quux"); xtw.WriteStartAttribute ("xml", "space", null); - Assert.AreEqual (XmlSpace.Preserve, xtw.XmlSpace, "#6"); - Assert.AreEqual ("<foo><bar xml:space='preserve'><baz xml:space='preserve'><quux xml:space='", StringWriterText, "#7"); + Assert.AreEqual (XmlSpace.Preserve, xtw.XmlSpace); + Assert.AreEqual ("<foo><bar xml:space='preserve'><baz xml:space='preserve'><quux xml:space='", StringWriterText); // Commented out there: it is implementation-dependent // and incompatible between .NET 1.0 and 1.1 @@ -1461,15 +1446,15 @@ namespace MonoTests.System.Xml // Assert.AreEqual ("<foo><bar xml:space='preserve'><baz xml:space='preserve'><quux xml:space='", StringWriterText); xtw.WriteEndAttribute (); - Assert.AreEqual (XmlSpace.Default, xtw.XmlSpace, "#8"); - Assert.AreEqual ("<foo><bar xml:space='preserve'><baz xml:space='preserve'><quux xml:space='default'", StringWriterText, "#9"); + Assert.AreEqual (XmlSpace.Default, xtw.XmlSpace); + Assert.AreEqual ("<foo><bar xml:space='preserve'><baz xml:space='preserve'><quux xml:space='default'", StringWriterText); xtw.WriteEndElement (); - Assert.AreEqual (XmlSpace.Preserve, xtw.XmlSpace, "#10"); + Assert.AreEqual (XmlSpace.Preserve, xtw.XmlSpace); xtw.WriteEndElement (); - Assert.AreEqual (XmlSpace.Preserve, xtw.XmlSpace, "#11"); + Assert.AreEqual (XmlSpace.Preserve, xtw.XmlSpace); xtw.WriteEndElement (); - Assert.AreEqual (XmlSpace.None, xtw.XmlSpace, "#12"); + Assert.AreEqual (XmlSpace.None, xtw.XmlSpace); xtw.WriteStartElement ("quux"); } @@ -1681,9 +1666,9 @@ namespace MonoTests.System.Xml xtw.WriteStartDocument (); xtw.WriteStartElement ("foo"); xtw.WriteAttributeString ("xmlns", "probe"); - Assert.AreEqual (String.Empty, xtw.LookupPrefix ("probe"), "#1"); + Assert.AreEqual (String.Empty, xtw.LookupPrefix ("probe")); xtw.WriteStartElement ("b"); - Assert.AreEqual (String.Empty, xtw.LookupPrefix ("probe"), "#2"); + Assert.AreEqual (String.Empty, xtw.LookupPrefix ("probe")); xtw.WriteStartElement (null, "b2", null); // *Don't* output xmlns="" xtw.WriteEndElement (); // b2 xtw.WriteStartElement (null, "b2", ""); // *Do* output xmlns="" @@ -1693,7 +1678,7 @@ namespace MonoTests.System.Xml xtw.WriteEndDocument (); xtw.Close (); - Assert.AreEqual ("<?xml version='1.0' encoding='utf-16'?><foo xmlns='probe'><b><b2 /><b2 xmlns='' /></b></foo>", StringWriterText, "#3"); + Assert.AreEqual ("<?xml version='1.0' encoding='utf-16'?><foo xmlns='probe'><b><b2 /><b2 xmlns='' /></b></foo>", StringWriterText); } [Test] @@ -1703,19 +1688,19 @@ namespace MonoTests.System.Xml // IMPORTANT DIFFERENCE!! ns = "", not null xtw.WriteStartElement ("foo", ""); xtw.WriteAttributeString ("xmlns", "probe"); - Assert.IsNull (xtw.LookupPrefix ("probe"), "#1"); + Assert.IsNull (xtw.LookupPrefix ("probe")); xtw.WriteStartElement ("b"); - Assert.IsNull (xtw.LookupPrefix ("probe"), "#2"); + Assert.IsNull (xtw.LookupPrefix ("probe")); xtw.WriteStartElement (null, "b2", null); // *Don't* output xmlns="" xtw.WriteEndElement (); // b2 - xtw.WriteStartElement (null, "b2", ""); // *Don't* output xmlns="" + xtw.WriteStartElement (null, "b2", ""); // *Do* output xmlns="" xtw.WriteEndElement (); // b2 xtw.WriteEndElement (); // b xtw.WriteEndElement (); // foo xtw.WriteEndDocument (); xtw.Close (); - Assert.AreEqual ("<?xml version='1.0' encoding='utf-16'?><foo xmlns='probe'><b><b2 /><b2 /></b></foo>", StringWriterText, "#3"); + Assert.AreEqual ("<?xml version='1.0' encoding='utf-16'?><foo xmlns='probe'><b><b2 /><b2 /></b></foo>", StringWriterText); } [Test] @@ -1797,9 +1782,7 @@ namespace MonoTests.System.Xml [ExpectedException (typeof (ArgumentException))] public void AttributeWriteEndAttributeXmlnsNullNs () { - // This test checks if the specified namespace URI is - // incorrectly empty or not. Compare it with - // AttributeWriteStartAttributeXmlnsNullNS(). + // Compare with the test AttributeWriteStartAttributeXmlnsNullNS(). xtw.WriteStartAttribute ("xmlns", "foo", null); xtw.WriteEndAttribute (); } @@ -1899,13 +1882,13 @@ namespace MonoTests.System.Xml xtw.WriteEndElement (); xtw.WriteEndElement (); string xml = sw.ToString (); - Assert.IsTrue (xml.IndexOf ("p:foo='xyz'") > 0, "p:foo" + ". output is " + xml); - Assert.IsTrue (xml.IndexOf ("d1p1:bar='xyz'") > 0, "d1p1:bar" + ". output is " + xml); - Assert.IsTrue (xml.IndexOf ("d1p2:baz='xyz'") > 0, "d1p1:baz" + ". output is " + xml); - Assert.IsTrue (xml.IndexOf ("xmlns:d1p2='urn:baz'") > 0, "xmlns:d1p2" + ". output is " + xml); - Assert.IsTrue (xml.IndexOf ("xmlns:d1p1='urn:bar'") > 0, "xmlns:d1p1" + ". output is " + xml); - Assert.IsTrue (xml.IndexOf ("xmlns:p='urn:foo'") > 0, "xmlns:p" + ". output is " + xml); - Assert.IsTrue (xml.IndexOf ("<out p:foo='xyz'><out p:foo='xyz' /></out></out>") > 0, "remaining" + ". output is " + xml); + Assert.IsTrue (xml.IndexOf ("p:foo='xyz'") > 0, "p:foo"); + Assert.IsTrue (xml.IndexOf ("d1p1:bar='xyz'") > 0, "d1p1:bar"); + Assert.IsTrue (xml.IndexOf ("d1p2:baz='xyz'") > 0, "d1p1:baz"); + Assert.IsTrue (xml.IndexOf ("xmlns:d1p2='urn:baz'") > 0, "xmlns:d1p2"); + Assert.IsTrue (xml.IndexOf ("xmlns:d1p1='urn:bar'") > 0, "xmlns:d1p1"); + Assert.IsTrue (xml.IndexOf ("xmlns:p='urn:foo'") > 0, "xmlns:p"); + Assert.IsTrue (xml.IndexOf ("<out p:foo='xyz'><out p:foo='xyz' /></out></out>") > 0, "remaining"); } [Test] @@ -1932,15 +1915,6 @@ namespace MonoTests.System.Xml } [Test] - [ExpectedException (typeof (ArgumentException))] - // cannot bind any prefix to "http://www.w3.org/2000/xmlns/". - public void WriteQualifiedNameXmlnsError () - { - xtw.WriteStartElement ("foo"); - xtw.WriteQualifiedName ("", "http://www.w3.org/2000/xmlns/"); - } - - [Test] public void WriteDocType () { // we have the following test matrix: @@ -2122,24 +2096,6 @@ namespace MonoTests.System.Xml NUnit.Framework.Assert.AreEqual (referent, ms.ToArray ()); } - [Test] - public void InvalidCharIsWrittenAsSillyReferences () - { - // I can't say how MS XmlTextWriter is silly. - // The expected output is *not* well-formed XML. - // Everyone have to make sure that he or she does - // not write invalid characters directly so that - // the output XML string can be fed by other XML - // processors. - - // The funny thing is that XmlTextWriter spends - // significant performance on checking invalid - // characters, but results in nothing. - xtw.WriteElementString ("a", "\x0"); - NUnit.Framework.Assert.AreEqual ("<a>�</a>", - StringWriterText); - } - [Test] // see also bug #77082 public void WriteDocTypeIndent () { @@ -2185,20 +2141,6 @@ namespace MonoTests.System.Xml xtw.WriteStartDocument (); } - [Test] - public void WriteRawEmptyCloseStartTag () - { - xtw.WriteStartElement ("stream", "stream","http://etherx.jabber.org/streams"); - xtw.WriteAttributeString ("version", "1.0"); - xtw.WriteAttributeString ("to", "me@test.com"); - xtw.WriteAttributeString ("from", "server"); - xtw.WriteAttributeString ("xmlns", "jabber:client"); - xtw.WriteRaw ("");// Ensure that the tag is closed - xtw.Flush (); - - Assert.AreEqual ("<stream:stream version='1.0' to='me@test.com' from='server' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>", StringWriterText); - } - #if NET_2_0 [Test] [ExpectedException (typeof (InvalidOperationException))] |