From 91fe6b97952aa6f7cef58327fd085a17db38ad95 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 11:44:47 +0200 Subject: Merging upstream version 4:24.2.2. Signed-off-by: Daniel Baumann --- .../extras/uiwriter/data/FrameInHiddenSection.fodt | 20 ++++++ .../data/hiddenSectionsAroundPageBreak.fodt | 21 ++++++ sw/qa/extras/uiwriter/uiwriter4.cxx | 15 ++--- sw/qa/extras/uiwriter/uiwriter9.cxx | 78 ++++++++++++++++++++++ 4 files changed, 124 insertions(+), 10 deletions(-) create mode 100644 sw/qa/extras/uiwriter/data/FrameInHiddenSection.fodt create mode 100644 sw/qa/extras/uiwriter/data/hiddenSectionsAroundPageBreak.fodt (limited to 'sw/qa/extras/uiwriter') diff --git a/sw/qa/extras/uiwriter/data/FrameInHiddenSection.fodt b/sw/qa/extras/uiwriter/data/FrameInHiddenSection.fodt new file mode 100644 index 0000000000..2095c71730 --- /dev/null +++ b/sw/qa/extras/uiwriter/data/FrameInHiddenSection.fodt @@ -0,0 +1,20 @@ + + + + + + + + + + lorem + + + + + ipsum + + + + + \ No newline at end of file diff --git a/sw/qa/extras/uiwriter/data/hiddenSectionsAroundPageBreak.fodt b/sw/qa/extras/uiwriter/data/hiddenSectionsAroundPageBreak.fodt new file mode 100644 index 0000000000..12761847ed --- /dev/null +++ b/sw/qa/extras/uiwriter/data/hiddenSectionsAroundPageBreak.fodt @@ -0,0 +1,21 @@ + + + + + + + + + + + + + A paragraph with a page-break-before + + + + Lorem + + + + \ No newline at end of file diff --git a/sw/qa/extras/uiwriter/uiwriter4.cxx b/sw/qa/extras/uiwriter/uiwriter4.cxx index c1f0be1757..98fcbcae22 100644 --- a/sw/qa/extras/uiwriter/uiwriter4.cxx +++ b/sw/qa/extras/uiwriter/uiwriter4.cxx @@ -682,8 +682,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest4, testBookmarkCollapsed) // 6. Hit Del, thus deleting "abc" (The bookmark "test" is still there). // 7. Save the document: // -// -// +// // def // // @@ -737,14 +736,10 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest4, testRemoveBookmarkText) // load only content.xml from the resaved document xmlDocUniquePtr pXmlDoc = parseExport("content.xml"); - constexpr OString aPath("/office:document-content/office:body/office:text/text:p"_ostr); - - CPPUNIT_ASSERT_ASSERTION_FAIL(getXPathPosition(pXmlDoc, aPath, "bookmark")); // not found - const int pos2 = getXPathPosition(pXmlDoc, aPath, "bookmark-start"); - const int pos3 = getXPathPosition(pXmlDoc, aPath, "bookmark-end"); - - CPPUNIT_ASSERT_EQUAL(0, pos2); // found, and it is first - CPPUNIT_ASSERT_EQUAL(1, pos3); // found, and it is second + // Bookmark without text becomes collapsed + assertXPath(pXmlDoc, "//office:body/office:text/text:p/text:bookmark"_ostr, 1); + assertXPath(pXmlDoc, "//office:body/office:text/text:p/text:bookmark-start"_ostr, 0); + assertXPath(pXmlDoc, "//office:body/office:text/text:p/text:bookmark-end"_ostr, 0); } // 1. Open a new writer document 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 #include #include +#include + #include #include #include @@ -26,8 +28,10 @@ #include #include #include +#include #include #include +#include namespace { @@ -122,6 +126,80 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf135083) CPPUNIT_ASSERT(!getProperty(xLastPara, u"ListId"_ustr).isEmpty()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testHiddenSectionsAroundPageBreak) +{ + createSwDoc("hiddenSectionsAroundPageBreak.fodt"); + + CPPUNIT_ASSERT_EQUAL(1, getPages()); + + auto xModel(mxComponent.queryThrow()); + auto xTextViewCursorSupplier( + xModel->getCurrentController().queryThrow()); + auto xCursor(xTextViewCursorSupplier->getViewCursor().queryThrow()); + + // Make sure that the page style is set correctly + xCursor->jumpToFirstPage(); + CPPUNIT_ASSERT_EQUAL(u"Landscape"_ustr, getProperty(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()); + auto xSelSupplier(xModel->getCurrentController().queryThrow()); + auto xSelections(xSelSupplier->getSelection().queryThrow()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSelections->getCount()); + auto xSelection(xSelections->getByIndex(0).queryThrow()); + + // 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 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(); -- cgit v1.2.3