#ifndef test_PI_H #define test_PI_H #include "../CppUnit/framework/TestCase.h" #include "../CppUnit/framework/TestSuite.h" #include "../CppUnit/framework/TestCaller.h" #include template class PITest : public TestCase { Arabica::DOM::DOMImplementation factory; typedef string_adaptor SA; public: PITest(std::string name) : TestCase(name) { } // PITest void setUp() { factory = Arabica::SimpleDOM::DOMImplementation::getDOMImplementation(); } // setUp void testNull() { Arabica::DOM::ProcessingInstruction d; Arabica::DOM::Node n; assert(d == 0); assert(n == 0); assert(n == d); } // testNull void testCreate() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0); Arabica::DOM::ProcessingInstruction p = d.createProcessingInstruction(SA::construct_from_utf8("target"), SA::construct_from_utf8("data")); assert(p.getTarget() == SA::construct_from_utf8("target")); assert(p.getData() == SA::construct_from_utf8("data")); assert(p.getNodeName() == p.getTarget()); assert(p.getNodeValue() == p.getData()); p.setData(SA::construct_from_utf8("newData")); assert(p.getData() == SA::construct_from_utf8("newData")); } // testCreate void testConversion() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0); Arabica::DOM::ProcessingInstruction pi = d.createProcessingInstruction(SA::construct_from_utf8("target"), SA::construct_from_utf8("data")); Arabica::DOM::Node n; assert(n != pi); n = pi; assert(n == pi); Arabica::DOM::ProcessingInstruction pi2; assert(n != pi2); pi2 = Arabica::DOM::ProcessingInstruction(n); assert(pi == pi2); assert(n == pi2); } // testConverstion void testEverythingElse() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0); Arabica::DOM::ProcessingInstruction pi = d.createProcessingInstruction(SA::construct_from_utf8("target"), SA::construct_from_utf8("data")); assert(pi.getNodeType() == Arabica::DOM::Node_base::PROCESSING_INSTRUCTION_NODE); assert(pi.hasAttributes() == false); assert(pi.getAttributes() == 0); assert(pi.getChildNodes() == 0); assert(pi.getFirstChild() == 0); try { pi.appendChild(Arabica::DOM::Node()); } catch(const Arabica::DOM::DOMException&) { } assert(pi.getFirstChild() == 0); assert(pi.getOwnerDocument() == d); assert(pi.getParentNode() == 0); d.appendChild(pi); assert(pi.getOwnerDocument() == d); assert(pi.getParentNode() == d); assert(d.getFirstChild() == pi); } // testEverythingElse }; // class PITest template TestSuite* ProcessingInstructionTest_suite() { TestSuite *suiteOfTests = new TestSuite; suiteOfTests->addTest(new TestCaller >("testNull", &PITest::testNull)); suiteOfTests->addTest(new TestCaller >("testCreate", &PITest::testCreate)); suiteOfTests->addTest(new TestCaller >("testConversion", &PITest::testConversion)); suiteOfTests->addTest(new TestCaller >("testEverythingElse", &PITest::testEverythingElse)); return suiteOfTests; } // ProcessingInstructionTest_suite #endif