165fb69671d7622a200660cc2e961b60d42f62dd
[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 Ximian.Mono.Tests
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 ("Ximian.Mono.Tests.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                 internal void TestXmlNodeBaseProperties (XmlNode original, XmlNode cloned)
49                 {
50 //                      assertequals (original.nodetype + " was incorrectly cloned.",
51 //                                    original.baseuri, cloned.baseuri);                        
52                         AssertNull (cloned.ParentNode);
53                         AssertEquals ("Value incorrectly cloned",
54                                        cloned.Value, original.Value);
55                         
56                         Assert ("Copies, not pointers", !Object.ReferenceEquals (original,cloned));
57                 }
58
59                 public void TestXmlSignificantWhitespaceBadConstructor ()
60                 {
61                         try {
62                                 broken = document.CreateSignificantWhitespace ("black");                                
63
64                         } catch (ArgumentException) {
65                                 return;
66
67                         } catch (Exception) {
68                                 Fail ("Incorrect Exception thrown.");
69                         }
70                 }
71
72                 public void TestXmlSignificantWhitespaceConstructor ()
73                 {
74                         AssertEquals ("whitespace char didn't get copied right",
75                                       "\r\n", whitespace.Data);
76                 }
77                 
78                
79                 public void TestXmlSignificantWhitespaceName ()
80                 {
81                         AssertEquals (whitespace.NodeType + " Name property broken",
82                                       whitespace.Name, "#significant-whitespace");
83                 }
84
85                 public void TestXmlSignificantWhitespaceLocalName ()
86                 {
87                         AssertEquals (whitespace.NodeType + " LocalName property broken",
88                                       whitespace.LocalName, "#significant-whitespace");
89                 }
90
91                 public void TestXmlSignificantWhitespaceNodeType ()
92                 {
93                         AssertEquals ("XmlSignificantWhitespace NodeType property broken",
94                                       whitespace.NodeType.ToString (), "SignificantWhitespace");
95                 }
96
97                 public void TestXmlSignificantWhitespaceIsReadOnly ()
98                 {
99                         AssertEquals ("XmlSignificantWhitespace IsReadOnly property broken",
100                                       whitespace.IsReadOnly, false);
101                 }
102
103                 public void TestXmlSignificantWhitespaceCloneNode ()
104                 {
105                         original = whitespace;
106
107                         shallow = whitespace.CloneNode (false); // shallow
108                         TestXmlNodeBaseProperties (original, shallow);
109                                                 
110                         deep = whitespace.CloneNode (true); // deep
111                         TestXmlNodeBaseProperties (original, deep); 
112
113                         AssertEquals ("deep cloning differs from shallow cloning",
114                                       deep.OuterXml, shallow.OuterXml);
115                 }
116         }
117 }