#ifdef _MSC_VER #pragma warning(disable: 4786 4250 4503) #endif #include "../CppUnit/framework/TestCase.h" #include "../CppUnit/framework/TestSuite.h" #include "../CppUnit/framework/TestCaller.h" #include class CharacterDataTest : public TestCase { DOM::DOMImplementation factory; public: CharacterDataTest(std::string name) : TestCase(name) { } // CharacterDataTest void setUp() { factory = SimpleDOM::DOMImplementation::getDOMImplementation(); } // setUp void testNull() { DOM::CharacterData d; DOM::Node n; assert(d == 0); assert(n == 0); assert(n == d); } // testNull void testCreateText() { DOM::Document d = factory.createDocument("","", 0); DOM::CharacterData t = d.createTextNode("some data"); assert(t.getData() == "some data"); assert(t.getNodeName() == "#text"); assert(t.getNodeValue() == t.getData()); t.setData("newData"); assert(t.getData() == "newData"); 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); } // testCreateText void testCreateCDATA() { DOM::Document d = factory.createDocument("","", 0); DOM::CharacterData t = d.createCDATASection("some data"); assert(t.getData() == "some data"); assert(t.getNodeName() == "#cdata-section"); assert(t.getNodeValue() == t.getData()); t.setData("newData"); assert(t.getData() == "newData"); assert(t.getNodeType() == DOM::Node::CDATA_SECTION_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); } // testCreateCDATA void testDownCasts() { DOM::Document d = factory.createDocument("","", 0); DOM::CDATASection cd = d.createCDATASection("some data"); DOM::Text t = cd; DOM::CharacterData c = t; DOM::Node n = c; assert(c == cd); assert(c == t); assert(c == n); assert(n == c); assert(n == cd); } // testDownCasts void testTextUpCasts() { DOM::Document d = factory.createDocument("","", 0); DOM::Node n = d.createTextNode("some data"); DOM::CharacterData c = DOM::CharacterData(n); DOM::Text t = DOM::Text(c); assert(c == t); assert(c == n); assert(n == c); } // testTextUpCasts void testCDATAUpCasts() { DOM::Document d = factory.createDocument("","", 0); DOM::Node n = d.createCDATASection("some data"); DOM::CharacterData c = DOM::CharacterData(n); DOM::Text t = DOM::Text(c); DOM::CDATASection cd = DOM::CDATASection(c); assert(c == cd); assert(c == t); assert(c == n); assert(n == c); assert(n == cd); } // testCDATAUpCasts }; 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