unoxml/qa/complex/unoxml/DOMTest.java | 43 ------------------------------ unoxml/qa/unit/domtest.cxx | 48 ++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 43 deletions(-)
New commits: commit c914a9da325616cb7a6319ffdc80b584db236cb4 Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Fri Oct 4 14:37:20 2024 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Fri Oct 4 16:31:03 2024 +0200 unoxml: port testXNodeList_ChildList from java to c++ Change-Id: I75d4d9bb275ac1d50fe92f6bd193037f81e3ac64 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174478 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> Tested-by: Jenkins diff --git a/unoxml/qa/complex/unoxml/DOMTest.java b/unoxml/qa/complex/unoxml/DOMTest.java index f61e448ba491..2e262f083b77 100644 --- a/unoxml/qa/complex/unoxml/DOMTest.java +++ b/unoxml/qa/complex/unoxml/DOMTest.java @@ -2220,49 +2220,6 @@ public class DOMTest } */ - @Test public void testXNodeList_ChildList() throws Exception - { - XDocumentBuilder xBuilder = - UnoRuntime.queryInterface(XDocumentBuilder.class, - m_xMSF.createInstance("com.sun.star.xml.dom.DocumentBuilder")); - XDocument xDoc = xBuilder.newDocument(); - - XElement xRoot = xDoc.createElement("root"); - XElement xFoo = xDoc.createElement("foo"); - XElement xBar = xDoc.createElement("bar"); - XElement xBaz = xDoc.createElement("baz"); - - xDoc.appendChild(xRoot); - - XNodeList xChildList = xRoot.getChildNodes(); - assertNotNull(xChildList); - assertSame("ChildList.getLength()", 0, xChildList.getLength()); - - try { - xChildList.item(4); - } catch (Exception e) { /* expected */ } - - xRoot.appendChild(xFoo); - assertSame("ChildList.getLength()", 1, xChildList.getLength()); - assertEquals("ChildList.item", xFoo, xChildList.item(0)); - - xRoot.appendChild(xBar); - assertSame("ChildList.getLength()", 2, xChildList.getLength()); - assertEquals("ChildList.item", xFoo, xChildList.item(0)); - assertEquals("ChildList.item", xBar, xChildList.item(1)); - - xRoot.appendChild(xBaz); - assertSame("ChildList.getLength()", 3, xChildList.getLength()); - assertEquals("ChildList.item", xFoo, xChildList.item(0)); - assertEquals("ChildList.item", xBar, xChildList.item(1)); - assertEquals("ChildList.item", xBaz, xChildList.item(2)); - - xRoot.removeChild(xBar); - assertSame("ChildList.getLength()", 2, xChildList.getLength()); - assertEquals("ChildList.item", xFoo, xChildList.item(0)); - assertEquals("ChildList.item", xBaz, xChildList.item(1)); - } - @Test public void testXNodeList_ElementList() throws Exception { XDocumentBuilder xBuilder = diff --git a/unoxml/qa/unit/domtest.cxx b/unoxml/qa/unit/domtest.cxx index d0c262123bf7..612d36654993 100644 --- a/unoxml/qa/unit/domtest.cxx +++ b/unoxml/qa/unit/domtest.cxx @@ -560,6 +560,53 @@ public: } } + void testXNodeList_ChildList() + { + Reference< xml::dom::XDocument > xDocument = mxDomBuilder->newDocument(); + CPPUNIT_ASSERT(xDocument); + + Reference< xml::dom::XElement > xRoot = xDocument->createElement(u"root"_ustr); + Reference< xml::dom::XElement > xFoo = xDocument->createElement(u"foo"_ustr); + Reference< xml::dom::XElement > xBar = xDocument->createElement(u"bar"_ustr); + Reference< xml::dom::XElement > xBaz = xDocument->createElement(u"baz"_ustr); + + xDocument->appendChild(xRoot); + + uno::Reference<xml::dom::XNodeList> xChildList = xRoot->getChildNodes(); + CPPUNIT_ASSERT(xChildList); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xChildList->getLength()); + + CPPUNIT_ASSERT(!xChildList->item(4)); + + xRoot->appendChild(xFoo); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xChildList->getLength()); + CPPUNIT_ASSERT_EQUAL(Reference< XInterface >(xFoo, uno::UNO_QUERY), + Reference< XInterface >(xChildList->item(0), uno::UNO_QUERY)); + + xRoot->appendChild(xBar); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xChildList->getLength()); + CPPUNIT_ASSERT_EQUAL(Reference< XInterface >(xFoo, uno::UNO_QUERY), + Reference< XInterface >(xChildList->item(0), uno::UNO_QUERY)); + CPPUNIT_ASSERT_EQUAL(Reference< XInterface >(xBar, uno::UNO_QUERY), + Reference< XInterface >(xChildList->item(1), uno::UNO_QUERY)); + + xRoot->appendChild(xBaz); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xChildList->getLength()); + CPPUNIT_ASSERT_EQUAL(Reference< XInterface >(xFoo, uno::UNO_QUERY), + Reference< XInterface >(xChildList->item(0), uno::UNO_QUERY)); + CPPUNIT_ASSERT_EQUAL(Reference< XInterface >(xBar, uno::UNO_QUERY), + Reference< XInterface >(xChildList->item(1), uno::UNO_QUERY)); + CPPUNIT_ASSERT_EQUAL(Reference< XInterface >(xBaz, uno::UNO_QUERY), + Reference< XInterface >(xChildList->item(2), uno::UNO_QUERY)); + + xRoot->removeChild(xBar); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xChildList->getLength()); + CPPUNIT_ASSERT_EQUAL(Reference< XInterface >(xFoo, uno::UNO_QUERY), + Reference< XInterface >(xChildList->item(0), uno::UNO_QUERY)); + CPPUNIT_ASSERT_EQUAL(Reference< XInterface >(xBaz, uno::UNO_QUERY), + Reference< XInterface >(xChildList->item(1), uno::UNO_QUERY)); + } + void testXNodeList_NodeList() { uno::Reference<xml::xpath::XXPathAPI> xXPathAPI( getMultiServiceFactory()->createInstance(u"com.sun.star.xml.xpath.XPathAPI"_ustr), uno::UNO_QUERY_THROW ); @@ -641,6 +688,7 @@ public: CPPUNIT_TEST(testXDocumentBuilder); CPPUNIT_TEST(testXXPathAPI); CPPUNIT_TEST(testXXPathObject); + CPPUNIT_TEST(testXNodeList_ChildList); CPPUNIT_TEST(testXNodeList_NodeList); CPPUNIT_TEST(serializerTest); CPPUNIT_TEST_SUITE_END();