PageRenderTime 47ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/mcs/class/System.XML/Test/System.Xml/nist_dom/fundamental/NamedNodeMap/NamedNodeMap.cs

https://bitbucket.org/danipen/mono
C# | 1216 lines | 549 code | 121 blank | 546 comment | 11 complexity | 043562028c4db2de5868d93bc092913d MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. //**************************************************************************
  2. //
  3. //
  4. // National Institute Of Standards and Technology
  5. // DTS Version 1.0
  6. //
  7. // NamedNodeMap Interface
  8. //
  9. // Written by: Carmelo Montanez
  10. // Modified by: Mary Brady
  11. //
  12. // Ported to System.Xml by: Mizrahi Rafael rafim@mainsoft.com
  13. // Mainsoft Corporation (c) 2003-2004
  14. //**************************************************************************
  15. using System;
  16. using System.Xml;
  17. using nist_dom;
  18. using NUnit.Framework;
  19. namespace nist_dom.fundamental
  20. {
  21. [TestFixture]
  22. public class NamedNodeMapTest
  23. {
  24. public static int i = 2;
  25. /*
  26. public testResults[] RunTests()
  27. {
  28. testResults[] tests = new testResults[] {core0001M(), core0002M(), core0003M(),core0004M(),
  29. core0005M(), core0006M(), core0007M(), core0008M(),
  30. core0009M(), core0010M(), core0011M(),
  31. core0014M(), core0015M(), core0016M(),
  32. core0017M(), core0018M(), core0019M(), core0020M(),
  33. core0021M()};
  34. return tests;
  35. }
  36. */
  37. //------------------------ test case core-0001M ------------------------
  38. //
  39. // Testing feature - The "getNamedItem(name)" method retrieves a node
  40. // specified by name.
  41. //
  42. // Testing approach - Retrieve the second employee and create a NamedNodeMap
  43. // listing of the attributes of its last child. Once
  44. // the list is created an invocation of the
  45. // "getNamedItem(name)" method is done where
  46. // name = "domestic". This should result on the domestic
  47. // Attr node being returned.
  48. //
  49. // Semantic Requirements: 1
  50. //
  51. //----------------------------------------------------------------------------
  52. [Test]
  53. public void core0001M()
  54. {
  55. string computedValue = "";
  56. string expectedValue = "domestic";
  57. System.Xml.XmlAttribute domesticAttr = null;
  58. System.Xml.XmlNode testNode = null;
  59. testResults results = new testResults("Core0001M");
  60. try
  61. {
  62. results.description = "The \"getNamedItem(name)\" method retrieves a node " +
  63. "specified by name.";
  64. //
  65. // Retrieve targeted data.
  66. //
  67. testNode = util.nodeObject(util.SECOND,util.SIXTH);
  68. domesticAttr = (System.Xml.XmlAttribute)testNode.Attributes.GetNamedItem("domestic");
  69. computedValue = domesticAttr.Name;
  70. }
  71. catch(System.Exception ex)
  72. {
  73. computedValue = "Exception " + ex.Message;
  74. }
  75. //
  76. // Write out results
  77. //
  78. results.expected = expectedValue;
  79. results.actual = computedValue;
  80. Assert.AreEqual (results.expected, results.actual);
  81. }
  82. //------------------------ End test case core-0001M --------------------------
  83. //
  84. //--------------------------- test case core-0002M ---------------------------
  85. //
  86. // Testing feature - The "getNamedItem(name)" method returns a node of any
  87. // type specified by name.
  88. //
  89. // Testing approach - Retrieve the second employee and create a NamedNodeMap
  90. // listing of the attributes of its last child. Once
  91. // the list is created an invocation of the
  92. // "getNamedItem(name)" method is done where
  93. // name = "street". This should cause the method to return
  94. // an Attr node.
  95. //
  96. // Semantic Requirements: 2
  97. //
  98. //----------------------------------------------------------------------------
  99. [Test]
  100. public void core0002M()
  101. {
  102. string computedValue = "";
  103. string expectedValue = "street";
  104. System.Xml.XmlAttribute streetAttr = null;
  105. System.Xml.XmlNode testNode = null;
  106. testResults results = new testResults("Core0002M");
  107. try
  108. {
  109. results.description = "The \"getNamedItem(name)\" method returns a node "+
  110. "of any type specified by name (test for Attr node).";
  111. //
  112. // Retrieve targeted data and get its attributes.
  113. //
  114. testNode = util.nodeObject(util.SECOND,util.SIXTH);
  115. streetAttr = (System.Xml.XmlAttribute)testNode.Attributes.GetNamedItem("street");
  116. computedValue = streetAttr.Name;
  117. }
  118. catch(System.Exception ex)
  119. {
  120. computedValue = "Exception " + ex.Message;
  121. }
  122. //
  123. // Write out results
  124. //
  125. results.expected = expectedValue;
  126. results.actual = computedValue;
  127. Assert.AreEqual (results.expected, results.actual);
  128. }
  129. //------------------------ End test case core-0002M --------------------------
  130. //
  131. //--------------------------- test case core-0003M ---------------------------
  132. //
  133. // Testing feature - The "getNamedItem(name)" method returns null if the
  134. // specified name did not identify any node in the map.
  135. //
  136. // Testing approach - Retrieve the second employee and create a NamedNodeMap
  137. // listing of the attributes of its last child. Once
  138. // the list is created an invocation of the
  139. // "getNamedItem(name)" method is done where
  140. // name = "district", this name does not match any names
  141. // in the list and the method should return null.
  142. //
  143. // Semantic Requirements: 3
  144. //
  145. //----------------------------------------------------------------------------
  146. [Test]
  147. public void core0003M()
  148. {
  149. object computedValue = null;
  150. object expectedValue = null;
  151. System.Xml.XmlNode testNode = null;
  152. testResults results = new testResults("Core0003M");
  153. try
  154. {
  155. results.description = "The \"getNamedItem(name)\" method returns null if the " +
  156. "specified name did not identify any node in the map.";
  157. //
  158. // Retrieve targeted data and attempt to get a non-existing attribute.
  159. //
  160. testNode = util.nodeObject(util.SECOND,util.SIXTH);
  161. computedValue = testNode.Attributes.GetNamedItem("district");
  162. }
  163. catch(System.Exception ex)
  164. {
  165. computedValue = "Exception " + ex.Message;
  166. }
  167. //
  168. // Write out results
  169. //
  170. results.expected = (expectedValue == null).ToString();
  171. results.actual = (computedValue == null).ToString();
  172. Assert.AreEqual (results.expected, results.actual);
  173. }
  174. //------------------------ End test case core-0003M --------------------------
  175. //
  176. //--------------------------- test case core-0004M ---------------------------
  177. //
  178. // Testing feature - The "setNamedItem(arg)" method adds a node using its
  179. // nodeName attribute.
  180. //
  181. // Testing approach - Retrieve the second employee and create a NamedNodeMap
  182. // object from the attributes in its last child
  183. // by invoking the "attributes" attribute. Once the
  184. // list is created, the "setNamedItem(arg)" method is
  185. // invoked with arg = newAttr, where newAttr is a new
  186. // Attr Node previously created. The "setNamedItem(arg)"
  187. // method should add the new node to the NamedNodeItem
  188. // object by using its "nodeName" attribute ("district"
  189. // in this case). Further this node is retrieved by using
  190. // the "getNamedItem(name)" method. This test uses the
  191. // "createAttribute(name)" method from the Document
  192. // interface.
  193. //
  194. // Semantic Requirements: 4
  195. //
  196. //----------------------------------------------------------------------------
  197. [Test]
  198. public void core0004M()
  199. {
  200. string computedValue = "";
  201. string expectedValue = "district";
  202. System.Xml.XmlAttribute districtAttr = null;
  203. System.Xml.XmlAttribute newAttr = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");
  204. System.Xml.XmlNode testNode = null;
  205. testResults results = new testResults("Core0004M");
  206. try
  207. {
  208. results.description = "The \"setNamedItem(arg)\" method adds a node "+
  209. "using its nodeName attribute.";
  210. //
  211. // Retrieve targeted data and add new attribute.
  212. //
  213. testNode = util.nodeObject(util.SECOND,util.SIXTH);
  214. testNode.Attributes.SetNamedItem(newAttr);
  215. districtAttr = (System.Xml.XmlAttribute)testNode.Attributes.GetNamedItem("district");
  216. computedValue = districtAttr.Name;
  217. }
  218. catch(System.Exception ex)
  219. {
  220. computedValue = "Exception " + ex.Message;
  221. }
  222. //
  223. // Write out results
  224. //
  225. results.expected = expectedValue;
  226. results.actual = computedValue;
  227. util.resetData();
  228. Assert.AreEqual (results.expected, results.actual);
  229. }
  230. //------------------------ End test case core-0004M --------------------------
  231. //
  232. //--------------------------- test case core-0005 ---------------------------
  233. //
  234. // Testing feature - If the node to be added by the "setNamedItem(arg)" method
  235. // already exists in the NamedNodeMap, it is replaced by the
  236. // new one.
  237. //
  238. // Testing approach - Retrieve the second employee and create a NamedNodeMap
  239. // object from the attributes in its last child. Once
  240. // the list is created, the "setNamedItem(arg) method is
  241. // invoked with arg = newAttr, where newAttr is a Node Attr
  242. // previously created and whose node name already exist
  243. // in the map. The "setNamedItem(arg)" method should
  244. // replace the already existing node with the new one.
  245. // Further this node is retrieved by using the
  246. // "getNamedItem(name)" method. This test uses the
  247. // "createAttribute(name)" method from the Document
  248. // interface.
  249. //
  250. // Semantic Requirements: 5
  251. //
  252. //----------------------------------------------------------------------------
  253. [Test]
  254. public void core0005M()
  255. {
  256. string computedValue = "";
  257. string expectedValue = "";
  258. System.Xml.XmlAttribute streetAttr = null;
  259. System.Xml.XmlAttribute newAttr = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"street");
  260. System.Xml.XmlNode testNode = null;
  261. testResults results = new testResults("Core0005M");
  262. try
  263. {
  264. results.description = "If the node to be replaced by the \"setNamedItem(arg)\" " +
  265. "method is already in the list, the existing node should " +
  266. "be replaced by the new one.";
  267. //
  268. // Retrieve targeted data and add new attribute with name matching an
  269. // already existing attribute.
  270. //
  271. testNode = util.nodeObject(util.SECOND,util.SIXTH);
  272. testNode.Attributes.SetNamedItem(newAttr);
  273. streetAttr = (System.Xml.XmlAttribute)testNode.Attributes.GetNamedItem("street");
  274. computedValue = streetAttr.Value;
  275. }
  276. catch(System.Exception ex)
  277. {
  278. computedValue = "Exception " + ex.Message;
  279. }
  280. //
  281. // Write out results
  282. //
  283. results.expected = expectedValue;
  284. results.actual = computedValue;
  285. util.resetData();
  286. Assert.AreEqual (results.expected, results.actual);
  287. }
  288. //------------------------ End test case core-0005M --------------------------
  289. //
  290. //--------------------------- test case core-0006 ---------------------------
  291. //
  292. // Testing feature - If the "setNamedItem(arg)" method replaces an already
  293. // existing node with the same name then the already existing
  294. // node is returned.
  295. //
  296. // Testing approach - Retrieve the third employee and create a "NamedNodeMap"
  297. // object of the attributes in its last child by
  298. // invoking the "attributes" attribute. Once the
  299. // list is created, the "setNamedItem(arg) method is
  300. // invoked with arg = newAttr, where newAttr is a Node Attr
  301. // previously created and whose node name already exist
  302. // in the map. The "setNamedItem(arg)" method should replace
  303. // the already existing node with the new one and return
  304. // the existing node. Further this node is retrieved by
  305. // using the "getNamedItem(name)" method. This test
  306. // uses the "createAttribute(name)" method from the Document
  307. // interface.
  308. //
  309. // Semantic Requirements: 6
  310. //
  311. //----------------------------------------------------------------------------
  312. [Test]
  313. public void core0006M()
  314. {
  315. string computedValue = "";
  316. string expectedValue = "No";
  317. System.Xml.XmlNode returnedNode = null;
  318. System.Xml.XmlAttribute newAttr = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"street");
  319. System.Xml.XmlNode testNode = null;
  320. testResults results = new testResults("Core0006M");
  321. try
  322. {
  323. results.description = "If the \"setNamedItem(arg)\" method replaces an "+
  324. "already existing node with the same name then it "+
  325. "returns the already existing node.";
  326. //
  327. // Retrieve targeted data and examine value returned by the setNamedItem
  328. // method.
  329. //
  330. testNode = util.nodeObject(util.THIRD,util.SIXTH);
  331. returnedNode = testNode.Attributes.SetNamedItem(newAttr);
  332. computedValue = returnedNode.Value;
  333. }
  334. catch(System.Exception ex)
  335. {
  336. computedValue = "Exception " + ex.Message;
  337. }
  338. //
  339. // Write out results
  340. //
  341. results.expected = expectedValue;
  342. results.actual = computedValue;
  343. util.resetData();
  344. Assert.AreEqual (results.expected, results.actual);
  345. }
  346. //------------------------ End test case core-0006M --------------------------
  347. //
  348. //--------------------------- test case core-0007 ---------------------------
  349. //
  350. // Testing feature - The "setNamedItem(arg)" method replace an
  351. // already existing node with the same name. If a node with
  352. // that name is already present in the collection,
  353. // it is replaced by the new one.
  354. //
  355. // Testing approach - Retrieve the third employee and create a NamedNodeMap
  356. // object from the attributes in its last child.
  357. // Once the list is created, the "setNamedItem(arg)"
  358. // method is invoked with arg = newAttr, where newAttr is
  359. // a new previously created Attr node The
  360. // "setNamedItem(arg)" method should add the new node
  361. // and return the new one. Further this node is retrieved by
  362. // using the "getNamedItem(name)" method. This test
  363. // uses the "createAttribute(name)" method from the
  364. // Document interface.
  365. //
  366. // Semantic Requirements: 7
  367. //
  368. //----------------------------------------------------------------------------
  369. [Test]
  370. public void core0007M()
  371. {
  372. string computedValue = "";
  373. string expectedValue = "district";
  374. System.Xml.XmlAttribute newAttr = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");
  375. System.Xml.XmlNode testNode = null;
  376. testResults results = new testResults("Core0007M");
  377. try
  378. {
  379. results.description = "If a node with that name is already present in the collection. The \"setNamedItem(arg)\" method is replacing it by the new one";
  380. //
  381. // Retrieve targeted data and set new attribute.
  382. //
  383. testNode = util.nodeObject(util.THIRD,util.SIXTH);
  384. computedValue = testNode.Attributes.SetNamedItem(newAttr).Name;
  385. }
  386. catch(System.Exception ex)
  387. {
  388. computedValue = "Exception " + ex.Message;
  389. }
  390. //
  391. // Write out results
  392. //
  393. results.expected = expectedValue;
  394. results.actual = computedValue;
  395. util.resetData();
  396. Assert.AreEqual (results.expected, results.actual);
  397. }
  398. //------------------------ End test case core-0007M --------------------------
  399. //
  400. //--------------------------- test case core-0008 ----------------------------
  401. //
  402. // Testing feature - The "removeNamedItem(name)" method removes a node
  403. // specified by name.
  404. //
  405. // Testing approach - Retrieve the third employee and create a NamedNodeMap
  406. // object from the attributes in its last child. Once
  407. // the list is created, the "removeNamedItem(name)"
  408. // method is invoked where "name" is the name of an
  409. // existing attribute. The "removeNamedItem(name)" method
  410. // should remove the specified attribute and its "specified"
  411. // attribute (since this is an Attr node) should be set
  412. // to false.
  413. //
  414. // Semantic Requirements: 8
  415. //
  416. //----------------------------------------------------------------------------
  417. [Test]
  418. public void core0008M()
  419. {
  420. string computedValue = "";
  421. string expectedValue = "False";
  422. System.Xml.XmlNode testNode = null;
  423. System.Xml.XmlAttribute Attr = null;
  424. testResults results = new testResults("Core0008M");
  425. try
  426. {
  427. results.description = "The \"removeNamedItem(name)\" method removes "+
  428. "a node specified by name.";
  429. //
  430. // Retrive targeted data and and remove attribute. It should no longer
  431. // be specified.
  432. //
  433. testNode = (System.Xml.XmlNode)util.nodeObject(util.THIRD,util.SIXTH);
  434. testNode.Attributes.RemoveNamedItem("street");
  435. Attr = (System.Xml.XmlAttribute)testNode.Attributes.GetNamedItem("street");
  436. computedValue = Attr.Specified.ToString();
  437. }
  438. catch(System.Exception ex)
  439. {
  440. computedValue = "Exception " + ex.Message;
  441. }
  442. //
  443. // Write out results
  444. //
  445. results.expected = expectedValue;
  446. results.actual = computedValue;
  447. util.resetData();
  448. Assert.AreEqual (results.expected, results.actual);
  449. }
  450. //------------------------ End test case core-0008M --------------------------
  451. //
  452. //--------------------------- test case core-0009 ----------------------------
  453. //
  454. // Testing feature - If the node removed by the "removeNamedItem(name)" method
  455. // is an Attr node with a default value, its is immediately
  456. // replaced.
  457. //
  458. // Testing approach - Retrieve the third employee and create a NamedNodeMap
  459. // object from the attributes in its last child. Once
  460. // the list is created, the "removeNamedItem(name)" method
  461. // is invoked where "name" is the name of an existing
  462. // attribute ("street)". The "removeNamedItem(name)" method
  463. // should remove the "street" attribute and since it has
  464. // a default value of "Yes", that value should immediately
  465. // be the attribute's value.
  466. //
  467. // Semantic Requirements: 9
  468. //
  469. //----------------------------------------------------------------------------
  470. [Test]
  471. #if NET_2_0
  472. [Category ("NotDotNet")]
  473. #endif
  474. public void core0009M()
  475. {
  476. string computedValue = "";
  477. string expectedValue = "Yes";
  478. System.Xml.XmlNode testNode = null;
  479. testResults results = new testResults("Core0009M");
  480. try
  481. {
  482. results.description = "If the node removed by the \"removeNamedItem(name)\" "+
  483. "method is an Attr node with a default value, then "+
  484. "it is immediately replaced.";
  485. //
  486. // Retrieve targeted data and remove attribute.
  487. //
  488. testNode = util.nodeObject(util.THIRD,util.SIXTH);
  489. testNode.Attributes.RemoveNamedItem("street");
  490. computedValue = testNode.Attributes.GetNamedItem("street").Value;
  491. }
  492. catch(System.Exception ex)
  493. {
  494. computedValue = "Exception " + ex.Message;
  495. }
  496. //
  497. // Write out results
  498. //
  499. results.expected = expectedValue;
  500. results.actual = computedValue;
  501. util.resetData();
  502. Assert.AreEqual (results.expected, results.actual);
  503. }
  504. //------------------------ End test case core-0009M --------------------------
  505. //
  506. //--------------------------- test case core-0010M ---------------------------
  507. //
  508. // Testing feature - The "removeNamedItem(name)" method returns the node removed
  509. // from the map.
  510. //
  511. // Testing approach - Retrieve the third employee and create a NamedNodeMap
  512. // object from the attributes in its last child.
  513. // Once the list is created, the "removeNamedItem(name)"
  514. // method is invoked where "name" is the name of an existing
  515. // attribute ("street)". The "removeNamedItem(name)"
  516. // method should remove the existing "street" attribute
  517. // and return it.
  518. //
  519. // Semantic Requirements: 10
  520. //
  521. //----------------------------------------------------------------------------
  522. [Test]
  523. public void core0010M()
  524. {
  525. string computedValue = "";
  526. string expectedValue = "No";
  527. System.Xml.XmlNode returnedNode = null;
  528. System.Xml.XmlNode testNode = null;
  529. testResults results = new testResults("Core0010M");
  530. try
  531. {
  532. results.description = "The \"removeNamedItem(name)\" method returns the "+
  533. "node removed from the map.";
  534. //
  535. // Retrieve targeted data, remove attribute and examine returned value of
  536. // removeNamedItem method.
  537. //
  538. testNode = util.nodeObject(util.THIRD,util.SIXTH);
  539. returnedNode = testNode.Attributes.RemoveNamedItem("street");
  540. computedValue = returnedNode.Value;
  541. }
  542. catch(System.Exception ex)
  543. {
  544. computedValue = "Exception " + ex.Message;
  545. }
  546. //
  547. // Write out results
  548. //
  549. results.expected = expectedValue;
  550. results.actual = computedValue;
  551. util.resetData();
  552. Assert.AreEqual (results.expected, results.actual);
  553. }
  554. //------------------------ End test case core-0010M --------------------------
  555. //
  556. //--------------------------- test case core-0011M ---------------------------
  557. //
  558. // Testing feature - The "removeNamedItem(name)" method returns null if the
  559. // name specified does not exists in the map.
  560. //
  561. // Testing approach - Retrieve the third employee and create a NamedNodeMap
  562. // object from the attributes in its last child.
  563. // Once the list is created, the "removeNamedItem(name)"
  564. // method is invoked where "name" does not exist in the
  565. // map. The method should return null.
  566. //
  567. // Semantic Requirements: 11
  568. //
  569. //----------------------------------------------------------------------------
  570. [Test]
  571. public void core0011M()
  572. {
  573. object computedValue = null;
  574. object expectedValue = null;
  575. System.Xml.XmlNode testNode = null;
  576. testResults results = new testResults("Core0011M");
  577. try
  578. {
  579. results.description = "The \"removeNamedItem(name)\" method returns null "+
  580. "if the specified \"name\" is not in the map.";
  581. //
  582. // Retrieve targeted data and attempt to remove a non-existing attribute.
  583. //
  584. testNode = util.nodeObject(util.THIRD,util.SIXTH);
  585. computedValue = testNode.Attributes.RemoveNamedItem("district");
  586. }
  587. catch(System.Exception ex)
  588. {
  589. computedValue = "Exception " + ex.Message;
  590. }
  591. //
  592. // Write out results
  593. //
  594. results.expected = (expectedValue == null).ToString();
  595. results.actual = (computedValue == null).ToString();
  596. util.resetData();
  597. Assert.AreEqual (results.expected, results.actual);
  598. }
  599. //------------------------ End test case core-0011M --------------------------
  600. //
  601. //--------------------------- test case core-0012M ---------------------------
  602. //
  603. // Testing feature - The "item(index)" method returns the indexth item in the
  604. // map (test for first item).
  605. //
  606. // Testing approach - Retrieve the second employee and create a NamedNodeMap
  607. // object from the attributes in its last child by
  608. // by invoking the "attributes" attribute. Once
  609. // the list is created, the "item(index)" method is
  610. // invoked with index = 0. This should return the node at
  611. // the first position. Since there are no guarantees that
  612. // first item in the map is the one that was listed first
  613. // in the attribute list the test checks for all of them.
  614. //
  615. // Semantic Requirements: 12
  616. //
  617. //----------------------------------------------------------------------------
  618. [Test]
  619. public void core0012M()
  620. {
  621. //string testName = "core-0012M";
  622. string computedValue = "";
  623. // string expectedValue = "domestic or street";
  624. string expectedValue = "domestic";
  625. System.Xml.XmlNode returnedNode = null;
  626. System.Xml.XmlNode testNode = null;
  627. testResults results = new testResults("Core0012M");
  628. try
  629. {
  630. results.description = "Retrieve the first item in the map via the \"item(index)\" method.";
  631. //
  632. // Retrieve targeted data and invoke "item" method.
  633. //
  634. testNode = util.nodeObject(util.SECOND,util.SIXTH);
  635. returnedNode = testNode.Attributes.Item(0);
  636. computedValue = returnedNode.Name;
  637. }
  638. catch(System.Exception ex)
  639. {
  640. computedValue = "Exception " + ex.Message;
  641. }
  642. //
  643. // Write out results
  644. //
  645. results.expected = expectedValue;
  646. results.actual = computedValue;
  647. Assert.AreEqual (results.expected, results.actual);
  648. }
  649. //------------------------ End test case core-0012M --------------------------
  650. //
  651. //--------------------------- test case core-0013M ---------------------------
  652. //
  653. // Testing feature - The "item(index)" method returns the indexth item in the
  654. // map (test for last item).
  655. //
  656. // Testing approach - Retrieve the second employee and create a NamedNodeMap
  657. // object from the attributes in its last child.
  658. // Once the list is created, the "item(index)" method is
  659. // invoked with index = 1. This should return the node at
  660. // the last position. Since there are no guarantees that
  661. // the last item in the map is the one that was listed last
  662. // in the attribute list, the test checks for all of them.
  663. //
  664. // Semantic Requirements: 12
  665. //
  666. //----------------------------------------------------------------------------
  667. [Test]
  668. public void core0013M()
  669. {
  670. string computedValue = "";
  671. // string expectedValue = "domestic or street";
  672. string expectedValue = "street";
  673. System.Xml.XmlNode returnedNode = null;
  674. System.Xml.XmlNode testNode = null;
  675. testResults results = new testResults("Core0013M");
  676. try
  677. {
  678. results.description = "Retrieve the last item in the map via the \"item(index)\" method.";
  679. //
  680. // Retrieve targeted data and invoke "item" attribute.
  681. //
  682. testNode = util.nodeObject(util.THIRD,util.SIXTH);
  683. returnedNode = testNode.Attributes.Item(1);
  684. computedValue = returnedNode.Name;
  685. }
  686. catch(System.Exception ex)
  687. {
  688. computedValue = "Exception " + ex.Message;
  689. }
  690. //
  691. // Write out results
  692. //
  693. results.expected = expectedValue;
  694. results.actual = computedValue;
  695. Assert.AreEqual (results.expected, results.actual);
  696. }
  697. //------------------------ End test case core-0013M --------------------------
  698. //
  699. //--------------------------- test case core-0014M ---------------------------
  700. //
  701. // Testing feature - The "item(index)" method returns null if the index is
  702. // greater than the number of nodes in the map.
  703. //
  704. // Testing approach - Retrieve the second employee and create a NamedNodeMap
  705. // object from the attributes in its last child.
  706. // element by invoking the "attributes" attribute. Once
  707. // the list is created, the "item(index)" method is
  708. // invoked with index = 3. This index value is greater than
  709. // the number of nodes in the map and under that condition
  710. // the method should return null.
  711. //
  712. // Semantic Requirements: 13
  713. //
  714. //----------------------------------------------------------------------------
  715. [Test]
  716. public void core0014M()
  717. {
  718. object computedValue = null;
  719. object expectedValue = null;
  720. System.Xml.XmlNode testNode = null;
  721. testResults results = new testResults("Core0014M");
  722. try
  723. {
  724. results.description = "The \"item(index)\" method returns null if the "+
  725. "index is greater than the number of nodes in the map.";
  726. //
  727. // Retrieve targeted data and invoke "item" method.
  728. //
  729. testNode = util.nodeObject(util.THIRD,util.SIXTH);
  730. computedValue = testNode.Attributes.Item(3);
  731. }
  732. catch(System.Exception ex)
  733. {
  734. computedValue = "Exception " + ex.Message;
  735. }
  736. //
  737. // Write out results
  738. //
  739. results.expected = (expectedValue == null).ToString();
  740. results.actual = (computedValue == null).ToString();
  741. Assert.AreEqual (results.expected, results.actual);
  742. }
  743. //------------------------ End test case core-0014M --------------------------
  744. //
  745. //--------------------------- test case core-0015M ---------------------------
  746. //
  747. // Testing feature - The "item(index)" method returns null if the index is
  748. // equal to the number of nodes in the map.
  749. //
  750. // Testing approach - Retrieve the second employee and create a NamedNodeMap
  751. // object from the attributes in its last child
  752. // Once the list is created, the "item(index)" method is
  753. // invoked with index = 2. This index value is equal to
  754. // the number of nodes in the map and under that condition
  755. // the method should return null (first item is at position
  756. // 0).
  757. //
  758. // Semantic Requirements: 13
  759. //
  760. //----------------------------------------------------------------------------
  761. [Test]
  762. public void core0015M()
  763. {
  764. object computedValue = null;
  765. object expectedValue = null;
  766. System.Xml.XmlNode testNode = null;
  767. testResults results = new testResults("Core0015M");
  768. try
  769. {
  770. results.description = "The \"item(index)\" method returns null if the index " +
  771. "is equal to the number of nodes in the map.";
  772. //
  773. // Retrieve targeted data and invoke "item" method.
  774. //
  775. testNode = util.nodeObject(util.THIRD,util.SIXTH);
  776. computedValue = testNode.Attributes.Item(2);
  777. }
  778. catch(System.Exception ex)
  779. {
  780. computedValue = "Exception " + ex.Message;
  781. }
  782. //
  783. // Write out results
  784. //
  785. results.expected = (expectedValue == null).ToString();
  786. results.actual = (computedValue == null).ToString();
  787. Assert.AreEqual (results.expected, results.actual);
  788. }
  789. //------------------------ End test case core-0015M --------------------------
  790. //
  791. //--------------------------- test case core-0016M ---------------------------
  792. //
  793. // Testing feature - The "length" attribute contains the total number of
  794. // nodes in the map.
  795. //
  796. // Testing approach - Retrieve the second employee and create a NamedNodeMap
  797. // object from the attributes in its last child.
  798. // Once the list is created, the "length" attribute is
  799. // invoked. That attribute should contain the number 2.
  800. //
  801. // Semantic Requirements: 14
  802. //
  803. //----------------------------------------------------------------------------
  804. [Test]
  805. public void core0016M()
  806. {
  807. string computedValue = "";
  808. string expectedValue = "2";
  809. System.Xml.XmlNode testNode = null;
  810. testResults results = new testResults("Core0016M");
  811. try
  812. {
  813. results.description = "The \"length\" attribute contains the number of " +
  814. "nodes in the map.";
  815. //
  816. // Retrieve targeted data and invoke "length" attribute.
  817. //
  818. testNode = util.nodeObject(util.THIRD,util.SIXTH);
  819. computedValue = testNode.Attributes.Count.ToString();
  820. }
  821. catch(System.Exception ex)
  822. {
  823. computedValue = "Exception " + ex.Message;
  824. }
  825. //
  826. // Write out results
  827. //
  828. results.expected = expectedValue;
  829. results.actual = computedValue;
  830. Assert.AreEqual (results.expected, results.actual);
  831. }
  832. //------------------------ End test case core-0016M --------------------------
  833. //
  834. //--------------------------- test case core-0017M ---------------------------
  835. //
  836. // Testing feature - The range of valid child nodes indices is 0 to length - 1.
  837. //
  838. // Testing approach - Create a NamedNodeMap object from the attributes of the
  839. // last child of the third employee and traverse the
  840. // list from index 0 to index length - 1. All indices
  841. // should be valid.
  842. //
  843. // Semantic Requirements: 15
  844. //
  845. //----------------------------------------------------------------------------
  846. [Test]
  847. public void core0017M()
  848. {
  849. string computedValue = "";
  850. string expectedValue = "0 1 ";
  851. int lastIndex = 0;
  852. //string attributes = "";
  853. System.Xml.XmlNode testNode = null;
  854. testResults results = new testResults("Core0017M");
  855. try
  856. {
  857. results.description = "The range of valid child nodes indices is 0 to " +
  858. "length - 1.";
  859. //
  860. // Retrieve targeted data and compute list length.
  861. //
  862. testNode = util.nodeObject(util.THIRD,util.SIXTH);
  863. lastIndex = testNode.Attributes.Count - 1;
  864. //
  865. // Traverse the list from 0 to length - 1. All indices should be valid.
  866. //
  867. for (int index = 0;index <= lastIndex; index++)
  868. computedValue += index+" ";
  869. }
  870. catch(System.Exception ex)
  871. {
  872. computedValue = "Exception " + ex.Message;
  873. }
  874. //
  875. // Write out results.
  876. //
  877. results.expected = expectedValue;
  878. results.actual = computedValue;
  879. Assert.AreEqual (results.expected, results.actual);
  880. }
  881. //------------------------ End test case core-0017M --------------------------
  882. //
  883. //--------------------------- test case core-0018M ---------------------------
  884. //
  885. // Testing feature - The "setNamedItem(arg) method raises a System.ArgumentException
  886. // Exception if "arg" was created from a different
  887. // document than the one that created the NamedNodeMap.
  888. //
  889. // Testing approach - Create a NamedNodeMap object from the attributes of the
  890. // last child of the third employee and attempt to
  891. // add another Attr node to it that was created from a
  892. // different DOM document. This condition should raise
  893. // the desired exception. This method uses the
  894. // "createAttribute(name)" method from the Document
  895. // interface.
  896. //
  897. // Semantic Requirements: 16
  898. //
  899. //----------------------------------------------------------------------------
  900. [Test]
  901. [Category ("NotDotNet")] // MS DOM is buggy
  902. public void core0018M()
  903. {
  904. string computedValue = "";
  905. System.Xml.XmlAttribute newAttrNode = util.getOtherDOMDocument().CreateAttribute("newAttribute");
  906. System.Xml.XmlNode testNode = null;
  907. string expectedValue = "System.ArgumentException";
  908. testResults results = new testResults("Core0018M");
  909. results.description = "The \"setNamedItem(arg)\" method raises a "+
  910. "System.ArgumentException Exception if \"arg\" was " +
  911. "created from a document different from the one that created "+
  912. "the NamedNodeList.";
  913. //
  914. // Retrieve targeted data and attempt to add an element that was created
  915. // from a different document. Should raise an exception.
  916. //
  917. testNode = util.nodeObject(util.THIRD,util.SIXTH);
  918. try
  919. {
  920. testNode.Attributes.SetNamedItem(newAttrNode);
  921. }
  922. catch(System.Exception ex)
  923. {
  924. computedValue = ex.GetType().ToString();
  925. }
  926. results.expected = expectedValue;
  927. results.actual = computedValue;
  928. util.resetData();
  929. Assert.AreEqual (results.expected, results.actual);
  930. }
  931. //------------------------ End test case core-0018M --------------------------
  932. //
  933. //--------------------------- test case core-0019M ---------------------------
  934. //
  935. // Testing feature - The "setNamedItem(arg) method raises a
  936. // NO_MODIFICATION_ALLOWED_ERR Exception if this
  937. // NamedNodeMap is readonly.
  938. //
  939. // Testing approach - Create a NamedNodeMap object from the first child of the
  940. // Entity named "ent4" inside the DocType node and then
  941. // attempt to add a new item to the list. It should raise
  942. // the desired exception as this is a readonly NamedNodeMap.
  943. //
  944. // Semantic Requirements: 17
  945. //
  946. //----------------------------------------------------------------------------
  947. [Test]
  948. [Category ("NotDotNet")] // MS DOM is buggy
  949. public void core0019M()
  950. {
  951. string computedValue = "";
  952. System.Xml.XmlNode testNode = null;
  953. System.Xml.XmlNode entityDesc;
  954. System.Xml.XmlAttribute newAttrNode = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"newAttribute");
  955. string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;
  956. testResults results = new testResults("Core0019M");
  957. results.description = "The \"setNamedItem(arg)\" method raises a " +
  958. "NO_MODIFICATION_ALLOWED_ERR Exception if this "+
  959. "NamedNodeMap is readonly.";
  960. //
  961. // Create a NamedNodeMap object and attempt to add a node to it.
  962. // Should raise an exception.
  963. //
  964. testNode = util.getEntity("ent4");
  965. entityDesc = testNode.FirstChild;
  966. try
  967. {
  968. entityDesc.Attributes.SetNamedItem(newAttrNode);
  969. }
  970. catch(ArgumentException ex)
  971. {
  972. computedValue = ex.GetType ().FullName;
  973. }
  974. results.expected = expectedValue;
  975. results.actual = computedValue;
  976. util.resetData();
  977. Assert.AreEqual (results.expected, results.actual);
  978. }
  979. //------------------------ End test case core-0019M --------------------------
  980. //
  981. //--------------------------- test case core-0020M ---------------------------
  982. //
  983. // Testing feature - The "setNamedItem(arg) method raises an
  984. // INUSE_ATTRIBUTE_ERR Exception if "arg" is an Attr
  985. // that is already an attribute of another Element.
  986. //
  987. // Testing approach - Create a NamedNodeMap object from the attributes of the
  988. // third child and attempt to add an attribute that is
  989. // already being used by the first employee. An attempt
  990. // to add such an attribute should raise the desired
  991. // exception.
  992. //
  993. // Semantic Requirements: 18
  994. //
  995. //----------------------------------------------------------------------------
  996. [Test]
  997. [Category ("NotDotNet")]
  998. public void core0020M()
  999. {
  1000. string computedValue= "";
  1001. System.Xml.XmlAttribute inUseAttribute = null;
  1002. System.Xml.XmlElement firstEmployee = null;
  1003. System.Xml.XmlNode testNode = null;
  1004. string expectedValue = "System.ArgumentException";//util.INUSE_ATTRIBUTE_ERR;
  1005. testResults results = new testResults("Core0020M");
  1006. try
  1007. {
  1008. results.description = "The \"setNamedItem(arg)\" method raises an "+
  1009. "INUSE_ATTRIBUTE_ERR Exception if \"arg\" "+
  1010. "is an Attr node that is already an attribute "+
  1011. "of another Element.";
  1012. firstEmployee = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);
  1013. inUseAttribute = firstEmployee.GetAttributeNode("domestic");
  1014. //
  1015. // Attempt to add an attribute that is already used by another element
  1016. // should raise an exception.
  1017. //
  1018. testNode = util.nodeObject(util.THIRD,util.SIXTH);
  1019. try
  1020. {
  1021. testNode.Attributes.SetNamedItem(inUseAttribute);
  1022. }
  1023. catch (System.Exception ex)
  1024. {
  1025. computedValue = ex.GetType ().FullName;
  1026. }
  1027. }
  1028. catch(System.Exception ex)
  1029. {
  1030. computedValue = "Exception " + ex.Message;
  1031. }
  1032. results.expected = expectedValue;
  1033. results.actual = computedValue;
  1034. util.resetData();
  1035. Assert.AreEqual (results.expected, results.actual);
  1036. }
  1037. //------------------------ End test case core-0020M --------------------------
  1038. //
  1039. //--------------------------- test case core-0021M ---------------------------
  1040. //
  1041. // Testing feature - The "removeNamedItem(name) method raises an
  1042. // NOT_FOUND_ERR Exception if there is no node

Large files files are truncated, but you can click here to view the full file