sd/qa/unit/uiimpress.cxx | 40 ++++++++++++++++++++++++++++++++++++++++ sw/qa/uibase/shells/shells.cxx | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+)
New commits: commit ae465d8f4d291d0aa3d88881b90ada481d62586c Author: Mike Kaganski <[email protected]> AuthorDate: Mon Oct 6 18:10:53 2025 +0500 Commit: Miklos Vajna <[email protected]> CommitDate: Tue Oct 14 08:42:36 2025 +0200 LOK Transform API: add unit tests for generic UnoCommand command Change-Id: I7cfbc1ff08cbd0e4089f9e4b9579ab22ec05d85d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192276 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/sd/qa/unit/uiimpress.cxx b/sd/qa/unit/uiimpress.cxx index edfaaaca6695..64d38fe23a2a 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/FillStyle.hpp> #include <com/sun/star/drawing/XDrawView.hpp> @@ -60,6 +61,7 @@ #include <slideshow.hxx> #include <sdresid.hxx> #include <strings.hrc> +#include <unopage.hxx> using namespace ::com::sun::star; @@ -275,6 +277,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/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx index 165eb7589379..a53c39663351 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:
