1 //**************************************************************************
4 // National Institute Of Standards and Technology
7 // NamedNodeMap Interface
9 // Written by: Carmelo Montanez
10 // Modified by: Mary Brady
12 // Ported to System.Xml by: Mizrahi Rafael rafim@mainsoft.com
13 // Mainsoft Corporation (c) 2003-2004
14 //**************************************************************************
19 using NUnit
.Framework
;
21 namespace nist_dom
.fundamental
24 public class NamedNodeMapTest
: Assertion
26 public static int i
= 2;
28 public testResults[] RunTests()
30 testResults[] tests = new testResults[] {core0001M(), core0002M(), core0003M(),core0004M(),
31 core0005M(), core0006M(), core0007M(), core0008M(),
32 core0009M(), core0010M(), core0011M(),
33 core0014M(), core0015M(), core0016M(),
34 core0017M(), core0018M(), core0019M(), core0020M(),
40 //------------------------ test case core-0001M ------------------------
42 // Testing feature - The "getNamedItem(name)" method retrieves a node
45 // Testing approach - Retrieve the second employee and create a NamedNodeMap
46 // listing of the attributes of its last child. Once
47 // the list is created an invocation of the
48 // "getNamedItem(name)" method is done where
49 // name = "domestic". This should result on the domestic
50 // Attr node being returned.
52 // Semantic Requirements: 1
54 //----------------------------------------------------------------------------
57 public void core0001M()
59 string computedValue
= "";
60 string expectedValue
= "domestic";
61 System
.Xml
.XmlAttribute domesticAttr
= null;
62 System
.Xml
.XmlNode testNode
= null;
64 testResults results
= new testResults("Core0001M");
67 results
.description
= "The \"getNamedItem(name)\" method retrieves a node " +
70 // Retrieve targeted data.
72 testNode
= util
.nodeObject(util
.SECOND
,util
.SIXTH
);
73 domesticAttr
= (System
.Xml
.XmlAttribute
)testNode
.Attributes
.GetNamedItem("domestic");
74 computedValue
= domesticAttr
.Name
;
76 catch(System
.Exception ex
)
78 computedValue
= "Exception " + ex
.Message
;
84 results
.expected
= expectedValue
;
85 results
.actual
= computedValue
;
87 AssertEquals (results
.expected
, results
.actual
);
90 //------------------------ End test case core-0001M --------------------------
92 //--------------------------- test case core-0002M ---------------------------
94 // Testing feature - The "getNamedItem(name)" method returns a node of any
95 // type specified by name.
97 // Testing approach - Retrieve the second employee and create a NamedNodeMap
98 // listing of the attributes of its last child. Once
99 // the list is created an invocation of the
100 // "getNamedItem(name)" method is done where
101 // name = "street". This should cause the method to return
104 // Semantic Requirements: 2
106 //----------------------------------------------------------------------------
109 public void core0002M()
111 string computedValue
= "";
112 string expectedValue
= "street";
113 System
.Xml
.XmlAttribute streetAttr
= null;
114 System
.Xml
.XmlNode testNode
= null;
116 testResults results
= new testResults("Core0002M");
119 results
.description
= "The \"getNamedItem(name)\" method returns a node "+
120 "of any type specified by name (test for Attr node).";
122 // Retrieve targeted data and get its attributes.
124 testNode
= util
.nodeObject(util
.SECOND
,util
.SIXTH
);
125 streetAttr
= (System
.Xml
.XmlAttribute
)testNode
.Attributes
.GetNamedItem("street");
126 computedValue
= streetAttr
.Name
;
128 catch(System
.Exception ex
)
130 computedValue
= "Exception " + ex
.Message
;
136 results
.expected
= expectedValue
;
137 results
.actual
= computedValue
;
139 AssertEquals (results
.expected
, results
.actual
);
142 //------------------------ End test case core-0002M --------------------------
144 //--------------------------- test case core-0003M ---------------------------
146 // Testing feature - The "getNamedItem(name)" method returns null if the
147 // specified name did not identify any node in the map.
149 // Testing approach - Retrieve the second employee and create a NamedNodeMap
150 // listing of the attributes of its last child. Once
151 // the list is created an invocation of the
152 // "getNamedItem(name)" method is done where
153 // name = "district", this name does not match any names
154 // in the list and the method should return null.
156 // Semantic Requirements: 3
158 //----------------------------------------------------------------------------
161 public void core0003M()
163 object computedValue
= null;
164 object expectedValue
= null;
165 System
.Xml
.XmlNode testNode
= null;
168 testResults results
= new testResults("Core0003M");
171 results
.description
= "The \"getNamedItem(name)\" method returns null if the " +
172 "specified name did not identify any node in the map.";
174 // Retrieve targeted data and attempt to get a non-existing attribute.
176 testNode
= util
.nodeObject(util
.SECOND
,util
.SIXTH
);
177 computedValue
= testNode
.Attributes
.GetNamedItem("district");
179 catch(System
.Exception ex
)
181 computedValue
= "Exception " + ex
.Message
;
187 results
.expected
= (expectedValue
== null).ToString();
188 results
.actual
= (computedValue
== null).ToString();
190 AssertEquals (results
.expected
, results
.actual
);
193 //------------------------ End test case core-0003M --------------------------
195 //--------------------------- test case core-0004M ---------------------------
197 // Testing feature - The "setNamedItem(arg)" method adds a node using its
198 // nodeName attribute.
200 // Testing approach - Retrieve the second employee and create a NamedNodeMap
201 // object from the attributes in its last child
202 // by invoking the "attributes" attribute. Once the
203 // list is created, the "setNamedItem(arg)" method is
204 // invoked with arg = newAttr, where newAttr is a new
205 // Attr Node previously created. The "setNamedItem(arg)"
206 // method should add the new node to the NamedNodeItem
207 // object by using its "nodeName" attribute ("district"
208 // in this case). Further this node is retrieved by using
209 // the "getNamedItem(name)" method. This test uses the
210 // "createAttribute(name)" method from the Document
213 // Semantic Requirements: 4
215 //----------------------------------------------------------------------------
218 public void core0004M()
220 string computedValue
= "";
221 string expectedValue
= "district";
222 System
.Xml
.XmlAttribute districtAttr
= null;
223 System
.Xml
.XmlAttribute newAttr
= (System
.Xml
.XmlAttribute
)util
.createNode(util
.ATTRIBUTE_NODE
,"district");
224 System
.Xml
.XmlNode testNode
= null;
226 testResults results
= new testResults("Core0004M");
229 results
.description
= "The \"setNamedItem(arg)\" method adds a node "+
230 "using its nodeName attribute.";
232 // Retrieve targeted data and add new attribute.
234 testNode
= util
.nodeObject(util
.SECOND
,util
.SIXTH
);
235 testNode
.Attributes
.SetNamedItem(newAttr
);
236 districtAttr
= (System
.Xml
.XmlAttribute
)testNode
.Attributes
.GetNamedItem("district");
237 computedValue
= districtAttr
.Name
;
239 catch(System
.Exception ex
)
241 computedValue
= "Exception " + ex
.Message
;
247 results
.expected
= expectedValue
;
248 results
.actual
= computedValue
;
251 AssertEquals (results
.expected
, results
.actual
);
254 //------------------------ End test case core-0004M --------------------------
256 //--------------------------- test case core-0005 ---------------------------
258 // Testing feature - If the node to be added by the "setNamedItem(arg)" method
259 // already exists in the NamedNodeMap, it is replaced by the
262 // Testing approach - Retrieve the second employee and create a NamedNodeMap
263 // object from the attributes in its last child. Once
264 // the list is created, the "setNamedItem(arg) method is
265 // invoked with arg = newAttr, where newAttr is a Node Attr
266 // previously created and whose node name already exist
267 // in the map. The "setNamedItem(arg)" method should
268 // replace the already existing node with the new one.
269 // Further this node is retrieved by using the
270 // "getNamedItem(name)" method. This test uses the
271 // "createAttribute(name)" method from the Document
274 // Semantic Requirements: 5
276 //----------------------------------------------------------------------------
279 public void core0005M()
281 string computedValue
= "";
282 string expectedValue
= "";
283 System
.Xml
.XmlAttribute streetAttr
= null;
284 System
.Xml
.XmlAttribute newAttr
= (System
.Xml
.XmlAttribute
)util
.createNode(util
.ATTRIBUTE_NODE
,"street");
285 System
.Xml
.XmlNode testNode
= null;
287 testResults results
= new testResults("Core0005M");
290 results
.description
= "If the node to be replaced by the \"setNamedItem(arg)\" " +
291 "method is already in the list, the existing node should " +
292 "be replaced by the new one.";
295 // Retrieve targeted data and add new attribute with name matching an
296 // already existing attribute.
298 testNode
= util
.nodeObject(util
.SECOND
,util
.SIXTH
);
299 testNode
.Attributes
.SetNamedItem(newAttr
);
300 streetAttr
= (System
.Xml
.XmlAttribute
)testNode
.Attributes
.GetNamedItem("street");
301 computedValue
= streetAttr
.Value
;
303 catch(System
.Exception ex
)
305 computedValue
= "Exception " + ex
.Message
;
310 results
.expected
= expectedValue
;
311 results
.actual
= computedValue
;
314 AssertEquals (results
.expected
, results
.actual
);
317 //------------------------ End test case core-0005M --------------------------
319 //--------------------------- test case core-0006 ---------------------------
321 // Testing feature - If the "setNamedItem(arg)" method replaces an already
322 // existing node with the same name then the already existing
325 // Testing approach - Retrieve the third employee and create a "NamedNodeMap"
326 // object of the attributes in its last child by
327 // invoking the "attributes" attribute. Once the
328 // list is created, the "setNamedItem(arg) method is
329 // invoked with arg = newAttr, where newAttr is a Node Attr
330 // previously created and whose node name already exist
331 // in the map. The "setNamedItem(arg)" method should replace
332 // the already existing node with the new one and return
333 // the existing node. Further this node is retrieved by
334 // using the "getNamedItem(name)" method. This test
335 // uses the "createAttribute(name)" method from the Document
338 // Semantic Requirements: 6
340 //----------------------------------------------------------------------------
343 public void core0006M()
345 string computedValue
= "";
346 string expectedValue
= "No";
347 System
.Xml
.XmlNode returnedNode
= null;
348 System
.Xml
.XmlAttribute newAttr
= (System
.Xml
.XmlAttribute
)util
.createNode(util
.ATTRIBUTE_NODE
,"street");
349 System
.Xml
.XmlNode testNode
= null;
351 testResults results
= new testResults("Core0006M");
354 results
.description
= "If the \"setNamedItem(arg)\" method replaces an "+
355 "already existing node with the same name then it "+
356 "returns the already existing node.";
358 // Retrieve targeted data and examine value returned by the setNamedItem
361 testNode
= util
.nodeObject(util
.THIRD
,util
.SIXTH
);
362 returnedNode
= testNode
.Attributes
.SetNamedItem(newAttr
);
363 computedValue
= returnedNode
.Value
;
365 catch(System
.Exception ex
)
367 computedValue
= "Exception " + ex
.Message
;
372 results
.expected
= expectedValue
;
373 results
.actual
= computedValue
;
376 AssertEquals (results
.expected
, results
.actual
);
379 //------------------------ End test case core-0006M --------------------------
381 //--------------------------- test case core-0007 ---------------------------
383 // Testing feature - The "setNamedItem(arg)" method replace an
384 // already existing node with the same name. If a node with
385 // that name is already present in the collection,
386 // it is replaced by the new one.
388 // Testing approach - Retrieve the third employee and create a NamedNodeMap
389 // object from the attributes in its last child.
390 // Once the list is created, the "setNamedItem(arg)"
391 // method is invoked with arg = newAttr, where newAttr is
392 // a new previously created Attr node The
393 // "setNamedItem(arg)" method should add the new node
394 // and return the new one. Further this node is retrieved by
395 // using the "getNamedItem(name)" method. This test
396 // uses the "createAttribute(name)" method from the
397 // Document interface.
399 // Semantic Requirements: 7
401 //----------------------------------------------------------------------------
404 public void core0007M()
406 string computedValue
= "";
407 string expectedValue
= "district";
408 System
.Xml
.XmlAttribute newAttr
= (System
.Xml
.XmlAttribute
)util
.createNode(util
.ATTRIBUTE_NODE
,"district");
409 System
.Xml
.XmlNode testNode
= null;
411 testResults results
= new testResults("Core0007M");
414 results
.description
= "If a node with that name is already present in the collection. The \"setNamedItem(arg)\" method is replacing it by the new one";
416 // Retrieve targeted data and set new attribute.
418 testNode
= util
.nodeObject(util
.THIRD
,util
.SIXTH
);
419 computedValue
= testNode
.Attributes
.SetNamedItem(newAttr
).Name
;
421 catch(System
.Exception ex
)
423 computedValue
= "Exception " + ex
.Message
;
428 results
.expected
= expectedValue
;
429 results
.actual
= computedValue
;
432 AssertEquals (results
.expected
, results
.actual
);
435 //------------------------ End test case core-0007M --------------------------
437 //--------------------------- test case core-0008 ----------------------------
439 // Testing feature - The "removeNamedItem(name)" method removes a node
440 // specified by name.
442 // Testing approach - Retrieve the third employee and create a NamedNodeMap
443 // object from the attributes in its last child. Once
444 // the list is created, the "removeNamedItem(name)"
445 // method is invoked where "name" is the name of an
446 // existing attribute. The "removeNamedItem(name)" method
447 // should remove the specified attribute and its "specified"
448 // attribute (since this is an Attr node) should be set
451 // Semantic Requirements: 8
453 //----------------------------------------------------------------------------
456 public void core0008M()
458 string computedValue
= "";
459 string expectedValue
= "False";
460 System
.Xml
.XmlNode testNode
= null;
461 System
.Xml
.XmlAttribute Attr
= null;
463 testResults results
= new testResults("Core0008M");
466 results
.description
= "The \"removeNamedItem(name)\" method removes "+
467 "a node specified by name.";
469 // Retrive targeted data and and remove attribute. It should no longer
472 testNode
= (System
.Xml
.XmlNode
)util
.nodeObject(util
.THIRD
,util
.SIXTH
);
473 testNode
.Attributes
.RemoveNamedItem("street");
474 Attr
= (System
.Xml
.XmlAttribute
)testNode
.Attributes
.GetNamedItem("street");
475 computedValue
= Attr
.Specified
.ToString();
477 catch(System
.Exception ex
)
479 computedValue
= "Exception " + ex
.Message
;
484 results
.expected
= expectedValue
;
485 results
.actual
= computedValue
;
488 AssertEquals (results
.expected
, results
.actual
);
491 //------------------------ End test case core-0008M --------------------------
493 //--------------------------- test case core-0009 ----------------------------
495 // Testing feature - If the node removed by the "removeNamedItem(name)" method
496 // is an Attr node with a default value, its is immediately
499 // Testing approach - Retrieve the third employee and create a NamedNodeMap
500 // object from the attributes in its last child. Once
501 // the list is created, the "removeNamedItem(name)" method
502 // is invoked where "name" is the name of an existing
503 // attribute ("street)". The "removeNamedItem(name)" method
504 // should remove the "street" attribute and since it has
505 // a default value of "Yes", that value should immediately
506 // be the attribute's value.
508 // Semantic Requirements: 9
510 //----------------------------------------------------------------------------
513 public void core0009M()
515 string computedValue
= "";
516 string expectedValue
= "Yes";
517 System
.Xml
.XmlNode testNode
= null;
519 testResults results
= new testResults("Core0009M");
522 results
.description
= "If the node removed by the \"removeNamedItem(name)\" "+
523 "method is an Attr node with a default value, then "+
524 "it is immediately replaced.";
526 // Retrieve targeted data and remove attribute.
528 testNode
= util
.nodeObject(util
.THIRD
,util
.SIXTH
);
529 testNode
.Attributes
.RemoveNamedItem("street");
530 computedValue
= testNode
.Attributes
.GetNamedItem("street").Value
;
532 catch(System
.Exception ex
)
534 computedValue
= "Exception " + ex
.Message
;
539 results
.expected
= expectedValue
;
540 results
.actual
= computedValue
;
544 AssertEquals (results
.expected
, results
.actual
);
547 //------------------------ End test case core-0009M --------------------------
549 //--------------------------- test case core-0010M ---------------------------
551 // Testing feature - The "removeNamedItem(name)" method returns the node removed
554 // Testing approach - Retrieve the third employee and create a NamedNodeMap
555 // object from the attributes in its last child.
556 // Once the list is created, the "removeNamedItem(name)"
557 // method is invoked where "name" is the name of an existing
558 // attribute ("street)". The "removeNamedItem(name)"
559 // method should remove the existing "street" attribute
562 // Semantic Requirements: 10
564 //----------------------------------------------------------------------------
567 public void core0010M()
569 string computedValue
= "";
570 string expectedValue
= "No";
571 System
.Xml
.XmlNode returnedNode
= null;
572 System
.Xml
.XmlNode testNode
= null;
574 testResults results
= new testResults("Core0010M");
577 results
.description
= "The \"removeNamedItem(name)\" method returns the "+
578 "node removed from the map.";
580 // Retrieve targeted data, remove attribute and examine returned value of
581 // removeNamedItem method.
583 testNode
= util
.nodeObject(util
.THIRD
,util
.SIXTH
);
584 returnedNode
= testNode
.Attributes
.RemoveNamedItem("street");
585 computedValue
= returnedNode
.Value
;
587 catch(System
.Exception ex
)
589 computedValue
= "Exception " + ex
.Message
;
595 results
.expected
= expectedValue
;
596 results
.actual
= computedValue
;
600 AssertEquals (results
.expected
, results
.actual
);
603 //------------------------ End test case core-0010M --------------------------
605 //--------------------------- test case core-0011M ---------------------------
607 // Testing feature - The "removeNamedItem(name)" method returns null if the
608 // name specified does not exists in the map.
610 // Testing approach - Retrieve the third employee and create a NamedNodeMap
611 // object from the attributes in its last child.
612 // Once the list is created, the "removeNamedItem(name)"
613 // method is invoked where "name" does not exist in the
614 // map. The method should return null.
616 // Semantic Requirements: 11
618 //----------------------------------------------------------------------------
621 public void core0011M()
623 object computedValue
= null;
624 object expectedValue
= null;
625 System
.Xml
.XmlNode testNode
= null;
627 testResults results
= new testResults("Core0011M");
630 results
.description
= "The \"removeNamedItem(name)\" method returns null "+
631 "if the specified \"name\" is not in the map.";
633 // Retrieve targeted data and attempt to remove a non-existing attribute.
635 testNode
= util
.nodeObject(util
.THIRD
,util
.SIXTH
);
636 computedValue
= testNode
.Attributes
.RemoveNamedItem("district");
638 catch(System
.Exception ex
)
640 computedValue
= "Exception " + ex
.Message
;
646 results
.expected
= (expectedValue
== null).ToString();
647 results
.actual
= (computedValue
== null).ToString();
651 AssertEquals (results
.expected
, results
.actual
);
654 //------------------------ End test case core-0011M --------------------------
656 //--------------------------- test case core-0012M ---------------------------
658 // Testing feature - The "item(index)" method returns the indexth item in the
659 // map (test for first item).
661 // Testing approach - Retrieve the second employee and create a NamedNodeMap
662 // object from the attributes in its last child by
663 // by invoking the "attributes" attribute. Once
664 // the list is created, the "item(index)" method is
665 // invoked with index = 0. This should return the node at
666 // the first position. Since there are no guarantees that
667 // first item in the map is the one that was listed first
668 // in the attribute list the test checks for all of them.
670 // Semantic Requirements: 12
672 //----------------------------------------------------------------------------
675 public void core0012M()
677 //string testName = "core-0012M";
678 string computedValue
= "";
679 // string expectedValue = "domestic or street";
680 string expectedValue
= "domestic";
681 System
.Xml
.XmlNode returnedNode
= null;
682 System
.Xml
.XmlNode testNode
= null;
684 testResults results
= new testResults("Core0012M");
687 results
.description
= "Retrieve the first item in the map via the \"item(index)\" method.";
690 // Retrieve targeted data and invoke "item" method.
692 testNode
= util
.nodeObject(util
.SECOND
,util
.SIXTH
);
693 returnedNode
= testNode
.Attributes
.Item(0);
694 computedValue
= returnedNode
.Name
;
696 catch(System
.Exception ex
)
698 computedValue
= "Exception " + ex
.Message
;
704 results
.expected
= expectedValue
;
705 results
.actual
= computedValue
;
707 AssertEquals (results
.expected
, results
.actual
);
710 //------------------------ End test case core-0012M --------------------------
712 //--------------------------- test case core-0013M ---------------------------
714 // Testing feature - The "item(index)" method returns the indexth item in the
715 // map (test for last item).
717 // Testing approach - Retrieve the second employee and create a NamedNodeMap
718 // object from the attributes in its last child.
719 // Once the list is created, the "item(index)" method is
720 // invoked with index = 1. This should return the node at
721 // the last position. Since there are no guarantees that
722 // the last item in the map is the one that was listed last
723 // in the attribute list, the test checks for all of them.
725 // Semantic Requirements: 12
727 //----------------------------------------------------------------------------
730 public void core0013M()
732 string computedValue
= "";
733 // string expectedValue = "domestic or street";
734 string expectedValue
= "street";
735 System
.Xml
.XmlNode returnedNode
= null;
736 System
.Xml
.XmlNode testNode
= null;
738 testResults results
= new testResults("Core0013M");
741 results
.description
= "Retrieve the last item in the map via the \"item(index)\" method.";
743 // Retrieve targeted data and invoke "item" attribute.
745 testNode
= util
.nodeObject(util
.THIRD
,util
.SIXTH
);
746 returnedNode
= testNode
.Attributes
.Item(1);
747 computedValue
= returnedNode
.Name
;
749 catch(System
.Exception ex
)
751 computedValue
= "Exception " + ex
.Message
;
756 results
.expected
= expectedValue
;
757 results
.actual
= computedValue
;
759 AssertEquals (results
.expected
, results
.actual
);
762 //------------------------ End test case core-0013M --------------------------
764 //--------------------------- test case core-0014M ---------------------------
766 // Testing feature - The "item(index)" method returns null if the index is
767 // greater than the number of nodes in the map.
769 // Testing approach - Retrieve the second employee and create a NamedNodeMap
770 // object from the attributes in its last child.
771 // element by invoking the "attributes" attribute. Once
772 // the list is created, the "item(index)" method is
773 // invoked with index = 3. This index value is greater than
774 // the number of nodes in the map and under that condition
775 // the method should return null.
777 // Semantic Requirements: 13
779 //----------------------------------------------------------------------------
782 public void core0014M()
784 object computedValue
= null;
785 object expectedValue
= null;
786 System
.Xml
.XmlNode testNode
= null;
788 testResults results
= new testResults("Core0014M");
791 results
.description
= "The \"item(index)\" method returns null if the "+
792 "index is greater than the number of nodes in the map.";
795 // Retrieve targeted data and invoke "item" method.
797 testNode
= util
.nodeObject(util
.THIRD
,util
.SIXTH
);
798 computedValue
= testNode
.Attributes
.Item(3);
800 catch(System
.Exception ex
)
802 computedValue
= "Exception " + ex
.Message
;
808 results
.expected
= (expectedValue
== null).ToString();
809 results
.actual
= (computedValue
== null).ToString();
811 AssertEquals (results
.expected
, results
.actual
);
814 //------------------------ End test case core-0014M --------------------------
816 //--------------------------- test case core-0015M ---------------------------
818 // Testing feature - The "item(index)" method returns null if the index is
819 // equal to the number of nodes in the map.
821 // Testing approach - Retrieve the second employee and create a NamedNodeMap
822 // object from the attributes in its last child
823 // Once the list is created, the "item(index)" method is
824 // invoked with index = 2. This index value is equal to
825 // the number of nodes in the map and under that condition
826 // the method should return null (first item is at position
829 // Semantic Requirements: 13
831 //----------------------------------------------------------------------------
834 public void core0015M()
836 object computedValue
= null;
837 object expectedValue
= null;
838 System
.Xml
.XmlNode testNode
= null;
840 testResults results
= new testResults("Core0015M");
843 results
.description
= "The \"item(index)\" method returns null if the index " +
844 "is equal to the number of nodes in the map.";
846 // Retrieve targeted data and invoke "item" method.
848 testNode
= util
.nodeObject(util
.THIRD
,util
.SIXTH
);
849 computedValue
= testNode
.Attributes
.Item(2);
851 catch(System
.Exception ex
)
853 computedValue
= "Exception " + ex
.Message
;
858 results
.expected
= (expectedValue
== null).ToString();
859 results
.actual
= (computedValue
== null).ToString();
861 AssertEquals (results
.expected
, results
.actual
);
864 //------------------------ End test case core-0015M --------------------------
866 //--------------------------- test case core-0016M ---------------------------
868 // Testing feature - The "length" attribute contains the total number of
871 // Testing approach - Retrieve the second employee and create a NamedNodeMap
872 // object from the attributes in its last child.
873 // Once the list is created, the "length" attribute is
874 // invoked. That attribute should contain the number 2.
876 // Semantic Requirements: 14
878 //----------------------------------------------------------------------------
881 public void core0016M()
883 string computedValue
= "";
884 string expectedValue
= "2";
885 System
.Xml
.XmlNode testNode
= null;
887 testResults results
= new testResults("Core0016M");
890 results
.description
= "The \"length\" attribute contains the number of " +
893 // Retrieve targeted data and invoke "length" attribute.
895 testNode
= util
.nodeObject(util
.THIRD
,util
.SIXTH
);
896 computedValue
= testNode
.Attributes
.Count
.ToString();
898 catch(System
.Exception ex
)
900 computedValue
= "Exception " + ex
.Message
;
905 results
.expected
= expectedValue
;
906 results
.actual
= computedValue
;
908 AssertEquals (results
.expected
, results
.actual
);
911 //------------------------ End test case core-0016M --------------------------
913 //--------------------------- test case core-0017M ---------------------------
915 // Testing feature - The range of valid child nodes indices is 0 to length - 1.
917 // Testing approach - Create a NamedNodeMap object from the attributes of the
918 // last child of the third employee and traverse the
919 // list from index 0 to index length - 1. All indices
922 // Semantic Requirements: 15
924 //----------------------------------------------------------------------------
927 public void core0017M()
929 string computedValue
= "";
930 string expectedValue
= "0 1 ";
932 //string attributes = "";
933 System
.Xml
.XmlNode testNode
= null;
935 testResults results
= new testResults("Core0017M");
938 results
.description
= "The range of valid child nodes indices is 0 to " +
941 // Retrieve targeted data and compute list length.
943 testNode
= util
.nodeObject(util
.THIRD
,util
.SIXTH
);
944 lastIndex
= testNode
.Attributes
.Count
- 1;
946 // Traverse the list from 0 to length - 1. All indices should be valid.
948 for (int index
= 0;index
<= lastIndex
; index
++)
949 computedValue
+= index
+" ";
951 catch(System
.Exception ex
)
953 computedValue
= "Exception " + ex
.Message
;
956 // Write out results.
958 results
.expected
= expectedValue
;
959 results
.actual
= computedValue
;
961 AssertEquals (results
.expected
, results
.actual
);
964 //------------------------ End test case core-0017M --------------------------
966 //--------------------------- test case core-0018M ---------------------------
968 // Testing feature - The "setNamedItem(arg) method raises a System.ArgumentException
969 // Exception if "arg" was created from a different
970 // document than the one that created the NamedNodeMap.
972 // Testing approach - Create a NamedNodeMap object from the attributes of the
973 // last child of the third employee and attempt to
974 // add another Attr node to it that was created from a
975 // different DOM document. This condition should raise
976 // the desired exception. This method uses the
977 // "createAttribute(name)" method from the Document
980 // Semantic Requirements: 16
982 //----------------------------------------------------------------------------
985 public void core0018M()
987 string computedValue
= "";
989 System
.Xml
.XmlAttribute newAttrNode
= util
.getOtherDOMDocument().CreateAttribute("newAttribute");
990 System
.Xml
.XmlNode testNode
= null;
991 string expectedValue
= "System.ArgumentException";
993 testResults results
= new testResults("Core0018M");
995 results
.description
= "The \"setNamedItem(arg)\" method raises a "+
996 "System.ArgumentException Exception if \"arg\" was " +
997 "created from a document different from the one that created "+
998 "the NamedNodeList.";
1000 // Retrieve targeted data and attempt to add an element that was created
1001 // from a different document. Should raise an exception.
1003 testNode
= util
.nodeObject(util
.THIRD
,util
.SIXTH
);
1007 testNode
.Attributes
.SetNamedItem(newAttrNode
);
1009 catch(System
.Exception ex
)
1011 computedValue
= ex
.GetType().ToString();
1015 results
.expected
= expectedValue
;
1016 results
.actual
= computedValue
;
1020 AssertEquals (results
.expected
, results
.actual
);
1023 //------------------------ End test case core-0018M --------------------------
1025 //--------------------------- test case core-0019M ---------------------------
1027 // Testing feature - The "setNamedItem(arg) method raises a
1028 // NO_MODIFICATION_ALLOWED_ERR Exception if this
1029 // NamedNodeMap is readonly.
1031 // Testing approach - Create a NamedNodeMap object from the first child of the
1032 // Entity named "ent4" inside the DocType node and then
1033 // attempt to add a new item to the list. It should raise
1034 // the desired exception as this is a readonly NamedNodeMap.
1036 // Semantic Requirements: 17
1038 //----------------------------------------------------------------------------
1041 public void core0019M()
1043 string computedValue
= "";
1044 System
.Xml
.XmlNode testNode
= null;
1045 System
.Xml
.XmlNode entityDesc
;
1046 System
.Xml
.XmlAttribute newAttrNode
= (System
.Xml
.XmlAttribute
)util
.createNode(util
.ATTRIBUTE_NODE
,"newAttribute");
1047 string expectedValue
= "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;
1049 testResults results
= new testResults("Core0019M");
1051 results
.description
= "The \"setNamedItem(arg)\" method raises a " +
1052 "NO_MODIFICATION_ALLOWED_ERR Exception if this "+
1053 "NamedNodeMap is readonly.";
1055 // Create a NamedNodeMap object and attempt to add a node to it.
1056 // Should raise an exception.
1058 testNode
= util
.getEntity("ent4");
1059 entityDesc
= testNode
.FirstChild
;
1063 entityDesc
.Attributes
.SetNamedItem(newAttrNode
);
1065 catch(ArgumentException ex
)
1067 computedValue
= ex
.GetType ().FullName
;
1071 results
.expected
= expectedValue
;
1072 results
.actual
= computedValue
;
1076 AssertEquals (results
.expected
, results
.actual
);
1079 //------------------------ End test case core-0019M --------------------------
1081 //--------------------------- test case core-0020M ---------------------------
1083 // Testing feature - The "setNamedItem(arg) method raises an
1084 // INUSE_ATTRIBUTE_ERR Exception if "arg" is an Attr
1085 // that is already an attribute of another Element.
1087 // Testing approach - Create a NamedNodeMap object from the attributes of the
1088 // third child and attempt to add an attribute that is
1089 // already being used by the first employee. An attempt
1090 // to add such an attribute should raise the desired
1093 // Semantic Requirements: 18
1095 //----------------------------------------------------------------------------
1098 public void core0020M()
1100 string computedValue
= "";
1101 System
.Xml
.XmlAttribute inUseAttribute
= null;
1102 System
.Xml
.XmlElement firstEmployee
= null;
1103 System
.Xml
.XmlNode testNode
= null;
1104 string expectedValue
= "System.ArgumentException";//util.INUSE_ATTRIBUTE_ERR;
1106 testResults results
= new testResults("Core0020M");
1109 results
.description
= "The \"setNamedItem(arg)\" method raises an "+
1110 "INUSE_ATTRIBUTE_ERR Exception if \"arg\" "+
1111 "is an Attr node that is already an attribute "+
1112 "of another Element.";
1114 firstEmployee
= (System
.Xml
.XmlElement
)util
.nodeObject(util
.FIRST
,util
.SIXTH
);
1115 inUseAttribute
= firstEmployee
.GetAttributeNode("domestic");
1117 // Attempt to add an attribute that is already used by another element
1118 // should raise an exception.
1120 testNode
= util
.nodeObject(util
.THIRD
,util
.SIXTH
);
1124 testNode
.Attributes
.SetNamedItem(inUseAttribute
);
1126 catch (System
.Exception ex
)
1128 computedValue
= ex
.GetType ().FullName
;
1132 catch(System
.Exception ex
)
1134 computedValue
= "Exception " + ex
.Message
;
1137 results
.expected
= expectedValue
;
1138 results
.actual
= computedValue
;
1142 AssertEquals (results
.expected
, results
.actual
);
1145 //------------------------ End test case core-0020M --------------------------
1147 //--------------------------- test case core-0021M ---------------------------
1149 // Testing feature - The "removeNamedItem(name) method raises an
1150 // NOT_FOUND_ERR Exception if there is no node
1151 // named "name" in the map.
1153 // Testing approach - Create a NamedNodeMap object from the attributes of the
1154 // last child of the third employee and attempt to
1155 // remove the "district" attribute. There is no node named
1156 // "district" in the list and therefore the desired
1157 // exception should be raised.
1159 // System.Xml - return null, if a matching node was not found.
1161 // Semantic Requirements: 19
1163 //----------------------------------------------------------------------------
1166 public void core0021M()
1168 object computedValue
= null;
1169 System
.Xml
.XmlNode testNode
= null;
1170 object expectedValue
= null;//util.NOT_FOUND1_ERR;
1172 testResults results
= new testResults("Core0021M");
1175 results
.description
= "The \"removeNamedItem(name)\" method raises a " +
1176 "NOT_FOUND_ERR Exception if there is no node "+
1177 "named \"name\" in the map.";
1179 // Create a NamedNodeMap object and attempt to remove an attribute that
1180 // is not in the list should raise an exception.
1182 testNode
= util
.nodeObject(util
.THIRD
,util
.SIXTH
);
1186 //null if a matching node was not found
1187 computedValue
= testNode
.Attributes
.RemoveNamedItem("district");
1189 catch(System
.Exception ex
)
1191 computedValue
= ex
.Message
;
1195 catch(System
.Exception ex
)
1197 computedValue
= "Exception " + ex
.Message
;
1200 results
.expected
= (expectedValue
== null).ToString();
1201 results
.actual
= (computedValue
== null).ToString();
1205 AssertEquals (results
.expected
, results
.actual
);
1208 //------------------------ End test case core-0021M --------------------------