summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2022-07-20 22:01:31 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2022-07-27 16:48:14 +0200
commit2bfad80805c248b47d099c1707ce4f1926867b82 (patch)
tree9fd3033fbbb3696698665ed1906e693ed3b0a245
parentrelated: tdf#97539: SVGIO: iterate over parent's clippaths (diff)
downloadcore-2bfad80805c248b47d099c1707ce4f1926867b82.tar.gz
core-2bfad80805c248b47d099c1707ce4f1926867b82.zip
tdf#123983 fix loading graphic that is in root folder + test
We need to detect that the storage name is empty, so in that case the root storage needs to be set as the current storage. Change-Id: Ibe3287ccf1f1513a3531dcf4d540a456cca8dfb1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137276 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit d449da36086409e3cc440036193c4fc8a10a37a1) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137424 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org> Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137469
-rw-r--r--svx/CppunitTest_svx_core.mk49
-rw-r--r--svx/Module_svx.mk1
-rw-r--r--svx/qa/unit/core.cxx97
-rw-r--r--svx/qa/unit/data/GraphicObjectResolverTest.zipbin0 -> 740 bytes
-rw-r--r--svx/source/xml/xmlgrhlp.cxx7
5 files changed, 152 insertions, 2 deletions
diff --git a/svx/CppunitTest_svx_core.mk b/svx/CppunitTest_svx_core.mk
new file mode 100644
index 000000000000..67445767cc1d
--- /dev/null
+++ b/svx/CppunitTest_svx_core.mk
@@ -0,0 +1,49 @@
+# -*- 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,svx_core))
+
+$(eval $(call gb_CppunitTest_use_externals,svx_core,\
+ boost_headers \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,svx_core, \
+ svx/qa/unit/core \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,svx_core, \
+ comphelper \
+ cppu \
+ cppuhelper \
+ sal \
+ svx \
+ svxcore \
+ test \
+ tl \
+ unotest \
+ utl \
+ vcl \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,svx_core))
+
+$(eval $(call gb_CppunitTest_use_ure,svx_core))
+$(eval $(call gb_CppunitTest_use_vcl,svx_core))
+
+$(eval $(call gb_CppunitTest_use_rdb,svx_core,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,svx_core,\
+ officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,svx_core))
+
+# vim: set noet sw=4 ts=4:
diff --git a/svx/Module_svx.mk b/svx/Module_svx.mk
index 3891829c8108..27a709b23d1b 100644
--- a/svx/Module_svx.mk
+++ b/svx/Module_svx.mk
@@ -39,6 +39,7 @@ $(eval $(call gb_Module_add_check_targets,svx,\
CppunitTest_svx_unit \
CppunitTest_svx_gallery_test \
CppunitTest_svx_removewhichrange \
+ CppunitTest_svx_core \
))
# screenshots
diff --git a/svx/qa/unit/core.cxx b/svx/qa/unit/core.cxx
new file mode 100644
index 000000000000..26cb13ee1faf
--- /dev/null
+++ b/svx/qa/unit/core.cxx
@@ -0,0 +1,97 @@
+/* -*- 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 <test/bootstrapfixture.hxx>
+#include <unotest/macros_test.hxx>
+#include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
+
+#include <comphelper/storagehelper.hxx>
+
+#include <svx/graphichelper.hxx>
+#include <svx/xmlgrhlp.hxx>
+#include <unotools/tempfile.hxx>
+#include <vcl/filter/PDFiumLibrary.hxx>
+
+using namespace ::com::sun::star;
+
+namespace
+{
+/// Tests for svx/source/core/ code.
+class Test : public test::BootstrapFixture, public unotest::MacrosTest
+{
+private:
+ uno::Reference<lang::XComponent> mxComponent;
+
+public:
+ void setUp() override;
+ void tearDown() override;
+};
+
+void Test::setUp()
+{
+ test::BootstrapFixture::setUp();
+
+ mxDesktop.set(frame::Desktop::create(mxComponentContext));
+}
+
+void Test::tearDown()
+{
+ if (mxComponent.is())
+ mxComponent->dispose();
+
+ test::BootstrapFixture::tearDown();
+}
+
+constexpr OUStringLiteral DATA_DIRECTORY = u"/svx/qa/unit/data/";
+
+CPPUNIT_TEST_FIXTURE(Test, testGraphicObjectResolver)
+{
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "GraphicObjectResolverTest.zip";
+ uno::Reference<embed::XStorage> xStorage
+ = comphelper::OStorageHelper::GetStorageOfFormatFromURL(ZIP_STORAGE_FORMAT_STRING, aURL,
+ embed::ElementModes::READWRITE);
+ CPPUNIT_ASSERT(xStorage.is());
+
+ rtl::Reference<SvXMLGraphicHelper> xGraphicHelper
+ = SvXMLGraphicHelper::Create(xStorage, SvXMLGraphicHelperMode::Read);
+ CPPUNIT_ASSERT(xGraphicHelper.is());
+
+ // Test name in root folder
+ {
+ uno::Reference<graphic::XGraphic> xGraphic = xGraphicHelper->loadGraphic("SomeImage.png");
+ CPPUNIT_ASSERT_EQUAL(true, xGraphic.is());
+ }
+
+ // Test name in sub-folder
+ {
+ uno::Reference<graphic::XGraphic> xGraphic
+ = xGraphicHelper->loadGraphic("Pictures/SomeOtherImage.png");
+ CPPUNIT_ASSERT_EQUAL(true, xGraphic.is());
+ }
+
+ // Test non-existent name
+ {
+ uno::Reference<graphic::XGraphic> xGraphic;
+ try
+ {
+ xGraphic = xGraphicHelper->loadGraphic("NoneExistent.png");
+ }
+ catch (const uno::Exception&)
+ {
+ }
+ CPPUNIT_ASSERT_EQUAL(false, xGraphic.is());
+ }
+}
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/qa/unit/data/GraphicObjectResolverTest.zip b/svx/qa/unit/data/GraphicObjectResolverTest.zip
new file mode 100644
index 000000000000..4c19bf2b01b7
--- /dev/null
+++ b/svx/qa/unit/data/GraphicObjectResolverTest.zip
Binary files differ
diff --git a/svx/source/xml/xmlgrhlp.cxx b/svx/source/xml/xmlgrhlp.cxx
index 522e6c076d19..03cf7a846a9b 100644
--- a/svx/source/xml/xmlgrhlp.cxx
+++ b/svx/source/xml/xmlgrhlp.cxx
@@ -400,7 +400,7 @@ bool SvXMLGraphicHelper::ImplGetStreamNames( const OUString& rURLStr,
if( !aURLStr.isEmpty() && aURLStr.indexOf('/')<0 ) // just one token?
{
- rPictureStorageName = XML_GRAPHICSTORAGE_NAME;
+ rPictureStorageName = OUString();
rPictureStreamName = aURLStr;
}
else
@@ -449,7 +449,10 @@ SvxGraphicHelperStream_Impl SvXMLGraphicHelper::ImplGetGraphicStream( const OUSt
const OUString& rPictureStreamName )
{
SvxGraphicHelperStream_Impl aRet;
- aRet.xStorage = ImplGetGraphicStorage( rPictureStorageName );
+ if (!rPictureStorageName.isEmpty())
+ aRet.xStorage = ImplGetGraphicStorage(rPictureStorageName);
+ else
+ aRet.xStorage = mxRootStorage;
sal_Int32 nMode = embed::ElementModes::READ;
if (SvXMLGraphicHelperMode::Write == meCreateMode)