PageRenderTime 194ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  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. // tag name. This test makes use of the "length" attribute
  1041. // from the NodeList interface.
  1042. //
  1043. // Semantic Requirements: 1, 17
  1044. //
  1045. //----------------------------------------------------------------------------
  1046. [Test]
  1047. public void core0019E()
  1048. {
  1049. int computedValue = 0;
  1050. int expectedValue = 0;
  1051. System.Xml.XmlNodeList employeeList = null;
  1052. System.Xml.XmlElement docElement = null;
  1053. testResults results = new testResults("Core0019E");
  1054. results.description = "The \"getElementsByTagName(name)\" method returns a "+
  1055. "NodeList of all descendant elements with the given " +
  1056. "tag name (method returns an empty list)";
  1057. //
  1058. // get a listing of all the elements that match the tag "noMatch".
  1059. //
  1060. docElement = util.getRootNode();
  1061. employeeList = docElement.GetElementsByTagName("noMatch");
  1062. //
  1063. // The method should return a NodeList whose length can then be examined.
  1064. //
  1065. computedValue = employeeList.Count;
  1066. //
  1067. // Write out results
  1068. //
  1069. results.expected = expectedValue.ToString();
  1070. results.actual = computedValue.ToString();
  1071. Assert.AreEqual (results.expected, results.actual);
  1072. }
  1073. //------------------------ End test case core-0019E --------------------------
  1074. //
  1075. //-------------------------- test case core-00020E ----------------------------
  1076. //
  1077. // Testing feature - The "getElementsByTagName(name)" returns a list of all
  1078. // descendant Elements in the order the children were
  1079. // encountered in a pre order traversal of the element tree.
  1080. //
  1081. // Testing approach - Get a listing of all the descendant elements of the
  1082. // root node using the string "employee" as the tag
  1083. // name. The method should return a Node list of length
  1084. // equal to 5 in the order the children were encountered.
  1085. // Item number four in the list is accessed using a
  1086. // subscript. Item number four is itself an Element node
  1087. // with children and whose first child should be
  1088. // "employeeId".
  1089. //
  1090. // Semantic Requirements: 1, 18
  1091. //
  1092. //----------------------------------------------------------------------------
  1093. [Test]
  1094. public void core0020E()
  1095. {
  1096. string computedValue = "";
  1097. string expectedValue = "employeeId";
  1098. System.Xml.XmlNodeList employeeList = null;
  1099. System.Xml.XmlNode fourthEmployee = null;
  1100. System.Xml.XmlElement docElement = null;
  1101. testResults results = new testResults("Core0020E");
  1102. results.description = "The \"getElementsByTagName(name)\" returns a NodeList " +
  1103. "of all descendant elements in the order the " +
  1104. "children were encountered in a preorder traversal " +
  1105. "of the element tree.";
  1106. //
  1107. // get a listing of all the elements that match the tag "employee".
  1108. //
  1109. docElement = util.getRootNode();
  1110. employeeList = docElement.GetElementsByTagName("employee");
  1111. //
  1112. // The method should return a NodeList of the children in the order the
  1113. // children were encountered. Since "employeeList" is a NodeList we should
  1114. // be able to access its elements by using a subscript. Item number four
  1115. // is itself an Element node with six children and the first child
  1116. // is "employeeId".
  1117. //
  1118. fourthEmployee = employeeList.Item(util.FOURTH);
  1119. computedValue = fourthEmployee.FirstChild.Name;
  1120. //
  1121. // Write out results
  1122. //
  1123. results.expected = expectedValue;
  1124. results.actual = computedValue;
  1125. Assert.AreEqual (results.expected, results.actual);
  1126. }
  1127. //------------------------ End test case core-0020E --------------------------
  1128. //
  1129. //-------------------------- test case core-00021E ----------------------------
  1130. //
  1131. // Testing feature - The "getElementsByTagName(name)" method may use the
  1132. // special value "*" to match all the tags in the element
  1133. // tree.
  1134. //
  1135. // Testing approach - Get a listing of all the descendant elements of the
  1136. // last employee by using the special value of "*". The
  1137. // method should return all of the descendant children
  1138. // (total of 6) in the order the children were encountered.
  1139. //
  1140. // Semantic Requirements: 1, 19
  1141. //
  1142. //----------------------------------------------------------------------------
  1143. [Test]
  1144. public void core0021E()
  1145. {
  1146. string computedValue = "";
  1147. string expectedValue = "employeeId name position salary gender address ";
  1148. System.Xml.XmlNodeList elementList = null;
  1149. System.Xml.XmlElement lastEmployee = null;
  1150. testResults results = new testResults("Core0021E");
  1151. results.description = "The \"getElementsByTagName(name)\" method may use the " +
  1152. "special value \"*\" to match all the tags in the " +
  1153. "element tree.";
  1154. //
  1155. // get a listing of all the descendant elements of the last employee by using
  1156. // the special value of "*".
  1157. //
  1158. lastEmployee = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,-1);
  1159. elementList = lastEmployee.GetElementsByTagName("*");//.node.
  1160. //
  1161. // Traverse the list.
  1162. //
  1163. for (int index = 0;index <= elementList.Count - 1;index++)
  1164. computedValue += elementList.Item(index).Name+" ";
  1165. //
  1166. // Write out results
  1167. //
  1168. results.expected = expectedValue;
  1169. results.actual = computedValue;
  1170. Assert.AreEqual (results.expected, results.actual);
  1171. }
  1172. //------------------------ End test case core-0021E --------------------------
  1173. //
  1174. //-------------------------- test case core-00022E ----------------------------
  1175. //
  1176. // Testing feature - The "normalize()" method puts all the nodes in the
  1177. // full depth of the sub-tree underneath this element
  1178. // into a "normal" form.
  1179. //
  1180. // Testing approach - Retrieve the third employee and access its second
  1181. // child. This child contains a block of text that spread
  1182. // accross multiple lines. The content of the "name"
  1183. // child should be parsed and treated as a single Text node.
  1184. //
  1185. // Semantic Requirements: 1, 20
  1186. //
  1187. //----------------------------------------------------------------------------
  1188. [Test]
  1189. public void core0022E()
  1190. {
  1191. string computedValue = "";
  1192. string expectedValue = "Roger\n Jones";
  1193. System.Xml.XmlNode idElement = null;
  1194. System.Xml.XmlNode textNode = null;
  1195. testResults results = new testResults("Core0022E");
  1196. try
  1197. {
  1198. results.description = "The \"normalize()\" method puts all the nodes in the " +
  1199. "full depth of the sub-tree of this element into a normal form.";
  1200. //
  1201. // The "normalize() method should combine all the contiguous blocks of text
  1202. // and form a single "Text" node. The "nodeValue" of that final Text node
  1203. // should be the combination of all continuos blocks of text that do not
  1204. // contain any markup language.
  1205. //
  1206. idElement = util.nodeObject(util.THIRD,util.SECOND);
  1207. idElement.Normalize();//.node.
  1208. textNode = idElement.LastChild;//.node.
  1209. //
  1210. // text should be in normal form now
  1211. //
  1212. computedValue = textNode.Value;
  1213. }
  1214. catch(System.Exception ex)
  1215. {
  1216. computedValue = "Exception " + ex.Message;
  1217. }
  1218. //
  1219. // Write out results
  1220. //
  1221. results.expected = expectedValue;
  1222. results.actual = computedValue;
  1223. util.resetData();
  1224. Assert.AreEqual (results.expected, results.actual);
  1225. }
  1226. //------------------------ End test case core-0022E --------------------------
  1227. //
  1228. //-------------------------- test case core-00023E ---------------------------
  1229. //
  1230. // Testing feature - The "setAttribute(name,value)" method raises an
  1231. // INVALID_CHARACTER_ERR Exception if the specified
  1232. // name contains an invalid character.
  1233. //
  1234. // Testing approach - Retrieve the last child of the first employee
  1235. // and call its "setAttribute(name,value)" method with
  1236. // "name" containing an invalid character.
  1237. //
  1238. // Semantic Requirements: 1, 21
  1239. //
  1240. //----------------------------------------------------------------------------
  1241. [Test]
  1242. [Category ("NotDotNet")] // MS DOM is buggy
  1243. public void core0023E()
  1244. {
  1245. string computedValue = "";
  1246. System.Xml.XmlElement addressElement = null;
  1247. string expectedValue = "System.ArgumentException";
  1248. testResults results = new testResults("Core0023E");
  1249. try
  1250. {
  1251. results.description = "The \"setAttribute(name,value)\" method raises an " +
  1252. "ArgumentException if the specified " +
  1253. "name contains an invalid character.";
  1254. //
  1255. // Access the "address" element of the first employee.
  1256. //
  1257. addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);
  1258. //
  1259. // Attempt to set an attribute with an invalid character in its name.
  1260. //
  1261. try
  1262. {
  1263. addressElement.SetAttribute("invalid^Name","thisValue");//.node.
  1264. }
  1265. catch(System.Exception ex)
  1266. {
  1267. computedValue = ex.GetType().ToString();
  1268. }
  1269. }
  1270. catch(System.Exception ex)
  1271. {
  1272. computedValue = "Exception " + ex.Message;
  1273. }
  1274. results.expected = expectedValue;
  1275. results.actual = computedValue;
  1276. util.resetData();
  1277. Assert.AreEqual (results.expected, results.actual);
  1278. }
  1279. //------------------------ End test case core-0023E --------------------------
  1280. //
  1281. //-------------------------- test case core-0024E ----------------------------
  1282. //
  1283. // Testing feature - The "setAttribute(name,value)" method raises a
  1284. // NO_MODIFICATION_ALLOWED_ERR Exception if this
  1285. // node is readonly.
  1286. //
  1287. // Testing approach - Retrieve the Element node inside the Entity node
  1288. // named "ent4" and attempt to set an attribute for
  1289. // it. Descendants of Entity nodes are readonly nodes
  1290. // and therefore the desired exception should be raised.
  1291. //
  1292. // Semantic Requirements: 22
  1293. //
  1294. //----------------------------------------------------------------------------
  1295. [Test]
  1296. [Category ("NotDotNet")] // MS DOM is buggy
  1297. public void core0024E()
  1298. {
  1299. string computedValue = "";
  1300. System.Xml.XmlEntity entityNode = null;
  1301. System.Xml.XmlElement entityDesc = null;
  1302. string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;
  1303. testResults results = new testResults("Core0024E");
  1304. try
  1305. {
  1306. results.description = "The \"setAttribute(name,value)\" method raises a " +
  1307. "NO_MODIFICATION_ALLOWED_ERR Exception if the node is readonly.";
  1308. //
  1309. // Retreive the targeted data.
  1310. //
  1311. entityNode = util.getEntity("ent4");
  1312. entityDesc = (System.Xml.XmlElement)entityNode.FirstChild;
  1313. //
  1314. // Attempt to set an attribute for a readonly node should raise an exception.
  1315. //
  1316. try
  1317. {
  1318. entityDesc.SetAttribute("newAttribute","thisValue");
  1319. }
  1320. catch(System.Exception ex)
  1321. {
  1322. computedValue = ex.GetType ().FullName;
  1323. }
  1324. }
  1325. catch(System.Exception ex)
  1326. {
  1327. computedValue = "Exception " + ex.Message;
  1328. }
  1329. results.expected = expectedValue;
  1330. results.actual = computedValue;
  1331. util.resetData();
  1332. Assert.AreEqual (results.expected, results.actual);
  1333. }
  1334. //------------------------ End test case core-0024E --------------------------
  1335. //
  1336. //-------------------------- test case core-00025E ---------------------------
  1337. //
  1338. // Testing feature - The "removeAttribute(name)" method raises a
  1339. // NO_MODIFICATION_ALLOWED_ERR Exception if this
  1340. // node is readonly.
  1341. //
  1342. // Testing approach - Retrieve the Element node inside the Entity node
  1343. // named "ent4" and attempt to remove an attribute from
  1344. // it. Descendants of Entity nodes are readonly nodes
  1345. // and therefore the desired exception should be raised.
  1346. //
  1347. // Semantic Requirements: 23
  1348. //
  1349. //----------------------------------------------------------------------------
  1350. [Test]
  1351. [Category ("NotDotNet")] // MS DOM is buggy
  1352. public void core0025E()
  1353. {
  1354. string computedValue = "";
  1355. System.Xml.XmlEntity entityNode = null;
  1356. System.Xml.XmlElement entityDesc = null;
  1357. string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;
  1358. testResults results = new testResults("Core0025E");
  1359. try
  1360. {
  1361. results.description = "The \"removeAttribute(name)\" method raises a " +
  1362. "NO_MODIFICATION_ALLOWED_ERR Exception if the node is readonly.";
  1363. //
  1364. // Retrieve the targeted data.
  1365. //
  1366. entityNode = util.getEntity("ent4");
  1367. entityDesc = (System.Xml.XmlElement)entityNode.FirstChild;
  1368. //
  1369. // Attempt to set an attribute for a readonly node should raise an exception.
  1370. //
  1371. try
  1372. {
  1373. entityDesc.RemoveAttribute("attr1");
  1374. }
  1375. catch(System.Exception ex)
  1376. {
  1377. computedValue = ex.GetType ().FullName;
  1378. }
  1379. }
  1380. catch(System.Exception ex)
  1381. {
  1382. computedValue = "Exception " + ex.Message;
  1383. }
  1384. results.expected = expectedValue;
  1385. results.actual = computedValue;
  1386. util.resetData();
  1387. Assert.AreEqual (results.expected, results.actual);
  1388. }
  1389. //------------------------ End test case core-0025E --------------------------
  1390. //
  1391. //-------------------------- test case core-00026E ---------------------------
  1392. //
  1393. // Testing feature - The "setAttributeNode(newAttr)" method raises a
  1394. // NO_MODIFICATION_ALLOWED_ERR Exception if this
  1395. // node is readonly.
  1396. //
  1397. // Testing approach - Retrieve the Element node inside the Entity node
  1398. // named "ent4" and attempt to add a newly created Attr
  1399. // node to it. Descendants of Entity nodes are readonly
  1400. // nodes and therefore the desired exception should be
  1401. // raised.
  1402. //
  1403. // Semantic Requirements: 24
  1404. //
  1405. //----------------------------------------------------------------------------
  1406. [Test]
  1407. [Category ("NotDotNet")] // MS DOM is buggy
  1408. public void core0026E()
  1409. {
  1410. string computedValue = "";
  1411. System.Xml.XmlEntity entityNode = null;
  1412. System.Xml.XmlElement entityDesc = null;
  1413. System.Xml.XmlAttribute newAttr = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"newAttribute");
  1414. string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;
  1415. testResults results = new testResults("Core0026E");
  1416. try
  1417. {
  1418. results.description = "The \"setAttributeNode(newAttr)\" method raises a " +
  1419. "NO_MODIFICATION_ALLOWED_ERR Exception if the node is readonly.";
  1420. //
  1421. // Retrieve targeted data
  1422. //
  1423. entityNode = util.getEntity("ent4");
  1424. entityDesc = (System.Xml.XmlElement)entityNode.FirstChild;
  1425. //
  1426. // Attempt to set an attribute for a readonly node should raise an exception.
  1427. //
  1428. try
  1429. {
  1430. entityDesc.SetAttributeNode(newAttr);
  1431. }
  1432. catch(System.Exception ex)
  1433. {
  1434. computedValue = ex.GetType ().FullName;
  1435. }
  1436. }
  1437. catch(System.Exception ex)
  1438. {
  1439. computedValue = "Exception " + ex.Message;
  1440. }
  1441. results.expected = expectedValue;
  1442. results.actual = computedValue;
  1443. util.resetData();
  1444. Assert.AreEqual (results.expected, results.actual);
  1445. }
  1446. //------------------------ End test case core-0026E --------------------------
  1447. //
  1448. //-------------------------- test case core-00027E ---------------------------
  1449. //
  1450. // Testing feature - The "removeAttributeNode(newAttr)" method raises a
  1451. // NO_MODIFICATION_ALLOWED_ERR Exception if this
  1452. // node is readonly.
  1453. //
  1454. // Testing approach - Retrieve the Element node inside the Entity node
  1455. // named "ent4" and attempt to remove its "attr1"
  1456. // attribute. Descendants of Entity nodes are readonly
  1457. // nodes and therefore the desired exception should be
  1458. // raised.
  1459. //
  1460. // Semantic Requirements: 25
  1461. //
  1462. //----------------------------------------------------------------------------
  1463. [Test]
  1464. [Category ("NotDotNet")] // MS DOM is buggy
  1465. public void core0027E()
  1466. {
  1467. string computedValue = "";
  1468. System.Xml.XmlEntity entityNode = null;
  1469. System.Xml.XmlElement entityDesc = null;
  1470. System.Xml.XmlAttribute oldAttribute = null;
  1471. string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;
  1472. testResults results = new testResults("Core0027E");
  1473. try
  1474. {
  1475. results.description = "The \"removeAttributeNode(newAttr)\" method raises a " +
  1476. "NO_MODIFICATION_ALLOWED_ERR Exception if the node is readonly.";
  1477. //
  1478. // Get an instance of an attribute node and retrieve targeted data.
  1479. //
  1480. entityNode = util.getEntity("ent4");
  1481. entityDesc = (System.Xml.XmlElement)entityNode.FirstChild;
  1482. oldAttribute = ((System.Xml.XmlElement)entityNode.FirstChild).GetAttributeNode("attr1");
  1483. //
  1484. // Attempt to set remove an attribute node from a readonly node (lastChild).
  1485. // Should raise an exception.
  1486. //
  1487. try
  1488. {
  1489. entityDesc.RemoveAttributeNode(oldAttribute);
  1490. }
  1491. catch(System.Exception ex)
  1492. {
  1493. computedValue = ex.GetType ().FullName;
  1494. }
  1495. }
  1496. catch(System.Exception ex)
  1497. {
  1498. computedValue = "Exception " + ex.Message;
  1499. }
  1500. results.expected = expectedValue;
  1501. results.actual = computedValue;
  1502. util.resetData();
  1503. Assert.AreEqual (results.expected, results.actual);
  1504. }
  1505. //------------------------ End test case core-0027E --------------------------
  1506. //
  1507. //-------------------------- test case core-00028E ---------------------------
  1508. //
  1509. // Testing feature - The "setAttributeNode(newAttr)" method raises a
  1510. // System.ArgumentException Exception if the "newAttr" was
  1511. // created from a different document than the one that
  1512. // created this document.
  1513. //
  1514. // Testing approach - Retrieve the last employee and attempt to set
  1515. // a new attribute node for its "employee" element.
  1516. // The new attribute was created from a document
  1517. // other than the one that crated this element,
  1518. // therefore the desired exception should be raised.
  1519. // This test uses the "createAttribute(newAttr)" method
  1520. // from the Document interface.
  1521. //
  1522. // Semantic Requirements: 26
  1523. //
  1524. //----------------------------------------------------------------------------
  1525. [Test]
  1526. [Category ("NotDotNet")] // MS DOM is buggy
  1527. public void core0028E()
  1528. {
  1529. System.Xml.XmlElement addressElement = null;
  1530. string computedValue = "";
  1531. System.Xml.XmlAttribute newAttr = null;
  1532. string expectedValue = "System.ArgumentException";
  1533. testResults results = new testResults("Core0028E");
  1534. try
  1535. {
  1536. results.description = "The \"setAttributeNode(newAttr)\" method raises a " +
  1537. "System.ArgumentException Exception if \"newAttr\" was created " +
  1538. "from a different document than the one who created this node.";
  1539. //
  1540. // Access the address Element of the last employee and attempt to set
  1541. // a new attribute node.
  1542. //
  1543. newAttr = util.getOtherDOMDocument().CreateAttribute("newAttribute");
  1544. addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.SIXTH);
  1545. //
  1546. // The new attribute was created from a different document and therefore
  1547. // an exception should be raised.
  1548. //
  1549. try
  1550. {
  1551. addressElement.SetAttributeNode(newAttr);//.node.
  1552. }
  1553. catch(System.Exception ex)
  1554. {
  1555. computedValue = ex.GetType().ToString();
  1556. }
  1557. }
  1558. catch(System.Exception ex)
  1559. {
  1560. computedValue = "Exception " + ex.Message;
  1561. }
  1562. results.expected = expectedValue;
  1563. results.actual = computedValue;
  1564. util.resetData();
  1565. Assert.AreEqual (results.expected, results.actual);
  1566. }
  1567. //------------------------ End test case core-0028E --------------------------
  1568. //
  1569. //-------------------------- test case core-00029E ---------------------------
  1570. //
  1571. // Testing feature - The "setAttributeNode(newAttr)" method raises an
  1572. // InvalidOperationException if the "newAttr"
  1573. // attribute is already an attribute of another element.
  1574. //
  1575. // Testing approach - Retrieve the last employee and attempt to set an
  1576. // attribute node to one of its children that
  1577. // already exist in another children. The attribute
  1578. // node used is "street", which already exist in the
  1579. // "address" element. An instance of that attribute
  1580. // node is first retrived from the "address" element and
  1581. // then attempted to be set in the "employeeId" element.
  1582. // This should cause the intended exception to be raised.
  1583. //
  1584. // Semantic Requirements: 27
  1585. //
  1586. //----------------------------------------------------------------------------
  1587. [Test]
  1588. public void core0029E()
  1589. {
  1590. string computedValue = "";
  1591. System.Xml.XmlElement employeeIdElement = null;
  1592. System.Xml.XmlElement addressElement = null;
  1593. System.Xml.XmlAttribute newAttribute = null;
  1594. string expectedValue = "InvalidOperationException";
  1595. testResults results = new testResults("Core0029E");
  1596. try
  1597. {
  1598. results.description = "The \"setAttributeNode(newAttr)\" method raises an "+
  1599. "InvalidOperationException if \"newAttr\" attribute "+
  1600. "is already being used by another element.";
  1601. //
  1602. // Retrieve an already existing attribute from the "address" element.
  1603. //
  1604. addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.SIXTH);
  1605. newAttribute = addressElement.GetAttributeNode("street");//.node.
  1606. //
  1607. // Access the "employeeId" element of the last employee.
  1608. //
  1609. employeeIdElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.FIRST);
  1610. //
  1611. // Attempt to set an attribute node with an already existing attribute node
  1612. // in another element.
  1613. //
  1614. try
  1615. {
  1616. employeeIdElement.SetAttributeNode(newAttribute);//.node.
  1617. }
  1618. catch(System.InvalidOperationException ex)
  1619. {
  1620. computedValue = "InvalidOperationException";
  1621. }
  1622. }
  1623. catch(System.Exception ex)
  1624. {
  1625. computedValue = "Exception " + ex.Message;
  1626. }
  1627. results.expected = expectedValue;
  1628. results.actual = computedValue;
  1629. util.resetData();
  1630. Assert.AreEqual (results.expected, results.actual);
  1631. }
  1632. //------------------------ End test case core-0029E -------------------------
  1633. //
  1634. //-------------------------- test case core-0030E ---------------------------
  1635. //
  1636. // Testing feature - The "removeAttributeNode(oldAttr)" method raises a
  1637. // NOT_FOUND_ERR Exception if the "oldAttr" attribute
  1638. // is not an attribute of the element.
  1639. //
  1640. // Testing approach - Retrieve the last employee and attempt to remove
  1641. // a non existing attribute node. This should cause
  1642. // the intended exception be raised. This test makes use
  1643. // of the "createAttribute(name)" method from the
  1644. // Document interface.
  1645. //
  1646. // Semantic Requirements: 28
  1647. //
  1648. //----------------------------------------------------------------------------
  1649. [Test]
  1650. [Category ("NotDotNet")] // MS DOM is buggy
  1651. public void core0030E()
  1652. {
  1653. string computedValue = "";
  1654. System.Xml.XmlElement addressElement = null;
  1655. System.Xml.XmlAttribute oldAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"oldAttribute");
  1656. string expectedValue = "System.ArgumentException";//util.NOT_FOUND1_ERR;
  1657. testResults results = new testResults("Core0030E");
  1658. try
  1659. {
  1660. results.description = "The \"removeAttributeNode(oldAttr)\" method raises a " +
  1661. "NOT_FOUND_ERR Exception if \"oldAttr\" attribute " +
  1662. "is not an attribute of the element.";
  1663. //
  1664. // Access the "address" element of the last employee.
  1665. //
  1666. addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.SIXTH);
  1667. //
  1668. // Attempt to remove a non-existing attribute. Should raise exception.
  1669. //
  1670. try
  1671. {
  1672. addressElement.RemoveAttributeNode(oldAttribute);//.node.
  1673. }
  1674. catch(ArgumentException ex)
  1675. {
  1676. computedValue = ex.GetType ().FullName;
  1677. }
  1678. }
  1679. catch(System.Exception ex)
  1680. {
  1681. computedValue = "Exception " + ex.Message;
  1682. }
  1683. results.expected = expectedValue;
  1684. results.actual = computedValue;
  1685. util.resetData();
  1686. Assert.AreEqual (results.expected, results.actual);
  1687. }
  1688. //------------------------ End test case core-0030E --------------------------
  1689. }
  1690. }