PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://bitbucket.org/danipen/mono
C# | 1851 lines | 824 code | 160 blank | 867 comment | 7 complexity | abe0edf2535d46276f94713d9e9a94de 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. // Element 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 ElementTest
  23. {
  24. public static int i = 2;
  25. /*
  26. public testResults[] RunTests()
  27. {
  28. testResults[] tests = new testResults[] {core0001E(), core0002E(), core0003E(),core0004E(),
  29. core0005E(), core0006E(), core0007E(), core0008E(),
  30. core0009E(), core0010E(), core0011E(), core0012E(),
  31. core0013E(), core0014E(), core0015E(), core0016E(),
  32. core0017E(), core0018E(), core0019E(), core0020E(),
  33. core0021E(), core0022E(), core0023E(), core0024E(),
  34. core0025E(), core0026E(), core0027E(), core0028E(),
  35. core0029E(), core0030E()};
  36. return tests;
  37. }
  38. */
  39. //------------------------ test case core-0001E ------------------------
  40. //
  41. // Testing feature - Elements may have attributes associated with them.
  42. //
  43. // Testing approach - Retrieve the first attribute from the last child of
  44. // the first employee and examine its "specified"
  45. // attribute. This test is only intended to show
  46. // that Elements can actually have attributes.
  47. // This test uses the "getNamedItem(name)" method from
  48. // the NamedNodeMap interface.
  49. //
  50. // Semantic Requirements: 1
  51. //
  52. //----------------------------------------------------------------------------
  53. [Test]
  54. public void core0001E()
  55. {
  56. string computedValue = "0";//0
  57. string expectedValue = "True";//true
  58. System.Xml.XmlNode addressElement = null;
  59. System.Xml.XmlAttributeCollection attrList = null;
  60. System.Xml.XmlAttribute domesticAttr = null;
  61. testResults results = new testResults("Core0001E");
  62. try
  63. {
  64. results.description = "Element nodes may have associated attributes.";
  65. //
  66. // Retrieve the "address" element from the first employee.
  67. //
  68. addressElement = util.nodeObject(util.FIRST,util.SIXTH);
  69. //
  70. // Access its "domestic" attribute by creating a list of all attributes
  71. // and then retrieving the desired attribute from the list by name.
  72. //
  73. attrList = addressElement.Attributes;//.node.
  74. domesticAttr = (System.Xml.XmlAttribute)attrList.GetNamedItem("domestic");
  75. //
  76. // Access its "specified" attribute.
  77. //
  78. computedValue = domesticAttr.Specified.ToString();
  79. }
  80. catch(System.Exception ex)
  81. {
  82. computedValue = "Exception " + ex.Message;
  83. }
  84. //
  85. // Write out results
  86. //
  87. results.expected = expectedValue;
  88. results.actual = computedValue;
  89. Assert.AreEqual (results.expected, results.actual);
  90. }
  91. //------------------------ End test case core-0001E --------------------------
  92. //
  93. //------------------------ test case core-0002E ------------------------
  94. //
  95. // Testing feature - The generic Attribute "attributes" (Node interface) may
  96. // be used to retrieve the set of all attributes of an
  97. // element.
  98. //
  99. // Testing approach - Create a list of all the attributes of the last child of
  100. // of the first employee by using the generic "attributes"
  101. // attribute from the Node interface. Further the length
  102. // of the attribute list is examined. This test makes
  103. // use of the "Count" attribute from the NameNodeMap
  104. // interface.
  105. //
  106. // Semantic Requirements: 1, 2
  107. //
  108. //----------------------------------------------------------------------------
  109. [Test]
  110. [Category ("NotDotNet")] // MS DOM is buggy
  111. public void core0002E()
  112. {
  113. string computedValue = "";
  114. string expectedValue = "2";
  115. System.Xml.XmlNode addressElement = null;
  116. System.Xml.XmlAttributeCollection attrList = null;
  117. testResults results = new testResults("Core0002E");
  118. try
  119. {
  120. results.description = "The generic \"attributes\" (from the Node interface) may " +
  121. "be used to retrieve the set of all attributes of an element.";
  122. //
  123. // Retrieve the "address" element from the first employee.
  124. //
  125. addressElement = util.nodeObject(util.FIRST,util.SIXTH);
  126. //
  127. // Access its attributes list.
  128. //
  129. attrList = addressElement.Attributes;
  130. //
  131. // Access its "length" attribute.
  132. //
  133. computedValue = attrList.Count.ToString();
  134. }
  135. catch(System.Exception ex)
  136. {
  137. computedValue = "Exception " + ex.Message;
  138. }
  139. //
  140. // Write out results
  141. //
  142. results.expected = expectedValue;
  143. results.actual = computedValue;
  144. Assert.AreEqual (results.expected, results.actual);
  145. }
  146. //------------------------ End test case core-0002E --------------------------
  147. //
  148. //-------------------------- test case core-0003E ----------------------------
  149. //
  150. // Testing feature - The "tagName" attribute contains the name of the
  151. // element.
  152. //
  153. // Testing approach - Retrieve the third child of the second employee and
  154. // examine its "tagName" attribute. It should return a
  155. // string containing the name of the element ("position",
  156. // in this case).
  157. //
  158. // Semantic Requirements: 3
  159. //
  160. //----------------------------------------------------------------------------
  161. [Test]
  162. public void core0003E()
  163. {
  164. string computedValue = "";
  165. string expectedValue = "position";
  166. System.Xml.XmlNode positionElement = null;
  167. testResults results = new testResults("Core0003E");
  168. try
  169. {
  170. results.description = "The \"tagName\" of an Element contains the " +
  171. "element's name.";
  172. //
  173. // Access its third child of the second employee.
  174. //
  175. positionElement = util.nodeObject(util.SECOND,util.THIRD);
  176. //
  177. // Access its "tagName" attribute.
  178. //
  179. computedValue = positionElement.Name;//tagName;//.node.
  180. }
  181. catch(System.Exception ex)
  182. {
  183. computedValue = "Exception " + ex.Message;
  184. }
  185. //
  186. // Write out results
  187. //
  188. results.expected = expectedValue;
  189. results.actual = computedValue;
  190. Assert.AreEqual (results.expected, results.actual);
  191. }
  192. //------------------------ End test case core-0003E --------------------------
  193. //
  194. //-------------------------- test case core-0004E ----------------------------
  195. //
  196. // Testing feature - The "getAttribute(name)" method returns an attribute value
  197. // by name.
  198. //
  199. // Testing approach - Retrieve the the last child of the third employee, then
  200. // invoke its "getAttribute(name)" method. It should
  201. // return the value of the attribute("No", in this case).
  202. //
  203. // Semantic Requirements: 1, 4
  204. //
  205. //----------------------------------------------------------------------------
  206. [Test]
  207. public void core0004E()
  208. {
  209. string computedValue = "";
  210. string expectedValue = "No";
  211. System.Xml.XmlElement addressElement = null;
  212. testResults results = new testResults("Core0004E");
  213. try
  214. {
  215. results.description = "The \"getAttribute(name)\" method of an Element returns " +
  216. "the value of an attribute by name.";
  217. //
  218. // Retrieve the targeted data.
  219. //
  220. addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
  221. computedValue = addressElement.GetAttribute("street");//addressElement.node.GetAttribute("street");
  222. }
  223. catch(System.Exception ex)
  224. {
  225. computedValue = "Exception " + ex.Message;
  226. }
  227. //
  228. // Write out results
  229. //
  230. results.expected = expectedValue;
  231. results.actual = computedValue;
  232. Assert.AreEqual (results.expected, results.actual);
  233. }
  234. //------------------------ End test case core-0004E --------------------------
  235. //
  236. //-------------------------- test case core-0005E ----------------------------
  237. //
  238. // Testing feature - The "getAttribute(name)" method returns an empty
  239. // string if no value was assigned to an attribute and
  240. // no default value was given in the DTD file.
  241. //
  242. // Testing approach - Retrieve the the last child of the last employee, then
  243. // invoke its "getAttribute(name)" method, where "name" is an
  244. // attribute with no specified or DTD default value. The
  245. // "getAttribute(name)" method should return the empty
  246. // string. This method makes use of the
  247. // "createAttribute(newAttr)" method from the Document
  248. // interface.
  249. //
  250. // Semantic Requirements: 1, 4, 5
  251. //
  252. //----------------------------------------------------------------------------
  253. [Test]
  254. public void core0005E()
  255. {
  256. string computedValue = "";
  257. string expectedValue = "";
  258. System.Xml.XmlElement addressElement = null;
  259. System.Xml.XmlAttribute newAttribute = null;
  260. testResults results = new testResults("Core0005E");
  261. try
  262. {
  263. results.description = "The \"getAttribute(name)\" method of an Element returns " +
  264. "the empty string if the attribue does not have a default " +
  265. "or specified value.";
  266. //
  267. // Access the sixth child of the last employee.
  268. //
  269. newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");
  270. addressElement = (System.Xml.XmlElement)util.nodeObject(util.FOURTH,util.SIXTH);
  271. //
  272. // Invoke its "setAttributeNode(newAttr)" method where
  273. // newAttr = "newAttribute". Since no value was specified or given
  274. // by default, the value returned by the "getAttribute(name)" method
  275. // should be the empty string.
  276. //
  277. addressElement.SetAttributeNode(newAttribute);//.node.
  278. computedValue = addressElement.GetAttribute("district");//.node.
  279. }
  280. catch(System.Exception ex)
  281. {
  282. computedValue = "Exception " + ex.Message;
  283. }
  284. //
  285. // Write out results
  286. //
  287. results.expected = expectedValue;
  288. results.actual = computedValue;
  289. util.resetData();
  290. Assert.AreEqual (results.expected, results.actual);
  291. }
  292. //------------------------ End test case core-0005E --------------------------
  293. //
  294. //-------------------------- test case core-0006E ----------------------------
  295. //
  296. // Testing feature - The "setAttribute(name,value)" method adds a new attribute
  297. // to the Element.
  298. //
  299. // Testing approach - Retrieve the last child of the last employee, then
  300. // add an attribute to it by invoking its
  301. // "setAttribute(name,value)" method. It should create
  302. // a "name" attribute with an assigned value equal to
  303. // "value".
  304. //
  305. // Semantic Requirements: 1, 4, 6
  306. //
  307. //----------------------------------------------------------------------------
  308. [Test]
  309. public void core0006E()
  310. {
  311. string computedValue = "";
  312. System.Xml.XmlElement addressElement = null;
  313. string name = "district";
  314. string expectedValue = "dallas";
  315. testResults results = new testResults("Core0006E");
  316. try
  317. {
  318. results.description = "The \"setAttribute(name,value)\" method of an Element " +
  319. "creates an new \"name\" attribute whose value is equal to \"value\".";
  320. //
  321. // Access the last child of the last employee.
  322. //
  323. addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.SIXTH);
  324. //
  325. // Invoke its "setAttribute(name,value)" method and create a new attribute
  326. //
  327. addressElement.SetAttribute(name,expectedValue);//.node.
  328. //
  329. // This Element should now have a new attribute that we can be retrieved
  330. // by name.
  331. //
  332. computedValue = addressElement.GetAttribute(name);//.node.
  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-0006E --------------------------
  347. //
  348. //-------------------------- test case core-0007E ----------------------------
  349. //
  350. // Testing feature - The "setAttribute(name,value)" method adds a new attribute
  351. // to the Element. If the "name" is already present, then
  352. // its value should be changed to the new one of the
  353. // "value" parameter.
  354. //
  355. // Testing approach - Retrieve the last child of the fourth employee,
  356. // then add an attribute to it by invoking its
  357. // "setAttribute(name,value)" method. Since the name
  358. // of the used attribute ("street") is already present
  359. // in this element, then its value should be
  360. // changed to the new one of the "value" parameter.
  361. //
  362. // Semantic Requirements: 1, 4, 7
  363. //
  364. //----------------------------------------------------------------------------
  365. [Test]
  366. public void core0007E()
  367. {
  368. string computedValue = "";
  369. string expectedValue = "Neither";
  370. System.Xml.XmlElement addressElement = null;
  371. testResults results = new testResults("Core0007E");
  372. try
  373. {
  374. results.description = "The \"setAttribute(name,value)\" method of an Element " +
  375. "where the \"name\" attribute is already present in this Element.";
  376. //
  377. // Access the sixth child of the fourth employee.
  378. //
  379. addressElement = (System.Xml.XmlElement)util.nodeObject(util.FOURTH,util.SIXTH);
  380. //
  381. // Invoke its "setAttribute(name,value)" method where name = "street"
  382. // and value = "Neither".
  383. //
  384. addressElement.SetAttribute("street","Neither");//.node.
  385. //
  386. // The "street" attribute should now have a value of "Neither"
  387. //
  388. computedValue = addressElement.GetAttribute("street");//.node.
  389. }
  390. catch(System.Exception ex)
  391. {
  392. computedValue = "Exception " + ex.Message;
  393. }
  394. //
  395. // Write out results
  396. //
  397. results.expected = expectedValue;
  398. results.actual = computedValue;
  399. util.resetData();
  400. Assert.AreEqual (results.expected, results.actual);
  401. }
  402. //------------------------ End test case core-0007E --------------------------
  403. //
  404. //-------------------------- test case core-0008E ----------------------------
  405. //
  406. // Testing feature - The "removeAttribute(name)" removes an attribute
  407. // by name. If the removed attribute is known to have a
  408. // default value, an attribute immediately appears
  409. // containing the default value.
  410. //
  411. // Testing approach - Retrieve the attribute named "street" from the last
  412. // child of the fourth employee, then remove the "street"
  413. // attribute by invoking its "removeAttribute(name) method.
  414. // The "street" attribute has a default value defined in the
  415. // DTD file, that value should immediately replace the
  416. // old value.
  417. //
  418. // Semantic Requirements: 1, 8
  419. //
  420. //----------------------------------------------------------------------------
  421. [Test]
  422. #if NET_2_0
  423. [Category ("NotDotNet")]
  424. #endif
  425. public void core0008E()
  426. {
  427. string computedValue = "";
  428. string expectedValue = "Yes";
  429. System.Xml.XmlElement addressElement = null;
  430. string streetAttr = "";
  431. testResults results = new testResults("Core0008E");
  432. try
  433. {
  434. results.description = "The \"removeAttribute(name)\" method of an Element " +
  435. "removes the \"name\" attribute and restores any " +
  436. "known default values.";
  437. //
  438. // Access the last child of the fourth employee.
  439. //
  440. addressElement = (System.Xml.XmlElement)util.nodeObject(util.FOURTH,util.SIXTH);
  441. //
  442. // Invoke its "removeAttribute(name)" method where name = "street"
  443. //
  444. addressElement.RemoveAttribute("street");//.node.
  445. //
  446. // Now access that attribute.
  447. //
  448. streetAttr = addressElement.GetAttribute("street");//.node.
  449. //
  450. // The "street" attribute should now have a default values
  451. //
  452. computedValue = addressElement.GetAttribute("street");//.node.
  453. }
  454. catch(System.Exception ex)
  455. {
  456. computedValue = "Exception " + ex.Message;
  457. }
  458. //
  459. // Write out results
  460. //
  461. results.expected = expectedValue;
  462. results.actual = computedValue;
  463. util.resetData();
  464. Assert.AreEqual (results.expected, results.actual);
  465. }
  466. //------------------------ End test case core-0008E --------------------------
  467. //
  468. //-------------------------- test case core-0009E ----------------------------
  469. //
  470. // Testing feature - The "getAttributeNode(name)" retrieves an attribute
  471. // node by name.
  472. //
  473. // Testing approach - Retrieve the attribute named "domestic" from the last
  474. // child of the first employee. Since the method returns
  475. // an Attr object, its name attribute can be examined to
  476. // ensure the proper attribute was retrieved.
  477. //
  478. // Semantic Requirements: 1, 9
  479. //
  480. //----------------------------------------------------------------------------
  481. [Test]
  482. public void core0009E()
  483. {
  484. string computedValue = "";
  485. string expectedValue = "domestic";
  486. System.Xml.XmlElement addressElement = null;
  487. System.Xml.XmlAttribute domesticAttrNode = null;
  488. testResults results = new testResults("Core0009E");
  489. try
  490. {
  491. results.description = "The \"getAttributeNode(name)\" method of an Element " +
  492. "returns the \"name\" Attr node.";
  493. //
  494. // Access the last child of the first employee.
  495. //
  496. addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);
  497. //
  498. // Invoke its "getAttributeNode(name)" method where name = "domestic"
  499. // and create an Attr object.
  500. //
  501. domesticAttrNode = addressElement.GetAttributeNode("domestic");//.node.
  502. //
  503. // Now access the "name" attribute of that Attr node. Since the "domestic"
  504. // attribute was retrieved, the name of the Attr node should also be
  505. // "domestic".
  506. //
  507. computedValue = domesticAttrNode.Name;
  508. }
  509. catch(System.Exception ex)
  510. {
  511. computedValue = "Exception " + ex.Message;
  512. }
  513. //
  514. // Write out results
  515. //
  516. results.expected = expectedValue;
  517. results.actual = computedValue;
  518. Assert.AreEqual (results.expected, results.actual);
  519. }
  520. //------------------------ End test case core-0009E --------------------------
  521. //
  522. //-------------------------- test case core-00010E ----------------------------
  523. //
  524. // Testing feature - The "getAttributeNode(name)" retrieves an attribute
  525. // node by name. It should return null if the "name"
  526. // attribute does not exist.
  527. //
  528. // Testing approach - Retrieve the last child of the first employee and
  529. // attempt to retrieve a non-existing attribute.
  530. // The method should return null. The non-existing
  531. // attribute to be used is "invalidAttribute".
  532. //
  533. // Semantic Requirements: 1, 10
  534. //
  535. //----------------------------------------------------------------------------
  536. [Test]
  537. public void core0010E()
  538. {
  539. object computedValue = null;
  540. object expectedValue = null;
  541. System.Xml.XmlElement addressElement = null;
  542. testResults results = new testResults("Core0010E");
  543. try
  544. {
  545. results.description = "The \"getAttributeNode(name)\" method returns null " +
  546. "if the \"name\" attribute does not exist.";
  547. //
  548. // Access the last child of the first employee.
  549. //
  550. addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);
  551. //
  552. // Invoke its "getAttributeNode(name)" method where name = "invalidAttribute"
  553. // This should result in a null value being returned by the method.
  554. //
  555. computedValue = addressElement.GetAttributeNode("invalidAttribute");//.node.
  556. }
  557. catch(System.Exception ex)
  558. {
  559. computedValue = "Exception " + ex.Message;
  560. }
  561. //
  562. // Write out results
  563. //
  564. results.expected = (expectedValue == null).ToString();
  565. results.actual = (computedValue == null).ToString();
  566. Assert.AreEqual (results.expected, results.actual);
  567. }
  568. //------------------------ End test case core-0010E --------------------------
  569. //
  570. //-------------------------- test case core-0011E ----------------------------
  571. //
  572. // Testing feature - The "setAttributeNode(newAttr)" adds a new attribute
  573. // to the Element.
  574. //
  575. // Testing approach - Retrieve the last child of the first employee and
  576. // add a new attribute node to it by invoking its
  577. // "setAttributeNode(newAttr)" method. This test makes
  578. // use of the "createAttribute(name)" method from the
  579. // Document interface.
  580. //
  581. // Semantic Requirements: 1, 11
  582. //
  583. //----------------------------------------------------------------------------
  584. [Test]
  585. public void core0011E()
  586. {
  587. string computedValue = "";
  588. string expectedValue = "";
  589. System.Xml.XmlElement addressElement = null;
  590. System.Xml.XmlAttribute newAttribute = null;
  591. string name = "district";
  592. testResults results = new testResults("Core0011E");
  593. try
  594. {
  595. results.description = "The \"setAttributeNode(newAttr)\" method adds a new " +
  596. "attribute node to the element.";
  597. //
  598. // Access the last child of the first employee.
  599. //
  600. newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,name);
  601. addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);
  602. //
  603. // Invoke its "setAttributeNode(newAttr)" method where
  604. // newAttr = "newAttribute". Since no value was specified or given
  605. // by default, its value should be the empty string.
  606. //
  607. addressElement.SetAttributeNode(newAttribute);//.node.
  608. computedValue = addressElement.GetAttribute(name);//.node.
  609. }
  610. catch(System.Exception ex)
  611. {
  612. computedValue = "Exception " + ex.Message;
  613. }
  614. //
  615. // Write out results
  616. //
  617. results.expected = expectedValue;
  618. results.actual = computedValue;
  619. util.resetData();
  620. Assert.AreEqual (results.expected, results.actual);
  621. }
  622. //------------------------ End test case core-0011E --------------------------
  623. //
  624. //-------------------------- test case core-00012E ----------------------------
  625. //
  626. // Testing feature - The "setAttributeNode(newAttr)" method adds a new attribute
  627. // to the Element. If the "newAttr" Attr node is already
  628. // present in this element, it should replace the existing
  629. // one.
  630. //
  631. // Testing approach - Retrieve the last child of the third employee and
  632. // add a new attribute node to it by invoking its
  633. // "setAttributeNode(newAttr)" method. The new attribute
  634. // node to be added is "street", which is already
  635. // present in this element. The method should replace the
  636. // existing Attr node with the new one. This test make use
  637. // of the "createAttribute(name)" method from the Document
  638. // interface.
  639. //
  640. // Semantic Requirements: 1, 12
  641. //
  642. //----------------------------------------------------------------------------
  643. [Test]
  644. public void core0012E()
  645. {
  646. string computedValue = "";
  647. string expectedValue = "";
  648. System.Xml.XmlElement addressElement = null;
  649. System.Xml.XmlAttribute newAttribute = null;
  650. testResults results = new testResults("Core0012E");
  651. try
  652. {
  653. results.description = "The \"setAttributeNode(newAttr)\" method when " +
  654. "the \"newAttr\" node is already part of this " +
  655. "element. The existing attribute node should be "+
  656. "replaced with the new one.";
  657. //
  658. // Access the last child of the third employee.
  659. //
  660. newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"street");
  661. addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
  662. //
  663. // Invoke its "setAttributeNode(newAttr)" method where
  664. // newAttr = "newAttribute". That attribute is already part of this
  665. // element. The existing attribute should be replaced with the new one
  666. // (newAttribute).
  667. //
  668. addressElement.SetAttributeNode(newAttribute);//.node.
  669. computedValue = addressElement.GetAttribute("street");//.node.
  670. }
  671. catch(System.Exception ex)
  672. {
  673. computedValue = "Exception " + ex.Message;
  674. }
  675. //
  676. // Write out results
  677. //
  678. results.expected = expectedValue;
  679. results.actual = computedValue;
  680. util.resetData();
  681. Assert.AreEqual (results.expected, results.actual);
  682. }
  683. //------------------------ End test case core-0012E --------------------------
  684. //
  685. //-------------------------- test case core-00013E ----------------------------
  686. //
  687. // Testing feature - If The "setAttributeNode(newAttr)" method replaces
  688. // an existing Attr node with the same name, then it
  689. // should return the previously existing Attr node.
  690. //
  691. // Testing approach - Retrieve the last child of the third employee and add
  692. // a new attribute node to it. The new attribute node to
  693. // be added is "street", which is already present in this
  694. // Element. The method should return the existing Attr
  695. // node(old "street" Attr). This test make use of the
  696. // "createAttribute(name)" method from the Document
  697. // interface.
  698. //
  699. // Semantic Requirements: 1, 13
  700. //
  701. //----------------------------------------------------------------------------
  702. [Test]
  703. public void core0013E()
  704. {
  705. string computedValue = "";
  706. string expectedValue = "No";
  707. System.Xml.XmlElement addressElement = null;
  708. System.Xml.XmlAttribute oldStreetAttribute = null;
  709. System.Xml.XmlAttribute newAttribute = null;
  710. testResults results = new testResults("Core0013E");
  711. try
  712. {
  713. results.description = "The \"setAttributeNode(newAttr)\" method when the " +
  714. "\"newAttr\" attribute node is already present in " +
  715. "this element. The method should return the previously " +
  716. "existing Attr node.";
  717. //
  718. // Access the last child of the third employee.
  719. //
  720. newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"street");
  721. addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
  722. //
  723. // Invoke its "setAttributeNode(newAttr)" method where
  724. // newAttr was just created with the same name as an already existing
  725. // attribute("street"). The existing attribute should be replaced with the
  726. // new one and the method should return the existing "street" Attr node.
  727. //
  728. oldStreetAttribute = addressElement.SetAttributeNode(newAttribute);//.node.
  729. //
  730. // The "oldStreetAttribute" now contains the old Attr node and its
  731. // "value" attribute should be available for examination.
  732. //
  733. computedValue = oldStreetAttribute.Value;
  734. }
  735. catch(System.Exception ex)
  736. {
  737. computedValue = "Exception " + ex.Message;
  738. }
  739. //
  740. // Write out results
  741. //
  742. results.expected = expectedValue;
  743. results.actual = computedValue;
  744. util.resetData();
  745. Assert.AreEqual (results.expected, results.actual);
  746. }
  747. //------------------------ End test case core-0013E --------------------------
  748. //
  749. //-------------------------- test case core-00014E ----------------------------
  750. //
  751. // Testing feature - The "setAttributeNode(newAttr)" method returns the
  752. // null value if no previously existing Attr node with the
  753. // same name was replaced.
  754. //
  755. // Testing approach - Retrieve the last child of the third and add a new
  756. // attribute node to it. The new attribute node to be
  757. // added is "district", which is not part of this Element.
  758. // The method should return the null value. This test makes
  759. // use of the "createAttribute(name)" method from the
  760. // Document interface.
  761. //
  762. // Semantic Requirements: 1, 15
  763. //
  764. //----------------------------------------------------------------------------
  765. [Test]
  766. [Category ("NotDotNet")] // MS DOM is buggy
  767. public void core0014E()
  768. {
  769. object computedValue = null;
  770. object expectedValue = null;
  771. System.Xml.XmlElement addressElement = null;
  772. System.Xml.XmlAttribute newAttribute = null;
  773. testResults results = new testResults("Core0014E");
  774. try
  775. {
  776. results.description = "The \"setAttributeNode(newAttr)\" method returns a " +
  777. "null value if no previously existing Attr node was replaced.";
  778. //
  779. // Access the sixth child of the third employee.
  780. //
  781. newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");
  782. addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
  783. //
  784. // Invoke its "setAttributeNode(newAttr)" method where name = "newAttribute".
  785. // This attribute is not part of this element. The method should add the
  786. // new Attribute and return a null value.
  787. //
  788. computedValue = addressElement.SetAttributeNode(newAttribute);//.node.
  789. }
  790. catch(System.Exception ex)
  791. {
  792. computedValue = "Exception " + ex.Message;
  793. }
  794. //
  795. // Write out results
  796. //
  797. results.expected = (expectedValue == null).ToString();
  798. results.actual = (computedValue == null).ToString();
  799. util.resetData();
  800. Assert.AreEqual (results.expected, results.actual);
  801. }
  802. //------------------------ End test case core-0014E --------------------------
  803. //
  804. //-------------------------- test case core-00015E ----------------------------
  805. //
  806. // Testing feature - The "removeAttributeNode(oldAttr)" method removes the
  807. // specified attribute.
  808. //
  809. // Testing approach - Retrieve the last child of the third employee, add
  810. // a new "district" node to it and the try to remove it.
  811. // To verify that the node was removed this test uses the
  812. // "getNamedItem(name)" from the NamedNodeMap interface.
  813. // This test also makes use of the "attributes" attribute
  814. // from the Node interface.
  815. //
  816. // Semantic Requirements: 1, 14
  817. //
  818. //----------------------------------------------------------------------------
  819. [Test]
  820. public void core0015E()
  821. {
  822. object computedValue = null;
  823. object expectedValue = null;
  824. System.Xml.XmlElement addressElement = null;
  825. System.Xml.XmlAttributeCollection attrList = null;
  826. System.Xml.XmlAttribute newAttribute = null;
  827. newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");
  828. testResults results = new testResults("Core0015E");
  829. try
  830. {
  831. results.description = "The \"removeAttributeNode(oldAttr)\" method removes the " +
  832. "specified attribute node.";
  833. //
  834. // Access the sixth child of the third employee and add the new
  835. // attribute to it.
  836. //
  837. addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
  838. addressElement.SetAttributeNode(newAttribute);//.node.
  839. //
  840. // Invoke its "removeAttributeNode(oldAttr)" method where
  841. // name = "newAttribute" and remove that attribute node.
  842. //
  843. addressElement.RemoveAttributeNode(newAttribute);//.node.
  844. //
  845. // To ensure that the "district" attribute was indeed removed, a listing
  846. // of all attributes is created by invoking the "attributes" attribute
  847. // of "addressElement". After the list is created, we attempt to
  848. // retrieve the "district" element from the list. A null value should
  849. // be return in its place.
  850. //
  851. attrList = addressElement.Attributes;
  852. computedValue = attrList.GetNamedItem("district");
  853. }
  854. catch(System.Exception ex)
  855. {
  856. computedValue = "Exception " + ex.Message;
  857. }
  858. //
  859. // Write out results
  860. //
  861. results.expected = (expectedValue == null).ToString();
  862. results.actual = (computedValue == null).ToString();
  863. util.resetData();
  864. Assert.AreEqual (results.expected, results.actual);
  865. }
  866. //------------------------ End test case core-0015E --------------------------
  867. //
  868. //-------------------------- test case core-00016E ----------------------------
  869. //
  870. // Testing feature - The "removeAttributeNode(oldAttr)" method removes the
  871. // specified attribute node and restore any default values.
  872. //
  873. // Testing approach - Retrieve the last child of the third employee and
  874. // remove its "street" Attr node. Since this node has
  875. // default value defined in the DTD file, that default
  876. // value should immediately be the new value.
  877. //
  878. // Semantic Requirements: 1, 15
  879. //
  880. //----------------------------------------------------------------------------
  881. [Test]
  882. #if NET_2_0
  883. [Category ("NotDotNet")]
  884. #endif
  885. public void core0016E()
  886. {
  887. string computedValue = "";
  888. string expectedValue = "Yes";
  889. System.Xml.XmlElement addressElement = null;
  890. System.Xml.XmlAttribute streetAttr = null;
  891. //System.Xml.XmlNode thirdEmployee = null;
  892. testResults results = new testResults("Core0016E");
  893. try
  894. {
  895. results.description = "The \"removeAttributeNode(oldAttr)\" method removes the " +
  896. "specified attribute node and restores any default values.";
  897. //
  898. // Access the sixth child of the third employee.
  899. //
  900. addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
  901. //
  902. // Create an instance of an Attr object by retrieving the "street"
  903. // attribute node, invoke its "removeAttributeNode(oldAttr)" method
  904. // where name = "streetAttr" and remove that attribute node. Note that
  905. // "the removeAttributeNode(oldAttr)" takes an Attr object as its
  906. // parameter, that is why an Attr object (named "street") is first created.
  907. //
  908. streetAttr = addressElement.GetAttributeNode("street");//.node.
  909. addressElement.RemoveAttributeNode(streetAttr);//.node.
  910. //
  911. // Since there is a default value defined for the "street" attribute, it
  912. // should immediately be the new value for that attribute.
  913. //
  914. computedValue = addressElement.GetAttribute("street");//.node.
  915. }
  916. catch(System.Exception ex)
  917. {
  918. computedValue = "Exception " + ex.Message;
  919. }
  920. //
  921. // Write out results
  922. //
  923. results.expected = expectedValue;
  924. results.actual = computedValue;
  925. util.resetData();
  926. Assert.AreEqual (results.expected, results.actual);
  927. }
  928. //------------------------ End test case core-0016E --------------------------
  929. //
  930. //-------------------------- test case core-00017E ----------------------------
  931. //
  932. // Testing feature - The "removeAttributeNode(oldAttr)" method returns the
  933. // node that was removed.
  934. //
  935. // Testing approach - Retrieve the last child of the third employee and
  936. // remove its "street" Attr node. The method should
  937. // return the old attribute node.
  938. //
  939. // Semantic Requirements: 1, 16
  940. //
  941. //----------------------------------------------------------------------------
  942. [Test]
  943. public void core0017E()
  944. {
  945. string computedValue = "";
  946. string expectedValue = "No";
  947. System.Xml.XmlElement addressElement = null;
  948. System.Xml.XmlAttribute streetAttr = null;
  949. System.Xml.XmlAttribute oldStreetAttribute = null;
  950. testResults results = new testResults("Core0017E");
  951. try
  952. {
  953. results.description = "The \"removeAttributeNode(oldAttr)\" method returns the "+
  954. "removed attribute node.";
  955. //
  956. // Access the sixth child of the third employee.
  957. //
  958. addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
  959. // create an instance of an Attr object by retrieving the "street"
  960. // attribute node, invoke its "removeAttributeNode(oldAttr)" method
  961. // where name = "streetAttr" and remove that attribute node. Note that
  962. // "the removeAttributeNode(oldAttr)" takes an Attr object as its
  963. // parameter, that is why an Attr object (named "street") is first created.
  964. //
  965. streetAttr = addressElement.GetAttributeNode("street");//.node.
  966. oldStreetAttribute = addressElement.RemoveAttributeNode(streetAttr);//.node.
  967. //
  968. // The method should return the removed attribute node. Its value can then
  969. // be examined.
  970. //
  971. computedValue = oldStreetAttribute.Value;
  972. }
  973. catch(System.Exception ex)
  974. {
  975. computedValue = "Exception " + ex.Message;
  976. }
  977. //
  978. // Write out results
  979. //
  980. results.expected = expectedValue;
  981. results.actual = computedValue;
  982. util.resetData();
  983. Assert.AreEqual (results.expected, results.actual);
  984. }
  985. //------------------------ End test case core-0017E --------------------------
  986. //
  987. //-------------------------- test case core-00018E ----------------------------
  988. //
  989. // Testing feature - The "getElementsByTagName(name)" method returns a list
  990. // of all descendant Elements with the given tag name.
  991. //
  992. // Testing approach - Get a listing of all the descendant elements of the
  993. // root element using the string "employee" as the tag
  994. // name. The method should return a Node list of length
  995. // equal to 5. This test makes use of the "length"
  996. // attribute from the NodeList interface.
  997. //
  998. // Semantic Requirements: 1, 17
  999. //
  1000. //----------------------------------------------------------------------------
  1001. [Test]
  1002. public void core0018E()
  1003. {
  1004. int computedValue = 0;
  1005. int expectedValue = 5;
  1006. System.Xml.XmlNodeList employeeList = null;
  1007. System.Xml.XmlElement docElement = null;
  1008. testResults results = new testResults("Core0018E");
  1009. results.description = "The \"getElementsByTagName(name)\" method returns a "+
  1010. "NodeList of all descendant elements with the given " +
  1011. "tag name(method returning a non-empty list)";
  1012. //
  1013. // get a listing of all the elements that match the tag "employee".
  1014. //
  1015. docElement = util.getRootNode();
  1016. employeeList = docElement.GetElementsByTagName("employee");
  1017. //
  1018. // The method should return a NodeList whose length can then be examined.
  1019. //
  1020. computedValue = employeeList.Count;
  1021. //
  1022. // Write out results
  1023. //
  1024. results.expected = expectedValue.ToString();
  1025. results.actual = computedValue.ToString();
  1026. Assert.AreEqual (results.expected, results.actual);
  1027. }
  1028. //------------------------ End test case core-0018E --------------------------
  1029. //
  1030. //-------------------------- test case core-00019E ----------------------------
  1031. //
  1032. // Testing feature - The "getElementsByTagName(name)" returns a list of all
  1033. // descendant Elements with the given tag name. Test
  1034. // for an empty list.
  1035. //
  1036. // Testing approach - Get a listing of all the descendant elements of the
  1037. // root element using the string "noMatches" as the tag
  1038. // name. The method should return a NodeList of length
  1039. // equal to 0 since no descendant elements match the given
  1040. // …

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