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 .
20 import com
.sun
.star
.beans
.PropertyValue
;
21 import com
.sun
.star
.beans
.XPropertySet
;
22 import com
.sun
.star
.container
.XNameAccess
;
23 import com
.sun
.star
.container
.XNamed
;
24 import com
.sun
.star
.lang
.XComponent
;
25 import com
.sun
.star
.sheet
.XCellRangeAddressable
;
26 import com
.sun
.star
.sheet
.XCellRangeReferrer
;
27 import com
.sun
.star
.sheet
.XDatabaseRanges
;
28 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
29 import com
.sun
.star
.sheet
.XSpreadsheets
;
30 import com
.sun
.star
.table
.CellRangeAddress
;
31 import com
.sun
.star
.table
.XCellRange
;
32 import com
.sun
.star
.uno
.AnyConverter
;
33 import com
.sun
.star
.uno
.Type
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.uno
.XInterface
;
36 import com
.sun
.star
.util
.XImportable
;
38 import java
.io
.PrintWriter
;
40 import lib
.StatusException
;
42 import lib
.TestEnvironment
;
43 import lib
.TestParameters
;
45 import util
.SOfficeFactory
;
49 * Test for object which is represented by service
50 * <code>com.sun.star.sheet.DatabaseRange</code>. <p>
51 * Object implements the following interfaces :
53 * <li> <code>com::sun::star::container::XNamed</code></li>
54 * <li> <code>com::sun::star::sheet::DatabaseRange</code></li>
55 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
56 * <li> <code>com::sun::star::sheet::XDatabaseRange</code></li>
57 * <li> <code>com::sun::star::sheet::XCellRangeReferrer</code></li>
59 * @see com.sun.star.sheet.DatabaseRange
60 * @see com.sun.star.container.XNamed
61 * @see com.sun.star.sheet.DatabaseRange
62 * @see com.sun.star.beans.XPropertySet
63 * @see com.sun.star.sheet.XDatabaseRange
64 * @see com.sun.star.sheet.XCellRangeReferrer
65 * @see ifc.container._XNamed
66 * @see ifc.sheet._DatabaseRange
67 * @see ifc.beans._XPropertySet
68 * @see ifc.sheet._XDatabaseRange
69 * @see ifc.sheet._XCellRangeReferrer
71 public class ScDatabaseRangeObj
extends TestCase
{
72 private XSpreadsheetDocument xSheetDoc
= null;
75 * Creates Spreadsheet document.
78 protected void initialize(TestParameters tParam
, PrintWriter log
) {
79 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
83 log
.println("creating a Spreadsheet document");
84 xSheetDoc
= SOF
.createCalcDoc(null);
85 } catch (com
.sun
.star
.uno
.Exception e
) {
86 // Some exception occurs.FAILED
87 e
.printStackTrace(log
);
88 throw new StatusException("Couldn't create document", e
);
93 * Disposes Spreadsheet document.
96 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
97 log
.println(" disposing xSheetDoc ");
99 XComponent oComp
= UnoRuntime
.queryInterface(
100 XComponent
.class, xSheetDoc
);
101 util
.DesktopTools
.closeDoc(oComp
);
105 * Creating a Testenvironment for the interfaces to be tested.
106 * Retrieves the collection of database ranges in the document.
107 * If the database range with name <code>'dbRange'</code> exists
108 * in the collection then removes it from the collection.
109 * Creates new database range and adds it to the collection with the name
110 * <code>'dbRange'</code>.The database range that was added to the collection
111 * is the instance of the service <code>com.sun.star.sheet.DatabaseRange</code>.
112 * Object relations created :
114 * <li> <code>'DATAAREA'</code> for
115 * {@link ifc.sheet._XCellRangeReferrer}(of type
116 * <code>CellRangeAddress</code>)</li>
117 * <li> <code>'XCELLRANGE'</code> (of type <code>XCellRange</code>):
118 * cell range of the spreadsheet with database range</li>
120 * @see com.sun.star.sheet.DatabaseRange
121 * @see com.sun.star.table.CellRangeAddress
124 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
,
126 XInterface oObj
= null;
129 // creation of testobject here
130 // first we write what we are intend to do to log file
131 log
.println("Creating a test environment");
133 log
.println("Getting test object ");
135 XPropertySet docProps
= UnoRuntime
.queryInterface(
136 XPropertySet
.class, xSheetDoc
);
138 XSpreadsheets sheets
= xSheetDoc
.getSheets();
139 String
[] names
= sheets
.getElementNames();
140 XDatabaseRanges dbRanges
= null;
141 XImportable xImp
= null;
144 Object sheet
= sheets
.getByName(names
[0]);
145 xImp
= UnoRuntime
.queryInterface(XImportable
.class,
147 dbRanges
= (XDatabaseRanges
) AnyConverter
.toObject(
148 new Type(XDatabaseRanges
.class),
149 docProps
.getPropertyValue("DatabaseRanges"));
151 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
152 e
.printStackTrace(log
);
153 throw new StatusException("Couldn't get a property", e
);
154 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
155 e
.printStackTrace(log
);
156 throw new StatusException("Couldn't get a property", e
);
157 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
158 e
.printStackTrace(log
);
159 throw new StatusException("Couldn't get a property", e
);
160 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
161 e
.printStackTrace(log
);
162 throw new StatusException(
163 "Error getting test object from spreadsheet document", e
);
166 String dbName
= "dbRange";
168 if (dbRanges
.hasByName(dbName
)) {
169 dbRanges
.removeByName(dbName
);
173 CellRangeAddress aRange
= null;
175 XNameAccess dbrNA
= UnoRuntime
.queryInterface(
176 XNameAccess
.class, dbRanges
);
179 dbRanges
.addNewByName(dbName
,new CellRangeAddress((short)0, 0, 0, 0, 5));
181 UnoRuntime
.queryInterface(XNamed
.class,
185 XCellRangeReferrer aReferrer
= UnoRuntime
.queryInterface(
186 XCellRangeReferrer
.class,
187 dbrNA
.getByName(dbName
));
188 XCellRangeAddressable aRangeA
= UnoRuntime
.queryInterface(
189 XCellRangeAddressable
.class,
190 aReferrer
.getReferredCells());
191 aRange
= aRangeA
.getRangeAddress();
192 oObj
= (XInterface
) AnyConverter
.toObject(
193 new Type(XInterface
.class),
194 dbrNA
.getByName(dbName
));
195 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
196 e
.printStackTrace(log
);
197 throw new StatusException(
198 "Error getting test object from spreadsheet document", e
);
199 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
200 e
.printStackTrace(log
);
201 throw new StatusException(
202 "Error getting test object from spreadsheet document", e
);
203 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
204 e
.printStackTrace(log
);
205 throw new StatusException(
206 "Error getting test object from spreadsheet document", e
);
209 TestEnvironment tEnv
= new TestEnvironment(oObj
);
212 // Other parameters required for interface tests
213 tEnv
.addObjRelation("DATAAREA", aRange
);
215 XCellRange xCellRange
= null;
218 Object sheet
= sheets
.getByName(names
[0]);
219 xCellRange
= UnoRuntime
.queryInterface(
220 XCellRange
.class, sheet
);
221 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
222 e
.printStackTrace(log
);
223 throw new StatusException(
224 "Error getting of first spreadsheet from spreadsheet" +
226 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
227 e
.printStackTrace(log
);
228 throw new StatusException(
229 "Error getting of first spreadsheet from spreadsheet" +
233 tEnv
.addObjRelation("XCELLRANGE", xCellRange
);
238 public void _doImport(XImportable imp
) {
239 PropertyValue
[] descriptor
= imp
.createImportDescriptor(false);
241 log
.print("Setting the ImportDescriptor (Bibliograpy, SQL, select Identifier from biblio) -- ");
242 descriptor
[0].Value
= "Bibliography";
243 descriptor
[1].Value
= com
.sun
.star
.sheet
.DataImportMode
.SQL
;
244 descriptor
[2].Value
= "select Identifier from biblio";
247 log
.print("Importing data (Bibliograpy, Table, biblio) -- ");
248 imp
.doImport(descriptor
);