sw/qa/extras/uiwriter/uiwriter9.cxx |   61 ++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

New commits:
commit 5f001eb9ceaff1398a65e21ed3fff4aba2450149
Author:     Kira Tubo <kira.t...@gmail.com>
AuthorDate: Thu Jul 25 13:13:55 2024 -0700
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Fri Jul 26 16:22:20 2024 +0200

    tdf#139631: sw unit test: cut preceding space w/ redline
    
    Test to see if preceding space is cut when cutting a word with redline
    turned on.
    
    Without the fix from tdf#139631, the preceding space is not cut in certain
    situations.
    
    Change-Id: Ic815fd04ee50ce116a8552205c24e8422d734b1b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171058
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/qa/extras/uiwriter/uiwriter9.cxx 
b/sw/qa/extras/uiwriter/uiwriter9.cxx
index 38163f870f30..caf480873072 100644
--- a/sw/qa/extras/uiwriter/uiwriter9.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter9.cxx
@@ -330,6 +330,67 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf159816)
     xTransfer->PrivateDrop(*pWrtShell, ptTo, /*bMove=*/true, 
/*bXSelection=*/true);
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf139631)
+{
+    // Unit test for tdf#139631
+    // Test to see if preceding space is cut when cutting a word with track 
changes (redline) on
+    createSwDoc();
+    SwDoc* pDoc = getSwDoc();
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+
+    pWrtShell->Insert(u"New World!\""_ustr);
+    // Assert that the string, New World!", is inserted correctly into the 
document
+    CPPUNIT_ASSERT_EQUAL(u"New World!\""_ustr, getParagraph(1)->getString());
+
+    // Enable redline
+    dispatchCommand(mxComponent, u".uno:TrackChanges"_ustr, {});
+    CPPUNIT_ASSERT(pDoc->getIDocumentRedlineAccess().IsRedlineOn());
+    // Hide redline changes
+    dispatchCommand(mxComponent, u".uno:ShowTrackedChanges"_ustr, {});
+    CPPUNIT_ASSERT(pWrtShell->GetLayout()->IsHideRedlines());
+
+    pWrtShell->Left(SwCursorSkipMode::Chars, false, 2, false);
+    // Select and cut "World" from string
+    pWrtShell->Left(SwCursorSkipMode::Chars, true, 5, false);
+    dispatchCommand(mxComponent, u".uno:Cut"_ustr, {});
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    pXmlDoc = parseLayoutDump();
+    // Verifies that the leading space before "World" was also cut
+    assertXPath(pXmlDoc, 
"/root/page[1]/body/txt[1]/SwParaPortion/SwLineLayout/SwParaPortion"_ostr,
+                "portion"_ostr, "New!\"");
+
+    // Reset to initial string
+    dispatchCommand(mxComponent, u".uno:Undo"_ustr, {});
+    discardDumpedLayout();
+    pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, 
"/root/page[1]/body/txt[1]/SwParaPortion/SwLineLayout/SwParaPortion"_ostr,
+                "portion"_ostr, "New World!\"");
+
+    pWrtShell->EndPara(false);
+    pWrtShell->Left(SwCursorSkipMode::Chars, false, 1, false);
+    // Replace ! with .
+    pWrtShell->Left(SwCursorSkipMode::Chars, true, 1, false);
+    pWrtShell->Delete();
+    pWrtShell->Insert(u"."_ustr);
+    discardDumpedLayout();
+    pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, 
"/root/page[1]/body/txt[1]/SwParaPortion/SwLineLayout/SwParaPortion"_ostr,
+                "portion"_ostr, "New World.\"");
+
+    pWrtShell->Left(SwCursorSkipMode::Chars, false, 1, false);
+    // Select and cut "World" from string
+    pWrtShell->Left(SwCursorSkipMode::Chars, true, 5, false);
+    dispatchCommand(mxComponent, u".uno:Cut"_ustr, {});
+
+    discardDumpedLayout();
+    pXmlDoc = parseLayoutDump();
+    // Without the test in place, the leading space before "World" is not also 
cut.
+    // Expected: New."
+    // Actual: New ."
+    assertXPath(pXmlDoc, 
"/root/page[1]/body/txt[1]/SwParaPortion/SwLineLayout/SwParaPortion"_ostr,
+                "portion"_ostr, "New.\"");
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf151710)
 {
     createSwDoc();

Reply via email to