summaryrefslogtreecommitdiffstats
path: root/sw/qa/uibase
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /sw/qa/uibase
parentInitial commit. (diff)
downloadlibreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz
libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sw/qa/uibase')
-rw-r--r--sw/qa/uibase/dochdl/dochdl.cxx61
-rw-r--r--sw/qa/uibase/frmdlg/data/wrapped-math-object.docxbin0 -> 20504 bytes
-rw-r--r--sw/qa/uibase/frmdlg/frmdlg.cxx51
-rw-r--r--sw/qa/uibase/shells/data/ole-save-preview-update.odtbin0 -> 16006 bytes
-rw-r--r--sw/qa/uibase/shells/shells.cxx144
5 files changed, 256 insertions, 0 deletions
diff --git a/sw/qa/uibase/dochdl/dochdl.cxx b/sw/qa/uibase/dochdl/dochdl.cxx
new file mode 100644
index 000000000..26f8fe502
--- /dev/null
+++ b/sw/qa/uibase/dochdl/dochdl.cxx
@@ -0,0 +1,61 @@
+/* -*- 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 <swmodeltestbase.hxx>
+
+#include <vcl/transfer.hxx>
+
+#include <wrtsh.hxx>
+#include <swdtflvr.hxx>
+
+/// Covers sw/source/uibase/dochdl/ fixes.
+class SwUibaseDochdlTest : public SwModelTestBase
+{
+public:
+ SwDoc* createDoc();
+};
+
+SwDoc* SwUibaseDochdlTest::createDoc()
+{
+ loadURL("private:factory/swriter", nullptr);
+
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ return pTextDoc->GetDocShell()->GetDoc();
+}
+
+CPPUNIT_TEST_FIXTURE(SwUibaseDochdlTest, testSelectPasteFormat)
+{
+ // Create a new document and cut a character.
+ SwDoc* pDoc = createDoc();
+ SwDocShell* pDocShell = pDoc->GetDocShell();
+ SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+ pWrtShell->Insert2("x");
+ pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false);
+ rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell);
+ pTransfer->Cut();
+
+ // Decide what format to use when doing a Writer->Writer paste and both RTF and ODF is an
+ // available format.
+ TransferableDataHelper aHelper(pTransfer.get());
+ sal_uInt8 nAction = EXCHG_OUT_ACTION_INSERT_STRING;
+ SotClipboardFormatId nFormat = SotClipboardFormatId::RICHTEXT;
+ SwTransferable::SelectPasteFormat(aHelper, nAction, nFormat);
+
+ CPPUNIT_ASSERT_EQUAL(EXCHG_OUT_ACTION_INSERT_OLE, nAction);
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 85 (EMBED_SOURCE)
+ // - Actual : 145 (RICHTEXT)
+ // i.e. RTF was selected for Writer->Writer out of process copying, which is worse than ODF.
+ CPPUNIT_ASSERT_EQUAL(SotClipboardFormatId::EMBED_SOURCE, nFormat);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/uibase/frmdlg/data/wrapped-math-object.docx b/sw/qa/uibase/frmdlg/data/wrapped-math-object.docx
new file mode 100644
index 000000000..c6f76dd5d
--- /dev/null
+++ b/sw/qa/uibase/frmdlg/data/wrapped-math-object.docx
Binary files differ
diff --git a/sw/qa/uibase/frmdlg/frmdlg.cxx b/sw/qa/uibase/frmdlg/frmdlg.cxx
new file mode 100644
index 000000000..3700abb9d
--- /dev/null
+++ b/sw/qa/uibase/frmdlg/frmdlg.cxx
@@ -0,0 +1,51 @@
+/* -*- 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 <swmodeltestbase.hxx>
+
+#include <com/sun/star/text/TextContentAnchorType.hpp>
+
+char const DATA_DIRECTORY[] = "/sw/qa/uibase/frmdlg/data/";
+
+/// Covers sw/source/uibase/frmdlg/ fixes.
+class SwUibaseFrmdlgTest : public SwModelTestBase
+{
+public:
+ void createDoc(const char* pName = nullptr);
+};
+
+void SwUibaseFrmdlgTest::createDoc(const char* pName)
+{
+ if (!pName)
+ {
+ loadURL("private:factory/swriter", nullptr);
+ }
+ else
+ {
+ load(DATA_DIRECTORY, pName);
+ }
+}
+
+CPPUNIT_TEST_FIXTURE(SwUibaseFrmdlgTest, testWrappedMathObject)
+{
+ // The document includes a Math object with explicit wrapping.
+ createDoc("wrapped-math-object.docx");
+ uno::Reference<drawing::XShape> xMath = getShape(1);
+
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 4 (AT_CHARACTER)
+ // - Actual : 1 (AS_CHARACTER)
+ // i.e. the object lost its wrapping, leading to an incorrect position.
+ CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER,
+ getProperty<text::TextContentAnchorType>(getShape(1), "AnchorType"));
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/uibase/shells/data/ole-save-preview-update.odt b/sw/qa/uibase/shells/data/ole-save-preview-update.odt
new file mode 100644
index 000000000..353ce7fa0
--- /dev/null
+++ b/sw/qa/uibase/shells/data/ole-save-preview-update.odt
Binary files differ
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 <swmodeltestbase.hxx>
+
+#include <sfx2/dispatch.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <vcl/GraphicObject.hxx>
+#include <svx/svdpage.hxx>
+#include <editeng/eeitem.hxx>
+#include <editeng/adjustitem.hxx>
+#include <editeng/outlobj.hxx>
+#include <editeng/editobj.hxx>
+
+#include <IDocumentContentOperations.hxx>
+#include <cmdid.h>
+#include <fmtanchr.hxx>
+#include <view.hxx>
+#include <wrtsh.hxx>
+#include <IDocumentDrawModelAccess.hxx>
+#include <drawdoc.hxx>
+
+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<SwXTextDocument*>(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<RES_FRMATR_BEGIN, RES_FRMATR_END - 1>{});
+ SfxItemSet aGrfSet(pDoc->GetAttrPool(), svl::Items<RES_GRFATR_BEGIN, RES_GRFATR_END - 1>{});
+ 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<SfxPoolItem> 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<sal_uInt16>(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<size_t>(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<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+ xStorable->storeToURL(maTempFile.GetURL(), {});
+ uno::Reference<packages::zip::XZipFileAccess2> 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: */