sw/qa/extras/odfexport/data/libreoffice.png |binary
 sw/qa/extras/odfexport/odfexport.cxx        |   98 ++++++++++++++++++++++++++++
 2 files changed, 98 insertions(+)

New commits:
commit b9054fed3724a19479e221a8b4818a127a18aabe
Author:     David Hashe <m...@dhashe.com>
AuthorDate: Fri Apr 25 15:34:02 2025 -0400
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Apr 29 08:20:04 2025 +0200

    tdf#60700 Unit tests for saving image icons and accelerators
    
    For tdf#60700 we want to reduce the number of empty directories
    under Configurations2/ that are created on every new document,
    and we need tests to verify that the features that rely on those
    directories continue to work.
    
    My previous test at commit aaed16eef8b2d32ac02c8cb3a42ca25246cb0d33
    covers most of the directories, which are directly created by
    UIConfigurationManager. But Configurations2/images/ is created by
    ImageManager and Configurations2/accelerator/ is created by
    DocumentAcceleratorConfiguration, so we need separate tests for those
    in order to exercise the codepaths.
    
    This change adds those two tests.
    
    Change-Id: Ie34b540f0c59de3bbb871b71b956d3387eb852c3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184646
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/odfexport/data/libreoffice.png 
b/sw/qa/extras/odfexport/data/libreoffice.png
new file mode 100644
index 000000000000..437f613c178c
Binary files /dev/null and b/sw/qa/extras/odfexport/data/libreoffice.png differ
diff --git a/sw/qa/extras/odfexport/odfexport.cxx 
b/sw/qa/extras/odfexport/odfexport.cxx
index 560fc32585a5..058d8adac6ba 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -13,6 +13,8 @@
 #include <swmodeltestbase.hxx>
 
 #include <com/sun/star/awt/Gradient2.hpp>
+#include <com/sun/star/awt/Key.hpp>
+#include <com/sun/star/awt/KeyModifier.hpp>
 #include <com/sun/star/beans/NamedValue.hpp>
 #include <com/sun/star/container/XIndexReplace.hpp>
 #include <com/sun/star/drawing/FillStyle.hpp>
@@ -38,6 +40,8 @@
 #include <com/sun/star/text/XTextDocument.hpp>
 #include <com/sun/star/util/XRefreshable.hpp>
 #include <com/sun/star/text/XTextTable.hpp>
+#include <com/sun/star/ui/ImageType.hpp>
+#include <com/sun/star/ui/XImageManager.hpp>
 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
 #include <com/sun/star/ui/XUIConfigurationManager.hpp>
 
@@ -47,6 +51,7 @@
 #include <svl/PasswordHelper.hxx>
 #include <comphelper/scopeguard.hxx>
 #include <docmodel/uno/UnoGradientTools.hxx>
+#include <vcl/image.hxx>
 
 #include <docufld.hxx> // for SwHiddenTextField::ParseIfFieldDefinition() 
method call
 #include <ftnidx.hxx>
@@ -1429,6 +1434,99 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf69500)
     }
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf60700_images)
+{
+    createSwDoc();
+
+    auto getUIConfigManager = [this]() {
+        css::uno::Reference<css::uno::XComponentContext> xContext
+            = comphelper::getProcessComponentContext();
+        uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xModel.is());
+        uno::Reference<ui::XUIConfigurationManagerSupplier> 
xConfigSupplier(xModel, uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xConfigSupplier.is());
+        uno::Reference<ui::XUIConfigurationManager> xConfigManager
+            = xConfigSupplier->getUIConfigurationManager();
+        return xConfigManager;
+    };
+
+    static constexpr sal_Int16 imageType
+        = css::ui::ImageType::COLOR_NORMAL | css::ui::ImageType::SIZE_DEFAULT;
+
+    // Create and persist a custom icon to the document
+    {
+        Image 
aImage(m_directories.getURLFromSrc(u"/sw/qa/extras/odfexport/data/libreoffice.png"));
+        CPPUNIT_ASSERT(!!aImage);
+
+        uno::Reference<graphic::XGraphic> xGraphic = 
Graphic(aImage.GetBitmapEx()).GetXGraphic();
+        CPPUNIT_ASSERT(xGraphic.is());
+
+        uno::Sequence<OUString> aImportURL{ u".uno:OpenFromWriter"_ustr };
+        uno::Sequence<uno::Reference<graphic::XGraphic>> aImportGraph{ 
xGraphic };
+
+        css::uno::Reference<css::ui::XImageManager> 
xImgMgr(getUIConfigManager()->getImageManager(),
+                                                            uno::UNO_QUERY);
+
+        xImgMgr->insertImages(imageType, aImportURL, aImportGraph);
+        xImgMgr->store();
+    }
+
+    saveAndReload(mpFilter);
+
+    // Verify that the custom icon is still present after save-and-reload
+    {
+        uno::Reference<ui::XUIConfigurationManager> xConfigManager = 
getUIConfigManager();
+        css::uno::Reference<css::ui::XImageManager> 
xImgMgr(xConfigManager->getImageManager(),
+                                                            uno::UNO_QUERY);
+
+        CPPUNIT_ASSERT(xImgMgr->hasImage(imageType, 
u".uno:OpenFromWriter"_ustr));
+    }
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testTdf60700_accelerators)
+{
+    createSwDoc();
+
+    auto getUIConfigManager = [this]() {
+        css::uno::Reference<css::uno::XComponentContext> xContext
+            = comphelper::getProcessComponentContext();
+        uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xModel.is());
+        uno::Reference<ui::XUIConfigurationManagerSupplier> 
xConfigSupplier(xModel, uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xConfigSupplier.is());
+        uno::Reference<ui::XUIConfigurationManager> xConfigManager
+            = xConfigSupplier->getUIConfigurationManager();
+        return xConfigManager;
+    };
+
+    awt::KeyEvent aCtrlU;
+    aCtrlU.KeyCode = css::awt::Key::U;
+    aCtrlU.Modifiers = css::awt::KeyModifier::MOD1;
+
+    static constexpr OUString sCommand = u".uno:OpenFromWriter"_ustr;
+
+    // Create and persist a custom keyboard shortcut to the document
+    {
+        css::uno::Reference<css::ui::XAcceleratorConfiguration> xAccel
+            = getUIConfigManager()->getShortCutManager();
+
+        xAccel->setKeyEvent(aCtrlU, sCommand);
+
+        xAccel->store();
+    }
+
+    saveAndReload(mpFilter);
+
+    // Verify that the custom keyboard shortcut is still present after 
save-and-reload
+    {
+        uno::Reference<ui::XUIConfigurationManager> xConfigManager = 
getUIConfigManager();
+        css::uno::Reference<css::ui::XAcceleratorConfiguration> xAccel
+            = getUIConfigManager()->getShortCutManager();
+
+        CPPUNIT_ASSERT_EQUAL(sCommand, xAccel->getCommandByKeyEvent(aCtrlU));
+    }
+}
+
 } // end of anonymous namespace
 CPPUNIT_PLUGIN_IMPLEMENT();
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to