1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScDatabaseRangeObj.java,v $
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 ************************************************************************/
32 import com
.sun
.star
.beans
.PropertyValue
;
33 import com
.sun
.star
.beans
.XPropertySet
;
34 import com
.sun
.star
.container
.XNameAccess
;
35 import com
.sun
.star
.container
.XNamed
;
36 import com
.sun
.star
.lang
.XComponent
;
37 import com
.sun
.star
.lang
.XMultiServiceFactory
;
38 import com
.sun
.star
.sheet
.XCellRangeAddressable
;
39 import com
.sun
.star
.sheet
.XCellRangeReferrer
;
40 import com
.sun
.star
.sheet
.XDatabaseRanges
;
41 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
42 import com
.sun
.star
.sheet
.XSpreadsheets
;
43 import com
.sun
.star
.table
.CellRangeAddress
;
44 import com
.sun
.star
.table
.XCellRange
;
45 import com
.sun
.star
.uno
.AnyConverter
;
46 import com
.sun
.star
.uno
.Type
;
47 import com
.sun
.star
.uno
.UnoRuntime
;
48 import com
.sun
.star
.uno
.XInterface
;
49 import com
.sun
.star
.util
.XImportable
;
51 import java
.io
.PrintWriter
;
53 import lib
.StatusException
;
55 import lib
.TestEnvironment
;
56 import lib
.TestParameters
;
58 import util
.SOfficeFactory
;
62 * Test for object which is represented by service
63 * <code>com.sun.star.sheet.DatabaseRange</code>. <p>
64 * Object implements the following interfaces :
66 * <li> <code>com::sun::star::container::XNamed</code></li>
67 * <li> <code>com::sun::star::sheet::DatabaseRange</code></li>
68 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
69 * <li> <code>com::sun::star::sheet::XDatabaseRange</code></li>
70 * <li> <code>com::sun::star::sheet::XCellRangeReferrer</code></li>
72 * @see com.sun.star.sheet.DatabaseRange
73 * @see com.sun.star.container.XNamed
74 * @see com.sun.star.sheet.DatabaseRange
75 * @see com.sun.star.beans.XPropertySet
76 * @see com.sun.star.sheet.XDatabaseRange
77 * @see com.sun.star.sheet.XCellRangeReferrer
78 * @see ifc.container._XNamed
79 * @see ifc.sheet._DatabaseRange
80 * @see ifc.beans._XPropertySet
81 * @see ifc.sheet._XDatabaseRange
82 * @see ifc.sheet._XCellRangeReferrer
84 public class ScDatabaseRangeObj
extends TestCase
{
85 static XSpreadsheetDocument xSheetDoc
= null;
88 * Creates Spreadsheet document.
90 protected void initialize(TestParameters tParam
, PrintWriter log
) {
91 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
92 (XMultiServiceFactory
) tParam
.getMSF());
95 log
.println("creating a Spreadsheet document");
96 xSheetDoc
= SOF
.createCalcDoc(null);
97 } catch (com
.sun
.star
.uno
.Exception e
) {
98 // Some exception occures.FAILED
99 e
.printStackTrace(log
);
100 throw new StatusException("Couldn't create document", e
);
105 * Disposes Spreadsheet document.
107 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
108 log
.println(" disposing xSheetDoc ");
110 XComponent oComp
= (XComponent
) UnoRuntime
.queryInterface(
111 XComponent
.class, xSheetDoc
);
112 util
.DesktopTools
.closeDoc(oComp
);
116 * Creating a Testenvironment for the interfaces to be tested.
117 * Retrieves the collection of database ranges in the document.
118 * If the database range with name <code>'dbRange'</code> exists
119 * in the collection then removes it from the collection.
120 * Creates new database range and adds it to the collection with the name
121 * <code>'dbRange'</code>.The database range that was added to the collection
122 * is the instance of the service <code>com.sun.star.sheet.DatabaseRange</code>.
123 * Object relations created :
125 * <li> <code>'DATAAREA'</code> for
126 * {@link ifc.sheet._XCellRangeReferrer}(of type
127 * <code>CellRangeAddress</code>)</li>
128 * <li> <code>'XCELLRANGE'</code> (of type <code>XCellRange</code>):
129 * cell range of the spreadsheet with database range</li>
131 * @see com.sun.star.sheet.DatabaseRange
132 * @see com.sun.star.table.CellRangeAddress
134 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
,
136 XInterface oObj
= null;
139 // creation of testobject here
140 // first we write what we are intend to do to log file
141 log
.println("Creating a test environment");
143 log
.println("Getting test object ");
145 XPropertySet docProps
= (XPropertySet
) UnoRuntime
.queryInterface(
146 XPropertySet
.class, xSheetDoc
);
148 XSpreadsheets sheets
= xSheetDoc
.getSheets();
149 String
[] names
= sheets
.getElementNames();
150 XDatabaseRanges dbRanges
= null;
151 XImportable xImp
= null;
154 Object sheet
= sheets
.getByName(names
[0]);
155 xImp
= (XImportable
) UnoRuntime
.queryInterface(XImportable
.class,
157 dbRanges
= (XDatabaseRanges
) AnyConverter
.toObject(
158 new Type(XDatabaseRanges
.class),
159 docProps
.getPropertyValue("DatabaseRanges"));
161 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
162 e
.printStackTrace(log
);
163 throw new StatusException("Couldn't get a property", e
);
164 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
165 e
.printStackTrace(log
);
166 throw new StatusException("Couldn't get a property", e
);
167 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
168 e
.printStackTrace(log
);
169 throw new StatusException("Couldn't get a property", e
);
170 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
171 e
.printStackTrace(log
);
172 throw new StatusException(
173 "Error getting test object from spreadsheet document", e
);
176 if (dbRanges
.hasByName("dbRange")) {
177 dbRanges
.removeByName("dbRange");
180 //CellRangeAddress aRange = new CellRangeAddress((short)0, 0, 0, 0, 13);
181 CellRangeAddress aRange
= null;
183 //dbRanges.addNewByName("dbRange", aRange);
184 XNameAccess dbrNA
= (XNameAccess
) UnoRuntime
.queryInterface(
185 XNameAccess
.class, dbRanges
);
186 XNamed xNamed
= null;
189 String
[] dbNames
= dbrNA
.getElementNames();
190 xNamed
= (XNamed
) UnoRuntime
.queryInterface(XNamed
.class,
193 xNamed
.setName("dbRange");
195 XCellRangeReferrer aReferrer
= (XCellRangeReferrer
) UnoRuntime
.queryInterface(
196 XCellRangeReferrer
.class,
197 dbrNA
.getByName("dbRange"));
198 XCellRangeAddressable aRangeA
= (XCellRangeAddressable
) UnoRuntime
.queryInterface(
199 XCellRangeAddressable
.class,
200 aReferrer
.getReferredCells());
201 aRange
= aRangeA
.getRangeAddress();
202 oObj
= (XInterface
) AnyConverter
.toObject(
203 new Type(XInterface
.class),
204 dbrNA
.getByName("dbRange"));
205 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
206 e
.printStackTrace(log
);
207 throw new StatusException(
208 "Error getting test object from spreadsheet document", e
);
209 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
210 e
.printStackTrace(log
);
211 throw new StatusException(
212 "Error getting test object from spreadsheet document", e
);
213 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
214 e
.printStackTrace(log
);
215 throw new StatusException(
216 "Error getting test object from spreadsheet document", e
);
219 TestEnvironment tEnv
= new TestEnvironment(oObj
);
222 // Other parameters required for interface tests
223 tEnv
.addObjRelation("DATAAREA", aRange
);
225 XCellRange xCellRange
= null;
228 Object sheet
= sheets
.getByName(names
[0]);
229 xCellRange
= (XCellRange
) UnoRuntime
.queryInterface(
230 XCellRange
.class, sheet
);
231 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
232 e
.printStackTrace(log
);
233 throw new StatusException(
234 "Error getting of first spreadsheet from spreadsheet" +
236 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
237 e
.printStackTrace(log
);
238 throw new StatusException(
239 "Error getting of first spreadsheet from spreadsheet" +
243 tEnv
.addObjRelation("XCELLRANGE", xCellRange
);
248 public void _doImport(XImportable imp
) {
249 PropertyValue
[] descriptor
= imp
.createImportDescriptor(false);
251 log
.print("Setting the ImportDescriptor (Bibliograpy, SQL, select Identifier from biblio) -- ");
252 descriptor
[0].Value
= "Bibliography";
253 descriptor
[1].Value
= com
.sun
.star
.sheet
.DataImportMode
.SQL
;
254 descriptor
[2].Value
= "select Identifier from biblio";
257 log
.print("Importing data (Bibliograpy, Table, biblio) -- ");
258 imp
.doImport(descriptor
);