1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XDocumentIndex.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import com
.sun
.star
.lang
.XMultiServiceFactory
;
36 import com
.sun
.star
.text
.XDocumentIndex
;
37 import com
.sun
.star
.text
.XText
;
38 import com
.sun
.star
.text
.XTextContent
;
39 import com
.sun
.star
.text
.XTextDocument
;
40 import com
.sun
.star
.text
.XTextRange
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
44 * Testing <code>com.sun.star.text.XDocumentIndex</code>
47 * <li><code> getServiceName()</code></li>
48 * <li><code> update()</code></li>
51 * This test needs the following object relations :
53 * <li> <code>'TextDoc'</code> (of type <code>XTextDocument</code>):
54 * the text document for creating and inserting index mark.</li>
57 * Test is <b> NOT </b> multithread compilant. <p>
58 * @see com.sun.star.text.XDocumentIndex
60 public class _XDocumentIndex
extends MultiMethodTest
{
62 public XDocumentIndex oObj
= null;
65 * Test calls the method. <p>
66 * Has <b> OK </b> status if the retruned service name
67 * is equal to 'com.sun.star.text.DocumentIndex'.
69 public void _getServiceName() {
70 String serv
= oObj
.getServiceName();
71 tRes
.tested("getServiceName()",
72 serv
.equals("com.sun.star.text.DocumentIndex"));
76 * Gets the document from relation and insert a new index mark.
77 * Then it stores the text content of document index before
78 * update and after.<p>
80 * Has <b> OK </b> status if index content is changed and
81 * new index contains index mark inserted. <p>
83 public void _update() {
87 XTextDocument xTextDoc
= (XTextDocument
)
88 tEnv
.getObjRelation("TextDoc");
89 XText xText
= xTextDoc
.getText();
90 XTextRange xTR
= xText
.getEnd();
91 xTR
.setString("IndexMark");
93 XMultiServiceFactory xDocMSF
= (XMultiServiceFactory
)
94 UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
96 Object idxMark
= xDocMSF
.createInstance
97 ("com.sun.star.text.DocumentIndexMark");
98 XTextContent xTC
= (XTextContent
) UnoRuntime
.queryInterface
99 (XTextContent
.class, idxMark
);
100 xText
.insertTextContent(xTR
, xTC
, true);
101 } catch (com
.sun
.star
.uno
.Exception e
) {
102 log
.println("Couldn't insert index mark.");
103 e
.printStackTrace(log
);
107 String contentBefore
= oObj
.getAnchor().getString();
108 log
.println("Content before: '" + contentBefore
+ "'");
115 catch (InterruptedException ex
) {
119 String contentAfter
= oObj
.getAnchor().getString();
120 log
.println("Content after: '" + contentAfter
+ "'");
122 bOK
&= !contentAfter
.equals(contentBefore
);
123 bOK
&= contentAfter
.indexOf("IndexMark") > -1;
125 tRes
.tested("update()",bOK
);
130 } // finish class _XDocumentIndex