2009-06-12 Bill Holmes <billholmes54@gmail.com>
[mono.git] / mcs / class / System.XML / Test / System.Xml / nist_dom / fundamental / Element / Element.cs
1 //**************************************************************************\r
2 //\r
3 //\r
4 //                       National Institute Of Standards and Technology\r
5 //                                     DTS Version 1.0\r
6 //         \r
7 //                                   Element 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 ElementTest : Assertion\r
25     {\r
26         public static int i = 2;\r
27 /*\r
28         public testResults[] RunTests()\r
29         {\r
30             testResults[] tests = new testResults[] {core0001E(), core0002E(), core0003E(),core0004E(),\r
31                                                         core0005E(), core0006E(), core0007E(), core0008E(),\r
32                                                         core0009E(), core0010E(), core0011E(), core0012E(),\r
33                                                         core0013E(), core0014E(), core0015E(), core0016E(),\r
34                                                         core0017E(), core0018E(), core0019E(), core0020E(),\r
35                                                         core0021E(), core0022E(), core0023E(), core0024E(),\r
36                                                         core0025E(), core0026E(), core0027E(), core0028E(),\r
37                                                         core0029E(), core0030E()};\r
38   \r
39             return tests;\r
40         }\r
41 */\r
42         //------------------------ test case core-0001E ------------------------\r
43         //\r
44         // Testing feature - Elements may have attributes associated with them. \r
45         //\r
46         // Testing approach - Retrieve the first attribute from the last child of\r
47         //                    the first employee and examine its "specified"\r
48         //                    attribute.  This test is only intended to show\r
49         //                    that Elements can actually have attributes.\r
50         //                    This test uses the "getNamedItem(name)" method from \r
51         //                    the NamedNodeMap interface.\r
52         //\r
53         // Semantic Requirements: 1\r
54         //\r
55         //----------------------------------------------------------------------------\r
56 \r
57         [Test]\r
58         public void core0001E()\r
59         {\r
60             string computedValue = "0";//0\r
61             string expectedValue = "True";//true\r
62             System.Xml.XmlNode addressElement = null;\r
63             System.Xml.XmlAttributeCollection attrList = null;\r
64             System.Xml.XmlAttribute domesticAttr = null;\r
65 \r
66             testResults results = new testResults("Core0001E");\r
67             try\r
68             {\r
69                 results.description = "Element nodes may have associated attributes.";\r
70                 //\r
71                 // Retrieve the "address" element from the first employee.\r
72                 //\r
73                 addressElement = util.nodeObject(util.FIRST,util.SIXTH);\r
74                 //\r
75                 // Access its "domestic" attribute by creating a list of all attributes\r
76                 // and then retrieving the desired attribute from the list by name. \r
77                 //\r
78                 attrList = addressElement.Attributes;//.node.\r
79                 domesticAttr = (System.Xml.XmlAttribute)attrList.GetNamedItem("domestic");\r
80                 //\r
81                 // Access its "specified" attribute.\r
82                 //\r
83                 computedValue = domesticAttr.Specified.ToString();\r
84             }\r
85             catch(System.Exception ex)\r
86             {\r
87                 computedValue = "Exception " + ex.Message;\r
88             }\r
89 \r
90             //\r
91             // Write out results \r
92             //\r
93             results.expected = expectedValue;\r
94             results.actual = computedValue;\r
95 \r
96             AssertEquals (results.expected, results.actual);\r
97         }\r
98         //------------------------ End test case core-0001E --------------------------\r
99         //\r
100         //------------------------ test case core-0002E ------------------------\r
101         //\r
102         // Testing feature - The generic Attribute "attributes" (Node interface) may \r
103         //                   be used to retrieve the set of all attributes of an\r
104         //                   element.\r
105         //\r
106         // Testing approach - Create a list of all the attributes of the last child of\r
107         //                    of the first employee by using the generic "attributes"\r
108         //                    attribute from the Node interface.  Further the length\r
109         //                    of the attribute list is examined.  This test makes\r
110         //                    use of the "Count" attribute from the NameNodeMap \r
111         //                    interface.\r
112         //\r
113         // Semantic Requirements: 1, 2 \r
114         //\r
115         //----------------------------------------------------------------------------\r
116 \r
117         [Test]\r
118         [Category ("NotDotNet")] // MS DOM is buggy\r
119         public void core0002E()\r
120         {\r
121             string computedValue = "";\r
122             string expectedValue = "2";\r
123             System.Xml.XmlNode addressElement = null;\r
124             System.Xml.XmlAttributeCollection attrList = null;\r
125 \r
126             testResults results = new testResults("Core0002E");\r
127             try\r
128             {\r
129                 results.description = "The generic \"attributes\" (from the Node interface) may " +\r
130                     "be used to retrieve the set of all attributes of an element.";\r
131                 //\r
132                 // Retrieve the "address" element from the first employee.\r
133                 //\r
134                 addressElement = util.nodeObject(util.FIRST,util.SIXTH);\r
135                 //\r
136                 // Access its attributes list.\r
137                 //\r
138                 attrList = addressElement.Attributes;\r
139                 //\r
140                 // Access its "length" attribute.\r
141                 //\r
142                 computedValue = attrList.Count.ToString();\r
143             }\r
144             catch(System.Exception ex)\r
145             {\r
146                 computedValue = "Exception " + ex.Message;\r
147             }\r
148             //\r
149             // Write out results\r
150             //\r
151             results.expected = expectedValue;\r
152             results.actual = computedValue;\r
153 \r
154             AssertEquals (results.expected, results.actual);\r
155         }\r
156 \r
157         //------------------------ End test case core-0002E --------------------------\r
158         //\r
159         //-------------------------- test case core-0003E ----------------------------\r
160         //\r
161         // Testing feature - The "tagName" attribute contains the name of the\r
162         //                   element. \r
163         //\r
164         // Testing approach - Retrieve the third child of the second employee and\r
165         //                    examine its "tagName" attribute.  It should return a \r
166         //                    string containing the name of the element ("position",\r
167         //                    in this case). \r
168         //\r
169         // Semantic Requirements: 3 \r
170         //\r
171         //----------------------------------------------------------------------------\r
172 \r
173         [Test]\r
174         public void core0003E()\r
175         {\r
176             string computedValue = "";\r
177             string expectedValue = "position";\r
178             System.Xml.XmlNode positionElement = null;\r
179 \r
180             testResults results = new testResults("Core0003E");\r
181             try\r
182             {\r
183                 results.description = "The \"tagName\" of an Element contains the " +\r
184                     "element's name.";\r
185                 //\r
186                 // Access its third child of the second employee.\r
187                 //\r
188                 positionElement = util.nodeObject(util.SECOND,util.THIRD);\r
189                 //\r
190                 // Access its "tagName" attribute.\r
191                 //\r
192                 computedValue = positionElement.Name;//tagName;//.node.\r
193             }\r
194             catch(System.Exception ex)\r
195             {\r
196                 computedValue = "Exception " + ex.Message;\r
197             }\r
198             //\r
199             // Write out results\r
200             //\r
201             results.expected = expectedValue;\r
202             results.actual = computedValue;\r
203 \r
204             AssertEquals (results.expected, results.actual);\r
205         }\r
206 \r
207         //------------------------ End test case core-0003E --------------------------\r
208         //\r
209         //-------------------------- test case core-0004E ----------------------------\r
210         //\r
211         // Testing feature - The "getAttribute(name)" method returns an attribute value\r
212         //                   by name. \r
213         //\r
214         // Testing approach - Retrieve the the last child of the third employee, then  \r
215         //                    invoke its "getAttribute(name)" method.  It should\r
216         //                    return the value of the attribute("No", in this case).\r
217         //\r
218         // Semantic Requirements: 1, 4\r
219         //\r
220         //----------------------------------------------------------------------------\r
221 \r
222         [Test]\r
223         public void core0004E()\r
224         {\r
225             string computedValue = "";\r
226             string expectedValue = "No";\r
227             System.Xml.XmlElement addressElement = null;\r
228 \r
229             testResults results = new testResults("Core0004E");\r
230             try\r
231             {\r
232                 results.description = "The \"getAttribute(name)\" method of an Element returns " +\r
233                     "the value of an attribute by name.";\r
234                 //\r
235                 // Retrieve the targeted data. \r
236                 //\r
237                 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);\r
238                 computedValue = addressElement.GetAttribute("street");//addressElement.node.GetAttribute("street");\r
239             }\r
240             catch(System.Exception ex)\r
241             {\r
242                 computedValue = "Exception " + ex.Message;\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             AssertEquals (results.expected, results.actual);\r
251         }\r
252 \r
253         //------------------------ End test case core-0004E --------------------------\r
254         //\r
255         //-------------------------- test case core-0005E ----------------------------\r
256         //\r
257         // Testing feature - The "getAttribute(name)" method returns an empty\r
258         //                   string if no value was assigned to an attribute and\r
259         //                   no default value was given in the DTD file.\r
260         //\r
261         // Testing approach - Retrieve the the last child of the last employee, then\r
262         //                    invoke its "getAttribute(name)" method, where "name" is an\r
263         //                    attribute with no specified or DTD default value.  The\r
264         //                    "getAttribute(name)" method should return the empty\r
265         //                    string.  This method makes use of the \r
266         //                    "createAttribute(newAttr)" method from the Document\r
267         //                    interface.\r
268         //\r
269         // Semantic Requirements: 1, 4, 5 \r
270         //\r
271         //----------------------------------------------------------------------------\r
272 \r
273         [Test]\r
274         public void core0005E()\r
275         {\r
276             string computedValue = "";\r
277             string expectedValue = "";\r
278             System.Xml.XmlElement addressElement = null;\r
279             System.Xml.XmlAttribute newAttribute = null;\r
280 \r
281 \r
282             testResults results = new testResults("Core0005E");\r
283             try\r
284             {\r
285                 results.description = "The \"getAttribute(name)\" method of an Element returns " +\r
286                     "the empty string if the attribue does not have a default " +\r
287                     "or specified value.";\r
288                 //\r
289                 // Access the sixth child of the last employee.\r
290                 //\r
291                 newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");\r
292                 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FOURTH,util.SIXTH);\r
293                 //\r
294                 // Invoke its "setAttributeNode(newAttr)" method where\r
295                 // newAttr = "newAttribute".  Since no value was specified or given\r
296                 // by default, the value returned by the "getAttribute(name)" method \r
297                 // should be the empty string.\r
298                 //\r
299                 addressElement.SetAttributeNode(newAttribute);//.node.\r
300                 computedValue = addressElement.GetAttribute("district");//.node.\r
301             }\r
302             catch(System.Exception ex)\r
303             {\r
304                 computedValue = "Exception " + ex.Message;\r
305             }\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 \r
315             AssertEquals (results.expected, results.actual);\r
316         }\r
317 \r
318         //------------------------ End test case core-0005E --------------------------\r
319         //\r
320         //-------------------------- test case core-0006E ----------------------------\r
321         //\r
322         // Testing feature - The "setAttribute(name,value)" method adds a new attribute\r
323         //                   to the Element.\r
324         //\r
325         // Testing approach - Retrieve the last child of the last employee, then\r
326         //                    add an attribute to it by invoking its \r
327         //                    "setAttribute(name,value)" method.  It should create \r
328         //                    a "name" attribute with an assigned value equal to \r
329         //                    "value".  \r
330         //\r
331         // Semantic Requirements: 1, 4, 6 \r
332         //\r
333         //----------------------------------------------------------------------------\r
334 \r
335         [Test]\r
336         public void core0006E()\r
337         {\r
338             string computedValue = "";\r
339             System.Xml.XmlElement addressElement = null;\r
340             string name = "district";\r
341             string expectedValue = "dallas"; \r
342 \r
343 \r
344             testResults results = new testResults("Core0006E");\r
345             try\r
346             {\r
347                 results.description = "The \"setAttribute(name,value)\" method of an Element " +\r
348                     "creates an new \"name\" attribute whose value is equal to \"value\".";\r
349                 //\r
350                 // Access the last child of the last employee.\r
351                 //\r
352                 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.SIXTH);\r
353                 //\r
354                 // Invoke its "setAttribute(name,value)" method and create a new attribute\r
355                 //\r
356                 addressElement.SetAttribute(name,expectedValue);//.node.\r
357                 //\r
358                 // This Element should now have a new attribute that we can be retrieved\r
359                 // by name. \r
360                 //\r
361                 computedValue = addressElement.GetAttribute(name);//.node.\r
362             }\r
363             catch(System.Exception ex)\r
364             {\r
365                 computedValue = "Exception " + ex.Message;\r
366             }\r
367             //\r
368             // Write out results\r
369             //\r
370             results.expected = expectedValue;\r
371             results.actual = computedValue;\r
372 \r
373             util.resetData();\r
374 \r
375             AssertEquals (results.expected, results.actual);\r
376         }\r
377 \r
378         //------------------------ End test case core-0006E --------------------------\r
379         //\r
380         //-------------------------- test case core-0007E ----------------------------\r
381         //\r
382         // Testing feature - The "setAttribute(name,value)" method adds a new attribute\r
383         //                   to the Element.  If the "name" is already present, then\r
384         //                   its value should be changed to the new one of the\r
385         //                   "value" parameter.\r
386         //\r
387         // Testing approach - Retrieve the last child of the fourth employee,\r
388         //                    then add an attribute to it by invoking its\r
389         //                    "setAttribute(name,value)" method.  Since the name \r
390         //                    of the used attribute ("street") is already present\r
391         //                    in this element, then its value should be\r
392         //                    changed to the new one of the "value" parameter.\r
393         //\r
394         // Semantic Requirements: 1, 4, 7 \r
395         //\r
396         //----------------------------------------------------------------------------\r
397 \r
398         [Test]\r
399         public void core0007E()\r
400         {\r
401             string computedValue = "";\r
402             string expectedValue = "Neither";\r
403             System.Xml.XmlElement addressElement = null;\r
404 \r
405             testResults results = new testResults("Core0007E");\r
406             try\r
407             {\r
408                 results.description = "The \"setAttribute(name,value)\" method of an Element " +\r
409                     "where the \"name\" attribute is already present in this Element.";\r
410                 //\r
411                 // Access the sixth child of the fourth employee.\r
412                 //\r
413                 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FOURTH,util.SIXTH);\r
414                 //\r
415                 // Invoke its "setAttribute(name,value)" method where name = "street"\r
416                 // and value = "Neither".\r
417                 //\r
418                 addressElement.SetAttribute("street","Neither");//.node.\r
419                 //\r
420                 // The "street" attribute should now have a value of "Neither" \r
421                 //\r
422                 computedValue = addressElement.GetAttribute("street");//.node.\r
423             }\r
424             catch(System.Exception ex)\r
425             {\r
426                 computedValue = "Exception " + ex.Message;\r
427             }\r
428 \r
429             //\r
430             // Write out results\r
431             //\r
432             results.expected = expectedValue;\r
433             results.actual = computedValue;\r
434 \r
435             util.resetData();\r
436 \r
437             AssertEquals (results.expected, results.actual);\r
438         }\r
439 \r
440         //------------------------ End test case core-0007E --------------------------\r
441         //\r
442         //-------------------------- test case core-0008E ----------------------------\r
443         //\r
444         // Testing feature - The "removeAttribute(name)" removes an attribute\r
445         //                   by name.  If the removed attribute is known to have a\r
446         //                   default value, an attribute immediately appears \r
447         //                   containing the default value.\r
448         //\r
449         // Testing approach - Retrieve the attribute named "street" from the last\r
450         //                    child of the fourth employee, then remove the "street"\r
451         //                    attribute by invoking its "removeAttribute(name) method.\r
452         //                    The "street" attribute has a default value defined in the \r
453         //                    DTD file, that value should immediately replace the \r
454         //                    old value.   \r
455         //\r
456         // Semantic Requirements: 1, 8 \r
457         //\r
458         //----------------------------------------------------------------------------\r
459 \r
460         [Test]\r
461 #if NET_2_0\r
462         [Category ("NotDotNet")]\r
463 #endif\r
464         public void core0008E()\r
465         {\r
466             string computedValue = "";\r
467             string expectedValue = "Yes";\r
468             System.Xml.XmlElement addressElement = null;\r
469             string streetAttr = "";\r
470 \r
471             testResults results = new testResults("Core0008E");\r
472             try\r
473             {\r
474                 results.description = "The \"removeAttribute(name)\" method of an Element " +\r
475                     "removes the \"name\" attribute and restores any " +\r
476                     "known default values.";\r
477                 //\r
478                 // Access the last child of the fourth employee.\r
479                 //\r
480                 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FOURTH,util.SIXTH);\r
481                 //\r
482                 // Invoke its "removeAttribute(name)" method where name = "street"\r
483                 //\r
484                 addressElement.RemoveAttribute("street");//.node.\r
485                 //\r
486                 // Now access that attribute.\r
487                 //\r
488                 streetAttr = addressElement.GetAttribute("street");//.node.\r
489                 //\r
490                 // The "street" attribute should now have a default values \r
491                 //\r
492                 computedValue = addressElement.GetAttribute("street");//.node.\r
493             }\r
494             catch(System.Exception ex)\r
495             {\r
496                 computedValue = "Exception " + ex.Message;\r
497             }\r
498 \r
499             //\r
500             // Write out results\r
501             //\r
502             results.expected = expectedValue;\r
503             results.actual = computedValue;\r
504 \r
505             util.resetData();\r
506 \r
507             AssertEquals (results.expected, results.actual);\r
508         }\r
509 \r
510         //------------------------ End test case core-0008E --------------------------\r
511         //\r
512         //-------------------------- test case core-0009E ----------------------------\r
513         //\r
514         // Testing feature - The "getAttributeNode(name)" retrieves an attribute\r
515         //                   node by name.  \r
516         //\r
517         // Testing approach - Retrieve the attribute named "domestic" from the last \r
518         //                    child of the first employee.  Since the method returns\r
519         //                    an Attr object, its name attribute can be examined to \r
520         //                    ensure the proper attribute was retrieved.\r
521         //\r
522         // Semantic Requirements: 1, 9 \r
523         //\r
524         //----------------------------------------------------------------------------\r
525 \r
526         [Test]\r
527         public void core0009E()\r
528         {\r
529             string computedValue = "";\r
530             string expectedValue = "domestic";\r
531             System.Xml.XmlElement addressElement = null;\r
532             System.Xml.XmlAttribute domesticAttrNode = null;\r
533 \r
534             testResults results = new testResults("Core0009E");\r
535             try\r
536             {\r
537                 results.description = "The \"getAttributeNode(name)\" method of an Element " +\r
538                     "returns the \"name\" Attr node.";\r
539                 //\r
540                 // Access the last child of the first employee.\r
541                 //\r
542                 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);\r
543                 //\r
544                 // Invoke its "getAttributeNode(name)" method where name = "domestic"\r
545                 // and create an Attr object.  \r
546                 //\r
547                 domesticAttrNode = addressElement.GetAttributeNode("domestic");//.node.\r
548                 //\r
549                 // Now access the "name" attribute of that Attr node.  Since the "domestic"\r
550                 // attribute was retrieved, the name of the Attr node should also be\r
551                 // "domestic". \r
552                 //\r
553                 computedValue = domesticAttrNode.Name;\r
554             }\r
555             catch(System.Exception ex)\r
556             {\r
557                 computedValue = "Exception " + ex.Message;\r
558             }\r
559 \r
560             //\r
561             // Write out results\r
562             //\r
563             results.expected = expectedValue;\r
564             results.actual = computedValue;\r
565 \r
566             AssertEquals (results.expected, results.actual);\r
567         }\r
568 \r
569         //------------------------ End test case core-0009E --------------------------\r
570         //\r
571         //-------------------------- test case core-00010E ----------------------------\r
572         //\r
573         // Testing feature - The "getAttributeNode(name)" retrieves an attribute\r
574         //                   node by name.  It should return null if the "name" \r
575         //                   attribute does not exist.\r
576         //\r
577         // Testing approach - Retrieve the last child of the first employee and \r
578         //                    attempt to retrieve a non-existing attribute.\r
579         //                    The method should return null.  The non-existing\r
580         //                    attribute to be used is "invalidAttribute".\r
581         //\r
582         // Semantic Requirements: 1, 10\r
583         //\r
584         //----------------------------------------------------------------------------\r
585 \r
586         [Test]\r
587         public void core0010E()\r
588         {\r
589             object computedValue = null;\r
590             object expectedValue = null;\r
591             System.Xml.XmlElement addressElement = null;\r
592 \r
593             testResults results = new testResults("Core0010E");\r
594             try\r
595             {\r
596                 results.description = "The \"getAttributeNode(name)\" method returns null " +\r
597                     "if the \"name\" attribute does not exist.";\r
598                 //\r
599                 // Access the last child of the first employee.\r
600                 //\r
601                 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);\r
602                 //\r
603                 // Invoke its "getAttributeNode(name)" method where name = "invalidAttribute"\r
604                 // This should result in a null value being returned by the method.\r
605                 //\r
606                 computedValue = addressElement.GetAttributeNode("invalidAttribute");//.node.\r
607             }\r
608             catch(System.Exception ex)\r
609             {\r
610                 computedValue = "Exception " + ex.Message;\r
611             }\r
612             //\r
613             // Write out results\r
614             //\r
615             results.expected = (expectedValue == null).ToString();\r
616             results.actual = (computedValue == null).ToString();\r
617 \r
618             AssertEquals (results.expected, results.actual);\r
619         }\r
620 \r
621         //------------------------ End test case core-0010E --------------------------\r
622         //\r
623         //-------------------------- test case core-0011E ----------------------------\r
624         //\r
625         // Testing feature - The "setAttributeNode(newAttr)" adds a new attribute\r
626         //                   to the Element.\r
627         //\r
628         // Testing approach - Retrieve the last child of the first employee and\r
629         //                    add a new attribute node to it by invoking its \r
630         //                    "setAttributeNode(newAttr)" method.  This test makes \r
631         //                    use of the "createAttribute(name)" method from the \r
632         //                    Document interface.\r
633         //\r
634         // Semantic Requirements: 1, 11\r
635         //\r
636         //----------------------------------------------------------------------------\r
637 \r
638         [Test]\r
639         public void core0011E()\r
640         {\r
641             string computedValue = "";\r
642             string expectedValue = "";\r
643             System.Xml.XmlElement addressElement = null;\r
644             System.Xml.XmlAttribute newAttribute = null;\r
645             string name = "district";\r
646 \r
647             testResults results = new testResults("Core0011E");\r
648             try\r
649             {\r
650                 results.description = "The \"setAttributeNode(newAttr)\" method adds a new " +\r
651                     "attribute node to the element.";\r
652                 //\r
653                 // Access the last child of the first employee.\r
654                 //\r
655                 newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,name);\r
656                 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);\r
657                 //\r
658                 // Invoke its "setAttributeNode(newAttr)" method where \r
659                 // newAttr = "newAttribute".  Since no value was specified or given \r
660                 // by default, its value should be the empty string. \r
661                 //\r
662                 addressElement.SetAttributeNode(newAttribute);//.node.\r
663                 computedValue = addressElement.GetAttribute(name);//.node.\r
664             }\r
665             catch(System.Exception ex)\r
666             {\r
667                 computedValue = "Exception " + ex.Message;\r
668             }\r
669             //\r
670             // Write out results\r
671             //\r
672             results.expected = expectedValue;\r
673             results.actual = computedValue;\r
674 \r
675             util.resetData();\r
676 \r
677             AssertEquals (results.expected, results.actual);\r
678         }\r
679 \r
680         //------------------------ End test case core-0011E --------------------------\r
681         //\r
682         //-------------------------- test case core-00012E ----------------------------\r
683         //\r
684         // Testing feature - The "setAttributeNode(newAttr)" method adds a new attribute\r
685         //                   to the Element.  If the "newAttr" Attr node is already\r
686         //                   present in this element, it should replace the existing\r
687         //                   one.\r
688         //\r
689         // Testing approach - Retrieve the last child of the third employee and\r
690         //                    add a new attribute node to it by invoking its\r
691         //                    "setAttributeNode(newAttr)" method.  The new attribute \r
692         //                    node to be added is "street", which is already\r
693         //                    present in this element.  The method should replace the \r
694         //                    existing Attr node with the new one.  This test make use \r
695         //                    of the "createAttribute(name)" method from the Document\r
696         //                    interface.\r
697         //\r
698         // Semantic Requirements: 1, 12\r
699         //\r
700         //----------------------------------------------------------------------------\r
701 \r
702         [Test]\r
703         public void core0012E()\r
704         {\r
705             string computedValue = "";\r
706             string expectedValue = "";\r
707             System.Xml.XmlElement addressElement = null;\r
708             System.Xml.XmlAttribute newAttribute = null;\r
709 \r
710             testResults results = new testResults("Core0012E");\r
711             try\r
712             {\r
713                 results.description = "The \"setAttributeNode(newAttr)\" method when " +\r
714                     "the \"newAttr\" node is already part of this " +\r
715                     "element.  The existing attribute node should be "+\r
716                     "replaced with the new one."; \r
717                 //\r
718                 // Access the last child of the third employee.\r
719                 //\r
720                 newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"street");  \r
721                 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);\r
722                 //\r
723                 // Invoke its "setAttributeNode(newAttr)" method where \r
724                 // newAttr = "newAttribute".  That attribute is already part of this \r
725                 // element.  The existing attribute should be replaced with the new one \r
726                 //    (newAttribute).\r
727                 //\r
728                 addressElement.SetAttributeNode(newAttribute);//.node.\r
729                 computedValue = addressElement.GetAttribute("street");//.node.\r
730             }\r
731             catch(System.Exception ex)\r
732             {\r
733                 computedValue = "Exception " + ex.Message;\r
734             }\r
735             //\r
736             // Write out results\r
737             //\r
738             results.expected = expectedValue;\r
739             results.actual = computedValue;\r
740 \r
741             util.resetData();\r
742 \r
743             AssertEquals (results.expected, results.actual);\r
744         }\r
745 \r
746         //------------------------ End test case core-0012E --------------------------\r
747         //\r
748         //-------------------------- test case core-00013E ----------------------------\r
749         //\r
750         // Testing feature - If The "setAttributeNode(newAttr)" method replaces \r
751         //                   an existing Attr node with the same name, then it \r
752         //                   should return the previously existing Attr node.\r
753         //\r
754         // Testing approach - Retrieve the last child of the third employee and add\r
755         //                    a new attribute node to it.  The new attribute node to \r
756         //                    be added is "street", which is already present in this\r
757         //                    Element.  The method should return the existing Attr \r
758         //                    node(old "street" Attr).  This test make use of the \r
759         //                    "createAttribute(name)" method from the Document \r
760         //                    interface.\r
761         //\r
762         // Semantic Requirements: 1, 13\r
763         //\r
764         //----------------------------------------------------------------------------\r
765 \r
766         [Test]\r
767         public void core0013E()\r
768         {\r
769             string computedValue = "";\r
770             string expectedValue = "No";\r
771             System.Xml.XmlElement addressElement = null;\r
772             System.Xml.XmlAttribute oldStreetAttribute = null;\r
773             System.Xml.XmlAttribute newAttribute = null;\r
774 \r
775             testResults results = new testResults("Core0013E");\r
776             try\r
777             {\r
778                 results.description = "The \"setAttributeNode(newAttr)\" method when the " +\r
779                     "\"newAttr\" attribute node is already present in " +\r
780                     "this element.  The method should return the previously " +\r
781                     "existing Attr node."; \r
782                 //\r
783                 // Access the last child of the third employee.\r
784                 //\r
785                 newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"street");\r
786                 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);\r
787                 //\r
788                 // Invoke its "setAttributeNode(newAttr)" method where \r
789                 // newAttr was just created with the same name as an already existing\r
790                 // attribute("street"). The existing attribute should be replaced with the \r
791                 // new one and the method should return the existing "street" Attr node.  \r
792                 //\r
793                 oldStreetAttribute = addressElement.SetAttributeNode(newAttribute);//.node.\r
794                 //\r
795                 // The "oldStreetAttribute" now contains the old Attr node and its \r
796                 // "value" attribute should be available for examination.\r
797                 //\r
798                 computedValue = oldStreetAttribute.Value;\r
799             }\r
800             catch(System.Exception ex)\r
801             {\r
802                 computedValue = "Exception " + ex.Message;\r
803             }\r
804 \r
805             //\r
806             // Write out results\r
807             //\r
808             results.expected = expectedValue;\r
809             results.actual = computedValue;\r
810 \r
811             util.resetData();\r
812 \r
813             AssertEquals (results.expected, results.actual);\r
814         }\r
815 \r
816         //------------------------ End test case core-0013E --------------------------\r
817         //\r
818         //-------------------------- test case core-00014E ----------------------------\r
819         //\r
820         // Testing feature - The "setAttributeNode(newAttr)" method returns the \r
821         //                   null value if no previously existing Attr node with the \r
822         //                   same name was replaced.\r
823         //\r
824         // Testing approach - Retrieve the last child of the third and add a new \r
825         //                    attribute node to it.  The new attribute node to be \r
826         //                    added is "district", which is not part of this Element.  \r
827         //                    The method should return the null value.  This test makes\r
828         //                    use of the "createAttribute(name)" method from the\r
829         //                    Document interface.\r
830         //\r
831         // Semantic Requirements: 1, 15\r
832         //\r
833         //----------------------------------------------------------------------------\r
834 \r
835         [Test]\r
836         [Category ("NotDotNet")] // MS DOM is buggy\r
837         public void core0014E()\r
838         {\r
839             object computedValue = null;\r
840             object expectedValue = null;\r
841             System.Xml.XmlElement addressElement = null;\r
842             System.Xml.XmlAttribute newAttribute = null;\r
843 \r
844             testResults results = new testResults("Core0014E");\r
845             try\r
846             {\r
847                 results.description = "The \"setAttributeNode(newAttr)\" method returns a " +\r
848                     "null value if no previously existing Attr node was replaced.";\r
849                 //\r
850                 // Access the sixth child of the third employee.\r
851                 //\r
852                 newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");\r
853                 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);\r
854                 //\r
855                 // Invoke its "setAttributeNode(newAttr)" method where name = "newAttribute".\r
856                 // This attribute is not part of this element.  The method should add the\r
857                 // new Attribute and return a null value.\r
858                 //\r
859                 computedValue = addressElement.SetAttributeNode(newAttribute);//.node.\r
860             }\r
861             catch(System.Exception ex)\r
862             {\r
863                 computedValue = "Exception " + ex.Message;\r
864             }\r
865 \r
866             //\r
867             // Write out results\r
868             //\r
869             results.expected = (expectedValue == null).ToString();\r
870             results.actual = (computedValue == null).ToString();\r
871 \r
872             util.resetData();\r
873 \r
874             AssertEquals (results.expected, results.actual);\r
875         }\r
876 \r
877         //------------------------ End test case core-0014E --------------------------\r
878         //\r
879         //-------------------------- test case core-00015E ----------------------------\r
880         //\r
881         // Testing feature - The "removeAttributeNode(oldAttr)" method removes the \r
882         //                   specified attribute. \r
883         //\r
884         // Testing approach - Retrieve the last child of the third employee, add\r
885         //                    a new "district" node to it and the try to remove it. \r
886         //                    To verify that the node was removed this test uses the \r
887         //                    "getNamedItem(name)" from the NamedNodeMap interface.   \r
888         //                    This test also makes use of the "attributes" attribute \r
889         //                    from the Node interface.\r
890         //\r
891         // Semantic Requirements: 1, 14\r
892         //\r
893         //----------------------------------------------------------------------------\r
894 \r
895         [Test]\r
896         public void core0015E()\r
897         {\r
898             object computedValue = null;\r
899             object expectedValue = null;\r
900             System.Xml.XmlElement addressElement = null;\r
901             System.Xml.XmlAttributeCollection attrList = null;\r
902             System.Xml.XmlAttribute newAttribute = null;\r
903             newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");\r
904 \r
905             testResults results = new testResults("Core0015E");\r
906             try\r
907             {\r
908                 results.description = "The \"removeAttributeNode(oldAttr)\" method removes the " +\r
909                     "specified attribute node.";\r
910                 //\r
911                 // Access the sixth child of the third employee and add the new\r
912                 // attribute to it.\r
913                 //\r
914                 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);\r
915                 addressElement.SetAttributeNode(newAttribute);//.node.\r
916                 //\r
917                 // Invoke its "removeAttributeNode(oldAttr)" method where \r
918                 // name = "newAttribute" and remove that attribute node.\r
919                 //\r
920                 addressElement.RemoveAttributeNode(newAttribute);//.node.\r
921                 //\r
922                 // To ensure that the "district" attribute was indeed removed, a listing\r
923                 // of all attributes is created by invoking the "attributes" attribute\r
924                 // of "addressElement".  After the list is created, we attempt to\r
925                 // retrieve the "district" element from the list.  A null value should\r
926                 // be return in its place.\r
927                 //\r
928                 attrList = addressElement.Attributes;\r
929                 computedValue = attrList.GetNamedItem("district");\r
930             }\r
931             catch(System.Exception ex)\r
932             {\r
933                 computedValue = "Exception " + ex.Message;\r
934             }\r
935             //\r
936             // Write out results\r
937             //\r
938             results.expected = (expectedValue == null).ToString();\r
939             results.actual = (computedValue == null).ToString();\r
940 \r
941             util.resetData();\r
942 \r
943             AssertEquals (results.expected, results.actual);\r
944         }\r
945 \r
946         //------------------------ End test case core-0015E --------------------------\r
947         //\r
948         //-------------------------- test case core-00016E ----------------------------\r
949         //\r
950         // Testing feature - The "removeAttributeNode(oldAttr)" method removes the \r
951         //                   specified attribute node and restore any default values.\r
952         //\r
953         // Testing approach - Retrieve the last child of the third employee and\r
954         //                    remove its "street" Attr node.  Since this node has\r
955         //                    default value defined in the DTD file, that default\r
956         //                    value should immediately be the new value.  \r
957         //\r
958         // Semantic Requirements: 1, 15\r
959         //\r
960         //----------------------------------------------------------------------------\r
961 \r
962         [Test]\r
963 #if NET_2_0\r
964         [Category ("NotDotNet")]\r
965 #endif\r
966         public void core0016E()\r
967         {\r
968             string computedValue = "";\r
969             string expectedValue = "Yes";\r
970             System.Xml.XmlElement addressElement = null;\r
971             System.Xml.XmlAttribute streetAttr = null;\r
972             //System.Xml.XmlNode thirdEmployee = null;\r
973 \r
974             testResults results = new testResults("Core0016E");\r
975             try\r
976             {\r
977                 results.description = "The \"removeAttributeNode(oldAttr)\" method removes the " +\r
978                     "specified attribute node and restores any default values.";\r
979                 //\r
980                 // Access the sixth child of the third employee.\r
981                 //\r
982                 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);\r
983                 //\r
984                 // Create an instance of an Attr object by retrieving the "street"\r
985                 // attribute node, invoke its "removeAttributeNode(oldAttr)" method\r
986                 // where name = "streetAttr" and remove that attribute node.  Note that \r
987                 // "the removeAttributeNode(oldAttr)" takes an Attr object as its \r
988                 // parameter, that is why an Attr object (named "street") is first created. \r
989                 //\r
990                 streetAttr = addressElement.GetAttributeNode("street");//.node.\r
991                 addressElement.RemoveAttributeNode(streetAttr);//.node.\r
992                 //\r
993                 // Since there is a default value defined for the "street" attribute, it\r
994                 // should immediately be the new value for that attribute. \r
995                 //\r
996                 computedValue = addressElement.GetAttribute("street");//.node.\r
997             }\r
998             catch(System.Exception ex)\r
999             {\r
1000                 computedValue = "Exception " + ex.Message;\r
1001             }\r
1002 \r
1003             //\r
1004             // Write out results\r
1005             //\r
1006             results.expected = expectedValue;\r
1007             results.actual = computedValue;\r
1008 \r
1009             util.resetData();\r
1010 \r
1011             AssertEquals (results.expected, results.actual);\r
1012         }\r
1013 \r
1014         //------------------------ End test case core-0016E --------------------------\r
1015         //\r
1016         //-------------------------- test case core-00017E ----------------------------\r
1017         //\r
1018         // Testing feature - The "removeAttributeNode(oldAttr)" method returns the \r
1019         //                   node that was removed.\r
1020         //\r
1021         // Testing approach - Retrieve the last child of the third employee and \r
1022         //                    remove its "street" Attr node.  The method should \r
1023         //                    return the old attribute node.\r
1024         //\r
1025         // Semantic Requirements: 1, 16\r
1026         //\r
1027         //----------------------------------------------------------------------------\r
1028 \r
1029         [Test]\r
1030         public void core0017E()\r
1031         {\r
1032             string computedValue = "";\r
1033             string expectedValue = "No";\r
1034             System.Xml.XmlElement addressElement = null;\r
1035             System.Xml.XmlAttribute streetAttr = null;\r
1036             System.Xml.XmlAttribute oldStreetAttribute = null;\r
1037 \r
1038             testResults results = new testResults("Core0017E");\r
1039             try\r
1040             {\r
1041                 results.description = "The \"removeAttributeNode(oldAttr)\" method returns the "+\r
1042                     "removed attribute node.";\r
1043                 //\r
1044                 // Access the sixth child of the third employee.\r
1045                 //\r
1046                 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);\r
1047 \r
1048                 // create an instance of an Attr object by retrieving the "street"\r
1049                 // attribute node, invoke its "removeAttributeNode(oldAttr)" method\r
1050                 // where name = "streetAttr" and remove that attribute node.  Note that\r
1051                 // "the removeAttributeNode(oldAttr)" takes an Attr object as its\r
1052                 // parameter, that is why an Attr object (named "street") is first created.\r
1053                 //\r
1054                 streetAttr = addressElement.GetAttributeNode("street");//.node.\r
1055                 oldStreetAttribute = addressElement.RemoveAttributeNode(streetAttr);//.node.\r
1056                 //\r
1057                 // The method should return the removed attribute node.  Its value can then\r
1058                 // be examined.\r
1059                 //\r
1060                 computedValue = oldStreetAttribute.Value;\r
1061             }\r
1062             catch(System.Exception ex)\r
1063             {\r
1064                 computedValue = "Exception " + ex.Message;\r
1065             }\r
1066             //\r
1067             // Write out results\r
1068             //\r
1069             results.expected = expectedValue;\r
1070             results.actual = computedValue;\r
1071 \r
1072             util.resetData();\r
1073 \r
1074             AssertEquals (results.expected, results.actual);\r
1075         }\r
1076 \r
1077         //------------------------ End test case core-0017E --------------------------\r
1078         //\r
1079         //-------------------------- test case core-00018E ----------------------------\r
1080         //\r
1081         // Testing feature - The "getElementsByTagName(name)" method returns a list \r
1082         //                   of all descendant Elements with the given tag name.\r
1083         //\r
1084         // Testing approach - Get a listing of all the descendant elements of the\r
1085         //                    root element using the string "employee" as the tag\r
1086         //                    name.  The  method should return a Node list of length \r
1087         //                    equal to 5.  This test makes use of the "length" \r
1088         //                    attribute from the NodeList interface.\r
1089         //\r
1090         // Semantic Requirements: 1, 17\r
1091         //\r
1092         //----------------------------------------------------------------------------\r
1093 \r
1094         [Test]\r
1095         public void core0018E()\r
1096         {\r
1097             int computedValue = 0;\r
1098             int expectedValue = 5;\r
1099             System.Xml.XmlNodeList employeeList = null;\r
1100             System.Xml.XmlElement docElement = null;\r
1101 \r
1102             testResults results = new testResults("Core0018E");\r
1103 \r
1104             results.description = "The \"getElementsByTagName(name)\" method returns a "+\r
1105                 "NodeList of all descendant elements with the given " +\r
1106                 "tag name(method returning a non-empty list)";\r
1107             //\r
1108             // get a listing of all the elements that match the tag "employee".\r
1109             //\r
1110             docElement = util.getRootNode();\r
1111             employeeList = docElement.GetElementsByTagName("employee");\r
1112             //\r
1113             // The method should return a NodeList whose length can then be examined. \r
1114             //\r
1115             computedValue = employeeList.Count;\r
1116             //\r
1117             // Write out results\r
1118             //\r
1119             results.expected = expectedValue.ToString();\r
1120             results.actual = computedValue.ToString();\r
1121 \r
1122             AssertEquals (results.expected, results.actual);\r
1123         }\r
1124 \r
1125         //------------------------ End test case core-0018E --------------------------\r
1126         //\r
1127         //-------------------------- test case core-00019E ----------------------------\r
1128         //\r
1129         // Testing feature - The "getElementsByTagName(name)" returns a list of all\r
1130         //                   descendant Elements with the given tag name.  Test\r
1131         //                   for an empty list.\r
1132         //\r
1133         // Testing approach - Get a listing of all the descendant elements of the\r
1134         //                    root element using the string "noMatches" as the tag\r
1135         //                    name.  The  method should return a NodeList of length\r
1136         //                    equal to 0 since no descendant elements match the given\r
1137         //                    tag name.  This test makes use of the "length" attribute\r
1138         //                    from the NodeList interface.\r
1139         //\r
1140         // Semantic Requirements: 1, 17\r
1141         //\r
1142         //----------------------------------------------------------------------------\r
1143 \r
1144         [Test]\r
1145         public void core0019E()\r
1146         {\r
1147             int computedValue = 0;\r
1148             int expectedValue = 0;\r
1149             System.Xml.XmlNodeList employeeList = null;\r
1150             System.Xml.XmlElement docElement = null;\r
1151 \r
1152             testResults results = new testResults("Core0019E");\r
1153 \r
1154             results.description = "The \"getElementsByTagName(name)\" method returns a "+\r
1155                 "NodeList of all descendant elements with the given " +\r
1156                 "tag name (method returns an empty list)";\r
1157             //\r
1158             // get a listing of all the elements that match the tag "noMatch".\r
1159             //\r
1160             docElement = util.getRootNode();\r
1161             employeeList = docElement.GetElementsByTagName("noMatch");\r
1162             //\r
1163             // The method should return a NodeList whose length can then be examined.\r
1164             //\r
1165             computedValue = employeeList.Count;\r
1166             //\r
1167             // Write out results\r
1168             //\r
1169             results.expected = expectedValue.ToString();\r
1170             results.actual = computedValue.ToString();\r
1171 \r
1172             AssertEquals (results.expected, results.actual);\r
1173         }\r
1174 \r
1175         //------------------------ End test case core-0019E --------------------------\r
1176         //\r
1177         //-------------------------- test case core-00020E ----------------------------\r
1178         //\r
1179         // Testing feature - The "getElementsByTagName(name)" returns a list of all\r
1180         //                   descendant Elements in the order the children were\r
1181         //                   encountered in a pre order traversal of the element tree.\r
1182         //\r
1183         // Testing approach - Get a listing of all the descendant elements of the\r
1184         //                    root node using the string "employee" as the tag\r
1185         //                    name.  The  method should return a Node list of length\r
1186         //                    equal to 5 in the order the children were encountered.\r
1187         //                    Item number four in the list is accessed using a \r
1188         //                    subscript.  Item number four is itself an Element node\r
1189         //                    with children and whose first child should be \r
1190         //                    "employeeId".\r
1191         //\r
1192         // Semantic Requirements: 1, 18 \r
1193         //\r
1194         //----------------------------------------------------------------------------\r
1195 \r
1196         [Test]\r
1197         public void core0020E()\r
1198         {\r
1199             string computedValue = "";\r
1200             string expectedValue = "employeeId";\r
1201             System.Xml.XmlNodeList employeeList = null;\r
1202             System.Xml.XmlNode fourthEmployee = null;\r
1203             System.Xml.XmlElement docElement = null;\r
1204 \r
1205             testResults results = new testResults("Core0020E");\r
1206 \r
1207             results.description = "The \"getElementsByTagName(name)\" returns a NodeList " +\r
1208                 "of all descendant elements in the order the " +\r
1209                 "children were encountered in a preorder traversal " +\r
1210                 "of the element tree.";\r
1211             //\r
1212             // get a listing of all the elements that match the tag "employee".\r
1213             //\r
1214             docElement = util.getRootNode();\r
1215             employeeList = docElement.GetElementsByTagName("employee");\r
1216 \r
1217             //\r
1218             // The method should return a NodeList of the children in the order the \r
1219             // children were encountered.  Since "employeeList" is a NodeList we should \r
1220             // be able to access its elements by using a subscript.  Item number four \r
1221             // is itself an Element node with six children and the first child \r
1222             // is "employeeId". \r
1223             //\r
1224             fourthEmployee = employeeList.Item(util.FOURTH);\r
1225             computedValue = fourthEmployee.FirstChild.Name;\r
1226             //\r
1227             // Write out results\r
1228             //\r
1229             results.expected = expectedValue;\r
1230             results.actual = computedValue;\r
1231 \r
1232             AssertEquals (results.expected, results.actual);\r
1233         }\r
1234 \r
1235         //------------------------ End test case core-0020E --------------------------\r
1236         //\r
1237         //-------------------------- test case core-00021E ----------------------------\r
1238         //\r
1239         // Testing feature - The "getElementsByTagName(name)" method may use the \r
1240         //                   special value "*" to match all the tags in the element \r
1241         //                   tree. \r
1242         //\r
1243         // Testing approach - Get a listing of all the descendant elements of the\r
1244         //                    last employee by using the special value of "*".  The \r
1245         //                    method should return all of the descendant children\r
1246         //                    (total of 6) in the order the children were encountered.\r
1247         //\r
1248         // Semantic Requirements: 1, 19 \r
1249         //\r
1250         //----------------------------------------------------------------------------\r
1251 \r
1252         [Test]\r
1253         public void core0021E()\r
1254         {\r
1255             string computedValue = "";\r
1256             string expectedValue = "employeeId name position salary gender address ";\r
1257             System.Xml.XmlNodeList elementList = null;\r
1258             System.Xml.XmlElement lastEmployee = null;\r
1259 \r
1260             testResults results = new testResults("Core0021E");\r
1261 \r
1262             results.description = "The \"getElementsByTagName(name)\" method may use the " +\r
1263                 "special value \"*\" to match all the tags in the " +\r
1264                 "element tree.";\r
1265             //\r
1266             // get a listing of all the descendant elements of the last employee by using\r
1267             // the special value of "*".\r
1268             //\r
1269             lastEmployee = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,-1);\r
1270             elementList = lastEmployee.GetElementsByTagName("*");//.node.\r
1271             //\r
1272             // Traverse the list.\r
1273             //\r
1274             for (int index = 0;index <= elementList.Count - 1;index++)\r
1275                 computedValue += elementList.Item(index).Name+" ";\r
1276             //\r
1277             // Write out results\r
1278             //\r
1279             results.expected = expectedValue;\r
1280             results.actual = computedValue;\r
1281 \r
1282             AssertEquals (results.expected, results.actual);\r
1283         }\r
1284 \r
1285         //------------------------ End test case core-0021E --------------------------\r
1286         //\r
1287         //-------------------------- test case core-00022E ----------------------------\r
1288         //\r
1289         // Testing feature - The "normalize()" method puts all the nodes in the\r
1290         //                   full depth of the sub-tree underneath this element\r
1291         //                   into a "normal" form.\r
1292         //\r
1293         // Testing approach - Retrieve the third employee and access its second \r
1294         //                    child.  This child contains a block of text that spread\r
1295         //                    accross multiple lines.  The content of the "name" \r
1296         //                    child should be parsed and treated as a single Text node.\r
1297         //\r
1298         // Semantic Requirements: 1, 20\r
1299         //\r
1300         //----------------------------------------------------------------------------\r
1301 \r
1302         [Test]\r
1303         public void core0022E()\r
1304         {\r
1305             string computedValue = "";\r
1306             string expectedValue = "Roger\n Jones";\r
1307             System.Xml.XmlNode idElement = null;\r
1308             System.Xml.XmlNode textNode = null;\r
1309 \r
1310             testResults results = new testResults("Core0022E");\r
1311             try\r
1312             {\r
1313                 results.description = "The \"normalize()\" method puts all the nodes in the " +\r
1314                     "full depth of the sub-tree of this element into a normal form.";\r
1315                 //\r
1316                 // The "normalize() method should combine all the contiguous blocks of text\r
1317                 // and form a single "Text" node.  The "nodeValue" of that final Text node\r
1318                 // should be the combination of all continuos blocks of text that do not\r
1319                 // contain any markup language. \r
1320                 //\r
1321                 idElement = util.nodeObject(util.THIRD,util.SECOND);\r
1322                 idElement.Normalize();//.node.\r
1323                 textNode = idElement.LastChild;//.node.\r
1324                 //\r
1325                 // text should be in normal form now\r
1326                 //\r
1327                 computedValue = textNode.Value;\r
1328             }\r
1329             catch(System.Exception ex)\r
1330             {\r
1331                 computedValue = "Exception " + ex.Message;\r
1332             }\r
1333 \r
1334             //\r
1335             // Write out results\r
1336             //\r
1337             results.expected = expectedValue;\r
1338             results.actual = computedValue;\r
1339 \r
1340             util.resetData();\r
1341 \r
1342             AssertEquals (results.expected, results.actual);\r
1343         }\r
1344 \r
1345         //------------------------ End test case core-0022E --------------------------\r
1346         //\r
1347         //-------------------------- test case core-00023E ---------------------------\r
1348         //\r
1349         // Testing feature - The "setAttribute(name,value)" method raises an\r
1350         //                   INVALID_CHARACTER_ERR Exception if the specified  \r
1351         //                   name contains an invalid character.\r
1352         //\r
1353         // Testing approach - Retrieve the last child of the first employee\r
1354         //                    and call its "setAttribute(name,value)" method with\r
1355         //                    "name" containing an invalid character.\r
1356         //\r
1357         // Semantic Requirements: 1, 21\r
1358         //\r
1359         //----------------------------------------------------------------------------\r
1360 \r
1361         [Test]\r
1362         [Category ("NotDotNet")] // MS DOM is buggy\r
1363         public void core0023E()\r
1364         {\r
1365             string computedValue = "";\r
1366             System.Xml.XmlElement addressElement = null;\r
1367             string expectedValue = "System.ArgumentException";\r
1368 \r
1369             testResults results = new testResults("Core0023E");\r
1370             try\r
1371             {\r
1372                 results.description = "The \"setAttribute(name,value)\" method raises an " +\r
1373                     "ArgumentException if the specified " +\r
1374                     "name contains an invalid character.";\r
1375                 //\r
1376                 // Access the "address" element of the first employee. \r
1377                 //\r
1378                 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);\r
1379                 //\r
1380                 // Attempt to set an attribute with an invalid character in its name.\r
1381                 //\r
1382                 try \r
1383                 {\r
1384                     addressElement.SetAttribute("invalid^Name","thisValue");//.node.\r
1385                 }\r
1386                 catch(System.Exception ex) \r
1387                 {\r
1388                     computedValue = ex.GetType().ToString(); \r
1389                 }\r
1390             }\r
1391             catch(System.Exception ex)\r
1392             {\r
1393                 computedValue = "Exception " + ex.Message;\r
1394             }\r
1395 \r
1396             results.expected = expectedValue;\r
1397             results.actual = computedValue;\r
1398 \r
1399             util.resetData();\r
1400 \r
1401             AssertEquals (results.expected, results.actual);\r
1402         }\r
1403 \r
1404         //------------------------ End test case core-0023E --------------------------\r
1405         //\r
1406         //-------------------------- test case core-0024E ----------------------------\r
1407         //\r
1408         // Testing feature - The "setAttribute(name,value)" method raises a\r
1409         //                   NO_MODIFICATION_ALLOWED_ERR Exception if this \r
1410         //                   node is readonly.\r
1411         //\r
1412         // Testing approach - Retrieve the Element node inside the Entity node \r
1413         //                    named "ent4" and attempt to set an attribute for\r
1414         //                    it.  Descendants of Entity nodes are readonly nodes\r
1415         //                    and therefore the desired exception should be raised.\r
1416         //\r
1417         // Semantic Requirements: 22\r
1418         //\r
1419         //----------------------------------------------------------------------------\r
1420 \r
1421         [Test]\r
1422         [Category ("NotDotNet")] // MS DOM is buggy\r
1423         public void core0024E()\r
1424         {\r
1425             string computedValue = "";\r
1426             System.Xml.XmlEntity entityNode = null;\r
1427             System.Xml.XmlElement entityDesc = null;\r
1428             string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;\r
1429 \r
1430             testResults results = new testResults("Core0024E");\r
1431             try\r
1432             {\r
1433                 results.description = "The \"setAttribute(name,value)\" method raises a " +\r
1434                     "NO_MODIFICATION_ALLOWED_ERR Exception if the node is readonly.";\r
1435 \r
1436                 //\r
1437                 // Retreive the targeted data.\r
1438                 //\r
1439                 entityNode = util.getEntity("ent4");\r
1440                 entityDesc = (System.Xml.XmlElement)entityNode.FirstChild;\r
1441                 //\r
1442                 // Attempt to set an attribute for a readonly node should raise an exception.\r
1443                 //\r
1444                 try \r
1445                 {\r
1446                     entityDesc.SetAttribute("newAttribute","thisValue");\r
1447                 }\r
1448                 catch(System.Exception ex) \r
1449                 {\r
1450                     computedValue = ex.GetType ().FullName; \r
1451                 }\r
1452             }\r
1453             catch(System.Exception ex)\r
1454             {\r
1455                 computedValue = "Exception " + ex.Message;\r
1456             }\r
1457             results.expected = expectedValue;\r
1458             results.actual = computedValue;\r
1459 \r
1460             util.resetData();\r
1461 \r
1462             AssertEquals (results.expected, results.actual);\r
1463         }\r
1464 \r
1465         //------------------------ End test case core-0024E --------------------------\r
1466         //\r
1467         //-------------------------- test case core-00025E ---------------------------\r
1468         //\r
1469         // Testing feature - The "removeAttribute(name)" method raises a\r
1470         //                   NO_MODIFICATION_ALLOWED_ERR Exception if this\r
1471         //                   node is readonly.\r
1472         //\r
1473         // Testing approach - Retrieve the Element node inside the Entity node\r
1474         //                    named "ent4" and attempt to remove an attribute from\r
1475         //                    it.  Descendants of Entity nodes are readonly nodes\r
1476         //                    and therefore the desired exception should be raised.\r
1477         //\r
1478         // Semantic Requirements: 23\r
1479         //\r
1480         //----------------------------------------------------------------------------\r
1481 \r
1482         [Test]\r
1483         [Category ("NotDotNet")] // MS DOM is buggy\r
1484         public void core0025E()\r
1485         {\r
1486             string computedValue = "";\r
1487             System.Xml.XmlEntity entityNode = null;\r
1488             System.Xml.XmlElement entityDesc = null;\r
1489             string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;\r
1490 \r
1491             testResults results = new testResults("Core0025E");\r
1492             try\r
1493             {\r
1494                 results.description = "The \"removeAttribute(name)\" method raises a " +\r
1495                     "NO_MODIFICATION_ALLOWED_ERR Exception if the node is readonly.";\r
1496                 //\r
1497                 // Retrieve the targeted data.\r
1498                 //\r
1499                 entityNode = util.getEntity("ent4");\r
1500                 entityDesc = (System.Xml.XmlElement)entityNode.FirstChild;\r
1501                 //\r
1502                 // Attempt to set an attribute for a readonly node should raise an exception.\r
1503                 //\r
1504                 try \r
1505                 {\r
1506                     entityDesc.RemoveAttribute("attr1");\r
1507                 }\r
1508                 catch(System.Exception ex) \r
1509                 {\r
1510                     computedValue = ex.GetType ().FullName; \r
1511                 }\r
1512             }\r
1513             catch(System.Exception ex)\r
1514             {\r
1515                 computedValue = "Exception " + ex.Message;\r
1516             }\r
1517             results.expected = expectedValue;\r
1518             results.actual = computedValue;\r
1519 \r
1520             util.resetData();\r
1521 \r
1522             AssertEquals (results.expected, results.actual);\r
1523         }\r
1524 \r
1525         //------------------------ End test case core-0025E --------------------------\r
1526         //\r
1527         //-------------------------- test case core-00026E ---------------------------\r
1528         //\r
1529         // Testing feature - The "setAttributeNode(newAttr)" method raises a\r
1530         //                   NO_MODIFICATION_ALLOWED_ERR Exception if this\r
1531         //                   node is readonly.\r
1532         //\r
1533         // Testing approach - Retrieve the Element node inside the Entity node\r
1534         //                    named "ent4" and attempt to add a newly created Attr \r
1535         //                    node to it.  Descendants of Entity nodes are readonly \r
1536         //                    nodes and therefore the desired exception should be\r
1537         //                    raised.\r
1538         //\r
1539         // Semantic Requirements: 24\r
1540         //\r
1541         //----------------------------------------------------------------------------\r
1542 \r
1543         [Test]\r
1544         [Category ("NotDotNet")] // MS DOM is buggy\r
1545         public void core0026E()\r
1546         {\r
1547             string computedValue = "";\r
1548             System.Xml.XmlEntity entityNode = null;\r
1549             System.Xml.XmlElement entityDesc = null;\r
1550             System.Xml.XmlAttribute newAttr = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"newAttribute");\r
1551             string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;\r
1552 \r
1553             testResults results = new testResults("Core0026E");\r
1554             try\r
1555             {\r
1556                 results.description = "The \"setAttributeNode(newAttr)\" method raises a " +\r
1557                     "NO_MODIFICATION_ALLOWED_ERR Exception if the node is readonly.";\r
1558                 //\r
1559                 // Retrieve targeted data\r
1560                 //\r
1561                 entityNode = util.getEntity("ent4");\r
1562                 entityDesc = (System.Xml.XmlElement)entityNode.FirstChild;\r
1563                 //\r
1564                 // Attempt to set an attribute for a readonly node should raise an exception.\r
1565                 //\r
1566                 try \r
1567                 {\r
1568                     entityDesc.SetAttributeNode(newAttr);\r
1569                 }\r
1570                 catch(System.Exception ex) \r
1571                 {\r
1572                     computedValue = ex.GetType ().FullName; \r
1573                 }\r
1574             }\r
1575             catch(System.Exception ex)\r
1576             {\r
1577                 computedValue = "Exception " + ex.Message;\r
1578             }\r
1579             results.expected = expectedValue;\r
1580             results.actual = computedValue;\r
1581 \r
1582             util.resetData();\r
1583 \r
1584             AssertEquals (results.expected, results.actual);\r
1585         }\r
1586 \r
1587         //------------------------ End test case core-0026E --------------------------\r
1588         //\r
1589         //-------------------------- test case core-00027E ---------------------------\r
1590         //\r
1591         // Testing feature - The "removeAttributeNode(newAttr)" method raises a\r
1592         //                   NO_MODIFICATION_ALLOWED_ERR Exception if this\r
1593         //                   node is readonly.\r
1594         //\r
1595         // Testing approach - Retrieve the Element node inside the Entity node\r
1596         //                    named "ent4" and attempt to remove its "attr1"\r
1597         //                    attribute.  Descendants of Entity nodes are readonly\r
1598         //                    nodes and therefore the desired exception should be\r
1599         //                    raised.\r
1600         //\r
1601         // Semantic Requirements: 25\r
1602         //\r
1603         //----------------------------------------------------------------------------\r
1604 \r
1605         [Test]\r
1606         [Category ("NotDotNet")] // MS DOM is buggy\r
1607         public void core0027E()\r
1608         {\r
1609             string computedValue = "";\r
1610             System.Xml.XmlEntity entityNode = null;\r
1611             System.Xml.XmlElement entityDesc = null;\r
1612             System.Xml.XmlAttribute oldAttribute = null;\r
1613             string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;\r
1614 \r
1615             testResults results = new testResults("Core0027E");\r
1616             try\r
1617             {\r
1618                 results.description = "The \"removeAttributeNode(newAttr)\" method raises a " +\r
1619                     "NO_MODIFICATION_ALLOWED_ERR Exception if the node is readonly.";\r
1620                 //\r
1621                 // Get an instance of an attribute node and retrieve targeted data.\r
1622                 //\r
1623                 entityNode = util.getEntity("ent4");\r
1624                 entityDesc = (System.Xml.XmlElement)entityNode.FirstChild;\r
1625                 oldAttribute = ((System.Xml.XmlElement)entityNode.FirstChild).GetAttributeNode("attr1");\r
1626                 //\r
1627                 // Attempt to set remove an attribute node from a readonly node (lastChild).  \r
1628                 // Should raise an exception. \r
1629                 //\r
1630                 try \r
1631                 {\r
1632                     entityDesc.RemoveAttributeNode(oldAttribute);\r
1633                 }\r
1634                 catch(System.Exception ex) \r
1635                 {\r
1636                     computedValue = ex.GetType ().FullName; \r
1637                 }\r
1638             }\r
1639             catch(System.Exception ex)\r
1640             {\r
1641                 computedValue = "Exception " + ex.Message;\r
1642             }\r
1643             results.expected = expectedValue;\r
1644             results.actual = computedValue;\r
1645 \r
1646             util.resetData();\r
1647 \r
1648             AssertEquals (results.expected, results.actual);\r
1649         }\r
1650 \r
1651         //------------------------ End test case core-0027E --------------------------\r
1652         //\r
1653         //-------------------------- test case core-00028E ---------------------------\r
1654         //\r
1655         // Testing feature - The "setAttributeNode(newAttr)" method raises a\r
1656         //                   System.ArgumentException Exception if the "newAttr" was \r
1657         //                   created from a different document than the one that\r
1658         //                   created this document. \r
1659         //\r
1660         // Testing approach - Retrieve the last employee and attempt to set\r
1661         //                    a new attribute node for its "employee" element.\r
1662         //                    The new attribute was created from a document \r
1663         //                    other than the one that crated this element,\r
1664         //                    therefore the desired exception should be raised. \r
1665         //                    This test uses the "createAttribute(newAttr)" method\r
1666         //                    from the Document interface.\r
1667         //\r
1668         // Semantic Requirements: 26\r
1669         //\r
1670         //----------------------------------------------------------------------------\r
1671 \r
1672         [Test]\r
1673         [Category ("NotDotNet")] // MS DOM is buggy\r
1674         public void core0028E()\r
1675         {\r
1676             System.Xml.XmlElement addressElement = null;\r
1677             string computedValue = "";\r
1678             System.Xml.XmlAttribute newAttr = null;\r
1679             string expectedValue = "System.ArgumentException";\r
1680 \r
1681             testResults results = new testResults("Core0028E");\r
1682             try\r
1683             {\r
1684                 results.description = "The \"setAttributeNode(newAttr)\" method raises a " +\r
1685                     "System.ArgumentException Exception if \"newAttr\" was created " +\r
1686                     "from a different document than the one who created this node.";\r
1687                 //\r
1688                 // Access the address Element of the last employee and attempt to set \r
1689                 // a new attribute node. \r
1690                 //\r
1691                 newAttr = util.getOtherDOMDocument().CreateAttribute("newAttribute");\r
1692                 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.SIXTH);\r
1693                 //\r
1694                 // The new attribute was created from a different document and therefore \r
1695                 // an exception should be raised.\r
1696                 //\r
1697                 try \r
1698                 {\r
1699                     addressElement.SetAttributeNode(newAttr);//.node.\r
1700                 }\r
1701                 catch(System.Exception ex) \r
1702                 {\r
1703                     computedValue = ex.GetType().ToString(); \r
1704                 }\r
1705             }\r
1706             catch(System.Exception ex)\r
1707             {\r
1708                 computedValue = "Exception " + ex.Message;\r
1709             }\r
1710             results.expected = expectedValue;\r
1711             results.actual = computedValue;\r
1712 \r
1713             util.resetData();\r
1714 \r
1715             AssertEquals (results.expected, results.actual);\r
1716         }\r
1717 \r
1718         //------------------------ End test case core-0028E --------------------------\r
1719         //\r
1720         //-------------------------- test case core-00029E ---------------------------\r
1721         //\r
1722         // Testing feature - The "setAttributeNode(newAttr)" method raises an\r
1723         //                   InvalidOperationException if the "newAttr"\r
1724         //                   attribute is already an attribute of another element. \r
1725         //\r
1726         // Testing approach - Retrieve the last employee and attempt to set an\r
1727         //                    attribute node to one of its children that\r
1728         //                    already exist in another children.  The attribute\r
1729         //                    node used is "street", which already exist in the\r
1730         //                    "address" element.  An instance of that attribute\r
1731         //                    node is first retrived from the "address" element and\r
1732         //                    then attempted to be set in the "employeeId" element.  \r
1733         //                    This should cause the intended exception to be raised.\r
1734         //\r
1735         // Semantic Requirements: 27\r
1736         //\r
1737         //----------------------------------------------------------------------------\r
1738 \r
1739         [Test]\r
1740         public void core0029E()\r
1741         {\r
1742             string computedValue = "";\r
1743             System.Xml.XmlElement employeeIdElement = null;\r
1744             System.Xml.XmlElement addressElement = null;\r
1745             System.Xml.XmlAttribute newAttribute = null; \r
1746             string expectedValue = "InvalidOperationException";\r
1747 \r
1748             testResults results = new testResults("Core0029E");\r
1749             try\r
1750             {\r
1751                 results.description = "The \"setAttributeNode(newAttr)\" method raises an "+\r
1752                     "InvalidOperationException if \"newAttr\" attribute "+\r
1753                     "is already being used by another element.";\r
1754                 //\r
1755                 // Retrieve an already existing attribute from the "address" element.\r
1756                 // \r
1757                 addressElement =  (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.SIXTH);\r
1758                 newAttribute = addressElement.GetAttributeNode("street");//.node.\r
1759                 //\r
1760                 // Access the "employeeId" element of the last employee.\r
1761                 //\r
1762                 employeeIdElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.FIRST);\r
1763                 //\r
1764                 // Attempt to set an attribute node with an already existing attribute node  \r
1765                 // in another element.\r
1766                 //\r
1767                 try \r
1768                 {\r
1769                     employeeIdElement.SetAttributeNode(newAttribute);//.node.\r
1770                 }\r
1771                 catch(System.InvalidOperationException ex) \r
1772                 { \r
1773                     computedValue = "InvalidOperationException"; \r
1774                 }\r
1775             }\r
1776             catch(System.Exception ex)\r
1777             {\r
1778                 computedValue = "Exception " + ex.Message;\r
1779             }\r
1780             results.expected = expectedValue;\r
1781             results.actual = computedValue;\r
1782 \r
1783             util.resetData();\r
1784 \r
1785             AssertEquals (results.expected, results.actual);\r
1786         }\r
1787 \r
1788         //------------------------ End test case core-0029E -------------------------\r
1789         //\r
1790         //-------------------------- test case core-0030E ---------------------------\r
1791         //\r
1792         // Testing feature - The "removeAttributeNode(oldAttr)" method raises a \r
1793         //                   NOT_FOUND_ERR Exception if the "oldAttr" attribute\r
1794         //                   is not an attribute of the element.\r
1795         //\r
1796         // Testing approach - Retrieve the last employee and attempt to remove\r
1797         //                    a non existing attribute node.   This should cause \r
1798         //                    the intended exception be raised.  This test makes use\r
1799         //                    of the "createAttribute(name)" method from the\r
1800         //                    Document interface.\r
1801         //\r
1802         // Semantic Requirements: 28\r
1803         //\r
1804         //----------------------------------------------------------------------------\r
1805 \r
1806         [Test]\r
1807         [Category ("NotDotNet")] // MS DOM is buggy\r
1808         public void core0030E()\r
1809         {\r
1810             string computedValue = "";\r
1811             System.Xml.XmlElement addressElement = null;\r
1812             System.Xml.XmlAttribute oldAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"oldAttribute");\r
1813             string expectedValue = "System.ArgumentException";//util.NOT_FOUND1_ERR;\r
1814 \r
1815             testResults results = new testResults("Core0030E");\r
1816             try\r
1817             {\r
1818                 results.description = "The \"removeAttributeNode(oldAttr)\" method raises a " +\r
1819                     "NOT_FOUND_ERR Exception if \"oldAttr\" attribute " +\r
1820                     "is not an attribute of the element.";\r
1821                 //\r
1822                 // Access the "address" element of the last employee.\r
1823                 //\r
1824                 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.SIXTH);\r
1825                 //\r
1826                 // Attempt to remove a non-existing attribute. Should raise exception.\r
1827                 //\r
1828                 try \r
1829                 {\r
1830                     addressElement.RemoveAttributeNode(oldAttribute);//.node.\r
1831                 }\r
1832                 catch(ArgumentException ex) \r
1833                 {\r
1834                     computedValue = ex.GetType ().FullName; \r
1835                 }\r
1836             }\r
1837             catch(System.Exception ex)\r
1838             {\r
1839                 computedValue = "Exception " + ex.Message;\r
1840             }\r
1841             results.expected = expectedValue;\r
1842             results.actual = computedValue;\r
1843 \r
1844             util.resetData();\r
1845 \r
1846             AssertEquals (results.expected, results.actual);\r
1847         }\r
1848 \r
1849         //------------------------ End test case core-0030E --------------------------\r
1850     }\r
1851 }\r