IRangeTest.cpp
上传用户:huihehuasu
上传日期:2007-01-10
资源大小:6948k
文件大小:47k
源码类别:

xml/soap/webservice

开发平台:

C/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: IRangeTest.cpp,v 1.6 2001/11/23 16:18:54 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 <idom/IDOM.hpp>
  66. #include <util/PlatformUtils.hpp>
  67. #include <util/XMLException.hpp>
  68. #include <util/XMLString.hpp>
  69. #include <util/XMLUni.hpp>
  70. #include <util/XMLUniDefs.hpp>
  71. #include <idom/IDOM_Range.hpp>
  72. #define TASSERT(c) tassert((c), __FILE__, __LINE__)
  73. void tassert(bool c, const char *file, int line)
  74. {
  75.     if (!c)
  76.         printf("Failure.  Line %d,   file %sn", line, file);
  77. };
  78. #define EXCEPTION_TEST(operation, expected_exception)               
  79. {                                                                   
  80.     try {                                                           
  81.     operation;                                                      
  82.     printf(" Error: no exception thrown at line %dn", __LINE__);   
  83. }                                                                   
  84.     catch (IDOM_DOMException &e) {                                       
  85.     if (e.code != expected_exception)                       
  86.     printf(" Wrong exception code: %d at line %dn", e.code, __LINE__); 
  87. }                                                                 
  88.     catch (...)   {                                                 
  89.     printf(" Wrong exception thrown at line %dn", __LINE__);       
  90. }                                                                   
  91. }
  92. //Define a bunch of XMLCh* string for comparison
  93. XMLCh xa[] = {chLatin_a, chNull};
  94. XMLCh xab[] = {chLatin_a, chLatin_b, chNull};
  95. XMLCh xabHello[] = {chLatin_a, chLatin_b, chLatin_H, chLatin_e, chLatin_l, chLatin_l, chLatin_o, chNull};
  96. XMLCh xabHellocd[] = {chLatin_a, chLatin_b, chLatin_H, chLatin_e, chLatin_l, chLatin_l, chLatin_o, chSpace, chLatin_c, chLatin_d, chNull};
  97. XMLCh xAnotherText[] = {chLatin_A, chLatin_n, chLatin_o, chLatin_t, chLatin_h, chLatin_e, chLatin_r,
  98.      chLatin_T, chLatin_e, chLatin_x, chLatin_t, chNull};
  99. XMLCh xb[] = {chLatin_b, chNull};
  100. XMLCh xBlahxyz[] = {chLatin_B, chLatin_l, chLatin_a, chLatin_h, chSpace,
  101.      chLatin_x, chLatin_y, chLatin_z, chNull};
  102. XMLCh xBody[] = {chLatin_B, chLatin_o, chLatin_d, chLatin_y, chNull};
  103. XMLCh xbody2[] = {chLatin_b, chLatin_o, chLatin_d, chLatin_y, chDigit_2, chNull};
  104. XMLCh xc[] = {chLatin_c, chNull};
  105. XMLCh xcool[] = {chLatin_c, chLatin_o, chLatin_o, chLatin_l, chNull};
  106. XMLCh xef[] = {chLatin_e, chLatin_f, chNull};
  107. XMLCh xElement1[] = {chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chDigit_1, chNull};
  108. XMLCh xElement2[] = {chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chDigit_2, chNull};
  109. XMLCh xElement3[] = {chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chDigit_3, chNull};
  110. XMLCh xell[] = {chLatin_e, chLatin_l, chLatin_l, chNull};
  111. XMLCh xellocd[] = {chLatin_e, chLatin_l, chLatin_l, chLatin_o, chSpace, chLatin_c, chLatin_d, chNull};
  112. XMLCh xellocdef[] = {chLatin_e, chLatin_l, chLatin_l, chLatin_o, chSpace, chLatin_c, chLatin_d, chLatin_e, chLatin_f, chNull};
  113. XMLCh xeplacedTextInsertedTexttle[] = {chLatin_e, chLatin_p, chLatin_l, chLatin_a, chLatin_c, chLatin_e, chLatin_d,
  114.      chLatin_T, chLatin_e, chLatin_x, chLatin_t, chLatin_I, chLatin_n, chLatin_s, chLatin_e, chLatin_r, chLatin_t, chLatin_e, chLatin_d,
  115.      chLatin_T, chLatin_e, chLatin_x, chLatin_t, chLatin_t, chLatin_l, chLatin_e, chNull};
  116. XMLCh xex[] = {chLatin_e, chLatin_x, chNull};
  117. XMLCh xext1[] = {chLatin_e, chLatin_x, chLatin_t, chDigit_1, chNull};
  118. XMLCh xext3[] = {chLatin_e, chLatin_x, chLatin_t, chDigit_3, chNull};
  119. XMLCh xfoo[] = {chLatin_f, chLatin_o, chLatin_o, chNull};
  120. XMLCh xH1[] = {chLatin_H, chDigit_1, chNull};
  121. XMLCh xh2[] = {chLatin_h, chDigit_2, chNull};
  122. XMLCh xh3[] = {chLatin_h, chDigit_3, chNull};
  123. XMLCh xh4[] = {chLatin_h, chDigit_4, chNull};
  124. XMLCh xHellocd[] = {chLatin_H, chLatin_e, chLatin_l, chLatin_l, chLatin_o, chSpace, chLatin_c, chLatin_d, chNull};
  125. XMLCh xhead[] = {chLatin_h, chLatin_e, chLatin_a, chLatin_d, chNull};
  126. XMLCh xhead2[] = {chLatin_h, chLatin_e, chLatin_a, chLatin_d, chDigit_2, chNull};
  127. XMLCh xInsertedText[] = {chLatin_I, chLatin_n, chLatin_s, chLatin_e, chLatin_r, chLatin_t, chLatin_e, chLatin_d,
  128.      chLatin_T, chLatin_e, chLatin_x, chLatin_t, chNull};
  129. XMLCh xInsertedTexttle[] = {chLatin_I, chLatin_n, chLatin_s, chLatin_e, chLatin_r, chLatin_t, chLatin_e, chLatin_d,
  130.      chLatin_T, chLatin_e, chLatin_x, chLatin_t, chLatin_t, chLatin_l, chLatin_e, chNull};
  131. XMLCh xmoo[] = {chLatin_m, chLatin_o, chLatin_o, chNull};
  132. XMLCh xroot[] = {chLatin_r, chLatin_o, chLatin_o, chLatin_t, chNull};
  133. XMLCh xroot2[] = {chLatin_r, chLatin_o, chLatin_o, chLatin_t, chDigit_2, chNull};
  134. XMLCh xP[] = {chLatin_P, chNull};
  135. XMLCh xp1[] = {chLatin_p, chDigit_1, chNull};
  136. XMLCh xp2[] = {chLatin_p, chDigit_2, chNull};
  137. XMLCh xptext2[] = {chLatin_p, chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_2, chNull};
  138. XMLCh xReplacedText[] = {chLatin_R, chLatin_e, chLatin_p, chLatin_l, chLatin_a, chLatin_c, chLatin_e, chLatin_d,
  139.      chLatin_T, chLatin_e, chLatin_x, chLatin_t, chNull};
  140. XMLCh xSurroundNode1[] = {chLatin_S, chLatin_u, chLatin_r, chLatin_r, chLatin_o, chLatin_u, chLatin_n, chLatin_d,
  141.       chLatin_N, chLatin_o, chLatin_d, chLatin_e, chDigit_1, chNull};
  142. XMLCh xt[] = {chLatin_t, chNull};
  143. XMLCh xtl[] = {chLatin_t, chLatin_l, chNull};
  144. XMLCh xtext1[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_1, chNull};
  145. XMLCh xtext2[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_2, chNull};
  146. XMLCh xtext2ex[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_2, chLatin_e, chLatin_x, chNull};
  147. XMLCh xtext3[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_3, chNull};
  148. XMLCh xtext4[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_4, chNull};
  149. XMLCh xtext4ext3[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_4, chLatin_e, chLatin_x, chLatin_t, chDigit_3, chNull};
  150. XMLCh xttext4ext3[] = {chLatin_t, chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_4, chLatin_e, chLatin_x, chLatin_t, chDigit_3, chNull};
  151. XMLCh xtext5[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_5, chNull};
  152. XMLCh xtext6[] = {chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_6, chNull};
  153. XMLCh xTi[] = {chLatin_T, chLatin_i, chNull};
  154. XMLCh xTitle[] = {chLatin_T, chLatin_i, chLatin_t, chLatin_l, chLatin_e, chNull};
  155. XMLCh xtle[] = {chLatin_t, chLatin_l, chLatin_e, chNull};
  156. XMLCh xu[] = {chLatin_u, chNull};
  157. XMLCh xupbody[] = {chLatin_u, chLatin_p, chLatin_b, chLatin_o, chLatin_d, chLatin_y, chNull};
  158. XMLCh xupbody2[] = {chLatin_u, chLatin_p, chLatin_b, chLatin_o, chLatin_d, chLatin_y, chDigit_2, chNull};
  159. XMLCh xupp1[] = {chLatin_u, chLatin_p, chLatin_p, chDigit_1, chNull};
  160. XMLCh xuptext1[] = {chLatin_u, chLatin_p, chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_1, chNull};
  161. XMLCh xuptext2[] = {chLatin_u, chLatin_p, chLatin_t, chLatin_e, chLatin_x, chLatin_t, chDigit_2, chNull};
  162. int  main()
  163. {
  164. try {
  165. XMLPlatformUtils::Initialize();
  166. }
  167. catch (const XMLException& toCatch) {
  168.         char *pMessage = XMLString::transcode(toCatch.getMessage());
  169.         fprintf(stderr, "Error during XMLPlatformUtils::Initialize(). n"
  170.                         "  Message is: %sn", pMessage);
  171.         delete [] pMessage;
  172.         return -1;
  173.     }
  174.     /*
  175.     Range tests include testing of
  176.     createRange
  177.     setStart, setStartBefore. setStartAfter,
  178.     setEnd, setEndBefore. setEndAfter
  179.     getStartContainer, getStartOffset
  180.     getEndContainer, getEndOffset
  181.     getCommonAncestorContainer
  182.     selectNode
  183.     selectNodeContents
  184.     insertNode
  185.     deleteContents
  186.     collapse
  187.     getCollapsed
  188.     surroundContents
  189.     compareBoundaryPoints
  190.     cloneRange
  191.     cloneContents
  192.     extractContents
  193.     toString
  194.     detach
  195.     removeChild
  196.     */
  197.     {
  198.         {
  199.             IDOM_DOMImplementation* impl = IDOM_DOMImplementation::getImplementation();
  200.             IDOM_Document* doc = impl->createDocument();
  201.             //Creating a root element
  202.             IDOM_Element*     root = doc->createElement(xBody);
  203.             doc->appendChild(root);
  204.             //Creating the siblings of root
  205.             IDOM_Element*     E11 = doc->createElement(xH1);
  206.             root->appendChild(E11);
  207.             IDOM_Element*     E12 = doc->createElement(xP);
  208.             root->appendChild(E12);
  209.             //Attaching texts to siblings
  210.             IDOM_Text*        textNode1 = doc->createTextNode(xTitle);
  211.             E11->appendChild(textNode1);
  212.             IDOM_Text*        textNode11 = doc->createTextNode(xAnotherText);
  213.             E11->appendChild(textNode11);
  214.             IDOM_Text*        textNode2 = doc->createTextNode(xBlahxyz);
  215.             E12->appendChild(textNode2);
  216.             IDOM_Text*     E210 = doc->createTextNode(xInsertedText);
  217.             delete doc;
  218.         }
  219.         {
  220.             //DOM Tree and some usable node creation
  221.             IDOM_DOMImplementation* impl = IDOM_DOMImplementation::getImplementation();
  222.             IDOM_Document* doc = impl->createDocument();
  223.             //Creating a root element
  224.             IDOM_Element*     root = doc->createElement(xBody);
  225.             doc->appendChild(root);
  226.             //Creating the siblings of root
  227.             IDOM_Element*     E11 = doc->createElement(xH1);
  228.             root->appendChild(E11);
  229.             IDOM_Element*     E12 = doc->createElement(xP);
  230.             root->appendChild(E12);
  231.             //Attaching texts to siblings
  232.             IDOM_Text*        textNode1 = doc->createTextNode(xTitle);
  233.             E11->appendChild(textNode1);
  234.             IDOM_Text*        textNode11 = doc->createTextNode(xAnotherText);
  235.             E11->appendChild(textNode11);
  236.             IDOM_Text*        textNode2 = doc->createTextNode(xBlahxyz);
  237.             E12->appendChild(textNode2);
  238.             //experimental nodes
  239.             IDOM_Element*     E120 = doc->createElement(xElement1);
  240.             IDOM_Element*     E121 = doc->createElement(xElement2);
  241.             IDOM_Element*     E122 = doc->createElement(xElement3);
  242.             IDOM_Element*     E311 = doc->createElement(xSurroundNode1);
  243.             IDOM_Text*     E210 = doc->createTextNode(xInsertedText);
  244.             IDOM_Node* rt = doc->getDocumentElement();
  245.             IDOM_Range* range = doc->createRange();
  246.             //Tests start here
  247.             // Initial dom tree looks like :
  248.             // <Body><H1>TitleAnother Text</H1><P>Blah xyz</P></Body>
  249.             //i.e.,            Body(rt)
  250.             //     _____________|________________
  251.             //     |                           |
  252.             //  ___H1(E11)___                    P(E12)
  253.             //  |           |                    |
  254.             //  "Title"  "Another Text"        "Blah xyz"
  255.             //test for start and end settings of a range
  256.             range->setStart(rt->getFirstChild(), 0);
  257.             TASSERT(range->getStartContainer() == rt->getFirstChild() );
  258.             TASSERT(range->getStartOffset() == 0);
  259.             range->setEnd(rt->getFirstChild(), 1);
  260.             TASSERT(range->getEndContainer() == rt->getFirstChild() );
  261.             TASSERT(range->getEndOffset() == 1);
  262.             //IDOM_Node* node = range->getCommonAncestorContainer();
  263.             TASSERT(range->getCommonAncestorContainer() == rt->getFirstChild());
  264.             //selection related test
  265.             range->selectNode(rt->getLastChild());
  266.             TASSERT(range->getStartContainer() == rt);
  267.             TASSERT(range->getStartOffset() == 1);
  268.             TASSERT(range->getEndContainer() == rt);
  269.             TASSERT(range->getEndOffset() == 2);
  270.             //insertion related tests
  271.             range->insertNode(E120);
  272.             //only end offset moves and new node gets into range as being inserted at boundary point
  273.             TASSERT(range->getStartContainer() == rt);
  274.             TASSERT(range->getStartOffset() == 1);
  275.             TASSERT(range->getEndContainer() == rt);
  276.             TASSERT(range->getEndOffset() == 3);
  277.             range->insertNode(E121);
  278.             //only end offset moves and new node gets into range as being inserted at boundary point
  279.             TASSERT(range->getStartContainer() == rt);
  280.             TASSERT(range->getStartOffset() == 1);
  281.             TASSERT(range->getEndContainer() == rt);
  282.             TASSERT(range->getEndOffset() == 4);
  283.             rt->insertBefore(E122, rt->getFirstChild());
  284.             //both offsets move as new node is not part of the range
  285.             TASSERT(range->getStartContainer() == rt);
  286.             TASSERT(range->getStartOffset() == 2);
  287.             TASSERT(range->getEndContainer() == rt);
  288.             TASSERT(range->getEndOffset() == 5);
  289.             //After above operations, now the tree looks like:
  290.             // <Body><Element3/><H1>TitleAnother Text</H1><Element2/><Element1/><P>Blah xyz</P></Body>
  291.             //i.e.,            Body(rt)
  292.             //     _____________|_______________________________________________________________
  293.             //     |                |                  |                |                      |
  294.             //  Element3(E122)  ___H1(E11)___        Element2(E121)    Element1(E120)          P(E12)
  295.             //                  |           |                                                  |
  296.             //               "Title"  "Another Text"                                        "Blah xyz"
  297.             //
  298.             // range has rt as start and end container, and 2 as start offset, 5 as end offset
  299.             //changing selection
  300.             range->selectNode(rt->getLastChild()->getPreviousSibling());
  301.             TASSERT(range->getStartContainer() == rt);
  302.             TASSERT(range->getStartOffset() == 3);
  303.             TASSERT(range->getEndContainer() == rt);
  304.             TASSERT(range->getEndOffset() == 4);
  305.             //deleting related tests
  306.             range->deleteContents();
  307.             TASSERT(rt->getLastChild()->getPreviousSibling() == E121);
  308.             range->setStart(rt->getFirstChild()->getNextSibling()->getFirstChild(), 2);
  309.             TASSERT(range->getStartContainer() == rt->getFirstChild()->getNextSibling()->getFirstChild());
  310.             TASSERT(!XMLString::compareString(range->getStartContainer()->getNodeValue(),xTitle));
  311.             TASSERT(range->getStartOffset() == 2);
  312.             range->setEnd(rt->getFirstChild()->getNextSibling()->getFirstChild(), 4);
  313.             TASSERT(range->getEndContainer() == rt->getFirstChild()->getNextSibling()->getFirstChild());
  314.             TASSERT(!XMLString::compareString(range->getEndContainer()->getNodeValue(),xTitle));
  315.             TASSERT(range->getEndOffset() == 4);
  316.             TASSERT(!XMLString::compareString(range->toString(),xtl));
  317.             //inserting text between a text node
  318.             range->insertNode(E210);
  319.             //only end offset moves and new node gets into range as being inserted at boundary point
  320.             TASSERT(range->getStartContainer() == rt->getFirstChild()->getNextSibling()->getFirstChild());
  321.             TASSERT(range->getStartOffset() == 2);
  322.             TASSERT(range->getEndContainer() == rt->getFirstChild()->getNextSibling()->getLastChild()->getPreviousSibling());
  323.             TASSERT(range->getEndOffset() == 2);
  324.             //inserting element node before the selected text node
  325.             range->insertNode(E120);
  326.             //only end offset moves and new node gets into range as being inserted at boundary point
  327.             TASSERT(range->getStartContainer() == rt->getFirstChild()->getNextSibling()->getFirstChild());
  328.             TASSERT(!XMLString::compareString(range->getStartContainer()->getNodeValue(),xTi));
  329.             TASSERT(range->getStartOffset() == 2);
  330.             TASSERT(range->getEndContainer() == rt->getFirstChild()->getNextSibling()->getLastChild()->getPreviousSibling());
  331.             TASSERT(!XMLString::compareString(range->getEndContainer()->getNodeValue(),xtle));
  332.             TASSERT(range->getEndOffset() == 2);
  333.             TASSERT(E11->getChildNodes()->getLength()==6);
  334.            //checking the text replacment
  335.             range->getStartContainer()->setNodeValue(xReplacedText);
  336.             //only the start offset is impact
  337.             TASSERT(range->getStartContainer() == rt->getFirstChild()->getNextSibling()->getFirstChild());
  338.             TASSERT(!XMLString::compareString(range->getStartContainer()->getNodeValue(),xReplacedText));
  339.             TASSERT(range->getStartOffset() == 0);
  340.             TASSERT(range->getEndContainer() == rt->getFirstChild()->getNextSibling()->getLastChild()->getPreviousSibling());
  341.             TASSERT(!XMLString::compareString(range->getEndContainer()->getNodeValue(),xtle));
  342.             TASSERT(range->getEndOffset() == 2);
  343.             //After above operations, now the tree looks like:
  344.             // <Body><Element3/><H1>ReplacedText<Element1/>InsertedTexttleAnother Text</H1><Element2/><P>Blah xyz</P></Body>
  345.             //i.e.,            Body(rt)
  346.             //     _____________|_______________________________________________________________________________________________
  347.             //     |                |                                                                          |                |
  348.             //  Element3(E122)  ___H1(E11)___________________________________________________________        Element2(E121)    P(E12)
  349.             //                  |              |     |                |                      |      |                             |
  350.             //               "ReplacedText"   ""   Element1(E120)   "InsertedText"(E210)   "tle"  "Another Text"              "Blah xyz"
  351.             //
  352.             // range has "ReplacedText" as start container and "tle" as end container
  353.             //   and 0 as start offset, 2 as end offset
  354.             //changing the selection. Preparing for 'surround'
  355.             range->setStart(range->getStartContainer()->getParentNode(), 2);
  356.             range->setEnd(range->getStartContainer(), 5);
  357.             TASSERT(!XMLString::compareString(range->getStartContainer()->getNodeName(),xH1));
  358.             TASSERT(!XMLString::compareString(range->getEndContainer()->getNodeName(),xH1));
  359.             TASSERT(!XMLString::compareString(range->toString(),xInsertedTexttle));
  360.             range->surroundContents(E311);
  361.             TASSERT(!XMLString::compareString(range->getStartContainer()->getNodeName(),xH1));
  362.             TASSERT(range->getStartOffset() == 2);
  363.             TASSERT(!XMLString::compareString(range->getEndContainer()->getNodeName(),xH1));
  364.             TASSERT(range->getEndOffset() == 3);
  365.             TASSERT(E11->getChildNodes()->getLength()==4);
  366.             TASSERT(E311->getChildNodes()->getLength()==3);
  367.             TASSERT(!XMLString::compareString(range->toString(),xInsertedTexttle));
  368.             //After above operations, now the tree looks like:
  369.             // <Body><Element3/><H1>ReplacedText<SurroundNode1><Element1/>InsertedTexttle</SurroundNode1>Another Text</H1><Element2/><P>Blah xyz</P></Body>
  370.             //i.e.,            Body(rt)
  371.             //     _____________|_________________________________________________________________________
  372.             //     |                |                                                    |                |
  373.             //  Element3(E122)  ___H1(E11)___________________________________        Element2(E121)    P(E12)
  374.             //                  |              |     |                      |                            |
  375.             //               "ReplacedText"   ""   SurroundNode1(E311)  "Another Text"              "Blah xyz"
  376.             //                          ____________ |_____________________________
  377.             //                          |                    |                    |
  378.             //                          Element1(E120)   "InsertedText"(E210)   "tle"
  379.             //
  380.             // range has H1 as start and end container and 2 as start offset, 3 as end offset
  381.             //testing cloning
  382.             IDOM_Range* aRange = range->cloneRange();
  383.             TASSERT(aRange->getStartContainer() == range->getStartContainer());
  384.             TASSERT(aRange->getEndContainer() == range->getEndContainer());
  385.             TASSERT(aRange->getStartOffset() == 2);
  386.             TASSERT(aRange->getEndOffset() == 3);
  387.             //changing the new ranges start
  388.             aRange->setStart(aRange->getStartContainer()->getFirstChild(), 1);
  389.             //comparing the ranges
  390.             short compVal = range->compareBoundaryPoints(IDOM_Range::END_TO_END, aRange);
  391.             TASSERT(compVal == 0);
  392.             compVal = range->compareBoundaryPoints(IDOM_Range::START_TO_START, aRange);
  393.             TASSERT(compVal == 1);
  394.             compVal = range->compareBoundaryPoints(IDOM_Range::START_TO_END, aRange);
  395.             TASSERT(compVal == 1);
  396.             compVal = range->compareBoundaryPoints(IDOM_Range::END_TO_START, aRange);
  397.             TASSERT(compVal == -1);
  398.             //testing collapse
  399.             //not collapsed
  400.             TASSERT(range->getCollapsed() == false);
  401.             TASSERT(range->getStartOffset() == 2);
  402.             TASSERT(range->getEndOffset() == 3);
  403.             //selectNodeContents
  404.             range->selectNodeContents(rt->getLastChild()->getFirstChild());
  405.             TASSERT(range->getStartContainer() == rt->getLastChild()->getFirstChild());
  406.             TASSERT(range->getEndContainer() == rt->getLastChild()->getFirstChild());
  407.             TASSERT(range->getStartOffset() == 0);
  408.             TASSERT(range->getEndOffset() == 8);
  409.             TASSERT(!XMLString::compareString(range->toString(),xBlahxyz));
  410.             //testing collapse
  411.             range->collapse(true); //collapse to start
  412.             TASSERT(range->getCollapsed() == true);
  413.             TASSERT(range->getStartOffset() == 0);
  414.             TASSERT(range->getEndOffset() == 0);
  415.             TASSERT(!XMLString::compareString(range->toString(),XMLUni::fgZeroLenString));
  416.             TASSERT(aRange->getEndOffset() == 3); //other range is unaffected
  417.             TASSERT(!XMLString::compareString(aRange->toString(),xeplacedTextInsertedTexttle));
  418.             //After above operations, now the tree looks like:
  419.             // <Body><Element3/><H1>ReplacedText<SurroundNode1><Element1/>InsertedTexttle</SurroundNode1>Another Text</H1><Element2/><P>Blah xyz</P></Body>
  420.             //i.e.,            Body(rt)
  421.             //     _____________|_________________________________________________________________________
  422.             //     |                |                                                    |                |
  423.             //  Element3(E122)  ___H1(E11)___________________________________        Element2(E121)    P(E12)
  424.             //                  |              |     |                      |                            |
  425.             //               "ReplacedText"   ""   SurroundNode1(E311)  "Another Text"              "Blah xyz"
  426.             //                          ____________ |_____________________________
  427.             //                          |                    |                    |
  428.             //                          Element1(E120)   "InsertedText"(E210)   "tle"
  429.             //
  430.             // range has "Blah xyz" as start and end container and 0 as start and end offset (collapsed)
  431.             // aRange has "ReplacedText" as start container and H1 as end container
  432.             //    and 1 as start offset and 3 as end offset
  433.             IDOM_DocumentFragment* docFrag = aRange->cloneContents();
  434.             TASSERT( docFrag != 0);
  435.             range->selectNode(rt->getFirstChild());
  436.             TASSERT(range->getStartContainer() == rt);
  437.             TASSERT(range->getEndContainer() == rt);
  438.             TASSERT(range->getStartOffset() == 0);
  439.             TASSERT(range->getEndOffset() == 1);
  440.             //Testing toString()
  441.             const XMLCh* str = aRange->toString();
  442.             TASSERT(!XMLString::compareString(str, xeplacedTextInsertedTexttle));
  443.             //start and end before and after tests
  444.             range->setStartBefore(rt->getFirstChild());
  445.             TASSERT(range->getStartOffset() == 0);
  446.             range->setEndBefore(rt->getFirstChild());
  447.             TASSERT(range->getEndOffset() == 0);
  448.             range->setStartAfter(rt->getLastChild());
  449.             TASSERT(range->getStartOffset() == 4);
  450.             range->setStartAfter(rt->getFirstChild());
  451.             TASSERT(range->getStartOffset() == 1);
  452.             range->setEndBefore(rt->getLastChild());
  453.             TASSERT(range->getEndOffset() == 3);
  454.             range->setEndAfter(rt->getLastChild());
  455.             TASSERT(range->getEndOffset() == 4);
  456.             //testing extract()
  457.             IDOM_DocumentFragment* frag2 = range->extractContents();
  458.             TASSERT( frag2 != 0);
  459.             //After above operations, now the tree looks like:
  460.             // <Body><Element3/></Body>
  461.             //i.e.,            Body(rt)
  462.             //                  |
  463.             //               Element3(E122)
  464.             //
  465.             // aRange has rt as start and end container, and 1 as start and end offset (collapsed)
  466.             // range has rt as start and end container, and 1 as start and end offset (collapsed)
  467.             //
  468.             //and frag2 looks:
  469.             // <Body>ReplacedText<SurroundNode1><Element1/>InsertedTexttle</SurroundNode1>Another Text</H1><Element2/><P>Blah xyz</P></Body>
  470.             //i.e.,             Body(rt)
  471.             //      ______________|________________________________________________________
  472.             //      |                                                    |                |
  473.             //   ___H1(E11)___________________________________        Element2(E121)    P(E12)
  474.             //   |              |     |                      |                            |
  475.             //"ReplacedText"   ""   SurroundNode1(E311)  "Another Text"              "Blah xyz"
  476.             //           ____________ |_____________________________
  477.             //           |                    |                    |
  478.             //        Element1(E120)   "InsertedText"(E210)   "tle"
  479.             //
  480.             //the tree do not have those node anymore after extract
  481.             //only Element3 left
  482.             TASSERT(rt->getChildNodes()->getLength()==1);
  483.             //aRange is collapsed
  484.             TASSERT(aRange->getCollapsed() == true);
  485.             TASSERT(aRange->getStartContainer() == rt);
  486.             TASSERT(aRange->getStartOffset() == 1);
  487.             TASSERT(aRange->getEndContainer() == rt);
  488.             TASSERT(aRange->getEndOffset() == 1);
  489.             //range is collapsed as well
  490.             TASSERT(range->getCollapsed() == true);
  491.             TASSERT(range->getStartContainer() == rt);
  492.             TASSERT(range->getStartOffset() == 1);
  493.             TASSERT(range->getEndContainer() == rt);
  494.             TASSERT(range->getEndOffset() == 1);
  495.             //test the document fragment frag2
  496.             TASSERT(frag2->getChildNodes()->getLength()==3);
  497.             //detaching the other range
  498.             aRange->detach();
  499.             range->detach();
  500.             //***************************************************************
  501.             //another set of test
  502.             //TEST createRange, setStart and setEnd, insertnode
  503.             //***************************************************************
  504.             IDOM_DOMImplementation* impl2 = IDOM_DOMImplementation::getImplementation();
  505.             IDOM_Document* doc2 = impl2->createDocument();
  506.             IDOM_Element* root2 = doc2->createElement(xroot2);
  507.             doc2->appendChild(root2);
  508.             //case 1: simple text node, start==end
  509.             // <body>text1</body>
  510.             IDOM_Element* body = doc2->createElement(xBody);
  511.             IDOM_Text* text1 = doc2->createTextNode(xtext1);
  512.             body->appendChild(text1);
  513.             root2->appendChild(body);
  514.             //set range
  515.             IDOM_Range* range1 = doc2->createRange();
  516.             range1->setStart(text1,1);
  517.             range1->setEnd(text1,3);
  518.             TASSERT(!XMLString::compareString(range1->toString(),xex));
  519.             TASSERT(range1->getStartOffset()==1);
  520.             TASSERT(!XMLString::compareString(range1->getStartContainer()->getNodeValue(),xtext1));
  521.             TASSERT(range1->getEndOffset()==3);
  522.             TASSERT(!XMLString::compareString(range1->getEndContainer()->getNodeValue(),xtext1));
  523.             //now insert a text node
  524.             //<body>ttext2ext1</body>
  525.             IDOM_Text* text2 = doc2->createTextNode(xtext2);
  526.             range1->insertNode(text2);
  527.             TASSERT(!XMLString::compareString(range1->toString(),xtext2ex));
  528.             TASSERT(range1->getStartOffset()==1);
  529.             TASSERT(!XMLString::compareString(range1->getStartContainer()->getNodeValue(),xt));
  530.             TASSERT(range1->getEndOffset()==2);
  531.             TASSERT(!XMLString::compareString(range1->getEndContainer()->getNodeValue(),xext1));
  532.             //now insert a non-text node
  533.             //<body>t<p1/>text2ext1</body>
  534.             IDOM_Element* p1 = doc2->createElement(xp1);
  535.             range1->insertNode(p1);
  536.             TASSERT(!XMLString::compareString(range1->toString(),xtext2ex));
  537.             TASSERT(range1->getStartOffset()==1);
  538.             TASSERT(!XMLString::compareString(range1->getStartContainer()->getNodeValue(),xt));
  539.             TASSERT(range1->getEndOffset()==2);
  540.             TASSERT(!XMLString::compareString(range1->getEndContainer()->getNodeValue(),xext1));
  541.             //case 2: non-text node, start==end
  542.             // <head><h1/></head>
  543.             IDOM_Element* head = doc2->createElement(xhead);
  544.             IDOM_Element* h1 = doc2->createElement(xH1);
  545.             head->appendChild(h1);
  546.             root2->appendChild(head);
  547.             //set range
  548.             IDOM_Range* range2 = doc2->createRange();
  549.             range2->setStart(head,0);
  550.             range2->setEnd(head,1);
  551.             TASSERT(!XMLString::compareString(range2->toString(),XMLUni::fgZeroLenString));
  552.             TASSERT(range2->getStartOffset()==0);
  553.             TASSERT(!XMLString::compareString(range2->getStartContainer()->getNodeName(),xhead));
  554.             TASSERT(range2->getEndOffset()==1);
  555.             TASSERT(!XMLString::compareString(range2->getEndContainer()->getNodeName(),xhead));
  556.             //now insert a non-text node
  557.             //<head><h2/><h1/></head>
  558.             IDOM_Element* h2 = doc2->createElement(xh2);
  559.             range2->insertNode(h2);
  560.             TASSERT(!XMLString::compareString(range2->toString(),XMLUni::fgZeroLenString));
  561.             TASSERT(range2->getStartOffset()==0);
  562.             TASSERT(!XMLString::compareString(range2->getStartContainer()->getNodeName(),xhead));
  563.             TASSERT(range2->getEndOffset()==2);
  564.             TASSERT(!XMLString::compareString(range2->getEndContainer()->getNodeName(),xhead));
  565.             //now insert a text node
  566.             //<head>text5<h2/><h1/></head>
  567.             IDOM_Text* text5 = doc2->createTextNode(xtext5);
  568.             range2->insertNode(text5);
  569.             TASSERT(!XMLString::compareString(range2->toString(),xtext5));
  570.             TASSERT(range2->getStartOffset()==0);
  571.             TASSERT(!XMLString::compareString(range2->getStartContainer()->getNodeName(),xhead));
  572.             TASSERT(range2->getEndOffset()==3);
  573.             TASSERT(!XMLString::compareString(range2->getEndContainer()->getNodeName(),xhead));
  574.             //case 3: simple text node, start!=end
  575.             // <body2>text3</body2>
  576.             IDOM_Element* body2 = doc2->createElement(xbody2);
  577.             IDOM_Text* text3 = doc2->createTextNode(xtext3);
  578.             body2->appendChild(text3);
  579.             root2->appendChild(body2);
  580.             //set range
  581.             IDOM_Range* range3 = doc2->createRange();
  582.             range3->setStart(text3,1);
  583.             range3->setEnd(body2,1);
  584.             TASSERT(!XMLString::compareString(range3->toString(),xext3));
  585.             TASSERT(range3->getStartOffset()==1);
  586.             TASSERT(!XMLString::compareString(range3->getStartContainer()->getNodeValue(),xtext3));
  587.             TASSERT(range3->getEndOffset()==1);
  588.             TASSERT(!XMLString::compareString(range3->getEndContainer()->getNodeName(),xbody2));
  589.             //now insert a textnode
  590.             //<body2>ttext4ext3</body2>
  591.             IDOM_Text* text4 = doc2->createTextNode(xtext4);
  592.             range3->insertNode(text4);
  593.             TASSERT(!XMLString::compareString(range3->toString(),XMLUni::fgZeroLenString));
  594.             TASSERT(range3->getStartOffset()==1);
  595.             TASSERT(!XMLString::compareString(range3->getStartContainer()->getNodeValue(),xt));
  596.             TASSERT(range3->getEndOffset()==1);
  597.             TASSERT(!XMLString::compareString(range3->getEndContainer()->getNodeName(),xbody2));
  598.             //now insert a non-text node
  599.             //<body2>t<p2/>text4ext3</body2>
  600.             IDOM_Element* p2 = doc2->createElement(xp2);
  601.             range3->insertNode(p2);
  602.             //extra empty node caused by splitting 't'
  603.             TASSERT(!XMLString::compareString(range3->toString(),XMLUni::fgZeroLenString));
  604.             TASSERT(range3->getStartOffset()==1);
  605.             TASSERT(!XMLString::compareString(range3->getStartContainer()->getNodeValue(),xt));
  606.             TASSERT(range3->getEndOffset()==1);
  607.             TASSERT(!XMLString::compareString(range3->getEndContainer()->getNodeName(),xbody2));
  608.             //test toString a bit
  609.             range3->setStart(body2,1);
  610.             range3->setEnd(body2,5);
  611.             TASSERT(!XMLString::compareString(range3->toString(),xtext4ext3));
  612.             range3->setStart(body2,0);
  613.             range3->setEnd(body2,5);
  614.             TASSERT(!XMLString::compareString(range3->toString(),xttext4ext3));
  615.             //case 4: non-text node, start!=end
  616.             // <head2><h3/></head2>
  617.             IDOM_Element* head2 = doc2->createElement(xhead2);
  618.             IDOM_Element* h3 = doc2->createElement(xh3);
  619.             head2->appendChild(h3);
  620.             root2->appendChild(head2);
  621.             //set range
  622.             IDOM_Range* range4 = doc2->createRange();
  623.             range4->setStart(head2,0);
  624.             range4->setEnd(h3,0);
  625.             TASSERT(!XMLString::compareString(range4->toString(),XMLUni::fgZeroLenString));
  626.             TASSERT(range4->getStartOffset()==0);
  627.             TASSERT(!XMLString::compareString(range4->getStartContainer()->getNodeName(),xhead2));
  628.             TASSERT(range4->getEndOffset()==0);
  629.             TASSERT(!XMLString::compareString(range4->getEndContainer()->getNodeName(),xh3));
  630.             //now insert a non-text node
  631.             //<head2><h4/><h3/></head2>
  632.             IDOM_Element* h4 = doc2->createElement(xh4);
  633.             range4->insertNode(h4);
  634.             TASSERT(!XMLString::compareString(range4->toString(),XMLUni::fgZeroLenString));
  635.             TASSERT(range4->getStartOffset()==0);
  636.             TASSERT(!XMLString::compareString(range4->getStartContainer()->getNodeName(),xhead2));
  637.             TASSERT(range4->getEndOffset()==0);
  638.             TASSERT(!XMLString::compareString(range4->getEndContainer()->getNodeName(),xh3));
  639.             //now insert a text node
  640.             //<head2>text6<h4/><h3/></head2>
  641.             IDOM_Text* text6 = doc2->createTextNode(xtext6);
  642.             range4->insertNode(text6);
  643.             TASSERT(!XMLString::compareString(range4->toString(),xtext6));
  644.             TASSERT(range4->getStartOffset()==0);
  645.             TASSERT(!XMLString::compareString(range4->getStartContainer()->getNodeName(),xhead2));
  646.             TASSERT(range4->getEndOffset()==0);
  647.             TASSERT(!XMLString::compareString(range4->getEndContainer()->getNodeName(),xh3));
  648.             //***************************************************************
  649.             // quick test of updating
  650.             //***************************************************************
  651.             // <upbody>text1</upbody>
  652.             IDOM_Element* upbody = doc2->createElement(xupbody);
  653.             IDOM_Text* uptext1 = doc2->createTextNode(xuptext1);
  654.             upbody->appendChild(uptext1);
  655.             root2->appendChild(upbody);
  656.             IDOM_Range* uprange = doc2->createRange();
  657.             uprange->setStart(upbody,0);
  658.             uprange->setEnd(upbody,1);
  659.             TASSERT(!XMLString::compareString(uprange->toString(),xuptext1));
  660.             TASSERT(uprange->getStartOffset()==0);
  661.             TASSERT(!XMLString::compareString(uprange->getStartContainer()->getNodeName(),xupbody));
  662.             TASSERT(uprange->getEndOffset()==1);
  663.             TASSERT(!XMLString::compareString(uprange->getEndContainer()->getNodeName(),xupbody));
  664.             // split text
  665.             uptext1->splitText(1);
  666.             TASSERT(!XMLString::compareString(uprange->toString(),xu));
  667.             TASSERT(uprange->getStartOffset()==0);
  668.             TASSERT(!XMLString::compareString(uprange->getStartContainer()->getNodeName(),xupbody));
  669.             TASSERT(uprange->getEndOffset()==1);
  670.             TASSERT(!XMLString::compareString(uprange->getEndContainer()->getNodeName(),xupbody));
  671.             //insert node
  672.             IDOM_Element* upbody2 = doc2->createElement(xupbody2);
  673.             IDOM_Text* uptext2 = doc2->createTextNode(xuptext2);
  674.             upbody2->appendChild(uptext2);
  675.             root2->appendChild(upbody2);
  676.             IDOM_Range* uprange2 = doc2->createRange();
  677.             uprange2->setStart(uptext2,1);
  678.             uprange2->setEnd(upbody2,1);
  679.             IDOM_Range* uprange3 = doc2->createRange();
  680.             uprange3->setStart(uptext2,1);
  681.             uprange3->setEnd(upbody2,1);
  682.             TASSERT(!XMLString::compareString(uprange2->toString(),xptext2));
  683.             TASSERT(uprange2->getStartOffset()==1);
  684.             TASSERT(!XMLString::compareString(uprange2->getStartContainer()->getNodeValue(),xuptext2));
  685.             TASSERT(uprange2->getEndOffset()==1);
  686.             TASSERT(!XMLString::compareString(uprange2->getEndContainer()->getNodeName(),xupbody2));
  687.             TASSERT(!XMLString::compareString(uprange3->toString(),xptext2));
  688.             TASSERT(uprange3->getStartOffset()==1);
  689.             TASSERT(!XMLString::compareString(uprange3->getStartContainer()->getNodeValue(),xuptext2));
  690.             TASSERT(uprange3->getEndOffset()==1);
  691.             TASSERT(!XMLString::compareString(uprange3->getEndContainer()->getNodeName(),xupbody2));
  692.             IDOM_Element* upp1 = doc2->createElement(xupp1);
  693.             uprange2->insertNode(upp1);
  694.             TASSERT(!XMLString::compareString(uprange2->toString(),XMLUni::fgZeroLenString));
  695.             TASSERT(uprange2->getStartOffset()==1);
  696.             TASSERT(!XMLString::compareString(uprange2->getStartContainer()->getNodeValue(),xu));
  697.             TASSERT(uprange2->getEndOffset()==1);
  698.             TASSERT(!XMLString::compareString(uprange2->getEndContainer()->getNodeName(),xupbody2));
  699.             TASSERT(!XMLString::compareString(uprange3->toString(),XMLUni::fgZeroLenString));
  700.             TASSERT(uprange3->getStartOffset()==1);
  701.             TASSERT(!XMLString::compareString(uprange3->getStartContainer()->getNodeValue(),xu));
  702.             TASSERT(uprange3->getEndOffset()==1);
  703.             TASSERT(!XMLString::compareString(uprange3->getEndContainer()->getNodeName(),xupbody2));
  704.             //***************************************************************
  705.             //another set of test
  706.             //<foo><c/><moo><b/></moo>ab<a>Hello cd</a><cool>ef</cool></foo>
  707.             //
  708.             //  ______________________foo_____________________
  709.             //  |          |           |          |           |
  710.             //  c         moo        "ab"         a          cool
  711.             //             |                      |           |
  712.             //             b                    "Hello cd"   "ef"
  713.             //
  714.             IDOM_DOMImplementation* impl3 = IDOM_DOMImplementation::getImplementation();
  715.             IDOM_Document* doc3 = impl3->createDocument();
  716.             IDOM_Element* root3 = doc3->createElement(xroot);
  717.             doc3->appendChild(root3);
  718.             IDOM_Element* foo = doc3->createElement(xfoo);
  719.             IDOM_Element* moo = doc3->createElement(xmoo);
  720.             IDOM_Element* cool = doc3->createElement(xcool);
  721.             IDOM_Text* ab = doc3->createTextNode(xab);
  722.             IDOM_Text* cd = doc3->createTextNode(xHellocd);
  723.             IDOM_Text* ef = doc3->createTextNode(xef);
  724.             IDOM_Element* a = doc3->createElement(xa);
  725.             IDOM_Element* b = doc3->createElement(xb);
  726.             IDOM_Element* c = doc3->createElement(xc);
  727.             root3->appendChild(foo);
  728.             foo->appendChild(c);
  729.             foo->appendChild(moo);
  730.             foo->appendChild(ab);
  731.             foo->appendChild(a);
  732.             foo->appendChild(cool);
  733.             moo->appendChild(b);
  734.             a->appendChild(cd);
  735.             cool->appendChild(ef);
  736.             //***************************************************************
  737.             //TEST toString
  738.             //***************************************************************
  739.             IDOM_Range* newtestrange = doc3->createRange();
  740.             //case 1:
  741.             //start container is text node
  742.             //   i) end container is also text node
  743.             //    a) start==end
  744.             //    b) start!=end
  745.             //  ii) end container is not text node
  746.             //    a) start==end => impossible
  747.             //    b) start!=end
  748.             //
  749.             //case 2:
  750.             //start container is not text node
  751.             //   i) end container is text node
  752.             //    a) start==end => impossible
  753.             //    b) start!=end
  754.             //  ii) end container is not text node
  755.             //    a) start==end
  756.             //    b) start!=end
  757.             //case 1, i, a
  758.             newtestrange->setStart( cd, 1 );
  759.             newtestrange->setEnd( cd, 4 );
  760.             TASSERT(!XMLString::compareString(newtestrange->toString(),xell));
  761.             //case 1, i, b
  762.             newtestrange->setStart( cd, 1 );
  763.             newtestrange->setEnd( ef, 2 );
  764.             TASSERT(!XMLString::compareString(newtestrange->toString(),xellocdef));
  765.             //case 1, ii, b
  766.             newtestrange->setStart( cd, 1 );
  767.             newtestrange->setEnd( foo, 4 );
  768.             TASSERT(!XMLString::compareString(newtestrange->toString(),xellocd));
  769.             //case 2, i, b
  770.             newtestrange->setStart( foo, 1 );
  771.             newtestrange->setEnd( cd, 5 );
  772.             TASSERT(!XMLString::compareString(newtestrange->toString(),xabHello));
  773.             //case 2, ii, a
  774.             newtestrange->setStart( foo, 1 );
  775.             newtestrange->setEnd( foo, 4 );
  776.             TASSERT(!XMLString::compareString(newtestrange->toString(),xabHellocd));
  777.             //case 2, ii, b
  778.             newtestrange->setStart( moo, 1 );
  779.             newtestrange->setEnd( foo, 4 );
  780.             TASSERT(!XMLString::compareString(newtestrange->toString(),xabHellocd));
  781.             //***************************************************************
  782.             //test removeChild
  783.             //***************************************************************
  784.             IDOM_Range* newrange = doc3->createRange();
  785.             newrange->setStart( moo, 0 );
  786.             newrange->setEnd( foo, 4 );
  787.             TASSERT(newrange->getStartOffset()==0);
  788.             TASSERT(!XMLString::compareString(newrange->getStartContainer()->getNodeName(),xmoo));
  789.             TASSERT(newrange->getEndOffset()==4);
  790.             TASSERT(!XMLString::compareString(newrange->getEndContainer()->getNodeName(),xfoo));
  791.             TASSERT(!XMLString::compareString(newrange->toString(),xabHellocd));
  792.             IDOM_Node* n = newrange->cloneContents();
  793.             IDOM_NodeList* nol = foo->getChildNodes();
  794.             //removing moo
  795.             foo->removeChild(nol->item(1));
  796.             TASSERT(newrange->getStartOffset()==1);
  797.             TASSERT(!XMLString::compareString(newrange->getStartContainer()->getNodeName(),xfoo));
  798.             TASSERT(newrange->getEndOffset()==3);
  799.             TASSERT(!XMLString::compareString(newrange->getEndContainer()->getNodeName(),xfoo));
  800.             TASSERT(!XMLString::compareString(newrange->toString(),xabHellocd));
  801.             TASSERT(newtestrange->getStartOffset()==1);
  802.             TASSERT(!XMLString::compareString(newtestrange->getStartContainer()->getNodeName(),xfoo));
  803.             TASSERT(newtestrange->getEndOffset()==3);
  804.             TASSERT(!XMLString::compareString(newtestrange->getEndContainer()->getNodeName(),xfoo));
  805.             TASSERT(!XMLString::compareString(newtestrange->toString(),xabHellocd));
  806.             delete doc;
  807.             delete doc2;
  808.             delete doc3;
  809.         }
  810.     } //creating the dom tree and tests
  811.     // And call the termination method
  812.     XMLPlatformUtils::Terminate();
  813.     printf("Test Run Successfullyn");
  814.     return 0;
  815. };