RangeTest.cpp
上传用户:zhuqijet
上传日期:2013-06-25
资源大小:10074k
文件大小:49k
源码类别:

词法分析

开发平台:

Visual C++

  1. /*
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2001 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Xerces" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation, and was
  51.  * originally based on software copyright (c) 2001, International
  52.  * Business Machines, Inc., http://www.ibm.com .  For more information
  53.  * on the Apache Software Foundation, please see
  54.  * <http://www.apache.org/>.
  55.  */
  56. /**
  57.  * $Id: RangeTest.cpp,v 1.14 2003/02/05 18:55:20 tng Exp $
  58.  */
  59. /** This IRangeTest tests all of the cases delineated as examples
  60.  *  in the DOM Level 2 Range specification, and a few others.
  61.  *  <p>These do not by any means completely test the API and
  62.  *  corner cases.
  63.  */
  64. #include <stdio.h>
  65. #include <xercesc/dom/DOM.hpp>
  66. #include <xercesc/util/PlatformUtils.hpp>
  67. #include <xercesc/util/XMLException.hpp>
  68. #include <xercesc/util/XMLString.hpp>
  69. #include <xercesc/util/XMLUni.hpp>
  70. #include <xercesc/util/XMLUniDefs.hpp>
  71. #include <xercesc/dom/DOMRange.hpp>
  72. XERCES_CPP_NAMESPACE_USE
  73. bool errorOccurred = false;
  74. #define TASSERT(c) tassert((c), __FILE__, __LINE__)
  75. void tassert(bool c, const char *file, int line)
  76. {
  77.     if (!c) {
  78.         errorOccurred = true;
  79.         printf("Failure.  Line %d,   file %sn", line, file);
  80.     }
  81. };
  82. #define EXCEPTION_TEST(operation, expected_exception)               
  83. {                                                                   
  84.     try {                                                           
  85.     operation;                                                      
  86.     printf(" Error: no exception thrown at line %dn", __LINE__);   
  87.     errorOccurred = true;                                           
  88.     }                                                               
  89.     catch (DOMRangeException &e) {                                  
  90.     if (e.code != expected_exception) {                             
  91.         printf(" Wrong RangeException code: %d at line %dn", e.code, __LINE__); 
  92.         errorOccurred = true;                                       
  93.     }                                                               
  94.     }                                                               
  95.     catch (DOMException &e) {                                       
  96.     if (e.code != expected_exception) {                             
  97.         printf(" Wrong exception code: %d at line %dn", e.code, __LINE__); 
  98.         errorOccurred = true;                                       
  99.     }                                                               
  100.     }                                                               
  101.     catch (...)   {                                                 
  102.         printf(" Wrong exception thrown at line %dn", __LINE__);   
  103.         errorOccurred = true;                                       
  104.     }                                                               
  105. }
  106. //Define a bunch of XMLCh* string for comparison
  107. XMLCh xa[] = {chLatin_a, chNull};
  108. XMLCh xab[] = {chLatin_a, chLatin_b, chNull};
  109. XMLCh xabHello[] = {chLatin_a, chLatin_b, chLatin_H, chLatin_e, chLatin_l, chLatin_l, chLatin_o, chNull};
  110. XMLCh xabHellocd[] = {chLatin_a, chLatin_b, chLatin_H, chLatin_e, chLatin_l, chLatin_l, chLatin_o, chSpace, chLatin_c, chLatin_d, chNull};
  111. XMLCh xAnotherText[] = {chLatin_A, chLatin_n, chLatin_o, chLatin_t, chLatin_h, chLatin_e, chLatin_r,
  112.      chLatin_T, chLatin_e, chLatin_x, chLatin_t, chNull};
  113. XMLCh xb[] = {chLatin_b, chNull};
  114. XMLCh xBlahxyz[] = {chLatin_B, chLatin_l, chLatin_a, chLatin_h, chSpace,
  115.      chLatin_x, chLatin_y, chLatin_z, chNull};
  116. XMLCh xBody[] = {chLatin_B, chLatin_o, chLatin_d, chLatin_y, chNull};
  117. XMLCh xbody2[] = {chLatin_b, chLatin_o, chLatin_d, chLatin_y, chDigit_2, chNull};
  118. XMLCh xc[] = {chLatin_c, chNull};
  119. XMLCh xcool[] = {chLatin_c, chLatin_o, chLatin_o, chLatin_l, chNull};
  120. XMLCh xef[] = {chLatin_e, chLatin_f, chNull};
  121. XMLCh xElement1[] = {chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chDigit_1, chNull};
  122. XMLCh xElement2[] = {chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chDigit_2, chNull};
  123. XMLCh xElement3[] = {chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chDigit_3, chNull};
  124. XMLCh xell[] = {chLatin_e, chLatin_l, chLatin_l, chNull};
  125. XMLCh xellocd[] = {chLatin_e, chLatin_l, chLatin_l, chLatin_o, chSpace, chLatin_c, chLatin_d, chNull};
  126. XMLCh xellocdef[] = {chLatin_e, chLatin_l, chLatin_l, chLatin_o, chSpace, chLatin_c, chLatin_d, chLatin_e, chLatin_f, chNull};
  127. XMLCh xeplacedTextInsertedTexttle[] = {chLatin_e, chLatin_p, chLatin_l, chLatin_a, chLatin_c, chLatin_e, chLatin_d,
  128.      chLatin_T, chLatin_e, chLatin_x, chLatin_t, chLatin_I, chLatin_n, chLatin_s, chLatin_e, chLatin_r, chLatin_t, chLatin_e, chLatin_d,
  129.      chLatin_T, chLatin_e, chLatin_x, chLatin_t, chLatin_t, chLatin_l, chLatin_e, chNull};
  130. XMLCh xex[] = {chLatin_e, chLatin_x, chNull};
  131. XMLCh xext1[] = {chLatin_e, chLatin_x, chLatin_t, chDigit_1, chNull};
  132. XMLCh xext3[] = {chLatin_e, chLatin_x, chLatin_t, chDigit_3, chNull};
  133. XMLCh xfoo[] = {chLatin_f, chLatin_o, chLatin_o, chNull};
  134. XMLCh xH1[] = {chLatin_H, chDigit_1, chNull};
  135. XMLCh xh2[] = {chLatin_h, chDigit_2, chNull};
  136. XMLCh xh3[] = {chLatin_h, chDigit_3, chNull};
  137. XMLCh xh4[] = {chLatin_h, chDigit_4, chNull};
  138. XMLCh xHellocd[] = {chLatin_H, chLatin_e, chLatin_l, chLatin_l, chLatin_o, chSpace, chLatin_c, chLatin_d, chNull};
  139. XMLCh xhead[] = {chLatin_h, chLatin_e, chLatin_a, chLatin_d, chNull};
  140. XMLCh xhead2[] = {chLatin_h, chLatin_e, chLatin_a, chLatin_d, chDigit_2, chNull};
  141. XMLCh xInsertedText[] = {chLatin_I, chLatin_n, chLatin_s, chLatin_e, chLatin_r, chLatin_t, chLatin_e, chLatin_d,
  142.      chLatin_T, chLatin_e, chLatin_x, chLatin_t, chNull};
  143. XMLCh xInsertedTexttle[] = {chLatin_I, chLatin_n, chLatin_s, chLatin_e, chLatin_r, chLatin_t, chLatin_e, chLatin_d,
  144.      chLatin_T, chLatin_e, chLatin_x, chLatin_t, chLatin_t, chLatin_l, chLatin_e, chNull};
  145. XMLCh xmoo[] = {chLatin_m, chLatin_o, chLatin_o, chNull};
  146. XMLCh xroot[] = {chLatin_r, chLatin_o, chLatin_o, chLatin_t, chNull};
  147. XMLCh xroot2[] = {chLatin_r, chLatin_o, chLatin_o, chLatin_t, chDigit_2, chNull};
  148. XMLCh xP[] = {chLatin_P, chNull};
  149. XMLCh xp1[] = {chLatin_p, chDigit_1, chNull};
  150. XMLCh xp2[] = {chLatin_p, chDigit_2, chNull};
  151. XMLCh xptext2[] = {chLatin_p, chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_2, chNull};
  152. XMLCh xReplacedText[] = {chLatin_R, chLatin_e, chLatin_p, chLatin_l, chLatin_a, chLatin_c, chLatin_e, chLatin_d,
  153.      chLatin_T, chLatin_e, chLatin_x, chLatin_t, chNull};
  154. XMLCh xSurroundNode1[] = {chLatin_S, chLatin_u, chLatin_r, chLatin_r, chLatin_o, chLatin_u, chLatin_n, chLatin_d,
  155.       chLatin_N, chLatin_o, chLatin_d, chLatin_e, chDigit_1, chNull};
  156. XMLCh xt[] = {chLatin_t, chNull};
  157. XMLCh xtl[] = {chLatin_t, chLatin_l, chNull};
  158. XMLCh xtext1[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_1, chNull};
  159. XMLCh xtext2[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_2, chNull};
  160. XMLCh xtext2ex[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_2, chLatin_e, chLatin_x, chNull};
  161. XMLCh xtext3[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_3, chNull};
  162. XMLCh xtext4[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_4, chNull};
  163. XMLCh xtext4ext3[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_4, chLatin_e, chLatin_x, chLatin_t, chDigit_3, chNull};
  164. XMLCh xttext4ext3[] = {chLatin_t, chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_4, chLatin_e, chLatin_x, chLatin_t, chDigit_3, chNull};
  165. XMLCh xtext5[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_5, chNull};
  166. XMLCh xtext6[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_6, chNull};
  167. XMLCh xTi[] = {chLatin_T, chLatin_i, chNull};
  168. XMLCh xTitle[] = {chLatin_T, chLatin_i, chLatin_t, chLatin_l, chLatin_e, chNull};
  169. XMLCh xtle[] = {chLatin_t, chLatin_l, chLatin_e, chNull};
  170. XMLCh xu[] = {chLatin_u, chNull};
  171. XMLCh xupbody[] = {chLatin_u, chLatin_p, chLatin_b, chLatin_o, chLatin_d, chLatin_y, chNull};
  172. XMLCh xupbody2[] = {chLatin_u, chLatin_p, chLatin_b, chLatin_o, chLatin_d, chLatin_y, chDigit_2, chNull};
  173. XMLCh xupp1[] = {chLatin_u, chLatin_p, chLatin_p, chDigit_1, chNull};
  174. XMLCh xuptext1[] = {chLatin_u, chLatin_p, chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_1, chNull};
  175. XMLCh xuptext2[] = {chLatin_u, chLatin_p, chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_2, chNull};
  176. int  main()
  177. {
  178. try {
  179. XMLPlatformUtils::Initialize();
  180. }
  181. catch (const XMLException& toCatch) {
  182.         char *pMessage = XMLString::transcode(toCatch.getMessage());
  183.         fprintf(stderr, "Error during XMLPlatformUtils::Initialize(). n"
  184.                         "  Message is: %sn", pMessage);
  185.         XMLString::release(&pMessage);
  186.         return -1;
  187.     }
  188.     /*
  189.     Range tests include testing of
  190.     createRange
  191.     setStart, setStartBefore. setStartAfter,
  192.     setEnd, setEndBefore. setEndAfter
  193.     getStartContainer, getStartOffset
  194.     getEndContainer, getEndOffset
  195.     getCommonAncestorContainer
  196.     selectNode
  197.     selectNodeContents
  198.     insertNode
  199.     deleteContents
  200.     collapse
  201.     getCollapsed
  202.     surroundContents
  203.     compareBoundaryPoints
  204.     cloneRange
  205.     cloneContents
  206.     extractContents
  207.     toString
  208.     detach
  209.     removeChild
  210.     */
  211.     {
  212.         XMLCh tempStr[100];
  213.         XMLString::transcode("Range",tempStr,99);
  214.         {
  215.             DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
  216.             DOMDocument* doc = impl->createDocument();
  217.             //Creating a root element
  218.             DOMElement*     root = doc->createElement(xBody);
  219.             doc->appendChild(root);
  220.             //Creating the siblings of root
  221.             DOMElement*     E11 = doc->createElement(xH1);
  222.             root->appendChild(E11);
  223.             DOMElement*     E12 = doc->createElement(xP);
  224.             root->appendChild(E12);
  225.             //Attaching texts to siblings
  226.             DOMText*        textNode1 = doc->createTextNode(xTitle);
  227.             E11->appendChild(textNode1);
  228.             DOMText*        textNode11 = doc->createTextNode(xAnotherText);
  229.             E11->appendChild(textNode11);
  230.             DOMText*        textNode2 = doc->createTextNode(xBlahxyz);
  231.             E12->appendChild(textNode2);
  232.             DOMText*     E210 = doc->createTextNode(xInsertedText);
  233.             doc->release();
  234.         }
  235.         {
  236.             //DOM Tree and some usable node creation
  237.             DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
  238.             DOMDocument* doc = impl->createDocument();
  239.             //Creating a root element
  240.             DOMElement*     root = doc->createElement(xBody);
  241.             doc->appendChild(root);
  242.             //Creating the siblings of root
  243.             DOMElement*     E11 = doc->createElement(xH1);
  244.             root->appendChild(E11);
  245.             DOMElement*     E12 = doc->createElement(xP);
  246.             root->appendChild(E12);
  247.             //Attaching texts to siblings
  248.             DOMText*        textNode1 = doc->createTextNode(xTitle);
  249.             E11->appendChild(textNode1);
  250.             DOMText*        textNode11 = doc->createTextNode(xAnotherText);
  251.             E11->appendChild(textNode11);
  252.             DOMText*        textNode2 = doc->createTextNode(xBlahxyz);
  253.             E12->appendChild(textNode2);
  254.             //experimental nodes
  255.             DOMElement*     E120 = doc->createElement(xElement1);
  256.             DOMElement*     E121 = doc->createElement(xElement2);
  257.             DOMElement*     E122 = doc->createElement(xElement3);
  258.             DOMElement*     E311 = doc->createElement(xSurroundNode1);
  259.             DOMText*     E210 = doc->createTextNode(xInsertedText);
  260.             DOMNode* rt = doc->getDocumentElement();
  261.             DOMRange* range = ((DOMDocumentRange*)doc)->createRange();
  262.             //Tests start here
  263.             // Initial dom tree looks like :
  264.             // <Body><H1>TitleAnother Text</H1><P>Blah xyz</P></Body>
  265.             //i.e.,            Body(rt)
  266.             //     _____________|________________
  267.             //     |                           |
  268.             //  ___H1(E11)___                    P(E12)
  269.             //  |           |                    |
  270.             //  "Title"  "Another Text"        "Blah xyz"
  271.             //test for start and end settings of a range
  272.             range->setStart(rt->getFirstChild(), 0);
  273.             TASSERT(range->getStartContainer() == rt->getFirstChild() );
  274.             TASSERT(range->getStartOffset() == 0);
  275.             range->setEnd(rt->getFirstChild(), 1);
  276.             TASSERT(range->getEndContainer() == rt->getFirstChild() );
  277.             TASSERT(range->getEndOffset() == 1);
  278.             //DOMNode* node = range->getCommonAncestorContainer();
  279.             TASSERT(range->getCommonAncestorContainer() == rt->getFirstChild());
  280.             //selection related test
  281.             range->selectNode(rt->getLastChild());
  282.             TASSERT(range->getStartContainer() == rt);
  283.             TASSERT(range->getStartOffset() == 1);
  284.             TASSERT(range->getEndContainer() == rt);
  285.             TASSERT(range->getEndOffset() == 2);
  286.             //insertion related tests
  287.             range->insertNode(E120);
  288.             //only end offset moves and new node gets into range as being inserted at boundary point
  289.             TASSERT(range->getStartContainer() == rt);
  290.             TASSERT(range->getStartOffset() == 1);
  291.             TASSERT(range->getEndContainer() == rt);
  292.             TASSERT(range->getEndOffset() == 3);
  293.             range->insertNode(E121);
  294.             //only end offset moves and new node gets into range as being inserted at boundary point
  295.             TASSERT(range->getStartContainer() == rt);
  296.             TASSERT(range->getStartOffset() == 1);
  297.             TASSERT(range->getEndContainer() == rt);
  298.             TASSERT(range->getEndOffset() == 4);
  299.             rt->insertBefore(E122, rt->getFirstChild());
  300.             //both offsets move as new node is not part of the range
  301.             TASSERT(range->getStartContainer() == rt);
  302.             TASSERT(range->getStartOffset() == 2);
  303.             TASSERT(range->getEndContainer() == rt);
  304.             TASSERT(range->getEndOffset() == 5);
  305.             //After above operations, now the tree looks like:
  306.             // <Body><Element3/><H1>TitleAnother Text</H1><Element2/><Element1/><P>Blah xyz</P></Body>
  307.             //i.e.,            Body(rt)
  308.             //     _____________|_______________________________________________________________
  309.             //     |                |                  |                |                      |
  310.             //  Element3(E122)  ___H1(E11)___        Element2(E121)    Element1(E120)          P(E12)
  311.             //                  |           |                                                  |
  312.             //               "Title"  "Another Text"                                        "Blah xyz"
  313.             //
  314.             // range has rt as start and end container, and 2 as start offset, 5 as end offset
  315.             //changing selection
  316.             range->selectNode(rt->getLastChild()->getPreviousSibling());
  317.             TASSERT(range->getStartContainer() == rt);
  318.             TASSERT(range->getStartOffset() == 3);
  319.             TASSERT(range->getEndContainer() == rt);
  320.             TASSERT(range->getEndOffset() == 4);
  321.             //deleting related tests
  322.             range->deleteContents();
  323.             TASSERT(rt->getLastChild()->getPreviousSibling() == E121);
  324.             range->setStart(rt->getFirstChild()->getNextSibling()->getFirstChild(), 2);
  325.             TASSERT(range->getStartContainer() == rt->getFirstChild()->getNextSibling()->getFirstChild());
  326.             TASSERT(!XMLString::compareString(range->getStartContainer()->getNodeValue(),xTitle));
  327.             TASSERT(range->getStartOffset() == 2);
  328.             range->setEnd(rt->getFirstChild()->getNextSibling()->getFirstChild(), 4);
  329.             TASSERT(range->getEndContainer() == rt->getFirstChild()->getNextSibling()->getFirstChild());
  330.             TASSERT(!XMLString::compareString(range->getEndContainer()->getNodeValue(),xTitle));
  331.             TASSERT(range->getEndOffset() == 4);
  332.             TASSERT(!XMLString::compareString(range->toString(),xtl));
  333.             //inserting text between a text node
  334.             range->insertNode(E210);
  335.             //only end offset moves and new node gets into range as being inserted at boundary point
  336.             TASSERT(range->getStartContainer() == rt->getFirstChild()->getNextSibling()->getFirstChild());
  337.             TASSERT(range->getStartOffset() == 2);
  338.             TASSERT(range->getEndContainer() == rt->getFirstChild()->getNextSibling()->getLastChild()->getPreviousSibling());
  339.             TASSERT(range->getEndOffset() == 2);
  340.             //inserting element node before the selected text node
  341.             range->insertNode(E120);
  342.             //only end offset moves and new node gets into range as being inserted at boundary point
  343.             TASSERT(range->getStartContainer() == rt->getFirstChild()->getNextSibling()->getFirstChild());
  344.             TASSERT(!XMLString::compareString(range->getStartContainer()->getNodeValue(),xTi));
  345.             TASSERT(range->getStartOffset() == 2);
  346.             TASSERT(range->getEndContainer() == rt->getFirstChild()->getNextSibling()->getLastChild()->getPreviousSibling());
  347.             TASSERT(!XMLString::compareString(range->getEndContainer()->getNodeValue(),xtle));
  348.             TASSERT(range->getEndOffset() == 2);
  349.             TASSERT(E11->getChildNodes()->getLength()==6);
  350.            //checking the text replacment
  351.             range->getStartContainer()->setNodeValue(xReplacedText);
  352.             //only the start offset is impact
  353.             TASSERT(range->getStartContainer() == rt->getFirstChild()->getNextSibling()->getFirstChild());
  354.             TASSERT(!XMLString::compareString(range->getStartContainer()->getNodeValue(),xReplacedText));
  355.             TASSERT(range->getStartOffset() == 0);
  356.             TASSERT(range->getEndContainer() == rt->getFirstChild()->getNextSibling()->getLastChild()->getPreviousSibling());
  357.             TASSERT(!XMLString::compareString(range->getEndContainer()->getNodeValue(),xtle));
  358.             TASSERT(range->getEndOffset() == 2);
  359.             //After above operations, now the tree looks like:
  360.             // <Body><Element3/><H1>ReplacedText<Element1/>InsertedTexttleAnother Text</H1><Element2/><P>Blah xyz</P></Body>
  361.             //i.e.,            Body(rt)
  362.             //     _____________|_______________________________________________________________________________________________
  363.             //     |                |                                                                          |                |
  364.             //  Element3(E122)  ___H1(E11)___________________________________________________________        Element2(E121)    P(E12)
  365.             //                  |              |     |                |                      |      |                             |
  366.             //               "ReplacedText"   ""   Element1(E120)   "InsertedText"(E210)   "tle"  "Another Text"              "Blah xyz"
  367.             //
  368.             // range has "ReplacedText" as start container and "tle" as end container
  369.             //   and 0 as start offset, 2 as end offset
  370.             //changing the selection. Preparing for 'surround'
  371.             range->setStart(range->getStartContainer()->getParentNode(), 2);
  372.             range->setEnd(range->getStartContainer(), 5);
  373.             TASSERT(!XMLString::compareString(range->getStartContainer()->getNodeName(),xH1));
  374.             TASSERT(!XMLString::compareString(range->getEndContainer()->getNodeName(),xH1));
  375.             TASSERT(!XMLString::compareString(range->toString(),xInsertedTexttle));
  376.             range->surroundContents(E311);
  377.             TASSERT(!XMLString::compareString(range->getStartContainer()->getNodeName(),xH1));
  378.             TASSERT(range->getStartOffset() == 2);
  379.             TASSERT(!XMLString::compareString(range->getEndContainer()->getNodeName(),xH1));
  380.             TASSERT(range->getEndOffset() == 3);
  381.             TASSERT(E11->getChildNodes()->getLength()==4);
  382.             TASSERT(E311->getChildNodes()->getLength()==3);
  383.             TASSERT(!XMLString::compareString(range->toString(),xInsertedTexttle));
  384.             //After above operations, now the tree looks like:
  385.             // <Body><Element3/><H1>ReplacedText<SurroundNode1><Element1/>InsertedTexttle</SurroundNode1>Another Text</H1><Element2/><P>Blah xyz</P></Body>
  386.             //i.e.,            Body(rt)
  387.             //     _____________|_________________________________________________________________________
  388.             //     |                |                                                    |                |
  389.             //  Element3(E122)  ___H1(E11)___________________________________        Element2(E121)    P(E12)
  390.             //                  |              |     |                      |                            |
  391.             //               "ReplacedText"   ""   SurroundNode1(E311)  "Another Text"              "Blah xyz"
  392.             //                          ____________ |_____________________________
  393.             //                          |                    |                    |
  394.             //                          Element1(E120)   "InsertedText"(E210)   "tle"
  395.             //
  396.             // range has H1 as start and end container and 2 as start offset, 3 as end offset
  397.             //testing cloning
  398.             DOMRange* aRange = range->cloneRange();
  399.             TASSERT(aRange->getStartContainer() == range->getStartContainer());
  400.             TASSERT(aRange->getEndContainer() == range->getEndContainer());
  401.             TASSERT(aRange->getStartOffset() == 2);
  402.             TASSERT(aRange->getEndOffset() == 3);
  403.             //changing the new ranges start
  404.             aRange->setStart(aRange->getStartContainer()->getFirstChild(), 1);
  405.             //comparing the ranges
  406.             short compVal = range->compareBoundaryPoints(DOMRange::END_TO_END, aRange);
  407.             TASSERT(compVal == 0);
  408.             compVal = range->compareBoundaryPoints(DOMRange::START_TO_START, aRange);
  409.             TASSERT(compVal == 1);
  410.             compVal = range->compareBoundaryPoints(DOMRange::START_TO_END, aRange);
  411.             TASSERT(compVal == 1);
  412.             compVal = range->compareBoundaryPoints(DOMRange::END_TO_START, aRange);
  413.             TASSERT(compVal == -1);
  414.             //testing collapse
  415.             //not collapsed
  416.             TASSERT(range->getCollapsed() == false);
  417.             TASSERT(range->getStartOffset() == 2);
  418.             TASSERT(range->getEndOffset() == 3);
  419.             //selectNodeContents
  420.             range->selectNodeContents(rt->getLastChild()->getFirstChild());
  421.             TASSERT(range->getStartContainer() == rt->getLastChild()->getFirstChild());
  422.             TASSERT(range->getEndContainer() == rt->getLastChild()->getFirstChild());
  423.             TASSERT(range->getStartOffset() == 0);
  424.             TASSERT(range->getEndOffset() == 8);
  425.             TASSERT(!XMLString::compareString(range->toString(),xBlahxyz));
  426.             //testing collapse
  427.             range->collapse(true); //collapse to start
  428.             TASSERT(range->getCollapsed() == true);
  429.             TASSERT(range->getStartOffset() == 0);
  430.             TASSERT(range->getEndOffset() == 0);
  431.             TASSERT(!XMLString::compareString(range->toString(),XMLUni::fgZeroLenString));
  432.             TASSERT(aRange->getEndOffset() == 3); //other range is unaffected
  433.             TASSERT(!XMLString::compareString(aRange->toString(),xeplacedTextInsertedTexttle));
  434.             //After above operations, now the tree looks like:
  435.             // <Body><Element3/><H1>ReplacedText<SurroundNode1><Element1/>InsertedTexttle</SurroundNode1>Another Text</H1><Element2/><P>Blah xyz</P></Body>
  436.             //i.e.,            Body(rt)
  437.             //     _____________|_________________________________________________________________________
  438.             //     |                |                                                    |                |
  439.             //  Element3(E122)  ___H1(E11)___________________________________        Element2(E121)    P(E12)
  440.             //                  |              |     |                      |                            |
  441.             //               "ReplacedText"   ""   SurroundNode1(E311)  "Another Text"              "Blah xyz"
  442.             //                          ____________ |_____________________________
  443.             //                          |                    |                    |
  444.             //                          Element1(E120)   "InsertedText"(E210)   "tle"
  445.             //
  446.             // range has "Blah xyz" as start and end container and 0 as start and end offset (collapsed)
  447.             // aRange has "ReplacedText" as start container and H1 as end container
  448.             //    and 1 as start offset and 3 as end offset
  449.             DOMDocumentFragment* docFrag = aRange->cloneContents();
  450.             TASSERT( docFrag != 0);
  451.             range->selectNode(rt->getFirstChild());
  452.             TASSERT(range->getStartContainer() == rt);
  453.             TASSERT(range->getEndContainer() == rt);
  454.             TASSERT(range->getStartOffset() == 0);
  455.             TASSERT(range->getEndOffset() == 1);
  456.             //Testing toString()
  457.             const XMLCh* str = aRange->toString();
  458.             TASSERT(!XMLString::compareString(str, xeplacedTextInsertedTexttle));
  459.             //start and end before and after tests
  460.             range->setStartBefore(rt->getFirstChild());
  461.             TASSERT(range->getStartOffset() == 0);
  462.             range->setEndBefore(rt->getFirstChild());
  463.             TASSERT(range->getEndOffset() == 0);
  464.             range->setStartAfter(rt->getLastChild());
  465.             TASSERT(range->getStartOffset() == 4);
  466.             range->setStartAfter(rt->getFirstChild());
  467.             TASSERT(range->getStartOffset() == 1);
  468.             range->setEndBefore(rt->getLastChild());
  469.             TASSERT(range->getEndOffset() == 3);
  470.             range->setEndAfter(rt->getLastChild());
  471.             TASSERT(range->getEndOffset() == 4);
  472.             //testing extract()
  473.             DOMDocumentFragment* frag2 = range->extractContents();
  474.             TASSERT( frag2 != 0);
  475.             //After above operations, now the tree looks like:
  476.             // <Body><Element3/></Body>
  477.             //i.e.,            Body(rt)
  478.             //                  |
  479.             //               Element3(E122)
  480.             //
  481.             // aRange has rt as start and end container, and 1 as start and end offset (collapsed)
  482.             // range has rt as start and end container, and 1 as start and end offset (collapsed)
  483.             //
  484.             //and frag2 looks:
  485.             // <Body>ReplacedText<SurroundNode1><Element1/>InsertedTexttle</SurroundNode1>Another Text</H1><Element2/><P>Blah xyz</P></Body>
  486.             //i.e.,             Body(rt)
  487.             //      ______________|________________________________________________________
  488.             //      |                                                    |                |
  489.             //   ___H1(E11)___________________________________        Element2(E121)    P(E12)
  490.             //   |              |     |                      |                            |
  491.             //"ReplacedText"   ""   SurroundNode1(E311)  "Another Text"              "Blah xyz"
  492.             //           ____________ |_____________________________
  493.             //           |                    |                    |
  494.             //        Element1(E120)   "InsertedText"(E210)   "tle"
  495.             //
  496.             //the tree do not have those node anymore after extract
  497.             //only Element3 left
  498.             TASSERT(rt->getChildNodes()->getLength()==1);
  499.             //aRange is collapsed
  500.             TASSERT(aRange->getCollapsed() == true);
  501.             TASSERT(aRange->getStartContainer() == rt);
  502.             TASSERT(aRange->getStartOffset() == 1);
  503.             TASSERT(aRange->getEndContainer() == rt);
  504.             TASSERT(aRange->getEndOffset() == 1);
  505.             //range is collapsed as well
  506.             TASSERT(range->getCollapsed() == true);
  507.             TASSERT(range->getStartContainer() == rt);
  508.             TASSERT(range->getStartOffset() == 1);
  509.             TASSERT(range->getEndContainer() == rt);
  510.             TASSERT(range->getEndOffset() == 1);
  511.             //test the document fragment frag2
  512.             TASSERT(frag2->getChildNodes()->getLength()==3);
  513.             //detaching the other range
  514.             aRange->detach();
  515.             range->detach();
  516.             //***************************************************************
  517.             //another set of test
  518.             //TEST createRange, setStart and setEnd, insertnode
  519.             //***************************************************************
  520.             DOMImplementation* impl2 = DOMImplementationRegistry::getDOMImplementation(tempStr);
  521.             DOMDocument* doc2 = impl2->createDocument();
  522.             DOMElement* root2 = doc2->createElement(xroot2);
  523.             doc2->appendChild(root2);
  524.             //case 1: simple text node, start==end
  525.             // <body>text1</body>
  526.             DOMElement* body = doc2->createElement(xBody);
  527.             DOMText* text1 = doc2->createTextNode(xtext1);
  528.             body->appendChild(text1);
  529.             root2->appendChild(body);
  530.             //set range
  531.             DOMRange* range1 = doc2->createRange();
  532.             range1->setStart(text1,1);
  533.             range1->setEnd(text1,3);
  534.             TASSERT(!XMLString::compareString(range1->toString(),xex));
  535.             TASSERT(range1->getStartOffset()==1);
  536.             TASSERT(!XMLString::compareString(range1->getStartContainer()->getNodeValue(),xtext1));
  537.             TASSERT(range1->getEndOffset()==3);
  538.             TASSERT(!XMLString::compareString(range1->getEndContainer()->getNodeValue(),xtext1));
  539.             //now insert a text node
  540.             //<body>ttext2ext1</body>
  541.             DOMText* text2 = doc2->createTextNode(xtext2);
  542.             range1->insertNode(text2);
  543.             TASSERT(!XMLString::compareString(range1->toString(),xtext2ex));
  544.             TASSERT(range1->getStartOffset()==1);
  545.             TASSERT(!XMLString::compareString(range1->getStartContainer()->getNodeValue(),xt));
  546.             TASSERT(range1->getEndOffset()==2);
  547.             TASSERT(!XMLString::compareString(range1->getEndContainer()->getNodeValue(),xext1));
  548.             //now insert a non-text node
  549.             //<body>t<p1/>text2ext1</body>
  550.             DOMElement* p1 = doc2->createElement(xp1);
  551.             range1->insertNode(p1);
  552.             TASSERT(!XMLString::compareString(range1->toString(),xtext2ex));
  553.             TASSERT(range1->getStartOffset()==1);
  554.             TASSERT(!XMLString::compareString(range1->getStartContainer()->getNodeValue(),xt));
  555.             TASSERT(range1->getEndOffset()==2);
  556.             TASSERT(!XMLString::compareString(range1->getEndContainer()->getNodeValue(),xext1));
  557.             //case 2: non-text node, start==end
  558.             // <head><h1/></head>
  559.             DOMElement* head = doc2->createElement(xhead);
  560.             DOMElement* h1 = doc2->createElement(xH1);
  561.             head->appendChild(h1);
  562.             root2->appendChild(head);
  563.             //set range
  564.             DOMRange* range2 = doc2->createRange();
  565.             range2->setStart(head,0);
  566.             range2->setEnd(head,1);
  567.             TASSERT(!XMLString::compareString(range2->toString(),XMLUni::fgZeroLenString));
  568.             TASSERT(range2->getStartOffset()==0);
  569.             TASSERT(!XMLString::compareString(range2->getStartContainer()->getNodeName(),xhead));
  570.             TASSERT(range2->getEndOffset()==1);
  571.             TASSERT(!XMLString::compareString(range2->getEndContainer()->getNodeName(),xhead));
  572.             //now insert a non-text node
  573.             //<head><h2/><h1/></head>
  574.             DOMElement* h2 = doc2->createElement(xh2);
  575.             range2->insertNode(h2);
  576.             TASSERT(!XMLString::compareString(range2->toString(),XMLUni::fgZeroLenString));
  577.             TASSERT(range2->getStartOffset()==0);
  578.             TASSERT(!XMLString::compareString(range2->getStartContainer()->getNodeName(),xhead));
  579.             TASSERT(range2->getEndOffset()==2);
  580.             TASSERT(!XMLString::compareString(range2->getEndContainer()->getNodeName(),xhead));
  581.             //now insert a text node
  582.             //<head>text5<h2/><h1/></head>
  583.             DOMText* text5 = doc2->createTextNode(xtext5);
  584.             range2->insertNode(text5);
  585.             TASSERT(!XMLString::compareString(range2->toString(),xtext5));
  586.             TASSERT(range2->getStartOffset()==0);
  587.             TASSERT(!XMLString::compareString(range2->getStartContainer()->getNodeName(),xhead));
  588.             TASSERT(range2->getEndOffset()==3);
  589.             TASSERT(!XMLString::compareString(range2->getEndContainer()->getNodeName(),xhead));
  590.             //case 3: simple text node, start!=end
  591.             // <body2>text3</body2>
  592.             DOMElement* body2 = doc2->createElement(xbody2);
  593.             DOMText* text3 = doc2->createTextNode(xtext3);
  594.             body2->appendChild(text3);
  595.             root2->appendChild(body2);
  596.             //set range
  597.             DOMRange* range3 = ((DOMDocumentRange*)doc2)->createRange();
  598.             range3->setStart(text3,1);
  599.             range3->setEnd(body2,1);
  600.             TASSERT(!XMLString::compareString(range3->toString(),xext3));
  601.             TASSERT(range3->getStartOffset()==1);
  602.             TASSERT(!XMLString::compareString(range3->getStartContainer()->getNodeValue(),xtext3));
  603.             TASSERT(range3->getEndOffset()==1);
  604.             TASSERT(!XMLString::compareString(range3->getEndContainer()->getNodeName(),xbody2));
  605.             //now insert a textnode
  606.             //<body2>ttext4ext3</body2>
  607.             DOMText* text4 = doc2->createTextNode(xtext4);
  608.             range3->insertNode(text4);
  609.             TASSERT(!XMLString::compareString(range3->toString(),XMLUni::fgZeroLenString));
  610.             TASSERT(range3->getStartOffset()==1);
  611.             TASSERT(!XMLString::compareString(range3->getStartContainer()->getNodeValue(),xt));
  612.             TASSERT(range3->getEndOffset()==1);
  613.             TASSERT(!XMLString::compareString(range3->getEndContainer()->getNodeName(),xbody2));
  614.             //now insert a non-text node
  615.             //<body2>t<p2/>text4ext3</body2>
  616.             DOMElement* p2 = doc2->createElement(xp2);
  617.             range3->insertNode(p2);
  618.             //extra empty node caused by splitting 't'
  619.             TASSERT(!XMLString::compareString(range3->toString(),XMLUni::fgZeroLenString));
  620.             TASSERT(range3->getStartOffset()==1);
  621.             TASSERT(!XMLString::compareString(range3->getStartContainer()->getNodeValue(),xt));
  622.             TASSERT(range3->getEndOffset()==1);
  623.             TASSERT(!XMLString::compareString(range3->getEndContainer()->getNodeName(),xbody2));
  624.             //test toString a bit
  625.             range3->setStart(body2,1);
  626.             range3->setEnd(body2,5);
  627.             TASSERT(!XMLString::compareString(range3->toString(),xtext4ext3));
  628.             range3->setStart(body2,0);
  629.             range3->setEnd(body2,5);
  630.             TASSERT(!XMLString::compareString(range3->toString(),xttext4ext3));
  631.             //case 4: non-text node, start!=end
  632.             // <head2><h3/></head2>
  633.             DOMElement* head2 = doc2->createElement(xhead2);
  634.             DOMElement* h3 = doc2->createElement(xh3);
  635.             head2->appendChild(h3);
  636.             root2->appendChild(head2);
  637.             //set range
  638.             DOMRange* range4 = doc2->createRange();
  639.             range4->setStart(head2,0);
  640.             range4->setEnd(h3,0);
  641.             TASSERT(!XMLString::compareString(range4->toString(),XMLUni::fgZeroLenString));
  642.             TASSERT(range4->getStartOffset()==0);
  643.             TASSERT(!XMLString::compareString(range4->getStartContainer()->getNodeName(),xhead2));
  644.             TASSERT(range4->getEndOffset()==0);
  645.             TASSERT(!XMLString::compareString(range4->getEndContainer()->getNodeName(),xh3));
  646.             //now insert a non-text node
  647.             //<head2><h4/><h3/></head2>
  648.             DOMElement* h4 = doc2->createElement(xh4);
  649.             range4->insertNode(h4);
  650.             TASSERT(!XMLString::compareString(range4->toString(),XMLUni::fgZeroLenString));
  651.             TASSERT(range4->getStartOffset()==0);
  652.             TASSERT(!XMLString::compareString(range4->getStartContainer()->getNodeName(),xhead2));
  653.             TASSERT(range4->getEndOffset()==0);
  654.             TASSERT(!XMLString::compareString(range4->getEndContainer()->getNodeName(),xh3));
  655.             //now insert a text node
  656.             //<head2>text6<h4/><h3/></head2>
  657.             DOMText* text6 = doc2->createTextNode(xtext6);
  658.             range4->insertNode(text6);
  659.             TASSERT(!XMLString::compareString(range4->toString(),xtext6));
  660.             TASSERT(range4->getStartOffset()==0);
  661.             TASSERT(!XMLString::compareString(range4->getStartContainer()->getNodeName(),xhead2));
  662.             TASSERT(range4->getEndOffset()==0);
  663.             TASSERT(!XMLString::compareString(range4->getEndContainer()->getNodeName(),xh3));
  664.             //***************************************************************
  665.             // quick test of updating
  666.             //***************************************************************
  667.             // <upbody>text1</upbody>
  668.             DOMElement* upbody = doc2->createElement(xupbody);
  669.             DOMText* uptext1 = doc2->createTextNode(xuptext1);
  670.             upbody->appendChild(uptext1);
  671.             root2->appendChild(upbody);
  672.             DOMRange* uprange = ((DOMDocumentRange*)doc2)->createRange();
  673.             uprange->setStart(upbody,0);
  674.             uprange->setEnd(upbody,1);
  675.             TASSERT(!XMLString::compareString(uprange->toString(),xuptext1));
  676.             TASSERT(uprange->getStartOffset()==0);
  677.             TASSERT(!XMLString::compareString(uprange->getStartContainer()->getNodeName(),xupbody));
  678.             TASSERT(uprange->getEndOffset()==1);
  679.             TASSERT(!XMLString::compareString(uprange->getEndContainer()->getNodeName(),xupbody));
  680.             // split text
  681.             uptext1->splitText(1);
  682.             TASSERT(!XMLString::compareString(uprange->toString(),xu));
  683.             TASSERT(uprange->getStartOffset()==0);
  684.             TASSERT(!XMLString::compareString(uprange->getStartContainer()->getNodeName(),xupbody));
  685.             TASSERT(uprange->getEndOffset()==1);
  686.             TASSERT(!XMLString::compareString(uprange->getEndContainer()->getNodeName(),xupbody));
  687.             //insert node
  688.             DOMElement* upbody2 = doc2->createElement(xupbody2);
  689.             DOMText* uptext2 = doc2->createTextNode(xuptext2);
  690.             upbody2->appendChild(uptext2);
  691.             root2->appendChild(upbody2);
  692.             DOMRange* uprange2 = ((DOMDocumentRange*)doc2)->createRange();
  693.             uprange2->setStart(uptext2,1);
  694.             uprange2->setEnd(upbody2,1);
  695.             DOMRange* uprange3 = doc2->createRange();
  696.             uprange3->setStart(uptext2,1);
  697.             uprange3->setEnd(upbody2,1);
  698.             TASSERT(!XMLString::compareString(uprange2->toString(),xptext2));
  699.             TASSERT(uprange2->getStartOffset()==1);
  700.             TASSERT(!XMLString::compareString(uprange2->getStartContainer()->getNodeValue(),xuptext2));
  701.             TASSERT(uprange2->getEndOffset()==1);
  702.             TASSERT(!XMLString::compareString(uprange2->getEndContainer()->getNodeName(),xupbody2));
  703.             TASSERT(!XMLString::compareString(uprange3->toString(),xptext2));
  704.             TASSERT(uprange3->getStartOffset()==1);
  705.             TASSERT(!XMLString::compareString(uprange3->getStartContainer()->getNodeValue(),xuptext2));
  706.             TASSERT(uprange3->getEndOffset()==1);
  707.             TASSERT(!XMLString::compareString(uprange3->getEndContainer()->getNodeName(),xupbody2));
  708.             DOMElement* upp1 = doc2->createElement(xupp1);
  709.             uprange2->insertNode(upp1);
  710.             TASSERT(!XMLString::compareString(uprange2->toString(),XMLUni::fgZeroLenString));
  711.             TASSERT(uprange2->getStartOffset()==1);
  712.             TASSERT(!XMLString::compareString(uprange2->getStartContainer()->getNodeValue(),xu));
  713.             TASSERT(uprange2->getEndOffset()==1);
  714.             TASSERT(!XMLString::compareString(uprange2->getEndContainer()->getNodeName(),xupbody2));
  715.             TASSERT(!XMLString::compareString(uprange3->toString(),XMLUni::fgZeroLenString));
  716.             TASSERT(uprange3->getStartOffset()==1);
  717.             TASSERT(!XMLString::compareString(uprange3->getStartContainer()->getNodeValue(),xu));
  718.             TASSERT(uprange3->getEndOffset()==1);
  719.             TASSERT(!XMLString::compareString(uprange3->getEndContainer()->getNodeName(),xupbody2));
  720.             //***************************************************************
  721.             //another set of test
  722.             //<foo><c/><moo><b/></moo>ab<a>Hello cd</a><cool>ef</cool></foo>
  723.             //
  724.             //  ______________________foo_____________________
  725.             //  |          |           |          |           |
  726.             //  c         moo        "ab"         a          cool
  727.             //             |                      |           |
  728.             //             b                    "Hello cd"   "ef"
  729.             //
  730.             DOMImplementation* impl3 = DOMImplementationRegistry::getDOMImplementation(tempStr);
  731.             DOMDocument* doc3 = impl3->createDocument();
  732.             DOMElement* root3 = doc3->createElement(xroot);
  733.             doc3->appendChild(root3);
  734.             DOMElement* foo = doc3->createElement(xfoo);
  735.             DOMElement* moo = doc3->createElement(xmoo);
  736.             DOMElement* cool = doc3->createElement(xcool);
  737.             DOMText* ab = doc3->createTextNode(xab);
  738.             DOMText* cd = doc3->createTextNode(xHellocd);
  739.             DOMText* ef = doc3->createTextNode(xef);
  740.             DOMElement* a = doc3->createElement(xa);
  741.             DOMElement* b = doc3->createElement(xb);
  742.             DOMElement* c = doc3->createElement(xc);
  743.             root3->appendChild(foo);
  744.             foo->appendChild(c);
  745.             foo->appendChild(moo);
  746.             foo->appendChild(ab);
  747.             foo->appendChild(a);
  748.             foo->appendChild(cool);
  749.             moo->appendChild(b);
  750.             a->appendChild(cd);
  751.             cool->appendChild(ef);
  752.             //***************************************************************
  753.             //TEST toString
  754.             //***************************************************************
  755.             DOMRange* newtestrange = ((DOMDocumentRange*)doc3)->createRange();
  756.             //case 1:
  757.             //start container is text node
  758.             //   i) end container is also text node
  759.             //    a) start==end
  760.             //    b) start!=end
  761.             //  ii) end container is not text node
  762.             //    a) start==end => impossible
  763.             //    b) start!=end
  764.             //
  765.             //case 2:
  766.             //start container is not text node
  767.             //   i) end container is text node
  768.             //    a) start==end => impossible
  769.             //    b) start!=end
  770.             //  ii) end container is not text node
  771.             //    a) start==end
  772.             //    b) start!=end
  773.             //case 1, i, a
  774.             newtestrange->setStart( cd, 1 );
  775.             newtestrange->setEnd( cd, 4 );
  776.             TASSERT(!XMLString::compareString(newtestrange->toString(),xell));
  777.             //case 1, i, b
  778.             newtestrange->setStart( cd, 1 );
  779.             newtestrange->setEnd( ef, 2 );
  780.             TASSERT(!XMLString::compareString(newtestrange->toString(),xellocdef));
  781.             //case 1, ii, b
  782.             newtestrange->setStart( cd, 1 );
  783.             newtestrange->setEnd( foo, 4 );
  784.             TASSERT(!XMLString::compareString(newtestrange->toString(),xellocd));
  785.             //case 2, i, b
  786.             newtestrange->setStart( foo, 1 );
  787.             newtestrange->setEnd( cd, 5 );
  788.             TASSERT(!XMLString::compareString(newtestrange->toString(),xabHello));
  789.             //case 2, ii, a
  790.             newtestrange->setStart( foo, 1 );
  791.             newtestrange->setEnd( foo, 4 );
  792.             TASSERT(!XMLString::compareString(newtestrange->toString(),xabHellocd));
  793.             //case 2, ii, b
  794.             newtestrange->setStart( moo, 1 );
  795.             newtestrange->setEnd( foo, 4 );
  796.             TASSERT(!XMLString::compareString(newtestrange->toString(),xabHellocd));
  797.             //***************************************************************
  798.             //test removeChild
  799.             //***************************************************************
  800.             DOMRange* newrange = doc3->createRange();
  801.             newrange->setStart( moo, 0 );
  802.             newrange->setEnd( foo, 4 );
  803.             TASSERT(newrange->getStartOffset()==0);
  804.             TASSERT(!XMLString::compareString(newrange->getStartContainer()->getNodeName(),xmoo));
  805.             TASSERT(newrange->getEndOffset()==4);
  806.             TASSERT(!XMLString::compareString(newrange->getEndContainer()->getNodeName(),xfoo));
  807.             TASSERT(!XMLString::compareString(newrange->toString(),xabHellocd));
  808.             DOMNode* n = newrange->cloneContents();
  809.             DOMNodeList* nol = foo->getChildNodes();
  810.             //removing moo
  811.             DOMNode* rem = foo->removeChild(nol->item(1));
  812.             rem->release();
  813.             TASSERT(newrange->getStartOffset()==1);
  814.             TASSERT(!XMLString::compareString(newrange->getStartContainer()->getNodeName(),xfoo));
  815.             TASSERT(newrange->getEndOffset()==3);
  816.             TASSERT(!XMLString::compareString(newrange->getEndContainer()->getNodeName(),xfoo));
  817.             TASSERT(!XMLString::compareString(newrange->toString(),xabHellocd));
  818.             TASSERT(newtestrange->getStartOffset()==1);
  819.             TASSERT(!XMLString::compareString(newtestrange->getStartContainer()->getNodeName(),xfoo));
  820.             TASSERT(newtestrange->getEndOffset()==3);
  821.             TASSERT(!XMLString::compareString(newtestrange->getEndContainer()->getNodeName(),xfoo));
  822.             TASSERT(!XMLString::compareString(newtestrange->toString(),xabHellocd));
  823.             // Now do some exception test
  824.             newrange->detach();
  825.             EXCEPTION_TEST(newrange->setStart( moo, 0 ), DOMException::INVALID_STATE_ERR);
  826.             EXCEPTION_TEST(newtestrange->setStartBefore(moo), DOMRangeException::INVALID_NODE_TYPE_ERR);
  827.             doc->release();
  828.             doc2->release();
  829.             doc3->release();
  830.         }
  831.     } //creating the dom tree and tests
  832.     // And call the termination method
  833.     XMLPlatformUtils::Terminate();
  834.     if (errorOccurred) {
  835.         printf("Test Failedn");
  836.         return 4;
  837.     }
  838.     printf("Test Run Successfullyn");
  839.     return 0;
  840. };