1 /*
2  * This file is part of the LibreOffice project.
3  *
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/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
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 .
17  */
18 
19 package mod._sw;
20 
21 import java.io.PrintWriter;
22 
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.SOfficeFactory;
27 
28 import com.sun.star.text.XText;
29 import com.sun.star.text.XTextContent;
30 import com.sun.star.text.XTextCursor;
31 import com.sun.star.text.XTextRange;
32 import com.sun.star.text.XTextDocument;
33 import com.sun.star.uno.UnoRuntime;
34 
35 
36 /**
37  * Test for object which is represented by service
38  * <code>com.sun.star.text.DocumentIndex</code>. <p>
39  * Object implements the following interfaces :
40  * <ul>
41  *  <li> <code>com::sun::star::lang::XComponent</code></li>
42  *  <li> <code>com::sun::star::text::XDocumentIndex</code></li>
43  *  <li> <code>com::sun::star::text::BaseIndex</code></li>
44  *  <li> <code>com::sun::star::text::XTextContent</code></li>
45  *  <li> <code>com::sun::star::text::DocumentIndex</code></li>
46  * </ul> <p>
47  * This object test <b> is NOT </b> designed to be run in several
48  * threads concurrently.
49  * @see com.sun.star.lang.XComponent
50  * @see com.sun.star.text.XDocumentIndex
51  * @see com.sun.star.text.BaseIndex
52  * @see com.sun.star.text.XTextContent
53  * @see com.sun.star.text.DocumentIndex
54  * @see ifc.lang._XComponent
55  * @see ifc.text._XDocumentIndex
56  * @see ifc.text._BaseIndex
57  * @see ifc.text._XTextContent
58  * @see ifc.text._DocumentIndex
59  */
60 public class SwXDocumentIndex extends TestCase {
61     XTextDocument xTextDoc;
62 
63     /**
64     * Creates text document.
65     */
66     @Override
initialize( TestParameters tParam, PrintWriter log )67     protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
68         SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
69         log.println( "creating a textdocument" );
70         xTextDoc = SOF.createTextDoc( null );
71     }
72 
73     /**
74     * Disposes text document.
75     */
76     @Override
cleanup( TestParameters tParam, PrintWriter log )77     protected void cleanup( TestParameters tParam, PrintWriter log ) {
78         log.println( "    disposing xTextDoc " );
79         util.DesktopTools.closeDoc(xTextDoc);
80     }
81 
82     /**
83     * Creating a TestEnvironment for the interfaces to be tested.
84     * Creates an instance of the service
85     * <code>com.sun.star.text.DocumentIndex</code>, then created document index
86     * is inserted to the text of the document as content.
87     *
88     */
89     @Override
createTestEnvironment(TestParameters tParam, PrintWriter log)90     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) throws Exception {
91         XTextContent xTC = null;
92         Object instance = null;
93 
94         SOfficeFactory.getFactory(tParam.getMSF());
95         log.println( "creating a test environment" );
96         xTC = SOfficeFactory.createIndex(xTextDoc, "com.sun.star.text.DocumentIndex");
97         instance = SOfficeFactory.createIndex(xTextDoc, "com.sun.star.text.DocumentIndex");
98 
99         XText oText = xTextDoc.getText();
100         XTextCursor oCursor = oText.createTextCursor();
101 
102         log.println("inserting the Index into text document");
103         oText.insertTextContent(oCursor, xTC, false);
104 
105         TestEnvironment tEnv = new TestEnvironment(xTC);
106 
107         tEnv.addObjRelation("CONTENT", UnoRuntime.queryInterface(XTextContent.class,instance));
108         oCursor.gotoEnd(false);
109         tEnv.addObjRelation("RANGE", UnoRuntime.queryInterface(XTextRange.class, oCursor));
110 
111         // relation for XDocumentIndex
112         tEnv.addObjRelation("TextDoc", xTextDoc);
113 
114         return tEnv;
115     } // finish method getTestEnvironment
116 
117 }    // finish class SwXDocumentIndex
118 
119