1 //**************************************************************************
\r
4 // National Institute Of Standards and Technology
\r
7 // NamedNodeMap Interface
\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 NamedNodeMapTest
\r
26 public static int i = 2;
\r
28 public testResults[] RunTests()
\r
30 testResults[] tests = new testResults[] {core0001M(), core0002M(), core0003M(),core0004M(),
\r
31 core0005M(), core0006M(), core0007M(), core0008M(),
\r
32 core0009M(), core0010M(), core0011M(),
\r
33 core0014M(), core0015M(), core0016M(),
\r
34 core0017M(), core0018M(), core0019M(), core0020M(),
\r
40 //------------------------ test case core-0001M ------------------------
\r
42 // Testing feature - The "getNamedItem(name)" method retrieves a node
\r
43 // specified by name.
\r
45 // Testing approach - Retrieve the second employee and create a NamedNodeMap
\r
46 // listing of the attributes of its last child. Once
\r
47 // the list is created an invocation of the
\r
48 // "getNamedItem(name)" method is done where
\r
49 // name = "domestic". This should result on the domestic
\r
50 // Attr node being returned.
\r
52 // Semantic Requirements: 1
\r
54 //----------------------------------------------------------------------------
\r
57 public void core0001M()
\r
59 string computedValue = "";
\r
60 string expectedValue = "domestic";
\r
61 System.Xml.XmlAttribute domesticAttr = null;
\r
62 System.Xml.XmlNode testNode = null;
\r
64 testResults results = new testResults("Core0001M");
\r
67 results.description = "The \"getNamedItem(name)\" method retrieves a node " +
\r
68 "specified by name.";
\r
70 // Retrieve targeted data.
\r
72 testNode = util.nodeObject(util.SECOND,util.SIXTH);
\r
73 domesticAttr = (System.Xml.XmlAttribute)testNode.Attributes.GetNamedItem("domestic");
\r
74 computedValue = domesticAttr.Name;
\r
76 catch(System.Exception ex)
\r
78 computedValue = "Exception " + ex.Message;
\r
82 // Write out results
\r
84 results.expected = expectedValue;
\r
85 results.actual = computedValue;
\r
87 Assert.AreEqual (results.expected, results.actual);
\r
90 //------------------------ End test case core-0001M --------------------------
\r
92 //--------------------------- test case core-0002M ---------------------------
\r
94 // Testing feature - The "getNamedItem(name)" method returns a node of any
\r
95 // type specified by name.
\r
97 // Testing approach - Retrieve the second employee and create a NamedNodeMap
\r
98 // listing of the attributes of its last child. Once
\r
99 // the list is created an invocation of the
\r
100 // "getNamedItem(name)" method is done where
\r
101 // name = "street". This should cause the method to return
\r
104 // Semantic Requirements: 2
\r
106 //----------------------------------------------------------------------------
\r
109 public void core0002M()
\r
111 string computedValue = "";
\r
112 string expectedValue = "street";
\r
113 System.Xml.XmlAttribute streetAttr = null;
\r
114 System.Xml.XmlNode testNode = null;
\r
116 testResults results = new testResults("Core0002M");
\r
119 results.description = "The \"getNamedItem(name)\" method returns a node "+
\r
120 "of any type specified by name (test for Attr node).";
\r
122 // Retrieve targeted data and get its attributes.
\r
124 testNode = util.nodeObject(util.SECOND,util.SIXTH);
\r
125 streetAttr = (System.Xml.XmlAttribute)testNode.Attributes.GetNamedItem("street");
\r
126 computedValue = streetAttr.Name;
\r
128 catch(System.Exception ex)
\r
130 computedValue = "Exception " + ex.Message;
\r
134 // Write out results
\r
136 results.expected = expectedValue;
\r
137 results.actual = computedValue;
\r
139 Assert.AreEqual (results.expected, results.actual);
\r
142 //------------------------ End test case core-0002M --------------------------
\r
144 //--------------------------- test case core-0003M ---------------------------
\r
146 // Testing feature - The "getNamedItem(name)" method returns null if the
\r
147 // specified name did not identify any node in the map.
\r
149 // Testing approach - Retrieve the second employee and create a NamedNodeMap
\r
150 // listing of the attributes of its last child. Once
\r
151 // the list is created an invocation of the
\r
152 // "getNamedItem(name)" method is done where
\r
153 // name = "district", this name does not match any names
\r
154 // in the list and the method should return null.
\r
156 // Semantic Requirements: 3
\r
158 //----------------------------------------------------------------------------
\r
161 public void core0003M()
\r
163 object computedValue = null;
\r
164 object expectedValue = null;
\r
165 System.Xml.XmlNode testNode = null;
\r
168 testResults results = new testResults("Core0003M");
\r
171 results.description = "The \"getNamedItem(name)\" method returns null if the " +
\r
172 "specified name did not identify any node in the map.";
\r
174 // Retrieve targeted data and attempt to get a non-existing attribute.
\r
176 testNode = util.nodeObject(util.SECOND,util.SIXTH);
\r
177 computedValue = testNode.Attributes.GetNamedItem("district");
\r
179 catch(System.Exception ex)
\r
181 computedValue = "Exception " + ex.Message;
\r
185 // Write out results
\r
187 results.expected = (expectedValue == null).ToString();
\r
188 results.actual = (computedValue == null).ToString();
\r
190 Assert.AreEqual (results.expected, results.actual);
\r
193 //------------------------ End test case core-0003M --------------------------
\r
195 //--------------------------- test case core-0004M ---------------------------
\r
197 // Testing feature - The "setNamedItem(arg)" method adds a node using its
\r
198 // nodeName attribute.
\r
200 // Testing approach - Retrieve the second employee and create a NamedNodeMap
\r
201 // object from the attributes in its last child
\r
202 // by invoking the "attributes" attribute. Once the
\r
203 // list is created, the "setNamedItem(arg)" method is
\r
204 // invoked with arg = newAttr, where newAttr is a new
\r
205 // Attr Node previously created. The "setNamedItem(arg)"
\r
206 // method should add the new node to the NamedNodeItem
\r
207 // object by using its "nodeName" attribute ("district"
\r
208 // in this case). Further this node is retrieved by using
\r
209 // the "getNamedItem(name)" method. This test uses the
\r
210 // "createAttribute(name)" method from the Document
\r
213 // Semantic Requirements: 4
\r
215 //----------------------------------------------------------------------------
\r
218 public void core0004M()
\r
220 string computedValue = "";
\r
221 string expectedValue = "district";
\r
222 System.Xml.XmlAttribute districtAttr = null;
\r
223 System.Xml.XmlAttribute newAttr = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");
\r
224 System.Xml.XmlNode testNode = null;
\r
226 testResults results = new testResults("Core0004M");
\r
229 results.description = "The \"setNamedItem(arg)\" method adds a node "+
\r
230 "using its nodeName attribute.";
\r
232 // Retrieve targeted data and add new attribute.
\r
234 testNode = util.nodeObject(util.SECOND,util.SIXTH);
\r
235 testNode.Attributes.SetNamedItem(newAttr);
\r
236 districtAttr = (System.Xml.XmlAttribute)testNode.Attributes.GetNamedItem("district");
\r
237 computedValue = districtAttr.Name;
\r
239 catch(System.Exception ex)
\r
241 computedValue = "Exception " + ex.Message;
\r
245 // Write out results
\r
247 results.expected = expectedValue;
\r
248 results.actual = computedValue;
\r
251 Assert.AreEqual (results.expected, results.actual);
\r
254 //------------------------ End test case core-0004M --------------------------
\r
256 //--------------------------- test case core-0005 ---------------------------
\r
258 // Testing feature - If the node to be added by the "setNamedItem(arg)" method
\r
259 // already exists in the NamedNodeMap, it is replaced by the
\r
262 // Testing approach - Retrieve the second employee and create a NamedNodeMap
\r
263 // object from the attributes in its last child. Once
\r
264 // the list is created, the "setNamedItem(arg) method is
\r
265 // invoked with arg = newAttr, where newAttr is a Node Attr
\r
266 // previously created and whose node name already exist
\r
267 // in the map. The "setNamedItem(arg)" method should
\r
268 // replace the already existing node with the new one.
\r
269 // Further this node is retrieved by using the
\r
270 // "getNamedItem(name)" method. This test uses the
\r
271 // "createAttribute(name)" method from the Document
\r
274 // Semantic Requirements: 5
\r
276 //----------------------------------------------------------------------------
\r
279 public void core0005M()
\r
281 string computedValue = "";
\r
282 string expectedValue = "";
\r
283 System.Xml.XmlAttribute streetAttr = null;
\r
284 System.Xml.XmlAttribute newAttr = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"street");
\r
285 System.Xml.XmlNode testNode = null;
\r
287 testResults results = new testResults("Core0005M");
\r
290 results.description = "If the node to be replaced by the \"setNamedItem(arg)\" " +
\r
291 "method is already in the list, the existing node should " +
\r
292 "be replaced by the new one.";
\r
295 // Retrieve targeted data and add new attribute with name matching an
\r
296 // already existing attribute.
\r
298 testNode = util.nodeObject(util.SECOND,util.SIXTH);
\r
299 testNode.Attributes.SetNamedItem(newAttr);
\r
300 streetAttr = (System.Xml.XmlAttribute)testNode.Attributes.GetNamedItem("street");
\r
301 computedValue = streetAttr.Value;
\r
303 catch(System.Exception ex)
\r
305 computedValue = "Exception " + ex.Message;
\r
308 // Write out results
\r
310 results.expected = expectedValue;
\r
311 results.actual = computedValue;
\r
314 Assert.AreEqual (results.expected, results.actual);
\r
317 //------------------------ End test case core-0005M --------------------------
\r
319 //--------------------------- test case core-0006 ---------------------------
\r
321 // Testing feature - If the "setNamedItem(arg)" method replaces an already
\r
322 // existing node with the same name then the already existing
\r
323 // node is returned.
\r
325 // Testing approach - Retrieve the third employee and create a "NamedNodeMap"
\r
326 // object of the attributes in its last child by
\r
327 // invoking the "attributes" attribute. Once the
\r
328 // list is created, the "setNamedItem(arg) method is
\r
329 // invoked with arg = newAttr, where newAttr is a Node Attr
\r
330 // previously created and whose node name already exist
\r
331 // in the map. The "setNamedItem(arg)" method should replace
\r
332 // the already existing node with the new one and return
\r
333 // the existing node. Further this node is retrieved by
\r
334 // using the "getNamedItem(name)" method. This test
\r
335 // uses the "createAttribute(name)" method from the Document
\r
338 // Semantic Requirements: 6
\r
340 //----------------------------------------------------------------------------
\r
343 public void core0006M()
\r
345 string computedValue = "";
\r
346 string expectedValue = "No";
\r
347 System.Xml.XmlNode returnedNode = null;
\r
348 System.Xml.XmlAttribute newAttr = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"street");
\r
349 System.Xml.XmlNode testNode = null;
\r
351 testResults results = new testResults("Core0006M");
\r
354 results.description = "If the \"setNamedItem(arg)\" method replaces an "+
\r
355 "already existing node with the same name then it "+
\r
356 "returns the already existing node.";
\r
358 // Retrieve targeted data and examine value returned by the setNamedItem
\r
361 testNode = util.nodeObject(util.THIRD,util.SIXTH);
\r
362 returnedNode = testNode.Attributes.SetNamedItem(newAttr);
\r
363 computedValue = returnedNode.Value;
\r
365 catch(System.Exception ex)
\r
367 computedValue = "Exception " + ex.Message;
\r
370 // Write out results
\r
372 results.expected = expectedValue;
\r
373 results.actual = computedValue;
\r
376 Assert.AreEqual (results.expected, results.actual);
\r
379 //------------------------ End test case core-0006M --------------------------
\r
381 //--------------------------- test case core-0007 ---------------------------
\r
383 // Testing feature - The "setNamedItem(arg)" method replace an
\r
384 // already existing node with the same name. If a node with
\r
385 // that name is already present in the collection,
\r
386 // it is replaced by the new one.
\r
388 // Testing approach - Retrieve the third employee and create a NamedNodeMap
\r
389 // object from the attributes in its last child.
\r
390 // Once the list is created, the "setNamedItem(arg)"
\r
391 // method is invoked with arg = newAttr, where newAttr is
\r
392 // a new previously created Attr node The
\r
393 // "setNamedItem(arg)" method should add the new node
\r
394 // and return the new one. Further this node is retrieved by
\r
395 // using the "getNamedItem(name)" method. This test
\r
396 // uses the "createAttribute(name)" method from the
\r
397 // Document interface.
\r
399 // Semantic Requirements: 7
\r
401 //----------------------------------------------------------------------------
\r
404 public void core0007M()
\r
406 string computedValue = "";
\r
407 string expectedValue = "district";
\r
408 System.Xml.XmlAttribute newAttr = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");
\r
409 System.Xml.XmlNode testNode = null;
\r
411 testResults results = new testResults("Core0007M");
\r
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";
\r
416 // Retrieve targeted data and set new attribute.
\r
418 testNode = util.nodeObject(util.THIRD,util.SIXTH);
\r
419 computedValue = testNode.Attributes.SetNamedItem(newAttr).Name;
\r
421 catch(System.Exception ex)
\r
423 computedValue = "Exception " + ex.Message;
\r
426 // Write out results
\r
428 results.expected = expectedValue;
\r
429 results.actual = computedValue;
\r
432 Assert.AreEqual (results.expected, results.actual);
\r
435 //------------------------ End test case core-0007M --------------------------
\r
437 //--------------------------- test case core-0008 ----------------------------
\r
439 // Testing feature - The "removeNamedItem(name)" method removes a node
\r
440 // specified by name.
\r
442 // Testing approach - Retrieve the third employee and create a NamedNodeMap
\r
443 // object from the attributes in its last child. Once
\r
444 // the list is created, the "removeNamedItem(name)"
\r
445 // method is invoked where "name" is the name of an
\r
446 // existing attribute. The "removeNamedItem(name)" method
\r
447 // should remove the specified attribute and its "specified"
\r
448 // attribute (since this is an Attr node) should be set
\r
451 // Semantic Requirements: 8
\r
453 //----------------------------------------------------------------------------
\r
456 public void core0008M()
\r
458 string computedValue = "";
\r
459 string expectedValue = "False";
\r
460 System.Xml.XmlNode testNode = null;
\r
461 System.Xml.XmlAttribute Attr = null;
\r
463 testResults results = new testResults("Core0008M");
\r
466 results.description = "The \"removeNamedItem(name)\" method removes "+
\r
467 "a node specified by name.";
\r
469 // Retrive targeted data and and remove attribute. It should no longer
\r
472 testNode = (System.Xml.XmlNode)util.nodeObject(util.THIRD,util.SIXTH);
\r
473 testNode.Attributes.RemoveNamedItem("street");
\r
474 Attr = (System.Xml.XmlAttribute)testNode.Attributes.GetNamedItem("street");
\r
475 computedValue = Attr.Specified.ToString();
\r
477 catch(System.Exception ex)
\r
479 computedValue = "Exception " + ex.Message;
\r
482 // Write out results
\r
484 results.expected = expectedValue;
\r
485 results.actual = computedValue;
\r
488 Assert.AreEqual (results.expected, results.actual);
\r
491 //------------------------ End test case core-0008M --------------------------
\r
493 //--------------------------- test case core-0009 ----------------------------
\r
495 // Testing feature - If the node removed by the "removeNamedItem(name)" method
\r
496 // is an Attr node with a default value, its is immediately
\r
499 // Testing approach - Retrieve the third employee and create a NamedNodeMap
\r
500 // object from the attributes in its last child. Once
\r
501 // the list is created, the "removeNamedItem(name)" method
\r
502 // is invoked where "name" is the name of an existing
\r
503 // attribute ("street)". The "removeNamedItem(name)" method
\r
504 // should remove the "street" attribute and since it has
\r
505 // a default value of "Yes", that value should immediately
\r
506 // be the attribute's value.
\r
508 // Semantic Requirements: 9
\r
510 //----------------------------------------------------------------------------
\r
514 [Category ("NotDotNet")]
\r
516 public void core0009M()
\r
518 string computedValue = "";
\r
519 string expectedValue = "Yes";
\r
520 System.Xml.XmlNode testNode = null;
\r
522 testResults results = new testResults("Core0009M");
\r
525 results.description = "If the node removed by the \"removeNamedItem(name)\" "+
\r
526 "method is an Attr node with a default value, then "+
\r
527 "it is immediately replaced.";
\r
529 // Retrieve targeted data and remove attribute.
\r
531 testNode = util.nodeObject(util.THIRD,util.SIXTH);
\r
532 testNode.Attributes.RemoveNamedItem("street");
\r
533 computedValue = testNode.Attributes.GetNamedItem("street").Value;
\r
535 catch(System.Exception ex)
\r
537 computedValue = "Exception " + ex.Message;
\r
540 // Write out results
\r
542 results.expected = expectedValue;
\r
543 results.actual = computedValue;
\r
547 Assert.AreEqual (results.expected, results.actual);
\r
550 //------------------------ End test case core-0009M --------------------------
\r
552 //--------------------------- test case core-0010M ---------------------------
\r
554 // Testing feature - The "removeNamedItem(name)" method returns the node removed
\r
557 // Testing approach - Retrieve the third employee and create a NamedNodeMap
\r
558 // object from the attributes in its last child.
\r
559 // Once the list is created, the "removeNamedItem(name)"
\r
560 // method is invoked where "name" is the name of an existing
\r
561 // attribute ("street)". The "removeNamedItem(name)"
\r
562 // method should remove the existing "street" attribute
\r
565 // Semantic Requirements: 10
\r
567 //----------------------------------------------------------------------------
\r
570 public void core0010M()
\r
572 string computedValue = "";
\r
573 string expectedValue = "No";
\r
574 System.Xml.XmlNode returnedNode = null;
\r
575 System.Xml.XmlNode testNode = null;
\r
577 testResults results = new testResults("Core0010M");
\r
580 results.description = "The \"removeNamedItem(name)\" method returns the "+
\r
581 "node removed from the map.";
\r
583 // Retrieve targeted data, remove attribute and examine returned value of
\r
584 // removeNamedItem method.
\r
586 testNode = util.nodeObject(util.THIRD,util.SIXTH);
\r
587 returnedNode = testNode.Attributes.RemoveNamedItem("street");
\r
588 computedValue = returnedNode.Value;
\r
590 catch(System.Exception ex)
\r
592 computedValue = "Exception " + ex.Message;
\r
596 // Write out results
\r
598 results.expected = expectedValue;
\r
599 results.actual = computedValue;
\r
603 Assert.AreEqual (results.expected, results.actual);
\r
606 //------------------------ End test case core-0010M --------------------------
\r
608 //--------------------------- test case core-0011M ---------------------------
\r
610 // Testing feature - The "removeNamedItem(name)" method returns null if the
\r
611 // name specified does not exist in the map.
\r
613 // Testing approach - Retrieve the third employee and create a NamedNodeMap
\r
614 // object from the attributes in its last child.
\r
615 // Once the list is created, the "removeNamedItem(name)"
\r
616 // method is invoked where "name" does not exist in the
\r
617 // map. The method should return null.
\r
619 // Semantic Requirements: 11
\r
621 //----------------------------------------------------------------------------
\r
624 public void core0011M()
\r
626 object computedValue = null;
\r
627 object expectedValue = null;
\r
628 System.Xml.XmlNode testNode = null;
\r
630 testResults results = new testResults("Core0011M");
\r
633 results.description = "The \"removeNamedItem(name)\" method returns null "+
\r
634 "if the specified \"name\" is not in the map.";
\r
636 // Retrieve targeted data and attempt to remove a non-existing attribute.
\r
638 testNode = util.nodeObject(util.THIRD,util.SIXTH);
\r
639 computedValue = testNode.Attributes.RemoveNamedItem("district");
\r
641 catch(System.Exception ex)
\r
643 computedValue = "Exception " + ex.Message;
\r
647 // Write out results
\r
649 results.expected = (expectedValue == null).ToString();
\r
650 results.actual = (computedValue == null).ToString();
\r
654 Assert.AreEqual (results.expected, results.actual);
\r
657 //------------------------ End test case core-0011M --------------------------
\r
659 //--------------------------- test case core-0012M ---------------------------
\r
661 // Testing feature - The "item(index)" method returns the indexth item in the
\r
662 // map (test for first item).
\r
664 // Testing approach - Retrieve the second employee and create a NamedNodeMap
\r
665 // object from the attributes in its last child by
\r
666 // by invoking the "attributes" attribute. Once
\r
667 // the list is created, the "item(index)" method is
\r
668 // invoked with index = 0. This should return the node at
\r
669 // the first position. Since there are no guarantees that
\r
670 // first item in the map is the one that was listed first
\r
671 // in the attribute list the test checks for all of them.
\r
673 // Semantic Requirements: 12
\r
675 //----------------------------------------------------------------------------
\r
678 public void core0012M()
\r
680 //string testName = "core-0012M";
\r
681 string computedValue = "";
\r
682 // string expectedValue = "domestic or street";
\r
683 string expectedValue = "domestic";
\r
684 System.Xml.XmlNode returnedNode = null;
\r
685 System.Xml.XmlNode testNode = null;
\r
687 testResults results = new testResults("Core0012M");
\r
690 results.description = "Retrieve the first item in the map via the \"item(index)\" method.";
\r
693 // Retrieve targeted data and invoke "item" method.
\r
695 testNode = util.nodeObject(util.SECOND,util.SIXTH);
\r
696 returnedNode = testNode.Attributes.Item(0);
\r
697 computedValue = returnedNode.Name;
\r
699 catch(System.Exception ex)
\r
701 computedValue = "Exception " + ex.Message;
\r
705 // Write out results
\r
707 results.expected = expectedValue;
\r
708 results.actual = computedValue;
\r
710 Assert.AreEqual (results.expected, results.actual);
\r
713 //------------------------ End test case core-0012M --------------------------
\r
715 //--------------------------- test case core-0013M ---------------------------
\r
717 // Testing feature - The "item(index)" method returns the indexth item in the
\r
718 // map (test for last item).
\r
720 // Testing approach - Retrieve the second employee and create a NamedNodeMap
\r
721 // object from the attributes in its last child.
\r
722 // Once the list is created, the "item(index)" method is
\r
723 // invoked with index = 1. This should return the node at
\r
724 // the last position. Since there are no guarantees that
\r
725 // the last item in the map is the one that was listed last
\r
726 // in the attribute list, the test checks for all of them.
\r
728 // Semantic Requirements: 12
\r
730 //----------------------------------------------------------------------------
\r
733 public void core0013M()
\r
735 string computedValue = "";
\r
736 // string expectedValue = "domestic or street";
\r
737 string expectedValue = "street";
\r
738 System.Xml.XmlNode returnedNode = null;
\r
739 System.Xml.XmlNode testNode = null;
\r
741 testResults results = new testResults("Core0013M");
\r
744 results.description = "Retrieve the last item in the map via the \"item(index)\" method.";
\r
746 // Retrieve targeted data and invoke "item" attribute.
\r
748 testNode = util.nodeObject(util.THIRD,util.SIXTH);
\r
749 returnedNode = testNode.Attributes.Item(1);
\r
750 computedValue = returnedNode.Name;
\r
752 catch(System.Exception ex)
\r
754 computedValue = "Exception " + ex.Message;
\r
757 // Write out results
\r
759 results.expected = expectedValue;
\r
760 results.actual = computedValue;
\r
762 Assert.AreEqual (results.expected, results.actual);
\r
765 //------------------------ End test case core-0013M --------------------------
\r
767 //--------------------------- test case core-0014M ---------------------------
\r
769 // Testing feature - The "item(index)" method returns null if the index is
\r
770 // greater than the number of nodes in the map.
\r
772 // Testing approach - Retrieve the second employee and create a NamedNodeMap
\r
773 // object from the attributes in its last child.
\r
774 // element by invoking the "attributes" attribute. Once
\r
775 // the list is created, the "item(index)" method is
\r
776 // invoked with index = 3. This index value is greater than
\r
777 // the number of nodes in the map and under that condition
\r
778 // the method should return null.
\r
780 // Semantic Requirements: 13
\r
782 //----------------------------------------------------------------------------
\r
785 public void core0014M()
\r
787 object computedValue = null;
\r
788 object expectedValue = null;
\r
789 System.Xml.XmlNode testNode = null;
\r
791 testResults results = new testResults("Core0014M");
\r
794 results.description = "The \"item(index)\" method returns null if the "+
\r
795 "index is greater than the number of nodes in the map.";
\r
798 // Retrieve targeted data and invoke "item" method.
\r
800 testNode = util.nodeObject(util.THIRD,util.SIXTH);
\r
801 computedValue = testNode.Attributes.Item(3);
\r
803 catch(System.Exception ex)
\r
805 computedValue = "Exception " + ex.Message;
\r
809 // Write out results
\r
811 results.expected = (expectedValue == null).ToString();
\r
812 results.actual = (computedValue == null).ToString();
\r
814 Assert.AreEqual (results.expected, results.actual);
\r
817 //------------------------ End test case core-0014M --------------------------
\r
819 //--------------------------- test case core-0015M ---------------------------
\r
821 // Testing feature - The "item(index)" method returns null if the index is
\r
822 // equal to the number of nodes in the map.
\r
824 // Testing approach - Retrieve the second employee and create a NamedNodeMap
\r
825 // object from the attributes in its last child
\r
826 // Once the list is created, the "item(index)" method is
\r
827 // invoked with index = 2. This index value is equal to
\r
828 // the number of nodes in the map and under that condition
\r
829 // the method should return null (first item is at position
\r
832 // Semantic Requirements: 13
\r
834 //----------------------------------------------------------------------------
\r
837 public void core0015M()
\r
839 object computedValue = null;
\r
840 object expectedValue = null;
\r
841 System.Xml.XmlNode testNode = null;
\r
843 testResults results = new testResults("Core0015M");
\r
846 results.description = "The \"item(index)\" method returns null if the index " +
\r
847 "is equal to the number of nodes in the map.";
\r
849 // Retrieve targeted data and invoke "item" method.
\r
851 testNode = util.nodeObject(util.THIRD,util.SIXTH);
\r
852 computedValue = testNode.Attributes.Item(2);
\r
854 catch(System.Exception ex)
\r
856 computedValue = "Exception " + ex.Message;
\r
859 // Write out results
\r
861 results.expected = (expectedValue == null).ToString();
\r
862 results.actual = (computedValue == null).ToString();
\r
864 Assert.AreEqual (results.expected, results.actual);
\r
867 //------------------------ End test case core-0015M --------------------------
\r
869 //--------------------------- test case core-0016M ---------------------------
\r
871 // Testing feature - The "length" attribute contains the total number of
\r
872 // nodes in the map.
\r
874 // Testing approach - Retrieve the second employee and create a NamedNodeMap
\r
875 // object from the attributes in its last child.
\r
876 // Once the list is created, the "length" attribute is
\r
877 // invoked. That attribute should contain the number 2.
\r
879 // Semantic Requirements: 14
\r
881 //----------------------------------------------------------------------------
\r
884 public void core0016M()
\r
886 string computedValue = "";
\r
887 string expectedValue = "2";
\r
888 System.Xml.XmlNode testNode = null;
\r
890 testResults results = new testResults("Core0016M");
\r
893 results.description = "The \"length\" attribute contains the number of " +
\r
894 "nodes in the map.";
\r
896 // Retrieve targeted data and invoke "length" attribute.
\r
898 testNode = util.nodeObject(util.THIRD,util.SIXTH);
\r
899 computedValue = testNode.Attributes.Count.ToString();
\r
901 catch(System.Exception ex)
\r
903 computedValue = "Exception " + ex.Message;
\r
906 // Write out results
\r
908 results.expected = expectedValue;
\r
909 results.actual = computedValue;
\r
911 Assert.AreEqual (results.expected, results.actual);
\r
914 //------------------------ End test case core-0016M --------------------------
\r
916 //--------------------------- test case core-0017M ---------------------------
\r
918 // Testing feature - The range of valid child nodes indices is 0 to length - 1.
\r
920 // Testing approach - Create a NamedNodeMap object from the attributes of the
\r
921 // last child of the third employee and traverse the
\r
922 // list from index 0 to index length - 1. All indices
\r
923 // should be valid.
\r
925 // Semantic Requirements: 15
\r
927 //----------------------------------------------------------------------------
\r
930 public void core0017M()
\r
932 string computedValue = "";
\r
933 string expectedValue = "0 1 ";
\r
935 //string attributes = "";
\r
936 System.Xml.XmlNode testNode = null;
\r
938 testResults results = new testResults("Core0017M");
\r
941 results.description = "The range of valid child nodes indices is 0 to " +
\r
944 // Retrieve targeted data and compute list length.
\r
946 testNode = util.nodeObject(util.THIRD,util.SIXTH);
\r
947 lastIndex = testNode.Attributes.Count - 1;
\r
949 // Traverse the list from 0 to length - 1. All indices should be valid.
\r
951 for (int index = 0;index <= lastIndex; index++)
\r
952 computedValue += index+" ";
\r
954 catch(System.Exception ex)
\r
956 computedValue = "Exception " + ex.Message;
\r
959 // Write out results.
\r
961 results.expected = expectedValue;
\r
962 results.actual = computedValue;
\r
964 Assert.AreEqual (results.expected, results.actual);
\r
967 //------------------------ End test case core-0017M --------------------------
\r
969 //--------------------------- test case core-0018M ---------------------------
\r
971 // Testing feature - The "setNamedItem(arg) method raises a System.ArgumentException
\r
972 // Exception if "arg" was created from a different
\r
973 // document than the one that created the NamedNodeMap.
\r
975 // Testing approach - Create a NamedNodeMap object from the attributes of the
\r
976 // last child of the third employee and attempt to
\r
977 // add another Attr node to it that was created from a
\r
978 // different DOM document. This condition should raise
\r
979 // the desired exception. This method uses the
\r
980 // "createAttribute(name)" method from the Document
\r
983 // Semantic Requirements: 16
\r
985 //----------------------------------------------------------------------------
\r
988 [Category ("NotDotNet")] // MS DOM is buggy
\r
989 public void core0018M()
\r
991 string computedValue = "";
\r
993 System.Xml.XmlAttribute newAttrNode = util.getOtherDOMDocument().CreateAttribute("newAttribute");
\r
994 System.Xml.XmlNode testNode = null;
\r
995 string expectedValue = "System.ArgumentException";
\r
997 testResults results = new testResults("Core0018M");
\r
999 results.description = "The \"setNamedItem(arg)\" method raises a "+
\r
1000 "System.ArgumentException Exception if \"arg\" was " +
\r
1001 "created from a document different from the one that created "+
\r
1002 "the NamedNodeList.";
\r
1004 // Retrieve targeted data and attempt to add an element that was created
\r
1005 // from a different document. Should raise an exception.
\r
1007 testNode = util.nodeObject(util.THIRD,util.SIXTH);
\r
1011 testNode.Attributes.SetNamedItem(newAttrNode);
\r
1013 catch(System.Exception ex)
\r
1015 computedValue = ex.GetType().ToString();
\r
1019 results.expected = expectedValue;
\r
1020 results.actual = computedValue;
\r
1024 Assert.AreEqual (results.expected, results.actual);
\r
1027 //------------------------ End test case core-0018M --------------------------
\r
1029 //--------------------------- test case core-0019M ---------------------------
\r
1031 // Testing feature - The "setNamedItem(arg) method raises a
\r
1032 // NO_MODIFICATION_ALLOWED_ERR Exception if this
\r
1033 // NamedNodeMap is readonly.
\r
1035 // Testing approach - Create a NamedNodeMap object from the first child of the
\r
1036 // Entity named "ent4" inside the DocType node and then
\r
1037 // attempt to add a new item to the list. It should raise
\r
1038 // the desired exception as this is a readonly NamedNodeMap.
\r
1040 // Semantic Requirements: 17
\r
1042 //----------------------------------------------------------------------------
\r
1045 [Category ("NotDotNet")] // MS DOM is buggy
\r
1046 public void core0019M()
\r
1048 string computedValue = "";
\r
1049 System.Xml.XmlNode testNode = null;
\r
1050 System.Xml.XmlNode entityDesc;
\r
1051 System.Xml.XmlAttribute newAttrNode = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"newAttribute");
\r
1052 string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;
\r
1054 testResults results = new testResults("Core0019M");
\r
1056 results.description = "The \"setNamedItem(arg)\" method raises a " +
\r
1057 "NO_MODIFICATION_ALLOWED_ERR Exception if this "+
\r
1058 "NamedNodeMap is readonly.";
\r
1060 // Create a NamedNodeMap object and attempt to add a node to it.
\r
1061 // Should raise an exception.
\r
1063 testNode = util.getEntity("ent4");
\r
1064 entityDesc = testNode.FirstChild;
\r
1068 entityDesc.Attributes.SetNamedItem(newAttrNode);
\r
1070 catch(ArgumentException ex)
\r
1072 computedValue = ex.GetType ().FullName;
\r
1076 results.expected = expectedValue;
\r
1077 results.actual = computedValue;
\r
1081 Assert.AreEqual (results.expected, results.actual);
\r
1084 //------------------------ End test case core-0019M --------------------------
\r
1086 //--------------------------- test case core-0020M ---------------------------
\r
1088 // Testing feature - The "setNamedItem(arg) method raises an
\r
1089 // INUSE_ATTRIBUTE_ERR Exception if "arg" is an Attr
\r
1090 // that is already an attribute of another Element.
\r
1092 // Testing approach - Create a NamedNodeMap object from the attributes of the
\r
1093 // third child and attempt to add an attribute that is
\r
1094 // already being used by the first employee. An attempt
\r
1095 // to add such an attribute should raise the desired
\r
1098 // Semantic Requirements: 18
\r
1100 //----------------------------------------------------------------------------
\r
1103 [Category ("NotDotNet")]
\r
1104 public void core0020M()
\r
1106 string computedValue= "";
\r
1107 System.Xml.XmlAttribute inUseAttribute = null;
\r
1108 System.Xml.XmlElement firstEmployee = null;
\r
1109 System.Xml.XmlNode testNode = null;
\r
1110 string expectedValue = "System.ArgumentException";//util.INUSE_ATTRIBUTE_ERR;
\r
1112 testResults results = new testResults("Core0020M");
\r
1115 results.description = "The \"setNamedItem(arg)\" method raises an "+
\r
1116 "INUSE_ATTRIBUTE_ERR Exception if \"arg\" "+
\r
1117 "is an Attr node that is already an attribute "+
\r
1118 "of another Element.";
\r
1120 firstEmployee = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);
\r
1121 inUseAttribute = firstEmployee.GetAttributeNode("domestic");
\r
1123 // Attempt to add an attribute that is already used by another element
\r
1124 // should raise an exception.
\r
1126 testNode = util.nodeObject(util.THIRD,util.SIXTH);
\r
1130 testNode.Attributes.SetNamedItem(inUseAttribute);
\r
1132 catch (System.Exception ex)
\r
1134 computedValue = ex.GetType ().FullName;
\r
1138 catch(System.Exception ex)
\r
1140 computedValue = "Exception " + ex.Message;
\r
1143 results.expected = expectedValue;
\r
1144 results.actual = computedValue;
\r
1148 Assert.AreEqual (results.expected, results.actual);
\r
1151 //------------------------ End test case core-0020M --------------------------
\r
1153 //--------------------------- test case core-0021M ---------------------------
\r
1155 // Testing feature - The "removeNamedItem(name) method raises an
\r
1156 // NOT_FOUND_ERR Exception if there is no node
\r
1157 // named "name" in the map.
\r
1159 // Testing approach - Create a NamedNodeMap object from the attributes of the
\r
1160 // last child of the third employee and attempt to
\r
1161 // remove the "district" attribute. There is no node named
\r
1162 // "district" in the list and therefore the desired
\r
1163 // exception should be raised.
\r
1165 // System.Xml - return null, if a matching node was not found.
\r
1167 // Semantic Requirements: 19
\r
1169 //----------------------------------------------------------------------------
\r
1172 public void core0021M()
\r
1174 object computedValue = null;
\r
1175 System.Xml.XmlNode testNode = null;
\r
1176 object expectedValue = null;//util.NOT_FOUND1_ERR;
\r
1178 testResults results = new testResults("Core0021M");
\r
1181 results.description = "The \"removeNamedItem(name)\" method raises a " +
\r
1182 "NOT_FOUND_ERR Exception if there is no node "+
\r
1183 "named \"name\" in the map.";
\r
1185 // Create a NamedNodeMap object and attempt to remove an attribute that
\r
1186 // is not in the list should raise an exception.
\r
1188 testNode = util.nodeObject(util.THIRD,util.SIXTH);
\r
1192 //null if a matching node was not found
\r
1193 computedValue = testNode.Attributes.RemoveNamedItem("district");
\r
1195 catch(System.Exception ex)
\r
1197 computedValue = ex.Message;
\r
1201 catch(System.Exception ex)
\r
1203 computedValue = "Exception " + ex.Message;
\r
1206 results.expected = (expectedValue == null).ToString();
\r
1207 results.actual = (computedValue == null).ToString();
\r
1211 Assert.AreEqual (results.expected, results.actual);
\r
1214 //------------------------ End test case core-0021M --------------------------
\r