diff options
Diffstat (limited to 'sw/qa/extras/uiwriter/uiwriter9.cxx')
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter9.cxx | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter9.cxx b/sw/qa/extras/uiwriter/uiwriter9.cxx index 1a3e49c257..3772955dd9 100644 --- a/sw/qa/extras/uiwriter/uiwriter9.cxx +++ b/sw/qa/extras/uiwriter/uiwriter9.cxx @@ -16,6 +16,8 @@ #include <com/sun/star/text/XTextTable.hpp> #include <com/sun/star/text/XTextViewCursorSupplier.hpp> #include <com/sun/star/text/XPageCursor.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> + #include <comphelper/propertysequence.hxx> #include <swdtflvr.hxx> #include <o3tl/string_view.hxx> @@ -26,8 +28,10 @@ #include <ndtxt.hxx> #include <toxmgr.hxx> #include <IDocumentFieldsAccess.hxx> +#include <IDocumentLayoutAccess.hxx> #include <IDocumentRedlineAccess.hxx> #include <fmtinfmt.hxx> +#include <rootfrm.hxx> namespace { @@ -122,6 +126,80 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf135083) CPPUNIT_ASSERT(!getProperty<OUString>(xLastPara, u"ListId"_ustr).isEmpty()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testHiddenSectionsAroundPageBreak) +{ + createSwDoc("hiddenSectionsAroundPageBreak.fodt"); + + CPPUNIT_ASSERT_EQUAL(1, getPages()); + + auto xModel(mxComponent.queryThrow<frame::XModel>()); + auto xTextViewCursorSupplier( + xModel->getCurrentController().queryThrow<text::XTextViewCursorSupplier>()); + auto xCursor(xTextViewCursorSupplier->getViewCursor().queryThrow<text::XPageCursor>()); + + // Make sure that the page style is set correctly + xCursor->jumpToFirstPage(); + CPPUNIT_ASSERT_EQUAL(u"Landscape"_ustr, getProperty<OUString>(xCursor, "PageStyleName")); +} + +CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf159565) +{ + // Given a document with a hidden section in the beginning, additionally containing a frame + createSwDoc("FrameInHiddenSection.fodt"); + + dispatchCommand(mxComponent, u".uno:SelectAll"_ustr, {}); + + // Check that the selection covers the whole visible text + auto xModel(mxComponent.queryThrow<css::frame::XModel>()); + auto xSelSupplier(xModel->getCurrentController().queryThrow<css::view::XSelectionSupplier>()); + auto xSelections(xSelSupplier->getSelection().queryThrow<css::container::XIndexAccess>()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSelections->getCount()); + auto xSelection(xSelections->getByIndex(0).queryThrow<css::text::XTextRange>()); + + // Without the fix, this would fail - there was no selection + CPPUNIT_ASSERT_EQUAL(u"" SAL_NEWLINE_STRING SAL_NEWLINE_STRING "ipsum"_ustr, + xSelection->getString()); +} + +CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf159816) +{ + createSwDoc(); + + SwDoc* pDoc = getSwDoc(); + CPPUNIT_ASSERT(pDoc); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + CPPUNIT_ASSERT(pWrtShell); + + // Add 5 empty paragraphs + pWrtShell->SplitNode(); + pWrtShell->SplitNode(); + pWrtShell->SplitNode(); + pWrtShell->SplitNode(); + pWrtShell->SplitNode(); + + // Add a bookmark at the very end + IDocumentMarkAccess& rIDMA(*pDoc->getIDocumentMarkAccess()); + rIDMA.makeMark(*pWrtShell->GetCursor(), "Mark", IDocumentMarkAccess::MarkType::BOOKMARK, + sw::mark::InsertMode::New); + + // Get coordinates of the end point in the document + SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout(); + SwFrame* pPage = pLayout->Lower(); + SwFrame* pBody = pPage->GetLower(); + SwFrame* pLastPara = pBody->GetLower()->GetNext()->GetNext()->GetNext()->GetNext()->GetNext(); + Point ptTo = pLastPara->getFrameArea().BottomRight(); + + pWrtShell->SelAll(); + + // Drag-n-drop to its own end + rtl::Reference<SwTransferable> xTransfer = new SwTransferable(*pWrtShell); + // Without the fix, this would crash: either in CopyFlyInFlyImpl (tdf#159813): + // Assertion failed: !pCopiedPaM || pCopiedPaM->End()->GetNode() == rRg.aEnd.GetNode() + // or in BigPtrArray::operator[] (tdf#159816): + // Assertion failed: idx < m_nSize + xTransfer->PrivateDrop(*pWrtShell, ptTo, /*bMove=*/true, /*bXSelection=*/true); +} + } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); |