sw/qa/extras/uiwriter/data/tdf158198.odt |binary sw/qa/extras/uiwriter/uiwriter6.cxx | 32 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+)
New commits: commit 6a680ef017e5a842113f4eb4b555acb51e921f20 Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Wed Feb 5 11:10:44 2025 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed Feb 5 13:11:43 2025 +0100 tdf#158198: sw_uiwriter6: Add unittest Change-Id: Ie155880ec549ef66d36116db587eef98c06423e9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181149 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sw/qa/extras/uiwriter/data/tdf158198.odt b/sw/qa/extras/uiwriter/data/tdf158198.odt new file mode 100644 index 000000000000..527f0a2843d4 Binary files /dev/null and b/sw/qa/extras/uiwriter/data/tdf158198.odt differ diff --git a/sw/qa/extras/uiwriter/uiwriter6.cxx b/sw/qa/extras/uiwriter/uiwriter6.cxx index af5c132f880a..e73a6ca4c929 100644 --- a/sw/qa/extras/uiwriter/uiwriter6.cxx +++ b/sw/qa/extras/uiwriter/uiwriter6.cxx @@ -2181,6 +2181,38 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testHtmlCopyImages) CPPUNIT_ASSERT(aImage.startsWith("file:///")); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf158198) +{ + createSwDoc("tdf158198.odt"); + uno::Reference<text::XBookmarksSupplier> xBookmarksSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xBookmarksByIdx(xBookmarksSupplier->getBookmarks(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xBookmarksByIdx->getCount()); + uno::Reference<container::XNameAccess> xBookmarksByName = xBookmarksSupplier->getBookmarks(); + CPPUNIT_ASSERT(xBookmarksByName->hasByName(u"WORD"_ustr)); + CPPUNIT_ASSERT(xBookmarksByName->hasByName(u"PARAGRAPH"_ustr)); + + uno::Reference<text::XTextContent> xBookmark1(xBookmarksByName->getByName(u"WORD"_ustr), + uno::UNO_QUERY); + uno::Reference<text::XTextRange> xAnchor1 = xBookmark1->getAnchor(); + + uno::Reference<text::XTextContent> xBookmark2(xBookmarksByName->getByName(u"PARAGRAPH"_ustr), + uno::UNO_QUERY); + uno::Reference<text::XTextRange> xAnchor2 = xBookmark2->getAnchor(); + CPPUNIT_ASSERT_EQUAL(u"{WORD}"_ustr, xAnchor1->getString()); + CPPUNIT_ASSERT_EQUAL(u"{PARAGRAPH}"_ustr, xAnchor2->getString()); + + xAnchor1->setString(""); + xAnchor2->setString(""); + + // Without the fix in place, this test would have failed here + // - Expected: 2 + // - Actual : 1 + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xBookmarksByIdx->getCount()); + CPPUNIT_ASSERT(xAnchor1->getString().isEmpty()); + CPPUNIT_ASSERT(xAnchor2->getString().isEmpty()); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf116789) { createSwDoc("tdf116789.fodt");