[Libreoffice-commits] core.git: Branch 'libreoffice-6-0' - include/test test/source
Miklos Vajna
vmiklos at collabora.co.uk
Thu Mar 1 16:14:09 UTC 2018
include/test/xmltesttools.hxx | 5 +++++
test/source/xmltesttools.cxx | 27 +++++++++++++++++++++++++++
2 files changed, 32 insertions(+)
New commits:
commit 0809eac4baddd02c3f4405148269f877c0f56c3f
Author: Miklos Vajna <vmiklos at 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/50588
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
diff --git a/include/test/xmltesttools.hxx b/include/test/xmltesttools.hxx
index bfcaf91cdd6d..eba5c84a0644 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 bcdf93e1ae0b..57baa91fe9f6 100644
--- a/test/source/xmltesttools.cxx
+++ b/test/source/xmltesttools.cxx
@@ -123,6 +123,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 */
More information about the Libreoffice-commits
mailing list