diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2018-02-26 07:46:09 -0500 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2018-03-07 14:54:58 +0100 |
commit | a8f92371317d0056212063d473bb518cfbdbf874 (patch) | |
tree | c21b763424ec533e5e7d37b071ed577d312419b8 /sc | |
parent | 54ac8cf00820ae17f25251f16989485f4271cbe7 (diff) |
oox: unit-tests for custom package preservation
Change-Id: I69d0d7d6bdc8804d0e56be19cd86a699200fc85f
Reviewed-on: https://gerrit.libreoffice.org/50895
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/data/xlsx/customxml.xlsx | bin | 0 -> 13282 bytes | |||
-rw-r--r-- | sc/qa/unit/helper/xpath.cxx | 7 | ||||
-rw-r--r-- | sc/qa/unit/helper/xpath.hxx | 6 | ||||
-rw-r--r-- | sc/qa/unit/subsequent_export-test.cxx | 19 |
4 files changed, 31 insertions, 1 deletions
diff --git a/sc/qa/unit/data/xlsx/customxml.xlsx b/sc/qa/unit/data/xlsx/customxml.xlsx Binary files differnew file mode 100644 index 000000000000..53619ae4af30 --- /dev/null +++ b/sc/qa/unit/data/xlsx/customxml.xlsx diff --git a/sc/qa/unit/helper/xpath.cxx b/sc/qa/unit/helper/xpath.cxx index 2d047b60bf61..562facc84f1e 100644 --- a/sc/qa/unit/helper/xpath.cxx +++ b/sc/qa/unit/helper/xpath.cxx @@ -25,14 +25,19 @@ xmlDocPtr XPathHelper::parseExport(ScDocShell& rShell, uno::Reference<lang::XMul return parseExport(pTempFile, xSFactory, rFile); } -xmlDocPtr XPathHelper::parseExport(std::shared_ptr<utl::TempFile> const & pTempFile, uno::Reference<lang::XMultiServiceFactory> const & xSFactory, const OUString& rFile) +std::shared_ptr<SvStream> XPathHelper::parseExportStream(std::shared_ptr<utl::TempFile> const & pTempFile, uno::Reference<lang::XMultiServiceFactory> const & 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); CPPUNIT_ASSERT(xInputStream.is()); std::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); + return pStream; +} +xmlDocPtr XPathHelper::parseExport(std::shared_ptr<utl::TempFile> const & pTempFile, uno::Reference<lang::XMultiServiceFactory> const & xSFactory, const OUString& rFile) +{ + std::shared_ptr<SvStream> pStream = parseExportStream(pTempFile, xSFactory, rFile); return XmlTestTools::parseXmlStream(pStream.get()); } diff --git a/sc/qa/unit/helper/xpath.hxx b/sc/qa/unit/helper/xpath.hxx index 86d1d279576e..fed540fc8b93 100644 --- a/sc/qa/unit/helper/xpath.hxx +++ b/sc/qa/unit/helper/xpath.hxx @@ -48,6 +48,12 @@ namespace XPathHelper const OUString& rFile, sal_Int32 nFormat); /** + * Tries to parse the specified file in the temp file zip container as a binary file. + */ + SCQAHELPER_DLLPUBLIC std::shared_ptr<SvStream> parseExportStream(std::shared_ptr<utl::TempFile> const & pTempFile, + uno::Reference<lang::XMultiServiceFactory> const & xSFactory, const OUString& rFile); + + /** * 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 diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index 092324658f3c..c013d836fb8b 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -155,6 +155,8 @@ public: void testCeilingFloorXLS(); void testCeilingFloorODS(); + void testCustomXml(); + #if !defined _WIN32 void testRelativePaths(); #endif @@ -275,6 +277,7 @@ public: CPPUNIT_TEST(testCeilingFloorXLSX); CPPUNIT_TEST(testCeilingFloorXLS); CPPUNIT_TEST(testCeilingFloorODS); + CPPUNIT_TEST(testCustomXml); #if !defined(_WIN32) CPPUNIT_TEST(testRelativePaths); #endif @@ -3015,6 +3018,22 @@ void ScExportTest::testCeilingFloorODS() testCeilingFloor(FORMAT_ODS); } +void ScExportTest::testCustomXml() +{ + // Load document and export it to a temporary file + ScDocShellRef xShell = loadDoc("customxml.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to load the document.", xShell.Is()); + + std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); + xmlDocPtr pXmlDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "customXml/item1.xml"); + CPPUNIT_ASSERT(pXmlDoc); + xmlDocPtr pRelsDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "customXml/_rels/item1.xml.rels"); + CPPUNIT_ASSERT(pRelsDoc); + + std::shared_ptr<SvStream> pStream = XPathHelper::parseExportStream(pXPathFile, m_xSFactory, "ddp/ddpfile.xen"); + CPPUNIT_ASSERT(pStream); +} + #if !defined _WIN32 void ScExportTest::testRelativePaths() { |