XmlCommentTests.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // System.Xml.XmlCommentTests.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 XmlCommentTests : TestCase
  15. {
  16. XmlDocument document;
  17. XmlComment comment;
  18. XmlNode original;
  19. XmlNode deep;
  20. XmlNode shallow;
  21. public XmlCommentTests () : base ("MonoTests.System.Xml.XmlCommentTests testsuite") {}
  22. public XmlCommentTests (string name) : base (name) {}
  23. protected override void SetUp ()
  24. {
  25. document = new XmlDocument ();
  26. }
  27. public void TestXmlCommentCloneNode ()
  28. {
  29. document.LoadXml ("<root><foo></foo></root>");
  30. comment = document.CreateComment ("Comment");
  31. original = comment;
  32. shallow = comment.CloneNode (false); // shallow
  33. TestXmlNodeBaseProperties (original, shallow);
  34. deep = comment.CloneNode (true); // deep
  35. TestXmlNodeBaseProperties (original, deep);
  36. AssertEquals ("Value incorrectly cloned",
  37. original.Value, deep.Value);
  38. AssertEquals ("deep cloning differs from shallow cloning",
  39. deep.OuterXml, shallow.OuterXml);
  40. }
  41. public void TestXmlCommentInnerAndOuterXml ()
  42. {
  43. comment = document.CreateComment ("foo");
  44. AssertEquals (String.Empty, comment.InnerXml);
  45. AssertEquals ("<!--foo-->", comment.OuterXml);
  46. }
  47. public void TestXmlCommentIsReadOnly ()
  48. {
  49. document.LoadXml ("<root><foo></foo></root>");
  50. comment = document.CreateComment ("Comment");
  51. AssertEquals ("XmlComment IsReadOnly property broken",
  52. comment.IsReadOnly, false);
  53. }
  54. public void TestXmlCommentLocalName ()
  55. {
  56. document.LoadXml ("<root><foo></foo></root>");
  57. comment = document.CreateComment ("Comment");
  58. AssertEquals (comment.NodeType + " LocalName property broken",
  59. comment.LocalName, "#comment");
  60. }
  61. public void TestXmlCommentName ()
  62. {
  63. document.LoadXml ("<root><foo></foo></root>");
  64. comment = document.CreateComment ("Comment");
  65. AssertEquals (comment.NodeType + " Name property broken",
  66. comment.Name, "#comment");
  67. }
  68. public void TestXmlCommentNodeType ()
  69. {
  70. document.LoadXml ("<root><foo></foo></root>");
  71. comment = document.CreateComment ("Comment");
  72. AssertEquals ("XmlComment NodeType property broken",
  73. comment.NodeType.ToString (), "Comment");
  74. }
  75. internal void TestXmlNodeBaseProperties (XmlNode original, XmlNode cloned)
  76. {
  77. document.LoadXml ("<root><foo></foo></root>");
  78. comment = document.CreateComment ("Comment");
  79. // assertequals (original.nodetype + " was incorrectly cloned.",
  80. // original.baseuri, cloned.baseuri);
  81. AssertNull (cloned.ParentNode);
  82. AssertEquals ("Value incorrectly cloned",
  83. original.Value, cloned.Value);
  84. Assert ("Copies, not pointers", !Object.ReferenceEquals (original,cloned));
  85. }
  86. }
  87. }