LibreOffice Module test (master) 1
xdocumentindex.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
10#include <cppunit/TestAssert.h>
11
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>
17
19
20namespace apitest
21{
32{
33 css::uno::Reference<css::text::XDocumentIndex> xDocumentIndex(init(),
34 css::uno::UNO_QUERY_THROW);
35
36 bool bOK = true;
37 try
38 {
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);
48 }
49 catch (css::uno::Exception /*exception*/)
50 {
51 bOK = false;
52 }
53
54 CPPUNIT_ASSERT_MESSAGE("Couldn't create the document index mark", bOK);
55
56 OUString sContentBefore = xDocumentIndex->getAnchor()->getString();
57 xDocumentIndex->update();
58 OUString sContentAfter = xDocumentIndex->getAnchor()->getString();
59
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);
63}
64}
65
66/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< css::uno::XInterface > init()=0
virtual css::uno::Reference< css::text::XTextDocument > getTextDocument()=0
void testUpdate()
Gets the document from relation and insert a new index mark.
Reference< XSingleServiceFactory > xFactory