#ifndef XPATHIC_EXPRESSION_TEST_HPP #define XPATHIC_EXPRESSION_TEST_HPP #include "../CppUnit/framework/TestCase.h" #include "../CppUnit/framework/TestSuite.h" #include "../CppUnit/framework/TestCaller.h" #include #include template class ExpressionTest : public TestCase { Arabica::XPath::XPath parser; Arabica::DOM::DOMImplementation factory_; Arabica::DOM::Document document_; Arabica::DOM::Element root_; Arabica::DOM::Element element1_; Arabica::DOM::Element element2_; Arabica::DOM::Element element3_; Arabica::DOM::Element spinkle_; Arabica::DOM::Attr attr_; Arabica::DOM::Text text_; Arabica::DOM::Comment comment_; Arabica::DOM::ProcessingInstruction processingInstruction_; Arabica::DOM::Document chapters_; Arabica::DOM::Document numbers_; typedef string_adaptor SA; public: ExpressionTest(std::string name) : TestCase(name) { } // ExpressionTest void setUp() { factory_ = Arabica::SimpleDOM::DOMImplementation::getDOMImplementation(); document_ = factory_.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8("root"), 0); root_ = document_.getDocumentElement(); element1_ = document_.createElement(SA::construct_from_utf8("child1")); element2_ = document_.createElement(SA::construct_from_utf8("child2")); element3_ = document_.createElement(SA::construct_from_utf8("child3")); element1_.setAttribute(SA::construct_from_utf8("one"), SA::construct_from_utf8("1")); element2_.setAttribute(SA::construct_from_utf8("one"), SA::construct_from_utf8("1")); element2_.setAttribute(SA::construct_from_utf8("two"), SA::construct_from_utf8("1")); element2_.setAttribute(SA::construct_from_utf8("three"), SA::construct_from_utf8("1")); element2_.setAttribute(SA::construct_from_utf8("four"), SA::construct_from_utf8("1")); text_ = document_.createTextNode(SA::construct_from_utf8("data")); comment_ = document_.createComment(SA::construct_from_utf8("comment")); processingInstruction_ = document_.createProcessingInstruction(SA::construct_from_utf8("target"), SA::construct_from_utf8("data")); element2_.appendChild(text_); spinkle_ = document_.createElement(SA::construct_from_utf8("spinkle")); element2_.appendChild(spinkle_); element2_.appendChild(comment_); element2_.appendChild(processingInstruction_); attr_ = element1_.getAttributeNode(SA::construct_from_utf8("one")); root_.appendChild(element1_); root_.appendChild(element2_); root_.appendChild(element3_); chapters_ = factory_.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8("document"), 0); chapters_.getFirstChild().appendChild(chapters_.createElement(SA::construct_from_utf8("chapter"))).appendChild(chapters_.createTextNode(SA::construct_from_utf8("one"))); chapters_.getFirstChild().appendChild(chapters_.createElement(SA::construct_from_utf8("chapter"))).appendChild(chapters_.createTextNode(SA::construct_from_utf8("two"))); chapters_.getFirstChild().appendChild(chapters_.createElement(SA::construct_from_utf8("chapter"))).appendChild(chapters_.createTextNode(SA::construct_from_utf8("three"))); chapters_.getFirstChild().appendChild(chapters_.createElement(SA::construct_from_utf8("chapter"))).appendChild(chapters_.createTextNode(SA::construct_from_utf8("four"))); chapters_.getFirstChild().appendChild(chapters_.createElement(SA::construct_from_utf8("chapter"))).appendChild(chapters_.createTextNode(SA::construct_from_utf8("five"))); numbers_ = factory_.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8("doc"), 0); numbers_.getFirstChild().appendChild(numbers_.createElement(SA::construct_from_utf8("number"))).appendChild(numbers_.createTextNode(SA::construct_from_utf8("1"))); numbers_.getFirstChild().appendChild(numbers_.createElement(SA::construct_from_utf8("number"))).appendChild(numbers_.createTextNode(SA::construct_from_utf8("2"))); numbers_.getFirstChild().appendChild(numbers_.createElement(SA::construct_from_utf8("number"))).appendChild(numbers_.createTextNode(SA::construct_from_utf8("3"))); numbers_.getFirstChild().appendChild(numbers_.createElement(SA::construct_from_utf8("number"))).appendChild(numbers_.createTextNode(SA::construct_from_utf8("4"))); numbers_.getFirstChild().appendChild(numbers_.createElement(SA::construct_from_utf8("number"))).appendChild(numbers_.createTextNode(SA::construct_from_utf8("5"))); numbers_.getFirstChild().appendChild(numbers_.createElement(SA::construct_from_utf8("number"))).appendChild(numbers_.createTextNode(SA::construct_from_utf8("6"))); numbers_.getFirstChild().appendChild(numbers_.createElement(SA::construct_from_utf8("number"))).appendChild(numbers_.createTextNode(SA::construct_from_utf8("7"))); numbers_.getFirstChild().appendChild(numbers_.createElement(SA::construct_from_utf8("number"))).appendChild(numbers_.createTextNode(SA::construct_from_utf8("8"))); numbers_.getFirstChild().appendChild(numbers_.createElement(SA::construct_from_utf8("number"))).appendChild(numbers_.createTextNode(SA::construct_from_utf8("9"))); } // setUp void testNode1() { using namespace Arabica::XPath; XPathExpression xpath = parser.compile_expr(SA::construct_from_utf8("node()")); XPathValue result = xpath.evaluate(document_); assertValuesEqual(NODE_SET, result.type()); assertValuesEqual(1, result.asNodeSet().size()); assertTrue(root_ == result.asNodeSet()[0]); result = xpath.evaluate(element2_); assertValuesEqual(NODE_SET, result.type()); assertValuesEqual(4, result.asNodeSet().size()); } // testNode1 }; // class ExpressionTest template TestSuite* ExpressionTest_suite() { TestSuite *suiteOfTests = new TestSuite; suiteOfTests->addTest(new TestCaller >("testNode1", &ExpressionTest::testNode1)); return suiteOfTests; } // ExpressionTest_suite #endif