2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import lib
.MultiMethodTest
;
23 import com
.sun
.star
.lang
.XMultiServiceFactory
;
24 import com
.sun
.star
.text
.XDocumentIndex
;
25 import com
.sun
.star
.text
.XText
;
26 import com
.sun
.star
.text
.XTextContent
;
27 import com
.sun
.star
.text
.XTextDocument
;
28 import com
.sun
.star
.text
.XTextRange
;
29 import com
.sun
.star
.uno
.UnoRuntime
;
32 * Testing <code>com.sun.star.text.XDocumentIndex</code>
35 * <li><code> getServiceName()</code></li>
36 * <li><code> update()</code></li>
39 * This test needs the following object relations :
41 * <li> <code>'TextDoc'</code> (of type <code>XTextDocument</code>):
42 * the text document for creating and inserting index mark.</li>
45 * Test is <b> NOT </b> multithread compliant. <p>
46 * @see com.sun.star.text.XDocumentIndex
48 public class _XDocumentIndex
extends MultiMethodTest
{
50 public XDocumentIndex oObj
= null;
53 * Test calls the method. <p>
54 * Has <b> OK </b> status if the returned service name
55 * is equal to 'com.sun.star.text.DocumentIndex'.
57 public void _getServiceName() {
58 String serv
= oObj
.getServiceName();
59 tRes
.tested("getServiceName()",
60 serv
.equals("com.sun.star.text.DocumentIndex"));
64 * Gets the document from relation and insert a new index mark.
65 * Then it stores the text content of document index before
66 * update and after.<p>
68 * Has <b> OK </b> status if index content is changed and
69 * new index contains index mark inserted. <p>
71 public void _update() {
75 XTextDocument xTextDoc
= (XTextDocument
)
76 tEnv
.getObjRelation("TextDoc");
77 XText xText
= xTextDoc
.getText();
78 XTextRange xTR
= xText
.getEnd();
79 xTR
.setString("IndexMark");
81 XMultiServiceFactory xDocMSF
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
83 Object idxMark
= xDocMSF
.createInstance
84 ("com.sun.star.text.DocumentIndexMark");
85 XTextContent xTC
= UnoRuntime
.queryInterface
86 (XTextContent
.class, idxMark
);
87 xText
.insertTextContent(xTR
, xTC
, true);
88 } catch (com
.sun
.star
.uno
.Exception e
) {
89 log
.println("Couldn't insert index mark.");
90 e
.printStackTrace(log
);
94 String contentBefore
= oObj
.getAnchor().getString();
95 log
.println("Content before: '" + contentBefore
+ "'");
102 String contentAfter
= oObj
.getAnchor().getString();
103 log
.println("Content after: '" + contentAfter
+ "'");
105 bOK
&= !contentAfter
.equals(contentBefore
);
106 bOK
&= contentAfter
.indexOf("IndexMark") > -1;
108 tRes
.tested("update()",bOK
);
113 } // finish class _XDocumentIndex