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

/ATF2/control-software/epics-3.14.8/extensions/src/ChannelArchiver/ThirdParty/xerces-c-src2_4_0/tests/DOM/DOMMemTest/DOMMemTest.cpp

http://atf2flightsim.googlecode.com/
C++ | 1525 lines | 797 code | 431 blank | 297 comment | 191 complexity | 38b1d273cbe444a5dcb77ee40faeda31 MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.0, IPL-1.0, BSD-3-Clause

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

  1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 2002 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution,
  20. * if any, must include the following acknowledgment:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowledgment may appear in the software itself,
  24. * if and wherever such third-party acknowledgments normally appear.
  25. *
  26. * 4. The names "Xerces" and "Apache Software Foundation" must
  27. * not be used to endorse or promote products derived from this
  28. * software without prior written permission. For written
  29. * permission, please contact apache\@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache",
  32. * nor may "Apache" appear in their name, without prior written
  33. * permission of the Apache Software Foundation.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation, and was
  51. * originally based on software copyright (c) 2002, International
  52. * Business Machines, Inc., http://www.ibm.com . For more information
  53. * on the Apache Software Foundation, please see
  54. * <http://www.apache.org/>.
  55. */
  56. //
  57. // Various DOM tests.
  58. // This is NOT a complete test of DOM functionality.
  59. //
  60. /*
  61. * $Id: DOMMemTest.cpp,v 1.1.1.1 2009/03/14 06:42:15 whitegr Exp $
  62. */
  63. #include <stdio.h>
  64. #include <string.h>
  65. #include <xercesc/dom/DOM.hpp>
  66. #include <xercesc/util/PlatformUtils.hpp>
  67. #include <xercesc/util/XMLException.hpp>
  68. #include <xercesc/util/XMLString.hpp>
  69. #include <xercesc/util/XMLUniDefs.hpp>
  70. XERCES_CPP_NAMESPACE_USE
  71. bool errorOccurred = false;
  72. #define TASSERT(c) tassert((c), __FILE__, __LINE__)
  73. void tassert(bool c, const char *file, int line)
  74. {
  75. if (!c) {
  76. printf("Failure. Line %d, file %s\n", line, file);
  77. errorOccurred = true;
  78. }
  79. };
  80. #define EXCEPTION_TEST(operation, expected_exception) \
  81. { \
  82. try { \
  83. operation; \
  84. printf(" Error: no exception thrown at line %d\n", __LINE__); \
  85. errorOccurred = true; \
  86. } \
  87. catch (DOMException &e) { \
  88. if (e.code != expected_exception) { \
  89. printf(" Wrong exception code: %d at line %d\n", e.code, __LINE__); \
  90. errorOccurred = true; \
  91. } \
  92. } \
  93. catch (...) { \
  94. printf(" Wrong exception thrown at line %d\n", __LINE__); \
  95. errorOccurred = true; \
  96. } \
  97. }
  98. // ---------------------------------------------------------------------------
  99. // This is a simple class that lets us do easy (though not terribly efficient)
  100. // trancoding of char* data to XMLCh data.
  101. // ---------------------------------------------------------------------------
  102. class XStr
  103. {
  104. public :
  105. // -----------------------------------------------------------------------
  106. // Constructors and Destructor
  107. // -----------------------------------------------------------------------
  108. XStr(const char* const toTranscode)
  109. {
  110. // Call the private transcoding method
  111. fUnicodeForm = XMLString::transcode(toTranscode);
  112. }
  113. ~XStr()
  114. {
  115. XMLString::release(&fUnicodeForm);
  116. }
  117. // -----------------------------------------------------------------------
  118. // Getter methods
  119. // -----------------------------------------------------------------------
  120. const XMLCh* unicodeForm() const
  121. {
  122. return fUnicodeForm;
  123. }
  124. private :
  125. // -----------------------------------------------------------------------
  126. // Private data members
  127. //
  128. // fUnicodeForm
  129. // This is the Unicode XMLCh format of the string.
  130. // -----------------------------------------------------------------------
  131. XMLCh* fUnicodeForm;
  132. };
  133. #define X(str) XStr(str).unicodeForm()
  134. //---------------------------------------------------------------------------------------
  135. //
  136. // DOMBasicTests Basic DOM Level 1 tests
  137. //
  138. //---------------------------------------------------------------------------------------
  139. void DOMBasicTests()
  140. {
  141. //
  142. // Test Doc01 Create a new empty document
  143. //
  144. {
  145. // First precondition, so that lazily created strings do not appear
  146. // as memory leaks.
  147. DOMDocument* doc;
  148. doc = DOMImplementationRegistry::getDOMImplementation(X("Core"))->createDocument();
  149. doc->release();
  150. }
  151. //
  152. // Test Doc02 Create one of each kind of node using the
  153. // document createXXX methods.
  154. // Watch for memory leaks.
  155. //
  156. {
  157. // Do all operations in a preconditioning step, to force the
  158. // creation of implementation objects that are set up on first use.
  159. // Don't watch for leaks in this block (no / )
  160. DOMDocument* doc = DOMImplementationRegistry::getDOMImplementation(X("Core"))->createDocument();
  161. DOMElement* el = doc->createElement(X("Doc02Element"));
  162. DOMDocumentFragment* frag = doc->createDocumentFragment ();
  163. DOMText* text = doc->createTextNode(X("Doc02TextNode"));
  164. DOMComment* comment = doc->createComment(X("Doc02Comment"));
  165. DOMCDATASection* cdataSec = doc->createCDATASection(X("Doc02CDataSection"));
  166. DOMDocumentType* docType = doc->createDocumentType(X("Doc02DocumentType"));
  167. DOMNotation* notation = doc->createNotation(X("Doc02Notation"));
  168. DOMProcessingInstruction* pi = doc->createProcessingInstruction(X("Doc02PITarget"), X("Doc02PIData"));
  169. DOMNodeList* nodeList = doc->getElementsByTagName(X("*"));
  170. doc->release();
  171. }
  172. //
  173. // Doc03 - Create a small document tree
  174. //
  175. {
  176. DOMDocument* doc = DOMImplementationRegistry::getDOMImplementation(X("Core"))->createDocument();
  177. DOMElement* rootEl = doc->createElement(X("Doc03RootElement"));
  178. doc->appendChild(rootEl);
  179. DOMText* textNode = doc->createTextNode(X("Doc03 text stuff"));
  180. rootEl->appendChild(textNode);
  181. DOMNodeList* nodeList = doc->getElementsByTagName(X("*"));
  182. doc->release();
  183. };
  184. //
  185. // Attr01
  186. //
  187. {
  188. DOMDocument* doc = DOMImplementationRegistry::getDOMImplementation(X("Core"))->createDocument();
  189. DOMElement* rootEl = doc->createElement(X("RootElement"));
  190. doc->appendChild(rootEl);
  191. {
  192. DOMAttr* attr01 = doc->createAttribute(X("Attr01"));
  193. DOMNode* rem = rootEl->setAttributeNode(attr01);
  194. if (rem)
  195. rem->release();
  196. }
  197. {
  198. DOMAttr* attr02 = doc->createAttribute(X("Attr01"));
  199. DOMNode* rem = rootEl->setAttributeNode(attr02);
  200. if (rem)
  201. rem->release();
  202. }
  203. doc->release();
  204. };
  205. //
  206. // Attr02
  207. //
  208. {
  209. DOMDocument* doc = DOMImplementationRegistry::getDOMImplementation(X("Core"))->createDocument();
  210. DOMElement* rootEl = doc->createElement(X("RootElement"));
  211. doc->appendChild(rootEl);
  212. DOMAttr* attr01 = doc->createAttribute(X("Attr02"));
  213. DOMNode* rem = rootEl->setAttributeNode(attr01);
  214. if (rem)
  215. rem->release();
  216. DOMAttr* attr02 = doc->createAttribute(X("Attr02"));
  217. rem = rootEl->setAttributeNode(attr02);
  218. if (rem)
  219. rem->release();
  220. doc->release();
  221. }
  222. //
  223. // Attr03
  224. //
  225. {
  226. DOMDocument* doc = DOMImplementationRegistry::getDOMImplementation(X("Core"))->createDocument();
  227. DOMElement* rootEl = doc->createElement(X("RootElement"));
  228. doc->appendChild(rootEl);
  229. DOMAttr* attr01 = doc->createAttribute(X("Attr03"));
  230. DOMNode* rem = rootEl->setAttributeNode(attr01);
  231. if (rem)
  232. rem->release();
  233. attr01->setValue(X("Attr03Value1"));
  234. attr01->setValue(X("Attr03Value2"));
  235. doc->release();
  236. }
  237. //
  238. // Attr04
  239. //
  240. {
  241. DOMDocument* doc = DOMImplementationRegistry::getDOMImplementation(X("Core"))->createDocument();
  242. DOMElement* rootEl = doc->createElement(X("RootElement"));
  243. doc->appendChild(rootEl);
  244. DOMAttr* attr01 = doc->createAttribute(X("Attr04"));
  245. DOMNode* rem = rootEl->setAttributeNode(attr01);
  246. if (rem)
  247. rem->release();
  248. attr01->setValue(X("Attr04Value1"));
  249. DOMNode* value = attr01->getFirstChild();
  250. doc->release();
  251. }
  252. //
  253. // Text01
  254. //
  255. {
  256. DOMDocument* doc = DOMImplementationRegistry::getDOMImplementation(X("Core"))->createDocument();
  257. DOMElement* rootEl = doc->createElement(X("RootElement"));
  258. doc->appendChild(rootEl);
  259. DOMText* txt1 = doc->createTextNode(X("Hello Goodbye"));
  260. rootEl->appendChild(txt1);
  261. txt1->splitText(6);
  262. rootEl->normalize();
  263. doc->release();
  264. }
  265. //
  266. // Notation01
  267. //
  268. {
  269. DOMDocument* doc = DOMImplementationRegistry::getDOMImplementation(X("Core"))->createDocument();
  270. DOMDocumentType* dt = doc->createDocumentType(X("DocType_for_Notation01"));
  271. doc->appendChild(dt);
  272. DOMNamedNodeMap* notationMap = dt->getNotations();
  273. DOMNotation* nt1 = doc->createNotation(X("Notation01"));
  274. DOMNode* rem = notationMap->setNamedItem (nt1);
  275. if (rem)
  276. rem->release();
  277. DOMNode* abc1 = notationMap->getNamedItem(X("Notation01"));
  278. DOMNotation* nt2 = (DOMNotation*) abc1;
  279. TASSERT(nt1==nt2);
  280. nt2 = 0;
  281. nt1 = 0;
  282. DOMNode* abc6 = notationMap->getNamedItem(X("Notation01"));
  283. nt2 = (DOMNotation*) abc6;
  284. doc->release();
  285. }
  286. //
  287. // NamedNodeMap01 - comparison operators.
  288. //
  289. {
  290. DOMNamedNodeMap* nnm = 0;
  291. TASSERT(nnm == 0);
  292. DOMDocument* doc = DOMImplementationRegistry::getDOMImplementation(X("Core"))->createDocument();
  293. nnm = doc->getAttributes(); // Should be null, because node type
  294. // is not Element.
  295. TASSERT(nnm == 0);
  296. TASSERT(!(nnm != 0));
  297. DOMElement* el = doc->createElement(X("NamedNodeMap01"));
  298. DOMNamedNodeMap* nnm2 = el->getAttributes(); // Should be an empty, but non-null map.
  299. TASSERT(nnm2 != 0);
  300. TASSERT(nnm != nnm2);
  301. nnm = nnm2;
  302. TASSERT(nnm == nnm2);
  303. doc->release();
  304. }
  305. //
  306. // importNode quick test
  307. //
  308. {
  309. DOMDocument* doc1 = DOMImplementationRegistry::getDOMImplementation(X("Core"))->createDocument();
  310. DOMDocument* doc2 = DOMImplementationRegistry::getDOMImplementation(X("Core"))->createDocument();
  311. DOMElement* el1 = doc1->createElement(X("abc"));
  312. doc1->appendChild(el1);
  313. TASSERT(el1->getParentNode() != 0);
  314. DOMNode* el2 = doc2->importNode(el1, true);
  315. TASSERT(el2->getParentNode() == 0);
  316. const XMLCh* tagName = el2->getNodeName();
  317. TASSERT(!XMLString::compareString(tagName, X("abc")));
  318. TASSERT(el2->getOwnerDocument() == doc2);
  319. TASSERT(doc1 != doc2);
  320. doc1->release();
  321. doc2->release();
  322. }
  323. //
  324. // getLength() tests. Both Node CharacterData and NodeList implement
  325. // getLength(). Early versions of the DOM had a clash
  326. // between the two, originating in the implementation class
  327. // hirearchy, which has NodeList as a (distant) base class
  328. // of CharacterData. This is a regression test to verify
  329. // that the problem stays fixed.
  330. //
  331. {
  332. DOMDocument* doc = DOMImplementationRegistry::getDOMImplementation(X("Core"))->createDocument();
  333. DOMText* tx = doc->createTextNode(X("Hello"));
  334. DOMElement* el = doc->createElement(X("abc"));
  335. el->appendChild(tx);
  336. int textLength = tx->getLength();
  337. TASSERT(textLength == 5);
  338. DOMNodeList* nl = tx->getChildNodes();
  339. int nodeListLen = nl->getLength();
  340. TASSERT(nodeListLen == 0);
  341. nl = el->getChildNodes();
  342. nodeListLen = nl->getLength();
  343. TASSERT(nodeListLen == 1);
  344. doc->release();
  345. }
  346. //
  347. // NodeList - comparison operators, basic operation.
  348. //
  349. {
  350. DOMNodeList* nl = 0;
  351. DOMNodeList* nl2 = 0;
  352. TASSERT(nl == 0);
  353. TASSERT(!(nl != 0));
  354. TASSERT(nl == nl2);
  355. DOMDocument* doc = DOMImplementationRegistry::getDOMImplementation(X("Core"))->createDocument();
  356. nl = doc->getChildNodes(); // Should be non-null, but empty
  357. TASSERT(nl != 0);
  358. int len = nl->getLength();
  359. TASSERT(len == 0);
  360. DOMElement* el = doc->createElement(X("NodeList01"));
  361. doc->appendChild(el);
  362. len = nl->getLength();
  363. TASSERT(len == 1);
  364. TASSERT(nl != nl2);
  365. nl2 = nl;
  366. TASSERT(nl == nl2);
  367. doc->release();
  368. }
  369. //
  370. // Name validity checking.
  371. //
  372. {
  373. DOMDocument* doc = DOMImplementationRegistry::getDOMImplementation(X("Core"))->createDocument();
  374. try
  375. {
  376. DOMElement* el = doc->createElement(X("!@@ bad element name"));
  377. TASSERT(false); // Exception above should prevent us reaching here.
  378. }
  379. catch ( DOMException e)
  380. {
  381. TASSERT(e.code == DOMException::INVALID_CHARACTER_ERR);
  382. }
  383. catch (...)
  384. {
  385. TASSERT(false); // Wrong exception thrown.
  386. }
  387. doc->release();
  388. }
  389. //
  390. // Assignment ops return value
  391. //
  392. {
  393. DOMDocument* doc = DOMImplementationRegistry::getDOMImplementation(X("Core"))->createDocument();
  394. DOMElement* el = doc->createElement(X("NodeList01"));
  395. doc->appendChild(el);
  396. DOMElement* n1, *n2, *n3;
  397. n1 = n2 = n3 = el;
  398. TASSERT(n1 == n2);
  399. TASSERT(n1 == n3);
  400. TASSERT(n1 == el);
  401. TASSERT(n1 != 0);
  402. n1 = n2 = n3 = 0;
  403. TASSERT(n1 == 0);
  404. doc->release();
  405. }
  406. //
  407. // Cloning of a node with attributes. Regression test for a ref counting
  408. // bug in attributes of cloned nodes that occured when the "owned" flag
  409. // was not set in the clone.
  410. //
  411. {
  412. DOMDocument* doc = DOMImplementationRegistry::getDOMImplementation(X("Core"))->createDocument();
  413. DOMElement* root = doc->createElement(X("CTestRoot"));
  414. root->setAttribute(X("CTestAttr"), X("CTestAttrValue"));
  415. const XMLCh* s = root->getAttribute(X("CTestAttr"));
  416. TASSERT(!XMLString::compareString(s, X("CTestAttrValue")));
  417. DOMNode* abc2 = root->cloneNode(true);
  418. DOMElement* cloned = (DOMElement*) abc2;
  419. DOMAttr* a = cloned->getAttributeNode(X("CTestAttr"));
  420. TASSERT(a != 0);
  421. s = a->getValue();
  422. TASSERT(!XMLString::compareString(s, X("CTestAttrValue")));
  423. a = 0;
  424. a = cloned->getAttributeNode(X("CTestAttr"));
  425. TASSERT(a != 0);
  426. s = a->getValue();
  427. TASSERT(!XMLString::compareString(s, X("CTestAttrValue")));
  428. doc->release();
  429. }
  430. //
  431. // splitText()
  432. // Regression test for a bug from Tinny Ng
  433. //
  434. {
  435. DOMDocument* doc;
  436. doc = DOMImplementationRegistry::getDOMImplementation(X("Core"))->createDocument();
  437. DOMText* tn, *tn1, *tn2;
  438. tn = doc->createTextNode (X("0123456789"));
  439. tn1 = tn->splitText(5);
  440. TASSERT(!XMLString::compareString(tn->getNodeValue(), X("01234")));
  441. TASSERT(!XMLString::compareString(tn1->getNodeValue(), X("56789")));
  442. tn2 = tn->splitText(5);
  443. TASSERT(!XMLString::compareString(tn->getNodeValue(), X("01234")));
  444. TASSERT(!XMLString::compareString(tn2->getNodeValue(), XMLUni::fgZeroLenString));
  445. EXCEPTION_TEST(tn->splitText(6), DOMException::INDEX_SIZE_ERR);
  446. doc->release();
  447. }
  448. }
  449. //---------------------------------------------------------------------------------------
  450. //
  451. // DOMNSTests DOM Name Space tests
  452. //
  453. //---------------------------------------------------------------------------------------
  454. void DOMNSTests()
  455. {
  456. //
  457. // DOM Level 2 tests. These should be split out as a separate test.
  458. //
  459. //
  460. // hasFeature. The set of supported options tested here is for Xerces 1.1
  461. // Note: because the implementation lazily creates some of the comprison
  462. // strings within the implementation, this test must be pre-flighted
  463. // outside of the TESPROLOG/ macros to avoid spurious
  464. // reports of memory leaks.
  465. //
  466. // Also test the case-insensitive
  467. //
  468. {
  469. DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(X("Core"));
  470. TASSERT(impl->hasFeature(X("XmL"), X("2.0")) == true);
  471. TASSERT(impl->hasFeature(X("xML"), 0) == true);
  472. TASSERT(impl->hasFeature(X("xML"), XMLUni::fgZeroLenString) == true);
  473. TASSERT(impl->hasFeature(X("XMl"), X("1.0")) == true);
  474. TASSERT(impl->hasFeature(X("xMl"), X("3.0")) == false);
  475. TASSERT(impl->hasFeature(X("TrAveRsal"), 0) == true);
  476. TASSERT(impl->hasFeature(X("TrAveRsal"), XMLUni::fgZeroLenString) == true);
  477. }
  478. {
  479. DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(X("Core"));
  480. TASSERT(impl->hasFeature(X("XmL"), 0) == true);
  481. TASSERT(impl->hasFeature(X("XmL"), X("1.0")) == true);
  482. TASSERT(impl->hasFeature(X("XmL"), X("2.0")) == true);
  483. TASSERT(impl->hasFeature(X("XmL"), X("3.0")) == false);
  484. TASSERT(impl->hasFeature(X("Core"), 0) == true);
  485. TASSERT(impl->hasFeature(X("coRe"), X("1.0")) == true);
  486. TASSERT(impl->hasFeature(X("core"), X("2.0")) == true);
  487. TASSERT(impl->hasFeature(X("cORe"), X("3.0")) == true);
  488. TASSERT(impl->hasFeature(X("cORe"), X("4.0")) == false);
  489. TASSERT(impl->hasFeature(X("Traversal"), XMLUni::fgZeroLenString) == true);
  490. TASSERT(impl->hasFeature(X("traversal"), X("1.0")) == false);
  491. TASSERT(impl->hasFeature(X("TraVersal"), X("2.0")) == true);
  492. TASSERT(impl->hasFeature(X("Range"), 0) == true);
  493. TASSERT(impl->hasFeature(X("raNge"), X("1.0")) == false);
  494. TASSERT(impl->hasFeature(X("RaNge"), X("2.0")) == true);
  495. TASSERT(impl->hasFeature(X("HTML"), 0) == false);
  496. TASSERT(impl->hasFeature(X("Views"), XMLUni::fgZeroLenString) == false);
  497. TASSERT(impl->hasFeature(X("StyleSheets"), 0) == false);
  498. TASSERT(impl->hasFeature(X("CSS"), XMLUni::fgZeroLenString) == false);
  499. TASSERT(impl->hasFeature(X("CSS2"), 0) == false);
  500. TASSERT(impl->hasFeature(X("Events"), 0) == false);
  501. TASSERT(impl->hasFeature(X("UIEvents"), 0) == false);
  502. TASSERT(impl->hasFeature(X("MouseEvents"), 0) == false);
  503. TASSERT(impl->hasFeature(X("MutationEvents"), 0) == false);
  504. TASSERT(impl->hasFeature(X("HTMLEvents"), 0) == false);
  505. }
  506. //
  507. // isSupported test (similar to hasFeature)
  508. //
  509. {
  510. DOMDocument* doc;
  511. doc = DOMImplementationRegistry::getDOMImplementation(X("Core"))->createDocument();
  512. TASSERT(doc->isSupported(X("XmL"), 0) == true);
  513. TASSERT(doc->isSupported(X("XmL"), X("1.0")) == true);
  514. TASSERT(doc->isSupported(X("XmL"), X("2.0")) == true);
  515. TASSERT(doc->isSupported(X("XmL"), X("3.0")) == false);
  516. TASSERT(doc->isSupported(X("Core"), 0) == true);
  517. TASSERT(doc->isSupported(X("Core"), XMLUni::fgZeroLenString) == true);
  518. TASSERT(doc->isSupported(X("coRe"), X("1.0")) == true);
  519. TASSERT(doc->isSupported(X("core"), X("2.0")) == true);
  520. TASSERT(doc->isSupported(X("cORe"), X("3.0")) == true);
  521. TASSERT(doc->isSupported(X("cORe"), X("4.0")) == false);
  522. TASSERT(doc->isSupported(X("Traversal"), 0) == true);
  523. TASSERT(doc->isSupported(X("traversal"), X("1.0")) == false);
  524. TASSERT(doc->isSupported(X("TraVersal"), X("2.0")) == true);
  525. TASSERT(doc->isSupported(X("Range"), XMLUni::fgZeroLenString) == true);
  526. TASSERT(doc->isSupported(X("raNge"), X("1.0")) == false);
  527. TASSERT(doc->isSupported(X("RaNge"), X("2.0")) == true);
  528. TASSERT(doc->isSupported(X("HTML"), 0) == false);
  529. TASSERT(doc->isSupported(X("Views"), 0) == false);
  530. TASSERT(doc->isSupported(X("StyleSheets"), 0) == false);
  531. TASSERT(doc->isSupported(X("CSS"), 0) == false);
  532. TASSERT(doc->isSupported(X("CSS2"), XMLUni::fgZeroLenString) == false);
  533. TASSERT(doc->isSupported(X("Events"), 0) == false);
  534. TASSERT(doc->isSupported(X("UIEvents"), 0) == false);
  535. TASSERT(doc->isSupported(X("MouseEvents"), 0) == false);
  536. TASSERT(doc->isSupported(X("MutationEvents"), XMLUni::fgZeroLenString) == false);
  537. TASSERT(doc->isSupported(X("HTMLEvents"), 0) == false);
  538. doc->release();
  539. }
  540. //
  541. // CreateDocumentType
  542. //
  543. {
  544. DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(X("Core"));
  545. DOMDocumentType* dt = impl->createDocumentType(X("foo:docName"), X("pubId"), X("http://sysId"));
  546. TASSERT(dt != 0);
  547. TASSERT(dt->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE);
  548. TASSERT(!XMLString::compareString(dt->getNodeName(), X("foo:docName")));
  549. TASSERT(dt->getNamespaceURI() == 0);
  550. TASSERT(dt->getPrefix() == 0);
  551. TASSERT(dt->getLocalName() == 0);
  552. TASSERT(!XMLString::compareString(dt->getPublicId(), X("pubId")));
  553. TASSERT(!XMLString::compareString(dt->getSystemId(), X("http://sysId")));
  554. TASSERT(dt->getInternalSubset() == 0);
  555. TASSERT(dt->getOwnerDocument() == 0);
  556. DOMNamedNodeMap* nnm = dt->getEntities();
  557. TASSERT(nnm->getLength() == 0);
  558. nnm = dt->getNotations();
  559. TASSERT(nnm->getLength() == 0);
  560. // release the documentType (dt) which is an orphaned node (does not have the owner)
  561. dt->release();
  562. //
  563. // Qualified name without prefix should also work.
  564. //
  565. dt = impl->createDocumentType(X("docName"), X("pubId"), X("http://sysId"));
  566. TASSERT(dt != 0);
  567. TASSERT(dt->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE);
  568. TASSERT(!XMLString::compareString(dt->getNodeName(), X("docName")));
  569. TASSERT(dt->getNamespaceURI() == 0);
  570. TASSERT(dt->getPrefix() == 0);
  571. TASSERT(dt->getLocalName() == 0);
  572. TASSERT(!XMLString::compareString(dt->getPublicId(), X("pubId")));
  573. TASSERT(!XMLString::compareString(dt->getSystemId(), X("http://sysId")));
  574. TASSERT(dt->getInternalSubset() == 0);
  575. TASSERT(dt->getOwnerDocument() == 0);
  576. // Creating a DocumentType with invalid or malformed qName should fail.
  577. EXCEPTION_TEST(impl->createDocumentType(X("<docName"), X("pubId"), X("http://sysId")), DOMException::INVALID_CHARACTER_ERR);
  578. EXCEPTION_TEST(impl->createDocumentType(X(":docName"), X("pubId"), X("http://sysId")), DOMException::NAMESPACE_ERR);
  579. EXCEPTION_TEST(impl->createDocumentType(X("docName:"), X("pubId"), X("http://sysId")), DOMException::NAMESPACE_ERR);
  580. EXCEPTION_TEST(impl->createDocumentType(X("doc::Name"), X("pubId"), X("http://sysId")), DOMException::NAMESPACE_ERR);
  581. EXCEPTION_TEST(impl->createDocumentType(X("doc:N:ame"), X("pubId"), X("http://sysId")), DOMException::NAMESPACE_ERR);
  582. // release the documentType (dt) which is an orphaned node (does not have the owner)
  583. dt->release();
  584. }
  585. //
  586. // DOMImplementation::CreateDocument
  587. {
  588. DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(X("Core"));
  589. DOMDocumentType* dt = 0;
  590. DOMDocument* doc = impl->createDocument(XMLUni::fgZeroLenString, X("a"), dt);
  591. doc->getNodeName();
  592. doc->release();
  593. }
  594. //
  595. {
  596. DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(X("Core"));
  597. DOMDocumentType* dt = impl->createDocumentType(X("foo:docName"), X("pubId"), X("http://sysId"));
  598. DOMDocument* doc = impl->createDocument(X("http://document.namespace"), X("foo:docName"), dt);
  599. TASSERT(dt->getOwnerDocument() == doc);
  600. TASSERT(doc->getOwnerDocument() == 0);
  601. TASSERT(doc->getNodeType() == DOMNode::DOCUMENT_NODE);
  602. TASSERT(doc->getDoctype() == dt);
  603. TASSERT(!XMLString::compareString(doc->getNodeName(), X("#document")));
  604. TASSERT(doc->getNodeValue() == 0);
  605. TASSERT(doc->getNamespaceURI() == 0);
  606. TASSERT(doc->getPrefix() == 0);
  607. TASSERT(doc->getLocalName() == 0);
  608. DOMElement* el = doc->getDocumentElement();
  609. TASSERT(!XMLString::compareString(el->getLocalName(), X("docName")));
  610. TASSERT(!XMLString::compareString(el->getNamespaceURI(), X("http://document.namespace")));
  611. TASSERT(!XMLString::compareString(el->getNodeName(), X("foo:docName")));
  612. TASSERT(el->getOwnerDocument() == doc);
  613. TASSERT(el->getParentNode() == doc);
  614. TASSERT(!XMLString::compareString(el->getPrefix(), X("foo")));
  615. TASSERT(!XMLString::compareString(el->getTagName(), X("foo:docName")));
  616. TASSERT(el->hasChildNodes() == false);
  617. //
  618. // Creating a second document with the same docType object should fail.
  619. //
  620. try
  621. {
  622. DOMDocument* doc2 = impl->createDocument(X("pubId"), X("foo:docName"), dt);
  623. TASSERT(false); // should not reach here.
  624. }
  625. catch ( DOMException &e)
  626. {
  627. TASSERT(e.code == DOMException::WRONG_DOCUMENT_ERR);
  628. }
  629. catch (...)
  630. {
  631. TASSERT(false); // Wrong exception thrown.
  632. }
  633. // release the document, the documentType (dt) still has the owner, and thus no need to release
  634. doc->release();
  635. // Creating a document with null NamespaceURI and DocumentType
  636. doc = impl->createDocument(X("pubId"), X("foo:docName"), 0);
  637. doc->release();
  638. // Namespace tests of createDocument are covered by createElementNS below
  639. }
  640. //
  641. // CreateElementNS methods
  642. //
  643. {
  644. // Set up an initial (root element only) document.
  645. //
  646. DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(X("Core"));
  647. DOMDocumentType* dt = impl->createDocumentType(X("foo:docName"), X("pubId"), X("http://sysId"));
  648. DOMDocument* doc = impl->createDocument(X("http://document.namespace"), X("foo:docName"), dt);
  649. DOMElement* rootEl = doc->getDocumentElement();
  650. //
  651. // CreateElementNS
  652. //
  653. DOMElement* ela = doc->createElementNS(X("http://nsa"), X("a:ela")); // prefix and URI
  654. TASSERT(!XMLString::compareString(ela->getNodeName(), X("a:ela")));
  655. TASSERT(!XMLString::compareString(ela->getNamespaceURI(), X("http://nsa")));
  656. TASSERT(!XMLString::compareString(ela->getPrefix(), X("a")));
  657. TASSERT(!XMLString::compareString(ela->getLocalName(), X("ela")));
  658. TASSERT(!XMLString::compareString(ela->getTagName(), X("a:ela")));
  659. DOMElement* elb = doc->createElementNS(X("http://nsb"), X("elb")); // URI, no prefix.
  660. TASSERT(!XMLString::compareString(elb->getNodeName(), X("elb")));
  661. TASSERT(!XMLString::compareString(elb->getNamespaceURI(), X("http://nsb")));
  662. TASSERT(!XMLString::compareString(elb->getPrefix(), XMLUni::fgZeroLenString));
  663. TASSERT(!XMLString::compareString(elb->getLocalName(), X("elb")));
  664. TASSERT(!XMLString::compareString(elb->getTagName(), X("elb")));
  665. DOMElement* elc = doc->createElementNS(XMLUni::fgZeroLenString, X("elc")); // No URI, no prefix.
  666. TASSERT(!XMLString::compareString(elc->getNodeName(), X("elc")));
  667. TASSERT(!XMLString::compareString(elc->getNamespaceURI(), XMLUni::fgZeroLenString));
  668. TASSERT(!XMLString::compareString(elc->getPrefix(), XMLUni::fgZeroLenString));
  669. TASSERT(!XMLString::compareString(elc->getLocalName(), X("elc")));
  670. TASSERT(!XMLString::compareString(elc->getTagName(), X("elc")));
  671. rootEl->appendChild(ela);
  672. rootEl->appendChild(elb);
  673. rootEl->appendChild(elc);
  674. // Badly formed qualified name
  675. EXCEPTION_TEST(doc->createElementNS(X("http://nsa"), X("<a")), DOMException::INVALID_CHARACTER_ERR);
  676. EXCEPTION_TEST(doc->createElementNS(X("http://nsa"), X(":a")), DOMException::NAMESPACE_ERR);
  677. EXCEPTION_TEST(doc->createElementNS(X("http://nsa"), X("a:")), DOMException::NAMESPACE_ERR);
  678. EXCEPTION_TEST(doc->createElementNS(X("http://nsa"), X("a::a")), DOMException::NAMESPACE_ERR);
  679. EXCEPTION_TEST(doc->createElementNS(X("http://nsa"), X("a:a:a")), DOMException::NAMESPACE_ERR);
  680. // xml:a must have namespaceURI == "http://www.w3.org/XML/1998/namespace"
  681. TASSERT(!XMLString::compareString(doc->createElementNS(X("http://www.w3.org/XML/1998/namespace"), X("xml:a"))->getNamespaceURI(), X("http://www.w3.org/XML/1998/namespace")));
  682. EXCEPTION_TEST(doc->createElementNS(X("http://nsa"), X("xml:a")), DOMException::NAMESPACE_ERR);
  683. EXCEPTION_TEST(doc->createElementNS(XMLUni::fgZeroLenString, X("xml:a")), DOMException::NAMESPACE_ERR);
  684. EXCEPTION_TEST(doc->createElementNS(0, X("xml:a")), DOMException::NAMESPACE_ERR);
  685. //unlike Attribute, xmlns (no different from foo) can have any namespaceURI for Element
  686. TASSERT(!XMLString::compareString(doc->createElementNS(X("http://nsa"), X("xmlns"))->getNamespaceURI(), X("http://nsa")));
  687. TASSERT(!XMLString::compareString(doc->createElementNS(X("http://www.w3.org/XML/1998/namespace"), X("xmlns"))->getNamespaceURI(), X("http://www.w3.org/XML/1998/namespace")));
  688. TASSERT(!XMLString::compareString(doc->createElementNS(XMLUni::fgZeroLenString, X("xmlns"))->getNamespaceURI(), XMLUni::fgZeroLenString));
  689. TASSERT(!XMLString::compareString(doc->createElementNS(0, X("xmlns"))->getNamespaceURI(), XMLUni::fgZeroLenString));
  690. //unlike Attribute, xmlns:a (no different from foo:a) can have any namespaceURI for Element
  691. //except "" and null
  692. TASSERT(!XMLString::compareString(doc->createElementNS(X("http://nsa"), X("xmlns:a"))->getNamespaceURI(), X("http://nsa")));
  693. TASSERT(!XMLString::compareString(doc->createElementNS(X("http://www.w3.org/XML/1998/namespace"), X("xmlns:a"))->getNamespaceURI(), X("http://www.w3.org/XML/1998/namespace")));
  694. EXCEPTION_TEST(doc->createElementNS(XMLUni::fgZeroLenString, X("xmlns:a")), DOMException::NAMESPACE_ERR);
  695. EXCEPTION_TEST(doc->createElementNS(0, X("xmlns:a")), DOMException::NAMESPACE_ERR);
  696. //In fact, any prefix != null should have a namespaceURI != 0 or != ""
  697. TASSERT(!XMLString::compareString(doc->createElementNS(X("http://nsa"), X("foo:a"))->getNamespaceURI(), X("http://nsa")));
  698. EXCEPTION_TEST(doc->createElementNS(XMLUni::fgZeroLenString, X("foo:a")), DOMException::NAMESPACE_ERR);
  699. EXCEPTION_TEST(doc->createElementNS(0, X("foo:a")), DOMException::NAMESPACE_ERR);
  700. //Change prefix
  701. DOMElement* elem = doc->createElementNS(X("http://nsa"), X("foo:a"));
  702. elem->setPrefix(X("bar"));
  703. TASSERT(!XMLString::compareString(elem->getNodeName(), X("bar:a")));
  704. TASSERT(!XMLString::compareString(elem->getNamespaceURI(), X("http://nsa")));
  705. TASSERT(!XMLString::compareString(elem->getPrefix(), X("bar")));
  706. TASSERT(!XMLString::compareString(elem->getLocalName(), X("a")));
  707. TASSERT(!XMLString::compareString(elem->getTagName(), X("bar:a")));
  708. //The spec does not prevent us from setting prefix to a node without prefix
  709. elem = doc->createElementNS(X("http://nsa"), X("a"));
  710. TASSERT(!XMLString::compareString(elem->getPrefix(), XMLUni::fgZeroLenString));
  711. elem->setPrefix(X("bar"));
  712. TASSERT(!XMLString::compareString(elem->getNodeName(), X("bar:a")));
  713. TASSERT(!XMLString::compareString(elem->getNamespaceURI(), X("http://nsa")));
  714. TASSERT(!XMLString::compareString(elem->getPrefix(), X("bar")));
  715. TASSERT(!XMLString::compareString(elem->getLocalName(), X("a")));
  716. TASSERT(!XMLString::compareString(elem->getTagName(), X("bar:a")));
  717. //Special case for xml:a where namespaceURI must be xmlURI
  718. elem = doc->createElementNS(X("http://www.w3.org/XML/1998/namespace"), X("foo:a"));
  719. elem->setPrefix(X("xml"));
  720. elem = doc->createElementNS(X("http://nsa"), X("foo:a"));
  721. EXCEPTION_TEST(elem->setPrefix(X("xml")), DOMException::NAMESPACE_ERR);
  722. //However, there is no restriction on prefix xmlns
  723. elem->setPrefix(X("xmlns"));
  724. //Also an element can not have a prefix with namespaceURI == null or ""
  725. elem = doc->createElementNS(0, X("a"));
  726. EXCEPTION_TEST(elem->setPrefix(X("foo")), DOMException::NAMESPACE_ERR);
  727. elem = doc->createElementNS(XMLUni::fgZeroLenString, X("a"));
  728. EXCEPTION_TEST(elem->setPrefix(X("foo")), DOMException::NAMESPACE_ERR);
  729. //Only prefix of Element and Attribute can be changed
  730. EXCEPTION_TEST(doc->setPrefix(X("foo")), DOMException::NAMESPACE_ERR);
  731. //Prefix of readonly Element can not be changed.
  732. //However, there is no way to create such DOMElement* for testing yet.
  733. // release the document, the documentType (dt) still has the owner, and thus no need to release
  734. doc->release();
  735. }
  736. //
  737. // CreateAttributeNS methods
  738. //
  739. {
  740. // Set up an initial (root element only) document.
  741. //
  742. DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(X("Core"));
  743. DOMDocumentType* dt = impl->createDocumentType(X("foo:docName"), X("pubId"), X("http://sysId"));
  744. DOMDocument* doc = impl->createDocument(X("http://document.namespace"), X("foo:docName"), dt);
  745. DOMElement* rootEl = doc->getDocumentElement();
  746. //
  747. // CreateAttributeNS
  748. //
  749. DOMAttr* attra = doc->createAttributeNS(X("http://nsa"), X("a:attra")); // prefix and URI
  750. TASSERT(!XMLString::compareString(attra->getNodeName(), X("a:attra")));
  751. TASSERT(!XMLString::compareString(attra->getNamespaceURI(), X("http://nsa")));
  752. TASSERT(!XMLString::compareString(attra->getPrefix(), X("a")));
  753. TASSERT(!XMLString::compareString(attra->getLocalName(), X("attra")));
  754. TASSERT(!XMLString::compareString(attra->getName(), X("a:attra")));
  755. TASSERT(attra->getOwnerElement() == 0);
  756. DOMAttr* attrb = doc->createAttributeNS(X("http://nsb"), X("attrb")); // URI, no prefix.
  757. TASSERT(!XMLString::compareString(attrb->getNodeName(), X("attrb")));
  758. TASSERT(!XMLString::compareString(attrb->getNamespaceURI(), X("http://nsb")));
  759. TASSERT(!XMLString::compareString(attrb->getPrefix(), XMLUni::fgZeroLenString));
  760. TASSERT(!XMLString::compareString(attrb->getLocalName(), X("attrb")));
  761. TASSERT(!XMLString::compareString(attrb->getName(), X("attrb")));
  762. TASSERT(attrb->getOwnerElement() == 0);
  763. DOMAttr* attrc = doc->createAttributeNS(XMLUni::fgZeroLenString, X("attrc"));
  764. TASSERT(!XMLString::compareString(attrc->getNodeName(), X("attrc")));
  765. TASSERT(!XMLString::compareString(attrc->getNamespaceURI(), XMLUni::fgZeroLenString));
  766. TASSERT(!XMLString::compareString(attrc->getPrefix(), XMLUni::fgZeroLenString));
  767. TASSERT(!XMLString::compareString(attrc->getLocalName(), X("attrc")));
  768. TASSERT(!XMLString::compareString(attrc->getName(), X("attrc")));
  769. TASSERT(attrc->getOwnerElement() == 0);
  770. // Badly formed qualified name
  771. EXCEPTION_TEST(doc->createAttributeNS(X("http://nsa"), X("<a")), DOMException::INVALID_CHARACTER_ERR);
  772. EXCEPTION_TEST(doc->createAttributeNS(X("http://nsa"), X(":a")), DOMException::NAMESPACE_ERR);
  773. EXCEPTION_TEST(doc->createAttributeNS(X("http://nsa"), X("a:")), DOMException::NAMESPACE_ERR);
  774. EXCEPTION_TEST(doc->createAttributeNS(X("http://nsa"), X("a::a")), DOMException::NAMESPACE_ERR);
  775. EXCEPTION_TEST(doc->createAttributeNS(X("http://nsa"), X("a:a:a")), DOMException::NAMESPACE_ERR);
  776. // xml:a must have namespaceURI == "http://www.w3.org/XML/1998/namespace"
  777. TASSERT(!XMLString::compareString(doc->createAttributeNS(X("http://www.w3.org/XML/1998/namespace"), X("xml:a"))->getNamespaceURI(), X("http://www.w3.org/XML/1998/namespace")));
  778. EXCEPTION_TEST(doc->createAttributeNS(X("http://nsa"), X("xml:a")), DOMException::NAMESPACE_ERR);
  779. EXCEPTION_TEST(doc->createAttributeNS(XMLUni::fgZeroLenString, X("xml:a")), DOMException::NAMESPACE_ERR);
  780. EXCEPTION_TEST(doc->createAttributeNS(0, X("xml:a")), DOMException::NAMESPACE_ERR);
  781. //unlike Element, xmlns must have namespaceURI == "http://www.w3.org/2000/xmlns/"
  782. TASSERT(!XMLString::compareString(doc->createAttributeNS(X("http://www.w3.org/2000/xmlns/"), X("xmlns"))->getNamespaceURI(), X("http://www.w3.org/2000/xmlns/")));
  783. EXCEPTION_TEST(doc->createAttributeNS(X("http://nsa"), X("xmlns")), DOMException::NAMESPACE_ERR);
  784. EXCEPTION_TEST(doc->createAttributeNS(X("http://www.w3.org/XML/1998/namespace"), X("xmlns")), DOMException::NAMESPACE_ERR);
  785. EXCEPTION_TEST(doc->createAttributeNS(XMLUni::fgZeroLenString, X("xmlns")), DOMException::NAMESPACE_ERR);
  786. EXCEPTION_TEST(doc->createAttributeNS(0, X("xmlns")), DOMException::NAMESPACE_ERR);
  787. //unlike Element, xmlns:a must have namespaceURI == "http://www.w3.org/2000/xmlns/"
  788. TASSERT(!XMLString::compareString(doc->createAttributeNS(X("http://www.w3.org/2000/xmlns/"), X("xmlns:a"))->getNamespaceURI(), X("http://www.w3.org/2000/xmlns/")));
  789. EXCEPTION_TEST(doc->createAttributeNS(X("http://nsa"), X("xmlns:a")), DOMException::NAMESPACE_ERR);
  790. EXCEPTION_TEST(doc->createAttributeNS(X("http://www.w3.org/XML/1998/namespace"), X("xmlns:a")), DOMException::NAMESPACE_ERR);
  791. EXCEPTION_TEST(doc->createAttributeNS(XMLUni::fgZeroLenString, X("xmlns:a")), DOMException::NAMESPACE_ERR);
  792. EXCEPTION_TEST(doc->createAttributeNS(0, X("xmlns:a")), DOMException::NAMESPACE_ERR);
  793. //In fact, any prefix != null should have a namespaceURI != 0 or != ""
  794. TASSERT(!XMLString::compareString(doc->createAttributeNS(X("http://nsa"), X("foo:a"))->getNamespaceURI(), X("http://nsa")));
  795. EXCEPTION_TEST(doc->createAttributeNS(XMLUni::fgZeroLenString, X("foo:a")), DOMException::NAMESPACE_ERR);
  796. EXCEPTION_TEST(doc->createAttributeNS(0, X("foo:a")), DOMException::NAMESPACE_ERR);
  797. //Change prefix
  798. DOMAttr* attr = doc->createAttributeNS(X("http://nsa"), X("foo:a"));
  799. attr->setPrefix(X("bar"));
  800. TASSERT(!XMLString::compareString(attr->getNodeName(), X("bar:a")));
  801. TASSERT(!XMLString::compareString(attr->getNamespaceURI(), X("http://nsa")));
  802. TASSERT(!XMLString::compareString(attr->getPrefix(), X("bar")));
  803. TASSERT(!XMLString::compareString(attr->getName(), X("bar:a")));
  804. //The spec does not prevent us from setting prefix to a node without prefix
  805. TASSERT(!XMLString::compareString(attr->getLocalName(), X("a")));
  806. attr = doc->createAttributeNS(X("http://nsa"), X("a"));
  807. TASSERT(!XMLString::compareString(attr->getPrefix(), XMLUni::fgZeroLenString));
  808. attr->setPrefix(X("bar"));
  809. TASSERT(!XMLString::compareString(attr->getNodeName(), X("bar:a")));
  810. TASSERT(!XMLString::compareString(attr->getNamespaceURI(), X("http://nsa")));
  811. TASSERT(!XMLString::compareString(attr->getPrefix(), X("bar")));
  812. TASSERT(!XMLString::compareString(attr->getLocalName(), X("a")));
  813. TASSERT(!XMLString::compareString(attr->getName(), X("bar:a")));
  814. //Special case for xml:a where namespaceURI must be xmlURI
  815. attr = doc->createAttributeNS(X("http://www.w3.org/XML/1998/namespace"), X("foo:a"));
  816. attr->setPrefix(X("xml"));
  817. attr = doc->createAttributeNS(X("http://nsa"), X("foo:a"));
  818. EXCEPTION_TEST(attr->setPrefix(X("xml")), DOMException::NAMESPACE_ERR);
  819. //Special case for xmlns:a where namespaceURI must be xmlURI
  820. attr = doc->createAttributeNS(X("http://www.w3.org/2000/xmlns/"), X("foo:a"));
  821. attr->setPrefix(X("xmlns"));
  822. attr = doc->createAttributeNS(X("http://nsa"), X("foo:a"));
  823. EXCEPTION_TEST(attr->setPrefix(X("xmlns")), DOMException::NAMESPACE_ERR);
  824. //Special case for xmlns where no prefix can be set
  825. attr = doc->createAttributeNS(X("http://www.w3.org/2000/xmlns/"), X("xmlns"));
  826. EXCEPTION_TEST(attr->setPrefix(X("foo")), DOMException::NAMESPACE_ERR);
  827. EXCEPTION_TEST(attr->setPrefix(X("xmlns")), DOMException::NAMESPACE_ERR);
  828. //Also an attribute can not have a prefix with namespaceURI == null or ""
  829. attr = doc->createAttributeNS(XMLUni::fgZeroLenString, X("a"));
  830. EXCEPTION_TEST(attr->setPrefix(X("foo")), DOMException::NAMESPACE_ERR);
  831. attr = doc->createAttributeNS(0, X("a"));
  832. EXCEPTION_TEST(attr->setPrefix(X("foo")), DOMException::NAMESPACE_ERR);
  833. //Only prefix of Element and Attribute can be changed
  834. EXCEPTION_TEST(doc->setPrefix(X("foo")), DOMException::NAMESPACE_ERR);
  835. //Prefix of readonly Attribute can not be changed.
  836. //However, there is no way to create such DOMAttribute for testing yet.
  837. // release the document, the documentType (dt) still has the owner, and thus no need to release
  838. doc->release();
  839. }
  840. //
  841. // getElementsByTagName*
  842. //
  843. {
  844. // Set up an initial (root element only) document.
  845. //
  846. DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(X("Core"));
  847. DOMDocumentType* dt = impl->createDocumentType(X("foo:docName"), X("pubId"), X("http://sysId"));
  848. DOMDocument* doc = impl->createDocument(X("http://document.namespace"), X("foo:docName"), dt);
  849. DOMElement* rootEl = doc->getDocumentElement();
  850. //
  851. // Populate the document
  852. //
  853. DOMElement* ela = doc->createElementNS(X("http://nsa"), X("a:ela"));
  854. rootEl->appendChild(ela);
  855. DOMElement* elb = doc->createElementNS(X("http://nsb"), X("elb"));
  856. rootEl->appendChild(elb);
  857. DOMElement* elc = doc->createElementNS(XMLUni::fgZeroLenString, X("elc"));
  858. rootEl->appendChild(elc);
  859. DOMElement* eld = doc->createElementNS(X("http://nsa"), X("d:ela"));
  860. rootEl->appendChild(eld);
  861. DOMElement* ele = doc->createElementNS(X("http://nse"), X("elb"));
  862. rootEl->appendChild(ele);
  863. //
  864. // Access with DOM Level 1 getElementsByTagName
  865. //
  866. DOMNodeList* nl;
  867. nl = doc->getElementsByTagName(X("a:ela"));
  868. TASSERT(nl->getLength() == 1);
  869. TASSERT(nl->item(0) == ela);
  870. nl = doc->getElementsByTagName(X("elb"));
  871. TASSERT(nl->getLength() == 2);
  872. TASSERT(nl->item(0) == elb);
  873. TASSERT(nl->item(1) == ele);
  874. nl = doc->getElementsByTagName(X("d:ela"));
  875. TASSERT(nl->getLength() == 1);
  876. TASSERT(nl->item(0) == eld);
  877. //
  878. // Access with DOM Level 2 getElementsByTagNameNS
  879. //
  880. nl = doc->getElementsByTagNameNS(XMLUni::fgZeroLenString, X("elc"));
  881. TASSERT(nl->getLength() == 1);
  882. TASSERT(nl->item(0) == elc);
  883. nl = doc->getElementsByTagNameNS(0, X("elc"));
  884. TASSERT(nl->getLength() == 1);
  885. TASSERT(nl->item(0) == elc);
  886. nl = doc->getElementsByTagNameNS(X("http://nsa"), X("ela"));
  887. TASSERT(nl->getLength() == 2);
  888. TASSERT(nl->item(0) == ela);
  889. TASSERT(nl->item(1) == eld);
  890. nl = doc->getElementsByTagNameNS(XMLUni::fgZeroLenString, X("elb"));
  891. TASSERT(nl->getLength() == 0);
  892. nl = doc->getElementsByTagNameNS(X("http://nsb"), X("elb"));
  893. TASSERT(nl->getLength() == 1);
  894. TASSERT(nl->item(0) == elb);
  895. nl = doc->getElementsByTagNameNS(X("*"), X("elb"));
  896. TASSERT(nl->getLength() == 2);
  897. TASSERT(nl->item(0) == elb);
  898. TASSERT(nl->item(1) == ele);
  899. nl = doc->getElementsByTagNameNS(X("http://nsa"), X("*"));
  900. TASSERT(nl->getLength() == 2);
  901. TASSERT(nl->item(0) == ela);
  902. TASSERT(nl->item(1) == eld);
  903. nl = doc->getElementsByTagNameNS(X("*"), X("*"));
  904. TASSERT(nl->getLength() == 6); // Gets the document root element, plus 5 more
  905. TASSERT(nl->item(6) == 0);
  906. // TASSERT(nl->item(-1) == 0);
  907. nl = rootEl->getElementsByTagNameNS(X("*"), X("*"));
  908. TASSERT(nl->getLength() == 5);
  909. nl = doc->getElementsByTagNameNS(X("http://nsa"), X("d:ela"));
  910. TASSERT(nl->getLength() == 0);
  911. //
  912. // Node lists are Live
  913. //
  914. nl = doc->getElementsByTagNameNS(X("*"), X("*"));
  915. DOMNodeList* nla = ela->getElementsByTagNameNS(X("*"), X("*"));
  916. TASSERT(nl->getLength() == 6);
  917. TASSERT(nla->getLength() == 0);
  918. DOMNode* rem = rootEl->removeChild(elc);
  919. rem->release();
  920. TASSERT(nl->getLength() == 5);
  921. TASSERT(nla->getLength() == 0);
  922. ela->appendChild(elc);
  923. TASSERT(nl->getLength() == 6);
  924. TASSERT(nla->getLength() == 1);
  925. // release the document, the documentType (dt) still has the owner, and thus no need to release
  926. doc->release();
  927. }
  928. //
  929. // Attributes and NamedNodeMaps.
  930. //
  931. {
  932. // Set up an initial (root element only) document.
  933. //
  934. DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(X("Core"));
  935. DOMDocumentType* dt = impl->createDocumentType(X("foo:docName"), X("pubId"), X("http://sysId"));
  936. DOMDocument* doc = impl->createDocument(X("http://document.namespace"), X("foo:docName"), dt);
  937. DOMElement* rootEl = doc->getDocumentElement();
  938. //
  939. // Create a set of attributes and hang them on the root element.
  940. //
  941. DOMAttr* attra = doc->createAttributeNS(X("http://nsa"), X("a:attra"));
  942. DOMNode* rem = rootEl->setAttributeNodeNS(attra);
  943. if (rem)
  944. rem->release();
  945. //
  946. // Check that the attribute nodes were created with the correct properties.
  947. //
  948. TASSERT(!XMLString::compareString(attra->getNodeName(), X("a:attra")));
  949. TASSERT(!XMLString::compareString(attra->getNamespaceURI(), X("http://nsa")));
  950. TASSERT(!XMLString::compareString(attra->getLocalName(), X("attra")));
  951. TASSERT(!XMLString::compareString(attra->getName(), X("a:attra")));
  952. TASSERT(attra->getNodeType() == DOMNode::ATTRIBUTE_NODE);
  953. TASSERT(!XMLString::compareString(attra->getNodeValue(), XMLUni::fgZeroLenString));
  954. TASSERT(!XMLString::compareString(attra->getPrefix(), X("a")));
  955. TASSERT(attra->getSpecified() == true);
  956. TASSERT(!XMLString::compareString(attra->getValue(), XMLUni::fgZeroLenString));
  957. //
  958. // Create a set of attributes and hang them on the root element.
  959. //
  960. DOMAttr* attrb = doc->createAttributeNS(X("http://nsb"), X("attrb"));
  961. rem = rootEl->setAttributeNodeNS(attrb);

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