sc/qa/unit/helper/xpath.cxx           |    6 +++++-
 sc/qa/unit/helper/xpath.hxx           |   17 +++++++++++++++++
 sc/qa/unit/subsequent_export-test.cxx |   13 ++++---------
 3 files changed, 26 insertions(+), 10 deletions(-)

New commits:
commit 63bb0e891e94206bbd50c657bca8661d135ef5e6
Author: Markus Mohrhard <markus.mohrh...@googlemail.com>
Date:   Fri Mar 11 02:31:05 2016 +0100

    allow to call xpath expression on different files in container
    
    Change-Id: I0b95ac19e2f6a01cadb4de32937282f489dbca7f
    Reviewed-on: https://gerrit.libreoffice.org/23137
    Reviewed-by: Markus Mohrhard <markus.mohrh...@googlemail.com>
    Tested-by: Markus Mohrhard <markus.mohrh...@googlemail.com>

diff --git a/sc/qa/unit/helper/xpath.cxx b/sc/qa/unit/helper/xpath.cxx
index 43dafa3..8056d4d 100644
--- a/sc/qa/unit/helper/xpath.cxx
+++ b/sc/qa/unit/helper/xpath.cxx
@@ -12,7 +12,6 @@
 #include <cppunit/TestAssert.h>
 #include "qahelper.hxx"
 
-#include <unotools/tempfile.hxx>
 #include <unotools/ucbstreamhelper.hxx>
 
 #include <test/xmltesttools.hxx>
@@ -23,6 +22,11 @@ xmlDocPtr XPathHelper::parseExport(ScDocShell& rShell, 
uno::Reference<lang::XMul
 {
     std::shared_ptr<utl::TempFile> pTempFile = 
ScBootstrapFixture::exportTo(&rShell, nFormat);
 
+    return parseExport(pTempFile, xSFactory, rFile);
+}
+
+xmlDocPtr XPathHelper::parseExport(std::shared_ptr<utl::TempFile> pTempFile, 
uno::Reference<lang::XMultiServiceFactory> xSFactory, const OUString& rFile)
+{
     // Read the XML stream we're interested in.
     uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = 
packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(xSFactory),
 pTempFile->GetURL());
     uno::Reference<io::XInputStream> 
xInputStream(xNameAccess->getByName(rFile), uno::UNO_QUERY);
diff --git a/sc/qa/unit/helper/xpath.hxx b/sc/qa/unit/helper/xpath.hxx
index d45fc76..f53f927 100644
--- a/sc/qa/unit/helper/xpath.hxx
+++ b/sc/qa/unit/helper/xpath.hxx
@@ -12,12 +12,16 @@
 
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
 
+#include <unotools/tempfile.hxx>
+
 #include <libxml/xpathInternals.h>
 #include <libxml/parserInternals.h>
 
 #include <rtl/string.hxx>
 #include <rtl/ustring.hxx>
 
+#include <memory>
+
 #if defined(SCQAHELPER_DLLIMPLEMENTATION)
 #define SCQAHELPER_DLLPUBLIC  SAL_DLLPUBLIC_EXPORT
 #else
@@ -35,9 +39,22 @@ namespace XPathHelper
      * test the resulting file directly, by opening the zip file, parsing an
      * xml stream, and asserting an XPath expression. This method returns the
      * xml stream, so that you can do the asserting.
+     *
+     * Warning: This method saves the document and does not export it! If you 
need to
+     *      test several files in the same exported xml file you need to 
export the file manually
+     *      and call the parseExport method that takes a TempFile
      */
     SCQAHELPER_DLLPUBLIC xmlDocPtr parseExport(ScDocShell& rShell, 
uno::Reference< lang::XMultiServiceFactory> xSFactory,
             const OUString& rFile, sal_Int32 nFormat);
+
+    /**
+     * Tries to parse the specified file in the temp file zip container as an 
xml file.
+     *
+     * Should be used when the same exported file is used for testing 
different files in
+     * the same zip file.
+     */
+    SCQAHELPER_DLLPUBLIC xmlDocPtr parseExport(std::shared_ptr<utl::TempFile> 
pTempFile, uno::Reference< lang::XMultiServiceFactory> xSFactory,
+            const OUString& rFile);
 }
 
 #endif
diff --git a/sc/qa/unit/subsequent_export-test.cxx 
b/sc/qa/unit/subsequent_export-test.cxx
index cf13dcb..1228ada 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -1100,20 +1100,15 @@ void ScExportTest::testRichTextCellFormat()
     ScDocShellRef xDocSh = loadDoc("cellformat.", FORMAT_XLS);
     CPPUNIT_ASSERT(xDocSh.Is());
 
-    xmlDocPtr pSheet = XPathHelper::parseExport(*xDocSh, m_xSFactory, 
"xl/worksheets/sheet1.xml", FORMAT_XLSX);
+    std::shared_ptr<utl::TempFile> pXPathFile = 
ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX);
+    xmlDocPtr pSheet = XPathHelper::parseExport(pXPathFile, m_xSFactory, 
"xl/worksheets/sheet1.xml");
     CPPUNIT_ASSERT(pSheet);
 
     // make sure the only cell in this doc is assigned some formatting record
     OUString aCellFormat = getXPath(pSheet, 
"/x:worksheet/x:sheetData/x:row/x:c", "s");
     CPPUNIT_ASSERT_MESSAGE("Cell format is missing", !aCellFormat.isEmpty());
 
-    xDocSh->DoClose();
-    //FIXME: this shouldn't be necessary, but for some reason 2nd and every 
consecutive call
-    //to parseExport() (different stream name within the same doc, of course) 
doesn't find
-    //the stream anymore. I have neither knowledge nor time to debug it
-    ScDocShellRef xNewDocSh = loadDoc("cellformat.", FORMAT_XLS);
-
-    xmlDocPtr pStyles = XPathHelper::parseExport(*xNewDocSh, m_xSFactory, 
"xl/styles.xml", FORMAT_XLSX);
+    xmlDocPtr pStyles = XPathHelper::parseExport(pXPathFile, m_xSFactory, 
"xl/styles.xml");
     CPPUNIT_ASSERT(pStyles);
 
     OString nFormatIdx = OString::number( aCellFormat.toInt32() + 1 );
@@ -1130,7 +1125,7 @@ void ScExportTest::testRichTextCellFormat()
     const OString xPath3("/x:styleSheet/x:fonts/x:font[" + nFontIdx + "]/x:b");
     assertXPath(pStyles, xPath3, "val", "true");
 
-    xNewDocSh->DoClose();
+    xDocSh->DoClose();
 }
 
 void ScExportTest::testFormulaRefSheetNameODS()
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to