[Libreoffice-commits] core.git: 2 commits - svgio/CppunitTest_svgio.mk svgio/Module_svgio.mk svgio/qa svgio/source

Tomaž Vajngerl tomaz.vajngerl at collabora.com
Wed Apr 16 00:57:36 PDT 2014


 svgio/CppunitTest_svgio.mk                     |   68 +++++++++++++++++
 svgio/Module_svgio.mk                          |    4 +
 svgio/qa/cppunit/SvgImportTest.cxx             |   99 +++++++++++++++++++++++++
 svgio/qa/cppunit/data/Rect.svg                 |    4 +
 svgio/qa/cppunit/data/RectWithParentStyles.svg |   13 +++
 svgio/qa/cppunit/data/RectWithStyles.svg       |    4 +
 svgio/source/svgreader/svgstyleattributes.cxx  |   16 +---
 svgio/source/svgreader/svgsvgnode.cxx          |    3 
 8 files changed, 201 insertions(+), 10 deletions(-)

New commits:
commit 8c571e5f82a6d6e36bd47c7d2ab202f2f9b7cf86
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Wed Apr 16 09:51:27 2014 +0200

    svgio: introduce svg import tests
    
    Change-Id: Id69f659a9e4b0332970e75b1d0a7d820c8b2c998

diff --git a/svgio/CppunitTest_svgio.mk b/svgio/CppunitTest_svgio.mk
new file mode 100644
index 0000000..7fe8370
--- /dev/null
+++ b/svgio/CppunitTest_svgio.mk
@@ -0,0 +1,68 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,svgio_import_test))
+
+$(eval $(call gb_CppunitTest_set_include,svgio_import_test,\
+    $$(INCLUDE) \
+    -I$(SRCDIR)/svgio/inc \
+))
+
+$(eval $(call gb_CppunitTest_use_external,svgio_import_test,boost_headers))
+
+$(eval $(call gb_CppunitTest_use_api,svgio_import_test,\
+    offapi \
+    udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_library_objects,svgio_import_test,\
+    svgio \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,svgio_import_test,\
+    basegfx \
+    drawinglayer \
+    cppu \
+    cppuhelper \
+    comphelper \
+    sal \
+    sax \
+    svt \
+    test \
+    unotest \
+    tl \
+    vcl \
+	$(gb_UWINAPI) \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,svgio_import_test,\
+    svgio/qa/cppunit/SvgImportTest \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,svgio_import_test))
+
+$(eval $(call gb_CppunitTest_use_components,svgio_import_test,\
+    configmgr/source/configmgr \
+    dtrans/util/mcnttype \
+    framework/util/fwk \
+    i18npool/util/i18npool \
+    package/source/xstor/xstor \
+    package/util/package2 \
+    toolkit/util/tk \
+    sfx2/util/sfx \
+    ucb/source/core/ucb1 \
+    ucb/source/ucp/file/ucpfile1 \
+    unotools/util/utl \
+    svgio/svgio \
+    sax/source/expatwrap/expwrap \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,svgio_import_test))
+
+# vim: set noet sw=4 ts=4:
diff --git a/svgio/Module_svgio.mk b/svgio/Module_svgio.mk
index 8b827fc..29ef97d 100644
--- a/svgio/Module_svgio.mk
+++ b/svgio/Module_svgio.mk
@@ -22,4 +22,8 @@ $(eval $(call gb_Module_add_targets,svgio,\
     Library_svgio \
 ))
 
+$(eval $(call gb_Module_add_check_targets,svgio,\
+    CppunitTest_svgio \
+))
+
 # vim: set noet ts=4 sw=4:
diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx
new file mode 100644
index 0000000..4b42afd
--- /dev/null
+++ b/svgio/qa/cppunit/SvgImportTest.cxx
@@ -0,0 +1,99 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+#include <test/bootstrapfixture.hxx>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/seqstream.hxx>
+
+#include <com/sun/star/graphic/SvgTools.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/graphic/SvgTools.hpp>
+#include <com/sun/star/graphic/Primitive2DTools.hpp>
+#include <com/sun/star/graphic/XPrimitive2D.hpp>
+
+#include <boost/scoped_array.hpp>
+
+namespace
+{
+
+using namespace css::uno;
+using namespace css::io;
+using namespace css::graphic;
+
+class Test : public test::BootstrapFixture
+{
+    Reference<XComponentContext> mxContext;
+
+    void testStyles();
+
+    Primitive2DSequence parseSvg(const char* aSource);
+
+public:
+    virtual void setUp() SAL_OVERRIDE;
+    virtual void tearDown() SAL_OVERRIDE;
+
+    CPPUNIT_TEST_SUITE(Test);
+    CPPUNIT_TEST(testStyles);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+Primitive2DSequence Test::parseSvg(const char* aSource)
+{
+    const Reference<XSvgParser> xSvgParser = SvgTools::create(mxContext);
+
+    OUString aUrl  = getURLFromSrc(aSource);
+    OUString aPath = getPathFromSrc(aSource);
+
+    SvFileStream aFileStream(aUrl, STREAM_READ);
+    sal_Size nSize = aFileStream.remainingSize();
+    boost::scoped_array<sal_Int8> pBuffer(new sal_Int8[nSize + 1]);
+    aFileStream.Read(pBuffer.get(), nSize);
+    pBuffer[nSize] = 0;
+
+    Sequence<sal_Int8> aData(pBuffer.get(), nSize + 1);
+    Reference<XInputStream> aInputStream(new comphelper::SequenceInputStream(aData));
+
+    return xSvgParser->getDecomposition(aInputStream, aPath);
+}
+
+void Test::setUp()
+{
+    BootstrapFixture::setUp();
+
+    mxContext = Reference<XComponentContext>(comphelper::getProcessComponentContext());
+}
+
+void Test::tearDown()
+{
+    BootstrapFixture::tearDown();
+}
+
+void Test::testStyles()
+{
+    Primitive2DSequence maSequenceRect = parseSvg("/svgio/qa/cppunit/data/Rect.svg");
+    CPPUNIT_ASSERT_EQUAL(1, maSequenceRect.getLength());
+
+    Primitive2DSequence maSequenceRectWithStyle = parseSvg("/svgio/qa/cppunit/data/RectWithStyles.svg");
+    CPPUNIT_ASSERT_EQUAL(1, maSequenceRectWithStyle.getLength());
+
+    Primitive2DSequence maSequenceRectWithParentStyle = parseSvg("/svgio/qa/cppunit/data/RectWithParentStyles.svg");
+    CPPUNIT_ASSERT_EQUAL(1, maSequenceRectWithParentStyle.getLength());
+
+    // TODO: Test if the 3 sequences are equal..
+    //const Primitive2DReference xReference(maSequenceRect[0]);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Test);
+
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svgio/qa/cppunit/data/Rect.svg b/svgio/qa/cppunit/data/Rect.svg
new file mode 100644
index 0000000..7567cdf
--- /dev/null
+++ b/svgio/qa/cppunit/data/Rect.svg
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<svg width="120" height="120" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+   <rect x="10" y="10" width="100" height="100" rx="10" ry="10" stroke="#ff0000" fill="#00cc00" stroke-width="3" />
+</svg>
diff --git a/svgio/qa/cppunit/data/RectWithParentStyles.svg b/svgio/qa/cppunit/data/RectWithParentStyles.svg
new file mode 100644
index 0000000..a01ba3f
--- /dev/null
+++ b/svgio/qa/cppunit/data/RectWithParentStyles.svg
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<svg width="120" height="120" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+   <style type="text/css" >
+   <![CDATA[
+   svg
+      {
+         stroke: #ff0000;
+         fill:   #00cc00;
+      }
+   ]]>
+   </style>
+   <rect x="10" y="10" width="100" height="100" rx="10" ry="10" style="stroke-width: 3;" />
+</svg>
diff --git a/svgio/qa/cppunit/data/RectWithStyles.svg b/svgio/qa/cppunit/data/RectWithStyles.svg
new file mode 100644
index 0000000..b706849
--- /dev/null
+++ b/svgio/qa/cppunit/data/RectWithStyles.svg
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<svg width="120" height="120" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+   <rect x="10" y="10" width="100" height="100" rx="10" ry="10" style="stroke: #ff0000; fill: #00cc00; stroke-width: 3" />
+</svg>
commit 3b7472b284131c09d91b69f26d5d26d54648f939
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Wed Apr 16 09:40:29 2014 +0200

    fdo#74743 avoid infinite loop when gathering "svg" element styles
    
    Change-Id: Ifcfd0c64302b9174510e3d774607f5ca60173885

diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx
index 4e73888..9c080cd 100644
--- a/svgio/source/svgreader/svgstyleattributes.cxx
+++ b/svgio/source/svgreader/svgstyleattributes.cxx
@@ -205,17 +205,15 @@ namespace svgio
 
         const SvgStyleAttributes* SvgStyleAttributes::getParentStyle() const
         {
-            if(getCssStyleParent())
-            {
-                return getCssStyleParent();
-            }
+            const SvgStyleAttributes* pParentStyle = getCssStyleParent();
 
-            if(mrOwner.getParent())
-            {
-                return mrOwner.getParent()->getSvgStyleAttributes();
-            }
+            // no parent style set, check parent for its style attributes
+            if(pParentStyle == NULL && mrOwner.getParent() != NULL)
+               pParentStyle = mrOwner.getParent()->getSvgStyleAttributes();
 
-            return 0;
+            if (pParentStyle != this) // to prevent infinite loop
+                return pParentStyle;
+            return NULL;
         }
 
         void SvgStyleAttributes::add_text(
diff --git a/svgio/source/svgreader/svgsvgnode.cxx b/svgio/source/svgreader/svgsvgnode.cxx
index fef34ef..78e3ac9 100644
--- a/svgio/source/svgreader/svgsvgnode.cxx
+++ b/svgio/source/svgreader/svgsvgnode.cxx
@@ -60,7 +60,8 @@ namespace svgio
 
         const SvgStyleAttributes* SvgSvgNode::getSvgStyleAttributes() const
         {
-            return checkForCssStyle(OUString("svg"), maSvgStyleAttributes);
+            checkForCssStyle(OUString("svg"), maSvgStyleAttributes);
+            return maSvgStyleAttributes.getCssStyleParent();
         }
 
         void SvgSvgNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)


More information about the Libreoffice-commits mailing list