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

XmlParserContextTests.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: 8665c965fd34314c90d3824c190120ebff467bda (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//
// Unit tests for System.Xml.XmlParserContext
//
// Authors:
//   Gert Driesen (drieseng@users.sourceforge.net)
//
// (C) 2008 Gert Driesen
//

using System;
using System.IO;
using System.Text;
using System.Xml;

using NUnit.Framework;

namespace MonoTests.System.Xml
{
	[TestFixture]
	public class XmlParserContextTests
	{
		[Test]
		public void Constructor1 ()
		{
			XmlDocument doc = new XmlDocument ();
			XmlNamespaceManager ns = new XmlNamespaceManager (doc.NameTable);

			XmlParserContext pc = new XmlParserContext (doc.NameTable,
				ns, "whatever", XmlSpace.None);
			Assert.AreEqual (string.Empty, pc.BaseURI, "#A1");
			Assert.AreEqual (string.Empty, pc.DocTypeName, "#A2");
			Assert.IsNull (pc.Encoding, "#A3");
			Assert.AreEqual (string.Empty, pc.InternalSubset, "#A4");
			Assert.AreSame (ns, pc.NamespaceManager, "#A5");
			Assert.AreSame (doc.NameTable, pc.NameTable, "#A6");
			Assert.AreEqual (string.Empty, pc.PublicId, "#A7");
			Assert.AreEqual (string.Empty, pc.SystemId, "#A8");
			Assert.AreEqual ("whatever", pc.XmlLang, "#A9");
			Assert.AreEqual (XmlSpace.None, pc.XmlSpace, "#A10");

			pc = new XmlParserContext ((NameTable) null, (XmlNamespaceManager) null,
				(string) null, XmlSpace.None);
			Assert.AreEqual (string.Empty, pc.BaseURI, "#B1");
			Assert.AreEqual (string.Empty, pc.DocTypeName, "#B2");
			Assert.IsNull (pc.Encoding, "#B3");
			Assert.AreEqual (string.Empty, pc.InternalSubset, "#B4");
			Assert.IsNull (pc.NamespaceManager, "#B5");
			Assert.IsNull (pc.NameTable, "#B6");
			Assert.AreEqual (string.Empty, pc.PublicId, "#B7");
			Assert.AreEqual (string.Empty, pc.SystemId, "#B8");
			Assert.AreEqual (string.Empty, pc.XmlLang, "#B9");
			Assert.AreEqual (XmlSpace.None, pc.XmlSpace, "#B10");
		}

		[Test]
		public void Constructor2 ()
		{
			XmlDocument doc = new XmlDocument ();
			XmlNamespaceManager ns = new XmlNamespaceManager (doc.NameTable);

			XmlParserContext pc = new XmlParserContext (doc.NameTable,
				ns, "dunno", XmlSpace.None, Encoding.UTF8);
			Assert.AreEqual (string.Empty, pc.BaseURI, "#A1");
			Assert.AreEqual (string.Empty, pc.DocTypeName, "#A2");
			Assert.AreEqual (Encoding.UTF8, pc.Encoding, "#A3");
			Assert.AreEqual (string.Empty, pc.InternalSubset, "#A4");
			Assert.AreSame (ns, pc.NamespaceManager, "#A5");
			Assert.AreSame (doc.NameTable, pc.NameTable, "#A6");
			Assert.AreEqual (string.Empty, pc.PublicId, "#A7");
			Assert.AreEqual (string.Empty, pc.SystemId, "#A8");
			Assert.AreEqual ("dunno", pc.XmlLang, "#A9");
			Assert.AreEqual (XmlSpace.None, pc.XmlSpace, "#A10");

			pc = new XmlParserContext ((NameTable) null, (XmlNamespaceManager) null,
				(string) null, XmlSpace.None, (Encoding) null);
			Assert.AreEqual (string.Empty, pc.BaseURI, "#B1");
			Assert.AreEqual (string.Empty, pc.DocTypeName, "#B2");
			Assert.IsNull (pc.Encoding, "#B3");
			Assert.AreEqual (string.Empty, pc.InternalSubset, "#B4");
			Assert.IsNull (pc.NamespaceManager, "#B5");
			Assert.IsNull (pc.NameTable, "#B6");
			Assert.AreEqual (string.Empty, pc.PublicId, "#B7");
			Assert.AreEqual (string.Empty, pc.SystemId, "#B8");
			Assert.AreEqual (string.Empty, pc.XmlLang, "#B9");
			Assert.AreEqual (XmlSpace.None, pc.XmlSpace, "#B10");
		}

		[Test]
		public void Constructor3 ()
		{
			XmlDocument doc = new XmlDocument ();
			XmlNamespaceManager ns = new XmlNamespaceManager (doc.NameTable);
			XmlParserContext pc;

			pc = new XmlParserContext (doc.NameTable, ns, "html",
				"-//W3C//DTD XHTML 1.0 Strict//EN",
				"xhtml1-strict.dtd", "<!-- comment -->", "file://.",
				"xa", XmlSpace.Preserve);
			Assert.AreEqual ("file://.", pc.BaseURI, "#1");
			Assert.AreEqual ("html", pc.DocTypeName, "#2");
			Assert.IsNull (pc.Encoding, "#3");
			Assert.AreEqual ("<!-- comment -->", pc.InternalSubset, "#4");
			Assert.AreSame (ns, pc.NamespaceManager, "#5");
			Assert.AreSame (doc.NameTable, pc.NameTable, "#6");
			Assert.AreEqual ("-//W3C//DTD XHTML 1.0 Strict//EN", pc.PublicId, "#7");
			Assert.AreEqual ("xhtml1-strict.dtd", pc.SystemId, "#8");
			Assert.AreEqual ("xa", pc.XmlLang, "#9");
			Assert.AreEqual (XmlSpace.Preserve, pc.XmlSpace, "#10");

			pc = new XmlParserContext (null, null, (string) null,
				(string) null, (string) null, (string) null,
				(string) null, (string) null, XmlSpace.Preserve);
			Assert.AreEqual (string.Empty, pc.BaseURI, "#B1");
			Assert.AreEqual (string.Empty, pc.DocTypeName, "#B2");
			Assert.IsNull (pc.Encoding, "#B3");
			Assert.AreEqual ("", pc.InternalSubset, "#B4");
			Assert.IsNull (pc.NamespaceManager, "#B5");
			Assert.IsNull (pc.NameTable, "#B6");
			Assert.AreEqual ("", pc.PublicId, "#B7");
			Assert.AreEqual ("", pc.SystemId, "#B8");
			Assert.AreEqual ("", pc.XmlLang, "#B9");
			Assert.AreEqual (XmlSpace.Preserve, pc.XmlSpace, "#B10");
		}

		[Test]
		public void Constructor4 ()
		{
			XmlDocument doc = new XmlDocument ();
			XmlNamespaceManager ns = new XmlNamespaceManager (doc.NameTable);
			XmlParserContext pc;

			pc = new XmlParserContext (doc.NameTable, ns, "html",
				"-//W3C//DTD XHTML 1.0 Strict//EN",
				"xhtml1-strict.dtd", string.Empty, "file://.",
				string.Empty, XmlSpace.Preserve, Encoding.UTF7);
			Assert.AreEqual ("file://.", pc.BaseURI, "#A1");
			Assert.AreEqual ("html", pc.DocTypeName, "#A2");
			Assert.AreEqual (Encoding.UTF7, pc.Encoding, "#A3");
			Assert.AreEqual ("", pc.InternalSubset, "#A4");
			Assert.AreSame (ns, pc.NamespaceManager, "#A5");
			Assert.AreSame (doc.NameTable, pc.NameTable, "#A6");
			Assert.AreEqual ("-//W3C//DTD XHTML 1.0 Strict//EN", pc.PublicId, "#A7");
			Assert.AreEqual ("xhtml1-strict.dtd", pc.SystemId, "#A8");
			Assert.AreEqual ("", pc.XmlLang, "#A9");
			Assert.AreEqual (XmlSpace.Preserve, pc.XmlSpace, "#A10");

			pc = new XmlParserContext (null, null,
				(string) null, (string) null, (string) null,
				(string) null, (string) null, (string) null,
				XmlSpace.Preserve, (Encoding) null);
			Assert.AreEqual (string.Empty, pc.BaseURI, "#B1");
			Assert.AreEqual (string.Empty, pc.DocTypeName, "#B2");
			Assert.IsNull (pc.Encoding, "#B3");
			Assert.AreEqual ("", pc.InternalSubset, "#B4");
			Assert.IsNull (pc.NamespaceManager, "#B5");
			Assert.IsNull (pc.NameTable, "#B6");
			Assert.AreEqual ("", pc.PublicId, "#B7");
			Assert.AreEqual ("", pc.SystemId, "#B8");
			Assert.AreEqual ("", pc.XmlLang, "#B9");
			Assert.AreEqual (XmlSpace.Preserve, pc.XmlSpace, "#B10");
		}

		[Test]
		public void NameTableConstructor ()
		{
			NameTable nt = new NameTable ();
			XmlNamespaceManager nsmgr = new XmlNamespaceManager (nt);
			nsmgr.AddNamespace("Dynamic", "urn:Test");
			Assert.IsNotNull (new XmlParserContext (nt, nsmgr,
null, XmlSpace.Default).NameTable, "#1");
			Assert.IsNotNull (new XmlParserContext (null, nsmgr,
null, XmlSpace.Default).NameTable, "#2"); // bug #485419
		}
	}
}