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>
33 css::uno::Reference<css::text::XDocumentIndex> xDocumentIndex(
init(),
34 css::uno::UNO_QUERY_THROW);
40 auto xTextRange = xText->getEnd();
41 xTextRange->setString(
"IndexMark");
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 )
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);
virtual css::uno::Reference< css::uno::XInterface > init()=0
virtual css::uno::Reference< css::text::XTextDocument > getTextDocument()=0
virtual ~XDocumentIndex()
void testUpdate()
Gets the document from relation and insert a new index mark.
Reference< XSingleServiceFactory > xFactory