diff options
author | Michael Stahl <mstahl@redhat.com> | 2016-01-11 11:02:01 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2016-01-11 11:22:25 +0100 |
commit | 7dbdd410daeb6f51127da511990e98e77c62cd83 (patch) | |
tree | 39e15424c3200e11f8b3bed2c78dea3fd3f64900 /sd/qa | |
parent | 00d1c2800c10d542673ab6f5a5baa26aa1cbb20e (diff) |
sd: enhance the OLE object test to also test the exported XML
Needs adding various helpers to be able to use XPath.
Change-Id: Ifa7b1e5434fb253430da2bfcc5d38ea347d437af
Diffstat (limited to 'sd/qa')
-rw-r--r-- | sd/qa/unit/export-tests.cxx | 99 | ||||
-rw-r--r-- | sd/qa/unit/sdmodeltestbase.hxx | 20 |
2 files changed, 109 insertions, 10 deletions
diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx index 3ddde53113b7..5b1daf594c96 100644 --- a/sd/qa/unit/export-tests.cxx +++ b/sd/qa/unit/export-tests.cxx @@ -9,6 +9,7 @@ #include <officecfg/Office/Common.hxx> #include "sdmodeltestbase.hxx" #include "Outliner.hxx" +#include <test/xmltesttools.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/propertysequence.hxx> #include <svl/stritem.hxx> @@ -40,6 +41,7 @@ #include <svx/xflclit.hxx> #include <animations/animationnodehelper.hxx> #include <unotools/mediadescriptor.hxx> +#include <unotools/ucbstreamhelper.hxx> #include <rtl/ustring.hxx> #include <com/sun/star/drawing/XDrawPage.hpp> @@ -64,6 +66,7 @@ #include <com/sun/star/frame/XStorable.hpp> #include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp> #include <com/sun/star/drawing/FillStyle.hpp> +#include <com/sun/star/packages/zip/ZipFileAccess.hpp> #include <com/sun/star/text/XTextField.hpp> #include <com/sun/star/text/WritingMode2.hpp> #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> @@ -99,7 +102,7 @@ CPPUNIT_NS_END using namespace css; using namespace css::animations; -class SdExportTest : public SdModelTestBase +class SdExportTest : public SdModelTestBase, public XmlTestTools { public: void testN821567(); @@ -187,6 +190,58 @@ public: CPPUNIT_TEST(testTdf92527); CPPUNIT_TEST_SUITE_END(); + + virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override + { + struct { char const * pPrefix; char const * pURI; } namespaces[] = + { + // ODF + { "draw", "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" }, + { "fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" }, + { "number", "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" }, + { "office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0" }, + { "style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0" }, + { "svg", "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" }, + { "table", "urn:oasis:names:tc:opendocument:xmlns:table:1.0" }, + { "text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0" }, + { "xlink", "http://www.w3c.org/1999/xlink" }, + // OOXML + { "ContentType", "http://schemas.openxmlformats.org/package/2006/content-types" }, + { "rels", "http://schemas.openxmlformats.org/package/2006/relationships" }, + { "mc", "http://schemas.openxmlformats.org/markup-compatibility/2006" }, + { "v", "urn:schemas-microsoft-com:vml" }, + { "a", "http://schemas.openxmlformats.org/drawingml/2006/main" }, + { "c", "http://schemas.openxmlformats.org/drawingml/2006/chart" }, + { "pic", "http://schemas.openxmlformats.org/drawingml/2006/picture" }, + { "wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" }, + { "p", "http://schemas.openxmlformats.org/presentationml/2006/main" }, + { "w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main" }, + { "wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape" }, + { "wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" }, + }; + for (size_t i = 0; i < SAL_N_ELEMENTS(namespaces); ++i) + { + xmlXPathRegisterNs(pXmlXPathCtx, + reinterpret_cast<xmlChar const *>(namespaces[i].pPrefix), + reinterpret_cast<xmlChar const *>(namespaces[i].pURI)); + } + } + + xmlDocPtr parseExport(utl::TempFile & rTempFile, OUString const& rStreamName) + { + 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)); + xmlDocPtr const pXmlDoc = parseXmlStream(pStream.get()); + pXmlDoc->name = reinterpret_cast<char *>(xmlStrdup( + reinterpret_cast<xmlChar const *>(OUStringToOString(url, RTL_TEXTENCODING_UTF8).getStr()))); + return pXmlDoc; + } }; void SdExportTest::testN821567() @@ -1036,10 +1091,29 @@ void SdExportTest::testBnc822341() { // Check import / export of embedded text document ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("sd/qa/unit/data/odp/bnc822341.odp"), ODP); - xDocShRef = saveAndReload( xDocShRef, PPTX ); + utl::TempFile tempFile1; + xDocShRef = saveAndReload( xDocShRef, PPTX, &tempFile1 ); // Export an LO specific ole object (imported from an ODP document) { + xmlDocPtr pXmlDocCT = parseExport(tempFile1, "[Content_Types].xml"); + assertXPath(pXmlDocCT, + "/ContentType:Types/ContentType:Override[@ContentType='application/vnd.openxmlformats-officedocument.wordprocessingml.document']", + "PartName", + "/ppt/embeddings/oleObject1.docx"); + + xmlDocPtr pXmlDocRels = parseExport(tempFile1, "ppt/slides/_rels/slide1.xml.rels"); + assertXPath(pXmlDocRels, + "/rels:Relationships/rels:Relationship[@Target='../embeddings/oleObject1.docx']", + "Type", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package"); + + xmlDocPtr pXmlDocContent = parseExport(tempFile1, "ppt/slides/slide1.xml"); + assertXPath(pXmlDocContent, + "/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData/p:oleObj", + "progId", + "Word.Document.12"); + const SdrPage *pPage = GetPage( 1, xDocShRef ); const SdrObject* pObj = dynamic_cast<SdrObject*>( pPage->GetObj(0) ); @@ -1047,10 +1121,29 @@ void SdExportTest::testBnc822341() CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(OBJ_OLE2), pObj->GetObjIdentifier() ); } - xDocShRef = saveAndReload( xDocShRef, PPTX ); + utl::TempFile tempFile2; + xDocShRef = saveAndReload( xDocShRef, PPTX, &tempFile2 ); // Export an MS specific ole object (imported from a PPTX document) { + xmlDocPtr pXmlDocCT = parseExport(tempFile2, "[Content_Types].xml"); + assertXPath(pXmlDocCT, + "/ContentType:Types/ContentType:Override[@ContentType='application/vnd.openxmlformats-officedocument.wordprocessingml.document']", + "PartName", + "/ppt/embeddings/oleObject1.docx"); + + xmlDocPtr pXmlDocRels = parseExport(tempFile2, "ppt/slides/_rels/slide1.xml.rels"); + assertXPath(pXmlDocRels, + "/rels:Relationships/rels:Relationship[@Target='../embeddings/oleObject1.docx']", + "Type", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package"); + + xmlDocPtr pXmlDocContent = parseExport(tempFile2, "ppt/slides/slide1.xml"); + assertXPath(pXmlDocContent, + "/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData/p:oleObj", + "progId", + "Word.Document.12"); + SdDrawDocument *pDoc = xDocShRef->GetDoc(); CPPUNIT_ASSERT_MESSAGE( "no document", pDoc != nullptr ); const SdrPage *pPage = pDoc->GetPage(1); diff --git a/sd/qa/unit/sdmodeltestbase.hxx b/sd/qa/unit/sdmodeltestbase.hxx index a9682bbeb1dc..4c465470c4ef 100644 --- a/sd/qa/unit/sdmodeltestbase.hxx +++ b/sd/qa/unit/sdmodeltestbase.hxx @@ -180,21 +180,27 @@ protected: pShell->DoClose(); } - sd::DrawDocShellRef saveAndReload(sd::DrawDocShell *pShell, sal_Int32 nExportType) + sd::DrawDocShellRef saveAndReload(sd::DrawDocShell *pShell, sal_Int32 nExportType, + utl::TempFile * pTempFile = nullptr) { FileFormat* pFormat = getFormat(nExportType); - utl::TempFile aTempFile; - save(pShell, pFormat, aTempFile); + std::unique_ptr<utl::TempFile> pNewTempFile; + if (!pTempFile) + { + pNewTempFile.reset(new utl::TempFile); + pTempFile = pNewTempFile.get(); + } + save(pShell, pFormat, *pTempFile); if(nExportType == ODP) { - // BootstrapFixture::validate(aTempFile.GetFileName(), test::ODF); + // BootstrapFixture::validate(pTempFile->GetFileName(), test::ODF); } else if(nExportType == PPTX) { - BootstrapFixture::validate(aTempFile.GetFileName(), test::OOXML); + BootstrapFixture::validate(pTempFile->GetFileName(), test::OOXML); } - aTempFile.EnableKillingFile(); - return loadURL(aTempFile.GetURL(), nExportType); + pTempFile->EnableKillingFile(); + return loadURL(pTempFile->GetURL(), nExportType); } /** Dump shapes in xDocShRef, and compare the dump against content of pShapesDumpFileNameBase<number>.xml. |