2002-12-01 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
[mono.git] / mcs / class / System.XML / Test / XmlSignificantWhitespaceTests.cs
1 //
2 // System.Xml.XmlWhitespaceTests.cs
3 //
4 // Author:
5 //      Duncan Mak  (duncan@ximian.com)
6 //
7 // (C) Ximian, Inc.
8 //
9
10 using System;
11 using System.Xml;
12
13 using NUnit.Framework;
14
15 namespace MonoTests.System.Xml
16 {
17         public class XmlSignificantWhitespaceTests : TestCase
18         {
19                 XmlDocument document;
20                 XmlDocument doc2;
21                 XmlSignificantWhitespace whitespace;
22                 XmlSignificantWhitespace broken;
23                 XmlNode original;
24                 XmlNode deep;
25                 XmlNode shallow;
26                 
27                 public XmlSignificantWhitespaceTests () : base ("MonoTests.System.Xml.XmlWhitespaceTests testsuite") {}
28                 public XmlSignificantWhitespaceTests (string name) : base (name) {}
29
30                 protected override void SetUp ()
31                 {
32                         document = new XmlDocument ();
33                         document.LoadXml ("<root><foo></foo></root>");
34                         XmlElement element = document.CreateElement ("foo");
35                         whitespace = document.CreateSignificantWhitespace ("\r\n");
36                         element.AppendChild (whitespace);
37
38                         doc2 = new XmlDocument ();
39                 }
40
41                 public void TestInnerAndOuterXml ()
42                 {
43                         whitespace = doc2.CreateSignificantWhitespace ("\r\n\t ");
44                         AssertEquals (String.Empty, whitespace.InnerXml);
45                         AssertEquals ("\r\n\t ", whitespace.OuterXml);
46                 }
47
48                 public void TestDataAndValue ()
49                 {
50                         string val = "\t\t\r\n ";
51                         whitespace = doc2.CreateSignificantWhitespace (val);
52                         AssertEquals ("#DataValue.1", val, whitespace.Data);
53                         AssertEquals ("#DataValue.2", val, whitespace.Value);
54                         whitespace.Value = val + "\t";
55                         AssertEquals ("#DataValue.3", val + "\t", whitespace.Data);
56                 }
57                         
58                 internal void TestXmlNodeBaseProperties (XmlNode original, XmlNode cloned)
59                 {
60 //                      assertequals (original.nodetype + " was incorrectly cloned.",
61 //                                    original.baseuri, cloned.baseuri);                        
62                         AssertNull (cloned.ParentNode);
63                         AssertEquals ("Value incorrectly cloned",
64                                        cloned.Value, original.Value);
65                         
66                         Assert ("Copies, not pointers", !Object.ReferenceEquals (original,cloned));
67                 }
68
69                 public void TestXmlSignificantWhitespaceBadConstructor ()
70                 {
71                         try {
72                                 broken = document.CreateSignificantWhitespace ("black");                                
73
74                         } catch (ArgumentException) {
75                                 return;
76
77                         } catch (Exception) {
78                                 Fail ("Incorrect Exception thrown.");
79                         }
80                 }
81
82                 public void TestXmlSignificantWhitespaceConstructor ()
83                 {
84                         AssertEquals ("whitespace char didn't get copied right",
85                                       "\r\n", whitespace.Data);
86                 }
87                 
88                
89                 public void TestXmlSignificantWhitespaceName ()
90                 {
91                         AssertEquals (whitespace.NodeType + " Name property broken",
92                                       whitespace.Name, "#significant-whitespace");
93                 }
94
95                 public void TestXmlSignificantWhitespaceLocalName ()
96                 {
97                         AssertEquals (whitespace.NodeType + " LocalName property broken",
98                                       whitespace.LocalName, "#significant-whitespace");
99                 }
100
101                 public void TestXmlSignificantWhitespaceNodeType ()
102                 {
103                         AssertEquals ("XmlSignificantWhitespace NodeType property broken",
104                                       whitespace.NodeType.ToString (), "SignificantWhitespace");
105                 }
106
107                 public void TestXmlSignificantWhitespaceIsReadOnly ()
108                 {
109                         AssertEquals ("XmlSignificantWhitespace IsReadOnly property broken",
110                                       whitespace.IsReadOnly, false);
111                 }
112
113                 public void TestXmlSignificantWhitespaceCloneNode ()
114                 {
115                         original = whitespace;
116
117                         shallow = whitespace.CloneNode (false); // shallow
118                         TestXmlNodeBaseProperties (original, shallow);
119                                                 
120                         deep = whitespace.CloneNode (true); // deep
121                         TestXmlNodeBaseProperties (original, deep); 
122
123                         AssertEquals ("deep cloning differs from shallow cloning",
124                                       deep.OuterXml, shallow.OuterXml);
125                 }
126         }
127 }