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.ControlCharacter; 40 import com.sun.star.text.XText; 41 import com.sun.star.text.XTextCursor; 42 import com.sun.star.text.XTextDocument; 43 import com.sun.star.uno.UnoRuntime; 44 import com.sun.star.uno.XInterface; 45 import com.sun.star.util.XSearchDescriptor; 46 import com.sun.star.util.XSearchable; 47 48 /** 49 * 50 * initial description 51 * @see com.sun.star.container.XElementAccess 52 * @see com.sun.star.container.XIndexAccess 53 * 54 */ 55 public class SwXTextRanges extends TestCase { 56 XTextDocument xTextDoc; 57 58 protected void initialize( TestParameters tParam, PrintWriter log ) { 59 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 60 61 try { 62 log.println( "creating a textdocument" ); 63 xTextDoc = SOF.createTextDoc( null ); 64 } catch ( com.sun.star.uno.Exception e ) { 65 // Some exception occures.FAILED 66 e.printStackTrace( log ); 67 throw new StatusException( "Couldn't create document", e ); 68 } 69 } 70 71 protected void cleanup( TestParameters tParam, PrintWriter log ) { 72 log.println( " disposing xTextDoc " ); 73 util.DesktopTools.closeDoc(xTextDoc); 74 } 75 76 /** 77 * creating a Testenvironment for the interfaces to be tested 78 * 79 * @param tParam class which contains additional test parameters 80 * @param log class to log the test state and result 81 * 82 * @return Status class 83 * 84 * @see TestParameters 85 * @see PrintWriter 86 */ 87 public synchronized TestEnvironment createTestEnvironment 88 (TestParameters tParam, PrintWriter log) { 89 90 XInterface oObj = null; 91 92 // creation of testobject here 93 // first we write what we are intend to do to log file 94 log.println( "creating a test environment" ); 95 96 // create testobject here 97 XText oText = xTextDoc.getText(); 98 XTextCursor oCursor = oText.createTextCursor(); 99 100 for (int j =0; j < 5; j++){ 101 try{ 102 oText.insertString( oCursor, 103 "SwXTextRanges...SwXTextRanges...SwXTextRanges", false); 104 oText.insertControlCharacter( oCursor, 105 ControlCharacter.PARAGRAPH_BREAK, false ); 106 } 107 catch( Exception e ){ 108 log.println( "EXCEPTION: " + e); 109 } 110 } 111 112 XSearchable oSearch = (XSearchable)UnoRuntime.queryInterface 113 (XSearchable.class, xTextDoc); 114 XSearchDescriptor xSDesc = oSearch.createSearchDescriptor(); 115 xSDesc.setSearchString("SwXTextRanges"); 116 117 oObj = oSearch.findAll(xSDesc); 118 119 log.println( "creating a new environment for textrange object" ); 120 TestEnvironment tEnv = new TestEnvironment( oObj ); 121 122 log.println( "adding TextDocument as mod relation to environment" ); 123 tEnv.addObjRelation("TEXTDOC", xTextDoc); 124 125 return tEnv; 126 } // finish method getTestEnvironment 127 128 } // finish class SwXTextRanges 129 130