[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - sd/qa

Marco Cecchetti (via logerrit) logerrit at kemper.freedesktop.org
Fri Jan 29 13:40:16 UTC 2021


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

New commits:
commit b7f26d40a8223ea02845b415a724f2a5d3e94022
Author:     Marco Cecchetti <marco.cecchetti at collabora.com>
AuthorDate: Tue Jan 26 09:36:44 2021 +0100
Commit:     Ashod Nakashian <ash at collabora.com>
CommitDate: Fri Jan 29 14:39:34 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>

diff --git a/sd/qa/unit/SVGExportTests.cxx b/sd/qa/unit/SVGExportTests.cxx
index ab9b55658f23..0933e9a29c8a 100644
--- a/sd/qa/unit/SVGExportTests.cxx
+++ b/sd/qa/unit/SVGExportTests.cxx
@@ -18,15 +18,37 @@
 
 #include <boost/preprocessor/stringize.hpp>
 
+#include <regex>
+
 #define MAKE_PATH_STRING( path ) BOOST_PP_STRINGIZE( path )
 #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
+{
+static bool isValidBitmapId(const OUString& sId)
+{
+    std::regex aRegEx("bitmap\\(\\d+\\)");
+    return std::regex_match(sId.toUtf8().getStr(), aRegEx);
+}
+
+static BitmapChecksum getBitmapChecksumFromId(const OUString& sId)
+{
+    sal_Int32 nStart = sId.indexOf("(") + 1;
+    sal_Int32 nCount = sId.indexOf(")") - nStart;
+    CPPUNIT_ASSERT(nStart > 0 && nCount > 0);
+    OUString sChecksum = sId.copy( nStart, nCount );
+    return sChecksum.toUInt64();
+}
+}
+
 class SdSVGFilterTest : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools
 {
     uno::Reference<lang::XComponent> mxComponent;
@@ -162,11 +184,75 @@ public:
         assertXPathContent(svgDoc, MAKE_PATH_STRING( /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");
+
+        xmlDocPtr 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");
+
+        xmlDocPtr 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