/* -*- 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/. */ #ifndef INCLUDED_SW_QA_API_XDOCUMENTINDEXTEST_HXX #define INCLUDED_SW_QA_API_XDOCUMENTINDEXTEST_HXX #include "ApiTestBase.hxx" #include #include #include #include #include #include #include namespace apitest { class XDocumentIndexTest : public ApiTestBase { public: /** * Test calls the method.

* Has OK status if the returned service name * is equal to 'com.sun.star.text.DocumentIndex'. */ void testGetServiceName() { auto inputMap = init(); css::uno::Reference xDocumentIndex( inputMap["text::XDocumentIndex"], css::uno::UNO_QUERY_THROW); CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.text.DocumentIndex"), xDocumentIndex->getServiceName()); } /** * 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 testUpdate() { auto inputMap = init(); css::uno::Reference xDocumentIndex( inputMap["text::XDocumentIndex"], css::uno::UNO_QUERY_THROW); css::uno::Reference xTextDocument(inputMap["text::XTextDocument"], css::uno::UNO_QUERY_THROW); bool bOK = true; try { css::uno::Reference xText = xTextDocument->getText(); css::uno::Reference xTextRange = xText->getEnd(); xTextRange->setString("IndexMark"); css::uno::Reference xFactory( xTextDocument, 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); } }; } #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */