From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- sw/qa/core/crsr/crsr.cxx | 106 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 sw/qa/core/crsr/crsr.cxx (limited to 'sw/qa/core/crsr/crsr.cxx') diff --git a/sw/qa/core/crsr/crsr.cxx b/sw/qa/core/crsr/crsr.cxx new file mode 100644 index 000000000..e1664f70a --- /dev/null +++ b/sw/qa/core/crsr/crsr.cxx @@ -0,0 +1,106 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +char const DATA_DIRECTORY[] = "/sw/qa/core/crsr/data/"; + +/// Covers sw/source/core/crsr/ fixes. +class SwCoreCrsrTest : public SwModelTestBase +{ +}; + +CPPUNIT_TEST_FIXTURE(SwCoreCrsrTest, testFindReplace) +{ + loadURL("private:factory/swriter", nullptr); + + // Given: a document with two "foo" in it, the second followed by a formatted soft hyphen. + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xText = xTextDocument->getText(); + // Create a document which has 2 lines: first line has foo in it, second line has the same, but + // followed by a formatted soft hyphen. + xText->insertString(xText->getEnd(), "foo xxx", /*bAbsorb=*/false); + xText->insertControlCharacter(xText->getEnd(), text::ControlCharacter::PARAGRAPH_BREAK, + /*bAbsorb=*/false); + xText->insertString(xText->getEnd(), OUString(u"foo xxx \xad after"), /*bAbsorb=*/false); + uno::Reference xModel(mxComponent, uno::UNO_QUERY); + uno::Reference xTextViewCursorSupplier( + xModel->getCurrentController(), uno::UNO_QUERY); + uno::Reference xViewCursor = xTextViewCursorSupplier->getViewCursor(); + xViewCursor->gotoEnd(/*bExpand=*/false); + xViewCursor->goLeft(/*nCount=*/6, /*bExpand=*/false); + xViewCursor->goLeft(/*nCount=*/1, /*bExpand=*/true); + uno::Reference xViewCursorProps(xViewCursor, uno::UNO_QUERY); + xViewCursorProps->setPropertyValue("CharWeight", uno::makeAny(awt::FontWeight::BOLD)); + xViewCursor->gotoStart(/*bExpand=*/false); + + // When: doing search & replace 3 times. + uno::Sequence aArgs(comphelper::InitPropertySequence({ + { "SearchItem.SearchString", uno::makeAny(OUString("foo")) }, + { "SearchItem.ReplaceString", uno::makeAny(OUString("bar")) }, + { "SearchItem.Command", uno::makeAny(static_cast(SvxSearchCmd::REPLACE)) }, + })); + // Find the first foo. + dispatchCommand(mxComponent, ".uno:ExecuteSearch", aArgs); + // Replace the first foo. + dispatchCommand(mxComponent, ".uno:ExecuteSearch", aArgs); + // Replace the second foo. + dispatchCommand(mxComponent, ".uno:ExecuteSearch", aArgs); + + // Then: the second "foo" should be replaced as well. + xViewCursor->gotoEnd(/*bExpand=*/false); + uno::Reference xLineCursor(xViewCursor, uno::UNO_QUERY); + xLineCursor->gotoStartOfLine(/*bExpand=*/true); + OUString aActual = xViewCursor->getString(); + CPPUNIT_ASSERT_GREATEREQUAL(static_cast(3), aActual.getLength()); + OUString aActualStart = aActual.copy(0, 3); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: bar + // - Actual : foo + // i.e. the foo on the second line was not replaced. + CPPUNIT_ASSERT_EQUAL(OUString("bar"), aActualStart); +} + +CPPUNIT_TEST_FIXTURE(SwCoreCrsrTest, testSelAllStartsWithTable) +{ + load(DATA_DIRECTORY, "sel-all-starts-with-table.odt"); + SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); + SwDocShell* pDocShell = pTextDoc->GetDocShell(); + SwDoc* pDoc = pDocShell->GetDoc(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + + CPPUNIT_ASSERT_EQUAL(static_cast(1), pDoc->GetTableFrameFormatCount(/*bUsed=*/true)); + + pWrtShell->SelAll(); + pWrtShell->SelAll(); + Scheduler::ProcessEventsToIdle(); + pWrtShell->DelLeft(); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 0 + // - Actual : 1 + // i.e. the table selection was lost and the table was not deleted. + CPPUNIT_ASSERT_EQUAL(static_cast(0), pDoc->GetTableFrameFormatCount(/*bUsed=*/true)); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3