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
.XPropertySet
;
21 import com
.sun
.star
.container
.XIndexAccess
;
22 import com
.sun
.star
.container
.XNamed
;
23 import com
.sun
.star
.lang
.XComponent
;
24 import com
.sun
.star
.sheet
.DataPilotFieldOrientation
;
25 import com
.sun
.star
.sheet
.XDataPilotDescriptor
;
26 import com
.sun
.star
.sheet
.XDataPilotTables
;
27 import com
.sun
.star
.sheet
.XDataPilotTablesSupplier
;
28 import com
.sun
.star
.sheet
.XSpreadsheet
;
29 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
30 import com
.sun
.star
.sheet
.XSpreadsheets
;
31 import com
.sun
.star
.table
.CellAddress
;
32 import com
.sun
.star
.table
.CellRangeAddress
;
33 import com
.sun
.star
.uno
.AnyConverter
;
34 import com
.sun
.star
.uno
.Type
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
36 import com
.sun
.star
.uno
.XInterface
;
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.DataPilotField</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::DataPilotField</code></li>
55 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
57 * @see com.sun.star.sheet.DataPilotField
58 * @see com.sun.star.container.XNamed
59 * @see com.sun.star.sheet.DataPilotField
60 * @see com.sun.star.beans.XPropertySet
61 * @see ifc.container._XNamed
62 * @see ifc.sheet._DataPilotField
63 * @see ifc.beans._XPropertySet
65 public class ScDataPilotFieldObj
extends TestCase
{
66 private XSpreadsheetDocument xSheetDoc
= null;
69 * A field is filled some values. This integer determines the size of the
70 * field in x and y direction.
72 private static final int mMaxFieldIndex
= 6;
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 a collection of spreadsheets from a document
107 * and takes one of them. Fills some table in the spreadsheet.
108 * Obtains the collection of data pilot tables using the interface
109 * <code>XDataPilotTablesSupplier</code>. Creates a data pilot descriptor
110 * for the filled table and inserts new data pilot table with this descriptor
111 * to the collection. Obtains the collection of all the data pilot fields
112 * using the interface <code>XDataPilotDescriptor</code>. Retrieves from
113 * the collection the data pilot field with index 0. This data pilot field
114 * is the instance of the service <code>com.sun.star.sheet.DataPilotField</code>.
115 * @see com.sun.star.sheet.DataPilotField
116 * @see com.sun.star.sheet.XDataPilotTablesSupplier
117 * @see com.sun.star.sheet.XDataPilotDescriptor
120 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
,
122 XInterface oObj
= null;
125 // creation of testobject here
126 // first we write what we are intend to do to log file
127 log
.println("Creating a test environment");
130 CellRangeAddress sCellRangeAdress
= new CellRangeAddress();
131 sCellRangeAdress
.Sheet
= 0;
132 sCellRangeAdress
.StartColumn
= 1;
133 sCellRangeAdress
.StartRow
= 0;
134 sCellRangeAdress
.EndColumn
= mMaxFieldIndex
- 1;
135 sCellRangeAdress
.EndRow
= mMaxFieldIndex
- 1;
137 // position of the data pilot table
138 CellAddress sCellAdress
= new CellAddress();
139 sCellAdress
.Sheet
= 0;
140 sCellAdress
.Column
= 7;
143 log
.println("Getting a sheet");
145 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets();
146 XSpreadsheet oSheet
= null;
147 XSpreadsheet oSheet2
= null;
148 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(
149 XIndexAccess
.class, xSpreadsheets
);
150 // Make sure there are at least two sheets
151 xSpreadsheets
.insertNewByName("Some Sheet", (short)0);
154 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
155 new Type(XSpreadsheet
.class),
156 oIndexAccess
.getByIndex(0));
157 oSheet2
= (XSpreadsheet
) AnyConverter
.toObject(
158 new Type(XSpreadsheet
.class),
159 oIndexAccess
.getByIndex(1));
160 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
162 throw new StatusException("Couldn't get a spreadsheet", e
);
163 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
165 throw new StatusException("Couldn't get a spreadsheet", e
);
166 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
168 throw new StatusException("Couldn't get a spreadsheet", e
);
172 log
.println("Filling a table");
174 for (int i
= 1; i
< mMaxFieldIndex
; i
++) {
175 oSheet
.getCellByPosition(i
, 0).setFormula("Col" + i
);
176 oSheet
.getCellByPosition(0, i
).setFormula("Row" + i
);
177 oSheet2
.getCellByPosition(i
, 0).setFormula("Col" + i
);
178 oSheet2
.getCellByPosition(0, i
).setFormula("Row" + i
);
181 for (int i
= 1; i
< mMaxFieldIndex
; i
++)
182 for (int j
= 1; j
< mMaxFieldIndex
; j
++) {
183 oSheet
.getCellByPosition(i
, j
).setValue(i
* (j
+ 1));
184 oSheet2
.getCellByPosition(i
, j
).setValue(i
* (j
+ 2));
186 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
188 throw new StatusException("Couldn't fill some cells", e
);
192 oSheet
.getCellByPosition(1, 5);
194 int x
= sCellAdress
.Column
;
195 int y
= sCellAdress
.Row
+ 3;
198 oSheet
.getCellByPosition(x
, y
);
200 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
202 throw new StatusException("Couldn't get cells for changing.", e
);
206 // create the test objects
207 log
.println("Getting test objects");
209 XDataPilotTablesSupplier DPTS
= UnoRuntime
.queryInterface(
210 XDataPilotTablesSupplier
.class,
212 XDataPilotTables DPT
= DPTS
.getDataPilotTables();
213 XDataPilotDescriptor DPDsc
= DPT
.createDataPilotDescriptor();
214 DPDsc
.setSourceRange(sCellRangeAdress
);
216 XPropertySet fieldPropSet
= null;
219 Object oDataPilotField
= DPDsc
.getDataPilotFields().getByIndex(0);
220 fieldPropSet
= UnoRuntime
.queryInterface(
221 XPropertySet
.class, oDataPilotField
);
222 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
224 throw new StatusException("Couldn't create a test environment", e
);
225 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
227 throw new StatusException("Couldn't create a test environment", e
);
231 fieldPropSet
.setPropertyValue("Function",
232 com
.sun
.star
.sheet
.GeneralFunction
.SUM
);
233 fieldPropSet
.setPropertyValue("Orientation",
234 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.DATA
);
235 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
237 throw new StatusException("Couldn't create a test environment", e
);
238 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
240 throw new StatusException("Couldn't create a test environment", e
);
241 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
243 throw new StatusException("Couldn't create a test environment", e
);
244 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
246 throw new StatusException("Couldn't create a test environment", e
);
249 log
.println("Insert the DataPilotTable");
251 if (DPT
.hasByName("DataPilotTable")) {
252 DPT
.removeByName("DataPilotTable");
255 XIndexAccess IA
= DPDsc
.getDataPilotFields();
258 DPT
.insertNewByName("DataPilotTable", sCellAdress
, DPDsc
);
261 oObj
= (XInterface
) AnyConverter
.toObject(
262 new Type(XInterface
.class), IA
.getByIndex(0));
263 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
265 throw new StatusException("Couldn't get data pilot field", e
);
266 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
268 throw new StatusException("Couldn't get data pilot field", e
);
269 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
271 throw new StatusException("Couldn't get data pilot field", e
);
274 log
.println("Creating object - " +
275 ((oObj
== null) ?
"FAILED" : "OK"));
277 TestEnvironment tEnv
= new TestEnvironment(oObj
);
279 log
.println("Implementationname: " + util
.utils
.getImplName(oObj
));
281 // Other parameters required for interface tests
285 private void getSRange(XIndexAccess IA
) {
286 int fieldsAmount
= IA
.getCount() + 1;
288 String
[] fieldsNames
= new String
[fieldsAmount
];
293 while ((++i
) < fieldsAmount
) {
297 field
= IA
.getByIndex(i
);
298 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
299 e
.printStackTrace(log
);
302 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
303 e
.printStackTrace(log
);
308 XNamed named
= UnoRuntime
.queryInterface(XNamed
.class,
310 String name
= named
.getName();
312 log
.println("**Field : '" + name
+ "' ... ");
314 if (!name
.equals("Data")) {
315 fieldsNames
[cnt
] = name
;
317 XPropertySet props
= UnoRuntime
.queryInterface(
318 XPropertySet
.class, field
);
323 props
.setPropertyValue("Orientation",
324 DataPilotFieldOrientation
.COLUMN
);
325 log
.println(" Column");
330 props
.setPropertyValue("Orientation",
331 DataPilotFieldOrientation
.ROW
);
337 props
.setPropertyValue("Orientation",
338 DataPilotFieldOrientation
.DATA
);
339 log
.println(" Data");
344 props
.setPropertyValue("Orientation",
345 DataPilotFieldOrientation
.HIDDEN
);
346 log
.println(" Hidden");
351 props
.setPropertyValue("Orientation",
352 DataPilotFieldOrientation
.PAGE
);
353 log
.println(" Page");
357 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
358 e
.printStackTrace(log
);
361 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
362 e
.printStackTrace(log
);
365 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
366 e
.printStackTrace(log
);
369 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
370 e
.printStackTrace(log
);