[Libreoffice-commits] core.git: sd/qa

Marco Cecchetti (via logerrit) logerrit at kemper.freedesktop.org
Mon Mar 8 08:51:55 UTC 2021


 sd/qa/unit/SVGExportTests.cxx                   |   87 ++++++++++++++++++++++++
 sd/qa/unit/data/odp/slide-bitmap-background.odp |binary
 sd/qa/unit/data/odp/slide-tile-background.odp   |binary
 3 files changed, 87 insertions(+)

New commits:
commit c6abdc690075d7a627a62d04113a4fa911f90b00
Author:     Marco Cecchetti <marco.cecchetti at collabora.com>
AuthorDate: Tue Jan 26 09:36:44 2021 +0100
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Mon Mar 8 09:51:08 2021 +0100

    filter: svg: js engine: unit test: slide background: exporting bitmaps
    
    Two unit tests:
    1 - a slide background with a single bitmap
    2 - a slide background with bitmap tiles
    
    Change-Id: Iffdb9ea958ba07391dfbdcfd6e925a9461e2af84
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109932
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Ashod Nakashian <ash at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111843
    Tested-by: Jenkins
    Reviewed-by: Andras Timar <andras.timar at collabora.com>

diff --git a/sd/qa/unit/SVGExportTests.cxx b/sd/qa/unit/SVGExportTests.cxx
index 48ed7c78af4e..107c698afb68 100644
--- a/sd/qa/unit/SVGExportTests.cxx
+++ b/sd/qa/unit/SVGExportTests.cxx
@@ -21,14 +21,37 @@
 #include <com/sun/star/frame/Desktop.hpp>
 #include <comphelper/processfactory.hxx>
 
+#include <regex>
+
 #define SVG_SVG  *[name()='svg']
 #define SVG_G *[name()='g']
 #define SVG_TEXT *[name()='text']
 #define SVG_TSPAN *[name()='tspan']
 #define SVG_DEFS *[name()='defs']
+#define SVG_IMAGE *[name()='image']
+#define SVG_USE *[name()='use']
 
 using namespace css;
 
+namespace
+{
+bool isValidBitmapId(const OUString& sId)
+{
+    std::regex aRegEx("bitmap\\(\\d+\\)");
+    return std::regex_match(sId.toUtf8().getStr(), aRegEx);
+}
+
+BitmapChecksum getBitmapChecksumFromId(const OUString& sId)
+{
+    sal_Int32 nStart = sId.indexOf("(") + 1;
+    sal_Int32 nCount = sId.indexOf(")") - nStart;
+    bool bIsValidRange = nStart > 0 && nCount > 0;
+    CPPUNIT_ASSERT(bIsValidRange);
+    OUString sChecksum = sId.copy( nStart, nCount );
+    return sChecksum.toUInt64();
+}
+}
+
 class SdSVGFilterTest : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools
 {
     uno::Reference<lang::XComponent> mxComponent;
@@ -164,11 +187,75 @@ public:
         assertXPathContent(svgDoc, SAL_STRINGIFY( /SVG_SVG/SVG_DEFS[9]/SVG_G[2]/SVG_G[2]/SVG_G[7]/SVG_G/SVG_TEXT/SVG_TSPAN/SVG_TSPAN/SVG_TSPAN ), "<number>");
     }
 
+    void testSVGExportSlideBitmapBackground()
+    {
+        executeExport("slide-bitmap-background.odp");
+
+        xmlDocUniquePtr svgDoc = parseXml(maTempFile);
+        CPPUNIT_ASSERT(svgDoc);
+
+        assertXPath(svgDoc, SAL_STRINGIFY( /SVG_SVG/SVG_DEFS[9] ), "class", "BackgroundBitmaps");
+        assertXPath(svgDoc, SAL_STRINGIFY( /SVG_SVG/SVG_DEFS[9]/SVG_IMAGE ), 1);
+
+        OUString sImageId = getXPath(svgDoc, SAL_STRINGIFY( /SVG_SVG/SVG_DEFS[9]/SVG_IMAGE ), "id");
+        CPPUNIT_ASSERT_MESSAGE(OString("The exported bitmap has not a valid id: " + sImageId.toUtf8()).getStr(), isValidBitmapId(sImageId));
+
+        BitmapChecksum nChecksum = getBitmapChecksumFromId(sImageId);
+        CPPUNIT_ASSERT_MESSAGE(OString("The exported bitmap has not a valid checksum: " + sImageId.toUtf8()).getStr(), nChecksum != 0);
+
+        // single image case
+        assertXPath(svgDoc, SAL_STRINGIFY( /SVG_SVG/SVG_G[2]/SVG_G[1]/SVG_G/SVG_G/SVG_G/SVG_DEFS ), "class", "SlideBackground");
+        assertXPath(svgDoc, SAL_STRINGIFY( /SVG_SVG/SVG_G[2]/SVG_G[1]/SVG_G/SVG_G/SVG_G/SVG_DEFS/SVG_G/SVG_G/SVG_USE ), 1);
+        OUString sRef = getXPath(svgDoc, SAL_STRINGIFY( /SVG_SVG/SVG_G[2]/SVG_G[1]/SVG_G/SVG_G/SVG_G/SVG_DEFS/SVG_G/SVG_G/SVG_USE ), "href");
+        CPPUNIT_ASSERT_MESSAGE("The <use> element has not a valid href attribute: starting '#' not present.", sRef.startsWith("#"));
+        sRef = sRef.copy(1);
+        CPPUNIT_ASSERT_MESSAGE(OString("The <use> element does not point to a valid bitmap id: " + sRef.toUtf8()).getStr(), isValidBitmapId(sRef));
+
+        BitmapChecksum nUseChecksum = getBitmapChecksumFromId(sRef);
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("The bitmap checksum used in <use> does not match the expected one: ", nChecksum, nUseChecksum);
+    }
+
+    void testSVGExportSlideTileBitmapBackground()
+    {
+        executeExport("slide-tile-background.odp");
+
+        xmlDocUniquePtr svgDoc = parseXml(maTempFile);
+        CPPUNIT_ASSERT(svgDoc);
+
+        assertXPath(svgDoc, SAL_STRINGIFY( /SVG_SVG/SVG_DEFS[9] ), "class", "BackgroundBitmaps");
+        assertXPath(svgDoc, SAL_STRINGIFY( /SVG_SVG/SVG_DEFS[9]/SVG_IMAGE ), 1);
+
+        OUString sImageId = getXPath(svgDoc, SAL_STRINGIFY( /SVG_SVG/SVG_DEFS[9]/SVG_IMAGE ), "id");
+        CPPUNIT_ASSERT_MESSAGE(OString("The exported bitmap has not a valid id: " + sImageId.toUtf8()).getStr(), isValidBitmapId(sImageId));
+
+        BitmapChecksum nChecksum = getBitmapChecksumFromId(sImageId);
+        CPPUNIT_ASSERT_MESSAGE(OString("The exported bitmap has not a valid checksum: " + sImageId.toUtf8()).getStr(), nChecksum != 0);
+
+        // tiles case
+        constexpr unsigned int nNumberOfTiles = 37;
+        assertXPath(svgDoc, SAL_STRINGIFY( /SVG_SVG/SVG_G[2]/SVG_G[1]/SVG_G/SVG_G/SVG_G/SVG_DEFS ), "class", "SlideBackground");
+        assertXPath(svgDoc, SAL_STRINGIFY( /SVG_SVG/SVG_G[2]/SVG_G[1]/SVG_G/SVG_G/SVG_G/SVG_DEFS/SVG_G/SVG_G/SVG_USE ), nNumberOfTiles);
+
+        for (unsigned int i = 1; i <= nNumberOfTiles; ++i)
+        {
+            OString sIndex = OStringLiteral("[") + OString::number(i) + OStringLiteral("]");
+            OUString sRef = getXPath(svgDoc, SAL_STRINGIFY( /SVG_SVG/SVG_G[2]/SVG_G[1]/SVG_G/SVG_G/SVG_G/SVG_DEFS/SVG_G/SVG_G/SVG_USE ) + sIndex, "href");
+            CPPUNIT_ASSERT_MESSAGE("The <use> element has not a valid href attribute: starting '#' not present.", sRef.startsWith("#"));
+            sRef = sRef.copy(1);
+            CPPUNIT_ASSERT_MESSAGE(OString("The <use> element does not point to a valid bitmap id: " + sRef.toUtf8()).getStr(), isValidBitmapId(sRef));
+
+            BitmapChecksum nUseChecksum = getBitmapChecksumFromId(sRef);
+            CPPUNIT_ASSERT_EQUAL_MESSAGE("The bitmap checksum used in <use> does not match the expected one: ", nChecksum, nUseChecksum);
+        }
+    }
+
     CPPUNIT_TEST_SUITE(SdSVGFilterTest);
     CPPUNIT_TEST(testSVGExportTextDecorations);
     CPPUNIT_TEST(testSVGExportJavascriptURL);
     CPPUNIT_TEST(testSVGExportSlideCustomBackground);
     CPPUNIT_TEST(testSVGExportTextFieldsInMasterPage);
+    CPPUNIT_TEST(testSVGExportSlideBitmapBackground);
+    CPPUNIT_TEST(testSVGExportSlideTileBitmapBackground);
     CPPUNIT_TEST_SUITE_END();
 };
 
diff --git a/sd/qa/unit/data/odp/slide-bitmap-background.odp b/sd/qa/unit/data/odp/slide-bitmap-background.odp
new file mode 100644
index 000000000000..46ea62be5a3a
Binary files /dev/null and b/sd/qa/unit/data/odp/slide-bitmap-background.odp differ
diff --git a/sd/qa/unit/data/odp/slide-tile-background.odp b/sd/qa/unit/data/odp/slide-tile-background.odp
new file mode 100644
index 000000000000..d926b555f457
Binary files /dev/null and b/sd/qa/unit/data/odp/slide-tile-background.odp differ


More information about the Libreoffice-commits mailing list