Welcome to mirror list, hosted at ThFree Co, Russian Federation.

XmlSignificantWhitespaceTests.cs « System.Xml « Test « System.XML « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7d631df30b6d323b8ecc3c945d1b56d961489e55 (plain)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// 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 XmlSignificantWhitespaceTests
	{
		XmlDocument document;
		XmlDocument doc2;
		XmlSignificantWhitespace whitespace;
		XmlSignificantWhitespace 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.CreateSignificantWhitespace ("\r\n");
			element.AppendChild (whitespace);

			doc2 = new XmlDocument ();
		}

		[Test]
		public void InnerAndOuterXml ()
		{
			whitespace = doc2.CreateSignificantWhitespace ("\r\n\t ");
			Assert.AreEqual (String.Empty, whitespace.InnerXml);
			Assert.AreEqual ("\r\n\t ", whitespace.OuterXml);
		}

		[Test]
		public void DataAndValue ()
		{
			string val = "\t\t\r\n ";
			whitespace = doc2.CreateSignificantWhitespace (val);
			Assert.AreEqual (val, whitespace.Data, "#DataValue.1");
			Assert.AreEqual (val, whitespace.Value, "#DataValue.2");
			whitespace.Value = val + "\t";
			Assert.AreEqual (val + "\t", whitespace.Data, "#DataValue.3");
		}
			
		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]
		public void XmlSignificantWhitespaceBadConstructor ()
		{
			try {
				broken = document.CreateSignificantWhitespace ("black");				

			} catch (ArgumentException) {
				return;

			} catch (Exception) {
				Assert.Fail ("Incorrect Exception thrown.");
			}
		}

		[Test]
		public void XmlSignificantWhitespaceConstructor ()
		{
			Assert.AreEqual ("\r\n", whitespace.Data, "whitespace char didn't get copied right");
		}
		
	       	[Test]
		public void XmlSignificantWhitespaceName ()
		{
			Assert.AreEqual (whitespace.Name, "#significant-whitespace", whitespace.NodeType + " Name property broken");
		}

		[Test]
		public void XmlSignificantWhitespaceLocalName ()
		{
			Assert.AreEqual (whitespace.LocalName, "#significant-whitespace", whitespace.NodeType + " LocalName property broken");
		}

		[Test]
		public void XmlSignificantWhitespaceNodeType ()
		{
			Assert.AreEqual (whitespace.NodeType.ToString (), "SignificantWhitespace", "XmlSignificantWhitespace NodeType property broken");
		}

		[Test]
		public void XmlSignificantWhitespaceIsReadOnly ()
		{
			Assert.AreEqual (whitespace.IsReadOnly, false, "XmlSignificantWhitespace IsReadOnly property broken");
		}

		[Test]
		public void XmlSignificantWhitespaceCloneNode ()
		{
			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");
		}
	}
}