bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXDocumentIndexes.java
blobd4ff191f42f6d92aad87467c26e9b6386736beff
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.XDocumentIndexesSupplier;
31 import com.sun.star.text.XText;
32 import com.sun.star.text.XTextContent;
33 import com.sun.star.text.XTextCursor;
34 import com.sun.star.text.XTextDocument;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
39 /**
40 * Test for the object, which is represented by collection of document indexes.
41 * Object implements the following interfaces:
42 * <ul>
43 * <li> <code>com::sun::star::container::XNameAccess</code></li>
44 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
45 * <li> <code>com::sun::star::container::XElementAccess</code></li>
46 * </ul> <p>
47 * This object test <b> is NOT </b> designed to be run in several
48 * threads concurently.
49 * @see com.sun.star.container.XNameAccess
50 * @see com.sun.star.container.XIndexAccess
51 * @see com.sun.star.container.XElementAccess
52 * @see ifc.container._XNameAccess
53 * @see ifc.container._XIndexAccess
54 * @see ifc.container._XElementAccess
56 public class SwXDocumentIndexes extends TestCase {
57 XTextDocument xTextDoc;
59 /**
60 * Creates text document.
62 protected void initialize( TestParameters tParam, PrintWriter log ) {
63 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
64 try {
65 log.println( "creating a textdocument" );
66 xTextDoc = SOF.createTextDoc( null );
67 } catch ( com.sun.star.uno.Exception e ) {
68 e.printStackTrace( log );
69 throw new StatusException( "Couldn't create document", e );
73 /**
74 * Disposes text document.
76 protected void cleanup( TestParameters tParam, PrintWriter log ) {
77 log.println( " disposing xTextDoc " );
78 util.DesktopTools.closeDoc(xTextDoc);
82 /**
83 * Creating a Testenvironment for the interfaces to be tested.
84 * Creates an instance of the service
85 * <code>com.sun.star.text.ContentIndex</code>, then created content index is
86 * inserted to the text document, and finally all document indexes are gotten
87 * from a text document using <code>XDocumentIndexesSupplier</code> interface.
89 public TestEnvironment createTestEnvironment(
90 TestParameters tParam, PrintWriter log ) throws StatusException {
91 XInterface oObj = null;
92 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
94 log.println( "creating a test environment" );
95 XTextContent xTC = null;
97 try {
98 xTC = SOfficeFactory.createIndex(xTextDoc,"com.sun.star.text.ContentIndex");
100 catch ( com.sun.star.uno.Exception e) {
101 e.printStackTrace(log);
102 throw new StatusException("Couldn't create the Index", e);
105 XText oText = xTextDoc.getText();
106 XTextCursor oCursor = oText.createTextCursor();
108 log.println("inserting the Index into text document");
109 try {
110 oText.insertTextContent(oCursor, xTC, false);
111 } catch (com.sun.star.lang.IllegalArgumentException e) {
112 e.printStackTrace(log);
113 throw new StatusException("Couldn't insert the Index", e);
116 XDocumentIndexesSupplier xDocInd = UnoRuntime.queryInterface(XDocumentIndexesSupplier.class,xTextDoc);
118 oObj = xDocInd.getDocumentIndexes();
119 TestEnvironment tEnv = new TestEnvironment(oObj);
120 return tEnv;
122 } // finish method getTestEnvironment
124 } // finish class SwXDocumentIndexes