Can now scan most location paths (without predicates).
[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 Ximian.Mono.Tests
16 {
17         public class XmlDeclarationTests : TestCase
18         {
19
20                 XmlDocument document;
21                 XmlDeclaration declaration;
22                 
23                 public XmlDeclarationTests ()
24                         : base ("Ximian.Mono.Tests.XmlDeclarationTests testsuite")
25                 {
26                 }
27                 
28                 public XmlDeclarationTests (string name)
29                         : base (name)
30                 {
31                 }
32
33                 protected override void SetUp ()
34                 {
35                         document = new XmlDocument ();
36                         document.LoadXml ("<foo><bar></bar></foo>");
37                         declaration = document.CreateXmlDeclaration ("1.0", null, null);
38                 }
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
46                         AssertEquals ("Value incorrectly cloned",
47                                       original.Value, cloned.Value);
48                         
49                         Assert ("Copies, not pointers", !Object.ReferenceEquals (original,cloned));
50                 }
51
52                 public void TestConstructor ()
53                 {
54                         try {
55                                 XmlDeclaration broken = document.CreateXmlDeclaration ("2.0", null, null);
56                         } catch (Exception e) {
57                                 AssertEquals ("Wrong exception was thrown",
58                                               e.GetType (), Type.GetType ("System.ArgumentException"));
59                         }
60                 }
61
62                 public void TestNodeType ()
63                 {
64                         AssertEquals ("incorrect NodeType returned", XmlNodeType.XmlDeclaration, declaration.NodeType);
65                 }
66
67                 public void TestNames ()
68                 {
69                         AssertEquals ("Name is incorrect", "xml", declaration.Name);
70                         AssertEquals ("LocalName is incorrect", "xml", declaration.LocalName);
71                 }
72
73                 public void TestEncodingProperty ()
74                 {
75                         XmlDeclaration d1 = document.CreateXmlDeclaration ("1.0", "foo", null);
76                         AssertEquals ("Encoding property", "foo", d1.Encoding);
77
78                         XmlDeclaration d2 = document.CreateXmlDeclaration ("1.0", null, null);
79                         AssertEquals ("null Encoding property", String.Empty, d2.Encoding);
80                 }
81
82                 public void TestStandaloneProperty ()
83                 {
84                         XmlDeclaration d1 = document.CreateXmlDeclaration ("1.0", null, "yes");
85                         AssertEquals ("Yes standalone property", "yes", d1.Standalone);
86
87                         XmlDeclaration d2 = document.CreateXmlDeclaration ("1.0", null, "no");
88                         AssertEquals ("No standalone property", "no", d2.Standalone);
89
90                         XmlDeclaration d3 = document.CreateXmlDeclaration ("1.0", null, null);
91                         AssertEquals ("null Standalone property", String.Empty, d3.Standalone);
92                 }
93
94                 public void TestValueProperty ()
95                 {
96                         XmlDeclaration d = document.CreateXmlDeclaration ("1.0", "UTF-8", "yes");
97                         AssertEquals ("Value property", "version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"",
98                                       d.Value);
99                 }
100
101                 public void TestXmlCommentCloneNode ()
102                 {
103                         XmlNode original = declaration;
104
105                         XmlNode shallow = declaration.CloneNode (false); // shallow
106                         TestXmlNodeBaseProperties (original, shallow);
107                         
108                         XmlNode deep = declaration.CloneNode (true); // deep
109                         TestXmlNodeBaseProperties (original, deep);
110
111                         AssertEquals ("deep cloning differs from shallow cloning",
112                                       deep.OuterXml, shallow.OuterXml);
113                 }
114         }
115 }