#ifdef _MSC_VER #pragma warning(disable: 4786 4250 4503 4224 4267 4180) #endif #include "../CppUnit/framework/TestCase.h" #include "../CppUnit/framework/TestSuite.h" #include "../CppUnit/framework/TestCaller.h" #include #include "step_test.hpp" #include using namespace Arabica::XPath; class StepTest : public TestCase { DOM::DOMImplementation factory_; DOM::Document document_; DOM::Element root_; DOM::Element element1_; DOM::Element element2_; DOM::Element element3_; DOM::Attr attr_; public: StepTest(const std::string& name) : TestCase(name) { } // StepTest void setUp() { factory_ = SimpleDOM::DOMImplementation::getDOMImplementation(); document_ = factory_.createDocument("", "root", 0); root_ = document_.getDocumentElement(); element1_ = document_.createElement("child1"); element2_ = document_.createElement("child2"); element3_ = document_.createElement("child3"); element1_.setAttribute("one", "1"); element2_.setAttribute("one", "1"); element2_.setAttribute("two", "1"); element2_.setAttribute("three", "1"); element2_.setAttribute("four", "1"); attr_ = element1_.getAttributeNode("one"); root_.appendChild(element1_); root_.appendChild(element2_); root_.appendChild(element3_); } // setUp void test1() { XPathExpressionPtr step(new impl::TestStepExpression >(CHILD, new impl::AnyNodeTest())); XPathValuePtr value = step->evaluate(root_); const NodeSet& set = value->asNodeSet(); assertEquals(set.size(), 3); assertTrue(set[0] == element1_); assertTrue(set[1] == element2_); assertTrue(set[2] == element3_); } // test1 void test2() { XPathExpressionPtr step(new impl::TestStepExpression >(ATTRIBUTE, new impl::AnyNodeTest())); NodeSet set = step->evaluateAsNodeSet(element2_); assertEquals(4, set.size()); DOM::Attr attr = static_cast >(set[0]); assertEquals(attr.getNodeName(), "one"); attr = static_cast >(set[1]); assertEquals(attr.getNodeName(), "two"); attr = static_cast >(set[2]); assertEquals(attr.getNodeName(), "three"); attr = static_cast >(set[3]); assertEquals(attr.getNodeName(), "four"); } // test2 void test3() { XPathExpressionPtr step(new impl::TestStepExpression >(CHILD, new impl::NameNodeTest >("child2"))); XPathValuePtr value = step->evaluate(root_); const NodeSet& set = value->asNodeSet(); assertEquals(1, set.size()); assertTrue(set[0] == element2_); } // test3 }; // class StepTest TestSuite* StepTest_suite() { TestSuite* suiteOfTests = new TestSuite; suiteOfTests->addTest(new TestCaller("test1", &StepTest::test1)); suiteOfTests->addTest(new TestCaller("test2", &StepTest::test2)); suiteOfTests->addTest(new TestCaller("test3", &StepTest::test3)); return suiteOfTests; } // StepTest_suite