1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <cppunit/TestAssert.h>
12 #include <com/sun/star/text/XTextDocument.hpp>
13 #include <com/sun/star/text/XTextContent.hpp>
14 #include <com/sun/star/text/XText.hpp>
15 #include <com/sun/star/text/XDocumentIndex.hpp>
16 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
18 #include <test/text/xdocumentindex.hxx>
22 XDocumentIndex::~XDocumentIndex() {}
24 * Gets the document from relation and insert a new index mark.
25 * Then it stores the text content of document index before
26 * update and after.<p>
28 * Has <b> OK </b> status if index content is changed and
29 * new index contains index mark inserted. <p>
31 void XDocumentIndex::testUpdate()
33 css::uno::Reference
<css::text::XDocumentIndex
> xDocumentIndex(init(),
34 css::uno::UNO_QUERY_THROW
);
39 auto xText
= getTextDocument()->getText();
40 auto xTextRange
= xText
->getEnd();
41 xTextRange
->setString("IndexMark");
42 css::uno::Reference
<css::lang::XMultiServiceFactory
> xFactory(getTextDocument(),
43 css::uno::UNO_QUERY_THROW
);
44 css::uno::Reference
<css::text::XTextContent
> xTextContentMark(
45 xFactory
->createInstance("com.sun.star.text.DocumentIndexMark"),
46 css::uno::UNO_QUERY_THROW
);
47 xText
->insertTextContent(xTextRange
, xTextContentMark
, true);
49 catch (css::uno::Exception
/*exception*/)
54 CPPUNIT_ASSERT_MESSAGE("Couldn't create the document index mark", bOK
);
56 OUString sContentBefore
= xDocumentIndex
->getAnchor()->getString();
57 xDocumentIndex
->update();
58 OUString sContentAfter
= xDocumentIndex
->getAnchor()->getString();
60 CPPUNIT_ASSERT_MESSAGE("Before and after shouldn't be equal", sContentBefore
!= sContentAfter
);
61 CPPUNIT_ASSERT_MESSAGE("Content after should contain string 'IndexMark'",
62 sContentAfter
.indexOf("IndexMark") >= 0);
66 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */