XmlParserContextTests.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // Unit tests for System.Xml.XmlParserContext
  3. //
  4. // Authors:
  5. // Gert Driesen ([email protected])
  6. //
  7. // (C) 2008 Gert Driesen
  8. //
  9. using System;
  10. using System.IO;
  11. using System.Text;
  12. using System.Xml;
  13. using NUnit.Framework;
  14. namespace MonoTests.System.Xml
  15. {
  16. [TestFixture]
  17. public class XmlParserContextTests
  18. {
  19. [Test]
  20. public void Constructor1 ()
  21. {
  22. XmlDocument doc = new XmlDocument ();
  23. XmlNamespaceManager ns = new XmlNamespaceManager (doc.NameTable);
  24. XmlParserContext pc = new XmlParserContext (doc.NameTable,
  25. ns, "whatever", XmlSpace.None);
  26. Assert.AreEqual (string.Empty, pc.BaseURI, "#A1");
  27. Assert.AreEqual (string.Empty, pc.DocTypeName, "#A2");
  28. Assert.IsNull (pc.Encoding, "#A3");
  29. Assert.AreEqual (string.Empty, pc.InternalSubset, "#A4");
  30. Assert.AreSame (ns, pc.NamespaceManager, "#A5");
  31. Assert.AreSame (doc.NameTable, pc.NameTable, "#A6");
  32. Assert.AreEqual (string.Empty, pc.PublicId, "#A7");
  33. Assert.AreEqual (string.Empty, pc.SystemId, "#A8");
  34. Assert.AreEqual ("whatever", pc.XmlLang, "#A9");
  35. Assert.AreEqual (XmlSpace.None, pc.XmlSpace, "#A10");
  36. pc = new XmlParserContext ((NameTable) null, (XmlNamespaceManager) null,
  37. (string) null, XmlSpace.None);
  38. Assert.AreEqual (string.Empty, pc.BaseURI, "#B1");
  39. Assert.AreEqual (string.Empty, pc.DocTypeName, "#B2");
  40. Assert.IsNull (pc.Encoding, "#B3");
  41. Assert.AreEqual (string.Empty, pc.InternalSubset, "#B4");
  42. Assert.IsNull (pc.NamespaceManager, "#B5");
  43. Assert.IsNull (pc.NameTable, "#B6");
  44. Assert.AreEqual (string.Empty, pc.PublicId, "#B7");
  45. Assert.AreEqual (string.Empty, pc.SystemId, "#B8");
  46. Assert.AreEqual (string.Empty, pc.XmlLang, "#B9");
  47. Assert.AreEqual (XmlSpace.None, pc.XmlSpace, "#B10");
  48. }
  49. [Test]
  50. public void Constructor2 ()
  51. {
  52. XmlDocument doc = new XmlDocument ();
  53. XmlNamespaceManager ns = new XmlNamespaceManager (doc.NameTable);
  54. XmlParserContext pc = new XmlParserContext (doc.NameTable,
  55. ns, "dunno", XmlSpace.None, Encoding.UTF8);
  56. Assert.AreEqual (string.Empty, pc.BaseURI, "#A1");
  57. Assert.AreEqual (string.Empty, pc.DocTypeName, "#A2");
  58. Assert.AreEqual (Encoding.UTF8, pc.Encoding, "#A3");
  59. Assert.AreEqual (string.Empty, pc.InternalSubset, "#A4");
  60. Assert.AreSame (ns, pc.NamespaceManager, "#A5");
  61. Assert.AreSame (doc.NameTable, pc.NameTable, "#A6");
  62. Assert.AreEqual (string.Empty, pc.PublicId, "#A7");
  63. Assert.AreEqual (string.Empty, pc.SystemId, "#A8");
  64. Assert.AreEqual ("dunno", pc.XmlLang, "#A9");
  65. Assert.AreEqual (XmlSpace.None, pc.XmlSpace, "#A10");
  66. pc = new XmlParserContext ((NameTable) null, (XmlNamespaceManager) null,
  67. (string) null, XmlSpace.None, (Encoding) null);
  68. Assert.AreEqual (string.Empty, pc.BaseURI, "#B1");
  69. Assert.AreEqual (string.Empty, pc.DocTypeName, "#B2");
  70. Assert.IsNull (pc.Encoding, "#B3");
  71. Assert.AreEqual (string.Empty, pc.InternalSubset, "#B4");
  72. Assert.IsNull (pc.NamespaceManager, "#B5");
  73. Assert.IsNull (pc.NameTable, "#B6");
  74. Assert.AreEqual (string.Empty, pc.PublicId, "#B7");
  75. Assert.AreEqual (string.Empty, pc.SystemId, "#B8");
  76. Assert.AreEqual (string.Empty, pc.XmlLang, "#B9");
  77. Assert.AreEqual (XmlSpace.None, pc.XmlSpace, "#B10");
  78. }
  79. [Test]
  80. public void Constructor3 ()
  81. {
  82. XmlDocument doc = new XmlDocument ();
  83. XmlNamespaceManager ns = new XmlNamespaceManager (doc.NameTable);
  84. XmlParserContext pc;
  85. pc = new XmlParserContext (doc.NameTable, ns, "html",
  86. "-//W3C//DTD XHTML 1.0 Strict//EN",
  87. "xhtml1-strict.dtd", "<!-- comment -->", "file://.",
  88. "xa", XmlSpace.Preserve);
  89. Assert.AreEqual ("file://.", pc.BaseURI, "#1");
  90. Assert.AreEqual ("html", pc.DocTypeName, "#2");
  91. Assert.IsNull (pc.Encoding, "#3");
  92. Assert.AreEqual ("<!-- comment -->", pc.InternalSubset, "#4");
  93. Assert.AreSame (ns, pc.NamespaceManager, "#5");
  94. Assert.AreSame (doc.NameTable, pc.NameTable, "#6");
  95. Assert.AreEqual ("-//W3C//DTD XHTML 1.0 Strict//EN", pc.PublicId, "#7");
  96. Assert.AreEqual ("xhtml1-strict.dtd", pc.SystemId, "#8");
  97. Assert.AreEqual ("xa", pc.XmlLang, "#9");
  98. Assert.AreEqual (XmlSpace.Preserve, pc.XmlSpace, "#10");
  99. pc = new XmlParserContext (null, null, (string) null,
  100. (string) null, (string) null, (string) null,
  101. (string) null, (string) null, XmlSpace.Preserve);
  102. Assert.AreEqual (string.Empty, pc.BaseURI, "#B1");
  103. Assert.AreEqual (string.Empty, pc.DocTypeName, "#B2");
  104. Assert.IsNull (pc.Encoding, "#B3");
  105. Assert.AreEqual ("", pc.InternalSubset, "#B4");
  106. Assert.IsNull (pc.NamespaceManager, "#B5");
  107. Assert.IsNull (pc.NameTable, "#B6");
  108. Assert.AreEqual ("", pc.PublicId, "#B7");
  109. Assert.AreEqual ("", pc.SystemId, "#B8");
  110. Assert.AreEqual ("", pc.XmlLang, "#B9");
  111. Assert.AreEqual (XmlSpace.Preserve, pc.XmlSpace, "#B10");
  112. }
  113. [Test]
  114. public void Constructor4 ()
  115. {
  116. XmlDocument doc = new XmlDocument ();
  117. XmlNamespaceManager ns = new XmlNamespaceManager (doc.NameTable);
  118. XmlParserContext pc;
  119. pc = new XmlParserContext (doc.NameTable, ns, "html",
  120. "-//W3C//DTD XHTML 1.0 Strict//EN",
  121. "xhtml1-strict.dtd", string.Empty, "file://.",
  122. string.Empty, XmlSpace.Preserve, Encoding.UTF7);
  123. Assert.AreEqual ("file://.", pc.BaseURI, "#A1");
  124. Assert.AreEqual ("html", pc.DocTypeName, "#A2");
  125. Assert.AreEqual (Encoding.UTF7, pc.Encoding, "#A3");
  126. Assert.AreEqual ("", pc.InternalSubset, "#A4");
  127. Assert.AreSame (ns, pc.NamespaceManager, "#A5");
  128. Assert.AreSame (doc.NameTable, pc.NameTable, "#A6");
  129. Assert.AreEqual ("-//W3C//DTD XHTML 1.0 Strict//EN", pc.PublicId, "#A7");
  130. Assert.AreEqual ("xhtml1-strict.dtd", pc.SystemId, "#A8");
  131. Assert.AreEqual ("", pc.XmlLang, "#A9");
  132. Assert.AreEqual (XmlSpace.Preserve, pc.XmlSpace, "#A10");
  133. pc = new XmlParserContext (null, null,
  134. (string) null, (string) null, (string) null,
  135. (string) null, (string) null, (string) null,
  136. XmlSpace.Preserve, (Encoding) null);
  137. Assert.AreEqual (string.Empty, pc.BaseURI, "#B1");
  138. Assert.AreEqual (string.Empty, pc.DocTypeName, "#B2");
  139. Assert.IsNull (pc.Encoding, "#B3");
  140. Assert.AreEqual ("", pc.InternalSubset, "#B4");
  141. Assert.IsNull (pc.NamespaceManager, "#B5");
  142. Assert.IsNull (pc.NameTable, "#B6");
  143. Assert.AreEqual ("", pc.PublicId, "#B7");
  144. Assert.AreEqual ("", pc.SystemId, "#B8");
  145. Assert.AreEqual ("", pc.XmlLang, "#B9");
  146. Assert.AreEqual (XmlSpace.Preserve, pc.XmlSpace, "#B10");
  147. }
  148. [Test]
  149. public void NameTableConstructor ()
  150. {
  151. NameTable nt = new NameTable ();
  152. XmlNamespaceManager nsmgr = new XmlNamespaceManager (nt);
  153. nsmgr.AddNamespace("Dynamic", "urn:Test");
  154. Assert.IsNotNull (new XmlParserContext (nt, nsmgr,
  155. null, XmlSpace.Default).NameTable, "#1");
  156. Assert.IsNotNull (new XmlParserContext (null, nsmgr,
  157. null, XmlSpace.Default).NameTable, "#2"); // bug #485419
  158. }
  159. }
  160. }