sw/qa/extras/uiwriter/uiwriter8.cxx | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
New commits: commit 86a5c48cdce4b8392ade2858d7835b48af8afc00 Author: Justin Luth <jl...@mail.com> AuthorDate: Fri Aug 16 10:28:56 2024 -0400 Commit: Justin Luth <jl...@mail.com> CommitDate: Sat Aug 17 04:36:05 2024 +0200 tdf#161741: LO crashed on redo of header changes: unit test make CppunitTest_sw_uiwriter8 CPPUNIT_TEST_NAME=testTdf161741 Change-Id: I3f62fa600d4c1392f76fff02d51443ed51729e00 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171960 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> diff --git a/sw/qa/extras/uiwriter/uiwriter8.cxx b/sw/qa/extras/uiwriter/uiwriter8.cxx index 130bd89fd596..30f0545dbf00 100644 --- a/sw/qa/extras/uiwriter/uiwriter8.cxx +++ b/sw/qa/extras/uiwriter/uiwriter8.cxx @@ -29,6 +29,7 @@ #include <sfx2/linkmgr.hxx> #include <wrtsh.hxx> +#include <UndoManager.hxx> #include <unotxdoc.hxx> #include <drawdoc.hxx> #include <dcontact.hxx> @@ -1016,6 +1017,44 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf146248) CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xPageStyle, u"HeaderIsOn"_ustr)); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf161741) +{ + // Redo of header change causes LO to crash + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + sw::UndoManager& rUndoManager = pDoc->GetUndoManager(); + + uno::Reference<beans::XPropertySet> xPageStyle( + getStyles(u"PageStyles"_ustr)->getByName(u"Standard"_ustr), uno::UNO_QUERY); + + // sanity checks: verify baseline status + CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xPageStyle, u"HeaderIsOn"_ustr)); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), rUndoManager.GetUndoActionCount()); + + // Create a header + pWrtShell->ChangeHeaderOrFooter(u"Default Page Style", /*header*/ true, /*on*/ true, false); + CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xPageStyle, u"HeaderIsOn"_ustr)); + + // create an additional non-header undo point + pWrtShell->Insert(u"crash_test"_ustr); // three undo points + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), rUndoManager.GetUndoActionCount()); + + // undo all the changes in one pass + uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence({ + { "Undo", uno::Any(sal_Int32(4)) }, + })); + dispatchCommand(mxComponent, u".uno:Undo"_ustr, aPropertyValues); // undo all 4 actions + CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xPageStyle, u"HeaderIsOn"_ustr)); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), rUndoManager.GetUndoActionCount()); + + // Crash avoided by clearing the entire redo stack. This redo request will do nothing. + // Without the fix in place, this test would have crashed here + dispatchCommand(mxComponent, u".uno:Redo"_ustr, {}); // redo first (Header) change + // Since Redo is "cleared", the redo did nothing, thus the Header remains off + CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xPageStyle, u"HeaderIsOn"_ustr)); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf152964) { createSwDoc();