2003-07-26 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
[mono.git] / mcs / class / System.XML / Test / System.Xml / XmlTextWriterTests.cs
index 60b775bc651a7e2b51c848cabed5eef951d25e4b..6a9b8b61556e993d551bafab35884fb808db09e8 100644 (file)
@@ -98,7 +98,7 @@ namespace MonoTests.System.Xml
                                // MS.NET doesn't treat as an error.
                                Fail ("any prefix which name starts from \"xml\" must not be allowed.");
                        }
-                       catch (ArgumentException e) {}
+                       catch (ArgumentException) {}
                        xtw.WriteAttributeString ("", "xmlns", null, "http://abc.def");
                }
 
@@ -199,7 +199,7 @@ namespace MonoTests.System.Xml
                                xtw.WriteCData ("foo");
                                Fail ("WriteCData after Close Should have thrown an InvalidOperationException.");
                        } 
-                       catch (InvalidOperationException e) {
+                       catch (InvalidOperationException) {
                                // Don't rely on English message assertion.
                                // It is enough to check an exception occurs.
 //                             AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
@@ -209,7 +209,7 @@ namespace MonoTests.System.Xml
                                xtw.WriteComment ("foo");
                                Fail ("WriteComment after Close Should have thrown an InvalidOperationException.");
                        } 
-                       catch (InvalidOperationException e) {
+                       catch (InvalidOperationException) {
 //                             AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
                        }
 
@@ -217,7 +217,7 @@ namespace MonoTests.System.Xml
                                xtw.WriteProcessingInstruction ("foo", "bar");
                                Fail ("WriteProcessingInstruction after Close Should have thrown an InvalidOperationException.");
                        } 
-                       catch (InvalidOperationException e) {
+                       catch (InvalidOperationException) {
 //                             AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
                        }
 
@@ -225,7 +225,7 @@ namespace MonoTests.System.Xml
                                xtw.WriteStartElement ("foo", "bar", "baz");
                                Fail ("WriteStartElement after Close Should have thrown an InvalidOperationException.");
                        } 
-                       catch (InvalidOperationException e) {
+                       catch (InvalidOperationException) {
 //                             AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
                        }
 
@@ -234,7 +234,7 @@ namespace MonoTests.System.Xml
                                xtw.WriteAttributeString ("foo", "bar");
                                Fail ("WriteAttributeString after Close Should have thrown an InvalidOperationException.");
                        } 
-                       catch (InvalidOperationException e
+                       catch (InvalidOperationException) 
                        {
 //                             AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
                        }
@@ -243,7 +243,7 @@ namespace MonoTests.System.Xml
                                xtw.WriteString ("foo");
                                Fail ("WriteString after Close Should have thrown an InvalidOperationException.");
                        } 
-                       catch (InvalidOperationException e) {
+                       catch (InvalidOperationException) {
 //                             AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
                        }
                }
@@ -256,11 +256,19 @@ namespace MonoTests.System.Xml
                }
 
                [Test]
-               [ExpectedException (typeof (ArgumentException))]
                public void CommentInvalid ()
                {
-                       xtw.WriteComment("foo-");
-                       xtw.WriteComment("foo-->bar");
+                       try {
+                               xtw.WriteComment("foo-");
+                               Fail("Should have thrown an ArgumentException.");
+                       } 
+                       catch (ArgumentException) { }
+
+                       try {
+                               xtw.WriteComment("foo-->bar");
+                               Fail("Should have thrown an ArgumentException.");
+                       } 
+                       catch (ArgumentException) { }
                }
 
                [Test]
@@ -318,13 +326,23 @@ namespace MonoTests.System.Xml
                }
 
                [Test]
-               [ExpectedException (typeof (InvalidOperationException))]
                public void DocumentStart ()
                {
                        xtw.WriteStartDocument ();
                        AssertEquals ("XmlDeclaration is incorrect.", "<?xml version='1.0' encoding='utf-16'?>", StringWriterText);
 
-                       xtw.WriteStartDocument ();
+                       try 
+                       {
+                               xtw.WriteStartDocument ();
+                               Fail("Should have thrown an InvalidOperationException.");
+                       } 
+                       catch (InvalidOperationException) {
+                               // Don't rely on English message assertion.
+                               // It is enough to check an exception occurs.
+//                             AssertEquals ("Exception message is incorrect.",
+//                                     "WriteStartDocument should be the first call.", e.Message);
+                       }
+
                        xtw = new XmlTextWriter (sw = new StringWriter ());
                        xtw.QuoteChar = '\'';
                        xtw.WriteStartDocument (true);
@@ -446,7 +464,6 @@ namespace MonoTests.System.Xml
                }
 
                [Test]
-               [ExpectedException (typeof (ArgumentException))]
                public void NamespacesElementsPassingInNamespaces ()
                {
                        xtw.Namespaces = false;
@@ -466,12 +483,35 @@ namespace MonoTests.System.Xml
 
                        // These should throw ArgumentException because they pass in a
                        // namespace when Namespaces = false.
-                       xtw.WriteElementString ("qux", "http://netsack.com/", String.Empty);
-                       xtw.WriteStartElement ("foo", "http://netsack.com/");
-                       xtw.WriteStartElement ("foo", "bar", "http://netsack.com/");
-                       xtw.WriteStartElement ("foo", "bar", null);
-                       xtw.WriteStartElement ("foo", "bar", "");
-                       xtw.WriteStartElement ("foo", "", "");
+                       try {
+                               xtw.WriteElementString ("qux", "http://netsack.com/", String.Empty);
+                               Fail ("Expected an ArgumentException.");
+                       } catch (ArgumentException) {}
+
+                       try {
+                               xtw.WriteStartElement ("foo", "http://netsack.com/");
+                               Fail ("Expected an ArgumentException.");
+                       } catch (ArgumentException) {}
+
+                       try {
+                               xtw.WriteStartElement ("foo", "bar", "http://netsack.com/");
+                               Fail ("Expected an ArgumentException.");
+                       } catch (ArgumentException) {}
+
+                       try {
+                               xtw.WriteStartElement ("foo", "bar", null);
+                               Fail ("Expected an ArgumentException.");
+                       } catch (ArgumentException) {}
+
+                       try {
+                               xtw.WriteStartElement ("foo", "bar", "");
+                               Fail ("Expected an ArgumentException.");
+                       } catch (ArgumentException) {}
+
+                       try {
+                               xtw.WriteStartElement ("foo", "", "");
+                               Fail ("Expected an ArgumentException.");
+                       } catch (ArgumentException) {}
                }
 
                [Test]
@@ -499,19 +539,31 @@ namespace MonoTests.System.Xml
                }
 
                [Test]
-               [ExpectedException (typeof (ArgumentException))]
                public void NamespacesPrefixWithEmptyAndNullNamespace ()
                {
-                       xtw.WriteStartElement ("foo", "bar", "");
-                       xtw.WriteStartElement ("foo", "bar", null);
+                       try {
+                               xtw.WriteStartElement ("foo", "bar", "");
+                               Fail ("Should have thrown an ArgumentException.");
+                       } catch (ArgumentException) {}
+
+                       try 
+                       {
+                               xtw.WriteStartElement ("foo", "bar", null);
+                               Fail ("Should have thrown an ArgumentException.");
+                       } 
+                       catch (ArgumentException) {}
                }
 
                [Test]
-               [ExpectedException (typeof (InvalidOperationException))]
                public void NamespacesSettingWhenWriteStateNotStart ()
                {
                        xtw.WriteStartElement ("foo");
-                       xtw.Namespaces = false;
+                       try 
+                       {
+                               xtw.Namespaces = false;
+                               Fail ("Expected an InvalidOperationException.");
+                       } 
+                       catch (InvalidOperationException) {}
                        AssertEquals (true, xtw.Namespaces);
                }
 
@@ -523,13 +575,35 @@ namespace MonoTests.System.Xml
                }
 
                [Test]
-               [ExpectedException (typeof (ArgumentException))]
                public void ProcessingInstructionInvalid ()
                {
-                       xtw.WriteProcessingInstruction("fo?>o", "bar");
-                       xtw.WriteProcessingInstruction("foo", "ba?>r");
-                       xtw.WriteProcessingInstruction("", "bar");
-                       xtw.WriteProcessingInstruction(null, "bar");
+                       try 
+                       {
+                               xtw.WriteProcessingInstruction("fo?>o", "bar");
+                               Fail("Should have thrown an ArgumentException.");
+                       } 
+                       catch (ArgumentException) { }
+
+                       try 
+                       {
+                               xtw.WriteProcessingInstruction("foo", "ba?>r");
+                               Fail("Should have thrown an ArgumentException.");
+                       } 
+                       catch (ArgumentException) { }
+
+                       try 
+                       {
+                               xtw.WriteProcessingInstruction("", "bar");
+                               Fail("Should have thrown an ArgumentException.");
+                       } 
+                       catch (ArgumentException) { }
+
+                       try 
+                       {
+                               xtw.WriteProcessingInstruction(null, "bar");
+                               Fail("Should have thrown an ArgumentException.");
+                       } 
+                       catch (ArgumentException) { }
                }
 
                [Test]
@@ -585,7 +659,6 @@ namespace MonoTests.System.Xml
                }
 
                [Test]
-               [ExpectedException (typeof (ArgumentException))]
                public void WriteCharEntity ()
                {
                        xtw.WriteCharEntity ('a');
@@ -600,7 +673,9 @@ namespace MonoTests.System.Xml
                        xtw.WriteCharEntity ('K');
                        AssertEquals ("&#x61;&#x41;&#x31;&#x4B;", StringWriterText);
 
-                       xtw.WriteCharEntity ((char)0xd800);
+                       try {
+                               xtw.WriteCharEntity ((char)0xd800);
+                       } catch (ArgumentException) {}
                }
 
                [Test]
@@ -611,12 +686,21 @@ namespace MonoTests.System.Xml
                }
 
                [Test]
-               [ExpectedException (typeof (ArgumentException))]
                public void WriteEndDocument ()
                {
-                       xtw.WriteEndDocument ();
+                       try {
+                               xtw.WriteEndDocument ();
+                               Fail ("Expected an ArgumentException.");
+                       } catch (ArgumentException) {}
+
                        xtw.WriteStartDocument ();
-                       xtw.WriteEndDocument ();
+
+                       try 
+                       {
+                               xtw.WriteEndDocument ();
+                               Fail ("Expected an ArgumentException.");
+                       } 
+                       catch (ArgumentException) {}
 
                        xtw.WriteStartElement ("foo");
                        xtw.WriteStartAttribute ("bar", null);
@@ -628,13 +712,16 @@ namespace MonoTests.System.Xml
                }
 
                [Test]
-               [ExpectedException (typeof (InvalidOperationException))]
                public void WriteEndElement ()
                {
-                       xtw.WriteEndElement ();
-                       // Don't rely on English message assertion.
-                       // It is enough to check an exception occurs.
-                       // AssertEquals ("Exception message is incorrect.", "There was no XML start tag open.", e.Message);
+                       try {
+                               xtw.WriteEndElement ();
+                               Fail ("Should have thrown an InvalidOperationException.");
+                       } catch (InvalidOperationException) {
+                               // Don't rely on English message assertion.
+                               // It is enough to check an exception occurs.
+//                             AssertEquals ("Exception message is incorrect.", "There was no XML start tag open.", e.Message);
+                       }
 
                        xtw.WriteStartElement ("foo");
                        xtw.WriteEndElement ();
@@ -714,11 +801,12 @@ namespace MonoTests.System.Xml
                }
 
                [Test]
-               [ExpectedException (typeof (InvalidOperationException))]
                public void WriteString ()
                {
                        xtw.WriteStartDocument ();
-                       xtw.WriteString("foo");
+                       try {
+                               xtw.WriteString("foo");
+                       } catch (InvalidOperationException) {}
 
                        // Testing attribute values
 
@@ -967,5 +1055,16 @@ namespace MonoTests.System.Xml
                        xtw.WriteWhitespace (" ");
                        AssertEquals ("<foo bar='baz'> ", StringWriterText);
                }
+
+               [Test]
+               public void DontOutputMultipleXmlns ()
+               {
+                       XmlDocument doc = new XmlDocument();\r
+                       doc.LoadXml("<a xmlns:dt=\"b\" dt:dt=\"c\"/>");\r
+                       XmlDocument doc2 = new XmlDocument();\r
+                       doc2.LoadXml(doc.InnerXml);
+                       AssertEquals ("<a xmlns:dt=\"b\" dt:dt=\"c\" />",
+                               doc2.OuterXml);
+               }
        }
 }