From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- sw/qa/uibase/uno/data/cond-field-cached-value.docx | Bin 0 -> 12164 bytes sw/qa/uibase/uno/uno.cxx | 95 +++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 sw/qa/uibase/uno/data/cond-field-cached-value.docx create mode 100644 sw/qa/uibase/uno/uno.cxx (limited to 'sw/qa/uibase/uno') diff --git a/sw/qa/uibase/uno/data/cond-field-cached-value.docx b/sw/qa/uibase/uno/data/cond-field-cached-value.docx new file mode 100644 index 000000000..a19b1240c Binary files /dev/null and b/sw/qa/uibase/uno/data/cond-field-cached-value.docx differ diff --git a/sw/qa/uibase/uno/uno.cxx b/sw/qa/uibase/uno/uno.cxx new file mode 100644 index 000000000..f4b337d8f --- /dev/null +++ b/sw/qa/uibase/uno/uno.cxx @@ -0,0 +1,95 @@ +/* -*- 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 + +constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/uibase/uno/data/"; + +/// Covers sw/source/uibase/uno/ fixes. +class SwUibaseUnoTest : public SwModelTestBase +{ +}; + +CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testLockControllers) +{ + mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"); + { + uno::Reference xModel(mxComponent, uno::UNO_QUERY_THROW); + xModel->lockControllers(); + } + { + uno::Reference xCloseable(mxComponent, uno::UNO_QUERY_THROW); + xCloseable->close(false); + } + // Without the accompanying fix in place, this test would have crashed. + mxComponent.clear(); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testCondFieldCachedValue) +{ + load(DATA_DIRECTORY, "cond-field-cached-value.docx"); + Scheduler::ProcessEventsToIdle(); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : + // i.e. the conditional field lost its cached content. + getParagraph(2, "1"); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testCreateTextRangeByPixelPosition) +{ + // Given a document with 2 characters, and the pixel position of the point between them: + SwDoc* pDoc = createSwDoc(); + SwDocShell* pDocShell = pDoc->GetDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + pWrtShell->Insert2("AZ"); + pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false); + Point aLogic = pWrtShell->GetCharRect().Center(); + SwView* pView = pDocShell->GetView(); + SwEditWin& rEditWin = pView->GetEditWin(); + Point aPixel = rEditWin.LogicToPixel(aLogic); + + // When converting that pixel position to a document model position (text range): + uno::Reference xModel(mxComponent, uno::UNO_QUERY); + uno::Reference xControllers = xModel->getControllers(); + uno::Reference xController(xControllers->nextElement(), + uno::UNO_QUERY); + awt::Point aPoint(aPixel.getX(), aPixel.getY()); + uno::Reference xTextRange + = xController->createTextRangeByPixelPosition(aPoint); + + // Then make sure that text range points after the first character: + auto pTextRange = dynamic_cast(xTextRange.get()); + SwPaM aPaM(pDoc->GetNodes()); + pTextRange->GetPositions(aPaM); + sal_Int32 nActual = aPaM.GetPoint()->nContent.GetIndex(); + // Without the needed PixelToLogic() call in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // i.e. the returned text range pointed before the first character, not between the first and + // the second character. + CPPUNIT_ASSERT_EQUAL(static_cast(1), nActual); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3