DTest.cpp
上传用户:zhuqijet
上传日期:2013-06-25
资源大小:10074k
文件大小:187k
- OK = false;
- }
- node2->release();
- // Deep clone test comparison is also in testNode
- // Test the user data
- // Test simple set and get
- DOMDocumentFragment* userTest = docFragment;
- DOMDocumentFragment* userFirst = docFragment2;
- XMLCh* userSecond = tempStr2;
- XMLString::transcode("first", tempStr, 3999);
- XMLString::transcode("document", tempStr2, 3999);
- userTest->setUserData(tempStr2, (void*) document, 0);
- void* mydocument = userTest->getUserData(tempStr2);
- if (document != mydocument) {
- fprintf(stderr, "'set/getUserData' in line %i does not workn", __LINE__);
- OK = false;
- }
- userTest->setUserData(tempStr, (void*) userFirst, 0);
- void* myFirst = userTest->getUserData(tempStr);
- if (userFirst != myFirst) {
- fprintf(stderr, "'set/getUserData' in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test overwrite
- void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0);
- void* mySecond = userTest->getUserData(tempStr);
- if (userSecond != mySecond) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userFirst != myFirst2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userFirst == mySecond) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test null
- // test non-exist key
- XMLString::transcode("not-exist", tempStr3, 3999);
- if (userTest->getUserData(tempStr3)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // use a node that does not have user data set before
- if (userFirst->getUserData(tempStr)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test reset
- void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0);
- void* myNull = userTest->getUserData(tempStr);
- if (userSecond != mySecond2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (myNull) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0);
- void* myNull2 = userTest->getUserData(tempStr2);
- if (mydocument != mydocument2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (myNull2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- //the userTest user data table should be null now
- if (userTest->getUserData(tempStr)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userTest->getUserData(tempStr2)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test DOMUserDataHandler
- // test clone
- userTest->setUserData(tempStr2, (void*) document, &userhandler);
- DOMNode* mycloned = userTest->cloneNode(true);
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__);
- // test import
- document->setUserData(tempStr2, (void*) document, &userhandler);
- DOMNode* myimport = document->importNode(userTest,true);
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__);
- // test delete
- myimport->setUserData(tempStr2, (void*) userTest, &userhandler);
- myimport->release();
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__);
- // Test isSameNode
- if (!userTest->isSameNode(userTest)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isSameNode(userFirst)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- // Test isEqualNode
- if (!userTest->isEqualNode(mycloned)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (!userTest->isEqualNode(userTest)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isEqualNode(document)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- // Test rename, should throw exception
- EXCEPTIONSTEST(document->renameNode(userTest, 0, tempStr2), DOMException::NOT_SUPPORTED_ERR, OK, 207 );
- if (!OK)
- printf("n*****The DOMDocument* method calls listed above failed, all others worked correctly.*****n");
- return OK;
- };
- /**
- * This method tests DOMDocumentFragment* methods for the XML DOM implementation
- * @param document org.w3c.dom.DOMDocument
- *
- *
- *
- ********This really isn't needed, only exists to throw NO_MODIFICATION_ALLOWED_ERR ********
- */
- bool DOMTest::testDocumentFragment(DOMDocument* document)
- {
- bool OK = true;
- // For debugging***** printf("n testDocumentFragment's outputs:n");
- DOMDocumentFragment* testDocFragment = document->createDocumentFragment();
- // testDocFragment->setNodeValue("This is a document fragment!");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ********
- // Test isSameNode
- DOMDocumentFragment* userTest = testDocFragment;
- DOMNode* mycloned = testDocFragment->cloneNode(true);
- DOMDocument* userFirst = document;
- if (!userTest->isSameNode(userTest)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isSameNode(userFirst)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- // Test isEqualNode
- if (!userTest->isEqualNode(mycloned)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (!userTest->isEqualNode(userTest)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isEqualNode(userFirst)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- // Test rename, should throw exception
- EXCEPTIONSTEST(document->renameNode(userTest, 0, tempStr2), DOMException::NOT_SUPPORTED_ERR, OK, 208 );
- if (!OK)
- printf("n*****The DOMDocumentFragment* method calls listed above failed, all others worked correctly.*****n");
- return OK;
- };
- /**
- * This method tests DOMDocumentType* methods for the XML DOM implementation
- * @param document org.w3c.dom.DOMDocument
- *
- */
- bool DOMTest::testDocumentType(DOMDocument* document)
- {
- DOMTest test;
- DOMDocumentType* docType, *holdDocType;
- DOMNamedNodeMap* docNotationMap;
- DOMNode* node, *node2;
- bool OK = true;
- // For debugging***** printf("n testDocumentType's outputs:n");
- XMLString::transcode("TestDocument", tempStr, 3999);
- DOMDocumentType* newDocumentType = test.createDocumentType(document, tempStr);
- node = document->getFirstChild(); // node gets doc's docType node
- node2 = node->cloneNode(true);
- // Check nodes for equality, both their name and value or lack thereof
- if (!(!XMLString::compareString(node->getNodeName(), node2->getNodeName()) && // Compares node names for equality
- (node->getNodeValue() != 0 && node2->getNodeValue() != 0) // Checks to make sure each node has a value node
- ? !XMLString::compareString(node->getNodeValue(), node2->getNodeValue()) // If both have value nodes test those value nodes for equality
- : (node->getNodeValue() == 0 && node2->getNodeValue() == 0))) // If one node doesn't have a value node make sure both don't
- {
- fprintf(stderr, "'cloneNode' did not clone the DOMDocumentType* node correctlyn");
- OK = false;
- }
- // Deep clone test comparison is in testNode & testDocument
- DOMNode* abc9 = document->getFirstChild();
- docType = (DOMDocumentType*) abc9;
- XMLString::transcode("ourNotationNode", tempStr, 3999);
- docNotationMap = docType->getNotations();
- if (XMLString::compareString(tempStr, docNotationMap->item(0)->getNodeName()))
- {
- fprintf(stderr, "Warning!!! DOMDocumentType's 'getNotations' failed!n");
- OK = false;
- }
- // doc->appendChild(newDocumentTypeImpl);//!! Throws a HIERARCHY_REQUEST_ERR *******
- DOMNode* abc10 = document->removeChild(document->getFirstChild()); //Tests removeChild and stores removed branch for tree reconstruction
- holdDocType = (DOMDocumentType*) abc10;
- document->insertBefore(newDocumentType, document->getDocumentElement());
- //** Other aspects of insertBefore are tested in docBuilder through appendChild*
- DOMNode* rem = document->removeChild(document->getFirstChild()); //Removes newDocumentType for tree restoral
- rem->release();
- document->insertBefore(holdDocType, document->getFirstChild()); //Reattaches removed branch to restore tree to the original
- // Test the user data
- // Test simple set and get
- DOMDocumentType* userTest = docType;
- DOMNamedNodeMap* userFirst = docNotationMap;
- XMLCh* userSecond = tempStr2;
- XMLString::transcode("first", tempStr, 3999);
- XMLString::transcode("document", tempStr2, 3999);
- userTest->setUserData(tempStr2, (void*) document, 0);
- void* mydocument = userTest->getUserData(tempStr2);
- if (document != mydocument) {
- fprintf(stderr, "'set/getUserData' in line %i does not workn", __LINE__);
- OK = false;
- }
- userTest->setUserData(tempStr, (void*) userFirst, 0);
- void* myFirst = userTest->getUserData(tempStr);
- if (userFirst != myFirst) {
- fprintf(stderr, "'set/getUserData' in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test overwrite
- void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0);
- void* mySecond = userTest->getUserData(tempStr);
- if (userSecond != mySecond) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userFirst != myFirst2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userFirst == mySecond) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test null
- // test non-exist key
- XMLString::transcode("not-exist", tempStr3, 3999);
- if (userTest->getUserData(tempStr3)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // use a node that does not have user data set before
- if (node2->getUserData(tempStr)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test reset
- void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0);
- void* myNull = userTest->getUserData(tempStr);
- if (userSecond != mySecond2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (myNull) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0);
- void* myNull2 = userTest->getUserData(tempStr2);
- if (mydocument != mydocument2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (myNull2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- //the userTest user data table should be null now
- if (userTest->getUserData(tempStr)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userTest->getUserData(tempStr2)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test DOMUserDataHandler
- // test clone
- userTest->setUserData(tempStr2, (void*) document, &userhandler);
- DOMNode* mycloned = userTest->cloneNode(true);
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__);
- // document type cannot be imported, so no test import, rather test the exception
- document->setUserData(tempStr2, (void*) document, &userhandler);
- EXCEPTIONSTEST(document->importNode(userTest,true), DOMException::NOT_SUPPORTED_ERR, OK, 203 );
- // Test isSameNode
- if (!userTest->isSameNode(userTest)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isSameNode(document)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- // Test isEqualNode
- if (!userTest->isEqualNode(mycloned)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (!userTest->isEqualNode(userTest)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isEqualNode(document)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- // Test rename, should throw exception
- EXCEPTIONSTEST(document->renameNode(userTest, 0, tempStr2), DOMException::NOT_SUPPORTED_ERR, OK, 209 );
- if (!OK)
- printf("n*****The DOMDocumentType* method calls listed above failed, all others worked correctly.*****n");
- return OK;
- };
- /**
- * @param document org.w3c.dom.DOMDocument
- */
- bool DOMTest::testDOMerrors(DOMDocument* document) {
- bool OK = true;
- DOMTest tests;
- EXCEPTIONSTEST(document->appendChild(testElementNode), DOMException::HIERARCHY_REQUEST_ERR, OK, 201 );
- EXCEPTIONSTEST(testTextNode->appendChild(testTextNode), DOMException::HIERARCHY_REQUEST_ERR, OK, 202 );
- return OK;
- };
- /**
- * This method tests DOMImplementation methods for the XML DOM implementation
- * @param document org.w3c.dom.DOMDocument
- *
- */
- bool DOMTest::testDOMImplementation(DOMDocument* document)
- {
- DOMImplementation* implementation;
- bool result = false;
- bool OK = true;
- // For debugging***** printf("n testDOMImplementation's outputs:n");
- implementation = document->getImplementation(); //Uses getDOMImplementation to obtain implementation
- XMLString::transcode("XML", tempStr, 3999);
- XMLString::transcode("1.0", tempStr2, 3999);
- result = implementation->hasFeature(tempStr, tempStr2);
- if(!result)
- {
- fprintf(stderr, "Warning!!! DOMImplementation's 'hasFeature' that should be 'true' failed!");
- OK = false;
- }
- XMLString::transcode("HTML", tempStr, 3999);
- XMLString::transcode("4.0", tempStr2, 3999);
- result = implementation->hasFeature(tempStr, tempStr2);
- if(result)
- {
- fprintf(stderr, "Warning!!! DOMImplementation's 'hasFeature' that should be 'false' failed!");
- OK = false;
- }
- if (!OK)
- fprintf(stderr, "n*****The DOMImplementation method calls listed above failed, all others worked correctly.*****n");
- return OK;
- };
- /**
- * This method tests DOMElement* methods for the XML DOM implementation
- * @param document org.w3c.dom.DOMDocument
- *
- */
- bool DOMTest::testElement(DOMDocument* document)
- {
- DOMAttr* attributeNode, *newAttributeNode;
- DOMElement* element, *element2;
- DOMNode* node, *node2;
- const char* attributeCompare[] = {"AnotherFirstElementAttribute", "dFirstElement", "testAttribute"};
- const char* elementNames[] = {"dFirstElement", "dTestBody", "dBodyLevel21","dBodyLevel31","dBodyLevel32",
- "dBodyLevel22","dBodyLevel33","dBodyLevel34","dBodyLevel23","dBodyLevel24"};
- const char* textCompare[] = {"dBodyLevel31'sChildTextNode11",
- "dBodyLevel31'sChildTextNode12",
- "dBodyLevel31'sChildTextNode13"};
- DOMNamedNodeMap* nodeMap;
- bool OK = true;
- node = document->getDocumentElement(); // node gets doc's firstElement
- node2 = node->cloneNode(true);
- // Check nodes for equality, both their name and value or lack thereof
- if (!(!XMLString::compareString(node->getNodeName(), node2->getNodeName()) && // Compares node names for equality
- (node->getNodeValue() != 0 && node2->getNodeValue() != 0) // Checks to make sure each node has a value node
- ? !XMLString::compareString(node->getNodeValue(), node2->getNodeValue()) // If both have value nodes test those value nodes for equality
- : (node->getNodeValue() == 0 && node2->getNodeValue() == 0))) // If one node doesn't have a value node make sure both don't
- {
- fprintf(stderr, "'cloneNode' did not clone the DOMElement* node correctly.n");
- OK = false;
- }
- // Deep clone test comparison is in testNode & testDocument
- element = document->getDocumentElement(); // element gets doc's firstElement
- XMLString::copyString(tempStr, document->getNodeValue());
- XMLString::transcode("'s test attribute", tempStr2, 3999);
- XMLString::catString(tempStr, tempStr2);
- if (XMLString::compareString(XMLUni::fgZeroLenString, element->getAttribute(tempStr)))
- {
- fprintf(stderr, "Warning!!! DOMElement's 'getAttribute' failed!n");
- OK = false;
- }
- XMLString::copyString(tempStr, document->getNodeValue());
- XMLString::transcode("FirstElement", tempStr2, 3999);
- XMLString::catString(tempStr, tempStr2);
- attributeNode = element->getAttributeNode(tempStr);
- if(! (attributeNode == 0))
- {
- fprintf(stderr, "Warning!!! DOMElement's 'getAttributeNode' failed! It should have returned '0' here!n");
- OK = false;
- }
- XMLString::transcode("AnotherFirstElementAttribute", tempStr, 3999);
- newAttributeNode = document->createAttribute(tempStr);
- XMLString::transcode("A new attribute which helps test calls in DOMElement", tempStr, 3999);
- newAttributeNode->setValue(tempStr);
- // This test is incorrect. It assumes that there is a defined ordering of the entries
- // in a nodeMap, but there is no ordering required.
- #ifdef TheFollowingCheckIsInvalid
- DOMNode* rem2 = element->setAttributeNode(newAttributeNode);
- if (rem2)
- rem2->release();
- nodeMap = element->getAttributes();
- int size = nodeMap->getLength();
- int k;
- for (k = 0; k < size; k++)
- {
- DOMNode* n = (DOMNode) nodeMap->item(k);
- XMLString::transcode(attributeCompare[k], tempStr, 3999);
- if (XMLString::compareString(tempStr, n->getNodeName())))
- {
- fprintf(stderr, "Warning!!! Comparison of firstElement's attributes failed at line %i.n", __LINE__);
- fprintf(stderr, " This failure can be a result of DOMElement's 'setValue' and/or 'setAttributeNode' and/or 'getAttributes' failing.n");
- OK = false;
- break;
- }
- // printf("firstElement's attribute number " + k + " : " + n->getNodeName());
- }
- #endif
- nodeMap = element->getAttributes();
- int size = nodeMap->getLength();
- if (size != 2)
- {
- fprintf(stderr, "DOMElement* Tests Failure 001n");
- OK = false;
- };
- DOMNode* rem = element->setAttributeNode(newAttributeNode);
- if (rem)
- rem->release();
- size = nodeMap->getLength();
- if (size != 3)
- {
- fprintf(stderr, "DOMElement* Tests Failure 002n");
- OK = false;
- };
- // Fetch the newly added attribute node back out of from the named node map,
- // and check that we are returned the same node that we put in->
- XMLString::transcode("AnotherFirstElementAttribute", tempStr, 3999);
- DOMNode* abc12 = nodeMap->getNamedItem(tempStr);
- DOMAttr* fetchedAttr = (DOMAttr*) abc12;
- if (fetchedAttr != newAttributeNode)
- {
- fprintf(stderr, "DOMElement* Tests Failure 003n");
- OK = false;
- };
- // Fetch the newly added attribute back out directly from the element itself.
- XMLString::transcode("AnotherFirstElementAttribute", tempStr, 3999);
- fetchedAttr = element->getAttributeNode(tempStr);
- if (fetchedAttr != newAttributeNode)
- {
- fprintf(stderr, "DOMElement* Tests Failure 004n");
- OK = false;
- };
- XMLString::transcode("*",tempStr, 3999);
- DOMNodeList* docElements = document->getElementsByTagName(tempStr);
- int docSize = docElements->getLength();
- int i;
- for (i = 0; i < docSize; i++)
- {
- DOMNode* n = docElements->item(i);
- XMLString::transcode(elementNames[i], tempStr, 3999);
- if (XMLString::compareString(tempStr, n->getNodeName()))
- {
- fprintf(stderr, "Warning!!! Comparison of DOMElement's 'getElementsByTagName' "
- "and/or 'item' failed at element number %d at line %i n", i, __LINE__ );
- fprintf(stderr, "n");
- OK = false;
- break;
- }
- // printf("docElement's number " + i + " is: " + n->getNodeName());
- }
- XMLString::transcode("dBodyLevel21", tempStr, 3999);
- DOMNode* abc15 = document->getElementsByTagName(tempStr)->item(0); // element gets DOMElement* test BodyLevel21
- element = (DOMElement*) abc15;
- XMLString::transcode("dBodyLevel31", tempStr, 3999);
- DOMNode* abc16 = document->getElementsByTagName(tempStr)->item(0); // element2 gets DOMElement* test BodyLevel31
- element2 = (DOMElement*) abc16;
- DOMNodeList* text = ((DOMNode* &) element2)->getChildNodes();
- int textSize = text->getLength();
- int j;
- static bool firstTime = true;
- if (firstTime)
- {
- firstTime = false; // Temporary fix. Subsequent tests alter the doc, causing
- // this test to fail on all but the first time through.
- for (j = 0; j < textSize; j++)
- {
- DOMNode* n = text->item(j);
- XMLString::transcode(textCompare[j], tempStr, 3999);
- if (XMLString::compareString(tempStr, n->getNodeValue()))
- {
- fprintf(stderr, "Warning!!! Comparison of original text nodes via DOMNode* 'getChildNodes' & DOMNodeList 'item'n"
- " failed at text node: #%d at line %i n ", j, __LINE__ );
- OK = false;
- break;
- }
- // printf("DOMElement* testBodyLevel31's child text node " + j + " is: " + n->getNodeValue());
- }
- }
- element = document->getDocumentElement(); // element gets doc's firstElement
- element->normalize(); // Concatenates all adjacent text nodes in this element's subtree
- DOMNodeList* text2 = ((DOMNode*) element2)->getChildNodes();
- XMLString::transcode("dBodyLevel31'sChildTextNode11dBodyLevel31'sChildTextNode12dBodyLevel31'sChildTextNode13", tempStr, 3999);
- DOMNode* n = text2->item(0);
- if (XMLString::compareString(tempStr, n->getNodeValue()))
- {
- fprintf(stderr, "Warning!!! Comparison of concatenated text nodes created by DOMElement's 'normalize' failed!n");
- OK = false;
- }
- XMLString::transcode("FirstElementLastAttribute", tempStr, 3999);
- XMLString::transcode("More attribute stuff for firstElement!!", tempStr2, 3999);
- element->setAttribute(tempStr, tempStr2);
- XMLString::transcode("FirstElementLastAttribute", tempStr, 3999);
- element->removeAttribute(tempStr);
- rem = element->removeAttributeNode(newAttributeNode);
- if (rem)
- rem->release();
- // doc->getLastChild()->setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR***
- // Test the user data
- // Test simple set and get
- DOMElement* userTest = element;
- DOMAttr* userFirst = newAttributeNode;
- XMLCh* userSecond = tempStr2;
- XMLString::transcode("first", tempStr, 3999);
- XMLString::transcode("document", tempStr2, 3999);
- userTest->setUserData(tempStr2, (void*) document, 0);
- void* mydocument = userTest->getUserData(tempStr2);
- if (document != mydocument) {
- fprintf(stderr, "'set/getUserData' in line %i does not workn", __LINE__);
- OK = false;
- }
- userTest->setUserData(tempStr, (void*) userFirst, 0);
- void* myFirst = userTest->getUserData(tempStr);
- if (userFirst != myFirst) {
- fprintf(stderr, "'set/getUserData' in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test overwrite
- void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0);
- void* mySecond = userTest->getUserData(tempStr);
- if (userSecond != mySecond) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userFirst != myFirst2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userFirst == mySecond) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test null
- // test non-exist key
- XMLString::transcode("not-exist", tempStr3, 3999);
- if (userTest->getUserData(tempStr3)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // use a node that does not have user data set before
- if (userFirst->getUserData(tempStr)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test reset
- void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0);
- void* myNull = userTest->getUserData(tempStr);
- if (userSecond != mySecond2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (myNull) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0);
- void* myNull2 = userTest->getUserData(tempStr2);
- if (mydocument != mydocument2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (myNull2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- //the userTest user data table should be null now
- if (userTest->getUserData(tempStr)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userTest->getUserData(tempStr2)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test DOMUserDataHandler
- // test clone
- userTest->setUserData(tempStr2, (void*) document, &userhandler);
- DOMNode* mycloned = userTest->cloneNode(true);
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__);
- // test import
- document->setUserData(tempStr2, (void*) document, &userhandler);
- DOMNode* myimport = document->importNode(userTest,true);
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__);
- // test delete
- myimport->setUserData(tempStr2, (void*) userTest, &userhandler);
- myimport->release();
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__);
- // Test isSameNode
- if (!userTest->isSameNode(userTest)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isSameNode(userFirst)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- // Test isEqualNode
- if (!userTest->isEqualNode(mycloned)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (!userTest->isEqualNode(userTest)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isEqualNode(userFirst)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- // Test renameNode
- XMLString::transcode("http://nsa", tempStr4, 3999);
- XMLString::transcode("aa", tempStr5, 3999);
- XMLString::transcode("pnsa:aa", tempStr3, 3999);
- // create the element
- DOMElement* renameTestElement = document->createElement(tempStr5);
- DOMElement* renameTestElementNS = document->createElementNS(tempStr4, tempStr3);
- // create the parent
- DOMElement* renameTestParent = document->createElement(tempStr5);
- renameTestParent->appendChild(renameTestElement);
- renameTestParent->appendChild(renameTestElementNS);
- // set up the userdata
- renameTestElement->setUserData(tempStr5, (void*) document, &userhandler);
- renameTestElementNS->setUserData(tempStr4, (void*) document, 0);
- // append a text node as child
- DOMText* renameTestText = document->createTextNode(tempStr5);
- DOMText* renameTestTextNS = document->createTextNode(tempStr4);
- renameTestElement->appendChild(renameTestText);
- renameTestElementNS->appendChild(renameTestTextNS);
- XMLString::transcode("http://nsb", tempStr, 3999);
- XMLString::transcode("bb", tempStr2, 3999);
- XMLString::transcode("pnsb:bb", tempStr3, 3999);
- // set up some attributes
- DOMAttr* renameTestAttribute = document->createAttribute(tempStr5);
- DOMAttr* renameTestAttributeNS = document->createAttributeNS(tempStr4, tempStr3);
- renameTestElement->setAttributeNode(renameTestAttribute);
- renameTestElementNS->setAttributeNodeNS(renameTestAttributeNS);
- //Test compareTreePosition first before testing rename
- // renameTestParent
- // |
- // |_ renameTestElement (has renameTestAttribute)
- // | |
- // | |_ renameTestText
- // |
- // |_ renameTestElementNS (has renameTestAttributeNS)
- // | |
- // | |_ renameTestTextNS
- //
- COMPARETREEPOSITIONTEST(renameTestAttribute, renameTestAttributeNS, DOMNode::TREE_POSITION_FOLLOWING, __LINE__);
- COMPARETREEPOSITIONTEST(renameTestAttribute, renameTestElement, DOMNode::TREE_POSITION_PRECEDING, __LINE__);
- COMPARETREEPOSITIONTEST(renameTestAttribute, renameTestText, DOMNode::TREE_POSITION_FOLLOWING, __LINE__);
- COMPARETREEPOSITIONTEST(renameTestAttribute, renameTestTextNS, DOMNode::TREE_POSITION_FOLLOWING, __LINE__);
- COMPARETREEPOSITIONTEST(renameTestAttribute, renameTestParent, DOMNode::TREE_POSITION_PRECEDING, __LINE__);
- COMPARETREEPOSITIONTEST(renameTestAttributeNS, renameTestAttribute, DOMNode::TREE_POSITION_PRECEDING, __LINE__);
- COMPARETREEPOSITIONTEST(renameTestElement, renameTestAttributeNS, DOMNode::TREE_POSITION_FOLLOWING, __LINE__);
- COMPARETREEPOSITIONTEST(renameTestAttributeNS, renameTestText, DOMNode::TREE_POSITION_PRECEDING, __LINE__);
- COMPARETREEPOSITIONTEST(renameTestTextNS, renameTestAttributeNS, DOMNode::TREE_POSITION_PRECEDING, __LINE__);
- // start the rename tests
- // rename the NS Element
- DOMElement* renameTest = (DOMElement*) document->renameNode(renameTestElementNS, tempStr, tempStr3);
- // test the name
- if (XMLString::compareString(tempStr, renameTest->getNamespaceURI()))
- {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (XMLString::compareString(tempStr2, renameTest->getLocalName()))
- {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (XMLString::compareString(tempStr3, renameTest->getNodeName()))
- {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- // test the child / nodevalue
- if (XMLString::compareString(tempStr4, renameTest->getFirstChild()->getNodeValue()))
- {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- // test the attribute
- if (!renameTest->getAttributeNodeNS(tempStr4, tempStr2))
- {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- // test the owner element
- if (renameTestParent->getElementsByTagNameNS(tempStr, tempStr2)->getLength() != 1) {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (renameTestParent->getElementsByTagNameNS(tempStr4, tempStr5)->getLength() != 0) {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- // test user data
- void* renamedocument = renameTest->getUserData(tempStr4);
- if (document != renamedocument) {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- // test isSame and isEqual
- if (!renameTestElementNS->isEqualNode(renameTest)) {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (!renameTestElementNS->isSameNode(renameTest)) {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- // rename the Element (null namespace)
- renameTest = (DOMElement*) document->renameNode(renameTestElement, 0, tempStr2);
- // test the name
- if (renameTest->getNamespaceURI())
- {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (renameTest->getLocalName())
- {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (XMLString::compareString(tempStr2, renameTest->getNodeName()))
- {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- // test the child / nodevalue
- if (XMLString::compareString(tempStr5, renameTest->getFirstChild()->getNodeValue()))
- {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- // test the attribute
- if (!renameTest->getAttributeNode(tempStr5))
- {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- // test the owner element
- if (renameTestParent->getElementsByTagName(tempStr2)->getLength() != 1) {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (renameTestParent->getElementsByTagName(tempStr5)->getLength() != 0) {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- // test user data
- renamedocument = renameTest->getUserData(tempStr5);
- if (document != renamedocument) {
- fprintf(stderr, "'set/getUserData' in line %i does not workn", __LINE__);
- OK = false;
- }
- // test isSame and isEqual
- if (!renameTestElement->isEqualNode(renameTest)) {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (!renameTestElement->isSameNode(renameTest)) {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- // rename the Element (with namespace)
- renameTest = (DOMElement*) document->renameNode(renameTestElement, tempStr, tempStr3);
- // test the name
- if (XMLString::compareString(tempStr, renameTest->getNamespaceURI()))
- {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (XMLString::compareString(tempStr2, renameTest->getLocalName()))
- {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (XMLString::compareString(tempStr3, renameTest->getNodeName()))
- {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- // test the child / nodevalue
- if (XMLString::compareString(tempStr5, renameTest->getFirstChild()->getNodeValue()))
- {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (renameTestElement->getFirstChild())
- {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- // test the attribute
- if (!renameTest->getAttributeNode(tempStr5))
- {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (renameTestElement->getAttributeNode(tempStr5))
- {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- // test the owner element
- // the nodelist should be 2 items as we have to count the renameTestElementNS as well
- if (renameTestParent->getElementsByTagNameNS(tempStr, tempStr2)->getLength() != 2) {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (renameTestParent->getElementsByTagNameNS(0, tempStr2)->getLength() != 0) {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (renameTestParent->getElementsByTagName(tempStr2)->getLength() != 0) {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- // test user data
- renamedocument = renameTest->getUserData(tempStr5);
- if (document != renamedocument) {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- // test userdatahandler
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_RENAMED, tempStr5, document, renameTestElement, renameTest, __LINE__);
- // test isSame and isEqual
- // a new node is created here, so both isSame and isEqual are not compared
- if (renameTestElement->isEqualNode(renameTest)) {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (renameTestElement->isSameNode(renameTest)) {
- fprintf(stderr, "renameNode failed in line %in", __LINE__);
- OK = false;
- }
- //setIdAttribute tests
- XMLString::transcode("http://nsa", tempStr4, 3999);
- XMLString::transcode("aa", tempStr5, 3999);
- DOMAttr *idAtt = document->createAttributeNS(tempStr4, tempStr5);
- //tests for node not being on testElementNode
- EXCEPTIONSTEST(testElementNode->setIdAttribute(tempStr4), DOMException::NOT_FOUND_ERR, OK, 1000);
- EXCEPTIONSTEST(testElementNode->setIdAttributeNS(tempStr4, tempStr5), DOMException::NOT_FOUND_ERR, OK, 1001);
- EXCEPTIONSTEST(testElementNode->setIdAttributeNode(idAtt), DOMException::NOT_FOUND_ERR, OK, 1002);
- //should test NO_MODIFICATION_ALLOWED_ERR but dont know how to without direct access to DOMAttrImpl.
- idAtt = document->createAttributeNS(tempStr4, tempStr5);
- idAtt->setValue(tempStr3);
- testElementNode->setAttributeNode(idAtt);
- testElementNode->setIdAttributeNode(idAtt);
- if(!idAtt->isId()) {
- fprintf(stderr, "setIdAttributeNode failed in line %in", __LINE__);
- OK = false;
- }
- DOMElement *idEle = document->getElementById(tempStr3);
- if(!idEle || !idEle->isSameNode(testElementNode)) {
- fprintf(stderr, "setIdAttributeNode failed in line %in", __LINE__);
- OK = false;
- }
- testElementNode->removeAttributeNode(idAtt);
- XMLString::transcode("someval", tempStr3, 3999);
- idAtt = document->createAttributeNS(tempStr4, tempStr5);
- idAtt->setValue(tempStr3);
- testElementNode->setAttributeNode(idAtt);
- testElementNode->setIdAttributeNS(tempStr4, tempStr5);
- if(!idAtt->isId()) {
- fprintf(stderr, "setIdAttributeNS failed in line %in", __LINE__);
- OK = false;
- }
- idEle = document->getElementById(tempStr3);
- if(!idEle || !idEle->isSameNode(testElementNode)) {
- fprintf(stderr, "setIdAttributeNS failed in line %in", __LINE__);
- OK = false;
- }
- testElementNode->removeAttributeNode(idAtt);
- idAtt->release();
- XMLString::transcode("somevalDif", tempStr3, 3999);
- idAtt = document->createAttribute(tempStr5);
- idAtt->setValue(tempStr3);
- testElementNode->setAttributeNode(idAtt);
- testElementNode->setIdAttribute(tempStr5);
- if(!idAtt->isId()) {
- fprintf(stderr, "setIdAttribute failed in line %in", __LINE__);
- OK = false;
- }
- idEle = document->getElementById(tempStr3);
- if(!idEle || !idEle->isSameNode(testElementNode)) {
- fprintf(stderr, "setIdAttribute failed in line %in", __LINE__);
- OK = false;
- }
- testElementNode->removeAttributeNode(idAtt);
- idAtt->release();
- if (!OK)
- printf("n*****The DOMElement* method calls listed above failed, all others worked correctly.*****n");
- return OK;
- };
- /**
- * This method tests DOMEntity* methods for the XML DOM implementation
- * @param document org.w3c.dom.DOMDocument
- *
- */
- bool DOMTest::testEntity(DOMDocument* document)
- {
- DOMEntity* entity;
- DOMNode* node, *node2;
- bool OK = true;
- // For debugging***** printf("n testEntity's outputs:nn");
- XMLString::transcode("ourEntityNode", tempStr, 3999);
- DOMNode* abc20 = document->getDoctype()->getEntities()->getNamedItem(tempStr);
- entity = (DOMEntity*) abc20;
- node = entity;
- node2 = entity->cloneNode(true);
- // Check nodes for equality, both their name and value or lack thereof
- if (!(!XMLString::compareString(node->getNodeName(), node2->getNodeName()) && // Compares node names for equality
- (node->getNodeValue() != 0 && node2->getNodeValue() != 0) // Checks to make sure each node has a value node
- ? !XMLString::compareString(node->getNodeValue(), node2->getNodeValue()) // If both have value nodes test those value nodes for equality
- : (node->getNodeValue() == 0 && node2->getNodeValue() == 0))) // If one node doesn't have a value node make sure both don't
- {
- fprintf(stderr, "'cloneNode' did not clone the DOMEntity* node correctly");
- OK = false;
- }
- // Deep clone test comparison is in testNode & testDocument
- // Test the user data
- // Test simple set and get
- DOMEntity* userTest = entity;
- DOMNode* userFirst = node;
- XMLCh* userSecond = tempStr2;
- XMLString::transcode("first", tempStr, 3999);
- XMLString::transcode("document", tempStr2, 3999);
- userTest->setUserData(tempStr2, (void*) document, 0);
- void* mydocument = userTest->getUserData(tempStr2);
- if (document != mydocument) {
- fprintf(stderr, "'set/getUserData' in line %i does not workn", __LINE__);
- OK = false;
- }
- userTest->setUserData(tempStr, (void*) userFirst, 0);
- void* myFirst = userTest->getUserData(tempStr);
- if (userFirst != myFirst) {
- fprintf(stderr, "'set/getUserData' in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test overwrite
- void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0);
- void* mySecond = userTest->getUserData(tempStr);
- if (userSecond != mySecond) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userFirst != myFirst2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userFirst == mySecond) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test null
- // test non-exist key
- XMLString::transcode("not-exist", tempStr3, 3999);
- if (userTest->getUserData(tempStr3)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // use a node that does not have user data set before
- if (userFirst->getUserData(tempStr)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test reset
- void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0);
- void* myNull = userTest->getUserData(tempStr);
- if (userSecond != mySecond2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (myNull) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0);
- void* myNull2 = userTest->getUserData(tempStr2);
- if (mydocument != mydocument2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (myNull2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- //the userTest user data table should be null now
- if (userTest->getUserData(tempStr)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userTest->getUserData(tempStr2)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test DOMUserDataHandler
- // test clone
- userTest->setUserData(tempStr2, (void*) document, &userhandler);
- DOMNode* mycloned = userTest->cloneNode(true);
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__);
- // test import
- document->setUserData(tempStr2, (void*) document, &userhandler);
- DOMNode* myimport = document->importNode(userTest,true);
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__);
- // test delete
- myimport->setUserData(tempStr2, (void*) userTest, &userhandler);
- myimport->release();
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__);
- // Test isSameNode
- if (!userTest->isSameNode(userTest)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isSameNode(userFirst)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- // Test isEqualNode
- if (!userTest->isEqualNode(mycloned)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (!userTest->isEqualNode(userTest)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isEqualNode(userFirst)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- // Test rename, should throw exception
- EXCEPTIONSTEST(document->renameNode(userTest, 0, tempStr2), DOMException::NOT_SUPPORTED_ERR, OK, 210 );
- if (!OK)
- printf("n*****The DOMEntity* method calls listed above failed, all others worked correctly.*****n");
- return OK;
- };
- /**
- * This method tests DOMEntityReference* methods for the XML DOM implementation
- * @param document org.w3c.dom.DOMDocument
- *
- */
- bool DOMTest::testEntityReference(DOMDocument* document)
- {
- DOMEntityReference* entityReference;
- DOMNode* node, *node2;
- bool OK = true;
- // For debugging***** printf("n testEntityReference's outputs:n");
- DOMNode* abc30 = document->getLastChild()->getLastChild()->getLastChild()->getFirstChild();
- entityReference = (DOMEntityReference*) abc30;
- node = entityReference;
- node2 = node->cloneNode(true);
- // Check nodes for equality, both their name and value or lack thereof
- if (!(!XMLString::compareString(node->getNodeName(), node2->getNodeName()) && // Compares node names for equality
- (node->getNodeValue() != 0 && node2->getNodeValue() != 0) // Checks to make sure each node has a value node
- ? !XMLString::compareString(node->getNodeValue(), node2->getNodeValue()) // If both have value nodes test those value nodes for equality
- : (node->getNodeValue() == 0 && node2->getNodeValue() == 0))) // If one node doesn't have a value node make sure both don't
- {
- fprintf(stderr, "'cloneNode' did not clone the DOMEntityReference* node correctlyn");
- OK = false;
- }
- // Deep clone test comparison is in testNode & testDocument
- // entityReference->setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ********
- // Test the user data
- // Test simple set and get
- DOMEntityReference* userTest = entityReference;
- DOMNode* userFirst = node2;
- XMLCh* userSecond = tempStr2;
- XMLString::transcode("first", tempStr, 3999);
- XMLString::transcode("document", tempStr2, 3999);
- userTest->setUserData(tempStr2, (void*) document, 0);
- void* mydocument = userTest->getUserData(tempStr2);
- if (document != mydocument) {
- fprintf(stderr, "'set/getUserData' in line %i does not workn", __LINE__);
- OK = false;
- }
- userTest->setUserData(tempStr, (void*) userFirst, 0);
- void* myFirst = userTest->getUserData(tempStr);
- if (userFirst != myFirst) {
- fprintf(stderr, "'set/getUserData' in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test overwrite
- void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0);
- void* mySecond = userTest->getUserData(tempStr);
- if (userSecond != mySecond) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userFirst != myFirst2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userFirst == mySecond) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test null
- // test non-exist key
- XMLString::transcode("not-exist", tempStr3, 3999);
- if (userTest->getUserData(tempStr3)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // use a node that does not have user data set before
- if (node2->getUserData(tempStr)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test reset
- void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0);
- void* myNull = userTest->getUserData(tempStr);
- if (userSecond != mySecond2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (myNull) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0);
- void* myNull2 = userTest->getUserData(tempStr2);
- if (mydocument != mydocument2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (myNull2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- //the userTest user data table should be null now
- if (userTest->getUserData(tempStr)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userTest->getUserData(tempStr2)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test DOMUserDataHandler
- // test clone
- userTest->setUserData(tempStr2, (void*) document, &userhandler);
- DOMNode* mycloned = userTest->cloneNode(true);
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__);
- // test import
- document->setUserData(tempStr2, (void*) document, &userhandler);
- DOMNode* myimport = document->importNode(userTest,true);
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__);
- // test delete
- myimport->setUserData(tempStr2, (void*) userTest, &userhandler);
- myimport->release();
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__);
- // Test isSameNode
- if (!userTest->isSameNode(userTest)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isSameNode(userFirst)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- // Test isEqualNode
- if (!userTest->isEqualNode(mycloned)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (!userTest->isEqualNode(userTest)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isEqualNode(document)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- // Test rename, should throw exception
- EXCEPTIONSTEST(document->renameNode(userTest, 0, tempStr2), DOMException::NOT_SUPPORTED_ERR, OK, 211 );
- if (!OK)
- printf("n*****The DOMEntityReference* method calls listed above failed, all others worked correctly.*****n");
- return OK;
- };
- /**
- * This method tests DOMNode* methods for the XML DOM implementation
- * @param document org.w3c.dom.DOMDocument
- *
- *
- *
- ********* This is only for a test of cloneNode "deep"*******
- ********* And for error tests*********
- */
- bool DOMTest::testNode(DOMDocument* document)
- {
- DOMNode* node, *node2;
- bool result;
- bool OK = true;
- // For debugging***** printf("n testNode's outputs:n");
- node = document->getDocumentElement();
- node2 = node->cloneNode(true);
- result = treeCompare(node, node2); // Deep clone test of cloneNode
- if (result)
- {
- //printf("'cloneNode' successfully cloned this whole node tree (deep)!n");
- }
- else
- {
- fprintf(stderr, "'cloneNode' did not successfully clone this whole node tree (deep)!n");
- OK = false;
- }
- //!! The following gives a did not clone successfully message*********
- node = document->getDocumentElement();
- node2 = node->getFirstChild();
- result = treeCompare(node, node2);
- if (!result)
- {
- //fprintf(stderr, "'cloneNode' did not successfully clone this whole node tree (deep)!n");
- }
- else
- {
- fprintf(stderr, "'cloneNode' was supposed to fail here, either it or 'treeCompare' failed!!!n");
- OK = false;
- }
- // Deep clone test also in testDocument
- // Test the user data
- // Test simple set and get
- DOMNode* userTest = node;
- DOMNode* userFirst = node2;
- XMLCh* userSecond = tempStr2;
- XMLString::transcode("first", tempStr, 3999);
- XMLString::transcode("document", tempStr2, 3999);
- userTest->setUserData(tempStr2, (void*) document, 0);
- void* mydocument = userTest->getUserData(tempStr2);
- if (document != mydocument) {
- fprintf(stderr, "'set/getUserData' in line %i does not workn", __LINE__);
- OK = false;
- }
- userTest->setUserData(tempStr, (void*) userFirst, 0);
- void* myFirst = userTest->getUserData(tempStr);
- if (userFirst != myFirst) {
- fprintf(stderr, "'set/getUserData' in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test overwrite
- void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0);
- void* mySecond = userTest->getUserData(tempStr);
- if (userSecond != mySecond) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userFirst != myFirst2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userFirst == mySecond) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test null
- // test non-exist key
- XMLString::transcode("not-exist", tempStr3, 3999);
- if (userTest->getUserData(tempStr3)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // use a node that does not have user data set before
- if (userFirst->getUserData(tempStr)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test reset
- void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0);
- void* myNull = userTest->getUserData(tempStr);
- if (userSecond != mySecond2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (myNull) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0);
- void* myNull2 = userTest->getUserData(tempStr2);
- if (mydocument != mydocument2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (myNull2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- //the userTest user data table should be null now
- if (userTest->getUserData(tempStr)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userTest->getUserData(tempStr2)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test DOMUserDataHandler
- // test clone
- userTest->setUserData(tempStr2, (void*) document, &userhandler);
- DOMNode* mycloned = userTest->cloneNode(true);
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__);
- // test import
- document->setUserData(tempStr2, (void*) document, &userhandler);
- DOMNode* myimport = document->importNode(userTest,true);
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__);
- // test delete
- myimport->setUserData(tempStr2, (void*) userTest, &userhandler);
- myimport->release();
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__);
- // Test isSameNode
- if (!userTest->isSameNode(userTest)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isSameNode(userFirst)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- // Test isEqualNode
- if (!userTest->isEqualNode(mycloned)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (!userTest->isEqualNode(userTest)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isEqualNode(document)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (!OK)
- printf("n*****The DOMNode* method calls listed above failed, all others worked correctly.*****n");
- return OK;
- };
- /**
- * This method tests DOMNotation* methods for the XML DOM implementation
- * @param document org.w3c.dom.DOMDocument
- *
- */
- bool DOMTest::testNotation(DOMDocument* document)
- {
- DOMNode* node, *node2;
- DOMNotation* notation;
- bool OK = true;
- // For debugging***** printf("n testNotation's outputs:n");
- XMLString::transcode("ourNotationNode", tempStr, 3999);
- DOMNode* abc40 = document->getDoctype()->getNotations()->getNamedItem(tempStr);
- notation = (DOMNotation*) abc40;
- node = notation;
- node2 = notation->cloneNode(true);//*****?
- // Check nodes for equality, both their name and value or lack thereof
- if (!(!XMLString::compareString(node->getNodeName(), node2->getNodeName()) && // Compares node names for equality
- (node->getNodeValue() != 0 && node2->getNodeValue() != 0) // Checks to make sure each node has a value node
- ? !XMLString::compareString(node->getNodeValue(), node2->getNodeValue()) // If both have value nodes test those value nodes for equality
- : (node->getNodeValue() == 0 && node2->getNodeValue() == 0))) // If one node doesn't have a value node make sure both don't
- {
- fprintf(stderr, "'cloneNode' did not clone the DOMNotation* node correctly");
- OK = false;
- }
- // Deep clone test comparison is in testNode & testDocument
- // notation->setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ********
- // Test the user data
- // Test simple set and get
- DOMNotation* userTest = notation;
- DOMNode* userFirst = node2;
- XMLCh* userSecond = tempStr2;
- XMLString::transcode("first", tempStr, 3999);
- XMLString::transcode("document", tempStr2, 3999);
- userTest->setUserData(tempStr2, (void*) document, 0);
- void* mydocument = userTest->getUserData(tempStr2);
- if (document != mydocument) {
- fprintf(stderr, "'set/getUserData' in line %i does not workn", __LINE__);
- OK = false;
- }
- userTest->setUserData(tempStr, (void*) userFirst, 0);
- void* myFirst = userTest->getUserData(tempStr);
- if (userFirst != myFirst) {
- fprintf(stderr, "'set/getUserData' in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test overwrite
- void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0);
- void* mySecond = userTest->getUserData(tempStr);
- if (userSecond != mySecond) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userFirst != myFirst2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userFirst == mySecond) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test null
- // test non-exist key
- XMLString::transcode("not-exist", tempStr3, 3999);
- if (userTest->getUserData(tempStr3)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // use a node that does not have user data set before
- if (userFirst->getUserData(tempStr)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test reset
- void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0);
- void* myNull = userTest->getUserData(tempStr);
- if (userSecond != mySecond2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (myNull) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0);
- void* myNull2 = userTest->getUserData(tempStr2);
- if (mydocument != mydocument2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (myNull2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- //the userTest user data table should be null now
- if (userTest->getUserData(tempStr)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userTest->getUserData(tempStr2)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test DOMUserDataHandler
- // test clone
- userTest->setUserData(tempStr2, (void*) document, &userhandler);
- DOMNode* mycloned = userTest->cloneNode(true);
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__);
- // test import
- document->setUserData(tempStr2, (void*) document, &userhandler);
- DOMNode* myimport = document->importNode(userTest,true);
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__);
- // test delete
- myimport->setUserData(tempStr2, (void*) userTest, &userhandler);
- myimport->release();
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__);
- // Test isSameNode
- if (!userTest->isSameNode(userTest)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isSameNode(userFirst)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- // Test isEqualNode
- if (!userTest->isEqualNode(mycloned)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (!userTest->isEqualNode(userTest)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isEqualNode(document)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- // Test rename, should throw exception
- EXCEPTIONSTEST(document->renameNode(userTest, 0, tempStr2), DOMException::NOT_SUPPORTED_ERR, OK, 212 );
- if (!OK)
- printf("n*****The DOMNotation* method calls listed above failed, all others worked correctly.*****n");
- return OK;
- };
- /**
- * This method tests DOMProcessingInstruction* methods for the XML DOM implementation
- * @param document org.w3c.dom.DOMDocument
- *
- */
- bool DOMTest::testPI(DOMDocument* document)
- {
- DOMProcessingInstruction* pI, *pI2;
- bool OK = true;
- // For debugging***** printf("n testPI's outputs:n");
- DOMNode* abc50 = document->getDocumentElement()->getFirstChild();// Get doc's DOMProcessingInstruction
- pI = (DOMProcessingInstruction*) abc50;
- DOMNode* abc51 = pI->cloneNode(true);//*****?
- pI2 = (DOMProcessingInstruction*) abc51;
- // Check nodes for equality, both their name and value or lack thereof
- if (!(!XMLString::compareString(pI->getNodeName(), pI2->getNodeName()) && // Compares node names for equality
- (pI->getNodeValue() != 0 && pI2->getNodeValue() != 0) // Checks to make sure each node has a value node
- ? !XMLString::compareString(pI->getNodeValue(), pI2->getNodeValue()) // If both have value nodes test those value nodes for equality
- :(pI->getNodeValue() == 0 && pI2->getNodeValue() == 0)))// If one node doesn't have a value node make sure both don't
- {
- fprintf(stderr, "'cloneNode' did not clone the DOMEntity* node correctlyn");
- OK = false;
- }
- // Deep clone test comparison is in testNode & testDocument
- // compare = "This is [#document: 0]'s processing instruction"; // AH Revisit. Where id
- // this ": 0]" stuff come from in the Java version?? I don' think that it is right.
- XMLString::transcode("This is #document's processing instruction", tempStr, 3999);
- if (XMLString::compareString(tempStr, pI->getData()))
- {
- fprintf(stderr, "Warning!!! PI's 'getData' failed!n");
- OK = false;
- }
- XMLString::transcode("PI's reset data", tempStr, 3999);
- pI->setData(tempStr);
- if (XMLString::compareString(tempStr, pI->getData()))
- {
- fprintf(stderr, "Warning!!! PI's 'setData' failed!n");
- OK = false;
- }
- XMLString::transcode("dTargetProcessorChannel", tempStr, 3999);
- if (XMLString::compareString(tempStr, pI->getTarget()))
- {
- fprintf(stderr, "Warning!!! PI's 'getTarget' failed!n");
- OK = false;
- }
- // Restore original PI data.
- XMLString::transcode("This is #document's processing instruction", tempStr, 3999);
- pI->setData(tempStr);
- // Test the user data
- // Test simple set and get
- DOMProcessingInstruction* userTest = pI;
- DOMNode* userFirst = abc51;
- XMLCh* userSecond = tempStr2;
- XMLString::transcode("first", tempStr, 3999);
- XMLString::transcode("document", tempStr2, 3999);
- userTest->setUserData(tempStr2, (void*) document, 0);
- void* mydocument = userTest->getUserData(tempStr2);
- if (document != mydocument) {
- fprintf(stderr, "'set/getUserData' in line %i does not workn", __LINE__);
- OK = false;
- }
- userTest->setUserData(tempStr, (void*) userFirst, 0);
- void* myFirst = userTest->getUserData(tempStr);
- if (userFirst != myFirst) {
- fprintf(stderr, "'set/getUserData' in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test overwrite
- void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0);
- void* mySecond = userTest->getUserData(tempStr);
- if (userSecond != mySecond) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userFirst != myFirst2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userFirst == mySecond) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test null
- // test non-exist key
- XMLString::transcode("not-exist", tempStr3, 3999);
- if (userTest->getUserData(tempStr3)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // use a node that does not have user data set before
- if (abc51->getUserData(tempStr)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test reset(reset)
- void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0);
- void* myNull = userTest->getUserData(tempStr);
- if (userSecond != mySecond2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (myNull) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0);
- void* myNull2 = userTest->getUserData(tempStr2);
- if (mydocument != mydocument2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (myNull2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- //the userTest user data table should be null now
- if (userTest->getUserData(tempStr)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userTest->getUserData(tempStr2)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test DOMUserDataHandler
- // test clone
- userTest->setUserData(tempStr2, (void*) document, &userhandler);
- DOMNode* mycloned = userTest->cloneNode(true);
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__);
- // test import
- document->setUserData(tempStr2, (void*) document, &userhandler);
- DOMNode* myimport = document->importNode(userTest,true);
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__);
- // test delete
- myimport->setUserData(tempStr2, (void*) userTest, &userhandler);
- myimport->release();
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__);
- // Test isSameNode
- if (!userTest->isSameNode(userTest)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isSameNode(userFirst)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- // Test isEqualNode
- if (!userTest->isEqualNode(mycloned)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (!userTest->isEqualNode(userTest)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isEqualNode(document)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- // Test rename, should throw exception
- EXCEPTIONSTEST(document->renameNode(userTest, 0, tempStr2), DOMException::NOT_SUPPORTED_ERR, OK, 213 );
- if (!OK)
- printf("n*****The PI method calls listed above failed, all others worked correctly.*****n");
- return OK;
- };
- /**
- * This method tests DOMText* methods for the XML DOM implementation
- * @param document org.w3c.dom.DOMDocument
- *
- */
- bool DOMTest::testText(DOMDocument* document)
- {
- DOMNode* node, *node2;
- DOMText* text;
- bool OK = true;
- // For debugging***** printf("n testText's outputs:n");
- XMLString::transcode("dBodyLevel31", tempStr, 3999);
- DOMNode* abc70 = document->getDocumentElement()->getElementsByTagName(tempStr)->item(0);
- DOMElement* elem = (DOMElement*) abc70;
- node = elem->getFirstChild(); // charData gets textNode11
- text = (DOMText*) node;
- node2 = node->cloneNode(true);//*****?
- // Check nodes for equality, both their name and value or lack thereof
- if (!(!XMLString::compareString(node->getNodeName(), node2->getNodeName()) && // Compares node names for equality
- (node->getNodeValue() != 0 && node2->getNodeValue() != 0) // Checks to make sure each node has a value node
- ? !XMLString::compareString(node->getNodeValue(), node2->getNodeValue()) // If both have value nodes test those value nodes for equality
- : (node->getNodeValue() == 0 && node2->getNodeValue() == 0))) // If one node doesn't have a value node make sure both don't
- {
- fprintf(stderr, "'cloneNode' did not clone the DOMText* node correctlyn");
- OK = false;
- }
- // Deep clone test comparison is in testNode & testDocument
- text->splitText(25);
- // Three original text nodes were concatenated by 'normalize' in testElement
- XMLString::transcode("dBodyLevel31'sChildTextNo", tempStr, 3999);
- if (XMLString::compareString(tempStr, text->getNodeValue()))
- {
- fprintf(stderr, "First part of DOMText's split text failed!n" );
- OK = false;
- }
- // Three original text nodes were concatenated by 'normalize' in testElement
- XMLString::transcode("de11dBodyLevel31'sChildTextNode12dBodyLevel31'sChildTextNode13", tempStr, 3999);
- if (XMLString::compareString(tempStr, text->getNextSibling()->getNodeValue()))
- {
- fprintf(stderr, "The second part of DOMText's split text failed!n") ;
- OK = false;
- }
- // Re-normalize the text nodes under elem, so that this test can be rerun->
- elem->normalize();
- //************************************************* ERROR TESTS
- DOMTest tests;
- //!! Throws INDEX_SIZE_ERR ********************
- // text.splitText(-1);
- // text.splitText(100);
- // Test the user data
- // Test simple set and get
- DOMText* userTest = text;
- DOMNode* userFirst = node2;
- XMLCh* userSecond = tempStr2;
- XMLString::transcode("first", tempStr, 3999);
- XMLString::transcode("document", tempStr2, 3999);
- userTest->setUserData(tempStr2, (void*) document, 0);
- void* mydocument = userTest->getUserData(tempStr2);
- if (document != mydocument) {
- fprintf(stderr, "'set/getUserData' in line %i does not workn", __LINE__);
- OK = false;
- }
- userTest->setUserData(tempStr, (void*) userFirst, 0);
- void* myFirst = userTest->getUserData(tempStr);
- if (userFirst != myFirst) {
- fprintf(stderr, "'set/getUserData' in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test overwrite
- void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0);
- void* mySecond = userTest->getUserData(tempStr);
- if (userSecond != mySecond) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userFirst != myFirst2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userFirst == mySecond) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test null
- // test non-exist key
- XMLString::transcode("not-exist", tempStr3, 3999);
- if (userTest->getUserData(tempStr3)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // use a node that does not have user data set before
- if (userFirst->getUserData(tempStr)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test reset
- void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0);
- void* myNull = userTest->getUserData(tempStr);
- if (userSecond != mySecond2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (myNull) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0);
- void* myNull2 = userTest->getUserData(tempStr2);
- if (mydocument != mydocument2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- if (myNull2) {
- fprintf(stderr, "overwrite userdata with same key in line %i does not workn", __LINE__);
- OK = false;
- }
- //the userTest user data table should be null now
- if (userTest->getUserData(tempStr)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- if (userTest->getUserData(tempStr2)) {
- fprintf(stderr, "get non-exist user data in line %i does not workn", __LINE__);
- OK = false;
- }
- // Test DOMUserDataHandler
- // test clone
- userTest->setUserData(tempStr2, (void*) document, &userhandler);
- DOMNode* mycloned = userTest->cloneNode(true);
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__);
- // test import
- document->setUserData(tempStr2, (void*) document, &userhandler);
- DOMNode* myimport = document->importNode(userTest,true);
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__);
- // test delete
- myimport->setUserData(tempStr2, (void*) userTest, &userhandler);
- myimport->release();
- USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__);
- // Test isSameNode
- if (!userTest->isSameNode(userTest)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isSameNode(userFirst)) {
- fprintf(stderr, "isSameNode failed in line %in", __LINE__);
- OK = false;
- }
- // Test isEqualNode
- if (!userTest->isEqualNode(mycloned)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (!userTest->isEqualNode(userTest)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- if (userTest->isEqualNode(abc70)) {
- fprintf(stderr, "isEqualNode failed in line %in", __LINE__);
- OK = false;
- }
- // Test rename, should throw exception
- EXCEPTIONSTEST(document->renameNode(userTest, 0, tempStr2), DOMException::NOT_SUPPORTED_ERR, OK, 214 );
- if (!OK)
- printf("n*****The DOMText* method calls listed above failed, all others worked correctly.*****n");
- return OK;
- };
- /**
- * This method tests setting the DOM Level 3 baseURI attribute at
- * parse time on nodes from the document personal-schema.xml.xml
- *
- */
- bool DOMTest::testBaseURI(XercesDOMParser* parser) {
- bool OK = true;
- try {
- // this one assumes executing in samples/data where personal-schema.xml resides
- // please modify if this is not correct
- parser->parse("personal-schema.xml");
- }
- catch (...) {
- fprintf(stderr, "parsing personal-schema.xml failed at line %in", __LINE__);
- return false;
- }
- // test only if there is no error
- if (!parser->getErrorCount()) {
- //Setup testing strings
- XMLCh *fileSchema = XMLString::transcode("file://");
- XMLCh *filePath = XMLString::transcode("samples/data/personal-schema.xml");
- //Test document baseURI
- DOMDocument *document = parser->getDocument();
- //The baseURI should contain `file://' and `samples/data/personal-schema.xml'
- const XMLCh *docBaseURI = document->getBaseURI();
- if(XMLString::patternMatch(docBaseURI, fileSchema) == -1) {
- OK = false;
- fprintf(stderr, "checking baseURI failed at line %in", __LINE__);
- }
- if(XMLString::patternMatch(docBaseURI, filePath) == -1) {
- OK = false;
- fprintf(stderr, "checking baseURI failed at line %in", __LINE__);
- }
- //Create relative paths from document baseURI
- XMLCh *docBaseURIRoot = new XMLCh [ XMLString::stringLen(docBaseURI) ];
- XMLString::copyNString(docBaseURIRoot, docBaseURI, XMLString::lastIndexOf(docBaseURI, chForwardSlash) + 1);
- XMLCh *base_foobar = new XMLCh [ XMLString::stringLen(docBaseURIRoot) + 8];
- XMLString::copyString(base_foobar, docBaseURIRoot);
- XMLCh *foobar = XMLString::transcode("foo/bar");
- XMLString::catString(base_foobar, foobar);
- XMLCh *base_foobarbar = new XMLCh [ XMLString::stringLen(docBaseURIRoot) + 12];
- XMLString::copyString(base_foobarbar, docBaseURIRoot);
- XMLCh *foobarbar = XMLString::transcode("foo/bar/bar");
- XMLString::catString(base_foobarbar, foobarbar);
- XMLCh *base_foocarbar = new XMLCh [ XMLString::stringLen(docBaseURIRoot) + 12];
- XMLString::copyString(base_foocarbar, docBaseURIRoot);
- XMLCh *foocarbar = XMLString::transcode("foo/car/bar");
- XMLString::catString(base_foocarbar, foocarbar);
- XMLCh *file_autobar = XMLString::transcode("file:///auto/bar");
- XMLCh *file_carfoo = XMLString::transcode("file:///car/foo/");
- XMLCh *file_carfoobarbar = XMLString::transcode("file:///car/foo/bar/bar");
- XMLCh *http_carcar = XMLString::transcode("http://www.example.com/car/car");
- XMLCh *http_barfoo = XMLString::transcode("http://www.example.com/bar/foo/");
- XMLCh *http_barfoofoobar = XMLString::transcode("http://www.example.com/bar/foo/foo/bar");
- //Processing instruction before Document Element (has document baseURI)
- DOMNode *node = document->getFirstChild();
- while(node->getNodeType() != DOMNode::PROCESSING_INSTRUCTION_NODE)
- node = node->getNextSibling();
- if(XMLString::compareString(node->getBaseURI(), docBaseURI) != 0) {
- OK = false;
- fprintf(stderr, "checking baseURI failed at line %in", __LINE__);
- }
- //Document Element baseURI (same as document)
- node = document->getDocumentElement();
- if(XMLString::compareString(node->getBaseURI(), docBaseURI) != 0) {
- OK = false;
- fprintf(stderr, "checking baseURI, failed at line %in", __LINE__);
- }
- // <level 1>
- node = node->getFirstChild();
- while(node->getNodeType() != DOMNode::ELEMENT_NODE)
- node = node->getNextSibling();
- DOMNode *level1 = node;
- // <one>
- node = node->getFirstChild();
- while(node->getNodeType() != DOMNode::ELEMENT_NODE)
- node = node->getNextSibling();
- if(XMLString::compareString(node->getBaseURI(), base_foobar) != 0) {
- OK = false;
- fprintf(stderr, "checking baseURI failed at line %in", __LINE__);
- }
- // <inner1>
- node = node->getFirstChild();
- while(node->getNodeType() != DOMNode::ELEMENT_NODE)
- node = node->getNextSibling();
- if(XMLString::compareString(node->getBaseURI(), base_foobarbar) != 0) {
- OK = false;
- fprintf(stderr, "checking baseURI failed at line %in", __LINE__);
- }
- // <inner2>
- node = node->getNextSibling();
- while(node->getNodeType() != DOMNode::ELEMENT_NODE)
- node = node->getNextSibling();
- if(XMLString::compareString(node->getBaseURI(), base_foocarbar) != 0) {
- OK = false;
- fprintf(stderr, "checking baseURI failed at line %in", __LINE__);
- }
- // <?proc-inst-2?>
- node = node->getNextSibling();
- while(node->getNodeType() != DOMNode::PROCESSING_INSTRUCTION_NODE)
- node = node->getNextSibling();
- if(XMLString::compareString(node->getBaseURI(), base_foobar) != 0) {
- OK = false;
- fprintf(stderr, "checking baseURI failed at line %in", __LINE__);
- }
- // <level2>
- node = level1->getNextSibling();
- while(node->getNodeType() != DOMNode::ELEMENT_NODE)
- node = node->getNextSibling();
- DOMNode *level2 = node;
- if(XMLString::compareString(node->getBaseURI(), file_autobar) != 0) {
- OK = false;
- fprintf(stderr, "checking baseURI failed at line %in", __LINE__);
- }
- // <two>
- node = node->getFirstChild();
- while(node->getNodeType() != DOMNode::ELEMENT_NODE)
- node = node->getNextSibling();
- if(XMLString::compareString(node->getBaseURI(), file_carfoo) != 0) {
- OK = false;
- fprintf(stderr, "checking baseURI failed at line %in", __LINE__);
- }
- // <inner1>
- node = node->getFirstChild();
- while(node->getNodeType() != DOMNode::ELEMENT_NODE)
- node = node->getNextSibling();
- if(XMLString::compareString(node->getBaseURI(), file_carfoobarbar) != 0) {
- OK = false;
- fprintf(stderr, "checking baseURI failed at line %in", __LINE__);
- }
- // <level3>
- node = level2->getNextSibling();
- while(node->getNodeType() != DOMNode::ELEMENT_NODE)
- node = node->getNextSibling();
- if(XMLString::compareString(node->getBaseURI(), http_carcar) != 0) {
- OK = false;
- fprintf(stderr, "checking baseURI failed at line %in", __LINE__);
- }
- // <three>
- node = node->getFirstChild();
- while(node->getNodeType() != DOMNode::ELEMENT_NODE)
- node = node->getNextSibling();
- if(XMLString::compareString(node->getBaseURI(), http_barfoo) != 0) {
- OK = false;
- fprintf(stderr, "checking baseURI failed at line %in", __LINE__);
- }
- // <inner1>
- node = node->getFirstChild();
- while(node->getNodeType() != DOMNode::ELEMENT_NODE)
- node = node->getNextSibling();
- if(XMLString::compareString(node->getBaseURI(), http_barfoofoobar) != 0) {
- OK = false;
- fprintf(stderr, "checking baseURI failed at line %in", __LINE__);
- }
- }
- else {
- printf("baseURI test was not carried outn");
- }
- return OK;
- }
- /**
- *
- * @param node org.w3c.dom.DOMNode
- * @param node2 org.w3c.dom.DOMNode
- *
- */
- bool DOMTest::treeCompare(DOMNode* node, DOMNode* node2)
- {
- bool answer = true;
- DOMNode* kid, *kid2; // Check the subtree for equality
- kid = node->getFirstChild();
- kid2 = node2->getFirstChild();
- if (kid && kid2)
- {
- answer = treeCompare(kid, kid2);
- if (!answer)
- return answer;
- else
- if (kid->getNextSibling() && kid2->getNextSibling())
- {
- while (kid->getNextSibling() && kid2->getNextSibling())
- {
- answer = treeCompare(kid->getNextSibling(), kid2->getNextSibling());
- if (!answer)
- return answer;
- else
- {
- kid = kid->getNextSibling();
- kid2 = kid2->getNextSibling();
- }
- }
- } else
- if (!(!kid->getNextSibling() && !kid2->getNextSibling()))
- {
- return false;
- }
- } else
- if (kid != kid2)
- {
- // One or the other of (kid1, kid2) is 0, but not both.
- return false;
- }
- if (XMLString::compareString(node->getNodeName(), node2->getNodeName()))
- return false;
- if (node->getNodeValue()==0 && node2->getNodeValue()!=0)
- return false;
- if (node->getNodeValue()!=0 && node2->getNodeValue()==0)
- return false;
- if (XMLString::compareString(node->getNodeValue(), node2->getNodeValue()))
- return false;
- return answer;
- };