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._sc; 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.container.XIndexAccess; 39 import com.sun.star.lang.XComponent; 40 import com.sun.star.lang.XMultiServiceFactory; 41 import com.sun.star.sheet.XSpreadsheet; 42 import com.sun.star.sheet.XSpreadsheetDocument; 43 import com.sun.star.sheet.XSpreadsheets; 44 import com.sun.star.uno.AnyConverter; 45 import com.sun.star.uno.Type; 46 import com.sun.star.uno.UnoRuntime; 47 import com.sun.star.uno.XInterface; 48 import com.sun.star.util.XSearchable; 49 50 /** 51 * Test for object which is represented by service 52 * <code>com.sun.star.util.SearchDescriptor</code> that was implemented by 53 * a spreadsheet. <p> 54 * Object implements the following interfaces : 55 * <ul> 56 * <li> <code>com::sun::star::util::XSearchDescriptor</code></li> 57 * <li> <code>com::sun::star::util::SearchDescriptor</code></li> 58 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 59 * <li> <code>com::sun::star::util::XReplaceDescriptor</code></li> 60 * </ul> 61 * @see com.sun.star.util.SearchDescriptor 62 * @see com.sun.star.util.XSearchDescriptor 63 * @see com.sun.star.util.SearchDescriptor 64 * @see com.sun.star.beans.XPropertySet 65 * @see com.sun.star.util.XReplaceDescriptor 66 * @see ifc.util._XSearchDescriptor 67 * @see ifc.util._SearchDescriptor 68 * @see ifc.beans._XPropertySet 69 * @see ifc.util._XReplaceDescriptor 70 */ 71 public class ScCellSearchObj extends TestCase { 72 static XSpreadsheetDocument xSheetDoc = null; 73 74 /** 75 * Creates Spreadsheet document. 76 */ 77 protected void initialize( TestParameters tParam, PrintWriter log ) { 78 // get a soffice factory object 79 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 80 81 try { 82 log.println( "creating a sheetdocument" ); 83 xSheetDoc = SOF.createCalcDoc(null);; 84 } catch (com.sun.star.uno.Exception e) { 85 // Some exception occures.FAILED 86 e.printStackTrace( log ); 87 throw new StatusException( "Couldn't create document", e ); 88 } 89 } 90 91 /** 92 * Disposes Spreadsheet document. 93 */ 94 protected void cleanup( TestParameters tParam, PrintWriter log ) { 95 log.println( " disposing xSheetDoc " ); 96 XComponent oComp = (XComponent) 97 UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ; 98 util.DesktopTools.closeDoc(oComp); 99 } 100 101 /** 102 * Creating a Testenvironment for the interfaces to be tested. 103 * Retrieves a collection of spreadsheets from a document, 104 * and takes one of them. Creates search descriptor using the interface 105 * <code>XSearchable</code>. The created search descriptor is instance of 106 * the service <code>com.sun.star.util.SearchDescriptor</code> that 107 * implemented by a spreasheet. 108 * @see com.sun.star.util.XSearchable 109 */ 110 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { 111 112 XInterface oObj = null; 113 114 // creation of testobject here 115 // first we write what we are intend to do to log file 116 log.println( "creating a test environment" ); 117 118 log.println("getting sheets"); 119 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSheetDoc.getSheets(); 120 121 log.println("getting a sheet"); 122 XSpreadsheet oSheet = null; 123 XIndexAccess oIndexAccess = (XIndexAccess) 124 UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets); 125 126 try { 127 oSheet = (XSpreadsheet) AnyConverter.toObject( 128 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0)); 129 } catch (com.sun.star.lang.WrappedTargetException e) { 130 e.printStackTrace(log); 131 throw new StatusException( "Couldn't get a spreadsheet", e); 132 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 133 e.printStackTrace(log); 134 throw new StatusException( "Couldn't get a spreadsheet", e); 135 } catch (com.sun.star.lang.IllegalArgumentException e) { 136 e.printStackTrace(log); 137 throw new StatusException( "Couldn't get a spreadsheet", e); 138 } 139 140 XSearchable xSearch = (XSearchable) 141 UnoRuntime.queryInterface(XSearchable.class,oSheet); 142 143 oObj = xSearch.createSearchDescriptor(); 144 // create testobject here 145 log.println("creating a new environment for object"); 146 TestEnvironment tEnv = new TestEnvironment(oObj); 147 148 return tEnv; 149 } // finish method getTestEnvironment 150 } // finish class ScCellSearchObj 151 152