diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2018-10-30 12:54:56 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2018-10-30 14:42:45 +0100 |
commit | ac12028bf29aad389f03a296402e7af51a86a3e6 (patch) | |
tree | 9f9bb35ed0683f7f762b4af301a66802e9b20879 /test | |
parent | 8780fa41dcd164af244742461f4e57a4bcf4c7a4 (diff) |
tdf#116989: add unit test
Change-Id: Ia8b5478b0d2a15f91add4ee76455e73c2c970392
Reviewed-on: https://gerrit.libreoffice.org/62544
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/source/xmltesttools.cxx | 51 |
1 files changed, 38 insertions, 13 deletions
diff --git a/test/source/xmltesttools.cxx b/test/source/xmltesttools.cxx index cae81afa77a3..dd3179cb1e1f 100644 --- a/test/source/xmltesttools.cxx +++ b/test/source/xmltesttools.cxx @@ -82,20 +82,45 @@ OUString XmlTestTools::getXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString XmlTestTools::getXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath) { 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); + switch (pXmlObj->type) + { + case XPATH_UNDEFINED: + CPPUNIT_FAIL("Undefined XPath type"); + case XPATH_NODESET: + { + 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]; + xmlNodePtr pXmlChild = pXmlNode->children; + OUString s; + while (pXmlChild && pXmlChild->type != XML_TEXT_NODE) + pXmlChild = pXmlChild->next; + if (pXmlChild && pXmlChild->type == XML_TEXT_NODE) + s = convert(pXmlChild->content); + xmlXPathFreeObject(pXmlObj); + return s; + } + case XPATH_BOOLEAN: + return pXmlObj->boolval ? OUString("true") : OUString("false"); + case XPATH_NUMBER: + return OUString::number(pXmlObj->floatval); + case XPATH_STRING: + return convert(pXmlObj->stringval); + case XPATH_POINT: + case XPATH_RANGE: + case XPATH_LOCATIONSET: + case XPATH_USERS: + case XPATH_XSLT_TREE: + CPPUNIT_FAIL("Unsupported XPath type"); + } - xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; - xmlNodePtr pXmlChild = pXmlNode->children; - OUString s; - while (pXmlChild && pXmlChild->type != XML_TEXT_NODE) - pXmlChild = pXmlChild->next; - if (pXmlChild && pXmlChild->type == XML_TEXT_NODE) - s = convert(pXmlChild->content); - xmlXPathFreeObject(pXmlObj); - return s; + CPPUNIT_FAIL("Invalid XPath type"); + return OUString(); // to suppress "Not all control paths return a value" warning on MSVC } void XmlTestTools::assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute, const OUString& rExpectedValue) |