1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
//
// System.Xml.XmlWhitespaceTests.cs
//
// Authors:
// Duncan Mak (duncan@ximian.com)
// Martin Willemoes Hansen (mwh@sysrq.dk)
//
// (C) Ximian, Inc.
// (C) 2003 Martin Willemoes Hansen
//
using System;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.Xml
{
[TestFixture]
public class XmlWhiteSpaceTests
{
XmlDocument document;
XmlDocument doc2;
XmlWhitespace whitespace;
XmlWhitespace broken;
XmlNode original;
XmlNode deep;
XmlNode shallow;
[SetUp]
public void GetReady ()
{
document = new XmlDocument ();
document.LoadXml ("<root><foo></foo></root>");
XmlElement element = document.CreateElement ("foo");
whitespace = document.CreateWhitespace ("\r\n");
element.AppendChild (whitespace);
doc2 = new XmlDocument ();
doc2.PreserveWhitespace = true;
}
[Test]
public void InnerAndOuterXml ()
{
whitespace = doc2.CreateWhitespace ("\r\n\t ");
Assert.AreEqual (String.Empty, whitespace.InnerXml);
Assert.AreEqual ("\r\n\t ", whitespace.OuterXml);
}
internal void XmlNodeBaseProperties (XmlNode original, XmlNode cloned)
{
// assertequals (original.nodetype + " was incorrectly cloned.",
// original.baseuri, cloned.baseuri);
Assert.IsNull (cloned.ParentNode);
Assert.AreEqual (cloned.Value, original.Value, "Value incorrectly cloned");
Assert.IsTrue (!Object.ReferenceEquals (original, cloned), "Copies, not pointers");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void XmlWhitespaceBadConstructor ()
{
broken = document.CreateWhitespace ("black");
}
[Test]
public void XmlWhitespaceConstructor ()
{
Assert.AreEqual ("\r\n", whitespace.Data, "whitespace char didn't get copied right");
}
[Test]
public void XmlWhitespaceName ()
{
Assert.AreEqual (whitespace.Name, "#whitespace", whitespace.NodeType + " Name property broken");
}
[Test]
public void XmlWhitespaceLocalName ()
{
Assert.AreEqual (whitespace.LocalName, "#whitespace", whitespace.NodeType + " LocalName property broken");
}
[Test]
public void XmlWhitespaceNodeType ()
{
Assert.AreEqual (whitespace.NodeType.ToString (), "Whitespace", "XmlWhitespace NodeType property broken");
}
[Test]
public void XmlWhitespaceIsReadOnly ()
{
Assert.AreEqual (whitespace.IsReadOnly, false, "XmlWhitespace IsReadOnly property broken");
}
[Test]
public void XmlWhitespaceCloneNode ()
{
original = whitespace;
shallow = whitespace.CloneNode (false); // shallow
XmlNodeBaseProperties (original, shallow);
deep = whitespace.CloneNode (true); // deep
XmlNodeBaseProperties (original, deep);
Assert.AreEqual (deep.OuterXml, shallow.OuterXml, "deep cloning differs from shallow cloning");
}
}
}
|