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-08 12:39:50 +0100 |
commit | 4de1c0223ceb76556ff1c20000b4ea95bfc1d2a0 (patch) | |
tree | 3ffb0a340aa2b643ba8792418c9e7fe895b87eb2 | |
parent | e8ed3dfc35975b9e57da7803168f3e2a117a4004 (diff) |
oox: unit-tests for custom package preservation
Change-Id: I69d0d7d6bdc8804d0e56be19cd86a699200fc85f
Reviewed-on: https://gerrit.libreoffice.org/50855
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
-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 | 17 | ||||
-rw-r--r-- | sd/qa/unit/data/pptx/customxml.pptx | bin | 0 -> 44229 bytes | |||
-rw-r--r-- | sd/qa/unit/export-tests-ooxml1.cxx | 23 | ||||
-rw-r--r-- | sd/qa/unit/sdmodeltestbase.hxx | 21 | ||||
-rw-r--r-- | sw/qa/extras/inc/swmodeltestbase.hxx | 11 |
8 files changed, 74 insertions, 11 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 6f8c8aa3c170..ddffd31a4585 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 44831588ee0a..595e563dc301 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -162,6 +162,7 @@ public: void testCeilingFloorXLS(); void testCeilingFloorODS(); + void testCustomXml(); #if !defined _WIN32 void testRelativePathsODS(); @@ -268,6 +269,7 @@ public: CPPUNIT_TEST(testCeilingFloorODSToXLSX); CPPUNIT_TEST(testCeilingFloorXLS); CPPUNIT_TEST(testCeilingFloorODS); + CPPUNIT_TEST(testCustomXml); #if !defined(_WIN32) CPPUNIT_TEST(testRelativePathsODS); #endif @@ -3041,6 +3043,21 @@ 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::testRelativePathsODS() diff --git a/sd/qa/unit/data/pptx/customxml.pptx b/sd/qa/unit/data/pptx/customxml.pptx Binary files differnew file mode 100644 index 000000000000..ca9e8fe70d8f --- /dev/null +++ b/sd/qa/unit/data/pptx/customxml.pptx diff --git a/sd/qa/unit/export-tests-ooxml1.cxx b/sd/qa/unit/export-tests-ooxml1.cxx index 364595ca0a71..2ccc48982727 100644 --- a/sd/qa/unit/export-tests-ooxml1.cxx +++ b/sd/qa/unit/export-tests-ooxml1.cxx @@ -101,6 +101,7 @@ public: void testParaMarginAndindentation(); void testTdf111884(); void testTdf112633(); + void testCustomXml(); CPPUNIT_TEST_SUITE(SdOOXMLExportTest1); @@ -130,6 +131,7 @@ public: CPPUNIT_TEST(testParaMarginAndindentation); CPPUNIT_TEST(testTdf111884); CPPUNIT_TEST(testTdf112633); + CPPUNIT_TEST(testCustomXml); CPPUNIT_TEST_SUITE_END(); @@ -831,6 +833,27 @@ void SdOOXMLExportTest1::testTdf112633() CPPUNIT_ASSERT_EQUAL(true, bool(xNameAccess->hasByName("ppt/media/hdphoto1.wdp"))); } +void SdOOXMLExportTest1::testCustomXml() +{ + // Load document and export it to a temporary file + ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/pptx/customxml.pptx"), PPTX); + utl::TempFile tempFile; + xDocShRef = saveAndReload(xDocShRef.get(), PPTX, &tempFile); + xDocShRef->DoClose(); + + xmlDocPtr pXmlDoc = parseExport(tempFile, "customXml/item1.xml"); + CPPUNIT_ASSERT(pXmlDoc); + xmlDocPtr pRelsDoc = parseExport(tempFile, "customXml/_rels/item1.xml.rels"); + CPPUNIT_ASSERT(pRelsDoc); + + // Check there is a relation to itemProps1.xml. + const OUString sXmlPath = "/rels:Relationships/rels:Relationship[@Id='rId1']"; + assertXPath(pRelsDoc, OUStringToOString(sXmlPath, RTL_TEXTENCODING_UTF8), "Target", "itemProps1.xml"); + + std::shared_ptr<SvStream> pStream = parseExportStream(tempFile, "ddp/ddpfile.xen"); + CPPUNIT_ASSERT(pStream); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SdOOXMLExportTest1); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sd/qa/unit/sdmodeltestbase.hxx b/sd/qa/unit/sdmodeltestbase.hxx index 3662bf373d2a..512e945cad86 100644 --- a/sd/qa/unit/sdmodeltestbase.hxx +++ b/sd/qa/unit/sdmodeltestbase.hxx @@ -377,17 +377,22 @@ class SdModelTestBaseXML { public: - xmlDocPtr parseExport(utl::TempFile const & rTempFile, OUString const& rStreamName) + std::shared_ptr<SvStream> parseExportStream(utl::TempFile const & rTempFile, const OUString& rStreamName) { + // Read the stream we're interested in. OUString const url(rTempFile.GetURL()); - uno::Reference<packages::zip::XZipFileAccess2> const xZipNames( - packages::zip::ZipFileAccess::createWithURL( - comphelper::getComponentContext(m_xSFactory), url)); - uno::Reference<io::XInputStream> const xInputStream( - xZipNames->getByName(rStreamName), uno::UNO_QUERY); - std::unique_ptr<SvStream> const pStream( - utl::UcbStreamHelper::CreateStream(xInputStream, true)); + uno::Reference<packages::zip::XZipFileAccess2> const xZipNames(packages::zip::ZipFileAccess::createWithURL( + comphelper::getComponentContext(m_xSFactory), url)); + uno::Reference<io::XInputStream> const xInputStream(xZipNames->getByName(rStreamName), uno::UNO_QUERY); + std::shared_ptr<SvStream> const pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); + return pStream; + } + + xmlDocPtr parseExport(utl::TempFile const & rTempFile, OUString const& rStreamName) + { + std::shared_ptr<SvStream> const pStream(parseExportStream(rTempFile, rStreamName)); xmlDocPtr const pXmlDoc = parseXmlStream(pStream.get()); + OUString const url(rTempFile.GetURL()); pXmlDoc->name = reinterpret_cast<char *>(xmlStrdup( reinterpret_cast<xmlChar const *>(OUStringToOString(url, RTL_TEXTENCODING_UTF8).getStr()))); return pXmlDoc; diff --git a/sw/qa/extras/inc/swmodeltestbase.hxx b/sw/qa/extras/inc/swmodeltestbase.hxx index 1d1529b1aa63..1ac89119a6b4 100644 --- a/sw/qa/extras/inc/swmodeltestbase.hxx +++ b/sw/qa/extras/inc/swmodeltestbase.hxx @@ -829,12 +829,19 @@ protected: return parseXmlStream(maTempFile.GetStream(StreamMode::READ)); } - xmlDocPtr parseExportInternal( const OUString& url, const OUString& rStreamName ) + std::shared_ptr<SvStream> parseExportStream(const OUString& url, const OUString& rStreamName) { - // Read the XML stream we're interested in. + // Read the stream we're interested in. uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), url); uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName(rStreamName), uno::UNO_QUERY); + CPPUNIT_ASSERT(xInputStream.is()); std::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); + return pStream; + } + + xmlDocPtr parseExportInternal(const OUString& url, const OUString& rStreamName) + { + std::shared_ptr<SvStream> pStream(parseExportStream(url, rStreamName)); xmlDocPtr pXmlDoc = parseXmlStream(pStream.get()); pXmlDoc->name = reinterpret_cast<char *>(xmlStrdup(reinterpret_cast<xmlChar const *>(OUStringToOString(url, RTL_TEXTENCODING_UTF8).getStr()))); |