svx/CppunitTest_svx_core.mk                    |    1 
 svx/qa/unit/core.cxx                           |   44 ++++++++++++++++++++++++-
 svx/qa/unit/data/GraphicObjectResolverTest.zip |binary
 svx/source/xml/xmlgrhlp.cxx                    |    7 ++-
 4 files changed, 49 insertions(+), 3 deletions(-)

New commits:
commit 5cea89cb8c805ded5b571fca295158c462e30303
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Wed Jul 20 22:01:31 2022 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Jul 26 14:55:57 2022 +0200

    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 <qui...@gmail.com>
    (cherry picked from commit d449da36086409e3cc440036193c4fc8a10a37a1)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137424
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

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
Binary files /dev/null and b/svx/qa/unit/data/GraphicObjectResolverTest.zip 
differ
diff --git a/svx/source/xml/xmlgrhlp.cxx b/svx/source/xml/xmlgrhlp.cxx
index 03e85db36922..4815c9e8a35d 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)

Reply via email to