include/test/xmltesttools.hxx | 5 +++++ test/source/xmltesttools.cxx | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+)
New commits: commit 102292b1039462ad236730fb24baf232c1452c14 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Thu Mar 1 13:31:22 2018 +0100 test: add assertXPathNSDef() Partial backport of Miklos' master commit f8da775795052ad2eb879970c115d2e2a2fe8c81 without the EPUB changes. Change-Id: Ic9dd105249a59200dba03bb30eda350a95aff263 Reviewed-on: https://gerrit.libreoffice.org/50582 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk> (cherry picked from commit 15cf7d30d475271b394ead3bb2458c1dc791a97c) Reviewed-on: https://gerrit.libreoffice.org/51288 Reviewed-by: Michael Stahl <mst...@redhat.com> Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Eike Rathke <er...@redhat.com> Reviewed-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> diff --git a/include/test/xmltesttools.hxx b/include/test/xmltesttools.hxx index 80f95b321a50..42025f9c9ce2 100644 --- a/include/test/xmltesttools.hxx +++ b/include/test/xmltesttools.hxx @@ -76,6 +76,11 @@ protected: */ void assertXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString& rContent); /** + * Assert that rXPath exists and it has an rNSPrefix=rNSHref namespace definition. + */ + void assertXPathNSDef(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString& rNSPrefix, + const OUString& rNSHref); + /** * Assert that rXPath exists, and has exactly nNumberOfChildNodes child nodes. * Useful for checking that we do have a no child nodes to a specific node (nNumberOfChildNodes == 0). */ diff --git a/test/source/xmltesttools.cxx b/test/source/xmltesttools.cxx index 04e90f3cbd7e..94e2cc773e3c 100644 --- a/test/source/xmltesttools.cxx +++ b/test/source/xmltesttools.cxx @@ -122,6 +122,33 @@ void XmlTestTools::assertXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath, CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("In <" + OString(pXmlDoc->name) + ">, XPath contents of child does not match").getStr(), rContent, getXPathContent(pXmlDoc, rXPath)); } +void XmlTestTools::assertXPathNSDef(xmlDocPtr pXmlDoc, const OString& rXPath, + const OUString& rNSPrefix, const OUString& rNSHref) +{ + xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath); + xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval; + CPPUNIT_ASSERT_MESSAGE( + OString("In <" + OString(pXmlDoc->name) + ">, XPath '" + rXPath + "' not found").getStr(), + xmlXPathNodeSetGetLength(pXmlNodes) > 0); + + xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; + bool bFound = false; + for (xmlNsPtr pNamespace = pXmlNode->nsDef; pNamespace; pNamespace = pNamespace->next) + { + if (!pNamespace->prefix) + continue; + + CPPUNIT_ASSERT(pNamespace->href); + if (rNSPrefix == convert(pNamespace->prefix) && rNSHref == convert(pNamespace->href)) + { + bFound = true; + break; + } + } + xmlXPathFreeObject(pXmlObj); + CPPUNIT_ASSERT(bFound); +} + void XmlTestTools::assertXPathChildren(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfChildNodes) { #if LIBXML_VERSION >= 20703 /* xmlChildElementCount is only available in libxml2 >= 2.7.3 */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits