1 //**************************************************************************
\r
4 // National Institute Of Standards and Technology
\r
7 // NodeList Interface
\r
9 // Written by: Carmelo Montanez
\r
10 // Modified by: Mary Brady
\r
12 // Ported to System.Xml by: Mizrahi Rafael rafim@mainsoft.com
\r
13 // Mainsoft Corporation (c) 2003-2004
\r
14 //**************************************************************************
\r
19 using NUnit.Framework;
\r
21 namespace nist_dom.fundamental
\r
24 public class NodeListTest
\r
26 public static int i = 2;
\r
28 public testResults[] RunTests()
\r
30 testResults[] tests = new testResults[] {core0001N(), core0002N(), core0003N(),core0004N(),
\r
31 core0005N(), core0006N(), core0007N(), core0008N(),
\r
37 //------------------------ test case core-0001N ------------------------
\r
39 // Testing feature - The items in the list are accessible via an integral
\r
40 // index starting from zero. (index equal 0)
\r
42 // Testing approach - Create a list of all the children elements of the
\r
43 // third employee and access its first child by using
\r
44 // an index of 0. This should result in "employeeId"
\r
45 // being selected. Further we evaluate its content
\r
46 // (by examining its "nodeName" attribute) to ensure
\r
47 // the proper element was accessed.
\r
49 // Semantic Requirements: 1
\r
51 //----------------------------------------------------------------------------
\r
54 public void core0001N()
\r
56 string computedValue = "";
\r
57 string expectedValue = "employeeId";
\r
58 System.Xml.XmlNode employeeId = null;
\r
59 System.Xml.XmlElement testNode = null;
\r
61 testResults results = new testResults("Core0001N");
\r
64 results.description = "The elements in the list are accessible via an "+
\r
65 "integral index starting from 0 (this test checks "+
\r
66 "for index equal to 0).";
\r
68 // Retrieve targeted data.
\r
70 testNode = (System.Xml.XmlElement)util.nodeObject(util.THIRD,-1);
\r
71 employeeId = util.getSubNodes(testNode).Item(util.FIRST);
\r
72 computedValue = employeeId.Name;
\r
74 catch(System.Exception ex)
\r
76 computedValue = "Exception " + ex.Message;
\r
80 // Write out results
\r
82 results.expected = expectedValue;
\r
83 results.actual = computedValue;
\r
85 Assert.AreEqual (results.expected, results.actual);
\r
88 //------------------------ End test case core-0001N --------------------------
\r
90 //--------------------------- test case core-0002N ---------------------------
\r
92 // Testing feature - The items in the list are accessible via an integral
\r
93 // index starting from zero. (index not equal 0)
\r
95 // Testing approach - Create a list of all the children elements of the
\r
96 // third employee and access its fourth child by
\r
97 // using an index of 3. This should result in "salary"
\r
98 // being selected. Further we evaluate its "nodeName"
\r
99 // attribute to ensure the proper element was accessed.
\r
101 // Semantic Requirements: 1
\r
103 //----------------------------------------------------------------------------
\r
106 public void core0002N()
\r
108 string computedValue = "";
\r
109 string expectedValue = "salary";
\r
110 System.Xml.XmlNode salary = null;
\r
111 System.Xml.XmlElement testNode = null;
\r
113 testResults results = new testResults("Core0002N");
\r
116 results.description = "The elements in the list are accessible via an "+
\r
117 "integral index starting from 0 (this test checks "+
\r
118 "for index not equal 0).";
\r
120 // Retrieve targeted data.
\r
122 testNode = (System.Xml.XmlElement)util.nodeObject(util.THIRD,-1);
\r
123 salary = util.getSubNodes(testNode).Item(util.FOURTH);
\r
124 computedValue = salary.Name;
\r
126 catch(System.Exception ex)
\r
128 computedValue = "Exception " + ex.Message;
\r
131 // Write out results
\r
133 results.expected = expectedValue;
\r
134 results.actual = computedValue;
\r
136 Assert.AreEqual (results.expected, results.actual);
\r
139 //------------------------ End test case core-0002N --------------------------
\r
141 //--------------------------- test case core-0003N ---------------------------
\r
143 // Testing feature - The "item(index)" method returns the indexth item
\r
144 // in the collection.
\r
146 // Testing approach - Create a list of all the Element children of the
\r
147 // third employee and access its first child by invoking
\r
148 // the "item(index)" method with index = 0. This should
\r
149 // cause the method to return the "employeeId" child.
\r
150 // Further we evaluate the returned item's "nodeName"
\r
151 // attribute to ensure the correct item was returned.
\r
153 // Semantic Requirements: 2
\r
155 //----------------------------------------------------------------------------
\r
158 public void core0003N()
\r
160 string computedValue = "";
\r
161 string expectedValue = "employeeId";
\r
162 System.Xml.XmlNode employeeId = null;
\r
163 System.Xml.XmlElement testNode = null;
\r
165 testResults results = new testResults("Core0003N");
\r
168 results.description = "The \"item(index)\" method returns the indexth "+
\r
169 "item in the collection (return first item).";
\r
171 // Retrieve targeted data.
\r
173 testNode = (System.Xml.XmlElement)util.nodeObject(util.THIRD,-1);
\r
174 employeeId = util.getSubNodes(testNode).Item(util.FIRST);
\r
175 computedValue = employeeId.Name;
\r
177 catch(System.Exception ex)
\r
179 computedValue = "Exception " + ex.Message;
\r
182 // Write out results
\r
184 results.expected = expectedValue;
\r
185 results.actual = computedValue;
\r
187 Assert.AreEqual (results.expected, results.actual);
\r
190 //------------------------ End test case core-0003N --------------------------
\r
192 //--------------------------- test case core-0004N ---------------------------
\r
194 // Testing feature - The "item(index)" method returns the indexth item
\r
195 // in the collection.
\r
197 // Testing approach - Create a list of all the Element children of the
\r
198 // third employee and access its first child by invoking
\r
199 // the "item(index)" method with index equals to the last
\r
200 // item in the list. This should cause the method to
\r
201 // return the "address" child. Further we evaluate the
\r
202 // returned item's "nodeName" attribute to ensure the
\r
203 // correct item was returned.
\r
205 // Semantic Requirements: 2
\r
207 //----------------------------------------------------------------------------
\r
210 public void core0004N()
\r
212 string computedValue = "";
\r
213 string expectedValue = "address";
\r
214 System.Xml.XmlNode address = null;
\r
215 System.Xml.XmlElement testNode = null;
\r
217 testResults results = new testResults("Core0004N");
\r
220 results.description = "The \"item(index)\" method returns the indxth "+
\r
221 "item in the collection (return last item).";
\r
223 // Retrieve targeted data.
\r
225 testNode = (System.Xml.XmlElement)util.nodeObject(util.THIRD,-1);
\r
226 address = util.getSubNodes(testNode).Item(util.SIXTH);
\r
227 computedValue = address.Name;
\r
229 catch(System.Exception ex)
\r
231 computedValue = "Exception " + ex.Message;
\r
234 // Write out results
\r
236 results.expected = expectedValue;
\r
237 results.actual = computedValue;
\r
239 Assert.AreEqual (results.expected, results.actual);
\r
242 //------------------------ End test case core-0004N --------------------------
\r
244 //--------------------------- test case core-0005N ---------------------------
\r
246 // Testing feature - If the index is greater than or equal to number of
\r
247 // nodes, the "item(index)" method returns null.
\r
249 // Testing approach - Create a list of all the Element children of the third
\r
250 // employee and then invoke its "item(index)" method with
\r
251 // index equal to 6 (the number of nodes in the list). This
\r
252 // should cause the method to return null.
\r
254 // Semantic Requirements: 3
\r
256 //----------------------------------------------------------------------------
\r
259 public void core0005N()
\r
261 object computedValue = null;
\r
262 object expectedValue = null;
\r
263 System.Xml.XmlElement testNode = null;
\r
265 testResults results = new testResults("Core0005N");
\r
268 results.description = "The \"item(index)\" method returns null if the "+
\r
269 "index is greater than or equal to the number of "+
\r
270 "nodes (index = number of nodes).";
\r
272 // invoke the "item(index)" method with index equal to the number of nodes
\r
273 // in the list (6, count starts at zero). It should return null.
\r
275 testNode = (System.Xml.XmlElement)util.nodeObject(util.THIRD,-1);
\r
276 computedValue = util.getSubNodes(testNode).Item(util.SEVENTH);
\r
278 catch(System.Exception ex)
\r
280 computedValue = "Exception " + ex.Message;
\r
283 // Write out results
\r
285 results.expected = (expectedValue == null).ToString();
\r
286 results.actual = (computedValue == null).ToString();
\r
288 Assert.AreEqual (results.expected, results.actual);
\r
291 //------------------------ End test case core-0005N --------------------------
\r
293 //--------------------------- test case core-0006N ---------------------------
\r
295 // Testing feature - If the index is greater than or equal to number of
\r
296 // nodes, the "item(index)" method returns null.
\r
298 // Testing approach - Create a list of all the Element children of the third
\r
299 // employee and then invoke the "item(index)" with index
\r
300 // equal to 7 (index is greater than number of nodes).
\r
301 // This should cause the method to return null.
\r
303 // Semantic Requirements: 3
\r
305 //----------------------------------------------------------------------------
\r
308 public void core0006N()
\r
310 object computedValue = null;
\r
311 object expectedValue = null;
\r
312 System.Xml.XmlElement testNode = null;
\r
314 testResults results = new testResults("Core0006N");
\r
317 results.description = "The \"item(index)\" method returns null if the "+
\r
318 "index is greater than or equal to the number of "+
\r
319 "nodes (index > number of nodes).";
\r
321 // Retrieve targeted data. All counts start from zero
\r
323 testNode = (System.Xml.XmlElement)util.nodeObject(util.THIRD,-1);
\r
324 computedValue = util.getSubNodes(testNode).Item(util.EIGHT);
\r
326 catch(System.Exception ex)
\r
328 computedValue = "Exception " + ex.Message;
\r
331 // Write out results
\r
333 results.expected = (expectedValue == null).ToString();
\r
334 results.actual = (computedValue == null).ToString();
\r
336 Assert.AreEqual (results.expected, results.actual);
\r
339 //------------------------ End test case core-0006N --------------------------
\r
341 //--------------------------- test case core-0007N ---------------------------
\r
343 // Testing feature - The "length" attribute contains the number of items in
\r
346 // Testing approach - Create a list of all the Element children of the third
\r
347 // employee and then access the "length" attribute.
\r
348 // It should contain the value 6.
\r
350 // Semantic Requirements: 4
\r
352 //----------------------------------------------------------------------------
\r
355 public void core0007N()
\r
357 string computedValue = "0";
\r
358 string expectedValue = "6";
\r
359 //System.Xml.XmlNodeList thirdEmployeeList = null;
\r
361 testResults results = new testResults("Core0007N");
\r
364 results.description = "The \"length\" attribute contains the number of "+
\r
365 "nodes in the list (non empty list).";
\r
367 // retrieve the targeted data and access the "length" attribute.
\r
369 System.Xml.XmlElement testNode = (System.Xml.XmlElement)util.nodeObject(util.THIRD,-1);
\r
370 computedValue = util.getSubNodes(testNode).Count.ToString();
\r
372 catch(System.Exception ex)
\r
374 computedValue = "Exception " + ex.Message;
\r
377 // Write out results
\r
379 results.expected = expectedValue;
\r
380 results.actual = computedValue;
\r
382 Assert.AreEqual (results.expected, results.actual);
\r
385 //------------------------ End test case core-0007N --------------------------
\r
387 //--------------------------- test case core-0008N ---------------------------
\r
389 // Testing feature - The "length" attribute contains the number of items in
\r
390 // the list (test for empty list).
\r
392 // Testing approach - Create a list of all the children of the Text node
\r
393 // inside the first child o the third employee and
\r
394 // then access its "length" attribute. It should
\r
395 // contain the value 0.
\r
397 // Semantic Requirements: 4
\r
399 //----------------------------------------------------------------------------
\r
402 public void core0008N()
\r
404 string computedValue = "0";
\r
405 string expectedValue = "0";
\r
406 System.Xml.XmlNode testNode = null;
\r
407 System.Xml.XmlNode textNode = null;
\r
409 testResults results = new testResults("Core0008N");
\r
412 results.description = "The \"length\" attribute contains the number of "+
\r
413 "nodes in the list (test for empty list).";
\r
415 // Access the targeted data and examine the "length" attribute of an
\r
418 testNode = util.nodeObject(util.THIRD,util.FIRST);
\r
419 textNode = testNode.FirstChild;
\r
420 computedValue = textNode.ChildNodes.Count.ToString();
\r
422 catch(System.Exception ex)
\r
424 computedValue = "Exception " + ex.Message;
\r
427 // Write out results
\r
429 results.expected = expectedValue;
\r
430 results.actual = computedValue;
\r
432 Assert.AreEqual (results.expected, results.actual);
\r
435 //------------------------ End test case core-0008N --------------------------
\r
437 //--------------------------- test case core-0009 ---------------------------
\r
439 // Testing feature - The range of valid child nodes indices is 0 to length - 1.
\r
441 // Testing approach - Create a list of all the Element children of the
\r
442 // third employee and traverse the list from index
\r
443 // 0 to index length - 1.
\r
445 // Semantic Requirements: 5
\r
447 //----------------------------------------------------------------------------
\r
450 public void core0009N()
\r
452 string computedValue = "";
\r
453 string expectedValue = "employeeId name position salary gender address ";
\r
455 int listLength = 0;
\r
456 System.Xml.XmlElement testNode = null;
\r
458 testResults results = new testResults("Core0009N");
\r
461 results.description = "The range of valid child nodes indices is 0 to "+
\r
464 // Retrieve the targeted data and determine the length of the list.
\r
466 testNode = (System.Xml.XmlElement)util.nodeObject(util.THIRD,-1);
\r
467 listLength = util.getSubNodes(testNode).Count;
\r
468 lastIndex = listLength - 1;
\r
470 // Traverse the list from 0 to length - 1. All indices should be valid.
\r
472 for (int index = 0; index <= lastIndex; index++)
\r
473 computedValue += util.getSubNodes(testNode).Item(index).Name+" ";
\r
475 catch(System.Exception ex)
\r
477 computedValue = "Exception " + ex.Message;
\r
480 // Write out results.
\r
482 results.expected = expectedValue;
\r
483 results.actual = computedValue;
\r
485 Assert.AreEqual (results.expected, results.actual);
\r
488 //------------------------ End test case core-0009N --------------------------
\r