diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /sw/qa/core/doc/doc.cxx | |
parent | Initial commit. (diff) | |
download | libreoffice-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/core/doc/doc.cxx')
-rw-r--r-- | sw/qa/core/doc/doc.cxx | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/sw/qa/core/doc/doc.cxx b/sw/qa/core/doc/doc.cxx new file mode 100644 index 000000000..a8489e01a --- /dev/null +++ b/sw/qa/core/doc/doc.cxx @@ -0,0 +1,87 @@ +/* -*- 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 <comphelper/classids.hxx> +#include <tools/globname.hxx> +#include <svtools/embedhlp.hxx> +#include <editeng/frmdiritem.hxx> +#include <vcl/errinf.hxx> + +#include <wrtsh.hxx> +#include <fmtanchr.hxx> +#include <frameformats.hxx> + +static char const DATA_DIRECTORY[] = "/sw/qa/core/doc/data/"; + +/// Covers sw/source/core/doc/ fixes. +class SwCoreDocTest : public SwModelTestBase +{ +public: + SwDoc* createDoc(const char* pName = nullptr); +}; + +SwDoc* SwCoreDocTest::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(SwCoreDocTest, testMathInsertAnchorType) +{ + // Given an empty document. + SwDoc* pDoc = createDoc(); + + // When inserting an a math object. + SwWrtShell* pShell = pDoc->GetDocShell()->GetWrtShell(); + SvGlobalName aGlobalName(SO3_SM_CLASSID); + pShell->InsertObject(svt::EmbeddedObjectRef(), &aGlobalName); + + // Then the anchor type should be as-char. + SwFrameFormats& rFormats = *pDoc->GetSpzFrameFormats(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rFormats.size()); + const SwFrameFormat& rFormat = *rFormats[0]; + const SwFormatAnchor& rAnchor = rFormat.GetAnchor(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 4 + // i.e. the anchor type was at-char, not as-char. + CPPUNIT_ASSERT_EQUAL(RndStdIds::FLY_AS_CHAR, rAnchor.GetAnchorId()); + ErrorRegistry::Reset(); +} + +CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testTextboxTextRotateAngle) +{ + // Check the writing direction of the only TextFrame in the document. + SwDoc* pDoc = createDoc("textbox-textrotateangle.odt"); + SwFrameFormats& rFrameFormats = *pDoc->GetSpzFrameFormats(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rFrameFormats.size()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(RES_DRAWFRMFMT), rFrameFormats[0]->Which()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(RES_FLYFRMFMT), rFrameFormats[1]->Which()); + SvxFrameDirection eActual = rFrameFormats[1]->GetAttrSet().GetItem(RES_FRAMEDIR)->GetValue(); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 5 (btlr) + // - Actual : 0 (lrtb) + // i.e. the writing direction was in the ODT file, but it was lost on import in the textbox + // case. + CPPUNIT_ASSERT_EQUAL(SvxFrameDirection::Vertical_LR_BT, eActual); + ErrorRegistry::Reset(); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |