/mcs/class/System.XML/Test/System.Xml/nist_dom/fundamental/Element/Element.cs
C# | 1851 lines | 824 code | 160 blank | 867 comment | 7 complexity | abe0edf2535d46276f94713d9e9a94de MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
Large files files are truncated, but you can click here to view the full file
- //**************************************************************************
- //
- //
- // National Institute Of Standards and Technology
- // DTS Version 1.0
- //
- // Element Interface
- //
- // Written by: Carmelo Montanez
- // Modified by: Mary Brady
- //
- // Ported to System.Xml by: Mizrahi Rafael rafim@mainsoft.com
- // Mainsoft Corporation (c) 2003-2004
- //**************************************************************************
- using System;
- using System.Xml;
-
- using nist_dom;
- using NUnit.Framework;
-
- namespace nist_dom.fundamental
- {
- [TestFixture]
- public class ElementTest
- {
- public static int i = 2;
- /*
- public testResults[] RunTests()
- {
- testResults[] tests = new testResults[] {core0001E(), core0002E(), core0003E(),core0004E(),
- core0005E(), core0006E(), core0007E(), core0008E(),
- core0009E(), core0010E(), core0011E(), core0012E(),
- core0013E(), core0014E(), core0015E(), core0016E(),
- core0017E(), core0018E(), core0019E(), core0020E(),
- core0021E(), core0022E(), core0023E(), core0024E(),
- core0025E(), core0026E(), core0027E(), core0028E(),
- core0029E(), core0030E()};
-
- return tests;
- }
- */
- //------------------------ test case core-0001E ------------------------
- //
- // Testing feature - Elements may have attributes associated with them.
- //
- // Testing approach - Retrieve the first attribute from the last child of
- // the first employee and examine its "specified"
- // attribute. This test is only intended to show
- // that Elements can actually have attributes.
- // This test uses the "getNamedItem(name)" method from
- // the NamedNodeMap interface.
- //
- // Semantic Requirements: 1
- //
- //----------------------------------------------------------------------------
-
- [Test]
- public void core0001E()
- {
- string computedValue = "0";//0
- string expectedValue = "True";//true
- System.Xml.XmlNode addressElement = null;
- System.Xml.XmlAttributeCollection attrList = null;
- System.Xml.XmlAttribute domesticAttr = null;
-
- testResults results = new testResults("Core0001E");
- try
- {
- results.description = "Element nodes may have associated attributes.";
- //
- // Retrieve the "address" element from the first employee.
- //
- addressElement = util.nodeObject(util.FIRST,util.SIXTH);
- //
- // Access its "domestic" attribute by creating a list of all attributes
- // and then retrieving the desired attribute from the list by name.
- //
- attrList = addressElement.Attributes;//.node.
- domesticAttr = (System.Xml.XmlAttribute)attrList.GetNamedItem("domestic");
- //
- // Access its "specified" attribute.
- //
- computedValue = domesticAttr.Specified.ToString();
- }
- catch(System.Exception ex)
- {
- computedValue = "Exception " + ex.Message;
- }
-
- //
- // Write out results
- //
- results.expected = expectedValue;
- results.actual = computedValue;
-
- Assert.AreEqual (results.expected, results.actual);
- }
- //------------------------ End test case core-0001E --------------------------
- //
- //------------------------ test case core-0002E ------------------------
- //
- // Testing feature - The generic Attribute "attributes" (Node interface) may
- // be used to retrieve the set of all attributes of an
- // element.
- //
- // Testing approach - Create a list of all the attributes of the last child of
- // of the first employee by using the generic "attributes"
- // attribute from the Node interface. Further the length
- // of the attribute list is examined. This test makes
- // use of the "Count" attribute from the NameNodeMap
- // interface.
- //
- // Semantic Requirements: 1, 2
- //
- //----------------------------------------------------------------------------
-
- [Test]
- [Category ("NotDotNet")] // MS DOM is buggy
- public void core0002E()
- {
- string computedValue = "";
- string expectedValue = "2";
- System.Xml.XmlNode addressElement = null;
- System.Xml.XmlAttributeCollection attrList = null;
-
- testResults results = new testResults("Core0002E");
- try
- {
- results.description = "The generic \"attributes\" (from the Node interface) may " +
- "be used to retrieve the set of all attributes of an element.";
- //
- // Retrieve the "address" element from the first employee.
- //
- addressElement = util.nodeObject(util.FIRST,util.SIXTH);
- //
- // Access its attributes list.
- //
- attrList = addressElement.Attributes;
- //
- // Access its "length" attribute.
- //
- computedValue = attrList.Count.ToString();
- }
- catch(System.Exception ex)
- {
- computedValue = "Exception " + ex.Message;
- }
- //
- // Write out results
- //
- results.expected = expectedValue;
- results.actual = computedValue;
-
- Assert.AreEqual (results.expected, results.actual);
- }
-
- //------------------------ End test case core-0002E --------------------------
- //
- //-------------------------- test case core-0003E ----------------------------
- //
- // Testing feature - The "tagName" attribute contains the name of the
- // element.
- //
- // Testing approach - Retrieve the third child of the second employee and
- // examine its "tagName" attribute. It should return a
- // string containing the name of the element ("position",
- // in this case).
- //
- // Semantic Requirements: 3
- //
- //----------------------------------------------------------------------------
-
- [Test]
- public void core0003E()
- {
- string computedValue = "";
- string expectedValue = "position";
- System.Xml.XmlNode positionElement = null;
-
- testResults results = new testResults("Core0003E");
- try
- {
- results.description = "The \"tagName\" of an Element contains the " +
- "element's name.";
- //
- // Access its third child of the second employee.
- //
- positionElement = util.nodeObject(util.SECOND,util.THIRD);
- //
- // Access its "tagName" attribute.
- //
- computedValue = positionElement.Name;//tagName;//.node.
- }
- catch(System.Exception ex)
- {
- computedValue = "Exception " + ex.Message;
- }
- //
- // Write out results
- //
- results.expected = expectedValue;
- results.actual = computedValue;
-
- Assert.AreEqual (results.expected, results.actual);
- }
-
- //------------------------ End test case core-0003E --------------------------
- //
- //-------------------------- test case core-0004E ----------------------------
- //
- // Testing feature - The "getAttribute(name)" method returns an attribute value
- // by name.
- //
- // Testing approach - Retrieve the the last child of the third employee, then
- // invoke its "getAttribute(name)" method. It should
- // return the value of the attribute("No", in this case).
- //
- // Semantic Requirements: 1, 4
- //
- //----------------------------------------------------------------------------
-
- [Test]
- public void core0004E()
- {
- string computedValue = "";
- string expectedValue = "No";
- System.Xml.XmlElement addressElement = null;
-
- testResults results = new testResults("Core0004E");
- try
- {
- results.description = "The \"getAttribute(name)\" method of an Element returns " +
- "the value of an attribute by name.";
- //
- // Retrieve the targeted data.
- //
- addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
- computedValue = addressElement.GetAttribute("street");//addressElement.node.GetAttribute("street");
- }
- catch(System.Exception ex)
- {
- computedValue = "Exception " + ex.Message;
- }
- //
- // Write out results
- //
- results.expected = expectedValue;
- results.actual = computedValue;
-
- Assert.AreEqual (results.expected, results.actual);
- }
-
- //------------------------ End test case core-0004E --------------------------
- //
- //-------------------------- test case core-0005E ----------------------------
- //
- // Testing feature - The "getAttribute(name)" method returns an empty
- // string if no value was assigned to an attribute and
- // no default value was given in the DTD file.
- //
- // Testing approach - Retrieve the the last child of the last employee, then
- // invoke its "getAttribute(name)" method, where "name" is an
- // attribute with no specified or DTD default value. The
- // "getAttribute(name)" method should return the empty
- // string. This method makes use of the
- // "createAttribute(newAttr)" method from the Document
- // interface.
- //
- // Semantic Requirements: 1, 4, 5
- //
- //----------------------------------------------------------------------------
-
- [Test]
- public void core0005E()
- {
- string computedValue = "";
- string expectedValue = "";
- System.Xml.XmlElement addressElement = null;
- System.Xml.XmlAttribute newAttribute = null;
-
-
- testResults results = new testResults("Core0005E");
- try
- {
- results.description = "The \"getAttribute(name)\" method of an Element returns " +
- "the empty string if the attribue does not have a default " +
- "or specified value.";
- //
- // Access the sixth child of the last employee.
- //
- newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");
- addressElement = (System.Xml.XmlElement)util.nodeObject(util.FOURTH,util.SIXTH);
- //
- // Invoke its "setAttributeNode(newAttr)" method where
- // newAttr = "newAttribute". Since no value was specified or given
- // by default, the value returned by the "getAttribute(name)" method
- // should be the empty string.
- //
- addressElement.SetAttributeNode(newAttribute);//.node.
- computedValue = addressElement.GetAttribute("district");//.node.
- }
- catch(System.Exception ex)
- {
- computedValue = "Exception " + ex.Message;
- }
-
- //
- // Write out results
- //
- results.expected = expectedValue;
- results.actual = computedValue;
-
- util.resetData();
-
- Assert.AreEqual (results.expected, results.actual);
- }
-
- //------------------------ End test case core-0005E --------------------------
- //
- //-------------------------- test case core-0006E ----------------------------
- //
- // Testing feature - The "setAttribute(name,value)" method adds a new attribute
- // to the Element.
- //
- // Testing approach - Retrieve the last child of the last employee, then
- // add an attribute to it by invoking its
- // "setAttribute(name,value)" method. It should create
- // a "name" attribute with an assigned value equal to
- // "value".
- //
- // Semantic Requirements: 1, 4, 6
- //
- //----------------------------------------------------------------------------
-
- [Test]
- public void core0006E()
- {
- string computedValue = "";
- System.Xml.XmlElement addressElement = null;
- string name = "district";
- string expectedValue = "dallas";
-
-
- testResults results = new testResults("Core0006E");
- try
- {
- results.description = "The \"setAttribute(name,value)\" method of an Element " +
- "creates an new \"name\" attribute whose value is equal to \"value\".";
- //
- // Access the last child of the last employee.
- //
- addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.SIXTH);
- //
- // Invoke its "setAttribute(name,value)" method and create a new attribute
- //
- addressElement.SetAttribute(name,expectedValue);//.node.
- //
- // This Element should now have a new attribute that we can be retrieved
- // by name.
- //
- computedValue = addressElement.GetAttribute(name);//.node.
- }
- catch(System.Exception ex)
- {
- computedValue = "Exception " + ex.Message;
- }
- //
- // Write out results
- //
- results.expected = expectedValue;
- results.actual = computedValue;
-
- util.resetData();
-
- Assert.AreEqual (results.expected, results.actual);
- }
-
- //------------------------ End test case core-0006E --------------------------
- //
- //-------------------------- test case core-0007E ----------------------------
- //
- // Testing feature - The "setAttribute(name,value)" method adds a new attribute
- // to the Element. If the "name" is already present, then
- // its value should be changed to the new one of the
- // "value" parameter.
- //
- // Testing approach - Retrieve the last child of the fourth employee,
- // then add an attribute to it by invoking its
- // "setAttribute(name,value)" method. Since the name
- // of the used attribute ("street") is already present
- // in this element, then its value should be
- // changed to the new one of the "value" parameter.
- //
- // Semantic Requirements: 1, 4, 7
- //
- //----------------------------------------------------------------------------
-
- [Test]
- public void core0007E()
- {
- string computedValue = "";
- string expectedValue = "Neither";
- System.Xml.XmlElement addressElement = null;
-
- testResults results = new testResults("Core0007E");
- try
- {
- results.description = "The \"setAttribute(name,value)\" method of an Element " +
- "where the \"name\" attribute is already present in this Element.";
- //
- // Access the sixth child of the fourth employee.
- //
- addressElement = (System.Xml.XmlElement)util.nodeObject(util.FOURTH,util.SIXTH);
- //
- // Invoke its "setAttribute(name,value)" method where name = "street"
- // and value = "Neither".
- //
- addressElement.SetAttribute("street","Neither");//.node.
- //
- // The "street" attribute should now have a value of "Neither"
- //
- computedValue = addressElement.GetAttribute("street");//.node.
- }
- catch(System.Exception ex)
- {
- computedValue = "Exception " + ex.Message;
- }
-
- //
- // Write out results
- //
- results.expected = expectedValue;
- results.actual = computedValue;
-
- util.resetData();
-
- Assert.AreEqual (results.expected, results.actual);
- }
-
- //------------------------ End test case core-0007E --------------------------
- //
- //-------------------------- test case core-0008E ----------------------------
- //
- // Testing feature - The "removeAttribute(name)" removes an attribute
- // by name. If the removed attribute is known to have a
- // default value, an attribute immediately appears
- // containing the default value.
- //
- // Testing approach - Retrieve the attribute named "street" from the last
- // child of the fourth employee, then remove the "street"
- // attribute by invoking its "removeAttribute(name) method.
- // The "street" attribute has a default value defined in the
- // DTD file, that value should immediately replace the
- // old value.
- //
- // Semantic Requirements: 1, 8
- //
- //----------------------------------------------------------------------------
-
- [Test]
- #if NET_2_0
- [Category ("NotDotNet")]
- #endif
- public void core0008E()
- {
- string computedValue = "";
- string expectedValue = "Yes";
- System.Xml.XmlElement addressElement = null;
- string streetAttr = "";
-
- testResults results = new testResults("Core0008E");
- try
- {
- results.description = "The \"removeAttribute(name)\" method of an Element " +
- "removes the \"name\" attribute and restores any " +
- "known default values.";
- //
- // Access the last child of the fourth employee.
- //
- addressElement = (System.Xml.XmlElement)util.nodeObject(util.FOURTH,util.SIXTH);
- //
- // Invoke its "removeAttribute(name)" method where name = "street"
- //
- addressElement.RemoveAttribute("street");//.node.
- //
- // Now access that attribute.
- //
- streetAttr = addressElement.GetAttribute("street");//.node.
- //
- // The "street" attribute should now have a default values
- //
- computedValue = addressElement.GetAttribute("street");//.node.
- }
- catch(System.Exception ex)
- {
- computedValue = "Exception " + ex.Message;
- }
-
- //
- // Write out results
- //
- results.expected = expectedValue;
- results.actual = computedValue;
-
- util.resetData();
-
- Assert.AreEqual (results.expected, results.actual);
- }
-
- //------------------------ End test case core-0008E --------------------------
- //
- //-------------------------- test case core-0009E ----------------------------
- //
- // Testing feature - The "getAttributeNode(name)" retrieves an attribute
- // node by name.
- //
- // Testing approach - Retrieve the attribute named "domestic" from the last
- // child of the first employee. Since the method returns
- // an Attr object, its name attribute can be examined to
- // ensure the proper attribute was retrieved.
- //
- // Semantic Requirements: 1, 9
- //
- //----------------------------------------------------------------------------
-
- [Test]
- public void core0009E()
- {
- string computedValue = "";
- string expectedValue = "domestic";
- System.Xml.XmlElement addressElement = null;
- System.Xml.XmlAttribute domesticAttrNode = null;
-
- testResults results = new testResults("Core0009E");
- try
- {
- results.description = "The \"getAttributeNode(name)\" method of an Element " +
- "returns the \"name\" Attr node.";
- //
- // Access the last child of the first employee.
- //
- addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);
- //
- // Invoke its "getAttributeNode(name)" method where name = "domestic"
- // and create an Attr object.
- //
- domesticAttrNode = addressElement.GetAttributeNode("domestic");//.node.
- //
- // Now access the "name" attribute of that Attr node. Since the "domestic"
- // attribute was retrieved, the name of the Attr node should also be
- // "domestic".
- //
- computedValue = domesticAttrNode.Name;
- }
- catch(System.Exception ex)
- {
- computedValue = "Exception " + ex.Message;
- }
-
- //
- // Write out results
- //
- results.expected = expectedValue;
- results.actual = computedValue;
-
- Assert.AreEqual (results.expected, results.actual);
- }
-
- //------------------------ End test case core-0009E --------------------------
- //
- //-------------------------- test case core-00010E ----------------------------
- //
- // Testing feature - The "getAttributeNode(name)" retrieves an attribute
- // node by name. It should return null if the "name"
- // attribute does not exist.
- //
- // Testing approach - Retrieve the last child of the first employee and
- // attempt to retrieve a non-existing attribute.
- // The method should return null. The non-existing
- // attribute to be used is "invalidAttribute".
- //
- // Semantic Requirements: 1, 10
- //
- //----------------------------------------------------------------------------
-
- [Test]
- public void core0010E()
- {
- object computedValue = null;
- object expectedValue = null;
- System.Xml.XmlElement addressElement = null;
-
- testResults results = new testResults("Core0010E");
- try
- {
- results.description = "The \"getAttributeNode(name)\" method returns null " +
- "if the \"name\" attribute does not exist.";
- //
- // Access the last child of the first employee.
- //
- addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);
- //
- // Invoke its "getAttributeNode(name)" method where name = "invalidAttribute"
- // This should result in a null value being returned by the method.
- //
- computedValue = addressElement.GetAttributeNode("invalidAttribute");//.node.
- }
- catch(System.Exception ex)
- {
- computedValue = "Exception " + ex.Message;
- }
- //
- // Write out results
- //
- results.expected = (expectedValue == null).ToString();
- results.actual = (computedValue == null).ToString();
-
- Assert.AreEqual (results.expected, results.actual);
- }
-
- //------------------------ End test case core-0010E --------------------------
- //
- //-------------------------- test case core-0011E ----------------------------
- //
- // Testing feature - The "setAttributeNode(newAttr)" adds a new attribute
- // to the Element.
- //
- // Testing approach - Retrieve the last child of the first employee and
- // add a new attribute node to it by invoking its
- // "setAttributeNode(newAttr)" method. This test makes
- // use of the "createAttribute(name)" method from the
- // Document interface.
- //
- // Semantic Requirements: 1, 11
- //
- //----------------------------------------------------------------------------
-
- [Test]
- public void core0011E()
- {
- string computedValue = "";
- string expectedValue = "";
- System.Xml.XmlElement addressElement = null;
- System.Xml.XmlAttribute newAttribute = null;
- string name = "district";
-
- testResults results = new testResults("Core0011E");
- try
- {
- results.description = "The \"setAttributeNode(newAttr)\" method adds a new " +
- "attribute node to the element.";
- //
- // Access the last child of the first employee.
- //
- newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,name);
- addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);
- //
- // Invoke its "setAttributeNode(newAttr)" method where
- // newAttr = "newAttribute". Since no value was specified or given
- // by default, its value should be the empty string.
- //
- addressElement.SetAttributeNode(newAttribute);//.node.
- computedValue = addressElement.GetAttribute(name);//.node.
- }
- catch(System.Exception ex)
- {
- computedValue = "Exception " + ex.Message;
- }
- //
- // Write out results
- //
- results.expected = expectedValue;
- results.actual = computedValue;
-
- util.resetData();
-
- Assert.AreEqual (results.expected, results.actual);
- }
-
- //------------------------ End test case core-0011E --------------------------
- //
- //-------------------------- test case core-00012E ----------------------------
- //
- // Testing feature - The "setAttributeNode(newAttr)" method adds a new attribute
- // to the Element. If the "newAttr" Attr node is already
- // present in this element, it should replace the existing
- // one.
- //
- // Testing approach - Retrieve the last child of the third employee and
- // add a new attribute node to it by invoking its
- // "setAttributeNode(newAttr)" method. The new attribute
- // node to be added is "street", which is already
- // present in this element. The method should replace the
- // existing Attr node with the new one. This test make use
- // of the "createAttribute(name)" method from the Document
- // interface.
- //
- // Semantic Requirements: 1, 12
- //
- //----------------------------------------------------------------------------
-
- [Test]
- public void core0012E()
- {
- string computedValue = "";
- string expectedValue = "";
- System.Xml.XmlElement addressElement = null;
- System.Xml.XmlAttribute newAttribute = null;
-
- testResults results = new testResults("Core0012E");
- try
- {
- results.description = "The \"setAttributeNode(newAttr)\" method when " +
- "the \"newAttr\" node is already part of this " +
- "element. The existing attribute node should be "+
- "replaced with the new one.";
- //
- // Access the last child of the third employee.
- //
- newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"street");
- addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
- //
- // Invoke its "setAttributeNode(newAttr)" method where
- // newAttr = "newAttribute". That attribute is already part of this
- // element. The existing attribute should be replaced with the new one
- // (newAttribute).
- //
- addressElement.SetAttributeNode(newAttribute);//.node.
- computedValue = addressElement.GetAttribute("street");//.node.
- }
- catch(System.Exception ex)
- {
- computedValue = "Exception " + ex.Message;
- }
- //
- // Write out results
- //
- results.expected = expectedValue;
- results.actual = computedValue;
-
- util.resetData();
-
- Assert.AreEqual (results.expected, results.actual);
- }
-
- //------------------------ End test case core-0012E --------------------------
- //
- //-------------------------- test case core-00013E ----------------------------
- //
- // Testing feature - If The "setAttributeNode(newAttr)" method replaces
- // an existing Attr node with the same name, then it
- // should return the previously existing Attr node.
- //
- // Testing approach - Retrieve the last child of the third employee and add
- // a new attribute node to it. The new attribute node to
- // be added is "street", which is already present in this
- // Element. The method should return the existing Attr
- // node(old "street" Attr). This test make use of the
- // "createAttribute(name)" method from the Document
- // interface.
- //
- // Semantic Requirements: 1, 13
- //
- //----------------------------------------------------------------------------
-
- [Test]
- public void core0013E()
- {
- string computedValue = "";
- string expectedValue = "No";
- System.Xml.XmlElement addressElement = null;
- System.Xml.XmlAttribute oldStreetAttribute = null;
- System.Xml.XmlAttribute newAttribute = null;
-
- testResults results = new testResults("Core0013E");
- try
- {
- results.description = "The \"setAttributeNode(newAttr)\" method when the " +
- "\"newAttr\" attribute node is already present in " +
- "this element. The method should return the previously " +
- "existing Attr node.";
- //
- // Access the last child of the third employee.
- //
- newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"street");
- addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
- //
- // Invoke its "setAttributeNode(newAttr)" method where
- // newAttr was just created with the same name as an already existing
- // attribute("street"). The existing attribute should be replaced with the
- // new one and the method should return the existing "street" Attr node.
- //
- oldStreetAttribute = addressElement.SetAttributeNode(newAttribute);//.node.
- //
- // The "oldStreetAttribute" now contains the old Attr node and its
- // "value" attribute should be available for examination.
- //
- computedValue = oldStreetAttribute.Value;
- }
- catch(System.Exception ex)
- {
- computedValue = "Exception " + ex.Message;
- }
-
- //
- // Write out results
- //
- results.expected = expectedValue;
- results.actual = computedValue;
-
- util.resetData();
-
- Assert.AreEqual (results.expected, results.actual);
- }
-
- //------------------------ End test case core-0013E --------------------------
- //
- //-------------------------- test case core-00014E ----------------------------
- //
- // Testing feature - The "setAttributeNode(newAttr)" method returns the
- // null value if no previously existing Attr node with the
- // same name was replaced.
- //
- // Testing approach - Retrieve the last child of the third and add a new
- // attribute node to it. The new attribute node to be
- // added is "district", which is not part of this Element.
- // The method should return the null value. This test makes
- // use of the "createAttribute(name)" method from the
- // Document interface.
- //
- // Semantic Requirements: 1, 15
- //
- //----------------------------------------------------------------------------
-
- [Test]
- [Category ("NotDotNet")] // MS DOM is buggy
- public void core0014E()
- {
- object computedValue = null;
- object expectedValue = null;
- System.Xml.XmlElement addressElement = null;
- System.Xml.XmlAttribute newAttribute = null;
-
- testResults results = new testResults("Core0014E");
- try
- {
- results.description = "The \"setAttributeNode(newAttr)\" method returns a " +
- "null value if no previously existing Attr node was replaced.";
- //
- // Access the sixth child of the third employee.
- //
- newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");
- addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
- //
- // Invoke its "setAttributeNode(newAttr)" method where name = "newAttribute".
- // This attribute is not part of this element. The method should add the
- // new Attribute and return a null value.
- //
- computedValue = addressElement.SetAttributeNode(newAttribute);//.node.
- }
- catch(System.Exception ex)
- {
- computedValue = "Exception " + ex.Message;
- }
-
- //
- // Write out results
- //
- results.expected = (expectedValue == null).ToString();
- results.actual = (computedValue == null).ToString();
-
- util.resetData();
-
- Assert.AreEqual (results.expected, results.actual);
- }
-
- //------------------------ End test case core-0014E --------------------------
- //
- //-------------------------- test case core-00015E ----------------------------
- //
- // Testing feature - The "removeAttributeNode(oldAttr)" method removes the
- // specified attribute.
- //
- // Testing approach - Retrieve the last child of the third employee, add
- // a new "district" node to it and the try to remove it.
- // To verify that the node was removed this test uses the
- // "getNamedItem(name)" from the NamedNodeMap interface.
- // This test also makes use of the "attributes" attribute
- // from the Node interface.
- //
- // Semantic Requirements: 1, 14
- //
- //----------------------------------------------------------------------------
-
- [Test]
- public void core0015E()
- {
- object computedValue = null;
- object expectedValue = null;
- System.Xml.XmlElement addressElement = null;
- System.Xml.XmlAttributeCollection attrList = null;
- System.Xml.XmlAttribute newAttribute = null;
- newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");
-
- testResults results = new testResults("Core0015E");
- try
- {
- results.description = "The \"removeAttributeNode(oldAttr)\" method removes the " +
- "specified attribute node.";
- //
- // Access the sixth child of the third employee and add the new
- // attribute to it.
- //
- addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
- addressElement.SetAttributeNode(newAttribute);//.node.
- //
- // Invoke its "removeAttributeNode(oldAttr)" method where
- // name = "newAttribute" and remove that attribute node.
- //
- addressElement.RemoveAttributeNode(newAttribute);//.node.
- //
- // To ensure that the "district" attribute was indeed removed, a listing
- // of all attributes is created by invoking the "attributes" attribute
- // of "addressElement". After the list is created, we attempt to
- // retrieve the "district" element from the list. A null value should
- // be return in its place.
- //
- attrList = addressElement.Attributes;
- computedValue = attrList.GetNamedItem("district");
- }
- catch(System.Exception ex)
- {
- computedValue = "Exception " + ex.Message;
- }
- //
- // Write out results
- //
- results.expected = (expectedValue == null).ToString();
- results.actual = (computedValue == null).ToString();
-
- util.resetData();
-
- Assert.AreEqual (results.expected, results.actual);
- }
-
- //------------------------ End test case core-0015E --------------------------
- //
- //-------------------------- test case core-00016E ----------------------------
- //
- // Testing feature - The "removeAttributeNode(oldAttr)" method removes the
- // specified attribute node and restore any default values.
- //
- // Testing approach - Retrieve the last child of the third employee and
- // remove its "street" Attr node. Since this node has
- // default value defined in the DTD file, that default
- // value should immediately be the new value.
- //
- // Semantic Requirements: 1, 15
- //
- //----------------------------------------------------------------------------
-
- [Test]
- #if NET_2_0
- [Category ("NotDotNet")]
- #endif
- public void core0016E()
- {
- string computedValue = "";
- string expectedValue = "Yes";
- System.Xml.XmlElement addressElement = null;
- System.Xml.XmlAttribute streetAttr = null;
- //System.Xml.XmlNode thirdEmployee = null;
-
- testResults results = new testResults("Core0016E");
- try
- {
- results.description = "The \"removeAttributeNode(oldAttr)\" method removes the " +
- "specified attribute node and restores any default values.";
- //
- // Access the sixth child of the third employee.
- //
- addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
- //
- // Create an instance of an Attr object by retrieving the "street"
- // attribute node, invoke its "removeAttributeNode(oldAttr)" method
- // where name = "streetAttr" and remove that attribute node. Note that
- // "the removeAttributeNode(oldAttr)" takes an Attr object as its
- // parameter, that is why an Attr object (named "street") is first created.
- //
- streetAttr = addressElement.GetAttributeNode("street");//.node.
- addressElement.RemoveAttributeNode(streetAttr);//.node.
- //
- // Since there is a default value defined for the "street" attribute, it
- // should immediately be the new value for that attribute.
- //
- computedValue = addressElement.GetAttribute("street");//.node.
- }
- catch(System.Exception ex)
- {
- computedValue = "Exception " + ex.Message;
- }
-
- //
- // Write out results
- //
- results.expected = expectedValue;
- results.actual = computedValue;
-
- util.resetData();
-
- Assert.AreEqual (results.expected, results.actual);
- }
-
- //------------------------ End test case core-0016E --------------------------
- //
- //-------------------------- test case core-00017E ----------------------------
- //
- // Testing feature - The "removeAttributeNode(oldAttr)" method returns the
- // node that was removed.
- //
- // Testing approach - Retrieve the last child of the third employee and
- // remove its "street" Attr node. The method should
- // return the old attribute node.
- //
- // Semantic Requirements: 1, 16
- //
- //----------------------------------------------------------------------------
-
- [Test]
- public void core0017E()
- {
- string computedValue = "";
- string expectedValue = "No";
- System.Xml.XmlElement addressElement = null;
- System.Xml.XmlAttribute streetAttr = null;
- System.Xml.XmlAttribute oldStreetAttribute = null;
-
- testResults results = new testResults("Core0017E");
- try
- {
- results.description = "The \"removeAttributeNode(oldAttr)\" method returns the "+
- "removed attribute node.";
- //
- // Access the sixth child of the third employee.
- //
- addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
-
- // create an instance of an Attr object by retrieving the "street"
- // attribute node, invoke its "removeAttributeNode(oldAttr)" method
- // where name = "streetAttr" and remove that attribute node. Note that
- // "the removeAttributeNode(oldAttr)" takes an Attr object as its
- // parameter, that is why an Attr object (named "street") is first created.
- //
- streetAttr = addressElement.GetAttributeNode("street");//.node.
- oldStreetAttribute = addressElement.RemoveAttributeNode(streetAttr);//.node.
- //
- // The method should return the removed attribute node. Its value can then
- // be examined.
- //
- computedValue = oldStreetAttribute.Value;
- }
- catch(System.Exception ex)
- {
- computedValue = "Exception " + ex.Message;
- }
- //
- // Write out results
- //
- results.expected = expectedValue;
- results.actual = computedValue;
-
- util.resetData();
-
- Assert.AreEqual (results.expected, results.actual);
- }
-
- //------------------------ End test case core-0017E --------------------------
- //
- //-------------------------- test case core-00018E ----------------------------
- //
- // Testing feature - The "getElementsByTagName(name)" method returns a list
- // of all descendant Elements with the given tag name.
- //
- // Testing approach - Get a listing of all the descendant elements of the
- // root element using the string "employee" as the tag
- // name. The method should return a Node list of length
- // equal to 5. This test makes use of the "length"
- // attribute from the NodeList interface.
- //
- // Semantic Requirements: 1, 17
- //
- //----------------------------------------------------------------------------
-
- [Test]
- public void core0018E()
- {
- int computedValue = 0;
- int expectedValue = 5;
- System.Xml.XmlNodeList employeeList = null;
- System.Xml.XmlElement docElement = null;
-
- testResults results = new testResults("Core0018E");
-
- results.description = "The \"getElementsByTagName(name)\" method returns a "+
- "NodeList of all descendant elements with the given " +
- "tag name(method returning a non-empty list)";
- //
- // get a listing of all the elements that match the tag "employee".
- //
- docElement = util.getRootNode();
- employeeList = docElement.GetElementsByTagName("employee");
- //
- // The method should return a NodeList whose length can then be examined.
- //
- computedValue = employeeList.Count;
- //
- // Write out results
- //
- results.expected = expectedValue.ToString();
- results.actual = computedValue.ToString();
-
- Assert.AreEqual (results.expected, results.actual);
- }
-
- //------------------------ End test case core-0018E --------------------------
- //
- //-------------------------- test case core-00019E ----------------------------
- //
- // Testing feature - The "getElementsByTagName(name)" returns a list of all
- // descendant Elements with the given tag name. Test
- // for an empty list.
- //
- // Testing approach - Get a listing of all the descendant elements of the
- // root element using the string "noMatches" as the tag
- // name. The method should return a NodeList of length
- // equal to 0 since no descendant elements match the given
- // …
Large files files are truncated, but you can click here to view the full file