[Libreoffice-commits] core.git: filter/source include/test test/source writerperfect/qa

Miklos Vajna vmiklos at collabora.co.uk
Mon Feb 12 20:50:43 UTC 2018


 filter/source/svg/svgexport.cxx          |    2 ++
 include/test/xmltesttools.hxx            |    5 +++++
 test/source/xmltesttools.cxx             |   27 +++++++++++++++++++++++++++
 writerperfect/qa/unit/EPUBExportTest.cxx |    5 +++++
 4 files changed, 39 insertions(+)

New commits:
commit f8da775795052ad2eb879970c115d2e2a2fe8c81
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Feb 12 17:53:48 2018 +0100

    EPUB export, fixed layout: fix validation error with images
    
    The "xlink" prefix for the "xlink:href" attribute on the "image" element
    was not bound.
    
    Change-Id: I473a0b1612b4842cf84a264960bb28a9f19600e5
    Reviewed-on: https://gerrit.libreoffice.org/49612
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/filter/source/svg/svgexport.cxx b/filter/source/svg/svgexport.cxx
index c1d25b82b1a6..7f08357a80ae 100644
--- a/filter/source/svg/svgexport.cxx
+++ b/filter/source/svg/svgexport.cxx
@@ -2333,6 +2333,8 @@ void SVGExport::writeMtf( const GDIMetaFile& rMtf )
          AddAttribute( XML_NAMESPACE_NONE, "baseProfile", "tiny" );
 
     AddAttribute( XML_NAMESPACE_NONE, "xmlns", constSvgNamespace );
+    // For <image xlink:href="...">.
+    AddAttribute(XML_NAMESPACE_XMLNS, "xlink", "http://www.w3.org/1999/xlink");
     AddAttribute( XML_NAMESPACE_NONE, "stroke-width", OUString::number( 28.222 ) );
     AddAttribute( XML_NAMESPACE_NONE, "stroke-linejoin", "round" );
     AddAttribute( XML_NAMESPACE_NONE, "xml:space", "preserve" );
diff --git a/include/test/xmltesttools.hxx b/include/test/xmltesttools.hxx
index bfcaf91cdd6d..eba5c84a0644 100644
--- a/include/test/xmltesttools.hxx
+++ b/include/test/xmltesttools.hxx
@@ -76,6 +76,11 @@ protected:
      */
     void          assertXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString& rContent);
     /**
+     * Assert that rXPath exists and it has an rNSPrefix=rNSHref namespace definition.
+     */
+    void assertXPathNSDef(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString& rNSPrefix,
+                          const OUString& rNSHref);
+    /**
      * Assert that rXPath exists, and has exactly nNumberOfChildNodes child nodes.
      * Useful for checking that we do have a no child nodes to a specific node (nNumberOfChildNodes == 0).
      */
diff --git a/test/source/xmltesttools.cxx b/test/source/xmltesttools.cxx
index 5d476c46a5ec..45347b0c111b 100644
--- a/test/source/xmltesttools.cxx
+++ b/test/source/xmltesttools.cxx
@@ -123,6 +123,33 @@ void XmlTestTools::assertXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath,
     CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("In <" + OString(pXmlDoc->name) + ">, XPath contents of child does not match").getStr(), rContent, getXPathContent(pXmlDoc, rXPath));
 }
 
+void XmlTestTools::assertXPathNSDef(xmlDocPtr pXmlDoc, const OString& rXPath,
+                                    const OUString& rNSPrefix, const OUString& rNSHref)
+{
+    xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath);
+    xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
+    CPPUNIT_ASSERT_MESSAGE(
+        OString("In <" + OString(pXmlDoc->name) + ">, XPath '" + rXPath + "' not found").getStr(),
+        xmlXPathNodeSetGetLength(pXmlNodes) > 0);
+
+    xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
+    bool bFound = false;
+    for (xmlNsPtr pNamespace = pXmlNode->nsDef; pNamespace; pNamespace = pNamespace->next)
+    {
+        if (!pNamespace->prefix)
+            continue;
+
+        CPPUNIT_ASSERT(pNamespace->href);
+        if (rNSPrefix == convert(pNamespace->prefix) && rNSHref == convert(pNamespace->href))
+        {
+            bFound = true;
+            break;
+        }
+    }
+    xmlXPathFreeObject(pXmlObj);
+    CPPUNIT_ASSERT(bFound);
+}
+
 void XmlTestTools::assertXPathChildren(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfChildNodes)
 {
 #if LIBXML_VERSION >= 20703 /* xmlChildElementCount is only available in libxml2 >= 2.7.3 */
diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx
index 47e84ebf1bbc..81d70591a0da 100644
--- a/writerperfect/qa/unit/EPUBExportTest.cxx
+++ b/writerperfect/qa/unit/EPUBExportTest.cxx
@@ -874,6 +874,11 @@ void EPUBExportTest::testSVG()
     // one, causing a validation error.
     OString aActual(static_cast<const char *>(aMemoryStream.GetBuffer()), aExpected.getLength());
     CPPUNIT_ASSERT_EQUAL(aExpected, aActual);
+
+    // This failed, we used the xlink attribute namespace, but we did not
+    // define its URL.
+    mpXmlDoc = parseExport("OEBPS/images/image0001.svg");
+    assertXPathNSDef(mpXmlDoc, "/svg:svg", "xlink", "http://www.w3.org/1999/xlink");
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(EPUBExportTest);


More information about the Libreoffice-commits mailing list