1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._sc;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.SOfficeFactory;
33 
34 import com.sun.star.container.XIndexAccess;
35 import com.sun.star.lang.XComponent;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.sheet.XSpreadsheet;
38 import com.sun.star.sheet.XSpreadsheetDocument;
39 import com.sun.star.sheet.XSpreadsheets;
40 import com.sun.star.uno.AnyConverter;
41 import com.sun.star.uno.Type;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
44 import com.sun.star.util.XSearchable;
45 
46 /**
47 * Test for object which is represented by service
48 * <code>com.sun.star.util.SearchDescriptor</code> that was implemented by
49 * a spreadsheet. <p>
50 * Object implements the following interfaces :
51 * <ul>
52 *  <li> <code>com::sun::star::util::XSearchDescriptor</code></li>
53 *  <li> <code>com::sun::star::util::SearchDescriptor</code></li>
54 *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
55 *  <li> <code>com::sun::star::util::XReplaceDescriptor</code></li>
56 * </ul>
57 * @see com.sun.star.util.SearchDescriptor
58 * @see com.sun.star.util.XSearchDescriptor
59 * @see com.sun.star.util.SearchDescriptor
60 * @see com.sun.star.beans.XPropertySet
61 * @see com.sun.star.util.XReplaceDescriptor
62 * @see ifc.util._XSearchDescriptor
63 * @see ifc.util._SearchDescriptor
64 * @see ifc.beans._XPropertySet
65 * @see ifc.util._XReplaceDescriptor
66 */
67 public class ScCellSearchObj extends TestCase {
68     static XSpreadsheetDocument xSheetDoc = null;
69 
70     /**
71     * Creates Spreadsheet document.
72     */
initialize( TestParameters tParam, PrintWriter log )73     protected void initialize( TestParameters tParam, PrintWriter log ) {
74         // get a soffice factory object
75         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
76 
77         try {
78             log.println( "creating a sheetdocument" );
79             xSheetDoc = SOF.createCalcDoc(null);
80         } catch (com.sun.star.uno.Exception e) {
81             // Some exception occures.FAILED
82             e.printStackTrace( log );
83             throw new StatusException( "Couldn't create document", e );
84         }
85     }
86 
87     /**
88     * Disposes Spreadsheet document.
89     */
cleanup( TestParameters tParam, PrintWriter log )90     protected void cleanup( TestParameters tParam, PrintWriter log ) {
91         log.println( "    disposing xSheetDoc " );
92         XComponent oComp = (XComponent)
93             UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
94         util.DesktopTools.closeDoc(oComp);
95     }
96 
97     /**
98     * Creating a Testenvironment for the interfaces to be tested.
99     * Retrieves a collection of spreadsheets from a document,
100     * and takes one of them. Creates search descriptor using the interface
101     * <code>XSearchable</code>. The created search descriptor is instance of
102     * the service <code>com.sun.star.util.SearchDescriptor</code> that
103     * implemented by a spreasheet.
104     * @see com.sun.star.util.XSearchable
105     */
createTestEnvironment(TestParameters tParam, PrintWriter log)106     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
107 
108         XInterface oObj = null;
109 
110         // creation of testobject here
111         // first we write what we are intend to do to log file
112         log.println( "creating a test environment" );
113 
114         log.println("getting sheets");
115         XSpreadsheets xSpreadsheets = (XSpreadsheets)xSheetDoc.getSheets();
116 
117         log.println("getting a sheet");
118         XSpreadsheet oSheet = null;
119         XIndexAccess oIndexAccess = (XIndexAccess)
120             UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
121 
122         try {
123             oSheet = (XSpreadsheet) AnyConverter.toObject(
124                     new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
125         } catch (com.sun.star.lang.WrappedTargetException e) {
126             e.printStackTrace(log);
127             throw new StatusException( "Couldn't get a spreadsheet", e);
128         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
129             e.printStackTrace(log);
130             throw new StatusException( "Couldn't get a spreadsheet", e);
131         } catch (com.sun.star.lang.IllegalArgumentException e) {
132             e.printStackTrace(log);
133             throw new StatusException( "Couldn't get a spreadsheet", e);
134         }
135 
136         XSearchable xSearch = (XSearchable)
137                         UnoRuntime.queryInterface(XSearchable.class,oSheet);
138 
139         oObj = xSearch.createSearchDescriptor();
140         // create testobject here
141         log.println("creating a new environment for object");
142         TestEnvironment tEnv = new TestEnvironment(oObj);
143 
144         return tEnv;
145     } // finish method getTestEnvironment
146 }    // finish class ScCellSearchObj
147 
148