merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScCellSearchObj.java
blob7b112e5152ca4ad57b5bde456a61f89cd63494ff
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScCellSearchObj.java,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._sc;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.SOfficeFactory;
41 import com.sun.star.container.XIndexAccess;
42 import com.sun.star.lang.XComponent;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.sheet.XSpreadsheet;
45 import com.sun.star.sheet.XSpreadsheetDocument;
46 import com.sun.star.sheet.XSpreadsheets;
47 import com.sun.star.uno.AnyConverter;
48 import com.sun.star.uno.Type;
49 import com.sun.star.uno.UnoRuntime;
50 import com.sun.star.uno.XInterface;
51 import com.sun.star.util.XSearchable;
53 /**
54 * Test for object which is represented by service
55 * <code>com.sun.star.util.SearchDescriptor</code> that was implemented by
56 * a spreadsheet. <p>
57 * Object implements the following interfaces :
58 * <ul>
59 * <li> <code>com::sun::star::util::XSearchDescriptor</code></li>
60 * <li> <code>com::sun::star::util::SearchDescriptor</code></li>
61 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
62 * <li> <code>com::sun::star::util::XReplaceDescriptor</code></li>
63 * </ul>
64 * @see com.sun.star.util.SearchDescriptor
65 * @see com.sun.star.util.XSearchDescriptor
66 * @see com.sun.star.util.SearchDescriptor
67 * @see com.sun.star.beans.XPropertySet
68 * @see com.sun.star.util.XReplaceDescriptor
69 * @see ifc.util._XSearchDescriptor
70 * @see ifc.util._SearchDescriptor
71 * @see ifc.beans._XPropertySet
72 * @see ifc.util._XReplaceDescriptor
74 public class ScCellSearchObj extends TestCase {
75 static XSpreadsheetDocument xSheetDoc = null;
77 /**
78 * Creates Spreadsheet document.
80 protected void initialize( TestParameters tParam, PrintWriter log ) {
81 // get a soffice factory object
82 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
84 try {
85 log.println( "creating a sheetdocument" );
86 xSheetDoc = SOF.createCalcDoc(null);;
87 } catch (com.sun.star.uno.Exception e) {
88 // Some exception occures.FAILED
89 e.printStackTrace( log );
90 throw new StatusException( "Couldn't create document", e );
94 /**
95 * Disposes Spreadsheet document.
97 protected void cleanup( TestParameters tParam, PrintWriter log ) {
98 log.println( " disposing xSheetDoc " );
99 XComponent oComp = (XComponent)
100 UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
101 util.DesktopTools.closeDoc(oComp);
105 * Creating a Testenvironment for the interfaces to be tested.
106 * Retrieves a collection of spreadsheets from a document,
107 * and takes one of them. Creates search descriptor using the interface
108 * <code>XSearchable</code>. The created search descriptor is instance of
109 * the service <code>com.sun.star.util.SearchDescriptor</code> that
110 * implemented by a spreasheet.
111 * @see com.sun.star.util.XSearchable
113 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
115 XInterface oObj = null;
117 // creation of testobject here
118 // first we write what we are intend to do to log file
119 log.println( "creating a test environment" );
121 log.println("getting sheets");
122 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSheetDoc.getSheets();
124 log.println("getting a sheet");
125 XSpreadsheet oSheet = null;
126 XIndexAccess oIndexAccess = (XIndexAccess)
127 UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
129 try {
130 oSheet = (XSpreadsheet) AnyConverter.toObject(
131 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
132 } catch (com.sun.star.lang.WrappedTargetException e) {
133 e.printStackTrace(log);
134 throw new StatusException( "Couldn't get a spreadsheet", e);
135 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
136 e.printStackTrace(log);
137 throw new StatusException( "Couldn't get a spreadsheet", e);
138 } catch (com.sun.star.lang.IllegalArgumentException e) {
139 e.printStackTrace(log);
140 throw new StatusException( "Couldn't get a spreadsheet", e);
143 XSearchable xSearch = (XSearchable)
144 UnoRuntime.queryInterface(XSearchable.class,oSheet);
146 oObj = xSearch.createSearchDescriptor();
147 // create testobject here
148 log.println("creating a new environment for object");
149 TestEnvironment tEnv = new TestEnvironment(oObj);
151 return tEnv;
152 } // finish method getTestEnvironment
153 } // finish class ScCellSearchObj