1 //**************************************************************************
\r
4 // National Institute Of Standards and Technology
\r
9 // Written by: Carmelo Montanez
\r
10 // Modified by: Mary Brady
\r
12 // Ported to System.Xml by: Mizrahi Rafael rafim@mainsoft.com
\r
13 // Mainsoft Corporation (c) 2003-2004
\r
14 //**************************************************************************
\r
19 using NUnit.Framework;
\r
21 namespace nist_dom.fundamental
\r
24 public class ElementTest : Assertion
\r
26 public static int i = 2;
\r
28 public testResults[] RunTests()
\r
30 testResults[] tests = new testResults[] {core0001E(), core0002E(), core0003E(),core0004E(),
\r
31 core0005E(), core0006E(), core0007E(), core0008E(),
\r
32 core0009E(), core0010E(), core0011E(), core0012E(),
\r
33 core0013E(), core0014E(), core0015E(), core0016E(),
\r
34 core0017E(), core0018E(), core0019E(), core0020E(),
\r
35 core0021E(), core0022E(), core0023E(), core0024E(),
\r
36 core0025E(), core0026E(), core0027E(), core0028E(),
\r
37 core0029E(), core0030E()};
\r
42 //------------------------ test case core-0001E ------------------------
\r
44 // Testing feature - Elements may have attributes associated with them.
\r
46 // Testing approach - Retrieve the first attribute from the last child of
\r
47 // the first employee and examine its "specified"
\r
48 // attribute. This test is only intended to show
\r
49 // that Elements can actually have attributes.
\r
50 // This test uses the "getNamedItem(name)" method from
\r
51 // the NamedNodeMap interface.
\r
53 // Semantic Requirements: 1
\r
55 //----------------------------------------------------------------------------
\r
58 public void core0001E()
\r
60 string computedValue = "0";//0
\r
61 string expectedValue = "True";//true
\r
62 System.Xml.XmlNode addressElement = null;
\r
63 System.Xml.XmlAttributeCollection attrList = null;
\r
64 System.Xml.XmlAttribute domesticAttr = null;
\r
66 testResults results = new testResults("Core0001E");
\r
69 results.description = "Element nodes may have associated attributes.";
\r
71 // Retrieve the "address" element from the first employee.
\r
73 addressElement = util.nodeObject(util.FIRST,util.SIXTH);
\r
75 // Access its "domestic" attribute by creating a list of all attributes
\r
76 // and then retrieving the desired attribute from the list by name.
\r
78 attrList = addressElement.Attributes;//.node.
\r
79 domesticAttr = (System.Xml.XmlAttribute)attrList.GetNamedItem("domestic");
\r
81 // Access its "specified" attribute.
\r
83 computedValue = domesticAttr.Specified.ToString();
\r
85 catch(System.Exception ex)
\r
87 computedValue = "Exception " + ex.Message;
\r
91 // Write out results
\r
93 results.expected = expectedValue;
\r
94 results.actual = computedValue;
\r
96 AssertEquals (results.expected, results.actual);
\r
98 //------------------------ End test case core-0001E --------------------------
\r
100 //------------------------ test case core-0002E ------------------------
\r
102 // Testing feature - The generic Attribute "attributes" (Node interface) may
\r
103 // be used to retrieve the set of all attributes of an
\r
106 // Testing approach - Create a list of all the attributes of the last child of
\r
107 // of the first employee by using the generic "attributes"
\r
108 // attribute from the Node interface. Further the length
\r
109 // of the attribute list is examined. This test makes
\r
110 // use of the "Count" attribute from the NameNodeMap
\r
113 // Semantic Requirements: 1, 2
\r
115 //----------------------------------------------------------------------------
\r
118 [Category ("NotDotNet")] // MS DOM is buggy
\r
119 public void core0002E()
\r
121 string computedValue = "";
\r
122 string expectedValue = "2";
\r
123 System.Xml.XmlNode addressElement = null;
\r
124 System.Xml.XmlAttributeCollection attrList = null;
\r
126 testResults results = new testResults("Core0002E");
\r
129 results.description = "The generic \"attributes\" (from the Node interface) may " +
\r
130 "be used to retrieve the set of all attributes of an element.";
\r
132 // Retrieve the "address" element from the first employee.
\r
134 addressElement = util.nodeObject(util.FIRST,util.SIXTH);
\r
136 // Access its attributes list.
\r
138 attrList = addressElement.Attributes;
\r
140 // Access its "length" attribute.
\r
142 computedValue = attrList.Count.ToString();
\r
144 catch(System.Exception ex)
\r
146 computedValue = "Exception " + ex.Message;
\r
149 // Write out results
\r
151 results.expected = expectedValue;
\r
152 results.actual = computedValue;
\r
154 AssertEquals (results.expected, results.actual);
\r
157 //------------------------ End test case core-0002E --------------------------
\r
159 //-------------------------- test case core-0003E ----------------------------
\r
161 // Testing feature - The "tagName" attribute contains the name of the
\r
164 // Testing approach - Retrieve the third child of the second employee and
\r
165 // examine its "tagName" attribute. It should return a
\r
166 // string containing the name of the element ("position",
\r
169 // Semantic Requirements: 3
\r
171 //----------------------------------------------------------------------------
\r
174 public void core0003E()
\r
176 string computedValue = "";
\r
177 string expectedValue = "position";
\r
178 System.Xml.XmlNode positionElement = null;
\r
180 testResults results = new testResults("Core0003E");
\r
183 results.description = "The \"tagName\" of an Element contains the " +
\r
186 // Access its third child of the second employee.
\r
188 positionElement = util.nodeObject(util.SECOND,util.THIRD);
\r
190 // Access its "tagName" attribute.
\r
192 computedValue = positionElement.Name;//tagName;//.node.
\r
194 catch(System.Exception ex)
\r
196 computedValue = "Exception " + ex.Message;
\r
199 // Write out results
\r
201 results.expected = expectedValue;
\r
202 results.actual = computedValue;
\r
204 AssertEquals (results.expected, results.actual);
\r
207 //------------------------ End test case core-0003E --------------------------
\r
209 //-------------------------- test case core-0004E ----------------------------
\r
211 // Testing feature - The "getAttribute(name)" method returns an attribute value
\r
214 // Testing approach - Retrieve the the last child of the third employee, then
\r
215 // invoke its "getAttribute(name)" method. It should
\r
216 // return the value of the attribute("No", in this case).
\r
218 // Semantic Requirements: 1, 4
\r
220 //----------------------------------------------------------------------------
\r
223 public void core0004E()
\r
225 string computedValue = "";
\r
226 string expectedValue = "No";
\r
227 System.Xml.XmlElement addressElement = null;
\r
229 testResults results = new testResults("Core0004E");
\r
232 results.description = "The \"getAttribute(name)\" method of an Element returns " +
\r
233 "the value of an attribute by name.";
\r
235 // Retrieve the targeted data.
\r
237 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
\r
238 computedValue = addressElement.GetAttribute("street");//addressElement.node.GetAttribute("street");
\r
240 catch(System.Exception ex)
\r
242 computedValue = "Exception " + ex.Message;
\r
245 // Write out results
\r
247 results.expected = expectedValue;
\r
248 results.actual = computedValue;
\r
250 AssertEquals (results.expected, results.actual);
\r
253 //------------------------ End test case core-0004E --------------------------
\r
255 //-------------------------- test case core-0005E ----------------------------
\r
257 // Testing feature - The "getAttribute(name)" method returns an empty
\r
258 // string if no value was assigned to an attribute and
\r
259 // no default value was given in the DTD file.
\r
261 // Testing approach - Retrieve the the last child of the last employee, then
\r
262 // invoke its "getAttribute(name)" method, where "name" is an
\r
263 // attribute with no specified or DTD default value. The
\r
264 // "getAttribute(name)" method should return the empty
\r
265 // string. This method makes use of the
\r
266 // "createAttribute(newAttr)" method from the Document
\r
269 // Semantic Requirements: 1, 4, 5
\r
271 //----------------------------------------------------------------------------
\r
274 public void core0005E()
\r
276 string computedValue = "";
\r
277 string expectedValue = "";
\r
278 System.Xml.XmlElement addressElement = null;
\r
279 System.Xml.XmlAttribute newAttribute = null;
\r
282 testResults results = new testResults("Core0005E");
\r
285 results.description = "The \"getAttribute(name)\" method of an Element returns " +
\r
286 "the empty string if the attribue does not have a default " +
\r
287 "or specified value.";
\r
289 // Access the sixth child of the last employee.
\r
291 newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");
\r
292 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FOURTH,util.SIXTH);
\r
294 // Invoke its "setAttributeNode(newAttr)" method where
\r
295 // newAttr = "newAttribute". Since no value was specified or given
\r
296 // by default, the value returned by the "getAttribute(name)" method
\r
297 // should be the empty string.
\r
299 addressElement.SetAttributeNode(newAttribute);//.node.
\r
300 computedValue = addressElement.GetAttribute("district");//.node.
\r
302 catch(System.Exception ex)
\r
304 computedValue = "Exception " + ex.Message;
\r
308 // Write out results
\r
310 results.expected = expectedValue;
\r
311 results.actual = computedValue;
\r
315 AssertEquals (results.expected, results.actual);
\r
318 //------------------------ End test case core-0005E --------------------------
\r
320 //-------------------------- test case core-0006E ----------------------------
\r
322 // Testing feature - The "setAttribute(name,value)" method adds a new attribute
\r
325 // Testing approach - Retrieve the last child of the last employee, then
\r
326 // add an attribute to it by invoking its
\r
327 // "setAttribute(name,value)" method. It should create
\r
328 // a "name" attribute with an assigned value equal to
\r
331 // Semantic Requirements: 1, 4, 6
\r
333 //----------------------------------------------------------------------------
\r
336 public void core0006E()
\r
338 string computedValue = "";
\r
339 System.Xml.XmlElement addressElement = null;
\r
340 string name = "district";
\r
341 string expectedValue = "dallas";
\r
344 testResults results = new testResults("Core0006E");
\r
347 results.description = "The \"setAttribute(name,value)\" method of an Element " +
\r
348 "creates an new \"name\" attribute whose value is equal to \"value\".";
\r
350 // Access the last child of the last employee.
\r
352 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.SIXTH);
\r
354 // Invoke its "setAttribute(name,value)" method and create a new attribute
\r
356 addressElement.SetAttribute(name,expectedValue);//.node.
\r
358 // This Element should now have a new attribute that we can be retrieved
\r
361 computedValue = addressElement.GetAttribute(name);//.node.
\r
363 catch(System.Exception ex)
\r
365 computedValue = "Exception " + ex.Message;
\r
368 // Write out results
\r
370 results.expected = expectedValue;
\r
371 results.actual = computedValue;
\r
375 AssertEquals (results.expected, results.actual);
\r
378 //------------------------ End test case core-0006E --------------------------
\r
380 //-------------------------- test case core-0007E ----------------------------
\r
382 // Testing feature - The "setAttribute(name,value)" method adds a new attribute
\r
383 // to the Element. If the "name" is already present, then
\r
384 // its value should be changed to the new one of the
\r
385 // "value" parameter.
\r
387 // Testing approach - Retrieve the last child of the fourth employee,
\r
388 // then add an attribute to it by invoking its
\r
389 // "setAttribute(name,value)" method. Since the name
\r
390 // of the used attribute ("street") is already present
\r
391 // in this element, then its value should be
\r
392 // changed to the new one of the "value" parameter.
\r
394 // Semantic Requirements: 1, 4, 7
\r
396 //----------------------------------------------------------------------------
\r
399 public void core0007E()
\r
401 string computedValue = "";
\r
402 string expectedValue = "Neither";
\r
403 System.Xml.XmlElement addressElement = null;
\r
405 testResults results = new testResults("Core0007E");
\r
408 results.description = "The \"setAttribute(name,value)\" method of an Element " +
\r
409 "where the \"name\" attribute is already present in this Element.";
\r
411 // Access the sixth child of the fourth employee.
\r
413 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FOURTH,util.SIXTH);
\r
415 // Invoke its "setAttribute(name,value)" method where name = "street"
\r
416 // and value = "Neither".
\r
418 addressElement.SetAttribute("street","Neither");//.node.
\r
420 // The "street" attribute should now have a value of "Neither"
\r
422 computedValue = addressElement.GetAttribute("street");//.node.
\r
424 catch(System.Exception ex)
\r
426 computedValue = "Exception " + ex.Message;
\r
430 // Write out results
\r
432 results.expected = expectedValue;
\r
433 results.actual = computedValue;
\r
437 AssertEquals (results.expected, results.actual);
\r
440 //------------------------ End test case core-0007E --------------------------
\r
442 //-------------------------- test case core-0008E ----------------------------
\r
444 // Testing feature - The "removeAttribute(name)" removes an attribute
\r
445 // by name. If the removed attribute is known to have a
\r
446 // default value, an attribute immediately appears
\r
447 // containing the default value.
\r
449 // Testing approach - Retrieve the attribute named "street" from the last
\r
450 // child of the fourth employee, then remove the "street"
\r
451 // attribute by invoking its "removeAttribute(name) method.
\r
452 // The "street" attribute has a default value defined in the
\r
453 // DTD file, that value should immediately replace the
\r
456 // Semantic Requirements: 1, 8
\r
458 //----------------------------------------------------------------------------
\r
462 [Category ("NotDotNet")]
\r
464 public void core0008E()
\r
466 string computedValue = "";
\r
467 string expectedValue = "Yes";
\r
468 System.Xml.XmlElement addressElement = null;
\r
469 string streetAttr = "";
\r
471 testResults results = new testResults("Core0008E");
\r
474 results.description = "The \"removeAttribute(name)\" method of an Element " +
\r
475 "removes the \"name\" attribute and restores any " +
\r
476 "known default values.";
\r
478 // Access the last child of the fourth employee.
\r
480 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FOURTH,util.SIXTH);
\r
482 // Invoke its "removeAttribute(name)" method where name = "street"
\r
484 addressElement.RemoveAttribute("street");//.node.
\r
486 // Now access that attribute.
\r
488 streetAttr = addressElement.GetAttribute("street");//.node.
\r
490 // The "street" attribute should now have a default values
\r
492 computedValue = addressElement.GetAttribute("street");//.node.
\r
494 catch(System.Exception ex)
\r
496 computedValue = "Exception " + ex.Message;
\r
500 // Write out results
\r
502 results.expected = expectedValue;
\r
503 results.actual = computedValue;
\r
507 AssertEquals (results.expected, results.actual);
\r
510 //------------------------ End test case core-0008E --------------------------
\r
512 //-------------------------- test case core-0009E ----------------------------
\r
514 // Testing feature - The "getAttributeNode(name)" retrieves an attribute
\r
517 // Testing approach - Retrieve the attribute named "domestic" from the last
\r
518 // child of the first employee. Since the method returns
\r
519 // an Attr object, its name attribute can be examined to
\r
520 // ensure the proper attribute was retrieved.
\r
522 // Semantic Requirements: 1, 9
\r
524 //----------------------------------------------------------------------------
\r
527 public void core0009E()
\r
529 string computedValue = "";
\r
530 string expectedValue = "domestic";
\r
531 System.Xml.XmlElement addressElement = null;
\r
532 System.Xml.XmlAttribute domesticAttrNode = null;
\r
534 testResults results = new testResults("Core0009E");
\r
537 results.description = "The \"getAttributeNode(name)\" method of an Element " +
\r
538 "returns the \"name\" Attr node.";
\r
540 // Access the last child of the first employee.
\r
542 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);
\r
544 // Invoke its "getAttributeNode(name)" method where name = "domestic"
\r
545 // and create an Attr object.
\r
547 domesticAttrNode = addressElement.GetAttributeNode("domestic");//.node.
\r
549 // Now access the "name" attribute of that Attr node. Since the "domestic"
\r
550 // attribute was retrieved, the name of the Attr node should also be
\r
553 computedValue = domesticAttrNode.Name;
\r
555 catch(System.Exception ex)
\r
557 computedValue = "Exception " + ex.Message;
\r
561 // Write out results
\r
563 results.expected = expectedValue;
\r
564 results.actual = computedValue;
\r
566 AssertEquals (results.expected, results.actual);
\r
569 //------------------------ End test case core-0009E --------------------------
\r
571 //-------------------------- test case core-00010E ----------------------------
\r
573 // Testing feature - The "getAttributeNode(name)" retrieves an attribute
\r
574 // node by name. It should return null if the "name"
\r
575 // attribute does not exist.
\r
577 // Testing approach - Retrieve the last child of the first employee and
\r
578 // attempt to retrieve a non-existing attribute.
\r
579 // The method should return null. The non-existing
\r
580 // attribute to be used is "invalidAttribute".
\r
582 // Semantic Requirements: 1, 10
\r
584 //----------------------------------------------------------------------------
\r
587 public void core0010E()
\r
589 object computedValue = null;
\r
590 object expectedValue = null;
\r
591 System.Xml.XmlElement addressElement = null;
\r
593 testResults results = new testResults("Core0010E");
\r
596 results.description = "The \"getAttributeNode(name)\" method returns null " +
\r
597 "if the \"name\" attribute does not exist.";
\r
599 // Access the last child of the first employee.
\r
601 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);
\r
603 // Invoke its "getAttributeNode(name)" method where name = "invalidAttribute"
\r
604 // This should result in a null value being returned by the method.
\r
606 computedValue = addressElement.GetAttributeNode("invalidAttribute");//.node.
\r
608 catch(System.Exception ex)
\r
610 computedValue = "Exception " + ex.Message;
\r
613 // Write out results
\r
615 results.expected = (expectedValue == null).ToString();
\r
616 results.actual = (computedValue == null).ToString();
\r
618 AssertEquals (results.expected, results.actual);
\r
621 //------------------------ End test case core-0010E --------------------------
\r
623 //-------------------------- test case core-0011E ----------------------------
\r
625 // Testing feature - The "setAttributeNode(newAttr)" adds a new attribute
\r
628 // Testing approach - Retrieve the last child of the first employee and
\r
629 // add a new attribute node to it by invoking its
\r
630 // "setAttributeNode(newAttr)" method. This test makes
\r
631 // use of the "createAttribute(name)" method from the
\r
632 // Document interface.
\r
634 // Semantic Requirements: 1, 11
\r
636 //----------------------------------------------------------------------------
\r
639 public void core0011E()
\r
641 string computedValue = "";
\r
642 string expectedValue = "";
\r
643 System.Xml.XmlElement addressElement = null;
\r
644 System.Xml.XmlAttribute newAttribute = null;
\r
645 string name = "district";
\r
647 testResults results = new testResults("Core0011E");
\r
650 results.description = "The \"setAttributeNode(newAttr)\" method adds a new " +
\r
651 "attribute node to the element.";
\r
653 // Access the last child of the first employee.
\r
655 newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,name);
\r
656 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);
\r
658 // Invoke its "setAttributeNode(newAttr)" method where
\r
659 // newAttr = "newAttribute". Since no value was specified or given
\r
660 // by default, its value should be the empty string.
\r
662 addressElement.SetAttributeNode(newAttribute);//.node.
\r
663 computedValue = addressElement.GetAttribute(name);//.node.
\r
665 catch(System.Exception ex)
\r
667 computedValue = "Exception " + ex.Message;
\r
670 // Write out results
\r
672 results.expected = expectedValue;
\r
673 results.actual = computedValue;
\r
677 AssertEquals (results.expected, results.actual);
\r
680 //------------------------ End test case core-0011E --------------------------
\r
682 //-------------------------- test case core-00012E ----------------------------
\r
684 // Testing feature - The "setAttributeNode(newAttr)" method adds a new attribute
\r
685 // to the Element. If the "newAttr" Attr node is already
\r
686 // present in this element, it should replace the existing
\r
689 // Testing approach - Retrieve the last child of the third employee and
\r
690 // add a new attribute node to it by invoking its
\r
691 // "setAttributeNode(newAttr)" method. The new attribute
\r
692 // node to be added is "street", which is already
\r
693 // present in this element. The method should replace the
\r
694 // existing Attr node with the new one. This test make use
\r
695 // of the "createAttribute(name)" method from the Document
\r
698 // Semantic Requirements: 1, 12
\r
700 //----------------------------------------------------------------------------
\r
703 public void core0012E()
\r
705 string computedValue = "";
\r
706 string expectedValue = "";
\r
707 System.Xml.XmlElement addressElement = null;
\r
708 System.Xml.XmlAttribute newAttribute = null;
\r
710 testResults results = new testResults("Core0012E");
\r
713 results.description = "The \"setAttributeNode(newAttr)\" method when " +
\r
714 "the \"newAttr\" node is already part of this " +
\r
715 "element. The existing attribute node should be "+
\r
716 "replaced with the new one.";
\r
718 // Access the last child of the third employee.
\r
720 newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"street");
\r
721 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
\r
723 // Invoke its "setAttributeNode(newAttr)" method where
\r
724 // newAttr = "newAttribute". That attribute is already part of this
\r
725 // element. The existing attribute should be replaced with the new one
\r
728 addressElement.SetAttributeNode(newAttribute);//.node.
\r
729 computedValue = addressElement.GetAttribute("street");//.node.
\r
731 catch(System.Exception ex)
\r
733 computedValue = "Exception " + ex.Message;
\r
736 // Write out results
\r
738 results.expected = expectedValue;
\r
739 results.actual = computedValue;
\r
743 AssertEquals (results.expected, results.actual);
\r
746 //------------------------ End test case core-0012E --------------------------
\r
748 //-------------------------- test case core-00013E ----------------------------
\r
750 // Testing feature - If The "setAttributeNode(newAttr)" method replaces
\r
751 // an existing Attr node with the same name, then it
\r
752 // should return the previously existing Attr node.
\r
754 // Testing approach - Retrieve the last child of the third employee and add
\r
755 // a new attribute node to it. The new attribute node to
\r
756 // be added is "street", which is already present in this
\r
757 // Element. The method should return the existing Attr
\r
758 // node(old "street" Attr). This test make use of the
\r
759 // "createAttribute(name)" method from the Document
\r
762 // Semantic Requirements: 1, 13
\r
764 //----------------------------------------------------------------------------
\r
767 public void core0013E()
\r
769 string computedValue = "";
\r
770 string expectedValue = "No";
\r
771 System.Xml.XmlElement addressElement = null;
\r
772 System.Xml.XmlAttribute oldStreetAttribute = null;
\r
773 System.Xml.XmlAttribute newAttribute = null;
\r
775 testResults results = new testResults("Core0013E");
\r
778 results.description = "The \"setAttributeNode(newAttr)\" method when the " +
\r
779 "\"newAttr\" attribute node is already present in " +
\r
780 "this element. The method should return the previously " +
\r
781 "existing Attr node.";
\r
783 // Access the last child of the third employee.
\r
785 newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"street");
\r
786 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
\r
788 // Invoke its "setAttributeNode(newAttr)" method where
\r
789 // newAttr was just created with the same name as an already existing
\r
790 // attribute("street"). The existing attribute should be replaced with the
\r
791 // new one and the method should return the existing "street" Attr node.
\r
793 oldStreetAttribute = addressElement.SetAttributeNode(newAttribute);//.node.
\r
795 // The "oldStreetAttribute" now contains the old Attr node and its
\r
796 // "value" attribute should be available for examination.
\r
798 computedValue = oldStreetAttribute.Value;
\r
800 catch(System.Exception ex)
\r
802 computedValue = "Exception " + ex.Message;
\r
806 // Write out results
\r
808 results.expected = expectedValue;
\r
809 results.actual = computedValue;
\r
813 AssertEquals (results.expected, results.actual);
\r
816 //------------------------ End test case core-0013E --------------------------
\r
818 //-------------------------- test case core-00014E ----------------------------
\r
820 // Testing feature - The "setAttributeNode(newAttr)" method returns the
\r
821 // null value if no previously existing Attr node with the
\r
822 // same name was replaced.
\r
824 // Testing approach - Retrieve the last child of the third and add a new
\r
825 // attribute node to it. The new attribute node to be
\r
826 // added is "district", which is not part of this Element.
\r
827 // The method should return the null value. This test makes
\r
828 // use of the "createAttribute(name)" method from the
\r
829 // Document interface.
\r
831 // Semantic Requirements: 1, 15
\r
833 //----------------------------------------------------------------------------
\r
836 [Category ("NotDotNet")] // MS DOM is buggy
\r
837 public void core0014E()
\r
839 object computedValue = null;
\r
840 object expectedValue = null;
\r
841 System.Xml.XmlElement addressElement = null;
\r
842 System.Xml.XmlAttribute newAttribute = null;
\r
844 testResults results = new testResults("Core0014E");
\r
847 results.description = "The \"setAttributeNode(newAttr)\" method returns a " +
\r
848 "null value if no previously existing Attr node was replaced.";
\r
850 // Access the sixth child of the third employee.
\r
852 newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");
\r
853 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
\r
855 // Invoke its "setAttributeNode(newAttr)" method where name = "newAttribute".
\r
856 // This attribute is not part of this element. The method should add the
\r
857 // new Attribute and return a null value.
\r
859 computedValue = addressElement.SetAttributeNode(newAttribute);//.node.
\r
861 catch(System.Exception ex)
\r
863 computedValue = "Exception " + ex.Message;
\r
867 // Write out results
\r
869 results.expected = (expectedValue == null).ToString();
\r
870 results.actual = (computedValue == null).ToString();
\r
874 AssertEquals (results.expected, results.actual);
\r
877 //------------------------ End test case core-0014E --------------------------
\r
879 //-------------------------- test case core-00015E ----------------------------
\r
881 // Testing feature - The "removeAttributeNode(oldAttr)" method removes the
\r
882 // specified attribute.
\r
884 // Testing approach - Retrieve the last child of the third employee, add
\r
885 // a new "district" node to it and the try to remove it.
\r
886 // To verify that the node was removed this test uses the
\r
887 // "getNamedItem(name)" from the NamedNodeMap interface.
\r
888 // This test also makes use of the "attributes" attribute
\r
889 // from the Node interface.
\r
891 // Semantic Requirements: 1, 14
\r
893 //----------------------------------------------------------------------------
\r
896 public void core0015E()
\r
898 object computedValue = null;
\r
899 object expectedValue = null;
\r
900 System.Xml.XmlElement addressElement = null;
\r
901 System.Xml.XmlAttributeCollection attrList = null;
\r
902 System.Xml.XmlAttribute newAttribute = null;
\r
903 newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");
\r
905 testResults results = new testResults("Core0015E");
\r
908 results.description = "The \"removeAttributeNode(oldAttr)\" method removes the " +
\r
909 "specified attribute node.";
\r
911 // Access the sixth child of the third employee and add the new
\r
912 // attribute to it.
\r
914 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
\r
915 addressElement.SetAttributeNode(newAttribute);//.node.
\r
917 // Invoke its "removeAttributeNode(oldAttr)" method where
\r
918 // name = "newAttribute" and remove that attribute node.
\r
920 addressElement.RemoveAttributeNode(newAttribute);//.node.
\r
922 // To ensure that the "district" attribute was indeed removed, a listing
\r
923 // of all attributes is created by invoking the "attributes" attribute
\r
924 // of "addressElement". After the list is created, we attempt to
\r
925 // retrieve the "district" element from the list. A null value should
\r
926 // be return in its place.
\r
928 attrList = addressElement.Attributes;
\r
929 computedValue = attrList.GetNamedItem("district");
\r
931 catch(System.Exception ex)
\r
933 computedValue = "Exception " + ex.Message;
\r
936 // Write out results
\r
938 results.expected = (expectedValue == null).ToString();
\r
939 results.actual = (computedValue == null).ToString();
\r
943 AssertEquals (results.expected, results.actual);
\r
946 //------------------------ End test case core-0015E --------------------------
\r
948 //-------------------------- test case core-00016E ----------------------------
\r
950 // Testing feature - The "removeAttributeNode(oldAttr)" method removes the
\r
951 // specified attribute node and restore any default values.
\r
953 // Testing approach - Retrieve the last child of the third employee and
\r
954 // remove its "street" Attr node. Since this node has
\r
955 // default value defined in the DTD file, that default
\r
956 // value should immediately be the new value.
\r
958 // Semantic Requirements: 1, 15
\r
960 //----------------------------------------------------------------------------
\r
964 [Category ("NotDotNet")]
\r
966 public void core0016E()
\r
968 string computedValue = "";
\r
969 string expectedValue = "Yes";
\r
970 System.Xml.XmlElement addressElement = null;
\r
971 System.Xml.XmlAttribute streetAttr = null;
\r
972 //System.Xml.XmlNode thirdEmployee = null;
\r
974 testResults results = new testResults("Core0016E");
\r
977 results.description = "The \"removeAttributeNode(oldAttr)\" method removes the " +
\r
978 "specified attribute node and restores any default values.";
\r
980 // Access the sixth child of the third employee.
\r
982 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
\r
984 // Create an instance of an Attr object by retrieving the "street"
\r
985 // attribute node, invoke its "removeAttributeNode(oldAttr)" method
\r
986 // where name = "streetAttr" and remove that attribute node. Note that
\r
987 // "the removeAttributeNode(oldAttr)" takes an Attr object as its
\r
988 // parameter, that is why an Attr object (named "street") is first created.
\r
990 streetAttr = addressElement.GetAttributeNode("street");//.node.
\r
991 addressElement.RemoveAttributeNode(streetAttr);//.node.
\r
993 // Since there is a default value defined for the "street" attribute, it
\r
994 // should immediately be the new value for that attribute.
\r
996 computedValue = addressElement.GetAttribute("street");//.node.
\r
998 catch(System.Exception ex)
\r
1000 computedValue = "Exception " + ex.Message;
\r
1004 // Write out results
\r
1006 results.expected = expectedValue;
\r
1007 results.actual = computedValue;
\r
1011 AssertEquals (results.expected, results.actual);
\r
1014 //------------------------ End test case core-0016E --------------------------
\r
1016 //-------------------------- test case core-00017E ----------------------------
\r
1018 // Testing feature - The "removeAttributeNode(oldAttr)" method returns the
\r
1019 // node that was removed.
\r
1021 // Testing approach - Retrieve the last child of the third employee and
\r
1022 // remove its "street" Attr node. The method should
\r
1023 // return the old attribute node.
\r
1025 // Semantic Requirements: 1, 16
\r
1027 //----------------------------------------------------------------------------
\r
1030 public void core0017E()
\r
1032 string computedValue = "";
\r
1033 string expectedValue = "No";
\r
1034 System.Xml.XmlElement addressElement = null;
\r
1035 System.Xml.XmlAttribute streetAttr = null;
\r
1036 System.Xml.XmlAttribute oldStreetAttribute = null;
\r
1038 testResults results = new testResults("Core0017E");
\r
1041 results.description = "The \"removeAttributeNode(oldAttr)\" method returns the "+
\r
1042 "removed attribute node.";
\r
1044 // Access the sixth child of the third employee.
\r
1046 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
\r
1048 // create an instance of an Attr object by retrieving the "street"
\r
1049 // attribute node, invoke its "removeAttributeNode(oldAttr)" method
\r
1050 // where name = "streetAttr" and remove that attribute node. Note that
\r
1051 // "the removeAttributeNode(oldAttr)" takes an Attr object as its
\r
1052 // parameter, that is why an Attr object (named "street") is first created.
\r
1054 streetAttr = addressElement.GetAttributeNode("street");//.node.
\r
1055 oldStreetAttribute = addressElement.RemoveAttributeNode(streetAttr);//.node.
\r
1057 // The method should return the removed attribute node. Its value can then
\r
1060 computedValue = oldStreetAttribute.Value;
\r
1062 catch(System.Exception ex)
\r
1064 computedValue = "Exception " + ex.Message;
\r
1067 // Write out results
\r
1069 results.expected = expectedValue;
\r
1070 results.actual = computedValue;
\r
1074 AssertEquals (results.expected, results.actual);
\r
1077 //------------------------ End test case core-0017E --------------------------
\r
1079 //-------------------------- test case core-00018E ----------------------------
\r
1081 // Testing feature - The "getElementsByTagName(name)" method returns a list
\r
1082 // of all descendant Elements with the given tag name.
\r
1084 // Testing approach - Get a listing of all the descendant elements of the
\r
1085 // root element using the string "employee" as the tag
\r
1086 // name. The method should return a Node list of length
\r
1087 // equal to 5. This test makes use of the "length"
\r
1088 // attribute from the NodeList interface.
\r
1090 // Semantic Requirements: 1, 17
\r
1092 //----------------------------------------------------------------------------
\r
1095 public void core0018E()
\r
1097 int computedValue = 0;
\r
1098 int expectedValue = 5;
\r
1099 System.Xml.XmlNodeList employeeList = null;
\r
1100 System.Xml.XmlElement docElement = null;
\r
1102 testResults results = new testResults("Core0018E");
\r
1104 results.description = "The \"getElementsByTagName(name)\" method returns a "+
\r
1105 "NodeList of all descendant elements with the given " +
\r
1106 "tag name(method returning a non-empty list)";
\r
1108 // get a listing of all the elements that match the tag "employee".
\r
1110 docElement = util.getRootNode();
\r
1111 employeeList = docElement.GetElementsByTagName("employee");
\r
1113 // The method should return a NodeList whose length can then be examined.
\r
1115 computedValue = employeeList.Count;
\r
1117 // Write out results
\r
1119 results.expected = expectedValue.ToString();
\r
1120 results.actual = computedValue.ToString();
\r
1122 AssertEquals (results.expected, results.actual);
\r
1125 //------------------------ End test case core-0018E --------------------------
\r
1127 //-------------------------- test case core-00019E ----------------------------
\r
1129 // Testing feature - The "getElementsByTagName(name)" returns a list of all
\r
1130 // descendant Elements with the given tag name. Test
\r
1131 // for an empty list.
\r
1133 // Testing approach - Get a listing of all the descendant elements of the
\r
1134 // root element using the string "noMatches" as the tag
\r
1135 // name. The method should return a NodeList of length
\r
1136 // equal to 0 since no descendant elements match the given
\r
1137 // tag name. This test makes use of the "length" attribute
\r
1138 // from the NodeList interface.
\r
1140 // Semantic Requirements: 1, 17
\r
1142 //----------------------------------------------------------------------------
\r
1145 public void core0019E()
\r
1147 int computedValue = 0;
\r
1148 int expectedValue = 0;
\r
1149 System.Xml.XmlNodeList employeeList = null;
\r
1150 System.Xml.XmlElement docElement = null;
\r
1152 testResults results = new testResults("Core0019E");
\r
1154 results.description = "The \"getElementsByTagName(name)\" method returns a "+
\r
1155 "NodeList of all descendant elements with the given " +
\r
1156 "tag name (method returns an empty list)";
\r
1158 // get a listing of all the elements that match the tag "noMatch".
\r
1160 docElement = util.getRootNode();
\r
1161 employeeList = docElement.GetElementsByTagName("noMatch");
\r
1163 // The method should return a NodeList whose length can then be examined.
\r
1165 computedValue = employeeList.Count;
\r
1167 // Write out results
\r
1169 results.expected = expectedValue.ToString();
\r
1170 results.actual = computedValue.ToString();
\r
1172 AssertEquals (results.expected, results.actual);
\r
1175 //------------------------ End test case core-0019E --------------------------
\r
1177 //-------------------------- test case core-00020E ----------------------------
\r
1179 // Testing feature - The "getElementsByTagName(name)" returns a list of all
\r
1180 // descendant Elements in the order the children were
\r
1181 // encountered in a pre order traversal of the element tree.
\r
1183 // Testing approach - Get a listing of all the descendant elements of the
\r
1184 // root node using the string "employee" as the tag
\r
1185 // name. The method should return a Node list of length
\r
1186 // equal to 5 in the order the children were encountered.
\r
1187 // Item number four in the list is accessed using a
\r
1188 // subscript. Item number four is itself an Element node
\r
1189 // with children and whose first child should be
\r
1192 // Semantic Requirements: 1, 18
\r
1194 //----------------------------------------------------------------------------
\r
1197 public void core0020E()
\r
1199 string computedValue = "";
\r
1200 string expectedValue = "employeeId";
\r
1201 System.Xml.XmlNodeList employeeList = null;
\r
1202 System.Xml.XmlNode fourthEmployee = null;
\r
1203 System.Xml.XmlElement docElement = null;
\r
1205 testResults results = new testResults("Core0020E");
\r
1207 results.description = "The \"getElementsByTagName(name)\" returns a NodeList " +
\r
1208 "of all descendant elements in the order the " +
\r
1209 "children were encountered in a preorder traversal " +
\r
1210 "of the element tree.";
\r
1212 // get a listing of all the elements that match the tag "employee".
\r
1214 docElement = util.getRootNode();
\r
1215 employeeList = docElement.GetElementsByTagName("employee");
\r
1218 // The method should return a NodeList of the children in the order the
\r
1219 // children were encountered. Since "employeeList" is a NodeList we should
\r
1220 // be able to access its elements by using a subscript. Item number four
\r
1221 // is itself an Element node with six children and the first child
\r
1222 // is "employeeId".
\r
1224 fourthEmployee = employeeList.Item(util.FOURTH);
\r
1225 computedValue = fourthEmployee.FirstChild.Name;
\r
1227 // Write out results
\r
1229 results.expected = expectedValue;
\r
1230 results.actual = computedValue;
\r
1232 AssertEquals (results.expected, results.actual);
\r
1235 //------------------------ End test case core-0020E --------------------------
\r
1237 //-------------------------- test case core-00021E ----------------------------
\r
1239 // Testing feature - The "getElementsByTagName(name)" method may use the
\r
1240 // special value "*" to match all the tags in the element
\r
1243 // Testing approach - Get a listing of all the descendant elements of the
\r
1244 // last employee by using the special value of "*". The
\r
1245 // method should return all of the descendant children
\r
1246 // (total of 6) in the order the children were encountered.
\r
1248 // Semantic Requirements: 1, 19
\r
1250 //----------------------------------------------------------------------------
\r
1253 public void core0021E()
\r
1255 string computedValue = "";
\r
1256 string expectedValue = "employeeId name position salary gender address ";
\r
1257 System.Xml.XmlNodeList elementList = null;
\r
1258 System.Xml.XmlElement lastEmployee = null;
\r
1260 testResults results = new testResults("Core0021E");
\r
1262 results.description = "The \"getElementsByTagName(name)\" method may use the " +
\r
1263 "special value \"*\" to match all the tags in the " +
\r
1266 // get a listing of all the descendant elements of the last employee by using
\r
1267 // the special value of "*".
\r
1269 lastEmployee = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,-1);
\r
1270 elementList = lastEmployee.GetElementsByTagName("*");//.node.
\r
1272 // Traverse the list.
\r
1274 for (int index = 0;index <= elementList.Count - 1;index++)
\r
1275 computedValue += elementList.Item(index).Name+" ";
\r
1277 // Write out results
\r
1279 results.expected = expectedValue;
\r
1280 results.actual = computedValue;
\r
1282 AssertEquals (results.expected, results.actual);
\r
1285 //------------------------ End test case core-0021E --------------------------
\r
1287 //-------------------------- test case core-00022E ----------------------------
\r
1289 // Testing feature - The "normalize()" method puts all the nodes in the
\r
1290 // full depth of the sub-tree underneath this element
\r
1291 // into a "normal" form.
\r
1293 // Testing approach - Retrieve the third employee and access its second
\r
1294 // child. This child contains a block of text that spread
\r
1295 // accross multiple lines. The content of the "name"
\r
1296 // child should be parsed and treated as a single Text node.
\r
1298 // Semantic Requirements: 1, 20
\r
1300 //----------------------------------------------------------------------------
\r
1303 public void core0022E()
\r
1305 string computedValue = "";
\r
1306 string expectedValue = "Roger\n Jones";
\r
1307 System.Xml.XmlNode idElement = null;
\r
1308 System.Xml.XmlNode textNode = null;
\r
1310 testResults results = new testResults("Core0022E");
\r
1313 results.description = "The \"normalize()\" method puts all the nodes in the " +
\r
1314 "full depth of the sub-tree of this element into a normal form.";
\r
1316 // The "normalize() method should combine all the contiguous blocks of text
\r
1317 // and form a single "Text" node. The "nodeValue" of that final Text node
\r
1318 // should be the combination of all continuos blocks of text that do not
\r
1319 // contain any markup language.
\r
1321 idElement = util.nodeObject(util.THIRD,util.SECOND);
\r
1322 idElement.Normalize();//.node.
\r
1323 textNode = idElement.LastChild;//.node.
\r
1325 // text should be in normal form now
\r
1327 computedValue = textNode.Value;
\r
1329 catch(System.Exception ex)
\r
1331 computedValue = "Exception " + ex.Message;
\r
1335 // Write out results
\r
1337 results.expected = expectedValue;
\r
1338 results.actual = computedValue;
\r
1342 AssertEquals (results.expected, results.actual);
\r
1345 //------------------------ End test case core-0022E --------------------------
\r
1347 //-------------------------- test case core-00023E ---------------------------
\r
1349 // Testing feature - The "setAttribute(name,value)" method raises an
\r
1350 // INVALID_CHARACTER_ERR Exception if the specified
\r
1351 // name contains an invalid character.
\r
1353 // Testing approach - Retrieve the last child of the first employee
\r
1354 // and call its "setAttribute(name,value)" method with
\r
1355 // "name" containing an invalid character.
\r
1357 // Semantic Requirements: 1, 21
\r
1359 //----------------------------------------------------------------------------
\r
1362 [Category ("NotDotNet")] // MS DOM is buggy
\r
1363 public void core0023E()
\r
1365 string computedValue = "";
\r
1366 System.Xml.XmlElement addressElement = null;
\r
1367 string expectedValue = "System.ArgumentException";
\r
1369 testResults results = new testResults("Core0023E");
\r
1372 results.description = "The \"setAttribute(name,value)\" method raises an " +
\r
1373 "ArgumentException if the specified " +
\r
1374 "name contains an invalid character.";
\r
1376 // Access the "address" element of the first employee.
\r
1378 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);
\r
1380 // Attempt to set an attribute with an invalid character in its name.
\r
1384 addressElement.SetAttribute("invalid^Name","thisValue");//.node.
\r
1386 catch(System.Exception ex)
\r
1388 computedValue = ex.GetType().ToString();
\r
1391 catch(System.Exception ex)
\r
1393 computedValue = "Exception " + ex.Message;
\r
1396 results.expected = expectedValue;
\r
1397 results.actual = computedValue;
\r
1401 AssertEquals (results.expected, results.actual);
\r
1404 //------------------------ End test case core-0023E --------------------------
\r
1406 //-------------------------- test case core-0024E ----------------------------
\r
1408 // Testing feature - The "setAttribute(name,value)" method raises a
\r
1409 // NO_MODIFICATION_ALLOWED_ERR Exception if this
\r
1410 // node is readonly.
\r
1412 // Testing approach - Retrieve the Element node inside the Entity node
\r
1413 // named "ent4" and attempt to set an attribute for
\r
1414 // it. Descendants of Entity nodes are readonly nodes
\r
1415 // and therefore the desired exception should be raised.
\r
1417 // Semantic Requirements: 22
\r
1419 //----------------------------------------------------------------------------
\r
1422 [Category ("NotDotNet")] // MS DOM is buggy
\r
1423 public void core0024E()
\r
1425 string computedValue = "";
\r
1426 System.Xml.XmlEntity entityNode = null;
\r
1427 System.Xml.XmlElement entityDesc = null;
\r
1428 string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;
\r
1430 testResults results = new testResults("Core0024E");
\r
1433 results.description = "The \"setAttribute(name,value)\" method raises a " +
\r
1434 "NO_MODIFICATION_ALLOWED_ERR Exception if the node is readonly.";
\r
1437 // Retreive the targeted data.
\r
1439 entityNode = util.getEntity("ent4");
\r
1440 entityDesc = (System.Xml.XmlElement)entityNode.FirstChild;
\r
1442 // Attempt to set an attribute for a readonly node should raise an exception.
\r
1446 entityDesc.SetAttribute("newAttribute","thisValue");
\r
1448 catch(System.Exception ex)
\r
1450 computedValue = ex.GetType ().FullName;
\r
1453 catch(System.Exception ex)
\r
1455 computedValue = "Exception " + ex.Message;
\r
1457 results.expected = expectedValue;
\r
1458 results.actual = computedValue;
\r
1462 AssertEquals (results.expected, results.actual);
\r
1465 //------------------------ End test case core-0024E --------------------------
\r
1467 //-------------------------- test case core-00025E ---------------------------
\r
1469 // Testing feature - The "removeAttribute(name)" method raises a
\r
1470 // NO_MODIFICATION_ALLOWED_ERR Exception if this
\r
1471 // node is readonly.
\r
1473 // Testing approach - Retrieve the Element node inside the Entity node
\r
1474 // named "ent4" and attempt to remove an attribute from
\r
1475 // it. Descendants of Entity nodes are readonly nodes
\r
1476 // and therefore the desired exception should be raised.
\r
1478 // Semantic Requirements: 23
\r
1480 //----------------------------------------------------------------------------
\r
1483 [Category ("NotDotNet")] // MS DOM is buggy
\r
1484 public void core0025E()
\r
1486 string computedValue = "";
\r
1487 System.Xml.XmlEntity entityNode = null;
\r
1488 System.Xml.XmlElement entityDesc = null;
\r
1489 string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;
\r
1491 testResults results = new testResults("Core0025E");
\r
1494 results.description = "The \"removeAttribute(name)\" method raises a " +
\r
1495 "NO_MODIFICATION_ALLOWED_ERR Exception if the node is readonly.";
\r
1497 // Retrieve the targeted data.
\r
1499 entityNode = util.getEntity("ent4");
\r
1500 entityDesc = (System.Xml.XmlElement)entityNode.FirstChild;
\r
1502 // Attempt to set an attribute for a readonly node should raise an exception.
\r
1506 entityDesc.RemoveAttribute("attr1");
\r
1508 catch(System.Exception ex)
\r
1510 computedValue = ex.GetType ().FullName;
\r
1513 catch(System.Exception ex)
\r
1515 computedValue = "Exception " + ex.Message;
\r
1517 results.expected = expectedValue;
\r
1518 results.actual = computedValue;
\r
1522 AssertEquals (results.expected, results.actual);
\r
1525 //------------------------ End test case core-0025E --------------------------
\r
1527 //-------------------------- test case core-00026E ---------------------------
\r
1529 // Testing feature - The "setAttributeNode(newAttr)" method raises a
\r
1530 // NO_MODIFICATION_ALLOWED_ERR Exception if this
\r
1531 // node is readonly.
\r
1533 // Testing approach - Retrieve the Element node inside the Entity node
\r
1534 // named "ent4" and attempt to add a newly created Attr
\r
1535 // node to it. Descendants of Entity nodes are readonly
\r
1536 // nodes and therefore the desired exception should be
\r
1539 // Semantic Requirements: 24
\r
1541 //----------------------------------------------------------------------------
\r
1544 [Category ("NotDotNet")] // MS DOM is buggy
\r
1545 public void core0026E()
\r
1547 string computedValue = "";
\r
1548 System.Xml.XmlEntity entityNode = null;
\r
1549 System.Xml.XmlElement entityDesc = null;
\r
1550 System.Xml.XmlAttribute newAttr = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"newAttribute");
\r
1551 string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;
\r
1553 testResults results = new testResults("Core0026E");
\r
1556 results.description = "The \"setAttributeNode(newAttr)\" method raises a " +
\r
1557 "NO_MODIFICATION_ALLOWED_ERR Exception if the node is readonly.";
\r
1559 // Retrieve targeted data
\r
1561 entityNode = util.getEntity("ent4");
\r
1562 entityDesc = (System.Xml.XmlElement)entityNode.FirstChild;
\r
1564 // Attempt to set an attribute for a readonly node should raise an exception.
\r
1568 entityDesc.SetAttributeNode(newAttr);
\r
1570 catch(System.Exception ex)
\r
1572 computedValue = ex.GetType ().FullName;
\r
1575 catch(System.Exception ex)
\r
1577 computedValue = "Exception " + ex.Message;
\r
1579 results.expected = expectedValue;
\r
1580 results.actual = computedValue;
\r
1584 AssertEquals (results.expected, results.actual);
\r
1587 //------------------------ End test case core-0026E --------------------------
\r
1589 //-------------------------- test case core-00027E ---------------------------
\r
1591 // Testing feature - The "removeAttributeNode(newAttr)" method raises a
\r
1592 // NO_MODIFICATION_ALLOWED_ERR Exception if this
\r
1593 // node is readonly.
\r
1595 // Testing approach - Retrieve the Element node inside the Entity node
\r
1596 // named "ent4" and attempt to remove its "attr1"
\r
1597 // attribute. Descendants of Entity nodes are readonly
\r
1598 // nodes and therefore the desired exception should be
\r
1601 // Semantic Requirements: 25
\r
1603 //----------------------------------------------------------------------------
\r
1606 [Category ("NotDotNet")] // MS DOM is buggy
\r
1607 public void core0027E()
\r
1609 string computedValue = "";
\r
1610 System.Xml.XmlEntity entityNode = null;
\r
1611 System.Xml.XmlElement entityDesc = null;
\r
1612 System.Xml.XmlAttribute oldAttribute = null;
\r
1613 string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;
\r
1615 testResults results = new testResults("Core0027E");
\r
1618 results.description = "The \"removeAttributeNode(newAttr)\" method raises a " +
\r
1619 "NO_MODIFICATION_ALLOWED_ERR Exception if the node is readonly.";
\r
1621 // Get an instance of an attribute node and retrieve targeted data.
\r
1623 entityNode = util.getEntity("ent4");
\r
1624 entityDesc = (System.Xml.XmlElement)entityNode.FirstChild;
\r
1625 oldAttribute = ((System.Xml.XmlElement)entityNode.FirstChild).GetAttributeNode("attr1");
\r
1627 // Attempt to set remove an attribute node from a readonly node (lastChild).
\r
1628 // Should raise an exception.
\r
1632 entityDesc.RemoveAttributeNode(oldAttribute);
\r
1634 catch(System.Exception ex)
\r
1636 computedValue = ex.GetType ().FullName;
\r
1639 catch(System.Exception ex)
\r
1641 computedValue = "Exception " + ex.Message;
\r
1643 results.expected = expectedValue;
\r
1644 results.actual = computedValue;
\r
1648 AssertEquals (results.expected, results.actual);
\r
1651 //------------------------ End test case core-0027E --------------------------
\r
1653 //-------------------------- test case core-00028E ---------------------------
\r
1655 // Testing feature - The "setAttributeNode(newAttr)" method raises a
\r
1656 // System.ArgumentException Exception if the "newAttr" was
\r
1657 // created from a different document than the one that
\r
1658 // created this document.
\r
1660 // Testing approach - Retrieve the last employee and attempt to set
\r
1661 // a new attribute node for its "employee" element.
\r
1662 // The new attribute was created from a document
\r
1663 // other than the one that crated this element,
\r
1664 // therefore the desired exception should be raised.
\r
1665 // This test uses the "createAttribute(newAttr)" method
\r
1666 // from the Document interface.
\r
1668 // Semantic Requirements: 26
\r
1670 //----------------------------------------------------------------------------
\r
1673 [Category ("NotDotNet")] // MS DOM is buggy
\r
1674 public void core0028E()
\r
1676 System.Xml.XmlElement addressElement = null;
\r
1677 string computedValue = "";
\r
1678 System.Xml.XmlAttribute newAttr = null;
\r
1679 string expectedValue = "System.ArgumentException";
\r
1681 testResults results = new testResults("Core0028E");
\r
1684 results.description = "The \"setAttributeNode(newAttr)\" method raises a " +
\r
1685 "System.ArgumentException Exception if \"newAttr\" was created " +
\r
1686 "from a different document than the one who created this node.";
\r
1688 // Access the address Element of the last employee and attempt to set
\r
1689 // a new attribute node.
\r
1691 newAttr = util.getOtherDOMDocument().CreateAttribute("newAttribute");
\r
1692 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.SIXTH);
\r
1694 // The new attribute was created from a different document and therefore
\r
1695 // an exception should be raised.
\r
1699 addressElement.SetAttributeNode(newAttr);//.node.
\r
1701 catch(System.Exception ex)
\r
1703 computedValue = ex.GetType().ToString();
\r
1706 catch(System.Exception ex)
\r
1708 computedValue = "Exception " + ex.Message;
\r
1710 results.expected = expectedValue;
\r
1711 results.actual = computedValue;
\r
1715 AssertEquals (results.expected, results.actual);
\r
1718 //------------------------ End test case core-0028E --------------------------
\r
1720 //-------------------------- test case core-00029E ---------------------------
\r
1722 // Testing feature - The "setAttributeNode(newAttr)" method raises an
\r
1723 // InvalidOperationException if the "newAttr"
\r
1724 // attribute is already an attribute of another element.
\r
1726 // Testing approach - Retrieve the last employee and attempt to set an
\r
1727 // attribute node to one of its children that
\r
1728 // already exist in another children. The attribute
\r
1729 // node used is "street", which already exist in the
\r
1730 // "address" element. An instance of that attribute
\r
1731 // node is first retrived from the "address" element and
\r
1732 // then attempted to be set in the "employeeId" element.
\r
1733 // This should cause the intended exception to be raised.
\r
1735 // Semantic Requirements: 27
\r
1737 //----------------------------------------------------------------------------
\r
1740 public void core0029E()
\r
1742 string computedValue = "";
\r
1743 System.Xml.XmlElement employeeIdElement = null;
\r
1744 System.Xml.XmlElement addressElement = null;
\r
1745 System.Xml.XmlAttribute newAttribute = null;
\r
1746 string expectedValue = "InvalidOperationException";
\r
1748 testResults results = new testResults("Core0029E");
\r
1751 results.description = "The \"setAttributeNode(newAttr)\" method raises an "+
\r
1752 "InvalidOperationException if \"newAttr\" attribute "+
\r
1753 "is already being used by another element.";
\r
1755 // Retrieve an already existing attribute from the "address" element.
\r
1757 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.SIXTH);
\r
1758 newAttribute = addressElement.GetAttributeNode("street");//.node.
\r
1760 // Access the "employeeId" element of the last employee.
\r
1762 employeeIdElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.FIRST);
\r
1764 // Attempt to set an attribute node with an already existing attribute node
\r
1765 // in another element.
\r
1769 employeeIdElement.SetAttributeNode(newAttribute);//.node.
\r
1771 catch(System.InvalidOperationException ex)
\r
1773 computedValue = "InvalidOperationException";
\r
1776 catch(System.Exception ex)
\r
1778 computedValue = "Exception " + ex.Message;
\r
1780 results.expected = expectedValue;
\r
1781 results.actual = computedValue;
\r
1785 AssertEquals (results.expected, results.actual);
\r
1788 //------------------------ End test case core-0029E -------------------------
\r
1790 //-------------------------- test case core-0030E ---------------------------
\r
1792 // Testing feature - The "removeAttributeNode(oldAttr)" method raises a
\r
1793 // NOT_FOUND_ERR Exception if the "oldAttr" attribute
\r
1794 // is not an attribute of the element.
\r
1796 // Testing approach - Retrieve the last employee and attempt to remove
\r
1797 // a non existing attribute node. This should cause
\r
1798 // the intended exception be raised. This test makes use
\r
1799 // of the "createAttribute(name)" method from the
\r
1800 // Document interface.
\r
1802 // Semantic Requirements: 28
\r
1804 //----------------------------------------------------------------------------
\r
1807 [Category ("NotDotNet")] // MS DOM is buggy
\r
1808 public void core0030E()
\r
1810 string computedValue = "";
\r
1811 System.Xml.XmlElement addressElement = null;
\r
1812 System.Xml.XmlAttribute oldAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"oldAttribute");
\r
1813 string expectedValue = "System.ArgumentException";//util.NOT_FOUND1_ERR;
\r
1815 testResults results = new testResults("Core0030E");
\r
1818 results.description = "The \"removeAttributeNode(oldAttr)\" method raises a " +
\r
1819 "NOT_FOUND_ERR Exception if \"oldAttr\" attribute " +
\r
1820 "is not an attribute of the element.";
\r
1822 // Access the "address" element of the last employee.
\r
1824 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.SIXTH);
\r
1826 // Attempt to remove a non-existing attribute. Should raise exception.
\r
1830 addressElement.RemoveAttributeNode(oldAttribute);//.node.
\r
1832 catch(ArgumentException ex)
\r
1834 computedValue = ex.GetType ().FullName;
\r
1837 catch(System.Exception ex)
\r
1839 computedValue = "Exception " + ex.Message;
\r
1841 results.expected = expectedValue;
\r
1842 results.actual = computedValue;
\r
1846 AssertEquals (results.expected, results.actual);
\r
1849 //------------------------ End test case core-0030E --------------------------
\r