Kaydet (Commit) 4de1c022 authored tarafından Ashod Nakashian's avatar Ashod Nakashian Kaydeden (comit) Jan Holesovsky

oox: unit-tests for custom package preservation

Change-Id: I69d0d7d6bdc8804d0e56be19cd86a699200fc85f
Reviewed-on: https://gerrit.libreoffice.org/50855Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarJan Holesovsky <kendy@collabora.com>
üst e8ed3dfc
......@@ -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());
}
......
......@@ -47,6 +47,12 @@ namespace XPathHelper
SCQAHELPER_DLLPUBLIC xmlDocPtr parseExport(ScDocShell& rShell, uno::Reference< lang::XMultiServiceFactory> const & xSFactory,
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.
*
......
......@@ -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()
......
......@@ -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();
......
......@@ -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;
......
......@@ -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())));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment