XmlSignificantWhitespaceTests.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. internal void TestXmlNodeBaseProperties (XmlNode original, XmlNode cloned)
  41. {
  42. // assertequals (original.nodetype + " was incorrectly cloned.",
  43. // original.baseuri, cloned.baseuri);
  44. AssertNull (cloned.ParentNode);
  45. AssertEquals ("Value incorrectly cloned",
  46. cloned.Value, original.Value);
  47. Assert ("Copies, not pointers", !Object.ReferenceEquals (original,cloned));
  48. }
  49. public void TestXmlSignificantWhitespaceBadConstructor ()
  50. {
  51. try {
  52. broken = document.CreateSignificantWhitespace ("black");
  53. } catch (ArgumentException) {
  54. return;
  55. } catch (Exception) {
  56. Fail ("Incorrect Exception thrown.");
  57. }
  58. }
  59. public void TestXmlSignificantWhitespaceConstructor ()
  60. {
  61. AssertEquals ("whitespace char didn't get copied right",
  62. "\r\n", whitespace.Data);
  63. }
  64. public void TestXmlSignificantWhitespaceName ()
  65. {
  66. AssertEquals (whitespace.NodeType + " Name property broken",
  67. whitespace.Name, "#significant-whitespace");
  68. }
  69. public void TestXmlSignificantWhitespaceLocalName ()
  70. {
  71. AssertEquals (whitespace.NodeType + " LocalName property broken",
  72. whitespace.LocalName, "#significant-whitespace");
  73. }
  74. public void TestXmlSignificantWhitespaceNodeType ()
  75. {
  76. AssertEquals ("XmlSignificantWhitespace NodeType property broken",
  77. whitespace.NodeType.ToString (), "SignificantWhitespace");
  78. }
  79. public void TestXmlSignificantWhitespaceIsReadOnly ()
  80. {
  81. AssertEquals ("XmlSignificantWhitespace IsReadOnly property broken",
  82. whitespace.IsReadOnly, false);
  83. }
  84. public void TestXmlSignificantWhitespaceCloneNode ()
  85. {
  86. original = whitespace;
  87. shallow = whitespace.CloneNode (false); // shallow
  88. TestXmlNodeBaseProperties (original, shallow);
  89. deep = whitespace.CloneNode (true); // deep
  90. TestXmlNodeBaseProperties (original, deep);
  91. AssertEquals ("deep cloning differs from shallow cloning",
  92. deep.OuterXml, shallow.OuterXml);
  93. }
  94. }
  95. }