PageRenderTime 50ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://bitbucket.org/danipen/mono
C# | 1331 lines | 531 code | 135 blank | 665 comment | 4 complexity | 4ffa64f44a74bf87c122c5d6f3734c0d 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. // Document 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 DocumentTest
  23. {
  24. public static int i = 2;
  25. /*
  26. public testResults[] RunTests()
  27. {
  28. testResults[] tests = new testResults[] {core0001D(), core0002D(), core0003D(), core0004D(),
  29. core0005D(), core0006D(), core0007D(), core0008D(),
  30. core0009D(), core0010D(), core0011D(), core0012D(),
  31. core0013D(), core0014D(), core0015D(),
  32. core0019D(), core0020D(),
  33. core0021D(), core0022D(), core0023D(), core0024D(),
  34. core0025D()};
  35. return tests;
  36. }
  37. */
  38. //------------------------ test case core-0001T ------------------------
  39. //
  40. // Testing feature - The doctype attribute contains the Document Type
  41. // Declaration associated with this Document.
  42. //
  43. // Testing approach - Retrieve the entire DOM document and invoke its
  44. // doctype attribute. It should return the Document
  45. // type of this document. Its document Type name
  46. // should be equal to "staff".
  47. //
  48. // Semantic Requirements: 1
  49. //
  50. //----------------------------------------------------------------------------
  51. [Test]
  52. public void core0001D()
  53. {
  54. string computedValue = "";
  55. string expectedValue = "staff";
  56. System.Xml.XmlDocument testNode = null;
  57. testResults results = new testResults("Core0001D");
  58. results.description = "The doctype attribute contains the Document Type "+
  59. "Declaration associated with this object.";
  60. //
  61. // Retrieve the targeted data and access its "doctype" attribute.
  62. //
  63. testNode = util.getDOMDocument();
  64. System.Xml.XmlDocumentType dtype = testNode.DocumentType;
  65. computedValue = dtype.Name;
  66. //
  67. // Write out results.
  68. //
  69. results.expected = expectedValue;
  70. results.actual = computedValue;
  71. Assert.AreEqual (results.expected, results.actual);
  72. }
  73. //------------------------ End test case core-0001D --------------------------
  74. //
  75. //-------------------------- test case core-0002D ----------------------------
  76. //
  77. // Testing feature - The doctype attribute returns null for HTML documents.
  78. //
  79. // Testing approach - Retrieve the an HTML DOM document and invoke its
  80. // doctype attribute. It should return null.
  81. //
  82. // Semantic Requirements: 2
  83. //
  84. //----------------------------------------------------------------------------
  85. [Test]
  86. public void core0002D()
  87. {
  88. string testName = "core-0002D";
  89. object computedValue = null;
  90. object expectedValue = null;
  91. System.Xml.XmlDocument testNode = null;
  92. testResults results = new testResults("Core0002D");
  93. results.description = "The doctype attribute returns null for HTML "+
  94. "documents";
  95. //
  96. // Retrieve the targeted data and access its "doctype" attribute.
  97. //
  98. testNode = util.getDOMHTMLDocument();
  99. computedValue = (testNode.DocumentType == null).ToString();
  100. //
  101. // Write out results.
  102. //
  103. results.expected = (expectedValue == null).ToString();
  104. results.actual = computedValue.ToString();
  105. Assert.AreEqual (results.expected, results.actual);
  106. }
  107. //------------------------ End test case core-0002D --------------------------
  108. //
  109. //-------------------------- test case core-0003D ----------------------------
  110. //
  111. // Testing feature - The doctype attribute returns null for XML documents
  112. // without a document type declaration.
  113. //
  114. // Testing approach - Retrieve an XML DOM document without a Document
  115. // Type Declaration and invoke its doctype attribute.
  116. // It should return null.
  117. //
  118. // Semantic Requirements: 2
  119. //
  120. //----------------------------------------------------------------------------
  121. [Test]
  122. public void core0003D()
  123. {
  124. object computedValue = null;
  125. object expectedValue = null;
  126. System.Xml.XmlDocument testNode = null;
  127. testResults results = new testResults("Core0003D");
  128. results.description = "The doctype attribute returns null for XML "+
  129. " documents without a Document Type Declaration.";
  130. //
  131. // Retrieve the targeted data and access its "doctype" attribute.
  132. //
  133. testNode = util.getnoDTDXMLDocument();
  134. computedValue = (testNode.DocumentType == null).ToString();
  135. //
  136. // Write out results.
  137. //
  138. results.expected = (expectedValue == null).ToString();
  139. results.actual = computedValue.ToString();
  140. Assert.AreEqual (results.expected, results.actual);
  141. }
  142. //------------------------ End test case core-0003D --------------------------
  143. //
  144. //-------------------------- test case core-0004D ----------------------------
  145. //
  146. // Testing feature - The implementation attribute contains the
  147. // DOMImplementation object that handles this document.
  148. //
  149. // Testing approach - Retrieve the entire DOM document and invoke its
  150. // "implementation" attribute. It should return a
  151. // DOMImplementation object whose "hasFeature("XML,"1.0")
  152. // method is invoke and a true value expected.
  153. //
  154. // Semantic Requirements: 3
  155. //
  156. //----------------------------------------------------------------------------
  157. [Test]
  158. public void core0004D()
  159. {
  160. string computedValue = "";
  161. string expectedValue = "True";
  162. System.Xml.XmlImplementation domImp = null;
  163. System.Xml.XmlDocument testNode = null;
  164. testResults results = new testResults("Core0004D");
  165. results.description = "The implementation attribute contains the "+
  166. "DOMImplementation object that handles this"+
  167. " document.";
  168. //
  169. // Retrieve the targeted data and access its "implementation" attribute.
  170. //
  171. testNode = util.getDOMDocument();
  172. domImp = testNode.Implementation;
  173. //
  174. // The "hasFeature" method should return true.
  175. //
  176. computedValue = domImp.HasFeature("XML","1.0").ToString();
  177. //
  178. // Write out results.
  179. //
  180. results.expected = expectedValue;
  181. results.actual = computedValue;
  182. Assert.AreEqual (results.expected, results.actual);
  183. }
  184. //------------------------ End test case core-0004D --------------------------
  185. //
  186. //-------------------------- test case core-0005D ----------------------------
  187. //
  188. // Testing feature - The documentElement attribute provides direct access
  189. // to the child node that is the root element of the
  190. // document.
  191. //
  192. // Testing approach - Retrieve the entire DOM document and invoke its
  193. // "documentElement" attribute. It should return an
  194. // Element node whose "tagName" attribute is "staff".
  195. //
  196. // Semantic Requirements: 4
  197. //
  198. //----------------------------------------------------------------------------
  199. [Test]
  200. public void core0005D()
  201. {
  202. string computedValue = "";
  203. string expectedValue = "staff";
  204. System.Xml.XmlElement rootNode = null;
  205. System.Xml.XmlDocument testNode = null;
  206. testResults results = new testResults("Core0005D");
  207. results.description = "The documentElement attribute provides direct "+
  208. "to the root node of the document.";
  209. //
  210. // Retrieve the targeted data and access its "documentElement" attribute.
  211. //
  212. testNode = util.getDOMDocument();
  213. rootNode = testNode.DocumentElement;
  214. //
  215. // Its tagName should be set to "staff".
  216. //
  217. computedValue = rootNode.Name;//tagName;
  218. //
  219. // Write out results.
  220. //
  221. results.expected = expectedValue;
  222. results.actual = computedValue;
  223. Assert.AreEqual (results.expected, results.actual);
  224. }
  225. //------------------------ End test case core-0005D --------------------------
  226. //
  227. //-------------------------- test case core-0006D ----------------------------
  228. //
  229. // Testing feature - For HTML documents, the documentElement attribute returns
  230. // the Element with the HTML tag.
  231. //
  232. // Testing approach - Retrieve an HTML DOM document and invoke its
  233. // "documentElement" attribute. It should return the
  234. // Element whose "tagName" is "HTML".
  235. //
  236. // Semantic Requirements: 5
  237. //
  238. //----------------------------------------------------------------------------
  239. [Test]
  240. [Category ("NotDotNet")] // MS DOM is buggy
  241. public void core0006D()
  242. {
  243. string computedValue = "";
  244. string expectedValue = "HTML";
  245. System.Xml.XmlElement rootNode = null;
  246. System.Xml.XmlDocument testNode = null;
  247. testResults results = new testResults("Core0006D");
  248. results.description = "For HTML documents, the documentElement attribute "+
  249. "returns the element with the HTML tag.";
  250. //
  251. // Retrieve the targeted data and access its "documentElement" attribute.
  252. //
  253. testNode = util.getDOMHTMLDocument();
  254. rootNode = testNode.DocumentElement;
  255. //
  256. // Its tagName should be set to "HTML".
  257. //
  258. computedValue = rootNode.Name;//tagName;
  259. //
  260. // Write out results.
  261. //
  262. results.expected = expectedValue;
  263. results.actual = computedValue;
  264. Assert.AreEqual (results.expected, results.actual);
  265. }
  266. //------------------------ End test case core-0006D --------------------------
  267. //
  268. //-------------------------- test case core-0007D ----------------------------
  269. //
  270. // Testing feature - The "createElement(tagName)" method creates an Element of
  271. // the type specified.
  272. //
  273. // Testing approach - Retrieve the entire DOM document and invoke its
  274. // "createElement(tagName)" method with tagName="address".
  275. // The method should create an instance of an Element
  276. // node whose tagName is "address". The type, value and
  277. // are further checked.
  278. //
  279. // Semantic Requirements: 6
  280. //
  281. //----------------------------------------------------------------------------
  282. [Test]
  283. public void core0007D()
  284. {
  285. string computedValue = "";
  286. string expectedValue = "address Element ";
  287. System.Xml.XmlElement newElement = null;
  288. System.Xml.XmlDocument testNode = null;
  289. testResults results = new testResults("Core0007D");
  290. results.description = "The \"createElement(tagName)\" method creates an "+
  291. "Element of the specified type.";
  292. //
  293. // Retrieve the targeted data and invoke its "createElement" attribute.
  294. //
  295. testNode = util.getDOMDocument();
  296. newElement = testNode.CreateElement("address");
  297. //
  298. // Retrieve the characteristics of this new object.
  299. //
  300. computedValue = newElement.Name+" ";//tagName
  301. computedValue += newElement.NodeType +" ";
  302. computedValue += newElement.Value;
  303. //
  304. // Write out results.
  305. //
  306. results.expected = expectedValue;
  307. results.actual = computedValue;
  308. util.resetData();
  309. Assert.AreEqual (results.expected, results.actual);
  310. }
  311. //------------------------ End test case core-0007D --------------------------
  312. //
  313. //-------------------------- test case core-0008D ----------------------------
  314. //
  315. // Testing feature - The tagName parameter in the "createElement(tagName)"
  316. // method is case-sensitive for XML documents.
  317. //
  318. // Testing approach - Retrieve the entire DOM document and invoke its
  319. // "createElement(tagName)" method twice for tagName
  320. // equal "address" and "ADDRESS". Each call should
  321. // create two distinct Element nodes. Each Element
  322. // is in turn assigned an attribute and then that
  323. // attribute is retrieved.
  324. //
  325. // Semantic Requirements: 7
  326. //
  327. //----------------------------------------------------------------------------
  328. [Test]
  329. public void core0008D()
  330. {
  331. string computedValue = "";
  332. string expectedValue = "Fort Worth Dallas";
  333. System.Xml.XmlElement newElement1 = null;
  334. System.Xml.XmlElement newElement2 = null;
  335. System.Xml.XmlDocument testNode = null;
  336. testResults results = new testResults("Core0008D");
  337. results.description = "The tagName parameter in the \"createElement( "+
  338. "tagName)\" method is case-sensitive for XML "+
  339. "documents.";
  340. //
  341. // Retrieve the targeted data and invoke its "createElement" method.
  342. //
  343. testNode = util.getDOMDocument();
  344. newElement1 = testNode.CreateElement("ADDRESS");
  345. newElement2 = testNode.CreateElement("address");
  346. //
  347. // Assign attributes for each one of the created Elements.
  348. //
  349. newElement1.SetAttribute("district","Fort Worth");
  350. newElement2.SetAttribute("county","Dallas");
  351. //
  352. // Now retrieve the values of each Element's attribute.
  353. //
  354. computedValue += newElement1.GetAttribute("district")+" ";
  355. computedValue += newElement2.GetAttribute("county");
  356. //
  357. // Write out results.
  358. //
  359. results.expected = expectedValue;
  360. results.actual = computedValue;
  361. util.resetData();
  362. Assert.AreEqual (results.expected, results.actual);
  363. }
  364. //------------------------ End test case core-0008D --------------------------
  365. //
  366. //-------------------------- test case core-0009D ----------------------------
  367. //
  368. // Testing feature - The "createDocumentFragment()" method creates an
  369. // empty DocumentFragment object.
  370. //
  371. // Testing approach - Retrieve the entire DOM document and invoke its
  372. // createDocumentFragment() method. The content, name,
  373. // type and value of the newly created object are
  374. // further retrieved and checked.
  375. //
  376. // Semantic Requirements: 8
  377. //
  378. //----------------------------------------------------------------------------
  379. [Test]
  380. public void core0009D()
  381. {
  382. string computedValue = "";
  383. string expectedValue = "0 #document-fragment DocumentFragment ";//"0 #document-fragment 11 null";
  384. System.Xml.XmlDocumentFragment newDocFragment = null;
  385. System.Xml.XmlDocument testNode = null;
  386. testResults results = new testResults("Core0009D");
  387. results.description = "The \"createDocumentFragment()\" method creates "+
  388. "an empty DocumentFragment object.";
  389. //
  390. // Retrieve the targeted data and invoke its "createDocumentFragment()"
  391. // method.
  392. //
  393. testNode = util.getDOMDocument();
  394. newDocFragment = testNode.CreateDocumentFragment();
  395. //
  396. // Retrieve the characterstics of the newly created object.
  397. //
  398. computedValue += newDocFragment.ChildNodes.Count +" ";
  399. computedValue += newDocFragment.Name+" ";
  400. computedValue += newDocFragment.NodeType+" ";
  401. computedValue += newDocFragment.Value;
  402. //
  403. // Write out results.
  404. //
  405. results.expected = expectedValue;
  406. results.actual = computedValue;
  407. util.resetData();
  408. Assert.AreEqual (results.expected, results.actual);
  409. }
  410. //------------------------ End test case core-0009D --------------------------
  411. //
  412. //-------------------------- test case core-0010D ----------------------------
  413. //
  414. // Testing feature - The "createTextNode(data)" method creates a Text node
  415. // given by the specified string.
  416. //
  417. // Testing approach - Retrieve the entire DOM document and invoke its
  418. // "createTextNode(data)" method. It should create a
  419. // new Text node whose data is the specified string. The
  420. // name and type of the newly created object are further
  421. // retrieved and checked.
  422. //
  423. // Semantic Requirements: 9
  424. //
  425. //----------------------------------------------------------------------------
  426. [Test]
  427. public void core0010D()
  428. {
  429. string computedValue = "";
  430. string expectedValue = "This is a new Text node #text Text";//"This is a new Text node #text 3";
  431. System.Xml.XmlText newTextNode = null;
  432. System.Xml.XmlDocument testNode = null;
  433. testResults results = new testResults("Core0010D");
  434. results.description = "The \"createTextNode(data)\" method creates "+
  435. "a Text node given by the specified string.";
  436. //
  437. // Retrieve the targeted data and invoke its "createTextNode(data)" method.
  438. //
  439. testNode = util.getDOMDocument();
  440. newTextNode = testNode.CreateTextNode("This is a new Text node");
  441. //
  442. // Retrieve the characteristics of the newly created object.
  443. //
  444. computedValue += newTextNode.Data+" ";
  445. computedValue += newTextNode.Name+" ";
  446. computedValue += newTextNode.NodeType;
  447. //
  448. // Write out results.
  449. //
  450. results.expected = expectedValue;
  451. results.actual = computedValue;
  452. util.resetData();
  453. Assert.AreEqual (results.expected, results.actual);
  454. }
  455. //------------------------ End test case core-0010D --------------------------
  456. //
  457. //-------------------------- test case core-0011D ----------------------------
  458. //
  459. // Testing feature - The "createComment(data)" method creates a new Comment
  460. // node given the specified string.
  461. //
  462. // Testing approach - Retrieve the entire DOM document and invoke its
  463. // "createComment(data)" method. It should create a
  464. // new Comment node whose data is the specified string.
  465. // The content, name and type of the newly created
  466. // object are further retrieved and examined.
  467. //
  468. // Semantic Requirements: 10
  469. //
  470. //----------------------------------------------------------------------------
  471. [Test]
  472. public void core0011D()
  473. {
  474. string computedValue = "";
  475. string expectedValue = "This is a new Comment node #comment Comment";//"This is a new Comment node #comment 8";
  476. System.Xml.XmlComment newCommentNode = null;
  477. System.Xml.XmlDocument testNode = null;
  478. testResults results = new testResults("Core0011D");
  479. results.description = "The \"createComment(data)\" method creates "+
  480. "a new comment node given by the specified string.";
  481. //
  482. // Retrieve the targeted data and invoke its "createComment(data)" method.
  483. //
  484. testNode = util.getDOMDocument();
  485. newCommentNode = testNode.CreateComment("This is a new Comment node");
  486. //
  487. // Retrieve the characteristics of the new object.
  488. //
  489. computedValue += newCommentNode.Data+" ";
  490. computedValue += newCommentNode.Name+" ";
  491. computedValue += newCommentNode.NodeType;
  492. //
  493. // Write out results.
  494. //
  495. results.expected = expectedValue;
  496. results.actual = computedValue;
  497. util.resetData();
  498. Assert.AreEqual (results.expected, results.actual);
  499. }
  500. //------------------------ End test case core-0011D --------------------------
  501. //
  502. //-------------------------- test case core-0012D ----------------------------
  503. //
  504. // Testing feature - The "createCDATASection(data)" method creates a new
  505. // CDATASection node whose value is the specified string.
  506. //
  507. // Testing approach - Retrieve the entire DOM document and invoke its
  508. // "createCDATASection(data)" method. It should create a
  509. // new CDATASection node whose data is the specified string.
  510. // The content, name and type of the newly created
  511. // object are further retrieved and examined.
  512. //
  513. // Semantic Requirements: 11
  514. //
  515. //----------------------------------------------------------------------------
  516. [Test]
  517. public void core0012D()
  518. {
  519. string computedValue = "";
  520. string expectedValue = "This is a new CDATASection node #cdata-section CDATA";//"This is a new CDATASection node #cdata-section 4";
  521. System.Xml.XmlCDataSection newCDATASectionNode = null;
  522. System.Xml.XmlDocument testNode = null;
  523. testResults results = new testResults("Core0012D");
  524. results.description = "The \"createCDATASection(data)\" method creates "+
  525. "a new CDATASection node whose value is the "+
  526. "specified string.";
  527. //
  528. // Retrieve the targeted data and invoke its "createCDATASection(data)"
  529. // method.
  530. //
  531. testNode = util.getDOMDocument();
  532. newCDATASectionNode = testNode.CreateCDataSection("This is a new CDATASection node");
  533. //
  534. // Retrieve the characteristics of the new object.
  535. //
  536. computedValue += newCDATASectionNode.Data+" ";
  537. computedValue += newCDATASectionNode.Name+" ";
  538. computedValue += newCDATASectionNode.NodeType;
  539. //
  540. // Write out results.
  541. //
  542. results.expected = expectedValue;
  543. results.actual = computedValue;
  544. util.resetData();
  545. Assert.AreEqual (results.expected, results.actual);
  546. }
  547. //------------------------ End test case core-0012D --------------------------
  548. //
  549. //-------------------------- test case core-0013D ----------------------------
  550. //
  551. // Testing feature - The "createProcessingInstruction(target,data)" method
  552. // creates a new ProcessingInstruction node with the
  553. // specified name and data strings.
  554. //
  555. // Testing approach - Retrieve the entire DOM document and invoke its
  556. // "createProcessingInstruction(target,data)" method. It
  557. // should create a new PI node with the specified target
  558. // and data. The target, data and type of the newly created
  559. // object are further retrieved and examined.
  560. //
  561. // Semantic Requirements: 12
  562. //
  563. //----------------------------------------------------------------------------
  564. [Test]
  565. public void core0013D()
  566. {
  567. string computedValue = "";
  568. string expectedValue = "XML This is a new PI node ProcessingInstruction";//"XML This is a new PI node 7";
  569. System.Xml.XmlProcessingInstruction newPINode = null;
  570. System.Xml.XmlDocument testNode = null;
  571. testResults results = new testResults("Core0013D");
  572. results.description = "The \"createProcessingInstruction(target,data)\" "+
  573. "method creates a new processingInstruction node.";
  574. //
  575. // Retrieve the targeted data and invoke its
  576. // "createProcessingInstruction(target,data)" method.
  577. //
  578. testNode = util.getDOMDocument();
  579. newPINode = testNode.CreateProcessingInstruction("XML","This is a new PI node");
  580. //
  581. // Retrieve the characteristics of the new object.
  582. //
  583. computedValue += newPINode.Target+" ";
  584. computedValue += newPINode.Data+" ";
  585. computedValue += newPINode.NodeType;
  586. //
  587. // Write out results.
  588. //
  589. results.expected = expectedValue;
  590. results.actual = computedValue;
  591. util.resetData();
  592. Assert.AreEqual (results.expected, results.actual);
  593. }
  594. //------------------------ End test case core-0013D --------------------------
  595. //
  596. //-------------------------- test case core-0014D ----------------------------
  597. //
  598. // Testing feature - The "createAttribute(name)" method creates an Attr
  599. // node of the given name.
  600. //
  601. // Testing approach - Retrieve the entire DOM document and invoke its
  602. // "createAttribute(name)" method. It should create a
  603. // new Attr node with the given name. The name, value
  604. // and type of the newly created object are further
  605. // retrieved and examined.
  606. //
  607. // Semantic Requirements: 13
  608. //
  609. //----------------------------------------------------------------------------
  610. [Test]
  611. public void core0014D()
  612. {
  613. string computedValue = "";
  614. string expectedValue = "district Attribute";//"district 2";
  615. System.Xml.XmlAttribute newAttrNode = null;
  616. System.Xml.XmlDocument testNode = null;
  617. testResults results = new testResults("Core0014D");
  618. results.description = "The \"createAttribute(name)\" method creates "+
  619. "a new Attr node of the given name.";
  620. //
  621. // Retrieve the targeted data and invoke its "createAttribute(name)"
  622. // method.
  623. //
  624. testNode = util.getDOMDocument();
  625. newAttrNode = testNode.CreateAttribute("district");
  626. //
  627. // Retrieve the characteristics of the new object.
  628. //
  629. computedValue += newAttrNode.Name+" ";
  630. computedValue += newAttrNode.Value;
  631. computedValue += newAttrNode.NodeType;
  632. //
  633. // Write out results.
  634. //
  635. results.expected = expectedValue;
  636. results.actual = computedValue;
  637. util.resetData();
  638. Assert.AreEqual (results.expected, results.actual);
  639. }
  640. //------------------------ End test case core-0014D --------------------------
  641. //
  642. //-------------------------- test case core-0015D ----------------------------
  643. //
  644. // Testing feature - The "createEntityReference(name)" method creates an
  645. // EntityReference node.
  646. //
  647. // Testing approach - Retrieve the entire DOM document and invoke its
  648. // "createEntityReference(name)" method. It should
  649. // create a new EntityReference node for the Entity
  650. // with the given name. The name, value and type of
  651. // the newly created object are further retrieved
  652. // and examined.
  653. //
  654. // Semantic Requirements: 14
  655. //
  656. //----------------------------------------------------------------------------
  657. [Test]
  658. public void core0015D()
  659. {
  660. string computedValue = "";
  661. string expectedValue = "ent1 EntityReference";//"ent1 null 5";
  662. System.Xml.XmlEntityReference newEntRefNode = null;
  663. System.Xml.XmlDocument testNode = null;
  664. testResults results = new testResults("Core0015D");
  665. results.description = "The \"createEntityReference(name)\" method creates "+
  666. "a new EntityReference node.";
  667. //
  668. // Retrieve the targeted data and invoke its "createEntityReference(name)"
  669. // method.
  670. //
  671. testNode = util.getDOMDocument();
  672. newEntRefNode = testNode.CreateEntityReference("ent1");
  673. //
  674. // Retrieve the characteristics of the new object.
  675. //
  676. computedValue += newEntRefNode.Name+" ";
  677. computedValue += newEntRefNode.Value+" ";
  678. computedValue += newEntRefNode.NodeType;
  679. //
  680. // Write out results.
  681. //
  682. results.expected = expectedValue;
  683. results.actual = computedValue;
  684. util.resetData();
  685. Assert.AreEqual (results.expected, results.actual);
  686. }
  687. //------------------------ End test case core-0015D --------------------------
  688. //
  689. //-------------------------- test case core-0016D ----------------------------
  690. //
  691. // Testing feature - The "getElementsByTagName(tagName)" method returns a
  692. // NodeList of all the Elements with a given tagName.
  693. //
  694. // Testing approach - Retrieve the entire DOM document and invoke its
  695. // "getElementsByTagName(tagName)" method with tagName
  696. // equal to "name". The method should return a NodeList
  697. // that contains 5 elements.
  698. //
  699. // Semantic Requirements: 15
  700. //
  701. //----------------------------------------------------------------------------
  702. [Test]
  703. public void core0016D()
  704. {
  705. string computedValue = "0";//0;
  706. string expectedValue = "5";//5;
  707. System.Xml.XmlDocument testNode = null;
  708. testResults results = new testResults("Core0016D");
  709. results.description = "The \"getElementsByTagName(tagName)\" method "+
  710. "returns a NodeList of all the Elements with a "+
  711. "given tag name.";
  712. //
  713. // Retrieve the targeted data and invoke its "getElementsByTagName(tagName)"
  714. // method.
  715. //
  716. testNode = util.getDOMDocument();
  717. System.Xml.XmlNodeList elementList = testNode.GetElementsByTagName("name");
  718. //
  719. // Retrieve the length of the list.
  720. //
  721. computedValue = elementList.Count.ToString();
  722. //
  723. // Write out results.
  724. //
  725. results.expected = expectedValue;
  726. results.actual = computedValue;
  727. util.resetData();
  728. Assert.AreEqual (results.expected, results.actual);
  729. }
  730. //------------------------ End test case core-0016D --------------------------
  731. //
  732. //-------------------------- test case core-0017D ----------------------------
  733. //
  734. // Testing feature - The "getElementsByTagName(tagName)" method returns a
  735. // NodeList of all the Elements with a given tagName in
  736. // a pre-order traversal of the tree.
  737. //
  738. // Testing approach - Retrieve the entire DOM document and invoke its
  739. // "getElementsByTagName(tagName)" method with tagName
  740. // equal to "name". The method should return a NodeList
  741. // that contains 5 elements. Further the fourth item in
  742. // the list is retrieved and checked.
  743. //
  744. // Semantic Requirements: 16
  745. //
  746. //----------------------------------------------------------------------------
  747. [Test]
  748. public void core0017D()
  749. {
  750. string computedValue = "0";//0;
  751. string expectedValue = "Jeny Oconnor";
  752. System.Xml.XmlDocument testNode = null;
  753. testResults results = new testResults("Core0017D");
  754. results.description = "The \"getElementsByTagName(tagName)\" method "+
  755. "returns a NodeList of all the Elements with a "+
  756. "given tag name in a preorder traversal of the tree.";
  757. //
  758. // Retrieve the targeted data and invoke its "getElementsByTagName(tagName)"
  759. // method.
  760. //
  761. testNode = util.getDOMDocument();
  762. System.Xml.XmlNodeList elementList = testNode.GetElementsByTagName("name");
  763. //
  764. // Retrieve the fourth item and its data.
  765. //
  766. computedValue = elementList.Item(util.FOURTH).FirstChild.Value;//Data;
  767. //
  768. // Write out results.
  769. //
  770. results.expected = expectedValue;
  771. results.actual = computedValue;
  772. util.resetData();
  773. Assert.AreEqual (results.expected, results.actual);
  774. }
  775. //------------------------ End test case core-0017D --------------------------
  776. //
  777. //-------------------------- test case core-0018D ----------------------------
  778. //
  779. // Testing feature - The "getElementsByTagName(tagName)" method returns a
  780. // NodeList of all the Elements in the tree when the
  781. // tagName is equal to "*".
  782. //
  783. // Testing approach - Retrieve the entire DOM document and invoke its
  784. // "getElementsByTagName(tagName)" method with tagName
  785. // equal to "*". The method should return a NodeList
  786. // that contains 41 elements, which is the total number
  787. // of Elements in the document.
  788. //
  789. // Semantic Requirements: 17
  790. //
  791. //----------------------------------------------------------------------------
  792. [Test]
  793. public void core0018D()
  794. {
  795. string computedValue = "0";//0;
  796. // Mmm, shouldn't the count be 36?
  797. string expectedValue = "36";//37;
  798. System.Xml.XmlDocument testNode = null;
  799. testResults results = new testResults("Core0018D");
  800. results.description = "The \"getElementsByTagName(tagName)\" method "+
  801. "returns a NodeList of all the Elements in the "+
  802. "tree when the tag name is equal to \"*\".";
  803. //
  804. // Retrieve the targeted data and invoke its "getElementsByTagName(tagName)"
  805. // method.
  806. //
  807. testNode = util.getDOMDocument();
  808. System.Xml.XmlNodeList elementList = testNode.GetElementsByTagName("*");
  809. //
  810. // Retrieve the length of the list.
  811. //
  812. computedValue = elementList.Count.ToString();
  813. //
  814. // Write out results.
  815. //
  816. //
  817. results.expected = expectedValue;
  818. results.actual = computedValue;
  819. util.resetData();
  820. Assert.AreEqual (results.expected, results.actual);
  821. }
  822. //------------------------ End test case core-0018D --------------------------
  823. //
  824. //------------------------- test case core-0019D -----------------------------
  825. //
  826. // Testing feature - The "createElement(tagName)" method raises an
  827. // INVALID_CHARACTER_ERR Exception if the
  828. // specified name contains an invalid character.
  829. //
  830. // Testing approach - Retrieve the entire DOM document and invoke its
  831. // "createElement(tagName)" method with the tagName
  832. // equals to the string "invalid^Name" which contains
  833. // an invalid character ("^") in it. The desired
  834. // exception should be raised.
  835. //
  836. // Semantic Requirements: 18
  837. //
  838. //----------------------------------------------------------------------------
  839. [Test]
  840. [Category ("NotDotNet")] // MS DOM is buggy
  841. public void core0019D()
  842. {
  843. string computedValue = "";
  844. System.Xml.XmlDocument testNode = null;
  845. System.Xml.XmlElement invalidElement = null;
  846. string expectedValue = util.INVALID_CHARACTER_ERR;
  847. testResults results = new testResults("Core0019D");
  848. results.description = "The \"createElement(tagName)\" method raises an "+
  849. "INVALID_CHARACTER_ERR Exception if the "+
  850. "specified name contains an invalid character.";
  851. //
  852. // Retrieve the targeted data.
  853. //
  854. testNode = util.getDOMDocument();
  855. //
  856. // Attempt to create an Element with an invalid tagName should raise
  857. // an exception.
  858. //
  859. try
  860. {
  861. invalidElement = testNode.CreateElement("invalid^Name");
  862. }
  863. catch(System.Exception ex)
  864. {
  865. computedValue = ex.GetType ().FullName;
  866. }
  867. //
  868. // Write out results.
  869. //
  870. results.expected = typeof (XmlException).FullName; // MS.NET BUG: It never raises an error.
  871. results.actual = computedValue;
  872. util.resetData();
  873. Assert.AreEqual (results.expected, results.actual);
  874. }
  875. //------------------------ End test case core-0019D -------------------------
  876. //
  877. //------------------------- test case core-0020D -----------------------------
  878. //
  879. // Testing feature - The "createAttribute(name)" method raises an
  880. // INVALID_CHARACTER_ERR Exception if the
  881. // specified name contains an invalid character.
  882. //
  883. // Testing approach - Retrieve the entire DOM document and invoke its
  884. // "createAttribute(name)" method with the name
  885. // equals to the string "invalid^Name" which contains
  886. // an invalid character ("^") in it. The desired
  887. // exception should be raised.
  888. //
  889. // Semantic Requirements: 19
  890. //
  891. //----------------------------------------------------------------------------
  892. [Test]
  893. [Category ("NotDotNet")] // MS DOM is buggy
  894. public void core0020D()
  895. {
  896. string computedValue = "";
  897. string expectedValue = util.INVALID_CHARACTER_ERR;
  898. System.Xml.XmlDocument testNode = null;
  899. System.Xml.XmlAttribute invalidAttr = null;
  900. testResults results = new testResults("Core0020D");
  901. results.description = "The \"createAttribute(name)\" method raises an "+
  902. "INVALID_CHARACTER_ERR Exception if the "+
  903. "specified name contains an invalid character.";
  904. //
  905. // Retrieve the targeted data.
  906. //
  907. testNode = util.getDOMDocument();
  908. //
  909. // Attempt to create an Attr node with an invalid name should raise
  910. // an exception.
  911. //
  912. try
  913. {
  914. invalidAttr = testNode.CreateAttribute("invalid^Name");
  915. }
  916. catch(System.Exception ex)
  917. {
  918. computedValue = ex.GetType ().FullName;
  919. }
  920. //
  921. // Write out results.
  922. //
  923. results.expected = typeof (ArgumentException).FullName; // MS.NET BUG: It never raises an error.
  924. results.actual = computedValue;
  925. util.resetData();
  926. Assert.AreEqual (results.expected, results.actual);
  927. }
  928. //------------------------ End test case core-0020D -------------------------
  929. //
  930. //------------------------- test case core-0021D -----------------------------
  931. //
  932. // Testing feature - The "createEntityReference(name)" method raises an
  933. // INVALID_CHARACTER_ERR Exception if the
  934. // specified name contains an invalid character.
  935. //
  936. // Testing approach - Retrieve the entire DOM document and invoke its
  937. // "createEntityReference(name)" method with the name
  938. // equals to the string "invalid^Name" which contains
  939. // an invalid character ("^") in it. The desired
  940. // exception should be raised.
  941. //
  942. // Semantic Requirements: 20
  943. //
  944. //----------------------------------------------------------------------------
  945. [Test]
  946. [Category ("NotDotNet")] // MS DOM is buggy
  947. public void core0021D()
  948. {
  949. string computedValue = "";
  950. string expectedValue = "System.Xml.XmlException";//util.INVALID_CHARACTER_ERR;
  951. System.Xml.XmlDocument testNode = null;
  952. System.Xml.XmlEntityReference invalidEntRef = null;
  953. testResults results = new testResults("Core0021D");
  954. results.description = "The \"createEntityReference(name)\" method raises "+
  955. "an INVALID_CHARACTER_ERR Exception if the "+
  956. "specified name contains an invalid character.";
  957. //
  958. // Retrieve the targeted data.
  959. //
  960. testNode = util.getDOMDocument();
  961. //
  962. // Attempt to create an EntityReference node with an invalid name should
  963. // raise an exception.
  964. //
  965. try
  966. {
  967. invalidEntRef = testNode.CreateEntityReference("invalid^Name");
  968. }
  969. catch(XmlException ex)
  970. {
  971. computedValue = ex.GetType ().FullName;
  972. }
  973. //
  974. // Write out results.
  975. //
  976. results.expected = expectedValue;
  977. results.actual = computedValue;
  978. util.resetData();
  979. Assert.AreEqual (results.expected, results.actual);
  980. }
  981. //------------------------ End test case core-0021D -------------------------
  982. //
  983. //------------------------- test case core-0022D ----------------------------
  984. //
  985. // Testing feature - The "createProcessingInstruction(target,data)" method
  986. // raises an INVALID_CHARACTER_ERR Exception if an
  987. // invalid character was specified. (test for invalid
  988. // target)
  989. //
  990. // Testing approach - Retrieve the entire DOM document and invoke its
  991. // "createProcessingInstruction(target,data)" method with
  992. // the target equals to the string "invalid^target" which
  993. // contains an invalid character ("^") in it. The desired
  994. // exception should be raised.
  995. //
  996. // Semantic Requirements: 21
  997. //
  998. //----------------------------------------------------------------------------
  999. [Test]
  1000. [Category ("NotDotNet")] // MS DOM is buggy
  1001. public void core0022D()
  1002. {
  1003. string computedValue = "";
  1004. string expectedValue = "System.Xml.XmlException";//util.INVALID_CHARACTER_ERR;
  1005. System.Xml.XmlDocument testNode = null;
  1006. System.Xml.XmlProcessingInstruction invalidPI = null;
  1007. testResults results = new testResults("Core0022D");
  1008. results.description = "The \"createProcessingInstruction(target,data)\" "+
  1009. "method raises an INVALID_CHARACTER_ERR "+
  1010. "DOMException if an invalid character was specified "+ "(invalid target).";
  1011. //
  1012. // Retrieve the targeted data.
  1013. //
  1014. testNode = util.getDOMDocument();
  1015. //
  1016. // Attempt to create a ProcessingInstruction node with an invalid
  1017. // target name should raise an exception.
  1018. //
  1019. try
  1020. {
  1021. invalidPI = testNode.CreateProcessingInstruction("invalid^target","data");
  1022. }
  1023. catch(XmlException ex)
  1024. {
  1025. computedValue = ex.GetType ().FullName;
  1026. }
  1027. //
  1028. // Write out results.
  1029. //
  1030. results.expected = expectedValue;
  1031. results.actual = computedValue;
  1032. util.resetData();
  1033. Assert.AreEqual (results.expected, results.actual);
  1034. }
  1035. //------------------------ End test case core-0022D -------------------------
  1036. //
  1037. //------------------------- test case core-0023D ----------------------------
  1038. //
  1039. // Testing feature - The "createCDATASection(data)" method raises a
  1040. // NOT_SUPPORTED_ERR Exception if this is an
  1041. // HTML document.
  1042. //
  1043. // Testing approach - Retrieve an HTML based DOM document and invoke its
  1044. // "createCDATASection(data)" method. Since this DOM
  1045. // document was based on an HTML document, the desired
  1046. // exception should be raised.
  1047. //
  1048. // System.Xml - Microsoft System.Xml does not supporting this requirement
  1049. //
  1050. // Semantic Requirements: 22
  1051. //
  1052. //----------------------------------------------------------------------------
  1053. [Test]
  1054. public void core0023D()
  1055. {
  1056. string computedValue = "";
  1057. string expectedValue = "";//util.NOT_SUPPORTED_ERR;
  1058. System.Xml.XmlDocument testNode = null;
  1059. System.Xml.XmlCDataSection invalidCData = null;
  1060. testResults results = new testResults("Core0023D");
  1061. results.description = "The \"createCDATASection(data)\" …

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