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
.lang
.XMultiServiceFactory
;
25 import com
.sun
.star
.sheet
.DataPilotFieldOrientation
;
26 import com
.sun
.star
.sheet
.XDataPilotDescriptor
;
27 import com
.sun
.star
.sheet
.XDataPilotField
;
28 import com
.sun
.star
.sheet
.XDataPilotTables
;
29 import com
.sun
.star
.sheet
.XDataPilotTablesSupplier
;
30 import com
.sun
.star
.sheet
.XSpreadsheet
;
31 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
32 import com
.sun
.star
.sheet
.XSpreadsheets
;
33 import com
.sun
.star
.table
.CellAddress
;
34 import com
.sun
.star
.table
.CellRangeAddress
;
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
;
40 import java
.io
.PrintWriter
;
42 import lib
.StatusException
;
44 import lib
.TestEnvironment
;
45 import lib
.TestParameters
;
47 import util
.SOfficeFactory
;
51 * Test for object which is represented by service
52 * <code>com.sun.star.sheet.DataPilotField</code>. <p>
53 * Object implements the following interfaces :
55 * <li> <code>com::sun::star::container::XNamed</code></li>
56 * <li> <code>com::sun::star::sheet::DataPilotField</code></li>
57 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
59 * @see com.sun.star.sheet.DataPilotField
60 * @see com.sun.star.container.XNamed
61 * @see com.sun.star.sheet.DataPilotField
62 * @see com.sun.star.beans.XPropertySet
63 * @see ifc.container._XNamed
64 * @see ifc.sheet._DataPilotField
65 * @see ifc.beans._XPropertySet
67 public class ScDataPilotItemObj
extends TestCase
{
68 private XSpreadsheetDocument xSheetDoc
= null;
71 * A field is filled some values. This integer determines the size of the
72 * field in x and y direction.
74 private int mMaxFieldIndex
= 6;
77 * Creates Spreadsheet document.
79 protected void initialize(TestParameters tParam
, PrintWriter log
) {
80 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
81 (XMultiServiceFactory
) tParam
.getMSF());
84 log
.println("creating a Spreadsheet document");
85 xSheetDoc
= SOF
.createCalcDoc(null);
86 } catch (com
.sun
.star
.uno
.Exception e
) {
87 // Some exception occurs.FAILED
88 e
.printStackTrace(log
);
89 throw new StatusException("Couldn't create document", e
);
94 * 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
119 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
,
121 XInterface oObj
= null;
124 // creation of testobject here
125 // first we write what we are intend to do to log file
126 log
.println("Creating a test environment");
129 CellRangeAddress sCellRangeAdress
= new CellRangeAddress();
130 sCellRangeAdress
.Sheet
= 0;
131 sCellRangeAdress
.StartColumn
= 1;
132 sCellRangeAdress
.StartRow
= 0;
133 sCellRangeAdress
.EndColumn
= mMaxFieldIndex
- 1;
134 sCellRangeAdress
.EndRow
= mMaxFieldIndex
- 1;
136 // position of the data pilot table
137 CellAddress sCellAdress
= new CellAddress();
138 sCellAdress
.Sheet
= 0;
139 sCellAdress
.Column
= 7;
142 log
.println("Getting a sheet");
144 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets();
145 XSpreadsheet oSheet
= null;
146 XSpreadsheet oSheet2
= null;
147 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(
148 XIndexAccess
.class, xSpreadsheets
);
149 // Make sure there are at least two sheets
150 xSpreadsheets
.insertNewByName("Some Sheet", (short)0);
153 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
154 new Type(XSpreadsheet
.class),
155 oIndexAccess
.getByIndex(0));
156 oSheet2
= (XSpreadsheet
) AnyConverter
.toObject(
157 new Type(XSpreadsheet
.class),
158 oIndexAccess
.getByIndex(1));
159 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
161 throw new StatusException("Couldn't get a spreadsheet", e
);
162 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
164 throw new StatusException("Couldn't get a spreadsheet", e
);
165 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
167 throw new StatusException("Couldn't get a spreadsheet", e
);
171 log
.println("Filling a table");
173 for (int i
= 1; i
< mMaxFieldIndex
; i
++) {
174 oSheet
.getCellByPosition(i
, 0).setFormula("Col" + i
);
175 oSheet
.getCellByPosition(0, i
).setFormula("Row" + i
);
176 oSheet2
.getCellByPosition(i
, 0).setFormula("Col" + i
);
177 oSheet2
.getCellByPosition(0, i
).setFormula("Row" + i
);
180 for (int i
= 1; i
< mMaxFieldIndex
; i
++)
181 for (int j
= 1; j
< mMaxFieldIndex
; j
++) {
182 oSheet
.getCellByPosition(i
, j
).setValue(i
* (j
+ 1));
183 oSheet2
.getCellByPosition(i
, j
).setValue(i
* (j
+ 2));
185 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
187 throw new StatusException("Couldn't fill some cells", e
);
191 oSheet
.getCellByPosition(1, 5);
193 int x
= sCellAdress
.Column
;
194 int y
= sCellAdress
.Row
+ 3;
197 oSheet
.getCellByPosition(x
, y
);
199 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
201 throw new StatusException("Couldn't get cells for changing.", e
);
205 // create the test objects
206 log
.println("Getting test objects");
208 XDataPilotTablesSupplier DPTS
= UnoRuntime
.queryInterface(
209 XDataPilotTablesSupplier
.class,
211 XDataPilotTables DPT
= DPTS
.getDataPilotTables();
212 XDataPilotDescriptor DPDsc
= DPT
.createDataPilotDescriptor();
213 DPDsc
.setSourceRange(sCellRangeAdress
);
215 XPropertySet fieldPropSet
= null;
218 Object oDataPilotField
= DPDsc
.getDataPilotFields().getByIndex(0);
219 fieldPropSet
= UnoRuntime
.queryInterface(
220 XPropertySet
.class, oDataPilotField
);
221 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
223 throw new StatusException("Couldn't create a test environment", e
);
224 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
226 throw new StatusException("Couldn't create a test environment", e
);
230 fieldPropSet
.setPropertyValue("Function",
231 com
.sun
.star
.sheet
.GeneralFunction
.SUM
);
232 fieldPropSet
.setPropertyValue("Orientation",
233 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.DATA
);
234 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
236 throw new StatusException("Couldn't create a test environment", e
);
237 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
239 throw new StatusException("Couldn't create a test environment", e
);
240 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
242 throw new StatusException("Couldn't create a test environment", e
);
243 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
245 throw new StatusException("Couldn't create a test environment", e
);
248 log
.println("Insert the DataPilotTable");
250 if (DPT
.hasByName("DataPilotTable")) {
251 DPT
.removeByName("DataPilotTable");
254 XIndexAccess IA
= DPDsc
.getDataPilotFields();
257 DPT
.insertNewByName("DataPilotTable", sCellAdress
, DPDsc
);
260 oObj
= (XInterface
) AnyConverter
.toObject(
261 new Type(XInterface
.class), IA
.getByIndex(0));
262 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
264 throw new StatusException("Couldn't get data pilot field", e
);
265 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
267 throw new StatusException("Couldn't get data pilot field", e
);
268 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
270 throw new StatusException("Couldn't get data pilot field", e
);
273 log
.println("Creating object - " +
274 ((oObj
== null) ?
"FAILED" : "OK"));
276 XDataPilotField xDataPilotField
= UnoRuntime
.queryInterface(
277 XDataPilotField
.class, oObj
);
279 XIndexAccess xIA
= xDataPilotField
.getItems();
282 oObj
= UnoRuntime
.queryInterface(XInterface
.class,
284 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
285 log
.println("Couldn't get DataPilotItemObj");
286 e
.printStackTrace(log
);
287 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
288 log
.println("Couldn't get DataPilotItemObj");
289 e
.printStackTrace(log
);
292 TestEnvironment tEnv
= new TestEnvironment(oObj
);
294 log
.println("Implementationname: " + util
.utils
.getImplName(oObj
));
296 // Other parameters required for interface tests
297 tEnv
.addObjRelation("NoSetName", "ScDataPilotItemObj");
301 private void getSRange(XIndexAccess IA
) {
302 int fieldsAmount
= IA
.getCount() + 1;
304 String
[] fieldsNames
= new String
[fieldsAmount
];
309 while ((++i
) < fieldsAmount
) {
313 field
= IA
.getByIndex(i
);
314 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
315 e
.printStackTrace(log
);
318 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
319 e
.printStackTrace(log
);
324 XNamed named
= UnoRuntime
.queryInterface(XNamed
.class,
326 String name
= named
.getName();
328 log
.println("**Field : '" + name
+ "' ... ");
330 if (!name
.equals("Data")) {
331 fieldsNames
[cnt
] = name
;
333 XPropertySet props
= UnoRuntime
.queryInterface(
334 XPropertySet
.class, field
);
339 props
.setPropertyValue("Orientation",
340 DataPilotFieldOrientation
.COLUMN
);
341 log
.println(" Column");
346 props
.setPropertyValue("Orientation",
347 DataPilotFieldOrientation
.ROW
);
353 props
.setPropertyValue("Orientation",
354 DataPilotFieldOrientation
.DATA
);
355 log
.println(" Data");
360 props
.setPropertyValue("Orientation",
361 DataPilotFieldOrientation
.HIDDEN
);
362 log
.println(" Hidden");
367 props
.setPropertyValue("Orientation",
368 DataPilotFieldOrientation
.PAGE
);
369 log
.println(" Page");
373 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
374 e
.printStackTrace(log
);
377 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
378 e
.printStackTrace(log
);
381 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
382 e
.printStackTrace(log
);
385 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
386 e
.printStackTrace(log
);