Correction to previous GetElementsByTagName patch courtesy of Matt Hunter <xrkune...
[mono.git] / mcs / class / System.XML / Test / XmlDeclarationTests.cs
1 //
2 // System.Xml.XmlDeclarationTests.cs
3 //
4 // Author:
5 //      Duncan Mak  (duncan@ximian.com)
6 //
7 // (C) Ximian, Inc.
8 //
9
10 using System;
11 using System.Xml;
12
13 using NUnit.Framework;
14
15 namespace MonoTests.System.Xml
16 {
17         public class XmlDeclarationTests : TestCase
18         {
19
20                 XmlDocument document;
21                 XmlDeclaration declaration;
22                 
23                 public XmlDeclarationTests () : base ("MonoTests.System.Xml.XmlDeclarationTests testsuite") {}
24                 
25                 public XmlDeclarationTests (string name) : base (name) {}
26
27                 protected override void SetUp ()
28                 {
29                         document = new XmlDocument ();
30                         document.LoadXml ("<foo><bar></bar></foo>");
31                         declaration = document.CreateXmlDeclaration ("1.0", null, null);
32                 }
33
34                 public void TestInnerAndOuterXml ()
35                 {
36                         declaration = document.CreateXmlDeclaration ("1.0", null, null);
37                         AssertEquals (String.Empty, declaration.InnerXml);
38                         AssertEquals ("<?xml version=\"1.0\"?>", declaration.OuterXml);
39
40                         declaration = document.CreateXmlDeclaration ("1.0", "doesn't check", null);
41                         AssertEquals (String.Empty, declaration.InnerXml);
42                         AssertEquals ("<?xml version=\"1.0\" encoding=\"doesn't check\"?>", declaration.OuterXml);
43
44                         declaration = document.CreateXmlDeclaration ("1.0", null, "yes");
45                         AssertEquals (String.Empty, declaration.InnerXml);
46                         AssertEquals ("<?xml version=\"1.0\" standalone=\"yes\"?>", declaration.OuterXml);
47
48                         declaration = document.CreateXmlDeclaration ("1.0", "foo", "no");
49                         AssertEquals (String.Empty, declaration.InnerXml);
50                         AssertEquals ("<?xml version=\"1.0\" encoding=\"foo\" standalone=\"no\"?>", declaration.OuterXml);
51                 }
52
53                 internal void TestXmlNodeBaseProperties (XmlNode original, XmlNode cloned)
54                 {
55 //                      assertequals (original.nodetype + " was incorrectly cloned.",
56 //                                    original.baseuri, cloned.baseuri);                        
57                         AssertNull (cloned.ParentNode);
58
59                         AssertEquals ("Value incorrectly cloned",
60                                       original.Value, cloned.Value);
61                         
62                         Assert ("Copies, not pointers", !Object.ReferenceEquals (original,cloned));
63                 }
64
65                 public void TestConstructor ()
66                 {
67                         try {
68                                 XmlDeclaration broken = document.CreateXmlDeclaration ("2.0", null, null);
69                         } catch (ArgumentException) {
70                                 return;
71
72                         } catch (Exception e) {
73                                 Fail("first arg null, wrong exception: " + e.ToString());
74                         }
75                 }
76
77                 public void TestNodeType ()
78                 {
79                         AssertEquals ("incorrect NodeType returned", XmlNodeType.XmlDeclaration, declaration.NodeType);
80                 }
81
82                 public void TestNames ()
83                 {
84                         AssertEquals ("Name is incorrect", "xml", declaration.Name);
85                         AssertEquals ("LocalName is incorrect", "xml", declaration.LocalName);
86                 }
87
88                 public void TestEncodingProperty ()
89                 {
90                         XmlDeclaration d1 = document.CreateXmlDeclaration ("1.0", "foo", null);
91                         AssertEquals ("Encoding property", "foo", d1.Encoding);
92
93                         XmlDeclaration d2 = document.CreateXmlDeclaration ("1.0", null, null);
94                         AssertEquals ("null Encoding property", String.Empty, d2.Encoding);
95                 }
96
97                 public void TestStandaloneProperty ()
98                 {
99                         XmlDeclaration d1 = document.CreateXmlDeclaration ("1.0", null, "yes");
100                         AssertEquals ("Yes standalone property", "yes", d1.Standalone);
101
102                         XmlDeclaration d2 = document.CreateXmlDeclaration ("1.0", null, "no");
103                         AssertEquals ("No standalone property", "no", d2.Standalone);
104
105                         XmlDeclaration d3 = document.CreateXmlDeclaration ("1.0", null, null);
106                         AssertEquals ("null Standalone property", String.Empty, d3.Standalone);
107                 }
108
109                 public void TestValueProperty ()
110                 {
111                         XmlDeclaration d = document.CreateXmlDeclaration ("1.0", "UTF-8", "yes");
112                         AssertEquals ("Value property", "version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"",
113                                       d.Value);
114                 }
115
116                 public void TestXmlCommentCloneNode ()
117                 {
118                         XmlNode original = declaration;
119
120                         XmlNode shallow = declaration.CloneNode (false); // shallow
121                         TestXmlNodeBaseProperties (original, shallow);
122                         
123                         XmlNode deep = declaration.CloneNode (true); // deep
124                         TestXmlNodeBaseProperties (original, deep);
125
126                         AssertEquals ("deep cloning differs from shallow cloning",
127                                       deep.OuterXml, shallow.OuterXml);
128                 }
129         }
130 }