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.XDocumentIndexesSupplier; 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.XTextDocument; 33 import com.sun.star.uno.UnoRuntime; 34 import com.sun.star.uno.XInterface; 35 36 37 /** 38 * Test for the object, which is represented by collection of document indexes. 39 * Object implements the following interfaces: 40 * <ul> 41 * <li> <code>com::sun::star::container::XNameAccess</code></li> 42 * <li> <code>com::sun::star::container::XIndexAccess</code></li> 43 * <li> <code>com::sun::star::container::XElementAccess</code></li> 44 * </ul> <p> 45 * This object test <b> is NOT </b> designed to be run in several 46 * threads concurrently. 47 * @see com.sun.star.container.XNameAccess 48 * @see com.sun.star.container.XIndexAccess 49 * @see com.sun.star.container.XElementAccess 50 * @see ifc.container._XNameAccess 51 * @see ifc.container._XIndexAccess 52 * @see ifc.container._XElementAccess 53 */ 54 public class SwXDocumentIndexes extends TestCase { 55 XTextDocument xTextDoc; 56 57 /** 58 * Creates text document. 59 */ 60 @Override initialize( TestParameters tParam, PrintWriter log )61 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception { 62 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() ); 63 log.println( "creating a textdocument" ); 64 xTextDoc = SOF.createTextDoc( null ); 65 } 66 67 /** 68 * Disposes text document. 69 */ 70 @Override cleanup( TestParameters tParam, PrintWriter log )71 protected void cleanup( TestParameters tParam, PrintWriter log ) { 72 log.println( " disposing xTextDoc " ); 73 util.DesktopTools.closeDoc(xTextDoc); 74 } 75 76 77 /** 78 * Creating a TestEnvironment for the interfaces to be tested. 79 * Creates an instance of the service 80 * <code>com.sun.star.text.ContentIndex</code>, then created content index is 81 * inserted to the text document, and finally all document indexes are gotten 82 * from a text document using <code>XDocumentIndexesSupplier</code> interface. 83 */ 84 @Override createTestEnvironment( TestParameters tParam, PrintWriter log )85 public TestEnvironment createTestEnvironment( 86 TestParameters tParam, PrintWriter log ) throws Exception { 87 XInterface oObj = null; 88 SOfficeFactory.getFactory( tParam.getMSF() ); 89 90 log.println( "creating a test environment" ); 91 XTextContent xTC = SOfficeFactory.createIndex(xTextDoc,"com.sun.star.text.ContentIndex"); 92 93 XText oText = xTextDoc.getText(); 94 XTextCursor oCursor = oText.createTextCursor(); 95 96 log.println("inserting the Index into text document"); 97 oText.insertTextContent(oCursor, xTC, false); 98 99 XDocumentIndexesSupplier xDocInd = UnoRuntime.queryInterface(XDocumentIndexesSupplier.class,xTextDoc); 100 101 oObj = xDocInd.getDocumentIndexes(); 102 TestEnvironment tEnv = new TestEnvironment(oObj); 103 return tEnv; 104 105 } // finish method getTestEnvironment 106 107 } // finish class SwXDocumentIndexes 108 109