[Libreoffice-commits] core.git: sc/qa sd/qa sw/qa
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Thu Mar 8 11:40:25 UTC 2018
sc/qa/unit/data/xlsx/customxml.xlsx |binary
sc/qa/unit/helper/xpath.cxx | 7 ++++++-
sc/qa/unit/helper/xpath.hxx | 6 ++++++
sc/qa/unit/subsequent_export-test.cxx | 17 +++++++++++++++++
sd/qa/unit/data/pptx/customxml.pptx |binary
sd/qa/unit/export-tests-ooxml1.cxx | 23 +++++++++++++++++++++++
sd/qa/unit/sdmodeltestbase.hxx | 21 +++++++++++++--------
sw/qa/extras/inc/swmodeltestbase.hxx | 11 +++++++++--
8 files changed, 74 insertions(+), 11 deletions(-)
New commits:
commit 4de1c0223ceb76556ff1c20000b4ea95bfc1d2a0
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Mon Feb 26 07:46:09 2018 -0500
oox: unit-tests for custom package preservation
Change-Id: I69d0d7d6bdc8804d0e56be19cd86a699200fc85f
Reviewed-on: https://gerrit.libreoffice.org/50855
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Jan Holesovsky <kendy at collabora.com>
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
Binary files /dev/null and b/sc/qa/unit/data/xlsx/customxml.xlsx 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 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
new file mode 100644
index 000000000000..ca9e8fe70d8f
Binary files /dev/null and b/sd/qa/unit/data/pptx/customxml.pptx differ
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())));
More information about the Libreoffice-commits
mailing list