Work on XmlDocument and XmlTextWriter
[mono.git] / mcs / class / System.XML / Test / XmlTextWriterTests.cs
1 //
2 // System.Xml.XmlTextWriterTests
3 //
4 // Author:
5 //   Kral Ferch <kral_ferch@hotmail.com>
6 //
7 // (C) 2002 Kral Ferch
8 //
9
10 using System;
11 using System.IO;
12 using System.Xml;
13
14 using NUnit.Framework;
15
16 namespace Ximian.Mono.Tests
17 {
18         public class XmlTextWriterTests : TestCase
19         {
20                 public XmlTextWriterTests () : base ("Ximian.Mono.Tests.XmlTextWriterTests testsuite") {}
21                 public XmlTextWriterTests (string name) : base (name) {}
22
23                 StringWriter sw;
24                 XmlTextWriter xtw;
25
26                 protected override void SetUp ()
27                 {
28                         sw = new StringWriter ();
29                         xtw = new XmlTextWriter (sw);
30                 }
31
32                 public void TestCData ()
33                 {
34                         xtw.WriteCData ("foo");
35                         AssertEquals ("WriteCData had incorrect output.", sw.GetStringBuilder().ToString(), "<![CDATA[foo]]>");
36                 }
37
38                 public void TestComment ()
39                 {
40                         xtw.WriteComment ("foo");
41                         AssertEquals ("WriteComment had incorrect output.", "<!--foo-->", sw.GetStringBuilder().ToString());
42                 }
43
44                 public void TestElementEmpty ()
45                 {
46                         xtw.WriteStartElement ("foo");
47                         xtw.WriteEndElement ();
48                         AssertEquals ("Incorrect output.", "<foo />", sw.GetStringBuilder().ToString());
49                 }
50
51                 public void TestElementWriteElementString ()
52                 {
53                         xtw.WriteElementString ("foo", "bar");
54                         AssertEquals ("WriteElementString has incorrect output.", "<foo>bar</foo>", sw.GetStringBuilder().ToString());
55                 }
56
57                 public void TestProcessingInstructionInvalid ()
58                 {
59                         try {
60                                 xtw.WriteProcessingInstruction("fo?>o", "bar");
61                                 Fail("Should have thrown an ArgumentException.");
62                         } catch (ArgumentException) { }
63
64                         try {
65                                 xtw.WriteProcessingInstruction("foo", "ba?>r");
66                                 Fail("Should have thrown an ArgumentException.");
67                         } catch (ArgumentException) { }
68
69                         try {
70                                 xtw.WriteProcessingInstruction("", "bar");
71                                 Fail("Should have thrown an ArgumentException.");
72                         } catch (ArgumentException) { }
73
74                         try {
75                                 xtw.WriteProcessingInstruction(null, "bar");
76                                 Fail("Should have thrown an ArgumentException.");
77                         } catch (ArgumentException) { }
78                 }
79         }
80 }