summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-02-26 07:46:09 -0500
committerJan Holesovsky <kendy@collabora.com>2018-03-07 14:54:58 +0100
commita8f92371317d0056212063d473bb518cfbdbf874 (patch)
treec21b763424ec533e5e7d37b071ed577d312419b8
parent54ac8cf00820ae17f25251f16989485f4271cbe7 (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>
-rw-r--r--include/unotools/tempfile.hxx2
-rw-r--r--sc/qa/unit/data/xlsx/customxml.xlsxbin0 -> 13282 bytes
-rw-r--r--sc/qa/unit/helper/xpath.cxx7
-rw-r--r--sc/qa/unit/helper/xpath.hxx6
-rw-r--r--sc/qa/unit/subsequent_export-test.cxx19
-rw-r--r--sd/qa/unit/data/pptx/customxml.pptxbin0 -> 44229 bytes
-rw-r--r--sd/qa/unit/export-tests-ooxml1.cxx23
-rw-r--r--sd/qa/unit/sdmodeltestbase.hxx21
-rw-r--r--sw/qa/extras/inc/swmodeltestbase.hxx21
-rw-r--r--unotools/source/ucbhelper/tempfile.cxx2
10 files changed, 88 insertions, 13 deletions
diff --git a/include/unotools/tempfile.hxx b/include/unotools/tempfile.hxx
index edb9c9f39498..84db772647da 100644
--- a/include/unotools/tempfile.hxx
+++ b/include/unotools/tempfile.hxx
@@ -87,7 +87,7 @@ public:
Returns the URL of the tempfile object.
If you want to have the system path file name, use the GetFileName() method of this object
*/
- OUString const & GetURL();
+ OUString const & GetURL() const;
/**
Returns the system path name of the tempfile in host notation
diff --git a/sc/qa/unit/data/xlsx/customxml.xlsx b/sc/qa/unit/data/xlsx/customxml.xlsx
new file mode 100644
index 000000000000..53619ae4af30
--- /dev/null
+++ b/sc/qa/unit/data/xlsx/customxml.xlsx
Binary files differ
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()
{
diff --git a/sd/qa/unit/data/pptx/customxml.pptx b/sd/qa/unit/data/pptx/customxml.pptx
new file mode 100644
index 000000000000..ca9e8fe70d8f
--- /dev/null
+++ b/sd/qa/unit/data/pptx/customxml.pptx
Binary files differ
diff --git a/sd/qa/unit/export-tests-ooxml1.cxx b/sd/qa/unit/export-tests-ooxml1.cxx
index 3daf058daa9c..9147c662c634 100644
--- a/sd/qa/unit/export-tests-ooxml1.cxx
+++ b/sd/qa/unit/export-tests-ooxml1.cxx
@@ -105,6 +105,7 @@ public:
void testBulletMarginAndIndentation();
void testParaMarginAndindentation();
void testTdf111884();
+ void testCustomXml();
CPPUNIT_TEST_SUITE(SdOOXMLExportTest1);
@@ -133,6 +134,7 @@ public:
CPPUNIT_TEST(testBulletMarginAndIndentation);
CPPUNIT_TEST(testParaMarginAndindentation);
CPPUNIT_TEST(testTdf111884);
+ CPPUNIT_TEST(testCustomXml);
CPPUNIT_TEST_SUITE_END();
@@ -806,6 +808,27 @@ void SdOOXMLExportTest1::testTdf111884()
xDocShRef->DoClose();
}
+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 943a5e9e55a8..c7712f838899 100644
--- a/sd/qa/unit/sdmodeltestbase.hxx
+++ b/sd/qa/unit/sdmodeltestbase.hxx
@@ -372,17 +372,22 @@ class SdModelTestBaseXML
{
public:
- xmlDocPtr parseExport(utl::TempFile & 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 5a4ad3ede655..32bf2f204805 100644
--- a/sw/qa/extras/inc/swmodeltestbase.hxx
+++ b/sw/qa/extras/inc/swmodeltestbase.hxx
@@ -748,12 +748,29 @@ protected:
return parseExportInternal( maTempFile.GetURL(), rStreamName );
}
- xmlDocPtr parseExportInternal( const OUString& url, const OUString& rStreamName )
+ /**
+ * Returns an xml stream of a an exported file.
+ * To be used when the exporter doesn't create zip archives, but single files
+ * (like Flat ODF Export)
+ */
+ xmlDocPtr parseExportedFile()
+ {
+ return parseXmlStream(maTempFile.GetStream(StreamMode::READ));
+ }
+
+ 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(maTempFile.GetURL(), RTL_TEXTENCODING_UTF8).getStr())));
diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx
index fa2cbf567436..36887580f070 100644
--- a/unotools/source/ucbhelper/tempfile.cxx
+++ b/unotools/source/ucbhelper/tempfile.cxx
@@ -398,7 +398,7 @@ OUString TempFile::GetFileName() const
return aTmp;
}
-OUString const & TempFile::GetURL()
+OUString const & TempFile::GetURL() const
{
assert(!aName.isEmpty() && "TempFile::GetURL failed: unit test is leaking temp files, add the ucpfile1 component!");
return aName;