bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXDocumentIndex.java
blob8111ea596bf45cd1bcafe53418d5dc17d4bdde58
1 /*
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 .
19 package mod._sw;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.lang.XMultiServiceFactory;
30 import com.sun.star.text.XText;
31 import com.sun.star.text.XTextContent;
32 import com.sun.star.text.XTextCursor;
33 import com.sun.star.text.XTextRange;
34 import com.sun.star.text.XTextDocument;
35 import com.sun.star.uno.UnoRuntime;
38 /**
39 * Test for object which is represented by service
40 * <code>com.sun.star.text.DocumentIndex</code>. <p>
41 * Object implements the following interfaces :
42 * <ul>
43 * <li> <code>com::sun::star::lang::XComponent</code></li>
44 * <li> <code>com::sun::star::text::XDocumentIndex</code></li>
45 * <li> <code>com::sun::star::text::BaseIndex</code></li>
46 * <li> <code>com::sun::star::text::XTextContent</code></li>
47 * <li> <code>com::sun::star::text::DocumentIndex</code></li>
48 * </ul> <p>
49 * This object test <b> is NOT </b> designed to be run in several
50 * threads concurently.
51 * @see com.sun.star.lang.XComponent
52 * @see com.sun.star.text.XDocumentIndex
53 * @see com.sun.star.text.BaseIndex
54 * @see com.sun.star.text.XTextContent
55 * @see com.sun.star.text.DocumentIndex
56 * @see ifc.lang._XComponent
57 * @see ifc.text._XDocumentIndex
58 * @see ifc.text._BaseIndex
59 * @see ifc.text._XTextContent
60 * @see ifc.text._DocumentIndex
62 public class SwXDocumentIndex extends TestCase {
63 XTextDocument xTextDoc;
65 /**
66 * Creates text document.
68 protected void initialize( TestParameters tParam, PrintWriter log ) {
69 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
70 try {
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 );
79 /**
80 * Disposes text document.
82 protected void cleanup( TestParameters tParam, PrintWriter log ) {
83 log.println( " disposing xTextDoc " );
84 util.DesktopTools.closeDoc(xTextDoc);
87 /**
88 * Creating a Testenvironment for the interfaces to be tested.
89 * Creates an instance of the service
90 * <code>com.sun.star.text.DocumentIndex</code>, then created document index
91 * is inserted to the text of the document as content.
94 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
95 XTextContent xTC = null;
96 Object instance = null;
98 SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF());
99 log.println( "creating a test environment" );
100 try {
101 xTC = SOfficeFactory.createIndex(xTextDoc, "com.sun.star.text.DocumentIndex");
102 instance = SOfficeFactory.createIndex(xTextDoc, "com.sun.star.text.DocumentIndex");
104 catch ( com.sun.star.uno.Exception e) {
105 e.printStackTrace(log);
106 throw new StatusException("Couldn't create the Index", e);
109 XText oText = xTextDoc.getText();
110 XTextCursor oCursor = oText.createTextCursor();
112 log.println("inserting the Index into text document");
113 try {
114 oText.insertTextContent(oCursor, xTC, false);
115 } catch (com.sun.star.lang.IllegalArgumentException e) {
116 e.printStackTrace(log);
117 throw new StatusException("Couldn't insert the Index", e);
120 TestEnvironment tEnv = new TestEnvironment(xTC);
122 tEnv.addObjRelation("CONTENT", UnoRuntime.queryInterface(XTextContent.class,instance));
123 oCursor.gotoEnd(false);
124 tEnv.addObjRelation("RANGE", UnoRuntime.queryInterface(XTextRange.class, oCursor));
126 // relation for XDocumentIndex
127 tEnv.addObjRelation("TextDoc", xTextDoc);
129 return tEnv;
130 } // finish method getTestEnvironment
132 } // finish class SwXDocumentIndex