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 --- test/source/text/xdocumentindex.cxx | 66 +++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 test/source/text/xdocumentindex.cxx (limited to 'test/source/text/xdocumentindex.cxx') diff --git a/test/source/text/xdocumentindex.cxx b/test/source/text/xdocumentindex.cxx new file mode 100644 index 000000000..9f9ad73c8 --- /dev/null +++ b/test/source/text/xdocumentindex.cxx @@ -0,0 +1,66 @@ +/* -*- 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 + +namespace apitest +{ +XDocumentIndex::~XDocumentIndex() {} +/** + * Gets the document from relation and insert a new index mark. + * Then it stores the text content of document index before + * update and after.

+ * + * Has OK status if index content is changed and + * new index contains index mark inserted.

+ */ +void XDocumentIndex::testUpdate() +{ + css::uno::Reference xDocumentIndex(init(), + css::uno::UNO_QUERY_THROW); + + bool bOK = true; + try + { + auto xText = getTextDocument()->getText(); + auto xTextRange = xText->getEnd(); + xTextRange->setString("IndexMark"); + css::uno::Reference xFactory(getTextDocument(), + css::uno::UNO_QUERY_THROW); + css::uno::Reference xTextContentMark( + xFactory->createInstance("com.sun.star.text.DocumentIndexMark"), + css::uno::UNO_QUERY_THROW); + xText->insertTextContent(xTextRange, xTextContentMark, true); + } + catch (css::uno::Exception /*exception*/) + { + bOK = false; + } + + CPPUNIT_ASSERT_MESSAGE("Couldn't create the document index mark", bOK); + + OUString sContentBefore = xDocumentIndex->getAnchor()->getString(); + xDocumentIndex->update(); + OUString sContentAfter = xDocumentIndex->getAnchor()->getString(); + + CPPUNIT_ASSERT_MESSAGE("Before and after shouldn't be equal", sContentBefore != sContentAfter); + CPPUNIT_ASSERT_MESSAGE("Content after should contain string 'IndexMark'", + sContentAfter.indexOf("IndexMark") >= 0); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3