Add [Category ("NotWorking")] to failing test.
[mono.git] / mcs / class / System.XML / Test / System.Xml / nist_dom / fundamental / NamedNodeMap / NamedNodeMap.cs
1 //**************************************************************************\r
2 //\r
3 //\r
4 //                       National Institute Of Standards and Technology\r
5 //                                     DTS Version 1.0\r
6 //         \r
7 //                                 NamedNodeMap Interface\r
8 //\r
9 // Written by: Carmelo Montanez\r
10 // Modified by:  Mary Brady\r
11 //\r
12 // Ported to System.Xml by: Mizrahi Rafael rafim@mainsoft.com\r
13 // Mainsoft Corporation (c) 2003-2004\r
14 //**************************************************************************\r
15 using System;\r
16 using System.Xml;\r
17 \r
18 using nist_dom;\r
19 using NUnit.Framework;\r
20 \r
21 namespace nist_dom.fundamental\r
22 {\r
23     [TestFixture]\r
24     public class NamedNodeMapTest\r
25     {\r
26         public static int i = 2;\r
27 /*\r
28         public testResults[] RunTests()\r
29         {\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
35                                                         core0021M()};\r
36   \r
37             return tests;\r
38         }\r
39 */\r
40         //------------------------ test case core-0001M ------------------------\r
41         //\r
42         // Testing feature - The "getNamedItem(name)" method retrieves a node \r
43         //                   specified by name.\r
44         //\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
51         //                    \r
52         // Semantic Requirements: 1\r
53         //\r
54         //----------------------------------------------------------------------------\r
55 \r
56         [Test]\r
57         public void core0001M()\r
58         {\r
59             string computedValue = "";\r
60             string expectedValue = "domestic";\r
61             System.Xml.XmlAttribute domesticAttr = null;\r
62             System.Xml.XmlNode testNode = null;\r
63 \r
64             testResults results = new testResults("Core0001M");\r
65             try\r
66             {\r
67                 results.description = "The \"getNamedItem(name)\" method retrieves a node " +\r
68                     "specified by name.";\r
69                 //\r
70                 // Retrieve targeted data.\r
71                 //\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
75             }\r
76             catch(System.Exception ex)\r
77             {\r
78                 computedValue = "Exception " + ex.Message;\r
79             }\r
80 \r
81             //\r
82             // Write out results \r
83             //\r
84             results.expected = expectedValue;\r
85             results.actual = computedValue;\r
86 \r
87             Assert.AreEqual (results.expected, results.actual);\r
88         }\r
89 \r
90         //------------------------ End test case core-0001M --------------------------\r
91         //\r
92         //--------------------------- test case core-0002M ---------------------------\r
93         //\r
94         // Testing feature - The "getNamedItem(name)" method returns a node of any\r
95         //                   type specified by name.\r
96         //\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
102         //                    an Attr node.\r
103         //\r
104         // Semantic Requirements: 2 \r
105         //\r
106         //----------------------------------------------------------------------------\r
107 \r
108         [Test]\r
109         public void core0002M()\r
110         {\r
111             string computedValue = "";\r
112             string expectedValue = "street";\r
113             System.Xml.XmlAttribute streetAttr = null;\r
114             System.Xml.XmlNode testNode = null;\r
115 \r
116             testResults results = new testResults("Core0002M");\r
117             try\r
118             {\r
119                 results.description = "The \"getNamedItem(name)\" method returns a node "+\r
120                     "of any type specified by name (test for Attr node).";\r
121                 //\r
122                 // Retrieve targeted data and get its attributes.\r
123                 //\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
127             }\r
128             catch(System.Exception ex)\r
129             {\r
130                 computedValue = "Exception " + ex.Message;\r
131             }\r
132 \r
133             //\r
134             // Write out results\r
135             //\r
136             results.expected = expectedValue;\r
137             results.actual = computedValue;\r
138 \r
139             Assert.AreEqual (results.expected, results.actual);\r
140         }\r
141 \r
142         //------------------------ End test case core-0002M --------------------------\r
143         //\r
144         //--------------------------- test case core-0003M ---------------------------\r
145         //\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
148         //\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
155         //\r
156         // Semantic Requirements: 3 \r
157         //\r
158         //----------------------------------------------------------------------------\r
159 \r
160         [Test]\r
161         public void core0003M()\r
162         {\r
163             object computedValue = null;\r
164             object expectedValue = null;\r
165             System.Xml.XmlNode testNode = null;\r
166 \r
167 \r
168             testResults results = new testResults("Core0003M");\r
169             try\r
170             {\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
173                 //\r
174                 // Retrieve targeted data and attempt to get a non-existing attribute.\r
175                 //\r
176                 testNode = util.nodeObject(util.SECOND,util.SIXTH);\r
177                 computedValue = testNode.Attributes.GetNamedItem("district");\r
178             }\r
179             catch(System.Exception ex)\r
180             {\r
181                 computedValue = "Exception " + ex.Message;\r
182             }\r
183 \r
184             //\r
185             // Write out results\r
186             //\r
187             results.expected = (expectedValue == null).ToString();\r
188             results.actual = (computedValue == null).ToString();\r
189 \r
190             Assert.AreEqual (results.expected, results.actual);\r
191         }\r
192 \r
193         //------------------------ End test case core-0003M --------------------------\r
194         //\r
195         //--------------------------- test case core-0004M ---------------------------\r
196         //\r
197         // Testing feature - The "setNamedItem(arg)" method adds a node using its\r
198         //                   nodeName attribute. \r
199         //\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
211         //                    interface.\r
212         //\r
213         // Semantic Requirements: 4 \r
214         //\r
215         //----------------------------------------------------------------------------\r
216 \r
217         [Test]\r
218         public void core0004M()\r
219         {\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
225 \r
226             testResults results = new testResults("Core0004M");\r
227             try\r
228             {\r
229                 results.description = "The \"setNamedItem(arg)\" method adds a node "+\r
230                     "using its nodeName attribute.";\r
231                 //\r
232                 // Retrieve targeted data and add new attribute.\r
233                 //\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
238             }\r
239             catch(System.Exception ex)\r
240             {\r
241                 computedValue = "Exception " + ex.Message;\r
242             }\r
243 \r
244             //\r
245             // Write out results\r
246             //\r
247             results.expected = expectedValue;\r
248             results.actual = computedValue;\r
249 \r
250             util.resetData();\r
251             Assert.AreEqual (results.expected, results.actual);\r
252         }\r
253 \r
254         //------------------------ End test case core-0004M --------------------------\r
255         //\r
256         //--------------------------- test case core-0005 ---------------------------\r
257         //\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
260         //                   new one.\r
261         //\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
272         //                    interface.\r
273         //\r
274         // Semantic Requirements: 5 \r
275         //\r
276         //----------------------------------------------------------------------------\r
277 \r
278         [Test]\r
279         public void core0005M()\r
280         {\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
286 \r
287             testResults results = new testResults("Core0005M");\r
288             try\r
289             {\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
293 \r
294                 //\r
295                 // Retrieve targeted data and add new attribute with name matching an \r
296                 // already existing attribute.\r
297                 //\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
302             }\r
303             catch(System.Exception ex)\r
304             {\r
305                 computedValue = "Exception " + ex.Message;\r
306             }\r
307             //\r
308             // Write out results\r
309             //\r
310             results.expected = expectedValue;\r
311             results.actual = computedValue;\r
312 \r
313             util.resetData();\r
314             Assert.AreEqual (results.expected, results.actual);\r
315         }\r
316 \r
317         //------------------------ End test case core-0005M --------------------------\r
318         //\r
319         //--------------------------- test case core-0006 ---------------------------\r
320         //\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
324         //\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
336         //                    interface.\r
337         //\r
338         // Semantic Requirements: 6 \r
339         //\r
340         //----------------------------------------------------------------------------\r
341 \r
342         [Test]\r
343         public void core0006M()\r
344         {\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
350 \r
351             testResults results = new testResults("Core0006M");\r
352             try\r
353             {\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
357                 //\r
358                 // Retrieve targeted data and examine value returned by the setNamedItem\r
359                 // method.\r
360                 //\r
361                 testNode = util.nodeObject(util.THIRD,util.SIXTH);\r
362                 returnedNode = testNode.Attributes.SetNamedItem(newAttr);\r
363                 computedValue = returnedNode.Value;\r
364             }\r
365             catch(System.Exception ex)\r
366             {\r
367                 computedValue = "Exception " + ex.Message;\r
368             }\r
369             //\r
370             // Write out results\r
371             //\r
372             results.expected = expectedValue;\r
373             results.actual = computedValue;\r
374 \r
375             util.resetData();\r
376             Assert.AreEqual (results.expected, results.actual);\r
377         }\r
378 \r
379         //------------------------ End test case core-0006M --------------------------\r
380         //\r
381         //--------------------------- test case core-0007 ---------------------------\r
382         //\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
387         //\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
398         //\r
399         // Semantic Requirements: 7 \r
400         //\r
401         //----------------------------------------------------------------------------\r
402 \r
403         [Test]\r
404         public void core0007M()\r
405         {\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
410 \r
411             testResults results = new testResults("Core0007M");\r
412             try\r
413             {\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
415                 //\r
416                 // Retrieve targeted data and set new attribute.\r
417                 //\r
418                 testNode = util.nodeObject(util.THIRD,util.SIXTH);\r
419                 computedValue = testNode.Attributes.SetNamedItem(newAttr).Name;\r
420             }\r
421             catch(System.Exception ex)\r
422             {\r
423                 computedValue = "Exception " + ex.Message;\r
424             }\r
425             //\r
426             // Write out results\r
427             //\r
428             results.expected = expectedValue;\r
429             results.actual = computedValue;\r
430 \r
431             util.resetData();\r
432             Assert.AreEqual (results.expected, results.actual);\r
433         }\r
434 \r
435         //------------------------ End test case core-0007M --------------------------\r
436         //\r
437         //--------------------------- test case core-0008 ----------------------------\r
438         //\r
439         // Testing feature - The "removeNamedItem(name)" method removes a node\r
440         //                   specified by name. \r
441         //\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
449         //                    to false.  \r
450         //\r
451         // Semantic Requirements: 8 \r
452         //\r
453         //----------------------------------------------------------------------------\r
454 \r
455         [Test]\r
456         public void core0008M()\r
457         {\r
458             string computedValue = "";\r
459             string expectedValue = "False";\r
460             System.Xml.XmlNode testNode = null;\r
461             System.Xml.XmlAttribute Attr = null;\r
462 \r
463             testResults results = new testResults("Core0008M");\r
464             try\r
465             {\r
466                 results.description = "The \"removeNamedItem(name)\" method removes "+\r
467                     "a node specified by name.";\r
468                 //\r
469                 // Retrive targeted data and and remove attribute.  It should no longer\r
470                 // be specified.\r
471                 //\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
476             }\r
477             catch(System.Exception ex)\r
478             {\r
479                 computedValue = "Exception " + ex.Message;\r
480             }\r
481             //\r
482             // Write out results\r
483             //\r
484             results.expected = expectedValue;\r
485             results.actual = computedValue;\r
486 \r
487             util.resetData();\r
488             Assert.AreEqual (results.expected, results.actual);\r
489         }\r
490 \r
491         //------------------------ End test case core-0008M --------------------------\r
492         //\r
493         //--------------------------- test case core-0009 ----------------------------\r
494         //\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
497         //                   replaced.\r
498         //\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
507         //\r
508         // Semantic Requirements: 9 \r
509         //\r
510         //----------------------------------------------------------------------------\r
511 \r
512         [Test]\r
513 #if NET_2_0\r
514         [Category ("NotDotNet")]\r
515 #endif\r
516         public void core0009M()\r
517         {\r
518             string computedValue = "";\r
519             string expectedValue = "Yes";\r
520             System.Xml.XmlNode testNode = null;\r
521 \r
522             testResults results = new testResults("Core0009M");\r
523             try\r
524             {\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
528                 //\r
529                 // Retrieve targeted data and remove attribute.\r
530                 //\r
531                 testNode = util.nodeObject(util.THIRD,util.SIXTH);\r
532                 testNode.Attributes.RemoveNamedItem("street");\r
533                 computedValue = testNode.Attributes.GetNamedItem("street").Value;\r
534             }\r
535             catch(System.Exception ex)\r
536             {\r
537                 computedValue = "Exception " + ex.Message;\r
538             }\r
539             //\r
540             // Write out results\r
541             //\r
542             results.expected = expectedValue;\r
543             results.actual = computedValue;\r
544 \r
545             util.resetData();\r
546 \r
547             Assert.AreEqual (results.expected, results.actual);\r
548         }\r
549 \r
550         //------------------------ End test case core-0009M --------------------------\r
551         //\r
552         //--------------------------- test case core-0010M ---------------------------\r
553         //\r
554         // Testing feature - The "removeNamedItem(name)" method returns the node removed\r
555         //                   from the map.\r
556         //\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
563         //                    and return it.\r
564         //\r
565         // Semantic Requirements: 10 \r
566         //\r
567         //----------------------------------------------------------------------------\r
568 \r
569         [Test]\r
570         public void core0010M()\r
571         {\r
572             string computedValue = "";\r
573             string expectedValue = "No";\r
574             System.Xml.XmlNode returnedNode = null;\r
575             System.Xml.XmlNode testNode = null;\r
576 \r
577             testResults results = new testResults("Core0010M");\r
578             try\r
579             {\r
580                 results.description = "The \"removeNamedItem(name)\" method returns the "+\r
581                     "node removed from the map.";\r
582                 //\r
583                 // Retrieve targeted data, remove attribute and examine returned value of\r
584                 // removeNamedItem method.\r
585                 //\r
586                 testNode = util.nodeObject(util.THIRD,util.SIXTH);\r
587                 returnedNode = testNode.Attributes.RemoveNamedItem("street");\r
588                 computedValue = returnedNode.Value;\r
589             }\r
590             catch(System.Exception ex)\r
591             {\r
592                 computedValue = "Exception " + ex.Message;\r
593             }\r
594 \r
595             //\r
596             // Write out results\r
597             //\r
598             results.expected = expectedValue;\r
599             results.actual = computedValue;\r
600 \r
601             util.resetData();\r
602 \r
603             Assert.AreEqual (results.expected, results.actual);\r
604         }\r
605 \r
606         //------------------------ End test case core-0010M --------------------------\r
607         //\r
608         //--------------------------- test case core-0011M ---------------------------\r
609         //\r
610         // Testing feature - The "removeNamedItem(name)" method returns null if the\r
611         //                   name specified does not exists in the map.\r
612         //\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
618         //\r
619         // Semantic Requirements: 11\r
620         //\r
621         //----------------------------------------------------------------------------\r
622 \r
623         [Test]\r
624         public void core0011M()\r
625         {\r
626             object computedValue = null;\r
627             object expectedValue = null;\r
628             System.Xml.XmlNode testNode = null;\r
629 \r
630             testResults results = new testResults("Core0011M");\r
631             try\r
632             {\r
633                 results.description = "The \"removeNamedItem(name)\" method returns null "+\r
634                     "if the specified \"name\" is not in the map.";\r
635                 //\r
636                 // Retrieve targeted data and attempt to remove a non-existing attribute.\r
637                 //\r
638                 testNode = util.nodeObject(util.THIRD,util.SIXTH);\r
639                 computedValue = testNode.Attributes.RemoveNamedItem("district");\r
640             }\r
641             catch(System.Exception ex)\r
642             {\r
643                 computedValue = "Exception " + ex.Message;\r
644             }\r
645 \r
646             //\r
647             // Write out results\r
648             //\r
649             results.expected = (expectedValue == null).ToString();\r
650             results.actual = (computedValue == null).ToString();\r
651 \r
652             util.resetData();\r
653 \r
654             Assert.AreEqual (results.expected, results.actual);\r
655         }\r
656 \r
657         //------------------------ End test case core-0011M --------------------------\r
658         //\r
659         //--------------------------- test case core-0012M ---------------------------\r
660         //\r
661         // Testing feature - The "item(index)" method returns the indexth item in the\r
662         //                   map (test for first item).\r
663         //\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
672         //\r
673         // Semantic Requirements: 12\r
674         //\r
675         //----------------------------------------------------------------------------\r
676 \r
677         [Test]\r
678         public void core0012M()\r
679         {\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
686 \r
687             testResults results = new testResults("Core0012M");\r
688             try\r
689             {\r
690                 results.description = "Retrieve the first item in the map via the \"item(index)\" method."; \r
691 \r
692                 //\r
693                 // Retrieve targeted data and invoke "item" method.\r
694                 //  \r
695                 testNode = util.nodeObject(util.SECOND,util.SIXTH);\r
696                 returnedNode = testNode.Attributes.Item(0);\r
697                 computedValue = returnedNode.Name;\r
698             }\r
699             catch(System.Exception ex)\r
700             {\r
701                 computedValue = "Exception " + ex.Message;\r
702             }\r
703 \r
704             //\r
705             // Write out results\r
706             //\r
707             results.expected = expectedValue;\r
708             results.actual = computedValue;\r
709 \r
710             Assert.AreEqual (results.expected, results.actual);\r
711         }\r
712 \r
713         //------------------------ End test case core-0012M --------------------------\r
714         //\r
715         //--------------------------- test case core-0013M ---------------------------\r
716         //\r
717         // Testing feature - The "item(index)" method returns the indexth item in the\r
718         //                   map (test for last item).\r
719         //\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
727         //\r
728         // Semantic Requirements: 12\r
729         //\r
730         //----------------------------------------------------------------------------\r
731 \r
732         [Test]\r
733         public void core0013M()\r
734         {\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
740 \r
741             testResults results = new testResults("Core0013M");\r
742             try\r
743             {\r
744                 results.description = "Retrieve the last item in the map via the \"item(index)\" method."; \r
745                 //\r
746                 // Retrieve targeted data and invoke "item" attribute.\r
747                 //\r
748                 testNode = util.nodeObject(util.THIRD,util.SIXTH);\r
749                 returnedNode = testNode.Attributes.Item(1);\r
750                 computedValue = returnedNode.Name;\r
751             }\r
752             catch(System.Exception ex)\r
753             {\r
754                 computedValue = "Exception " + ex.Message;\r
755             }\r
756             //\r
757             // Write out results\r
758             //\r
759             results.expected = expectedValue;\r
760             results.actual = computedValue;\r
761 \r
762             Assert.AreEqual (results.expected, results.actual);\r
763         }\r
764 \r
765         //------------------------ End test case core-0013M --------------------------\r
766         //\r
767         //--------------------------- test case core-0014M ---------------------------\r
768         //\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
771         //\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
779         //\r
780         // Semantic Requirements: 13\r
781         //\r
782         //----------------------------------------------------------------------------\r
783 \r
784         [Test]\r
785         public void core0014M()\r
786         {\r
787             object computedValue = null;\r
788             object expectedValue = null;\r
789             System.Xml.XmlNode testNode = null;\r
790 \r
791             testResults results = new testResults("Core0014M");\r
792             try\r
793             {\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
796 \r
797                 //\r
798                 // Retrieve targeted data and invoke "item" method.\r
799                 //\r
800                 testNode = util.nodeObject(util.THIRD,util.SIXTH);\r
801                 computedValue = testNode.Attributes.Item(3);\r
802             }\r
803             catch(System.Exception ex)\r
804             {\r
805                 computedValue = "Exception " + ex.Message;\r
806             }\r
807 \r
808             //\r
809             // Write out results\r
810             //\r
811             results.expected = (expectedValue == null).ToString();\r
812             results.actual = (computedValue == null).ToString();\r
813 \r
814             Assert.AreEqual (results.expected, results.actual);\r
815         }\r
816 \r
817         //------------------------ End test case core-0014M --------------------------\r
818         //\r
819         //--------------------------- test case core-0015M ---------------------------\r
820         //\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
823         //\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
830         //                    0).\r
831         //\r
832         // Semantic Requirements: 13\r
833         //\r
834         //----------------------------------------------------------------------------\r
835 \r
836         [Test]\r
837         public void core0015M()\r
838         {\r
839             object computedValue = null;\r
840             object expectedValue = null;\r
841             System.Xml.XmlNode testNode = null;\r
842 \r
843             testResults results = new testResults("Core0015M");\r
844             try\r
845             {\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
848                 //\r
849                 // Retrieve targeted data and invoke "item" method.\r
850                 //\r
851                 testNode = util.nodeObject(util.THIRD,util.SIXTH);\r
852                 computedValue = testNode.Attributes.Item(2);\r
853             }\r
854             catch(System.Exception ex)\r
855             {\r
856                 computedValue = "Exception " + ex.Message;\r
857             }\r
858             //\r
859             // Write out results\r
860             //\r
861             results.expected = (expectedValue == null).ToString();\r
862             results.actual = (computedValue == null).ToString();\r
863 \r
864             Assert.AreEqual (results.expected, results.actual);\r
865         }\r
866 \r
867         //------------------------ End test case core-0015M --------------------------\r
868         //\r
869         //--------------------------- test case core-0016M ---------------------------\r
870         //\r
871         // Testing feature - The "length" attribute contains the total number of\r
872         //                   nodes in the map.\r
873         //\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
878         //\r
879         // Semantic Requirements: 14\r
880         //\r
881         //----------------------------------------------------------------------------\r
882 \r
883         [Test]\r
884         public void core0016M()\r
885         {\r
886             string computedValue = "";\r
887             string expectedValue = "2";\r
888             System.Xml.XmlNode testNode = null;\r
889 \r
890             testResults results = new testResults("Core0016M");\r
891             try\r
892             {\r
893                 results.description = "The \"length\" attribute contains the number of " +\r
894                     "nodes in the map.";\r
895                 //\r
896                 // Retrieve targeted data and invoke "length" attribute.\r
897                 //\r
898                 testNode = util.nodeObject(util.THIRD,util.SIXTH);\r
899                 computedValue = testNode.Attributes.Count.ToString();\r
900             }\r
901             catch(System.Exception ex)\r
902             {\r
903                 computedValue = "Exception " + ex.Message;\r
904             }\r
905             //\r
906             // Write out results\r
907             //\r
908             results.expected = expectedValue;\r
909             results.actual = computedValue;\r
910 \r
911             Assert.AreEqual (results.expected, results.actual);\r
912         }\r
913 \r
914         //------------------------ End test case core-0016M --------------------------\r
915         //\r
916         //--------------------------- test case core-0017M ---------------------------\r
917         //\r
918         // Testing feature - The range of valid child nodes indices is 0 to length - 1.\r
919         //\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
924         //\r
925         // Semantic Requirements: 15 \r
926         //\r
927         //----------------------------------------------------------------------------\r
928 \r
929         [Test]\r
930         public void core0017M()\r
931         {\r
932             string computedValue = "";\r
933             string expectedValue = "0 1 ";\r
934             int lastIndex = 0;\r
935             //string attributes = "";\r
936             System.Xml.XmlNode testNode = null;\r
937 \r
938             testResults results = new testResults("Core0017M");\r
939             try\r
940             {\r
941                 results.description = "The range of valid child nodes indices is 0 to " +\r
942                     "length - 1.";\r
943                 //\r
944                 // Retrieve targeted data and compute list length.\r
945                 //\r
946                 testNode = util.nodeObject(util.THIRD,util.SIXTH);\r
947                 lastIndex = testNode.Attributes.Count - 1;\r
948                 //\r
949                 // Traverse the list from 0 to length - 1.  All indices should be valid.\r
950                 //\r
951                 for (int index = 0;index <= lastIndex; index++)\r
952                     computedValue += index+" ";\r
953             }\r
954             catch(System.Exception ex)\r
955             {\r
956                 computedValue = "Exception " + ex.Message;\r
957             }\r
958             //\r
959             // Write out results.\r
960             //\r
961             results.expected = expectedValue;\r
962             results.actual = computedValue;\r
963 \r
964             Assert.AreEqual (results.expected, results.actual);\r
965         }\r
966 \r
967         //------------------------ End test case core-0017M --------------------------\r
968         //\r
969         //--------------------------- test case core-0018M ---------------------------\r
970         //\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
974         //\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
981         //                    interface. \r
982         //\r
983         // Semantic Requirements: 16\r
984         //\r
985         //----------------------------------------------------------------------------\r
986 \r
987         [Test]\r
988         [Category ("NotDotNet")] // MS DOM is buggy\r
989         public void core0018M()\r
990         {\r
991             string computedValue = "";\r
992             \r
993             System.Xml.XmlAttribute newAttrNode = util.getOtherDOMDocument().CreateAttribute("newAttribute");\r
994             System.Xml.XmlNode testNode = null;\r
995             string expectedValue = "System.ArgumentException";\r
996 \r
997             testResults results = new testResults("Core0018M");\r
998 \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
1003             //\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
1006             //\r
1007             testNode = util.nodeObject(util.THIRD,util.SIXTH);\r
1008 \r
1009             try \r
1010             {\r
1011                 testNode.Attributes.SetNamedItem(newAttrNode);\r
1012             } \r
1013             catch(System.Exception ex) \r
1014             {\r
1015                 computedValue = ex.GetType().ToString();\r
1016             }\r
1017 \r
1018 \r
1019             results.expected = expectedValue;\r
1020             results.actual = computedValue;\r
1021 \r
1022             util.resetData();\r
1023 \r
1024             Assert.AreEqual (results.expected, results.actual);\r
1025         }\r
1026 \r
1027         //------------------------ End test case core-0018M --------------------------\r
1028         //\r
1029         //--------------------------- test case core-0019M ---------------------------\r
1030         //\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
1034         //\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
1039         //                   \r
1040         // Semantic Requirements: 17\r
1041         //\r
1042         //----------------------------------------------------------------------------\r
1043 \r
1044         [Test]\r
1045         [Category ("NotDotNet")] // MS DOM is buggy\r
1046         public void core0019M()\r
1047         {\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
1053 \r
1054             testResults results = new testResults("Core0019M");\r
1055 \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
1059             //\r
1060             // Create a NamedNodeMap object and attempt to add a node to it.\r
1061             // Should raise an exception.\r
1062             //\r
1063             testNode = util.getEntity("ent4");\r
1064             entityDesc = testNode.FirstChild;\r
1065 \r
1066             try \r
1067             {\r
1068                 entityDesc.Attributes.SetNamedItem(newAttrNode);\r
1069             }\r
1070             catch(ArgumentException ex) \r
1071             {\r
1072                 computedValue = ex.GetType ().FullName; \r
1073             }\r
1074 \r
1075 \r
1076             results.expected = expectedValue;\r
1077             results.actual = computedValue;\r
1078 \r
1079             util.resetData();\r
1080 \r
1081             Assert.AreEqual (results.expected, results.actual);\r
1082         }\r
1083 \r
1084         //------------------------ End test case core-0019M --------------------------\r
1085         //\r
1086         //--------------------------- test case core-0020M ---------------------------\r
1087         //\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
1091         //\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
1096         //                    exception. \r
1097         //\r
1098         // Semantic Requirements: 18\r
1099         //\r
1100         //----------------------------------------------------------------------------\r
1101 \r
1102         [Test]\r
1103         [Category ("NotDotNet")]\r
1104         public void core0020M()\r
1105         {\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
1111 \r
1112             testResults results = new testResults("Core0020M");\r
1113             try\r
1114             {\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
1119 \r
1120                 firstEmployee = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);\r
1121                 inUseAttribute = firstEmployee.GetAttributeNode("domestic");\r
1122                 //\r
1123                 // Attempt to add an attribute that is already used by another element \r
1124                 // should raise an exception.\r
1125                 //\r
1126                 testNode = util.nodeObject(util.THIRD,util.SIXTH);\r
1127 \r
1128                 try \r
1129                 {\r
1130                     testNode.Attributes.SetNamedItem(inUseAttribute);\r
1131                 }\r
1132                 catch (System.Exception ex) \r
1133                 {\r
1134                     computedValue = ex.GetType ().FullName; \r
1135                 }\r
1136 \r
1137             }\r
1138             catch(System.Exception ex)\r
1139             {\r
1140                 computedValue = "Exception " + ex.Message;\r
1141             }\r
1142 \r
1143             results.expected = expectedValue;\r
1144             results.actual = computedValue;\r
1145 \r
1146             util.resetData();\r
1147 \r
1148             Assert.AreEqual (results.expected, results.actual);\r
1149         }\r
1150 \r
1151         //------------------------ End test case core-0020M --------------------------\r
1152         //\r
1153         //--------------------------- test case core-0021M ---------------------------\r
1154         //\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
1158         //\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
1164         //\r
1165         // System.Xml       - return null, if a matching node was not found.\r
1166         //\r
1167         // Semantic Requirements: 19\r
1168         //\r
1169         //----------------------------------------------------------------------------\r
1170 \r
1171         [Test]\r
1172         public void core0021M()\r
1173         {\r
1174             object computedValue = null;\r
1175             System.Xml.XmlNode testNode = null;\r
1176             object expectedValue = null;//util.NOT_FOUND1_ERR;\r
1177 \r
1178             testResults results = new testResults("Core0021M");\r
1179             try\r
1180             {\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
1184                 //\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
1187                 //\r
1188                 testNode = util.nodeObject(util.THIRD,util.SIXTH);\r
1189 \r
1190                 try \r
1191                 {\r
1192                     //null if a matching node was not found\r
1193                     computedValue = testNode.Attributes.RemoveNamedItem("district");\r
1194                 }\r
1195                 catch(System.Exception ex) \r
1196                 {\r
1197                     computedValue = ex.Message; \r
1198                 }\r
1199 \r
1200             }\r
1201             catch(System.Exception ex)\r
1202             {\r
1203                 computedValue = "Exception " + ex.Message;\r
1204             }\r
1205 \r
1206             results.expected = (expectedValue == null).ToString();\r
1207             results.actual = (computedValue == null).ToString();\r
1208 \r
1209             util.resetData();\r
1210 \r
1211             Assert.AreEqual (results.expected, results.actual);\r
1212         }\r
1213 \r
1214         //------------------------ End test case core-0021M --------------------------\r
1215     }\r
1216 }\r