[Libreoffice-commits] core.git: 3 commits - include/oox oox/source sd/CppunitTest_sd_export_tests.mk sd/qa

Michael Stahl mstahl at redhat.com
Mon Jan 11 02:24:43 PST 2016


 include/oox/export/shapes.hxx     |    2 
 oox/source/export/shapes.cxx      |    6 --
 sd/CppunitTest_sd_export_tests.mk |    5 +
 sd/qa/unit/export-tests.cxx       |  107 ++++++++++++++++++++++++++++++++++----
 sd/qa/unit/sdmodeltestbase.hxx    |   20 ++++---
 5 files changed, 116 insertions(+), 24 deletions(-)

New commits:
commit 92266dd8267481b654efd0dd76f1d145f9dc9e18
Author: Michael Stahl <mstahl at redhat.com>
Date:   Mon Jan 11 11:03:18 2016 +0100

    sd: with any luck the OLE test should run on WNT now too
    
    ... with the new implementation in oox.
    
    Change-Id: I65aca6e4151ad7383d45c60430132a45ae3a001e

diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx
index 5b1daf5..102a3f4 100644
--- a/sd/qa/unit/export-tests.cxx
+++ b/sd/qa/unit/export-tests.cxx
@@ -140,9 +140,7 @@ public:
 
     void testFdo90607();
     void testTdf91378();
-#if !defined WNT
     void testBnc822341();
-#endif
     void testTdf80224();
     void testTdf92527();
 
@@ -181,9 +179,7 @@ public:
     CPPUNIT_TEST(testTransparentBackground);
     CPPUNIT_TEST(testTdf91378);
 
-#if !defined WNT
     CPPUNIT_TEST(testBnc822341);
-#endif
     CPPUNIT_TEST(testTdf80224);
 
     CPPUNIT_TEST(testExportTransitionsPPTX);
@@ -1085,8 +1081,6 @@ void SdExportTest::testTdf91378()
     xDocShRef->DoClose();
 }
 
-#if !defined WNT
-
 void SdExportTest::testBnc822341()
 {
     // Check import / export of embedded text document
@@ -1157,8 +1151,6 @@ void SdExportTest::testBnc822341()
     xDocShRef->DoClose();
 }
 
-#endif
-
 void SdExportTest::testBulletMarginAndIndentation()
 {
     ::sd::DrawDocShellRef xDocShRef = loadURL( getURLFromSrc("/sd/qa/unit/data/pptx/bulletMarginAndIndent.pptx"), PPTX );
commit 7dbdd410daeb6f51127da511990e98e77c62cd83
Author: Michael Stahl <mstahl at redhat.com>
Date:   Mon Jan 11 11:02:01 2016 +0100

    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

diff --git a/sd/CppunitTest_sd_export_tests.mk b/sd/CppunitTest_sd_export_tests.mk
index 3384377..5e5bafd 100644
--- a/sd/CppunitTest_sd_export_tests.mk
+++ b/sd/CppunitTest_sd_export_tests.mk
@@ -11,7 +11,10 @@
 
 $(eval $(call gb_CppunitTest_CppunitTest,sd_export_tests))
 
-$(eval $(call gb_CppunitTest_use_external,sd_export_tests,boost_headers))
+$(eval $(call gb_CppunitTest_use_externals,sd_export_tests,\
+	boost_headers \
+	libxml2 \
+))
 
 $(eval $(call gb_CppunitTest_add_exception_objects,sd_export_tests, \
     sd/qa/unit/export-tests \
diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx
index 3ddde53..5b1daf5 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 a9682bb..4c46547 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.
commit 00d1c2800c10d542673ab6f5a5baa26aa1cbb20e
Author: Michael Stahl <mstahl at redhat.com>
Date:   Mon Jan 11 10:59:17 2016 +0100

    oox: deterministic oleObject stream numbering
    
    ... like in sw.
    
    Change-Id: I4ba5d404c4160e907330832b7710c1d96430badf

diff --git a/include/oox/export/shapes.hxx b/include/oox/export/shapes.hxx
index 3269df1..29f597f 100644
--- a/include/oox/export/shapes.hxx
+++ b/include/oox/export/shapes.hxx
@@ -69,7 +69,7 @@ public:
 class OOX_DLLPUBLIC ShapeExport : public DrawingML {
 
 private:
-    static int mnEmbeddeDocumentCounter;
+    int m_nEmbeddedObjects;
     struct ShapeCheck
     {
         bool operator()( const css::uno::Reference< css::drawing::XShape>& s1, const css::uno::Reference< css::drawing::XShape>& s2 ) const
diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index 95d1d77..654b11f 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -359,11 +359,9 @@ bool URLTransformer::isExternalURL(const OUString& /*rURL*/) const
     if ( GETA(propName) ) \
         mAny >>= variable;
 
-// not thread safe
-int ShapeExport::mnEmbeddeDocumentCounter = 1;
-
 ShapeExport::ShapeExport( sal_Int32 nXmlNamespace, FSHelperPtr pFS, ShapeHashMap* pShapeMap, XmlFilterBase* pFB, DocumentType eDocumentType, DMLTextExport* pTextExport )
     : DrawingML( pFS, pFB, eDocumentType, pTextExport )
+    , m_nEmbeddedObjects(0)
     , mnShapeIdMax( 1 )
     , mnPictureIdMax( 1 )
     , mnXmlNamespace( nXmlNamespace )
@@ -1683,7 +1681,7 @@ ShapeExport& ShapeExport::WriteOLE2Shape( Reference< XShape > xShape )
     assert(!sRelationType.isEmpty());
     assert(!sSuffix.isEmpty());
 
-    OUString sFileName = "embeddings/oleObject" + OUString::number(mnEmbeddeDocumentCounter++) + "." + sSuffix;
+    OUString sFileName = "embeddings/oleObject" + OUString::number(++m_nEmbeddedObjects) + "." + sSuffix;
     uno::Reference<io::XOutputStream> const xOutStream(
         mpFB->openFragmentStream(
             OUString::createFromAscii(GetComponentDir()) + "/" + sFileName,


More information about the Libreoffice-commits mailing list