diff options
-rw-r--r-- | include/test/xmltesttools.hxx | 3 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 12 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx | 23 | ||||
-rw-r--r-- | test/source/xmltesttools.cxx | 33 |
4 files changed, 48 insertions, 23 deletions
diff --git a/include/test/xmltesttools.hxx b/include/test/xmltesttools.hxx index 8937211b9f3f..4849ed9afb5b 100644 --- a/include/test/xmltesttools.hxx +++ b/include/test/xmltesttools.hxx @@ -36,7 +36,8 @@ protected: virtual void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx); - xmlNodeSetPtr getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath); + // Caller must call xmlXPathFreeObject: + xmlXPathObjectPtr getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath); /** * Same as the assertXPath(), but don't assert: return the string instead. */ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index aeb66e96463e..9c115a13e0f2 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -1541,7 +1541,8 @@ DECLARE_OOXMLEXPORT_TEST(testFontNameIsEmpty, "font-name-is-empty.docx") xmlDocPtr pXmlFontTable = parseExport("word/fontTable.xml"); if (!pXmlFontTable) return; - xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlFontTable, "/w:fonts/w:font"); + xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlFontTable, "/w:fonts/w:font"); + xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval; sal_Int32 length = xmlXPathNodeSetGetLength(pXmlNodes); for(sal_Int32 index = 0; index < length; index++){ xmlNodePtr pXmlNode = pXmlNodes->nodeTab[index]; @@ -1550,6 +1551,7 @@ DECLARE_OOXMLEXPORT_TEST(testFontNameIsEmpty, "font-name-is-empty.docx") CPPUNIT_FAIL("Font name is empty."); } } + xmlXPathFreeObject(pXmlObj); } DECLARE_OOXMLEXPORT_TEST(testMultiColumnLineSeparator, "multi-column-line-separator-SAVED.docx") @@ -2816,10 +2818,12 @@ DECLARE_OOXMLEXPORT_TEST(testGenericTextField, "Unsupportedtextfields.docx") xmlDocPtr pXmlDoc = parseExport(); if (!pXmlDoc) return; - xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc,"/w:document/w:body/w:p[2]/w:r[2]/w:instrText"); + xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc,"/w:document/w:body/w:p[2]/w:r[2]/w:instrText"); + xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval; xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; OUString contents = OUString::createFromAscii((const char*)((pXmlNode->children[0]).content)); CPPUNIT_ASSERT(contents.match("PRINTDATE \\* MERGEFORMAT")); + xmlXPathFreeObject(pXmlObj); } DECLARE_OOXMLEXPORT_TEST(testDateControl, "date-control.docx") @@ -2966,12 +2970,14 @@ DECLARE_OOXMLEXPORT_TEST(testCitation,"FDO74775.docx") xmlDocPtr pXmlDoc = parseExport(); if (!pXmlDoc) return; - xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc,"/w:document/w:body/w:sdt/w:sdtContent/w:p[1]/w:r[3]/w:instrText"); + xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc,"/w:document/w:body/w:sdt/w:sdtContent/w:p[1]/w:r[3]/w:instrText"); + xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval; CPPUNIT_ASSERT(pXmlNodes != 0); CPPUNIT_ASSERT(pXmlNodes->nodeNr > 0); xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; OUString contents = OUString::createFromAscii((const char*)((pXmlNode->children[0]).content)); CPPUNIT_ASSERT(contents.match(" CITATION [Kra06]")); + xmlXPathFreeObject(pXmlObj); } DECLARE_OOXMLEXPORT_TEST(testFdo76016, "fdo76016.docx") diff --git a/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx index b9610d0c00b9..ad5b49bb9b5f 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx @@ -1519,8 +1519,10 @@ DECLARE_OOXMLEXPORT_TEST(testFdo76101, "fdo76101.docx") if (!pXmlDoc) return; - xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, "/w:styles/w:style"); + xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, "/w:styles/w:style"); + xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval; CPPUNIT_ASSERT(4091 >= xmlXPathNodeSetGetLength(pXmlNodes)); + xmlXPathFreeObject(pXmlObj); } DECLARE_OOXMLEXPORT_TEST(testSdtAndShapeOverlapping,"ShapeOverlappingWithSdt.docx") @@ -1561,22 +1563,23 @@ DECLARE_OOXMLEXPORT_TEST(testAbsolutePositionOffsetValue,"fdo78432.docx") sal_Int32 IntMax = SAL_MAX_INT32; - xmlNodeSetPtr pXmlNodes[6]; - pXmlNodes[0] = getXPathNode(pXmlDoc,"/w:document[1]/w:body[1]/w:p[1]/w:r[1]/mc:AlternateContent[1]/mc:Choice[1]/w:drawing[1]/wp:anchor[1]/wp:positionH[1]/wp:posOffset[1]"); - pXmlNodes[1] = getXPathNode(pXmlDoc,"/w:document[1]/w:body[1]/w:p[1]/w:r[1]/mc:AlternateContent[1]/mc:Choice[1]/w:drawing[1]/wp:anchor[1]/wp:positionV[1]/wp:posOffset[1]"); + xmlXPathObjectPtr pXmlObjs[6]; + pXmlObjs[0] = getXPathNode(pXmlDoc,"/w:document[1]/w:body[1]/w:p[1]/w:r[1]/mc:AlternateContent[1]/mc:Choice[1]/w:drawing[1]/wp:anchor[1]/wp:positionH[1]/wp:posOffset[1]"); + pXmlObjs[1] = getXPathNode(pXmlDoc,"/w:document[1]/w:body[1]/w:p[1]/w:r[1]/mc:AlternateContent[1]/mc:Choice[1]/w:drawing[1]/wp:anchor[1]/wp:positionV[1]/wp:posOffset[1]"); - pXmlNodes[2] = getXPathNode(pXmlDoc,"/w:document[1]/w:body[1]/w:p[1]/w:r[1]/mc:AlternateContent[2]/mc:Choice[1]/w:drawing[1]/wp:anchor[1]/wp:positionH[1]/wp:posOffset[1]"); - pXmlNodes[3] = getXPathNode(pXmlDoc,"/w:document[1]/w:body[1]/w:p[1]/w:r[1]/mc:AlternateContent[2]/mc:Choice[1]/w:drawing[1]/wp:anchor[1]/wp:positionV[1]/wp:posOffset[1]"); + pXmlObjs[2] = getXPathNode(pXmlDoc,"/w:document[1]/w:body[1]/w:p[1]/w:r[1]/mc:AlternateContent[2]/mc:Choice[1]/w:drawing[1]/wp:anchor[1]/wp:positionH[1]/wp:posOffset[1]"); + pXmlObjs[3] = getXPathNode(pXmlDoc,"/w:document[1]/w:body[1]/w:p[1]/w:r[1]/mc:AlternateContent[2]/mc:Choice[1]/w:drawing[1]/wp:anchor[1]/wp:positionV[1]/wp:posOffset[1]"); - pXmlNodes[4] = getXPathNode(pXmlDoc,"/w:document[1]/w:body[1]/w:p[1]/w:r[1]/mc:AlternateContent[3]/mc:Choice[1]/w:drawing[1]/wp:anchor[1]/wp:positionH[1]/wp:posOffset[1]"); - pXmlNodes[5] = getXPathNode(pXmlDoc,"/w:document[1]/w:body[1]/w:p[1]/w:r[1]/mc:AlternateContent[3]/mc:Choice[1]/w:drawing[1]/wp:anchor[1]/wp:positionV[1]/wp:posOffset[1]"); + pXmlObjs[4] = getXPathNode(pXmlDoc,"/w:document[1]/w:body[1]/w:p[1]/w:r[1]/mc:AlternateContent[3]/mc:Choice[1]/w:drawing[1]/wp:anchor[1]/wp:positionH[1]/wp:posOffset[1]"); + pXmlObjs[5] = getXPathNode(pXmlDoc,"/w:document[1]/w:body[1]/w:p[1]/w:r[1]/mc:AlternateContent[3]/mc:Choice[1]/w:drawing[1]/wp:anchor[1]/wp:positionV[1]/wp:posOffset[1]"); for(sal_Int32 index = 0; index<6; ++index) { - CPPUNIT_ASSERT(pXmlNodes[index] != 0); - xmlNodePtr pXmlNode = pXmlNodes[index]->nodeTab[0]; + CPPUNIT_ASSERT(pXmlObjs[index]->nodesetval != 0); + xmlNodePtr pXmlNode = pXmlObjs[index]->nodesetval->nodeTab[0]; OUString contents = OUString::createFromAscii((const char*)((pXmlNode->children[0]).content)); CPPUNIT_ASSERT( contents.toInt64() <= IntMax ); + xmlXPathFreeObject(pXmlObjs[index]); } } diff --git a/test/source/xmltesttools.cxx b/test/source/xmltesttools.cxx index 1cb231c0849d..0cb89f701201 100644 --- a/test/source/xmltesttools.cxx +++ b/test/source/xmltesttools.cxx @@ -32,12 +32,13 @@ xmlDocPtr XmlTestTools::parseXmlStream(SvStream* pStream) return xmlParseDoc(reinterpret_cast<xmlChar*>(pBuffer.get())); } -xmlNodeSetPtr XmlTestTools::getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath) +xmlXPathObjectPtr XmlTestTools::getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath) { xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc); registerNamespaces(pXmlXpathCtx); xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(rXPath.getStr()), pXmlXpathCtx); - return pXmlXpathObj->nodesetval; + xmlXPathFreeContext(pXmlXpathCtx); + return pXmlXpathObj; } void XmlTestTools::registerNamespaces(xmlXPathContextPtr& /*pXmlXpathCtx*/) @@ -46,24 +47,32 @@ void XmlTestTools::registerNamespaces(xmlXPathContextPtr& /*pXmlXpathCtx*/) OUString XmlTestTools::getXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute) { - xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath); + xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath); + xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval; CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(), 1, xmlXPathNodeSetGetLength(pXmlNodes)); if (rAttribute.isEmpty()) return OUString(); xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; - return OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr()))); + xmlChar * prop = xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr())); + OUString s(OUString::createFromAscii((const char*)prop)); + xmlFree(prop); + xmlXPathFreeObject(pXmlObj); + return s; } OUString XmlTestTools::getXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath) { - xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath); + xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath); + xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval; CPPUNIT_ASSERT_MESSAGE(OString("XPath '" + rXPath + "' not found").getStr(), xmlXPathNodeSetGetLength(pXmlNodes) > 0); xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; - return OUString::createFromAscii((const char*)((pXmlNode->children[0]).content)); + OUString s(OUString::createFromAscii((const char*)((pXmlNode->children[0]).content))); + xmlXPathFreeObject(pXmlObj); + return s; } void XmlTestTools::assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute, const OUString& rExpectedValue) @@ -75,9 +84,11 @@ void XmlTestTools::assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const O void XmlTestTools::assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfNodes) { - xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath); + xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath); + xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval; CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(), nNumberOfNodes, xmlXPathNodeSetGetLength(pXmlNodes)); + xmlXPathFreeObject(pXmlObj); } void XmlTestTools::assertXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString& rContent) @@ -87,17 +98,20 @@ void XmlTestTools::assertXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath, void XmlTestTools::assertXPathChildren(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfChildNodes) { - xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath); + xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath); + xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval; CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(), 1, xmlXPathNodeSetGetLength(pXmlNodes)); xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of child-nodes is incorrect").getStr(), nNumberOfChildNodes, (int)xmlChildElementCount(pXmlNode)); + xmlXPathFreeObject(pXmlObj); } int XmlTestTools::getXPathPosition(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString& rChildName) { - xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath); + xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath); + xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval; CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(), 1, xmlXPathNodeSetGetLength(pXmlNodes)); @@ -109,6 +123,7 @@ int XmlTestTools::getXPathPosition(xmlDocPtr pXmlDoc, const OString& rXPath, con break; ++nRet; } + xmlXPathFreeObject(pXmlObj); return nRet; } |