2003-01-26 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
[mono.git] / mcs / class / System.XML / Test / XmlDocumentTypeTests.cs
1 //
2 // System.Xml.XmlDocumentTypeTests.cs
3 //
4 // Author: Duncan Mak  (duncan@ximian.com)
5 //
6 // (C) Ximian, Inc.
7 //
8
9 using System;
10 using System.Xml;
11
12 using NUnit.Framework;
13
14 namespace MonoTests.System.Xml
15 {
16         public class XmlDocumentTypeTests : TestCase
17         {
18                 XmlDocument document;
19                 XmlDocumentType docType;
20                 public XmlDocumentTypeTests ()
21                         : base ("MonoTests.System.Xml.XmlDocumentTypeTests testsuite")
22                 {
23                 }
24
25                 public XmlDocumentTypeTests (string name)
26                         : base (name)
27                 {
28                 }
29
30                 protected override void SetUp ()
31                 {
32                         document = new XmlDocument ();
33                         docType = document.CreateDocumentType ("book", null, null, "<!ELEMENT book ANY>");
34                         document.AppendChild (docType);
35                 }
36
37                 internal void TestXmlNodeBaseProperties (XmlNode original, XmlNode cloned)
38                 {
39 //                      assertequals (original.nodetype + " was incorrectly cloned.",
40 //                                    original.baseuri, cloned.baseuri);                        
41
42                         AssertNull (cloned.ParentNode);
43                         AssertEquals ("Value incorrectly cloned",
44                                       original.Value, cloned.Value);
45
46                         Assert ("Copies, not pointers", !Object.ReferenceEquals (original, cloned));
47                 }
48
49                 public void TestName ()
50                 {
51                         AssertEquals ("Getting Name property", "book", docType.Name);
52                 }
53
54                 public void TestLocalName ()
55                 {
56                         AssertEquals ("Getting LocalName property", "book", docType.LocalName);
57                 }
58
59                 public void TestInternalSubset ()
60                 {
61                         AssertEquals ("Getting Internal Subset property",
62                                       "<!ELEMENT book ANY>", docType.InternalSubset);
63                 }
64
65                 public void TestAppendChild ()
66                 {
67                         try {
68                                 XmlDocumentType type1 = document.CreateDocumentType ("book", null, null, null);
69                                 document.AppendChild (type1);
70
71                         } catch (InvalidOperationException) {
72                                 return;
73
74                         } catch (Exception) {                           
75                                 Fail ("Incorrect Exception thrown.");
76                         }
77                 }
78
79                 public void TestNodeType ()
80                 {
81                         AssertEquals ("NodeType property broken",
82                                       docType.NodeType.ToString (), "DocumentType");
83                 }
84                 
85                 public void TestIsReadOnly ()
86                 {
87                         AssertEquals ("IsReadOnly property", "True", docType.IsReadOnly.ToString ());
88                 }
89
90                 public void TestCloneNode ()
91                 {
92                         XmlNode original = docType;
93
94                         XmlNode cloned1 = docType.CloneNode (true);
95                         TestXmlNodeBaseProperties (original, cloned1);
96
97                         XmlNode cloned2 = docType.CloneNode (false);
98                         TestXmlNodeBaseProperties (original, cloned2);
99
100                         AssertEquals ("Deep and shallow cloning", cloned1.Value, cloned2.Value);
101                 }
102                
103         }
104 }