From 2cb2cc8bbe4a93d2e2ded7a7d4941859aa706b7a Mon Sep 17 00:00:00 2001 From: jez Date: Mon, 23 Nov 2009 22:36:15 +0000 Subject: [PATCH] NamedNodeMap tests and bugfix --- include/DOM/NamedNodeMap.hpp | 2 +- tests/DOM/dom_test_suite.hpp | 2 + tests/DOM/test_NamedNodeMap.hpp | 111 ++++++++++++++++++++++++++++++++ vs9/test_DOM.vcproj | 8 +++ 4 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 tests/DOM/test_NamedNodeMap.hpp diff --git a/include/DOM/NamedNodeMap.hpp b/include/DOM/NamedNodeMap.hpp index 89e8402f..6afff493 100644 --- a/include/DOM/NamedNodeMap.hpp +++ b/include/DOM/NamedNodeMap.hpp @@ -58,7 +58,7 @@ class NamedNodeMap NodeT removeNamedItemNS(const stringT& namespaceURI, const stringT& localName) const { - return NodeT(impl_->removeNamedItem(namespaceURI, localName)); + return NodeT(impl_->removeNamedItemNS(namespaceURI, localName)); } // removeNamedItemNS private: diff --git a/tests/DOM/dom_test_suite.hpp b/tests/DOM/dom_test_suite.hpp index 909ffc66..a97e0f07 100644 --- a/tests/DOM/dom_test_suite.hpp +++ b/tests/DOM/dom_test_suite.hpp @@ -18,6 +18,7 @@ #include "test_CharacterData.hpp" #include "test_SAX2DOM.hpp" #include "test_TreeWalker.hpp" +#include "test_NamedNodeMap.hpp" template bool DOM_test_suite(int argc, const char** argv) @@ -36,6 +37,7 @@ bool DOM_test_suite(int argc, const char** argv) runner.addTest("CharacterDataText", CharacterDataTest_suite()); runner.addTest("DocumentFragmentTest", DocumentFragmentTest_suite()); runner.addTest("SAX2DOMTest", SAX2DOMTest_suite()); + runner.addTest("NamedNodeMapTest", NamedNodeMapTest_suite()); runner.addTest("TreeWalkerTest", TreeWalkerTest_suite()); return runner.run(argc, argv); diff --git a/tests/DOM/test_NamedNodeMap.hpp b/tests/DOM/test_NamedNodeMap.hpp new file mode 100644 index 00000000..478583d0 --- /dev/null +++ b/tests/DOM/test_NamedNodeMap.hpp @@ -0,0 +1,111 @@ +#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::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()); + nm.removeNamedItem(s("a")); + assertEquals(0, nm.getLength()); + } // test4 + + void test5() + { + Element d = parse("").getDocumentElement(); + NamedNodeMap nm = d.getAttributes(); + assertEquals(2, nm.getLength()); + nm.removeNamedItemNS(s("urn:a"), s("a")); + assertEquals(1, 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 + diff --git a/vs9/test_DOM.vcproj b/vs9/test_DOM.vcproj index 9cb96ec3..6da26876 100644 --- a/vs9/test_DOM.vcproj +++ b/vs9/test_DOM.vcproj @@ -241,6 +241,10 @@ RelativePath=".\..\tests\DOM\test_Element.hpp" > + + @@ -257,6 +261,10 @@ RelativePath=".\..\tests\DOM\test_Text.hpp" > + +