2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.container
.XIndexAccess
;
30 import com
.sun
.star
.lang
.XComponent
;
31 import com
.sun
.star
.lang
.XMultiServiceFactory
;
32 import com
.sun
.star
.sheet
.XSpreadsheet
;
33 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
34 import com
.sun
.star
.sheet
.XSpreadsheets
;
35 import com
.sun
.star
.uno
.AnyConverter
;
36 import com
.sun
.star
.uno
.Type
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.uno
.XInterface
;
39 import com
.sun
.star
.util
.XSearchable
;
42 * Test for object which is represented by service
43 * <code>com.sun.star.util.SearchDescriptor</code> that was implemented by
45 * Object implements the following interfaces :
47 * <li> <code>com::sun::star::util::XSearchDescriptor</code></li>
48 * <li> <code>com::sun::star::util::SearchDescriptor</code></li>
49 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
50 * <li> <code>com::sun::star::util::XReplaceDescriptor</code></li>
52 * @see com.sun.star.util.SearchDescriptor
53 * @see com.sun.star.util.XSearchDescriptor
54 * @see com.sun.star.util.SearchDescriptor
55 * @see com.sun.star.beans.XPropertySet
56 * @see com.sun.star.util.XReplaceDescriptor
57 * @see ifc.util._XSearchDescriptor
58 * @see ifc.util._SearchDescriptor
59 * @see ifc.beans._XPropertySet
60 * @see ifc.util._XReplaceDescriptor
62 public class ScCellSearchObj
extends TestCase
{
63 private XSpreadsheetDocument xSheetDoc
= null;
66 * Creates Spreadsheet document.
68 protected void initialize( TestParameters tParam
, PrintWriter log
) {
69 // get a soffice factory object
70 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
73 log
.println( "creating a sheetdocument" );
74 xSheetDoc
= SOF
.createCalcDoc(null);
75 } catch (com
.sun
.star
.uno
.Exception e
) {
76 // Some exception occurs.FAILED
77 e
.printStackTrace( log
);
78 throw new StatusException( "Couldn't create document", e
);
83 * Disposes Spreadsheet document.
85 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
86 log
.println( " disposing xSheetDoc " );
87 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
) ;
88 util
.DesktopTools
.closeDoc(oComp
);
92 * Creating a Testenvironment for the interfaces to be tested.
93 * Retrieves a collection of spreadsheets from a document,
94 * and takes one of them. Creates search descriptor using the interface
95 * <code>XSearchable</code>. The created search descriptor is instance of
96 * the service <code>com.sun.star.util.SearchDescriptor</code> that
97 * implemented by a spreasheet.
98 * @see com.sun.star.util.XSearchable
100 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
102 XInterface oObj
= null;
104 // creation of testobject here
105 // first we write what we are intend to do to log file
106 log
.println( "creating a test environment" );
108 log
.println("getting sheets");
109 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets();
111 log
.println("getting a sheet");
112 XSpreadsheet oSheet
= null;
113 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
116 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
117 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
118 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
119 e
.printStackTrace(log
);
120 throw new StatusException( "Couldn't get a spreadsheet", e
);
121 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
122 e
.printStackTrace(log
);
123 throw new StatusException( "Couldn't get a spreadsheet", e
);
124 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
125 e
.printStackTrace(log
);
126 throw new StatusException( "Couldn't get a spreadsheet", e
);
129 XSearchable xSearch
= UnoRuntime
.queryInterface(XSearchable
.class,oSheet
);
131 oObj
= xSearch
.createSearchDescriptor();
132 // create testobject here
133 log
.println("creating a new environment for object");
134 TestEnvironment tEnv
= new TestEnvironment(oObj
);
137 } // finish method getTestEnvironment
138 } // finish class ScCellSearchObj