1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package mod._sw; 29 30 import java.io.PrintWriter; 31 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.SOfficeFactory; 37 38 import com.sun.star.lang.XMultiServiceFactory; 39 import com.sun.star.text.XText; 40 import com.sun.star.text.XTextContent; 41 import com.sun.star.text.XTextCursor; 42 import com.sun.star.text.XTextRange; 43 import com.sun.star.text.XTextDocument; 44 import com.sun.star.uno.UnoRuntime; 45 46 47 /** 48 * Test for object which is represented by service 49 * <code>com.sun.star.text.DocumentIndex</code>. <p> 50 * Object implements the following interfaces : 51 * <ul> 52 * <li> <code>com::sun::star::lang::XComponent</code></li> 53 * <li> <code>com::sun::star::text::XDocumentIndex</code></li> 54 * <li> <code>com::sun::star::text::BaseIndex</code></li> 55 * <li> <code>com::sun::star::text::XTextContent</code></li> 56 * <li> <code>com::sun::star::text::DocumentIndex</code></li> 57 * </ul> <p> 58 * This object test <b> is NOT </b> designed to be run in several 59 * threads concurently. 60 * @see com.sun.star.lang.XComponent 61 * @see com.sun.star.text.XDocumentIndex 62 * @see com.sun.star.text.BaseIndex 63 * @see com.sun.star.text.XTextContent 64 * @see com.sun.star.text.DocumentIndex 65 * @see ifc.lang._XComponent 66 * @see ifc.text._XDocumentIndex 67 * @see ifc.text._BaseIndex 68 * @see ifc.text._XTextContent 69 * @see ifc.text._DocumentIndex 70 */ 71 public class SwXDocumentIndex extends TestCase { 72 XTextDocument xTextDoc; 73 74 /** 75 * Creates text document. 76 */ 77 protected void initialize( TestParameters tParam, PrintWriter log ) { 78 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 79 try { 80 log.println( "creating a textdocument" ); 81 xTextDoc = SOF.createTextDoc( null ); 82 } catch ( com.sun.star.uno.Exception e ) { 83 e.printStackTrace( log ); 84 throw new StatusException( "Couldn't create document", e ); 85 } 86 } 87 88 /** 89 * Disposes text document. 90 */ 91 protected void cleanup( TestParameters tParam, PrintWriter log ) { 92 log.println( " disposing xTextDoc " ); 93 util.DesktopTools.closeDoc(xTextDoc); 94 } 95 96 /** 97 * Creating a Testenvironment for the interfaces to be tested. 98 * Creates an instance of the service 99 * <code>com.sun.star.text.DocumentIndex</code>, then created document index 100 * is inserted to the text of the document as content. 101 * 102 */ 103 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { 104 XTextContent xTC = null; 105 Object instance = null; 106 107 SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF()); 108 log.println( "creating a test environment" ); 109 try { 110 xTC = SOF.createIndex(xTextDoc, "com.sun.star.text.DocumentIndex"); 111 instance = SOF.createIndex(xTextDoc, "com.sun.star.text.DocumentIndex"); 112 } 113 catch ( com.sun.star.uno.Exception e) { 114 e.printStackTrace(log); 115 throw new StatusException("Couldn't create the Index", e); 116 } 117 118 XText oText = xTextDoc.getText(); 119 XTextCursor oCursor = oText.createTextCursor(); 120 121 log.println("inserting the Index into text document"); 122 try { 123 oText.insertTextContent(oCursor, xTC, false); 124 } catch (com.sun.star.uno.Exception e) { 125 e.printStackTrace(log); 126 throw new StatusException("Couldn't insert the Index", e); 127 } 128 129 TestEnvironment tEnv = new TestEnvironment(xTC); 130 131 tEnv.addObjRelation("CONTENT", (XTextContent) 132 UnoRuntime.queryInterface(XTextContent.class,instance)); 133 oCursor.gotoEnd(false); 134 tEnv.addObjRelation("RANGE", (XTextRange) 135 UnoRuntime.queryInterface(XTextRange.class, oCursor)); 136 137 // relation for XDocumentIndex 138 tEnv.addObjRelation("TextDoc", xTextDoc); 139 140 return tEnv; 141 } // finish method getTestEnvironment 142 143 } // finish class SwXDocumentIndex 144 145