#ifndef test_NAMEDNODEMAP_H #define test_NAMEDNODEMAP_H #include "../CppUnit/framework/TestCase.h" #include "../CppUnit/framework/TestSuite.h" #include "../CppUnit/framework/TestCaller.h" #include #include #include template class NamedNodeMapTest : public TestCase { typedef string_adaptor SA; typedef Arabica::DOM::Element Element; typedef Arabica::DOM::Node Node; typedef Arabica::DOM::NamedNodeMap NamedNodeMap; public: NamedNodeMapTest(std::string name) : TestCase(name) { } // NamedNodeMapTest void setUp() { } // setUp string_type s(const char* ss) { return SA::construct_from_utf8(ss); } // s Arabica::DOM::Document parse(const char* xml) { string_type str = s(xml); std::stringstream ss; ss << SA::asStdString(str); Arabica::SAX::InputSource is(ss); Arabica::SAX::CatchErrorHandler eh; Arabica::SAX2DOM::Parser parser; parser.setErrorHandler(eh); parser.parse(is); //if(eh.errorsReported()) // throw std::runtime_error(eh.errors()); return parser.getDocument(); } // parse void test1() { Element d = parse("").getDocumentElement(); NamedNodeMap nm = d.getAttributes(); assertEquals(0, nm.getLength()); } // test1 void test2() { Element d = parse("").getDocumentElement(); NamedNodeMap nm = d.getAttributes(); assertEquals(1, nm.getLength()); assert(s("one") == nm.item(0).getNodeValue()); assert(s("one") == nm.getNamedItem(s("a")).getNodeValue()); assert(s("one") == nm.getNamedItemNS(s(""), s("a")).getNodeValue()); } // test2 void test3() { Element d = parse("").getDocumentElement(); NamedNodeMap nm = d.getAttributes(); assertEquals(2, nm.getLength()); assert(0 == nm.getNamedItem(s("a"))); assert(s("one") == nm.getNamedItemNS(s("urn:a"), s("a")).getNodeValue()); } // test3 void test4() { Element d = parse("").getDocumentElement(); NamedNodeMap nm = d.getAttributes(); assertEquals(1, nm.getLength()); Node a = nm.removeNamedItem(s("a")); assertEquals(0, nm.getLength()); nm.setNamedItem(a); assertEquals(1, nm.getLength()); } // test4 void test5() { Element d = parse("").getDocumentElement(); NamedNodeMap nm = d.getAttributes(); assertEquals(2, nm.getLength()); Node a = nm.removeNamedItemNS(s("urn:a"), s("a")); assertEquals(1, nm.getLength()); nm.setNamedItemNS(a); assertEquals(2, nm.getLength()); } // test5 }; template TestSuite* NamedNodeMapTest_suite() { TestSuite *suiteOfTests = new TestSuite; suiteOfTests->addTest(new TestCaller >("test1", &NamedNodeMapTest::test1)); suiteOfTests->addTest(new TestCaller >("test2", &NamedNodeMapTest::test2)); suiteOfTests->addTest(new TestCaller >("test3", &NamedNodeMapTest::test3)); suiteOfTests->addTest(new TestCaller >("test4", &NamedNodeMapTest::test4)); suiteOfTests->addTest(new TestCaller >("test5", &NamedNodeMapTest::test5)); return suiteOfTests; } // NamedNodeMapTest_suite #endif