#ifndef NODE_TEST_TEST_H #define NODE_TEST_TEST_H #include "../CppUnit/framework/TestCase.h" #include "../CppUnit/framework/TestSuite.h" #include "../CppUnit/framework/TestCaller.h" #include #include template class NodeTestTest : public TestCase { 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::Attr attr_; Arabica::DOM::Text text_; Arabica::DOM::Comment comment_; Arabica::DOM::ProcessingInstruction processingInstruction_; typedef string_adaptor SA; public: NodeTestTest(const std::string& name) : TestCase(name) { } // NodeTestTest 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_); element2_.appendChild(document_.createElement(SA::construct_from_utf8("spinkle"))); element2_.appendChild(comment_); element2_.appendChild(processingInstruction_); attr_ = element1_.getAttributeNode(SA::construct_from_utf8("one")); root_.appendChild(element1_); root_.appendChild(element2_); root_.appendChild(element3_); } // setUp void test1() { using namespace Arabica::XPath; impl::AnyNodeTest test; assertTrue(test(element1_)); assertTrue(test(element2_)); assertTrue(test(root_)); assertTrue(test(attr_)); assertTrue(test(document_)); assertTrue(test(text_)); assertTrue(test(comment_)); assertTrue(test(processingInstruction_)); } // test1 void test2() { using namespace Arabica::XPath; impl::NameNodeTest test(SA::construct_from_utf8("child1")); assertTrue(test(element1_)); assertTrue(!test(element2_)); assertTrue(!test(root_)); assertTrue(!test(attr_)); assertTrue(!test(document_)); assertTrue(!test(text_)); assertTrue(!test(comment_)); assertTrue(!test(processingInstruction_)); } // test2 void test3() { using namespace Arabica::XPath; impl::NameNodeTest test(SA::construct_from_utf8("one")); assertTrue(!test(element1_)); assertTrue(!test(element2_)); assertTrue(!test(root_)); assertTrue(!test(attr_)); assertTrue(!test(document_)); assertTrue(!test(text_)); assertTrue(!test(comment_)); assertTrue(!test(processingInstruction_)); } // test3 void test4() { using namespace Arabica::XPath; impl::TextNodeTest test; assertTrue(!test(element1_)); assertTrue(!test(root_)); assertTrue(!test(attr_)); assertTrue(!test(document_)); assertTrue(test(text_)); assertTrue(!test(comment_)); assertTrue(!test(processingInstruction_)); } // test4 void test5() { using namespace Arabica::XPath; impl::CommentNodeTest test; assertTrue(!test(element1_)); assertTrue(!test(root_)); assertTrue(!test(attr_)); assertTrue(!test(document_)); assertTrue(!test(text_)); assertTrue(test(comment_)); assertTrue(!test(processingInstruction_)); } // test5 void test6() { using namespace Arabica::XPath; impl::ProcessingInstructionNodeTest test; assertTrue(!test(element1_)); assertTrue(!test(root_)); assertTrue(!test(attr_)); assertTrue(!test(document_)); assertTrue(!test(text_)); assertTrue(!test(comment_)); assertTrue(test(processingInstruction_)); } // test6 void test7() { using namespace Arabica::XPath; impl::ProcessingInstructionNodeTest test(SA::construct_from_utf8("fruity")); assertTrue(!test(element1_)); assertTrue(!test(root_)); assertTrue(!test(attr_)); assertTrue(!test(document_)); assertTrue(!test(text_)); assertTrue(!test(comment_)); assertTrue(!test(processingInstruction_)); } // test7 void test8() { using namespace Arabica::XPath; impl::ProcessingInstructionNodeTest test(SA::construct_from_utf8("target")); assertTrue(!test(element1_)); assertTrue(!test(root_)); assertTrue(!test(attr_)); assertTrue(!test(document_)); assertTrue(!test(text_)); assertTrue(!test(comment_)); assertTrue(test(processingInstruction_)); } // test8 void test9() { using namespace Arabica::XPath; impl::StarNodeTest test; AxisEnumerator e(element2_, CHILD); assertTrue(!test(*e)); ++e; assertTrue(test(*e)); ++e; assertTrue(!test(*e)); ++e; assertTrue(!test(*e)); } // test9 void test10() { using namespace Arabica::XPath; impl::QNameNodeTest test(SA::construct_from_utf8("http://example.com/test"), SA::construct_from_utf8("one")); assertTrue(!test(element1_)); assertTrue(!test(element2_)); assertTrue(!test(root_)); assertTrue(!test(attr_)); assertTrue(!test(document_)); assertTrue(!test(text_)); assertTrue(!test(comment_)); assertTrue(!test(processingInstruction_)); } // test10 void test11() { using namespace Arabica::XPath; impl::QNameNodeTest test(SA::construct_from_utf8("http://example.com/test"), SA::construct_from_utf8("one")); Arabica::DOM::Element e1_ = document_.createElementNS(SA::construct_from_utf8("http://example.com/test"), SA::construct_from_utf8("ns:one")); Arabica::DOM::Element e2_ = document_.createElementNS(SA::construct_from_utf8("http://example.com/test"), SA::construct_from_utf8("ttt:one")); Arabica::DOM::Element e3_ = document_.createElementNS(SA::construct_from_utf8("http://example.com/test"), SA::construct_from_utf8("ns:two")); Arabica::DOM::Element e4_ = document_.createElementNS(SA::construct_from_utf8("http://example.com/test"), SA::construct_from_utf8("ttt:two")); Arabica::DOM::Element e5_ = document_.createElementNS(SA::construct_from_utf8("http://example.com/ssss"), SA::construct_from_utf8("ns:one")); Arabica::DOM::Element e6_ = document_.createElementNS(SA::construct_from_utf8("http://example.com/eeee"), SA::construct_from_utf8("ttt:one")); assertTrue(test(e1_)); assertTrue(test(e2_)); assertTrue(!test(e3_)); assertTrue(!test(e4_)); assertTrue(!test(e5_)); assertTrue(!test(e6_)); } // test11 void test12() { using namespace Arabica::XPath; impl::QStarNodeTest test(SA::construct_from_utf8("http://example.com/test")); Arabica::DOM::Element e1_ = document_.createElementNS(SA::construct_from_utf8("http://example.com/test"), SA::construct_from_utf8("ns:one")); Arabica::DOM::Element e2_ = document_.createElementNS(SA::construct_from_utf8("http://example.com/test"), SA::construct_from_utf8("ttt:one")); Arabica::DOM::Element e3_ = document_.createElementNS(SA::construct_from_utf8("http://example.com/test"), SA::construct_from_utf8("ns:two")); Arabica::DOM::Element e4_ = document_.createElementNS(SA::construct_from_utf8("http://example.com/test"), SA::construct_from_utf8("ttt:two")); Arabica::DOM::Element e5_ = document_.createElementNS(SA::construct_from_utf8("http://example.com/ssss"), SA::construct_from_utf8("ns:one")); Arabica::DOM::Element e6_ = document_.createElementNS(SA::construct_from_utf8("http://example.com/eeee"), SA::construct_from_utf8("ttt:one")); assertTrue(test(e1_)); assertTrue(test(e2_)); assertTrue(test(e3_)); assertTrue(test(e4_)); assertTrue(!test(e5_)); assertTrue(!test(e6_)); } // test12 void test13() { using namespace Arabica::XPath; impl::AttributeNameNodeTest test(SA::construct_from_utf8("one")); assertTrue(!test(element1_)); assertTrue(!test(element2_)); assertTrue(!test(root_)); assertTrue(test(attr_)); assertTrue(!test(document_)); assertTrue(!test(text_)); assertTrue(!test(comment_)); assertTrue(!test(processingInstruction_)); } // test13 void test14() { using namespace Arabica::XPath; impl::NodeNodeTest test; assertTrue(test(element1_)); assertTrue(test(element2_)); assertTrue(test(root_)); assertTrue(test(attr_)); assertTrue(!test(document_)); assertTrue(test(text_)); assertTrue(test(comment_)); assertTrue(test(processingInstruction_)); } // test14 }; // class NodeTestTest template TestSuite* NodeTestTest_suite() { TestSuite* suiteOfTests = new TestSuite; suiteOfTests->addTest(new TestCaller >("test1", &NodeTestTest::test1)); suiteOfTests->addTest(new TestCaller >("test2", &NodeTestTest::test2)); suiteOfTests->addTest(new TestCaller >("test3", &NodeTestTest::test3)); suiteOfTests->addTest(new TestCaller >("test4", &NodeTestTest::test4)); suiteOfTests->addTest(new TestCaller >("test5", &NodeTestTest::test5)); suiteOfTests->addTest(new TestCaller >("test6", &NodeTestTest::test6)); suiteOfTests->addTest(new TestCaller >("test7", &NodeTestTest::test7)); suiteOfTests->addTest(new TestCaller >("test8", &NodeTestTest::test8)); suiteOfTests->addTest(new TestCaller >("test9", &NodeTestTest::test9)); suiteOfTests->addTest(new TestCaller >("test10", &NodeTestTest::test10)); suiteOfTests->addTest(new TestCaller >("test11", &NodeTestTest::test11)); suiteOfTests->addTest(new TestCaller >("test12", &NodeTestTest::test12)); suiteOfTests->addTest(new TestCaller >("test13", &NodeTestTest::test13)); suiteOfTests->addTest(new TestCaller >("test14", &NodeTestTest::test14)); return suiteOfTests; } // NodeTestTest_suite #endif