diff options
author | Marco Cecchetti <marco.cecchetti@collabora.com> | 2021-01-26 09:36:44 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2021-03-08 09:51:08 +0100 |
commit | c6abdc690075d7a627a62d04113a4fa911f90b00 (patch) | |
tree | 0c97975ef4704b74a288aa273031939fa798ea21 | |
parent | e7a471a8fbac22877973af7e7be8c6a0701b4046 (diff) |
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@gmail.com>
Reviewed-by: Ashod Nakashian <ash@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111843
Tested-by: Jenkins
Reviewed-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r-- | sd/qa/unit/SVGExportTests.cxx | 87 | ||||
-rw-r--r-- | sd/qa/unit/data/odp/slide-bitmap-background.odp | bin | 0 -> 82326 bytes | |||
-rw-r--r-- | sd/qa/unit/data/odp/slide-tile-background.odp | bin | 0 -> 95650 bytes |
3 files changed, 87 insertions, 0 deletions
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 Binary files differnew file mode 100644 index 000000000000..46ea62be5a3a --- /dev/null +++ b/sd/qa/unit/data/odp/slide-bitmap-background.odp diff --git a/sd/qa/unit/data/odp/slide-tile-background.odp b/sd/qa/unit/data/odp/slide-tile-background.odp Binary files differnew file mode 100644 index 000000000000..d926b555f457 --- /dev/null +++ b/sd/qa/unit/data/odp/slide-tile-background.odp |