diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2022-07-20 22:01:31 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2022-08-01 08:47:44 +0200 |
commit | d099c71191b8328fa3888723394e30371208bf59 (patch) | |
tree | db4161bea44a009cf7826656e5eda0248203cf4b /svx | |
parent | aae4920e88d4cadae44b4cc12e72dc848599c8dd (diff) |
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
Diffstat (limited to 'svx')
-rw-r--r-- | svx/CppunitTest_svx_core.mk | 49 | ||||
-rw-r--r-- | svx/Module_svx.mk | 1 | ||||
-rw-r--r-- | svx/qa/unit/core.cxx | 97 | ||||
-rw-r--r-- | svx/qa/unit/data/GraphicObjectResolverTest.zip | bin | 0 -> 740 bytes | |||
-rw-r--r-- | svx/source/xml/xmlgrhlp.cxx | 7 |
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 3fc4e889173e..b7d573d08f35 100644 --- a/svx/Module_svx.mk +++ b/svx/Module_svx.mk @@ -40,6 +40,7 @@ $(eval $(call gb_Module_add_check_targets,svx,\ CppunitTest_svx_gallery_test \ CppunitTest_svx_removewhichrange \ CppunitTest_svx_styles \ + 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 Binary files differnew file mode 100644 index 000000000000..4c19bf2b01b7 --- /dev/null +++ b/svx/qa/unit/data/GraphicObjectResolverTest.zip diff --git a/svx/source/xml/xmlgrhlp.cxx b/svx/source/xml/xmlgrhlp.cxx index 6a8c7c08fce5..a55c6057f193 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) |