#ifndef ARABICA_TEST_SAX2DOM_CHARACTER_DATA_HPP #define ARABICA_TEST_SAX2DOM_CHARACTER_DATA_HPP #include "../CppUnit/framework/TestCase.h" #include "../CppUnit/framework/TestSuite.h" #include "../CppUnit/framework/TestCaller.h" #include template class CharacterDataTest : public TestCase { Arabica::DOM::DOMImplementation factory; typedef string_adaptor SA; public: CharacterDataTest(std::string name) : TestCase(name) { } // CharacterDataTest void setUp() { factory = Arabica::SimpleDOM::DOMImplementation::getDOMImplementation(); } // setUp void testNull() { Arabica::DOM::CharacterData d; Arabica::DOM::Node n; assert(d == 0); assert(n == 0); assert(n == d); } // testNull void testCreateText() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::CharacterData 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")); assert(t.getNodeType() == Arabica::DOM::Node_base::TEXT_NODE); assert(t.hasAttributes() == false); assert(t.getAttributes() == 0); assert(t.getChildNodes() == 0); assert(t.getFirstChild() == 0); try { t.appendChild(Arabica::DOM::Node()); } catch(const Arabica::DOM::DOMException&) { } assert(t.getFirstChild() == 0); assert(t.getOwnerDocument() == d); assert(t.getParentNode() == 0); } // testCreateText void testCreateCDATA() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::CharacterData t = d.createCDATASection(SA::construct_from_utf8("some data")); assert(t.getData() == SA::construct_from_utf8("some data")); assert(t.getNodeName() == SA::construct_from_utf8("#cdata-section")); assert(t.getNodeValue() == t.getData()); t.setData(SA::construct_from_utf8("newData")); assert(t.getData() == SA::construct_from_utf8("newData")); assert(t.getNodeType() == Arabica::DOM::Node_base::CDATA_SECTION_NODE); assert(t.hasAttributes() == false); assert(t.getAttributes() == 0); assert(t.getChildNodes() == 0); assert(t.getFirstChild() == 0); try { t.appendChild(Arabica::DOM::Node()); } catch(const Arabica::DOM::DOMException&) { } assert(t.getFirstChild() == 0); assert(t.getOwnerDocument() == d); assert(t.getParentNode() == 0); } // testCreateCDATA void testDownCasts() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::CDATASection cd = d.createCDATASection(SA::construct_from_utf8("some data")); Arabica::DOM::Text t = cd; Arabica::DOM::CharacterData c = t; Arabica::DOM::Node n = c; assert(c == cd); assert(c == t); assert(c == n); assert(n == c); assert(n == cd); } // testDownCasts void testTextUpCasts() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::Node n = d.createTextNode(SA::construct_from_utf8("some data")); Arabica::DOM::CharacterData c = Arabica::DOM::CharacterData(n); Arabica::DOM::Text t = Arabica::DOM::Text(c); assert(c == t); assert(c == n); assert(n == c); } // testTextUpCasts void testCDATAUpCasts() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::Node n = d.createCDATASection(SA::construct_from_utf8("some data")); Arabica::DOM::CharacterData c = Arabica::DOM::CharacterData(n); Arabica::DOM::Text t = Arabica::DOM::Text(c); Arabica::DOM::CDATASection cd = Arabica::DOM::CDATASection(c); assert(c == cd); assert(c == t); assert(c == n); assert(n == c); assert(n == cd); } // testCDATAUpCasts }; template TestSuite* CharacterDataTest_suite() { TestSuite *suiteOfTests = new TestSuite; suiteOfTests->addTest(new TestCaller >("testNull", &CharacterDataTest::testNull)); suiteOfTests->addTest(new TestCaller >("testCreateText", &CharacterDataTest::testCreateText)); suiteOfTests->addTest(new TestCaller >("testCreateCDATA", &CharacterDataTest::testCreateCDATA)); suiteOfTests->addTest(new TestCaller >("testDownCasts", &CharacterDataTest::testDownCasts)); suiteOfTests->addTest(new TestCaller >("testTextUpCasts", &CharacterDataTest::testTextUpCasts)); suiteOfTests->addTest(new TestCaller >("testCDATAUpCasts", &CharacterDataTest::testCDATAUpCasts)); return suiteOfTests; } // CharacterDataTest_suite #endif