diff --git a/include/DOM/Traversal/DocumentTraversal.h b/include/DOM/Traversal/DocumentTraversal.h index 328008cf..ac86e188 100644 --- a/include/DOM/Traversal/DocumentTraversal.h +++ b/include/DOM/Traversal/DocumentTraversal.h @@ -82,7 +82,7 @@ class DocumentTraversal : protected DOM::Proxy > NodeFilter& filter, bool entityRefExpansion) { - return NodeIterator(Impl()->createNodeIterator(root, whatToShow, *filter, entityRefExpansion)); + return NodeIterator(Impl()->createNodeIterator(root, whatToShow, &filter, entityRefExpansion)); } // createNodeIterator TreeWalker createTreeWalker(DOM::Node root, @@ -97,7 +97,7 @@ class DocumentTraversal : protected DOM::Proxy > NodeFilter& filter, bool entityRefExpansion) { - return TreeWalker(Impl()->createTreeWalker(root, whatToShow, *filter, entityRefExpansion)); + return TreeWalker(Impl()->createTreeWalker(root, whatToShow, &filter, entityRefExpansion)); } // createTreeWalker private: diff --git a/include/DOM/Traversal/NodeFilter.h b/include/DOM/Traversal/NodeFilter.h index 21f5e247..dc4e546c 100644 --- a/include/DOM/Traversal/NodeFilter.h +++ b/include/DOM/Traversal/NodeFilter.h @@ -16,6 +16,9 @@ namespace Traversal template class NodeFilter { + protected: + virtual ~NodeFilter() { } + public: /////////////////////////////////////////////////////////////// // NodeFilter methods @@ -28,8 +31,6 @@ class NodeFilter virtual Result acceptNode(const DOM::Node& node) const = 0; - private: - virtual ~NodeFilter() { } }; // class NodeFilter } // namespace Traversal diff --git a/tests/SAX2DOM/test_TreeWalker.hpp b/tests/SAX2DOM/test_TreeWalker.hpp index 9cc277dc..0f6f315a 100644 --- a/tests/SAX2DOM/test_TreeWalker.hpp +++ b/tests/SAX2DOM/test_TreeWalker.hpp @@ -133,6 +133,61 @@ class TreeWalkerTest : public TestCase assert(walker.nextNode() == elem.getLastChild().getFirstChild()); assert(walker.nextNode() == 0); } // test6 + + void test7() + { + DOM::Document d = parse(SA::construct_from_utf8("hellomother")); + DOM::Element elem = d.getDocumentElement(); + + DOM::Traversal::DocumentTraversal traversal = d.createDocumentTraversal(); + DOM::Traversal::TreeWalker walker = traversal.createTreeWalker(d.getDocumentElement(), + DOM::Traversal::SHOW_COMMENT, + true); + assert(walker.getCurrentNode() == elem); + assert(walker.nextNode() == elem.getLastChild().getFirstChild()); + assert(walker.nextNode() == 0); + } // test7 + + void test8() + { + DOM::Document d = parse(SA::construct_from_utf8("hellomother")); + DOM::Element elem = d.getDocumentElement(); + + DOM::Traversal::DocumentTraversal traversal = d.createDocumentTraversal(); + DOM::Traversal::TreeWalker walker = traversal.createTreeWalker(d.getDocumentElement(), + DOM::Traversal::SHOW_PROCESSING_INSTRUCTION, + true); + assert(walker.getCurrentNode() == elem); + assert(walker.nextNode() == elem.getLastChild().getLastChild()); + assert(walker.nextNode() == 0); + } // test8 + + class TestFilter : public DOM::Traversal::NodeFilter + { + public: + virtual Result acceptNode(const DOM::Node& node) const + { + if(node.getFirstChild().getNodeType() == DOM::Node_base::COMMENT_NODE) + return FILTER_REJECT; + return FILTER_ACCEPT; + } // acceptNode + }; // TestFilter + + void test9() + { + DOM::Document d = parse(SA::construct_from_utf8("hellomother")); + DOM::Element elem = d.getDocumentElement(); + + DOM::Traversal::DocumentTraversal traversal = d.createDocumentTraversal(); + TestFilter filter; + DOM::Traversal::TreeWalker walker = traversal.createTreeWalker(d.getDocumentElement(), + DOM::Traversal::SHOW_ELEMENT, + filter, + true); + assert(walker.getCurrentNode() == elem); + assert(walker.nextNode() == elem.getFirstChild()); + assert(walker.nextNode() == 0); + } // test9 }; template @@ -145,6 +200,9 @@ TestSuite* TreeWalkerTest_suite() suiteOfTests->addTest(new TestCaller >("test4", &TreeWalkerTest::test4)); suiteOfTests->addTest(new TestCaller >("test5", &TreeWalkerTest::test5)); suiteOfTests->addTest(new TestCaller >("test6", &TreeWalkerTest::test6)); + suiteOfTests->addTest(new TestCaller >("test7", &TreeWalkerTest::test7)); + suiteOfTests->addTest(new TestCaller >("test8", &TreeWalkerTest::test8)); + suiteOfTests->addTest(new TestCaller >("test9", &TreeWalkerTest::test9)); return suiteOfTests; } // TreeWalkerTest_suite