summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2022-07-20 22:01:31 +0200
committerTomaž Vajngerl <quikee@gmail.com>2022-07-21 09:01:51 +0200
commitd449da36086409e3cc440036193c4fc8a10a37a1 (patch)
tree13f9447777c838129250c5902645964f429a9e49 /svx
parent6c24f112ad86df77f2de27a31742bca01ed56bdf (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>
Diffstat (limited to 'svx')
-rw-r--r--svx/CppunitTest_svx_core.mk1
-rw-r--r--svx/qa/unit/core.cxx44
-rw-r--r--svx/qa/unit/data/GraphicObjectResolverTest.zipbin0 -> 740 bytes
-rw-r--r--svx/source/xml/xmlgrhlp.cxx7
4 files changed, 49 insertions, 3 deletions
diff --git a/svx/CppunitTest_svx_core.mk b/svx/CppunitTest_svx_core.mk
index aac47ba1db0c..67445767cc1d 100644
--- a/svx/CppunitTest_svx_core.mk
+++ b/svx/CppunitTest_svx_core.mk
@@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,svx_core, \
$(eval $(call gb_CppunitTest_use_libraries,svx_core, \
comphelper \
cppu \
+ cppuhelper \
sal \
svx \
svxcore \
diff --git a/svx/qa/unit/core.cxx b/svx/qa/unit/core.cxx
index 7ec74da33859..27e5783e20db 100644
--- a/svx/qa/unit/core.cxx
+++ b/svx/qa/unit/core.cxx
@@ -9,11 +9,14 @@
#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>
@@ -77,6 +80,45 @@ CPPUNIT_TEST_FIXTURE(Test, testChartExportToPdf)
int nPageCount = pPdfDocument->getPageCount();
CPPUNIT_ASSERT_GREATER(0, nPageCount);
}
+
+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();
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 6c5c76bfce73..6c12aa4bee2b 100644
--- a/svx/source/xml/xmlgrhlp.cxx
+++ b/svx/source/xml/xmlgrhlp.cxx
@@ -390,7 +390,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
@@ -439,7 +439,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)