#ifndef ARABICA_TEST_SAX2DOM_CDATA_HPP #define ARABICA_TEST_SAX2DOM_CDATA_HPP #include "../CppUnit/framework/TestCase.h" #include "../CppUnit/framework/TestSuite.h" #include "../CppUnit/framework/TestCaller.h" #include template class CDATATest : public TestCase { Arabica::DOM::DOMImplementation factory; typedef string_adaptor SA; public: CDATATest(std::string name) : TestCase(name) { } // CDATATest void setUp() { factory = Arabica::SimpleDOM::DOMImplementation::getDOMImplementation(); } // setUp void testNull() { Arabica::DOM::CDATASection 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::CDATASection 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")); } // testCreate void testConversion() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::CDATASection t = d.createCDATASection(SA::construct_from_utf8("some data")); Arabica::DOM::Node n; assert(n != t); n = t; assert(n == t); Arabica::DOM::CDATASection t2; assert(n != t2); t2 = Arabica::DOM::CDATASection(n); assert(t == t2); assert(n == t2); Arabica::DOM::CDATASection t3; t3 = t2; assert(t3 == t2); assert(t3 == t); Arabica::DOM::Comment c = d.createComment(SA::construct_from_utf8("woo")); try { t = Arabica::DOM::CDATASection(c); assertImplementation(false, "converted comment to text"); } catch(const std::bad_cast&) { } } // testConverstion void testConversionToText() { 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; assert(t == 0); assert(cd != t); t = cd; assert(cd == t); Arabica::DOM::CDATASection cd2; assert(cd2 == 0); cd2 = Arabica::DOM::CDATASection(t); assert(cd2 == t); assert(t == cd2); assert(cd == cd2); assert(cd2 == cd); t = d.createTextNode(SA::construct_from_utf8("boom")); try { cd = Arabica::DOM::CDATASection(t); assertImplementation(false, "converted text to CDATA"); } catch(const std::bad_cast&) { } } // testConversionToTest void testEverythingElse() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::CDATASection t = d.createCDATASection(SA::construct_from_utf8("some data")); 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); } // }; template TestSuite* CDATATest_suite() { TestSuite *suiteOfTests = new TestSuite; suiteOfTests->addTest(new TestCaller >("testNull", &CDATATest ::testNull)); suiteOfTests->addTest(new TestCaller >("testCreate", &CDATATest ::testCreate)); suiteOfTests->addTest(new TestCaller >("testConversion", &CDATATest ::testConversion)); suiteOfTests->addTest(new TestCaller >("testConversionToText", &CDATATest ::testConversionToText)); suiteOfTests->addTest(new TestCaller >("testEverythingElse", &CDATATest ::testEverythingElse)); return suiteOfTests; } // CDATATest_suite #endif