From bc04a3c85afaf290958ae63ff374ff1d3f07bb66 Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Mon, 1 Feb 2021 16:19:45 +0100 Subject: tdf#100950: sd_uiimpress: Add unittest Change-Id: Ia2ecdc6d2836f51d7c47f1dc7208f52d4ab12a02 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110258 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- sd/qa/unit/uiimpress.cxx | 84 ++++++++++++++++++++++ .../slidesorter/inc/controller/SlsPageSelector.hxx | 2 +- 2 files changed, 85 insertions(+), 1 deletion(-) (limited to 'sd') diff --git a/sd/qa/unit/uiimpress.cxx b/sd/qa/unit/uiimpress.cxx index 7bfe6e42ac87..83eb2a39cd13 100644 --- a/sd/qa/unit/uiimpress.cxx +++ b/sd/qa/unit/uiimpress.cxx @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -29,6 +30,11 @@ #include #include #include +#include +#include +#include +#include +#include #include #include #include @@ -39,6 +45,7 @@ #include #include #include +#include using namespace ::com::sun::star; @@ -53,6 +60,8 @@ public: virtual void tearDown() override; void checkCurrentPageNumber(sal_uInt16 nNum); + void insertStringToObject(sal_uInt16 nObj, const std::string& rStr); + sd::slidesorter::SlideSorterViewShell* getSlideSorterViewShell(); }; void SdUiImpressTest::setUp() @@ -82,6 +91,55 @@ void SdUiImpressTest::checkCurrentPageNumber(sal_uInt16 nNum) CPPUNIT_ASSERT_EQUAL(nNum, nPageNumber); } +void SdUiImpressTest::insertStringToObject(sal_uInt16 nObj, const std::string& rStr) +{ + auto pImpressDocument = dynamic_cast(mxComponent.get()); + sd::ViewShell* pViewShell = pImpressDocument->GetDocShell()->GetViewShell(); + SdPage* pPage = pViewShell->GetActualPage(); + SdrObject* pShape = pPage->GetObj(nObj); + CPPUNIT_ASSERT_MESSAGE("No Shape", pShape); + SdrView* pView = pViewShell->GetView(); + pView->MarkObj(pShape, pView->GetSdrPageView()); + + CPPUNIT_ASSERT(!pView->IsTextEdit()); + + for (const char c : rStr) + { + pImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, c, 0); + pImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, c, 0); + Scheduler::ProcessEventsToIdle(); + } + + CPPUNIT_ASSERT(pView->IsTextEdit()); + + pImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::ESCAPE); + pImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::ESCAPE); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT(!pView->IsTextEdit()); +} + +sd::slidesorter::SlideSorterViewShell* SdUiImpressTest::getSlideSorterViewShell() +{ + auto pXImpressDocument = dynamic_cast(mxComponent.get()); + sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell(); + sd::slidesorter::SlideSorterViewShell* pSSVS = nullptr; + // Same as in sd/qa/unit/misc-tests.cxx + for (int i = 0; i < 1000; i++) + { + // Process all Tasks - slide sorter is created here + while (Scheduler::ProcessTaskScheduling()) + ; + if ((pSSVS = sd::slidesorter::SlideSorterViewShell::GetSlideSorter( + pViewShell->GetViewShellBase())) + != nullptr) + break; + osl::Thread::wait(std::chrono::milliseconds(100)); + } + CPPUNIT_ASSERT(pSSVS); + return pSSVS; +} + CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf111522) { // Load the document and create two new windows. @@ -213,6 +271,32 @@ CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf128651) CPPUNIT_ASSERT_EQUAL_MESSAGE("Redo changes width", nUndoWidth, nRedoWidth); } +CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf100950) +{ + mxComponent = loadFromDesktop("private:factory/simpress", + "com.sun.star.presentation.PresentationDocument"); + + CPPUNIT_ASSERT(mxComponent.is()); + + dispatchCommand(mxComponent, ".uno:InsertPage", {}); + Scheduler::ProcessEventsToIdle(); + + dispatchCommand(mxComponent, ".uno:InsertPage", {}); + Scheduler::ProcessEventsToIdle(); + + insertStringToObject(0, "Test"); + + dispatchCommand(mxComponent, ".uno:Undo", {}); + Scheduler::ProcessEventsToIdle(); + + sd::slidesorter::SlideSorterViewShell* pSSVS = getSlideSorterViewShell(); + auto& rSSController = pSSVS->GetSlideSorter().GetController(); + auto& rPageSelector = rSSController.GetPageSelector(); + + // Without the fix in place, this test would have failed here + CPPUNIT_ASSERT(rPageSelector.IsPageSelected(2)); +} + CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf129346) { mxComponent = loadFromDesktop("private:factory/simpress", diff --git a/sd/source/ui/slidesorter/inc/controller/SlsPageSelector.hxx b/sd/source/ui/slidesorter/inc/controller/SlsPageSelector.hxx index c61578954dae..5993618db157 100644 --- a/sd/source/ui/slidesorter/inc/controller/SlsPageSelector.hxx +++ b/sd/source/ui/slidesorter/inc/controller/SlsPageSelector.hxx @@ -91,7 +91,7 @@ public: SlideSorterModel::GetPageDescriptor(i)->HasState(ST_Selected) is included here to make this class more self contained. */ - bool IsPageSelected(int nPageIndex); + SD_DLLPUBLIC bool IsPageSelected(int nPageIndex); /** Return whether the specified page is visible. This convenience method is a substitute for -- cgit