?? rangetest.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. *//** * $Id: RangeTest.cpp,v 1.15 2004/09/08 13:57:03 peiyongz Exp $ *//** This IRangeTest tests all of the cases delineated as examples * in the DOM Level 2 Range specification, and a few others. * <p>These do not by any means completely test the API and * corner cases. */#include <stdio.h>#include <xercesc/dom/DOM.hpp>#include <xercesc/util/PlatformUtils.hpp>#include <xercesc/util/XMLException.hpp>#include <xercesc/util/XMLString.hpp>#include <xercesc/util/XMLUni.hpp>#include <xercesc/util/XMLUniDefs.hpp>#include <xercesc/dom/DOMRange.hpp>XERCES_CPP_NAMESPACE_USEbool errorOccurred = false;#define TASSERT(c) tassert((c), __FILE__, __LINE__)void tassert(bool c, const char *file, int line){ if (!c) { errorOccurred = true; printf("Failure. Line %d, file %s\n", line, file); }};#define EXCEPTION_TEST(operation, expected_exception) \{ \ try { \ operation; \ printf(" Error: no exception thrown at line %d\n", __LINE__); \ errorOccurred = true; \ } \ catch (DOMRangeException &e) { \ if (e.code != expected_exception) { \ printf(" Wrong RangeException code: %d at line %d\n", e.code, __LINE__); \ errorOccurred = true; \ } \ } \ catch (DOMException &e) { \ if (e.code != expected_exception) { \ printf(" Wrong exception code: %d at line %d\n", e.code, __LINE__); \ errorOccurred = true; \ } \ } \ catch (...) { \ printf(" Wrong exception thrown at line %d\n", __LINE__); \ errorOccurred = true; \ } \}//Define a bunch of XMLCh* string for comparisonXMLCh xa[] = {chLatin_a, chNull};XMLCh xab[] = {chLatin_a, chLatin_b, chNull};XMLCh xabHello[] = {chLatin_a, chLatin_b, chLatin_H, chLatin_e, chLatin_l, chLatin_l, chLatin_o, chNull};XMLCh xabHellocd[] = {chLatin_a, chLatin_b, chLatin_H, chLatin_e, chLatin_l, chLatin_l, chLatin_o, chSpace, chLatin_c, chLatin_d, chNull};XMLCh xAnotherText[] = {chLatin_A, chLatin_n, chLatin_o, chLatin_t, chLatin_h, chLatin_e, chLatin_r, chLatin_T, chLatin_e, chLatin_x, chLatin_t, chNull};XMLCh xb[] = {chLatin_b, chNull};XMLCh xBlahxyz[] = {chLatin_B, chLatin_l, chLatin_a, chLatin_h, chSpace, chLatin_x, chLatin_y, chLatin_z, chNull};XMLCh xBody[] = {chLatin_B, chLatin_o, chLatin_d, chLatin_y, chNull};XMLCh xbody2[] = {chLatin_b, chLatin_o, chLatin_d, chLatin_y, chDigit_2, chNull};XMLCh xc[] = {chLatin_c, chNull};XMLCh xcool[] = {chLatin_c, chLatin_o, chLatin_o, chLatin_l, chNull};XMLCh xef[] = {chLatin_e, chLatin_f, chNull};XMLCh xElement1[] = {chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chDigit_1, chNull};XMLCh xElement2[] = {chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chDigit_2, chNull};XMLCh xElement3[] = {chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chDigit_3, chNull};XMLCh xell[] = {chLatin_e, chLatin_l, chLatin_l, chNull};XMLCh xellocd[] = {chLatin_e, chLatin_l, chLatin_l, chLatin_o, chSpace, chLatin_c, chLatin_d, chNull};XMLCh xellocdef[] = {chLatin_e, chLatin_l, chLatin_l, chLatin_o, chSpace, chLatin_c, chLatin_d, chLatin_e, chLatin_f, chNull};XMLCh xeplacedTextInsertedTexttle[] = {chLatin_e, chLatin_p, chLatin_l, chLatin_a, chLatin_c, chLatin_e, chLatin_d, chLatin_T, chLatin_e, chLatin_x, chLatin_t, chLatin_I, chLatin_n, chLatin_s, chLatin_e, chLatin_r, chLatin_t, chLatin_e, chLatin_d, chLatin_T, chLatin_e, chLatin_x, chLatin_t, chLatin_t, chLatin_l, chLatin_e, chNull};XMLCh xex[] = {chLatin_e, chLatin_x, chNull};XMLCh xext1[] = {chLatin_e, chLatin_x, chLatin_t, chDigit_1, chNull};XMLCh xext3[] = {chLatin_e, chLatin_x, chLatin_t, chDigit_3, chNull};XMLCh xfoo[] = {chLatin_f, chLatin_o, chLatin_o, chNull};XMLCh xH1[] = {chLatin_H, chDigit_1, chNull};XMLCh xh2[] = {chLatin_h, chDigit_2, chNull};XMLCh xh3[] = {chLatin_h, chDigit_3, chNull};XMLCh xh4[] = {chLatin_h, chDigit_4, chNull};XMLCh xHellocd[] = {chLatin_H, chLatin_e, chLatin_l, chLatin_l, chLatin_o, chSpace, chLatin_c, chLatin_d, chNull};XMLCh xhead[] = {chLatin_h, chLatin_e, chLatin_a, chLatin_d, chNull};XMLCh xhead2[] = {chLatin_h, chLatin_e, chLatin_a, chLatin_d, chDigit_2, chNull};XMLCh xInsertedText[] = {chLatin_I, chLatin_n, chLatin_s, chLatin_e, chLatin_r, chLatin_t, chLatin_e, chLatin_d, chLatin_T, chLatin_e, chLatin_x, chLatin_t, chNull};XMLCh xInsertedTexttle[] = {chLatin_I, chLatin_n, chLatin_s, chLatin_e, chLatin_r, chLatin_t, chLatin_e, chLatin_d, chLatin_T, chLatin_e, chLatin_x, chLatin_t, chLatin_t, chLatin_l, chLatin_e, chNull};XMLCh xmoo[] = {chLatin_m, chLatin_o, chLatin_o, chNull};XMLCh xroot[] = {chLatin_r, chLatin_o, chLatin_o, chLatin_t, chNull};XMLCh xroot2[] = {chLatin_r, chLatin_o, chLatin_o, chLatin_t, chDigit_2, chNull};XMLCh xP[] = {chLatin_P, chNull};XMLCh xp1[] = {chLatin_p, chDigit_1, chNull};XMLCh xp2[] = {chLatin_p, chDigit_2, chNull};XMLCh xptext2[] = {chLatin_p, chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_2, chNull};XMLCh xReplacedText[] = {chLatin_R, chLatin_e, chLatin_p, chLatin_l, chLatin_a, chLatin_c, chLatin_e, chLatin_d, chLatin_T, chLatin_e, chLatin_x, chLatin_t, chNull};XMLCh xSurroundNode1[] = {chLatin_S, chLatin_u, chLatin_r, chLatin_r, chLatin_o, chLatin_u, chLatin_n, chLatin_d, chLatin_N, chLatin_o, chLatin_d, chLatin_e, chDigit_1, chNull};XMLCh xt[] = {chLatin_t, chNull};XMLCh xtl[] = {chLatin_t, chLatin_l, chNull};XMLCh xtext1[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_1, chNull};XMLCh xtext2[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_2, chNull};XMLCh xtext2ex[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_2, chLatin_e, chLatin_x, chNull};XMLCh xtext3[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_3, chNull};XMLCh xtext4[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_4, chNull};XMLCh xtext4ext3[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_4, chLatin_e, chLatin_x, chLatin_t, chDigit_3, chNull};XMLCh xttext4ext3[] = {chLatin_t, chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_4, chLatin_e, chLatin_x, chLatin_t, chDigit_3, chNull};XMLCh xtext5[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_5, chNull};XMLCh xtext6[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_6, chNull};XMLCh xTi[] = {chLatin_T, chLatin_i, chNull};XMLCh xTitle[] = {chLatin_T, chLatin_i, chLatin_t, chLatin_l, chLatin_e, chNull};XMLCh xtle[] = {chLatin_t, chLatin_l, chLatin_e, chNull};XMLCh xu[] = {chLatin_u, chNull};XMLCh xupbody[] = {chLatin_u, chLatin_p, chLatin_b, chLatin_o, chLatin_d, chLatin_y, chNull};XMLCh xupbody2[] = {chLatin_u, chLatin_p, chLatin_b, chLatin_o, chLatin_d, chLatin_y, chDigit_2, chNull};XMLCh xupp1[] = {chLatin_u, chLatin_p, chLatin_p, chDigit_1, chNull};XMLCh xuptext1[] = {chLatin_u, chLatin_p, chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_1, chNull};XMLCh xuptext2[] = {chLatin_u, chLatin_p, chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_2, chNull};int main(){ try { XMLPlatformUtils::Initialize(); } catch (const XMLException& toCatch) { char *pMessage = XMLString::transcode(toCatch.getMessage()); fprintf(stderr, "Error during XMLPlatformUtils::Initialize(). \n" " Message is: %s\n", pMessage); XMLString::release(&pMessage); return -1; } /* Range tests include testing of createRange setStart, setStartBefore. setStartAfter, setEnd, setEndBefore. setEndAfter getStartContainer, getStartOffset getEndContainer, getEndOffset getCommonAncestorContainer selectNode selectNodeContents insertNode deleteContents collapse getCollapsed surroundContents compareBoundaryPoints cloneRange cloneContents extractContents toString detach removeChild */ { XMLCh tempStr[100]; XMLString::transcode("Range",tempStr,99); { DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(tempStr); DOMDocument* doc = impl->createDocument(); //Creating a root element DOMElement* root = doc->createElement(xBody); doc->appendChild(root); //Creating the siblings of root DOMElement* E11 = doc->createElement(xH1); root->appendChild(E11); DOMElement* E12 = doc->createElement(xP); root->appendChild(E12); //Attaching texts to siblings DOMText* textNode1 = doc->createTextNode(xTitle); E11->appendChild(textNode1); DOMText* textNode11 = doc->createTextNode(xAnotherText); E11->appendChild(textNode11); DOMText* textNode2 = doc->createTextNode(xBlahxyz); E12->appendChild(textNode2); DOMText* E210 = doc->createTextNode(xInsertedText); doc->release(); } { //DOM Tree and some usable node creation DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(tempStr); DOMDocument* doc = impl->createDocument(); //Creating a root element DOMElement* root = doc->createElement(xBody); doc->appendChild(root); //Creating the siblings of root DOMElement* E11 = doc->createElement(xH1); root->appendChild(E11); DOMElement* E12 = doc->createElement(xP); root->appendChild(E12); //Attaching texts to siblings
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -