#ifndef test_Element_H #define test_Element_H #include "../CppUnit/framework/TestCase.h" #include "../CppUnit/framework/TestSuite.h" #include "../CppUnit/framework/TestCaller.h" #include template class ElementTest : public TestCase { Arabica::DOM::DOMImplementation factory; typedef string_adaptor SA; public: ElementTest(std::string name) : TestCase(name) { } // ElementTest void setUp() { factory = Arabica::SimpleDOM::DOMImplementation::getDOMImplementation(); } // setUp void test1() { Arabica::DOM::Element d; Arabica::DOM::Node n; assert(d == 0); assert(n == 0); assert(n == d); } // test1 void test2() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0); Arabica::DOM::Element elem = d.createElement(SA::construct_from_utf8("root")); assert(elem.getParentNode() == 0); assert(elem.getOwnerDocument() == d); d.appendChild(elem); Arabica::DOM::Element child = d.createElement(SA::construct_from_utf8("child")); elem.appendChild(child); } // test2 void test3() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0); Arabica::DOM::Element elem = d.createElement(SA::construct_from_utf8("root")); assert(elem.getParentNode() == 0); assert(elem.getOwnerDocument() == d); d.appendChild(elem); Arabica::DOM::Attr attr = d.createAttribute(SA::construct_from_utf8("attr")); attr.setNodeValue(SA::construct_from_utf8("trousers")); try { elem.appendChild(attr); } catch(const Arabica::DOM::DOMException&) { } assert(elem.getFirstChild() == 0); } // test3 void test4() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0); Arabica::DOM::Element elem = d.createElement(SA::construct_from_utf8("root")); assert(elem.getParentNode() == 0); assert(elem.getOwnerDocument() == d); d.appendChild(elem); Arabica::DOM::Attr attr = d.createAttribute(SA::construct_from_utf8("attr")); elem.setAttributeNode(attr); assert(elem.getAttributeNode(SA::construct_from_utf8("attr")) == attr); assert(elem.removeAttributeNode(attr) == attr); Arabica::DOM::Attr attrNS = d.createAttributeNS(SA::construct_from_utf8("ns"), SA::construct_from_utf8("attr")); elem.setAttributeNodeNS(attrNS); assert(elem.getAttributeNodeNS(SA::construct_from_utf8("ns"), SA::construct_from_utf8("attr")) == attrNS); assert(elem.removeAttributeNode(attrNS) == attrNS); } // test4 void test5() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0); Arabica::DOM::Element elem = d.createElement(SA::construct_from_utf8("root")); assert(elem.getParentNode() == 0); assert(elem.getOwnerDocument() == d); d.appendChild(elem); assert(elem.hasAttributes() == false); assert(elem.hasAttribute(SA::construct_from_utf8("attr")) == false); elem.setAttribute(SA::construct_from_utf8("attr"), SA::construct_from_utf8("poop")); assert(elem.hasAttributes() == true); assert(elem.hasAttribute(SA::construct_from_utf8("attr")) == true); Arabica::DOM::Node n = elem.getAttributeNode(SA::construct_from_utf8("attr")); assert(n.getNodeValue() == SA::construct_from_utf8("poop")); assert(elem.setAttributeNode(d.createAttribute(SA::construct_from_utf8("attr"))) == n); } // test5 void test6() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0); Arabica::DOM::Element elem = d.createElement(SA::construct_from_utf8("root")); assert(elem.getParentNode() == 0); assert(elem.getOwnerDocument() == d); d.appendChild(elem); assert(elem.hasAttributes() == false); assert(elem.hasAttribute(SA::construct_from_utf8("attr")) == false); elem.setAttribute(SA::construct_from_utf8("attr"), SA::construct_from_utf8("poop")); assert(elem.hasAttributes() == true); assert(elem.hasAttribute(SA::construct_from_utf8("attr")) == true); elem.removeAttribute(SA::construct_from_utf8("attr")); assert(elem.hasAttributes() == false); assert(elem.hasAttribute(SA::construct_from_utf8("attr")) == false); } // test6 void test7() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0); Arabica::DOM::Element elem = d.createElement(SA::construct_from_utf8("root")); elem.setAttribute(SA::construct_from_utf8("attr"), SA::construct_from_utf8("poop")); elem.appendChild(d.createElement(SA::construct_from_utf8("child"))); Arabica::DOM::Element e2 = Arabica::DOM::Element(elem.cloneNode(false)); assert(e2.getOwnerDocument() == d); assert(e2.getParentNode() == 0); assert(e2.hasAttributes() == true); assert(e2.getAttribute(SA::construct_from_utf8("attr")) == SA::construct_from_utf8("poop")); assert(e2.getFirstChild() == 0); } // test7 void test8() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0); Arabica::DOM::Element elem = d.createElement(SA::construct_from_utf8("root")); elem.setAttribute(SA::construct_from_utf8("attr"), SA::construct_from_utf8("poop")); elem.appendChild(d.createElement(SA::construct_from_utf8("child"))); Arabica::DOM::Element e2 = Arabica::DOM::Element(elem.cloneNode(true)); assert(e2.getOwnerDocument() == d); assert(e2.getParentNode() == 0); assert(e2.hasAttributes() == true); assert(e2.getAttribute(SA::construct_from_utf8("attr")) == SA::construct_from_utf8("poop")); assert(e2.getFirstChild().getNodeName() == SA::construct_from_utf8("child")); } // test }; template TestSuite* ElementTest_suite() { TestSuite *suiteOfTests = new TestSuite; suiteOfTests->addTest(new TestCaller >("test1", &ElementTest::test1)); suiteOfTests->addTest(new TestCaller >("test2", &ElementTest::test2)); suiteOfTests->addTest(new TestCaller >("test3", &ElementTest::test3)); suiteOfTests->addTest(new TestCaller >("test4", &ElementTest::test4)); suiteOfTests->addTest(new TestCaller >("test5", &ElementTest::test5)); suiteOfTests->addTest(new TestCaller >("test6", &ElementTest::test6)); suiteOfTests->addTest(new TestCaller >("test7", &ElementTest::test7)); suiteOfTests->addTest(new TestCaller >("test8", &ElementTest::test8)); return suiteOfTests; } // ElementTest_suite #endif