sd/qa/unit/uiimpress.cxx            |   40 ++++++++++++++++++++++++++++++++++++
 sd/source/ui/view/drviews2.cxx      |    8 +++----
 sw/qa/uibase/shells/shells.cxx      |   39 +++++++++++++++++++++++++++++++++++
 sw/source/uibase/shells/textsh1.cxx |    8 +++----
 4 files changed, 87 insertions(+), 8 deletions(-)

New commits:
commit b0fb88e4568dfb150f29c94fbd70dcae764a1f3f
Author:     Mike Kaganski <[email protected]>
AuthorDate: Mon Oct 6 18:10:53 2025 +0500
Commit:     Mike Kaganski <[email protected]>
CommitDate: Mon Oct 13 14:21:32 2025 +0200

    LOK Transform API: add unit tests for generic UnoCommand command
    
    This also fixes a mismerge.
    
    Change-Id: I7cfbc1ff08cbd0e4089f9e4b9579ab22ec05d85d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192275
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/sd/qa/unit/uiimpress.cxx b/sd/qa/unit/uiimpress.cxx
index f32b2d891529..33b8c3ff7896 100644
--- a/sd/qa/unit/uiimpress.cxx
+++ b/sd/qa/unit/uiimpress.cxx
@@ -12,6 +12,7 @@
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 
 #include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/uno/Reference.hxx>
 #include <com/sun/star/drawing/LineStyle.hpp>
 #include <com/sun/star/drawing/FillStyle.hpp>
@@ -64,6 +65,7 @@
 #include <slideshow.hxx>
 #include <sdresid.hxx>
 #include <strings.hrc>
+#include <unopage.hxx>
 
 using namespace ::com::sun::star;
 
@@ -279,6 +281,44 @@ CPPUNIT_TEST_FIXTURE(SdUiImpressTest, 
testDocumentStructureTransformExtractSlide
     CPPUNIT_ASSERT_EQUAL(aExpectedStr, aJsonWriter.finishAndGetAsOString());
 }
 
+CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testDocumentStructureUnoCommand)
+{
+    // 1. Create a document;
+    // 2. Check that its first slide has two objects (the default title + 
content placeholders);
+    // 3. Perform a "TransformDocumentStructure" with a "UnoCommand" calling 
".uno:SelectAll" and
+    //    ".uno:Cut";
+    // 4. Check that the first slide has no objects now.
+
+    createSdImpressDoc();
+
+    // Let comphelper::dispatchCommand (in SfxLokHelper::dispatchUnoCommand) 
find the frame
+    auto xDesktop = 
frame::Desktop::create(comphelper::getProcessComponentContext());
+    auto pImpressDocument = 
static_cast<SdXImpressDocument*>(mxComponent.get());
+    auto pFrame = pImpressDocument->GetDocShell()->GetFrame();
+    CPPUNIT_ASSERT(pFrame);
+    xDesktop->setActiveFrame(pFrame->GetFrame().GetFrameInterface());
+
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(2),
+                         
pImpressDocument->getSdDrawPages()->getDrawPageByIndex(0)->getCount());
+
+    static constexpr OUString aJson = uR"json(
+{
+    "UnoCommand": {
+        "name": ".uno:SelectAll"
+    },
+    "UnoCommand": {
+        "name": ".uno:Cut"
+    }
+}
+)json"_ustr;
+
+    dispatchCommand(mxComponent, u".uno:TransformDocumentStructure"_ustr,
+                    { comphelper::makePropertyValue(u"DataJson"_ustr, aJson) 
});
+
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0),
+                         
pImpressDocument->getSdDrawPages()->getDrawPageByIndex(0)->getCount());
+}
+
 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf111522)
 {
     // Load the document and create two new windows.
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
index 422483a57a45..b3616e46c1cf 100644
--- a/sd/source/ui/view/drviews2.cxx
+++ b/sd/source/ui/view/drviews2.cxx
@@ -1371,12 +1371,12 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
                                 }
                             }
                         }
-                        else if (aItem2.first == "UnoCommand")
-                        {
-                            SfxLokHelper::dispatchUnoCommand(aItem2.second);
-                        }
                     }
                 }
+                else if (aItem.first == "UnoCommand")
+                {
+                    SfxLokHelper::dispatchUnoCommand(aItem.second);
+                }
             }
             rReq.Done();
         }
diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx
index 5838de9c4e73..300e0294aa1d 100644
--- a/sw/qa/uibase/shells/shells.cxx
+++ b/sw/qa/uibase/shells/shells.cxx
@@ -9,6 +9,7 @@
 
 #include <swmodeltestbase.hxx>
 
+#include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/frame/XStorable.hpp>
 #include <com/sun/star/packages/zip/ZipFileAccess.hpp>
 #include <com/sun/star/text/BibliographyDataType.hpp>
@@ -34,6 +35,7 @@
 #include <osl/thread.hxx>
 
 #include <IDocumentContentOperations.hxx>
+#include <IDocumentRedlineAccess.hxx>
 #include <cmdid.h>
 #include <fmtanchr.hxx>
 #include <view.hxx>
@@ -1123,6 +1125,43 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testDocumentStructureExtractRedlines_te
     CPPUNIT_ASSERT(bool(it == docStructure.end()));
 }
 
+CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testDocumentStructureUnoCommand)
+{
+    // 1. Create a document;
+    // 2. Check that it's not in change tracking mode;
+    // 3. Perform a "TransformDocumentStructure" with a "UnoCommand" of 
".uno:TrackChanges";
+    // 4. Check that it's in change tracking mode now.
+
+    createSwDoc();
+
+    // Let comphelper::dispatchCommand (in SfxLokHelper::dispatchUnoCommand) 
find the frame
+    auto xDesktop = 
frame::Desktop::create(comphelper::getProcessComponentContext());
+    auto pFrame = getSwDocShell()->GetFrame();
+    CPPUNIT_ASSERT(pFrame);
+    xDesktop->setActiveFrame(pFrame->GetFrame().GetFrameInterface());
+
+    CPPUNIT_ASSERT(!getSwDoc()->getIDocumentRedlineAccess().IsRedlineOn());
+
+    static constexpr OUString aJson = uR"json(
+{
+    "UnoCommand": {
+        "name": ".uno:TrackChanges",
+        "arguments": {
+            "TrackChanges": {
+                "type": "boolean",
+                "value": "true"
+            }
+        }
+    }
+}
+)json"_ustr;
+
+    dispatchCommand(mxComponent, u".uno:TransformDocumentStructure"_ustr,
+                    { comphelper::makePropertyValue(u"DataJson"_ustr, aJson) 
});
+
+    CPPUNIT_ASSERT(getSwDoc()->getIDocumentRedlineAccess().IsRedlineOn());
+}
+
 CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateRefmarks)
 {
     // Given a document with two refmarks, one is not interesting the other is 
a citation:
diff --git a/sw/source/uibase/shells/textsh1.cxx 
b/sw/source/uibase/shells/textsh1.cxx
index 15b9e7c9e283..08178e04ab73 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -3579,12 +3579,12 @@ void SwTextShell::Execute(SfxRequest &rReq)
                                     + aItem2.first + "'");
                             }
                         }
-                        else if (aItem2.first == "UnoCommand")
-                        {
-                            SfxLokHelper::dispatchUnoCommand(aItem2.second);
-                        }
                     }
                 }
+                else if (aItem.first == "UnoCommand")
+                {
+                    SfxLokHelper::dispatchUnoCommand(aItem.second);
+                }
             }
         }
         break;

Reply via email to