Procházet zdrojové kódy

2004-02-04 Atsushi Enomoto <[email protected]>

	* XmlEntityReferenceTests.cs : renamed TestDescendantsRecursively to
	  DescendantsRecursively and added more test lines.
	  Added ChildNodes().
	* XmlReaderCommonTests.cs : Added MoveToXmlDeclAttribute(). However
	  it is ignored (since XmlNodeReader behaves differently, maybe bug).

svn path=/trunk/mcs/; revision=22768
Atsushi Eno před 22 roky
rodič
revize
88eb2f8d4f

+ 8 - 0
mcs/class/System.XML/Test/System.Xml/ChangeLog

@@ -1,3 +1,11 @@
+2004-02-04  Atsushi Enomoto <[email protected]>
+
+	* XmlEntityReferenceTests.cs : renamed TestDescendantsRecursively to
+	  DescendantsRecursively and added more test lines.
+	  Added ChildNodes().
+	* XmlReaderCommonTests.cs : Added MoveToXmlDeclAttribute(). However
+	  it is ignored (since XmlNodeReader behaves differently, maybe bug).
+
 2004-02-03  Atsushi Enomoto <[email protected]>
 
 	* XmlReaderCommonTests.cs : Added SurrogatePairContent().

+ 35 - 2
mcs/class/System.XML/Test/System.Xml/XmlEntityReferenceTests.cs

@@ -30,7 +30,7 @@ namespace MonoTests.System.Xml
 		}
 
 		[Test]
-		public void TestDescendantsRecursively ()
+		public void DescendantsRecursively ()
 		{
 			string dtd = "<!DOCTYPE root [<!ELEMENT root (#PCDATA)*>"
 				+ "<!ENTITY ent 'value'>"
@@ -42,8 +42,41 @@ namespace MonoTests.System.Xml
 			doc.Load (xtr);
 			XmlEntity ent = (XmlEntity) doc.DocumentType.Entities.GetNamedItem ("ent2");
 			AssertEquals ("ent2", ent.Name);
-			AssertEquals ("my", ent.FirstChild.Value);
+			AssertEquals ("my ", ent.FirstChild.Value);
+			AssertNotNull (ent.FirstChild.NextSibling.FirstChild);
 			AssertEquals ("value", ent.FirstChild.NextSibling.FirstChild.Value);
 		}
+
+		[Test]
+		public void ChildNodes ()
+		{
+			XmlTextReader xtr = new XmlTextReader ("<!DOCTYPE root [<!ENTITY ent 'ent-value'><!ENTITY el '<foo>hoge</foo><bar/>'>]><root/>",
+				XmlNodeType.Document, null);
+			XmlDocument doc = new XmlDocument ();
+
+			doc.Load (xtr);
+			XmlEntityReference ent = doc.CreateEntityReference ("ent");
+			// ChildNodes are not added yet.
+			AssertNull (ent.FirstChild);
+			doc.DocumentElement.AppendChild (ent);
+			// ChildNodes are added here.
+			AssertNotNull (ent.FirstChild);
+
+			ent = doc.CreateEntityReference ("foo");
+			AssertNull (ent.FirstChild);
+			// Entity value is empty when the matching DTD entity 
+			// node does not exist.
+			doc.DocumentElement.AppendChild (ent);
+			AssertNotNull (ent.FirstChild);
+
+			AssertEquals (String.Empty, ent.FirstChild.Value);
+
+			ent = doc.CreateEntityReference ("el");
+			AssertEquals ("", ent.InnerText);
+			doc.DocumentElement.AppendChild (ent);
+			AssertEquals ("<foo>hoge</foo><bar />", ent.InnerXml);
+			AssertEquals ("hoge", ent.InnerText);
+			AssertEquals (XmlNodeType.Element, ent.FirstChild.NodeType);
+		}
 	}
 }

+ 67 - 0
mcs/class/System.XML/Test/System.Xml/XmlReaderCommonTests.cs

@@ -1207,6 +1207,73 @@ namespace MonoTests.System.Xml
 			AssertEndDocument (xmlReader);
 		}
 
+		[Test]
+		[Ignore ("XmlNodeReader never moves to xml declaration.")]
+		public void MoveToXmlDeclAttributes ()
+		{
+			string xml = "<?xml version=\"1.0\" standalone=\"yes\"?><root/>";
+			RunTest (xml, new TestMethod (MoveToXmlDeclAttributes));
+		}
+
+		public void MoveToXmlDeclAttributes (XmlReader xmlReader)
+		{
+			xmlReader.Read ();
+			this.AssertNodeValues (xmlReader, 
+				XmlNodeType.XmlDeclaration,
+				0,
+				false,
+				"xml",
+				String.Empty,
+				"xml",
+				String.Empty,
+				"version=\"1.0\" standalone=\"yes\"",
+				2);
+			xmlReader.MoveToFirstAttribute ();
+			this.AssertNodeValues (xmlReader, 
+				XmlNodeType.Attribute,
+				1,
+				false,
+				"version",
+				String.Empty,
+				"version",
+				String.Empty,
+				"1.0",
+				2);
+			xmlReader.ReadAttributeValue ();
+			this.AssertNodeValues (xmlReader, 
+				XmlNodeType.Text,
+				2,
+				false,
+				String.Empty,
+				String.Empty,
+				String.Empty,
+				String.Empty,
+				"1.0",
+				2);
+			xmlReader.MoveToNextAttribute ();
+			this.AssertNodeValues (xmlReader, 
+				XmlNodeType.Attribute,
+				1,
+				false,
+				"standalone",
+				String.Empty,
+				"standalone",
+				String.Empty,
+				"yes",
+				2);
+			xmlReader.ReadAttributeValue ();
+			this.AssertNodeValues (xmlReader, 
+				XmlNodeType.Text,
+				2,
+				false,
+				String.Empty,
+				String.Empty,
+				String.Empty,
+				String.Empty,
+				"yes",
+				2);
+		}
+
 		[Test]
 		public void AttributeOrder ()
 		{