?? dtest.cpp
字號:
/* * Copyright 2001,2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *//* * $Log: DTest.cpp,v $ * Revision 1.42 2004/09/08 13:57:02 peiyongz * Apache License Version 2.0 * * Revision 1.41 2004/09/02 15:11:42 cargilld * Add OutOfMemoryException block to tests. * * Revision 1.40 2004/03/02 13:53:50 amassari * Added test for bug# 26919 * * Revision 1.39 2003/02/05 18:55:19 tng * [Bug 11915] Utility for freeing memory. * * Revision 1.38 2003/01/29 20:04:09 gareth * testing for DOMTypeInfo * * Revision 1.37 2003/01/03 17:09:02 tng * delete the parser when done, avoid memory leak report with the test case * * Revision 1.36 2002/11/21 22:12:08 tng * fix typo where isID should be isId * * Revision 1.35 2002/11/21 14:24:39 gareth * Tests added for isId, setIdAttribute, setIdAttributeNS, setIdAttributeNode * * Revision 1.34 2002/11/12 17:52:01 tng * Test update: do not issue "Test Run Successfully" if there was an error. * * Revision 1.33 2002/09/23 21:00:14 tng * DOM L3: fix to isDefaultNamespace. Patch from Gareth Reakes. * * Revision 1.32 2002/09/23 20:09:23 tng * DOM L3: Test baseURI with different parser's setting. * * Revision 1.31 2002/09/23 18:27:48 tng * DOM L3: Test baseURI. Added by Gareth Reakes and Thomas Ford. * * Revision 1.30 2002/08/21 20:59:11 tng * release the cloned document. * * Revision 1.29 2002/08/19 19:56:08 tng * DOM L3: test DOMNode::isDefaultNamespace. Added by Gareth Reakes. * * Revision 1.28 2002/08/16 19:22:29 tng * Test DOM L3 lookupNamespacePrefix, lookupNamespaceURI support. Added by Gareth Reakes. * * Revision 1.27 2002/08/16 16:03:02 tng * [Bug 11360] Release user data using handler. * * Revision 1.26 2002/08/16 13:49:56 tng * [Bug 11360] Release user data using handler. * * Revision 1.25 2002/08/09 20:21:21 tng * Test DOM L3 compareTreePosition. * * Revision 1.24 2002/07/04 15:35:15 tng * DOM L3: Test DOMDocument::renameNode * * Revision 1.23 2002/06/27 18:42:16 tng * DOM L3: Test DOMNode::isSameNode and DOMNode::isEqualNode * * Revision 1.22 2002/06/25 16:22:52 tng * DOM L3: use release() * * Revision 1.21 2002/06/12 18:31:17 tng * DOM L3: test the DOMUserDataHandler and set/getUserData * * Revision 1.20 2002/06/03 20:51:21 tng * DOM L3: Add DOMImplementationRegistry and DOMImplementationSource * * Revision 1.19 2002/05/21 18:50:16 tng * Test case update: modify to use the latest DOM interface * * Revision 1.6 2002/04/01 21:04:00 tng * According to DOM spec, setNodeValue by default is no-op. * * Revision 1.5 2002/03/14 21:59:29 tng * Run methods test[NodeType] in the IDOMTest and other fixes. * * Revision 1.4 2002/02/01 22:44:24 peiyongz * sane_include * * Revision 1.3 2001/12/07 01:48:27 tng * [Bug 1959] setNodeValue throws exception when spec specifies NOP. * * Revision 1.2 2001/11/23 16:16:52 tng * Elimiate compiler warning Warning: String literal converted to char* in initialization. * * Revision 1.1 2001/08/09 19:28:47 tng * Port test case DOMTest to IDOMTest * *//** * This class tests methods for XML DOM implementation * DOMException errors are tested by calls to DOMExceptionsTest from: Main, docBuilder... * */#include <stdio.h>#include "DTest.h"#include <xercesc/util/PlatformUtils.hpp>#include <xercesc/util/XMLException.hpp>#include <xercesc/util/XMLString.hpp>#include <xercesc/parsers/XercesDOMParser.hpp>#include <xercesc/dom/DOMException.hpp>#include <xercesc/util/OutOfMemoryException.hpp>#define EXCEPTIONSTEST(operation, expectedException, resultFlag, testNum) \ { \ try \ { \ operation; \ fprintf(stderr, "Exceptions Test # %d: no Exception thrown->\n", testNum); \ } \ catch (DOMException &e) \ { \ if (e.code != expectedException) { \ fprintf(stderr, "Exceptions Test # %d: wrong DOMException thrown->\n", \ testNum); \ resultFlag = false; \ } \ } \ catch (...) \ { \ fprintf(stderr, "Exceptions Test # %d: unknown exception thrown->\n", \ testNum); \ resultFlag = false; \ } \ }#define USERDATAHANDLERTEST(userhandler, uoperation, ukey, udata, usrc, udst, uline) \ if (userhandler.getCurrentType() != uoperation) {\ fprintf(stderr, "DOMUserDataHandler::handler's operationType does not work in line %i\n", uline); \ OK = false; \ } \ if (XMLString::compareString(userhandler.getCurrentKey(), ukey)) {\ fprintf(stderr, "DOMUserDataHandler::handler's key does not work in line %i\n", uline); \ OK = false; \ } \ if (userhandler.getCurrentData() != udata) {\ fprintf(stderr, "DOMUserDataHandler::handler's data does not work in line %i\n", uline); \ OK = false; \ } \ if (userhandler.getCurrentSrc() != usrc) {\ fprintf(stderr, "DOMUserDataHandler::handler's src does not work in line %i\n", uline); \ OK = false; \ } \ if (userhandler.getCurrentDst() != udst) {\ fprintf(stderr, "DOMUserDataHandler::handler's dst does not work in line %i\n", uline); \ OK = false; \ }#define LOOKUPDEFAULTNSTEST(thisNode, uri, pass, line) \ if(thisNode->isDefaultNamespace(uri)) { \ if(!pass) { \ fprintf(stderr, "DOMNode::isDefaultNamespace returned true in line %i\n", line); \ OK = false; \ } \ } \ else { \ if(pass) { \ fprintf(stderr, "DOMNode::isDefaultNamespace returned false in line %i\n", line); \ OK = false; \ } \ }#define LOOKUPNSTEST(thisNode, prefix, uri, pass, line) \ prefixResult = XMLString::compareString(thisNode->lookupNamespacePrefix(uri, false), prefix); \ prefixResult2 = XMLString::compareString(thisNode->lookupNamespacePrefix(uri, true), prefix); \ uriResult = XMLString::compareString(thisNode->lookupNamespaceURI(prefix), uri); \ if(pass) { \ if(prefixResult != 0) { \ fprintf(stderr, "DOMNode::lookupNamespacePrefix does not work in line %i\n", line); \ OK = false; \ } \ if(prefixResult2 != 0) { \ fprintf(stderr, "DOMNode::lookupNamespacePrefix does not work in line %i\n", line); \ OK = false; \ } \ if(uriResult != 0) { \ fprintf(stderr, "DOMNode::lookupNamespaceURI does not work in line %i\n", line); \ OK = false;\ } \ } \ else { \ if(prefixResult == 0) { \ fprintf(stderr, "DOMNode::lookupNamespacePrefix does not work in line %i\n", line); \ OK = false; \ } \ if(prefixResult2 == 0) { \ fprintf(stderr, "DOMNode::lookupNamespacePrefix does not work in line %i\n", line); \ OK = false; \ } \ if(uriResult == 0) { \ fprintf(stderr, "DOMNode::lookupNamespaceURI does not work in line %i\n", line); \ OK = false; \ } \ } \int prefixResult;int prefixResult2;int uriResult;#define COMPARETREEPOSITIONTEST(thisNode, otherNode, position, line) \ myposition = thisNode->compareTreePosition(otherNode); \ if (position == DOMNode::TREE_POSITION_DISCONNECTED) { \ if ((myposition & DOMNode::TREE_POSITION_DISCONNECTED) != 0) {\ fprintf(stderr, "DOMNode::compareTreePosition does not work in line %i\n", line); \ OK = false; \ } \ } \ else if ((myposition & position) == 0) {\ fprintf(stderr, "DOMNode::compareTreePosition does not work in line %i\n", line); \ OK = false; \ }// temp position for compareTreePositionshort myposition;//temp XMLCh String BufferXMLCh tempStr[4000];XMLCh tempStr2[4000];XMLCh tempStr3[4000];XMLCh tempStr4[4000];XMLCh tempStr5[4000];//DOMUserDataHandlermyUserDataHandler userhandler;DOMElement* DOMTest::testElementNode;DOMAttr* DOMTest::testAttributeNode;DOMText* DOMTest::testTextNode;DOMCDATASection* DOMTest::testCDATASectionNode;DOMEntityReference* DOMTest::testEntityReferenceNode;DOMEntity* DOMTest::testEntityNode;DOMProcessingInstruction* DOMTest::testProcessingInstructionNode;DOMComment* DOMTest::testCommentNode;DOMDocument* DOMTest::testDocumentNode;DOMDocumentType* DOMTest::testDocumentTypeNode;DOMDocumentFragment* DOMTest::testDocumentFragmentNode;DOMNotation* DOMTest::testNotationNode;/** * * */DOMTest::DOMTest(){};/** * * @return DOMDocument * */DOMDocument* DOMTest::createDocument() { XMLCh coreStr[100]; XMLString::transcode("Core",coreStr,99); DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(coreStr); return impl->createDocument();};/** * * @return DOMDocumentType * @param name XMLCh* * */DOMDocumentType* DOMTest::createDocumentType(DOMDocument* doc, XMLCh* name) { return doc->createDocumentType(name); //Replace with a DOMDocumentType* creator};/** * * @return org.w3c.dom.DOMEntity * @param doc org.w3c.dom.DOMDocument * @param name XMLCh* * */DOMEntity* DOMTest::createEntity(DOMDocument* doc, XMLCh* name) { return doc->createEntity(name);};/** * * @return org.w3c.dom.DOMNotation * @param doc org.w3c.dom.DOMDocument * @param name XMLCh* * */DOMNotation* DOMTest::createNotation(DOMDocument* doc, XMLCh* name) { return doc->createNotation(name);};/** * This method builds test documents for the XML DOM implementation * @param document org.w3c.dom.DOMDocument * @param name document's name * @param type document's type * */bool DOMTest::docBuilder(DOMDocument* document, XMLCh* nameIn){ XMLCh* name = XMLString::replicate(nameIn); DOMDocument* doc = document;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -