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

词法分析

开发平台:

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. //  Various DOM tests.
  58. //     Contents include
  59. //       1.  NodeIterator tests
  60. //       2.  Tree Walker tests
  61. //     All individual are wrapped in a memory leak checker.
  62. //
  63. //     This is NOT a complete test of DOM functionality.
  64. //
  65. /**
  66.  * $Log: Traversal.cpp,v $
  67.  * Revision 1.15  2003/02/05 18:55:20  tng
  68.  * [Bug 11915] Utility for freeing memory.
  69.  *
  70.  * Revision 1.14  2002/11/12 17:52:12  tng
  71.  * Test update: do not issue "Test Run Successfully" if there was an error.
  72.  *
  73.  * Revision 1.13  2002/11/05 21:47:36  tng
  74.  * Explicit code using namespace in application.
  75.  *
  76.  * Revision 1.12  2002/06/25 16:23:16  tng
  77.  * DOM L3: use release()
  78.  *
  79.  * Revision 1.11  2002/06/04 16:14:44  tng
  80.  * Use proper feature in DOMImplementationRegistry::getDOMImplementation
  81.  *
  82.  * Revision 1.10  2002/06/03 20:51:46  tng
  83.  * DOM L3: Add DOMImplementationRegistry and DOMImplementationSource
  84.  *
  85.  * Revision 1.9  2002/05/27 21:11:26  tng
  86.  * Add DOMDocumentRange and DOMDocumentTraversal.
  87.  *
  88.  * Revision 1.8  2002/05/21 18:52:35  tng
  89.  * Test case update: modify to use the latest DOM interface.
  90.  *
  91.  * Revision 1.8  2002/03/07 21:41:58  peiyongz
  92.  * Call Terminate() to avoid memory tools reporting memory leak
  93.  *
  94.  * Revision 1.7  2002/02/04 21:56:57  tng
  95.  * Test DOM Level 2 function getRoot.
  96.  *
  97.  * Revision 1.6  2002/02/04 19:02:37  tng
  98.  * Memory leak fix in samples / test cases.
  99.  *
  100.  * Revision 1.5  2002/02/01 22:44:51  peiyongz
  101.  * sane_include
  102.  *
  103.  * Revision 1.4  2001/11/23 16:18:54  tng
  104.  * Elimiate compiler warning: Warning: String literal converted to char* in formal argument file in call to tassert(bool, char*, int).
  105.  *
  106.  * Revision 1.3  2001/07/19 20:45:16  tng
  107.  * Add some test cases in the tests folder to sanityTest.pl
  108.  *
  109.  * Revision 1.2  2001/06/05 11:58:31  tng
  110.  * Delete the document at the end for clearing the memory.
  111.  *
  112.  * Revision 1.1  2001/06/04 20:11:55  tng
  113.  * IDOM: Complete IDNodeIterator, IDTreeWalker, IDNodeFilter.
  114.  *
  115.  *
  116.  */
  117. #include <stdio.h>
  118. #include <string.h>
  119. #include <xercesc/dom/DOM.hpp>
  120. #include <xercesc/util/PlatformUtils.hpp>
  121. #include <xercesc/util/XMLException.hpp>
  122. #include <xercesc/util/XMLString.hpp>
  123. #include <xercesc/util/XMLUniDefs.hpp>
  124. XERCES_CPP_NAMESPACE_USE
  125. bool errorOccurred = false;
  126. #define TASSERT(c) tassert((c), __FILE__, __LINE__)
  127. void tassert(bool c, const char *file, int line)
  128. {
  129.     if (!c) {
  130.         printf("Failure.  Line %d,   file %sn", line, file);
  131.         errorOccurred = true;
  132.     }
  133. };
  134. #define EXCEPTION_TEST(operation, expected_exception)               
  135. {                                                                   
  136.     try {                                                           
  137.     operation;                                                      
  138.     printf(" Error: no exception thrown at line %dn", __LINE__);   
  139.     errorOccurred = true;                                           
  140.     }                                                               
  141.     catch (DOMException &e) {                                       
  142.     if (e.code != expected_exception) {                             
  143.         printf(" Wrong exception code: %d at line %dn", e.code, __LINE__); 
  144.         errorOccurred = true;                                       
  145.     }                                                               
  146.     }                                                               
  147.     catch (...)   {                                                 
  148.         printf(" Wrong exception thrown at line %dn", __LINE__);   
  149.         errorOccurred = true;                                       
  150.     }                                                               
  151. }
  152. class  MyFilter : public DOMNodeFilter {
  153. public:
  154.   MyFilter(short nodeType, bool reject=false) : DOMNodeFilter(), fNodeType(nodeType), fReject(reject) {};
  155.   virtual short acceptNode(const DOMNode* node) const;
  156. private:
  157.     short fNodeType;
  158.     bool fReject;
  159. };
  160. /*
  161.         Node Types can be of the following:
  162.         ELEMENT_NODE         = 1,
  163.         ATTRIBUTE_NODE       = 2,
  164.         TEXT_NODE            = 3,
  165.         CDATA_SECTION_NODE   = 4,
  166.         ENTITY_REFERENCE_NODE = 5,
  167.         ENTITY_NODE          = 6,
  168.         PROCESSING_INSTRUCTION_NODE = 7,
  169.         COMMENT_NODE         = 8,
  170.         DOCUMENT_NODE        = 9,
  171.         DOCUMENT_TYPE_NODE   = 10,
  172.         DOCUMENT_FRAGMENT_NODE = 11,
  173.         NOTATION_NODE        = 12
  174. */
  175. short  MyFilter::acceptNode(const DOMNode* node) const {
  176.     if (fNodeType == 0)
  177.         return  DOMNodeFilter::FILTER_ACCEPT;
  178. if (node->getNodeType() ==  fNodeType) {
  179.         return  DOMNodeFilter::FILTER_ACCEPT;
  180. } else {
  181.     return  fReject ? DOMNodeFilter::FILTER_REJECT : DOMNodeFilter::FILTER_SKIP;
  182. }
  183. }
  184. int  main()
  185. {
  186. try {
  187. XMLPlatformUtils::Initialize();
  188. }
  189. catch (const XMLException& toCatch) {
  190.         char *pMessage = XMLString::transcode(toCatch.getMessage());
  191.         fprintf(stderr, "Error during XMLPlatformUtils::Initialize(). n"
  192.                         "  Message is: %sn", pMessage);
  193.         XMLString::release(&pMessage);
  194.         return -1;
  195.     }
  196.     // Create a XMLCh buffer for string manipulation
  197.     XMLCh tempStr[4000];
  198.     XMLCh featureStr[100];
  199.     XMLString::transcode("Traversal",featureStr,99);
  200.     //
  201.     //  Doc - Create a small document tree
  202.     //
  203.     {
  204.         //creating a DOM Tree
  205.          /* Tests are based on the tree structure below
  206.            doc - root - E11 (attr01) - textNode1
  207.                                      - E111
  208.                                      - E112
  209.                                      - cdataSec
  210.                       - E12 (attr02) - textNode2
  211.                                      - E121
  212.                                      - E122
  213.                       - E13          - E131
  214.                                      - docPI
  215.                       - comment
  216.          */
  217.         DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(featureStr);
  218.         DOMDocument* doc = impl->createDocument();
  219.         //Creating a root element
  220.         XMLString::transcode("RootElement", tempStr, 3999);
  221.         DOMElement*     root = doc->createElement(tempStr);
  222.         doc->appendChild(root);
  223.         //Creating the siblings of root
  224.         XMLString::transcode("FirstSibling", tempStr, 3999);
  225.         DOMElement*     E11 = doc->createElement(tempStr);
  226.         root->appendChild(E11);
  227.         XMLString::transcode("SecondSibling", tempStr, 3999);
  228.         DOMElement*     E12 = doc->createElement(tempStr);
  229.         root->appendChild(E12);
  230.         XMLString::transcode("ThirdSibling", tempStr, 3999);
  231.         DOMElement*     E13 = doc->createElement(tempStr);
  232.         root->appendChild(E13);
  233.         //Attaching texts to few siblings
  234.         XMLString::transcode("Text1", tempStr, 3999);
  235.         DOMText*        textNode1 = doc->createTextNode(tempStr);
  236.         E11->appendChild(textNode1);
  237.         XMLString::transcode("Text2", tempStr, 3999);
  238.         DOMText*        textNode2 = doc->createTextNode(tempStr);
  239.         E12->appendChild(textNode2);
  240.         //creating child of siblings
  241.         XMLString::transcode("FirstSiblingChild1", tempStr, 3999);
  242.         DOMElement*     E111 = doc->createElement(tempStr);
  243.         E11->appendChild(E111);
  244.         XMLString::transcode("Attr01", tempStr, 3999);
  245.         DOMAttr*        attr01  = doc->createAttribute(tempStr);
  246.         DOMNode* rem = E11->setAttributeNode(attr01);
  247.         if (rem)
  248.             rem->release();
  249.         XMLString::transcode("FirstSiblingChild2", tempStr, 3999);
  250.         DOMElement*     E112 = doc->createElement(tempStr);
  251.         E11->appendChild(E112);
  252.         XMLString::transcode("SecondSiblingChild1", tempStr, 3999);
  253.         DOMElement*     E121 = doc->createElement(tempStr);
  254.         E12->appendChild(E121);
  255.         XMLString::transcode("Attr01", tempStr, 3999);
  256.         DOMAttr* attr02 = doc->createAttribute(tempStr);
  257.         rem = E12->setAttributeNode(attr02);
  258.         if (rem)
  259.             rem->release();
  260.         XMLString::transcode("SecondSiblingChild2", tempStr, 3999);
  261.         DOMElement*     E122 = doc->createElement(tempStr);
  262.         E12->appendChild(E122);
  263.         XMLString::transcode("ThirdSiblingChild1", tempStr, 3999);
  264.         DOMElement*     E131 = doc->createElement(tempStr);
  265.         E13->appendChild(E131);
  266.         XMLString::transcode("DocComment", tempStr, 3999);
  267.         DOMComment* comment = doc->createComment(tempStr);
  268.         root->appendChild(comment);
  269.         XMLString::transcode("DocCDataSection", tempStr, 3999);
  270.         DOMCDATASection*  cdataSec = doc->createCDATASection(tempStr);
  271.         E11->appendChild(cdataSec);
  272.         XMLString::transcode("DocPI", tempStr, 3999);
  273.         XMLCh piStr[] = {chLatin_D, chLatin_o, chLatin_c, chLatin_P, chLatin_I, chNull};
  274.         DOMProcessingInstruction*  docPI = doc->createProcessingInstruction(piStr, tempStr);
  275.         E13->appendChild(docPI);
  276.         /*
  277.         following are whatToShow types:
  278.             SHOW_ALL                       = 0x0000FFFF,
  279.             SHOW_ELEMENT                   = 0x00000001,
  280.             SHOW_ATTRIBUTE                 = 0x00000002,
  281.             SHOW_TEXT                      = 0x00000004,
  282.             SHOW_CDATA_SECTION             = 0x00000008,
  283.             SHOW_ENTITY_REFERENCE          = 0x00000010,
  284.             SHOW_ENTITY                    = 0x00000020,
  285.             SHOW_PROCESSING_INSTRUCTION    = 0x00000040,
  286.             SHOW_COMMENT                   = 0x00000080,
  287.             SHOW_DOCUMENT                  = 0x00000100,
  288.             SHOW_DOCUMENT_TYPE             = 0x00000200,
  289.             SHOW_DOCUMENT_FRAGMENT         = 0x00000400,
  290.             SHOW_NOTATION                  = 0x00000800
  291.         */
  292.         ////////// NodeIterator Test Cases ////////////////
  293.         {
  294.             // all node iterating test
  295.             DOMNode*    node = doc->getFirstChild();
  296.             unsigned long       whatToShow = DOMNodeFilter::SHOW_ALL;
  297.             MyFilter* filter = new MyFilter(0);
  298.             DOMNodeIterator*  iter = ((DOMDocumentTraversal*)doc)->createNodeIterator(root, whatToShow,  filter, true);
  299.             TASSERT(iter->getWhatToShow() == 65535);
  300.             TASSERT(iter->getExpandEntityReferences() == 1);
  301.             DOMNode*  nd;
  302.             nd = iter->nextNode();
  303.             TASSERT (nd ==root);
  304.             nd = iter->nextNode();
  305.             TASSERT (nd ==E11);
  306.             nd = iter->nextNode();
  307.             TASSERT(nd == textNode1);
  308.             nd = iter->nextNode();
  309.             TASSERT(nd == E111);
  310.             nd = iter->nextNode();
  311.             TASSERT(nd == E112);
  312.             nd = iter->nextNode();
  313.             TASSERT(nd == cdataSec);
  314.             nd = iter->nextNode();
  315.             TASSERT(nd == E12);
  316.             nd = iter->nextNode();
  317.             TASSERT(nd == textNode2);
  318.             nd = iter->nextNode();
  319.             TASSERT(nd == E121);
  320.             nd = iter->nextNode();
  321.             TASSERT(nd == E122);
  322.             nd = iter->nextNode();
  323.             TASSERT(nd == E13);
  324.             nd = iter->nextNode();
  325.             TASSERT(nd == E131);
  326.             nd = iter->nextNode();
  327.             TASSERT(nd == docPI);
  328.             nd = iter->nextNode();
  329.             TASSERT(nd == comment);
  330.             nd = iter->previousNode();
  331.             TASSERT(nd == comment);
  332.             nd = iter->previousNode();
  333.             TASSERT(nd == docPI);
  334.             nd = iter->previousNode();
  335.             TASSERT(nd == E131);
  336.             //test getRoot
  337.             TASSERT(iter->getRoot() == root);
  338.             TASSERT(iter->getRoot() != doc);
  339.             delete filter;
  340.         }
  341.         {
  342.             //element node iterating test
  343.             DOMNode*    node = doc->getFirstChild();
  344.             unsigned long       whatToShow = DOMNodeFilter::SHOW_ELEMENT;
  345.             MyFilter* filter = new MyFilter(DOMNode::ELEMENT_NODE);
  346.             DOMNodeIterator*  iter = doc->createNodeIterator(root, whatToShow,  filter, true);
  347.             TASSERT(iter->getWhatToShow() == 1);
  348.             TASSERT(iter->getExpandEntityReferences() == 1);
  349.             DOMNode*  nd;
  350.             nd = iter->nextNode();
  351.             TASSERT (nd ==root);
  352.             nd = iter->nextNode();
  353.             TASSERT (nd ==E11);
  354.             nd = iter->nextNode();
  355.             TASSERT(nd == E111);
  356.             nd = iter->nextNode();
  357.             TASSERT(nd == E112);
  358.             nd = iter->nextNode();
  359.             TASSERT(nd == E12);
  360.             nd = iter->nextNode();
  361.             TASSERT(nd == E121);
  362.             nd = iter->nextNode();
  363.             TASSERT(nd == E122);
  364.             nd = iter->nextNode();
  365.             TASSERT(nd == E13);
  366.             nd = iter->nextNode();
  367.             TASSERT(nd == E131);
  368.             nd = iter->previousNode();
  369.             TASSERT(nd == E131);
  370.             nd = iter->previousNode();
  371.             TASSERT(nd == E13);
  372.             nd = iter->previousNode();
  373.             TASSERT(nd == E122);
  374.             delete filter;
  375.         }
  376.         {
  377.             // Text node iterating test
  378.             DOMNode*    node = doc->getFirstChild();
  379.             unsigned long       whatToShow = DOMNodeFilter::SHOW_TEXT;
  380.             MyFilter* filter = new MyFilter(DOMNode::TEXT_NODE);
  381.             DOMNodeIterator*  iter = ((DOMDocumentTraversal*)doc)->createNodeIterator(root, whatToShow,  filter, true);
  382.             TASSERT(iter->getWhatToShow() == 4);
  383.             TASSERT(iter->getExpandEntityReferences() == 1);
  384.             DOMNode*  nd;
  385.             nd = iter->nextNode();
  386.             TASSERT (nd ==textNode1);
  387.             nd = iter->nextNode();
  388.             TASSERT (nd ==textNode2);
  389.             nd = iter->previousNode();
  390.             TASSERT(nd == textNode2);
  391.             delete filter;
  392.         }
  393.         {
  394.             //CDataSection node itearating test
  395.             DOMNode*    node = doc->getFirstChild();
  396.             unsigned long       whatToShow = DOMNodeFilter::SHOW_CDATA_SECTION;
  397.             MyFilter* filter = new MyFilter(DOMNode::CDATA_SECTION_NODE);
  398.             DOMNodeIterator*  iter = doc->createNodeIterator(root, whatToShow,  filter, true);
  399.             TASSERT(iter->getWhatToShow() == 8);
  400.             TASSERT(iter->getExpandEntityReferences() == 1);
  401.             DOMNode*  nd;
  402.             nd = iter->nextNode();
  403.             TASSERT(nd == cdataSec);
  404.             nd = iter->nextNode();
  405.             TASSERT(nd == 0);
  406.             delete filter;
  407.         }
  408.         {
  409.             // PI nodes iterating test
  410.             DOMNode*    node = doc->getFirstChild();
  411.             unsigned long       whatToShow = DOMNodeFilter::SHOW_PROCESSING_INSTRUCTION;
  412.             MyFilter* filter = new MyFilter(DOMNode::PROCESSING_INSTRUCTION_NODE);
  413.             DOMNodeIterator*  iter = ((DOMDocumentTraversal*)doc)->createNodeIterator(root, whatToShow,  filter, true);
  414.             TASSERT(iter->getWhatToShow() == 64);
  415.             TASSERT(iter->getExpandEntityReferences() == 1);
  416.             DOMNode*  nd;
  417.             nd = iter->nextNode();
  418.             TASSERT(nd == docPI);
  419.             nd = iter->nextNode();
  420.             TASSERT(nd == 0);
  421.             delete filter;
  422.         }
  423.         {
  424.             DOMNode*    node = doc->getFirstChild();
  425.             unsigned long       whatToShow = DOMNodeFilter::SHOW_COMMENT;
  426.             MyFilter* filter = new MyFilter(DOMNode::COMMENT_NODE);
  427.             DOMNodeIterator*  iter = doc->createNodeIterator(root, whatToShow,  filter, true);
  428.             TASSERT(iter->getWhatToShow() == 128);
  429.             TASSERT(iter->getExpandEntityReferences() == 1);
  430.             DOMNode*  nd;
  431.             nd = iter->nextNode();
  432.             TASSERT(nd == comment);
  433.             nd = iter->nextNode();
  434.             TASSERT(nd == 0);
  435.             delete filter;
  436.         }
  437.         ////////// TreeWalker Test Cases ////////////////
  438.         {
  439.             unsigned long whatToShow = DOMNodeFilter::SHOW_ALL;
  440.             DOMTreeWalker* tw = ((DOMDocumentTraversal*)doc)->createTreeWalker(doc, whatToShow, 0, true);
  441.             TASSERT(tw->getCurrentNode() == doc);
  442.             TASSERT(tw->firstChild() == root);
  443.             TASSERT(tw->nextSibling() == 0);
  444.             TASSERT(tw->lastChild() == comment);
  445.             TASSERT(tw->firstChild() == 0);
  446.             TASSERT(tw->lastChild() == 0);
  447.             TASSERT(tw->nextSibling() == 0);
  448.             TASSERT(tw->nextNode() == 0);
  449.             TASSERT(tw->previousSibling() == E13);
  450.             TASSERT(tw->previousNode() == E122);
  451.             TASSERT(tw->parentNode() == E12);
  452.             TASSERT(tw->firstChild() == textNode2);
  453.             TASSERT(tw->previousSibling() == 0);
  454.             TASSERT(tw->nextSibling() == E121);
  455.             TASSERT(tw->nextNode() == E122);
  456.             TASSERT(tw->parentNode() == E12);
  457.             TASSERT(tw->previousSibling() == E11);
  458.             TASSERT(tw->previousNode() == root);
  459.             TASSERT(tw->previousNode() == doc);
  460.             TASSERT(tw->previousNode() == 0);
  461.             TASSERT(tw->parentNode() == 0);
  462.             TASSERT(tw->getCurrentNode() == doc);
  463.         }
  464.         {
  465.             MyFilter mf(DOMNode::ELEMENT_NODE);
  466.             unsigned long whatToShow = DOMNodeFilter::SHOW_ALL;
  467.             DOMTreeWalker* tw = doc->createTreeWalker(root, whatToShow, &mf, true);
  468.             TASSERT(tw->getCurrentNode() == root);
  469.             TASSERT(tw->parentNode() == 0);  //should not change currentNode
  470.             TASSERT(tw->getCurrentNode() == root);
  471.             TASSERT(tw->nextNode() == E11);
  472.             TASSERT(tw->nextNode() == E111);
  473.             tw->setCurrentNode(E12);
  474.             //when first is not visible, should it go to its sibling?
  475.             TASSERT(tw->firstChild() == E121);   //first visible child
  476.             TASSERT(tw->previousSibling() == 0);
  477.         }
  478.         {
  479.             MyFilter mf(DOMNode::ELEMENT_NODE, true);
  480.             unsigned long whatToShow = DOMNodeFilter::SHOW_ELEMENT;
  481.             DOMTreeWalker* tw = ((DOMDocumentTraversal*)doc)->createTreeWalker(root, whatToShow, &mf, true);
  482.             tw->setCurrentNode(E12);
  483.             TASSERT(tw->firstChild() == E121);   //still first visible child
  484.         }
  485.         {
  486.             MyFilter mf(DOMNode::TEXT_NODE);
  487.             unsigned long whatToShow = DOMNodeFilter::SHOW_TEXT;
  488.             DOMTreeWalker* tw = doc->createTreeWalker(root, whatToShow, &mf, true);
  489.             //when first is not visible, should it go to its descendent?
  490.             TASSERT(tw->firstChild() == textNode1);   //E11 skipped
  491.             TASSERT(tw->firstChild() == 0);
  492.             TASSERT(tw->nextNode() == textNode2);
  493.             TASSERT(tw->nextSibling() == 0);
  494.             TASSERT(tw->parentNode() == 0);  //no visible ancestor
  495.             TASSERT(tw->getCurrentNode() == textNode2);
  496.             tw->setCurrentNode(root);
  497.             //when last is not visible, should it go to its sibling & descendent?
  498.             TASSERT(tw->lastChild() == textNode2);   //last visible child
  499.             tw->setCurrentNode(E12);
  500.             //when next sibling is not visible, should it go to its descendent?
  501.             TASSERT(tw->nextSibling() == 0);
  502.         }
  503.         {
  504.             MyFilter mf(DOMNode::TEXT_NODE, true);
  505.             unsigned long whatToShow = DOMNodeFilter::SHOW_TEXT;
  506.             DOMTreeWalker* tw = ((DOMDocumentTraversal*)doc)->createTreeWalker(root, whatToShow, &mf, true);
  507.             TASSERT(tw->firstChild() == 0);   //E11 rejected and no children is TEXT
  508.             TASSERT(tw->getCurrentNode() == root);
  509.             TASSERT(tw->nextNode() == 0);    //E11 rejected so can't get to textNode1
  510.             //test getRoot
  511.             TASSERT(tw->getRoot() == root);
  512.             TASSERT(tw->getRoot() != doc);
  513.         }
  514.         doc->release();
  515.     };
  516.     // And call the termination method
  517.     XMLPlatformUtils::Terminate();
  518.     if (errorOccurred) {
  519.         printf("Test Failedn");
  520.         return 4;
  521.     }
  522.     printf("Test Run Successfullyn");
  523.     return 0;
  524. };