XmlSignificantWhitespaceTests.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // System.Xml.XmlWhitespaceTests.cs
  3. //
  4. // Author:
  5. // Duncan Mak ([email protected])
  6. //
  7. // (C) Ximian, Inc.
  8. //
  9. using System;
  10. using System.Xml;
  11. using NUnit.Framework;
  12. namespace MonoTests.System.Xml
  13. {
  14. public class XmlSignificantWhitespaceTests : TestCase
  15. {
  16. XmlDocument document;
  17. XmlDocument doc2;
  18. XmlSignificantWhitespace whitespace;
  19. XmlSignificantWhitespace broken;
  20. XmlNode original;
  21. XmlNode deep;
  22. XmlNode shallow;
  23. public XmlSignificantWhitespaceTests () : base ("MonoTests.System.Xml.XmlWhitespaceTests testsuite") {}
  24. public XmlSignificantWhitespaceTests (string name) : base (name) {}
  25. protected override void SetUp ()
  26. {
  27. document = new XmlDocument ();
  28. document.LoadXml ("<root><foo></foo></root>");
  29. XmlElement element = document.CreateElement ("foo");
  30. whitespace = document.CreateSignificantWhitespace ("\r\n");
  31. element.AppendChild (whitespace);
  32. doc2 = new XmlDocument ();
  33. }
  34. public void TestInnerAndOuterXml ()
  35. {
  36. whitespace = doc2.CreateSignificantWhitespace ("\r\n\t ");
  37. AssertEquals (String.Empty, whitespace.InnerXml);
  38. AssertEquals ("\r\n\t ", whitespace.OuterXml);
  39. }
  40. public void TestDataAndValue ()
  41. {
  42. string val = "\t\t\r\n ";
  43. whitespace = doc2.CreateSignificantWhitespace (val);
  44. AssertEquals ("#DataValue.1", val, whitespace.Data);
  45. AssertEquals ("#DataValue.2", val, whitespace.Value);
  46. whitespace.Value = val + "\t";
  47. AssertEquals ("#DataValue.3", val + "\t", whitespace.Data);
  48. }
  49. internal void TestXmlNodeBaseProperties (XmlNode original, XmlNode cloned)
  50. {
  51. // assertequals (original.nodetype + " was incorrectly cloned.",
  52. // original.baseuri, cloned.baseuri);
  53. AssertNull (cloned.ParentNode);
  54. AssertEquals ("Value incorrectly cloned",
  55. cloned.Value, original.Value);
  56. Assert ("Copies, not pointers", !Object.ReferenceEquals (original,cloned));
  57. }
  58. public void TestXmlSignificantWhitespaceBadConstructor ()
  59. {
  60. try {
  61. broken = document.CreateSignificantWhitespace ("black");
  62. } catch (ArgumentException) {
  63. return;
  64. } catch (Exception) {
  65. Fail ("Incorrect Exception thrown.");
  66. }
  67. }
  68. public void TestXmlSignificantWhitespaceConstructor ()
  69. {
  70. AssertEquals ("whitespace char didn't get copied right",
  71. "\r\n", whitespace.Data);
  72. }
  73. public void TestXmlSignificantWhitespaceName ()
  74. {
  75. AssertEquals (whitespace.NodeType + " Name property broken",
  76. whitespace.Name, "#significant-whitespace");
  77. }
  78. public void TestXmlSignificantWhitespaceLocalName ()
  79. {
  80. AssertEquals (whitespace.NodeType + " LocalName property broken",
  81. whitespace.LocalName, "#significant-whitespace");
  82. }
  83. public void TestXmlSignificantWhitespaceNodeType ()
  84. {
  85. AssertEquals ("XmlSignificantWhitespace NodeType property broken",
  86. whitespace.NodeType.ToString (), "SignificantWhitespace");
  87. }
  88. public void TestXmlSignificantWhitespaceIsReadOnly ()
  89. {
  90. AssertEquals ("XmlSignificantWhitespace IsReadOnly property broken",
  91. whitespace.IsReadOnly, false);
  92. }
  93. public void TestXmlSignificantWhitespaceCloneNode ()
  94. {
  95. original = whitespace;
  96. shallow = whitespace.CloneNode (false); // shallow
  97. TestXmlNodeBaseProperties (original, shallow);
  98. deep = whitespace.CloneNode (true); // deep
  99. TestXmlNodeBaseProperties (original, deep);
  100. AssertEquals ("deep cloning differs from shallow cloning",
  101. deep.OuterXml, shallow.OuterXml);
  102. }
  103. }
  104. }