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 java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.text
.XText
;
30 import com
.sun
.star
.text
.XTextContent
;
31 import com
.sun
.star
.text
.XTextCursor
;
32 import com
.sun
.star
.text
.XTextRange
;
33 import com
.sun
.star
.text
.XTextDocument
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
38 * Test for object which is represented by service
39 * <code>com.sun.star.text.DocumentIndex</code>. <p>
40 * Object implements the following interfaces :
42 * <li> <code>com::sun::star::lang::XComponent</code></li>
43 * <li> <code>com::sun::star::text::XDocumentIndex</code></li>
44 * <li> <code>com::sun::star::text::BaseIndex</code></li>
45 * <li> <code>com::sun::star::text::XTextContent</code></li>
46 * <li> <code>com::sun::star::text::DocumentIndex</code></li>
48 * This object test <b> is NOT </b> designed to be run in several
49 * threads concurently.
50 * @see com.sun.star.lang.XComponent
51 * @see com.sun.star.text.XDocumentIndex
52 * @see com.sun.star.text.BaseIndex
53 * @see com.sun.star.text.XTextContent
54 * @see com.sun.star.text.DocumentIndex
55 * @see ifc.lang._XComponent
56 * @see ifc.text._XDocumentIndex
57 * @see ifc.text._BaseIndex
58 * @see ifc.text._XTextContent
59 * @see ifc.text._DocumentIndex
61 public class SwXDocumentIndex
extends TestCase
{
62 XTextDocument xTextDoc
;
65 * Creates text document.
68 protected void initialize( TestParameters tParam
, PrintWriter log
) {
69 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
71 log
.println( "creating a textdocument" );
72 xTextDoc
= SOF
.createTextDoc( null );
73 } catch ( com
.sun
.star
.uno
.Exception e
) {
74 e
.printStackTrace( log
);
75 throw new StatusException( "Couldn't create document", e
);
80 * Disposes text document.
83 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
84 log
.println( " disposing xTextDoc " );
85 util
.DesktopTools
.closeDoc(xTextDoc
);
89 * Creating a Testenvironment for the interfaces to be tested.
90 * Creates an instance of the service
91 * <code>com.sun.star.text.DocumentIndex</code>, then created document index
92 * is inserted to the text of the document as content.
96 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
97 XTextContent xTC
= null;
98 Object instance
= null;
100 SOfficeFactory
.getFactory(tParam
.getMSF());
101 log
.println( "creating a test environment" );
103 xTC
= SOfficeFactory
.createIndex(xTextDoc
, "com.sun.star.text.DocumentIndex");
104 instance
= SOfficeFactory
.createIndex(xTextDoc
, "com.sun.star.text.DocumentIndex");
106 catch ( com
.sun
.star
.uno
.Exception e
) {
107 e
.printStackTrace(log
);
108 throw new StatusException("Couldn't create the Index", e
);
111 XText oText
= xTextDoc
.getText();
112 XTextCursor oCursor
= oText
.createTextCursor();
114 log
.println("inserting the Index into text document");
116 oText
.insertTextContent(oCursor
, xTC
, false);
117 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
118 e
.printStackTrace(log
);
119 throw new StatusException("Couldn't insert the Index", e
);
122 TestEnvironment tEnv
= new TestEnvironment(xTC
);
124 tEnv
.addObjRelation("CONTENT", UnoRuntime
.queryInterface(XTextContent
.class,instance
));
125 oCursor
.gotoEnd(false);
126 tEnv
.addObjRelation("RANGE", UnoRuntime
.queryInterface(XTextRange
.class, oCursor
));
128 // relation for XDocumentIndex
129 tEnv
.addObjRelation("TextDoc", xTextDoc
);
132 } // finish method getTestEnvironment
134 } // finish class SwXDocumentIndex