#ifndef ARABICA_TEST_SAX2DOM_TEXT_HPP #define ARABICA_TEST_SAX2DOM_TEXT_HPP #include "../CppUnit/framework/TestCase.h" #include "../CppUnit/framework/TestSuite.h" #include "../CppUnit/framework/TestCaller.h" #include template class TextTest : public TestCase { DOM::DOMImplementation factory; typedef string_adaptor SA; public: TextTest(std::string name) : TestCase(name) { } // TextTest void setUp() { factory = SimpleDOM::DOMImplementation::getDOMImplementation(); } // setUp void testNull() { DOM::Text d; DOM::Node n; assert(d == 0); assert(n == 0); assert(n == d); } // testNull void testCreate() { DOM::Document d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0); DOM::Text t = d.createTextNode(SA::construct_from_utf8("some data")); assert(t.getData() == SA::construct_from_utf8("some data")); assert(t.getNodeName() == SA::construct_from_utf8("#text")); assert(t.getNodeValue() == t.getData()); t.setData(SA::construct_from_utf8("newData")); assert(t.getData() == SA::construct_from_utf8("newData")); } // testCreate void testConversion() { DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); DOM::Text t = d.createTextNode(SA::construct_from_utf8("some data")); DOM::Node n; assert(n != t); n = t; assert(n == t); DOM::Text t2; assert(n != t2); t2 = DOM::Text(n); assert(t == t2); assert(n == t2); DOM::Text t3; t3 = t2; assert(t3 == t2); assert(t3 == t); DOM::Comment c = d.createComment(SA::construct_from_utf8("woo")); try { t = DOM::Text(c); assertImplementation(false, "converted comment to text"); } catch(const std::bad_cast&) { } } // testConverstion void testEverythingElse() { DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); DOM::Text t = d.createTextNode(SA::construct_from_utf8("some data")); assert(t.getNodeType() == DOM::Node::TEXT_NODE); assert(t.hasAttributes() == false); assert(t.getAttributes() == 0); assert(t.getChildNodes() == 0); assert(t.getFirstChild() == 0); try { t.appendChild(DOM::Node()); } catch(const DOM::DOMException&) { } assert(t.getFirstChild() == 0); assert(t.getOwnerDocument() == d); assert(t.getParentNode() == 0); } // }; template TestSuite* TextTest_suite() { TestSuite *suiteOfTests = new TestSuite; suiteOfTests->addTest(new TestCaller >("testNull", &TextTest::testNull)); suiteOfTests->addTest(new TestCaller >("testCreate", &TextTest::testCreate)); suiteOfTests->addTest(new TestCaller >("testConversion", &TextTest::testConversion)); suiteOfTests->addTest(new TestCaller >("testEverythingElse", &TextTest::testEverythingElse)); return suiteOfTests; } // TextTest_suite #endif