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/uibase/shells/shells.cxx | 144 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 sw/qa/uibase/shells/shells.cxx (limited to 'sw/qa/uibase/shells/shells.cxx') diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx new file mode 100644 index 000000000..fbdf35758 --- /dev/null +++ b/sw/qa/uibase/shells/shells.cxx @@ -0,0 +1,144 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include + +static char const DATA_DIRECTORY[] = "/sw/qa/uibase/shells/data/"; + +/// Covers sw/source/uibase/shells/ fixes. +class SwUibaseShellsTest : public SwModelTestBase +{ +public: + SwDoc* createDoc(const char* pName = nullptr); +}; + +SwDoc* SwUibaseShellsTest::createDoc(const char* pName) +{ + if (!pName) + loadURL("private:factory/swriter", nullptr); + else + load(DATA_DIRECTORY, pName); + + SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + return pTextDoc->GetDocShell()->GetDoc(); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testTdf130179) +{ + SwDoc* pDoc = createDoc(); + IDocumentContentOperations& rIDCO = pDoc->getIDocumentContentOperations(); + SwCursorShell* pShell(pDoc->GetEditShell()); + SfxItemSet aFrameSet(pDoc->GetAttrPool(), svl::Items{}); + SfxItemSet aGrfSet(pDoc->GetAttrPool(), svl::Items{}); + SwFormatAnchor aAnchor(RndStdIds::FLY_AT_PARA); + aFrameSet.Put(aAnchor); + GraphicObject aGrf; + CPPUNIT_ASSERT(rIDCO.InsertGraphicObject(*pShell->GetCursor(), aGrf, &aFrameSet, &aGrfSet)); + CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_GRF)); + + SwView* pView = pDoc->GetDocShell()->GetView(); + pView->GetViewFrame()->GetDispatcher()->Execute(FN_CNTNT_TO_NEXT_FRAME, SfxCallMode::SYNCHRON); + // Make sure SwTextShell is replaced with SwDrawShell right now, not after 120 ms, as set in the + // SwView ctor. + pView->StopShellTimer(); + + std::unique_ptr pItem; + pView->GetViewFrame()->GetBindings().QueryState(FN_POSTIT, pItem); + // Without the accompanying fix in place, this test would have failed with: + // assertion failed + // - Expression: !pItem + // i.e. comment insertion was enabled for an at-para anchored image. + CPPUNIT_ASSERT(!pItem); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testShapeTextAlignment) +{ +// FIXME find out why this fails on macOS/Windows +#if !defined(MACOSX) && !defined(_WIN32) + // Create a document with a rectangle in it. + SwDoc* pDoc = createDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + Point aStartPos(1000, 1000); + pWrtShell->BeginCreate(static_cast(OBJ_RECT), aStartPos); + Point aMovePos(2000, 2000); + pWrtShell->MoveCreate(aMovePos); + pWrtShell->EndCreate(SdrCreateCmd::ForceEnd); + + // Start shape text edit. + SwView* pView = pDoc->GetDocShell()->GetView(); + // Select the shape. + pView->GetViewFrame()->GetDispatcher()->Execute(FN_CNTNT_TO_NEXT_FRAME, SfxCallMode::SYNCHRON); + pView->StopShellTimer(); + // Start the actual text edit. + SdrPage* pPage = pWrtShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0); + CPPUNIT_ASSERT_EQUAL(static_cast(1), pPage->GetObjCount()); + SdrObject* pObject = pPage->GetObj(0); + pView->EnterShapeDrawTextMode(pObject); + pView->AttrChangedNotify(nullptr); + + // Change paragraph adjustment to center. + pView->GetViewFrame()->GetDispatcher()->Execute(SID_ATTR_PARA_ADJUST_CENTER, + SfxCallMode::SYNCHRON); + + // End shape text edit. + pWrtShell->EndTextEdit(); + + const OutlinerParaObject* pOutliner = pObject->GetOutlinerParaObject(); + // Without the accompanying fix in place, this test would have failed, because the shape had no + // text or text formatting. In other words the paragraph adjustment command was ignored. + CPPUNIT_ASSERT(pOutliner); + const SfxItemSet& rParaAttribs = pOutliner->GetTextObject().GetParaAttribs(0); + SvxAdjust eAdjust = rParaAttribs.GetItem(EE_PARA_JUST)->GetAdjust(); + CPPUNIT_ASSERT_EQUAL(SvxAdjust::Center, eAdjust); +#endif +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testOleSavePreviewUpdate) +{ + // Load a document with 2 charts in it. The second is down enough that you have to scroll to + // trigger its rendering. Previews are missing for both. + createDoc("ole-save-preview-update.odt"); + + // Explicitly update OLE previews, etc. + dispatchCommand(mxComponent, ".uno:UpdateAll", {}); + + // Save the document and see if we get the previews. + uno::Reference xStorable(mxComponent, uno::UNO_QUERY); + xStorable->storeToURL(maTempFile.GetURL(), {}); + uno::Reference xNameAccess + = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), + maTempFile.GetURL()); + + // Without the accompanying fix in place, this test would have failed, because the object + // replacements were not generated, even after UpdateAll. + CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Object 1")); + CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Object 2")); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3