sw/qa/extras/uiwriter/data/tdf157129.doc |binary sw/qa/extras/uiwriter/uiwriter8.cxx | 39 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
New commits: commit 5cef51f30d9dccfa35683bd0a023cffdc43fbc85 Author: Kira Tubo <kira.t...@gmail.com> AuthorDate: Sat Jul 27 21:41:51 2024 -0700 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed Jul 31 13:28:48 2024 +0200 tdf#157129: sw unit test: cursor position after paste Test to see if the cursor position moves to the end after paste. Without the fix in tdf#157129, the cursor position remains at the beginning of the document. Change-Id: Id577b262b6c885d38eecdd21ae83467c9aa5eed0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171132 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> Tested-by: Jenkins diff --git a/sw/qa/extras/uiwriter/data/tdf157129.doc b/sw/qa/extras/uiwriter/data/tdf157129.doc new file mode 100644 index 000000000000..955426077b4d Binary files /dev/null and b/sw/qa/extras/uiwriter/data/tdf157129.doc differ diff --git a/sw/qa/extras/uiwriter/uiwriter8.cxx b/sw/qa/extras/uiwriter/uiwriter8.cxx index b70a2fbaf5d9..130bd89fd596 100644 --- a/sw/qa/extras/uiwriter/uiwriter8.cxx +++ b/sw/qa/extras/uiwriter/uiwriter8.cxx @@ -2899,6 +2899,45 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf151462) "portion"_ostr, u"another sub three"_ustr); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf157129) +{ + // Unit test for tdf#157129 + // Test to see if cursor moves to the end after paste + + // First document containing test data + createSwDoc("tdf157129.doc"); + CPPUNIT_ASSERT_EQUAL(5, getParagraphs()); + // Copy data from first document + dispatchCommand(mxComponent, u".uno:SelectAll"_ustr, {}); + dispatchCommand(mxComponent, u".uno:Copy"_ustr, {}); + + // Create a new document + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + + CPPUNIT_ASSERT_EQUAL(1, getParagraphs()); + + // Paste data from first document + dispatchCommand(mxComponent, u".uno:Paste"_ustr, {}); + CPPUNIT_ASSERT_EQUAL(5, getParagraphs()); + + // Save cursor position after paste occurs + SwPosition aCursorPosPaste(*pWrtShell->GetCursor()->GetPoint()); + + // Move cursor position to the end + pWrtShell->SttEndDoc(false); //bStart = false + + // Save cursor position at end + SwPosition aCursorPosEnd(*pWrtShell->GetCursor()->GetPoint()); + + // Assert the cursor position after paste is at the end + // Without the test in place, the cursor position is at the beginning of the document + // - Expected : SwPosition (node 18, offset 0) + // - Actual : SwPosition (node 6, offset 0) + CPPUNIT_ASSERT_EQUAL(aCursorPosEnd, aCursorPosPaste); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testCursorPositionAfterUndo) { createSwDoc("cursor_position_after_undo.odt");