dtest.cpp

来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 1,677 行 · 第 1/5 页

CPP
1,677
字号
    LOOKUPDEFAULTNSTEST(docBodyLevel21, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docBodyLevel31, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docBodyLevel32, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docCDATASection, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docFirstElement, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docReferenceEntity, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docFirstElementAttr, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(doc, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docNotation, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docComment, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docTextNode2, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docTextNode4, tempStr3, false, __LINE__);    XMLString::transcode("default", tempStr3, 3999);    LOOKUPDEFAULTNSTEST(docProcessingInstruction, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docBodyLevel24, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docBodyLevel23, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docBodyLevel21, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docBodyLevel31, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docBodyLevel32, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docCDATASection, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docFirstElement, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docReferenceEntity, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docFirstElementAttr, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(doc, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docNotation, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docComment, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docTextNode2, tempStr3, false, __LINE__);    LOOKUPDEFAULTNSTEST(docTextNode4, tempStr3, false, __LINE__);    //remove the xmlns attr    docFirstElement->removeAttributeNode(attr3);    LOOKUPDEFAULTNSTEST(docProcessingInstruction, 0, true, __LINE__);    LOOKUPDEFAULTNSTEST(docBodyLevel24, 0, true, __LINE__);    LOOKUPDEFAULTNSTEST(docBodyLevel23, 0, true, __LINE__);    LOOKUPDEFAULTNSTEST(docBodyLevel21, 0, true, __LINE__);    LOOKUPDEFAULTNSTEST(docBodyLevel31, 0, true, __LINE__);    LOOKUPDEFAULTNSTEST(docBodyLevel32, 0, true, __LINE__);    LOOKUPDEFAULTNSTEST(docCDATASection, 0, true, __LINE__);    LOOKUPDEFAULTNSTEST(docFirstElement, 0, true, __LINE__);    LOOKUPDEFAULTNSTEST(docReferenceEntity, 0, true, __LINE__);    LOOKUPDEFAULTNSTEST(docFirstElementAttr, 0, true, __LINE__);    LOOKUPDEFAULTNSTEST(doc, 0, true, __LINE__);    LOOKUPDEFAULTNSTEST(docNotation, 0, false, __LINE__);    LOOKUPDEFAULTNSTEST(docComment, 0, true, __LINE__);    LOOKUPDEFAULTNSTEST(docTextNode2, 0, true, __LINE__);    LOOKUPDEFAULTNSTEST(docTextNode4, 0, true, __LINE__);    XMLString::transcode("someSpecialURI", tempStr3, 3999);    XMLString::transcode("newNameForEle", tempStr4, 3999);    DOMElement *ele = doc->createElementNS(tempStr3, tempStr4);    docFirstElement->insertBefore(ele, docFirstElement->getFirstChild());    // test for bug# 26919    docFirstElement->insertBefore(docFirstElement->getFirstChild(), docFirstElement->getFirstChild());    //a test for lookup when xmlns is not set so we take the fact that there is no prefix to be confimation    LOOKUPDEFAULTNSTEST(ele, tempStr3, true, __LINE__);    docFirstElement->removeAttributeNode(attr1);    docBodyLevel21->removeAttributeNode(attr2);    docFirstElement->removeChild(ele);//***********Following are for errorTests    DOMDocumentFragment* docDocFragment = doc->createDocumentFragment();    //name + "docTextNode3"    XMLString::copyString(tempStr, name);    XMLString::transcode("docTextNode3", tempStr2, 3999);    XMLString::catString(tempStr, tempStr2);    DOMText* docNode3 = doc->createTextNode(tempStr);    //name + "docTextNode4"    XMLString::copyString(tempStr, name);    XMLString::transcode("docTextNode4", tempStr2, 3999);    XMLString::catString(tempStr, tempStr2);    DOMText* docNode4 = doc->createTextNode(tempStr);    //"ourEntityNode"    XMLString::transcode("ourEntityNode", tempStr, 3999);    DOMNode*   abc2 =  doc->getDoctype()->getEntities()->getNamedItem(tempStr);  // Get the DOMEntity* node    DOMEntity* docEntity = (DOMEntity*) abc2;    DOMNode*   abc3 = doc->getFirstChild(); // Get the DOMDocumentType* node    DOMDocumentType* docDocType = (DOMDocumentType*) abc3;    DOMNode*   abc4 = doc->getLastChild()->getLastChild()->getLastChild()->getFirstChild();    DOMEntityReference* entityReferenceText = (DOMEntityReference*) abc4;    //"entityReferenceText information"    XMLString::transcode("entityReferenceText information", tempStr, 3999);    DOMText* entityReferenceText2 = doc->createTextNode(tempStr);//************************************************ ERROR TESTS    DOMTest tests;    EXCEPTIONSTEST(document->appendChild(docBody), DOMException::HIERARCHY_REQUEST_ERR, OK,  1);    EXCEPTIONSTEST(document->appendChild(docBody), DOMException::HIERARCHY_REQUEST_ERR, OK, 2);    EXCEPTIONSTEST(docNode3->appendChild(docNode4), DOMException::HIERARCHY_REQUEST_ERR, OK, 3);    // EXCEPTIONSTEST(doc->insertBefore(docEntity, docFirstElement), DOMException::HIERARCHY_REQUEST_ERR, OK, 4);    EXCEPTIONSTEST(doc->replaceChild(docCDATASection, docFirstElement), DOMException::HIERARCHY_REQUEST_ERR, OK, 5);    //"This shouldn't work!"    XMLString::transcode("entityReferenceText information", tempStr, 3999);    // The following setNodeValue tests are not invalid    // According to DOM spec, if the node value is defined to be null in the DOM spec, setting it has no effect.    // Only those node type that are supposed to have node value, exception will be raised if the node is readonly.    // EXCEPTIONSTEST(docFirstElement->setNodeValue(tempStr), DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 6);    // EXCEPTIONSTEST(docReferenceEntity->setNodeValue(tempStr), DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 7);    // EXCEPTIONSTEST(docEntity->setNodeValue(tempStr), DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 8);    // EXCEPTIONSTEST(doc->setNodeValue(tempStr), DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 9);    // EXCEPTIONSTEST(docDocType->setNodeValue(tempStr), DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 10);    // EXCEPTIONSTEST(docDocFragment->setNodeValue(tempStr), DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 11);    // EXCEPTIONSTEST(docNotation->setNodeValue(tempStr), DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 12);    EXCEPTIONSTEST(docReferenceEntity->appendChild(entityReferenceText2 ), DOMException::NO_MODIFICATION_ALLOWED_ERR , OK, 13);    EXCEPTIONSTEST(docBodyLevel32->insertBefore(docTextNode11,docBody ), DOMException::NOT_FOUND_ERR, OK, 14);    EXCEPTIONSTEST(docBodyLevel32->removeChild(docFirstElement), DOMException::NOT_FOUND_ERR, OK, 15);    EXCEPTIONSTEST(docBodyLevel32->replaceChild(docTextNode11,docFirstElement ), DOMException::NOT_FOUND_ERR, OK, 16);    XMLString::release(&name);    return OK;//!! Throws a NOT_FOUND_ERR ********     // docBodyLevel32->getAttributes()->removeNamedItem(testAttribute->getName());    16  // To test removeNamedItem};  //END OF DOCBUILDER/** * @param document org.w3c.dom.DOMDocument */void DOMTest::findTestNodes(DOMDocument* document) {    DOMNode* node = document;    int nodeCount = 0;    // Walk the tree until you find and assign all node types needed that exist.    while (node != 0 && nodeCount < 12)    {        switch (node->getNodeType())    {        case DOMNode::ELEMENT_NODE :            if (testElementNode == 0) {testElementNode = (DOMElement*)node; nodeCount++;}            break;        case DOMNode::ATTRIBUTE_NODE :            if (testAttributeNode == 0) {testAttributeNode = (DOMAttr*)node; nodeCount++;}            break;        case DOMNode::TEXT_NODE :            if (testTextNode == 0) {testTextNode = (DOMText*)node; nodeCount++;}            break;        case DOMNode::CDATA_SECTION_NODE :            if (testCDATASectionNode == 0) {testCDATASectionNode = (DOMCDATASection*)node; nodeCount++;}            break;        case DOMNode::ENTITY_REFERENCE_NODE :            if (testEntityReferenceNode == 0) {testEntityReferenceNode = (DOMEntityReference*)node; nodeCount++;}            break;        case DOMNode::ENTITY_NODE :            if (testEntityNode == 0) {testEntityNode = (DOMEntity*)node; nodeCount++;}            break;        case DOMNode::PROCESSING_INSTRUCTION_NODE :            if (testProcessingInstructionNode == 0) {testProcessingInstructionNode = (DOMProcessingInstruction*)node; nodeCount++;}            break;        case DOMNode::COMMENT_NODE :            if (testCommentNode == 0) {testCommentNode = (DOMComment*)node; nodeCount++;}            break;        case DOMNode::DOCUMENT_TYPE_NODE :            if (testDocumentTypeNode == 0) {testDocumentTypeNode = (DOMDocumentType*)node; nodeCount++;}            break;        case DOMNode::DOCUMENT_FRAGMENT_NODE :            if (testDocumentFragmentNode == 0) {testDocumentFragmentNode = (DOMDocumentFragment*)node; nodeCount++;}            break;        case DOMNode::NOTATION_NODE :            if (testNotationNode == 0) {testNotationNode = (DOMNotation*)node; nodeCount++;}            break;        case DOMNode::DOCUMENT_NODE :            if (testDocumentNode == 0) {testDocumentNode = (DOMDocument*)node; nodeCount++;}            break;        default:            ;    }// End of switch    }   // End of while};/** * @param document org.w3c.dom.DOMDocument */void DOMTest::findTestNodes(DOMNode* node) {    DOMTest test;    DOMNode*  kid;    // Walk the tree until you find and assign all node types needed that exist.    if (node->getFirstChild() != 0)    {        kid = node->getFirstChild();        test.findTestNodes(kid);    }    if (node->getNextSibling() != 0)    {        kid = node->getNextSibling();        test.findTestNodes(kid);    }    switch (node->getNodeType())    {        case DOMNode::ELEMENT_NODE :            if (testElementNode == 0) {testElementNode = (DOMElement*)node; }            break;        case DOMNode::ATTRIBUTE_NODE :            if (testAttributeNode == 0) {testAttributeNode = (DOMAttr*)node; }            break;        case DOMNode::TEXT_NODE :            if (testTextNode == 0) {testTextNode = (DOMText*)node; }            break;        case DOMNode::CDATA_SECTION_NODE :            if (testCDATASectionNode == 0) {testCDATASectionNode = (DOMCDATASection*)node; }            break;        case DOMNode::ENTITY_REFERENCE_NODE :            if (testEntityReferenceNode == 0) {testEntityReferenceNode = (DOMEntityReference*)node;}            break;        case DOMNode::ENTITY_NODE :            if (testEntityNode == 0) {testEntityNode = (DOMEntity*)node;}            break;        case DOMNode::PROCESSING_INSTRUCTION_NODE :            if (testProcessingInstructionNode == 0) {testProcessingInstructionNode = (DOMProcessingInstruction*)node;}            break;        case DOMNode::COMMENT_NODE :            if (testCommentNode == 0) {testCommentNode = (DOMComment*)node;}            break;        case DOMNode::DOCUMENT_TYPE_NODE :            if (testDocumentTypeNode == 0) {testDocumentTypeNode = (DOMDocumentType*)node; }            break;        case DOMNode::DOCUMENT_FRAGMENT_NODE :            if (testDocumentFragmentNode == 0) {testDocumentFragmentNode = (DOMDocumentFragment*)node;}            break;        case DOMNode::NOTATION_NODE :            if (testNotationNode == 0) {testNotationNode = (DOMNotation*)node;}            break;        case DOMNode::DOCUMENT_NODE :            if (testDocumentNode == 0) {testDocumentNode = (DOMDocument*)node;}            break;        default:            ;    }// End of switch};//End of class/** * * */int main(int argc, char **argv) {     bool OK = true;     {         //  Nest entire test in an inner block.         //     Reference counting should recover all document         //     storage when this block exits.         DOMTest test;         try {             XMLPlatformUtils::Initialize();         }         catch (const XMLException& toCatch) {             char *pMessage = XMLString::transcode(toCatch.getMessage());             fprintf(stderr, "Error during initialization! \n  %s \n", pMessage);             XMLString::release(&pMessage);             return -1;         }         long avgTime = 0;         long startTime = 0;//****************Time the whole thing for efficiency of DOM implementation         // for (int i=0; i< 1000; i++)         // {         // AH Revisit  //  startTime = System.currentTimeMillis();         //     if(!OK)         //     break;         DOMDocument* d = test.createDocument();         XMLString::transcode("testDocument1", tempStr, 3999);         DOMDocumentType* docDocType = test.createDocumentType(d,tempStr);         d->appendChild(docDocType);         XMLString::transcode("ourEntityNode", tempStr, 3999);         DOMEntity* docEntity = test.createEntity( d, tempStr);         //Build a branch for entityReference tests         // DOMText* entityChildText = d.createTextNode("entityChildText information"); //         // docEntity->appendChild(entityChildText);         // docDocType->getEntities()->setNamedItem(docEntity);         XMLString::transcode("d", tempStr3, 3999);         OK = test.docBuilder(d, tempStr3);         test.findTestNodes((DOMNode*)d);         OK = test.testAttr(d);         OK = test.testCDATASection(d);         OK = test.testCharacterData(d);         OK = test.testChildNodeList(d);         OK = test.testComment(d);         OK = test.testDeepNodeList(d);         OK = test.testDocument(d);         OK = test.testDocumentFragment(d);         OK = test.testDocumentType(d);         OK = test.testDOMImplementation(d);         OK = test.testElement(d);//         OK = test.testEntity(d);  // Can not test entities;  only parser can create them.         OK = test.testEntityReference(d);         OK = test.testNode(d);         OK = test.testNotation(d);         OK = test.testPI(d);         OK = test.testText(d);         OK = test.testDOMerrors(d);         // Null out the static object references in class DOMTest,         // which will recover their storage.         DOMTest::testElementNode = 0;         DOMTest::testAttributeNode = 0;         DOMTest::testTextNode = 0;         DOMTest::testCDATASectionNode = 0;         DOMTest::testEntityReferenceNode = 0;         DOMTest::testEntityNode = 0;         DOMTest::testProcessingInstructionNode = 0;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?