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
.XEnumerationAccess
;
22 import com
.sun
.star
.container
.XIndexAccess
;
23 import com
.sun
.star
.container
.XNamed
;
24 import com
.sun
.star
.lang
.XComponent
;
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 ScIndexEnumeration_DataPilotItemsEnumeration
69 private XSpreadsheetDocument xSheetDoc
= null;
72 * A field is filled some values. This integer determines the size of the
73 * field in x and y direction.
75 private static final int mMaxFieldIndex
= 6;
78 * Creates Spreadsheet document.
81 protected void initialize(TestParameters tParam
, PrintWriter log
) {
82 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
86 log
.println("creating a Spreadsheet document");
87 xSheetDoc
= SOF
.createCalcDoc(null);
88 } catch (com
.sun
.star
.uno
.Exception e
) {
89 // Some exception occurs.FAILED
90 e
.printStackTrace(log
);
91 throw new StatusException("Couldn't create document", e
);
96 * Disposes Spreadsheet document.
99 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
100 log
.println(" disposing xSheetDoc ");
102 XComponent oComp
= UnoRuntime
.queryInterface(
103 XComponent
.class, xSheetDoc
);
104 util
.DesktopTools
.closeDoc(oComp
);
108 * Creating a Testenvironment for the interfaces to be tested.
109 * Retrieves a collection of spreadsheets from a document
110 * and takes one of them. Fills some table in the spreadsheet.
111 * Obtains the collection of data pilot tables using the interface
112 * <code>XDataPilotTablesSupplier</code>. Creates a data pilot descriptor
113 * for the filled table and inserts new data pilot table with this descriptor
114 * to the collection. Obtains the collection of all the data pilot fields
115 * using the interface <code>XDataPilotDescriptor</code>. Retrieves from
116 * the collection the data pilot field with index 0. This data pilot field
117 * is the instance of the service <code>com.sun.star.sheet.DataPilotField</code>.
118 * @see com.sun.star.sheet.DataPilotField
119 * @see com.sun.star.sheet.XDataPilotTablesSupplier
120 * @see com.sun.star.sheet.XDataPilotDescriptor
123 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
,
125 XInterface oObj
= null;
128 // creation of testobject here
129 // first we write what we are intend to do to log file
130 log
.println("Creating a test environment");
133 CellRangeAddress sCellRangeAdress
= new CellRangeAddress();
134 sCellRangeAdress
.Sheet
= 0;
135 sCellRangeAdress
.StartColumn
= 1;
136 sCellRangeAdress
.StartRow
= 0;
137 sCellRangeAdress
.EndColumn
= mMaxFieldIndex
- 1;
138 sCellRangeAdress
.EndRow
= mMaxFieldIndex
- 1;
140 // position of the data pilot table
141 CellAddress sCellAdress
= new CellAddress();
142 sCellAdress
.Sheet
= 0;
143 sCellAdress
.Column
= 7;
146 log
.println("Getting a sheet");
148 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets();
149 XSpreadsheet oSheet
= null;
150 XSpreadsheet oSheet2
= null;
151 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(
152 XIndexAccess
.class, xSpreadsheets
);
153 // Make sure there are at least two sheets
154 xSpreadsheets
.insertNewByName("Some Sheet", (short)0);
157 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
158 new Type(XSpreadsheet
.class),
159 oIndexAccess
.getByIndex(0));
160 oSheet2
= (XSpreadsheet
) AnyConverter
.toObject(
161 new Type(XSpreadsheet
.class),
162 oIndexAccess
.getByIndex(1));
163 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
165 throw new StatusException("Couldn't get a spreadsheet", e
);
166 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
168 throw new StatusException("Couldn't get a spreadsheet", e
);
169 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
171 throw new StatusException("Couldn't get a spreadsheet", e
);
175 log
.println("Filling a table");
177 for (int i
= 1; i
< mMaxFieldIndex
; i
++) {
178 oSheet
.getCellByPosition(i
, 0).setFormula("Col" + i
);
179 oSheet
.getCellByPosition(0, i
).setFormula("Row" + i
);
180 oSheet2
.getCellByPosition(i
, 0).setFormula("Col" + i
);
181 oSheet2
.getCellByPosition(0, i
).setFormula("Row" + i
);
184 for (int i
= 1; i
< mMaxFieldIndex
; i
++)
185 for (int j
= 1; j
< mMaxFieldIndex
; j
++) {
186 oSheet
.getCellByPosition(i
, j
).setValue(i
* (j
+ 1));
187 oSheet2
.getCellByPosition(i
, j
).setValue(i
* (j
+ 2));
189 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
191 throw new StatusException("Couldn't fill some cells", e
);
195 oSheet
.getCellByPosition(1, 5);
197 int x
= sCellAdress
.Column
;
198 int y
= sCellAdress
.Row
+ 3;
201 oSheet
.getCellByPosition(x
, y
);
203 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
205 throw new StatusException("Couldn't get cells for changing.", e
);
209 // create the test objects
210 log
.println("Getting test objects");
212 XDataPilotTablesSupplier DPTS
= UnoRuntime
.queryInterface(
213 XDataPilotTablesSupplier
.class,
215 XDataPilotTables DPT
= DPTS
.getDataPilotTables();
216 XDataPilotDescriptor DPDsc
= DPT
.createDataPilotDescriptor();
217 DPDsc
.setSourceRange(sCellRangeAdress
);
219 XPropertySet fieldPropSet
= null;
222 Object oDataPilotField
= DPDsc
.getDataPilotFields().getByIndex(0);
223 fieldPropSet
= UnoRuntime
.queryInterface(
224 XPropertySet
.class, oDataPilotField
);
225 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
227 throw new StatusException("Couldn't create a test environment", e
);
228 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
230 throw new StatusException("Couldn't create a test environment", e
);
234 fieldPropSet
.setPropertyValue("Function",
235 com
.sun
.star
.sheet
.GeneralFunction
.SUM
);
236 fieldPropSet
.setPropertyValue("Orientation",
237 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.DATA
);
238 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
240 throw new StatusException("Couldn't create a test environment", e
);
241 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
243 throw new StatusException("Couldn't create a test environment", e
);
244 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
246 throw new StatusException("Couldn't create a test environment", e
);
247 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
249 throw new StatusException("Couldn't create a test environment", e
);
252 log
.println("Insert the DataPilotTable");
254 if (DPT
.hasByName("DataPilotTable")) {
255 DPT
.removeByName("DataPilotTable");
258 XIndexAccess IA
= DPDsc
.getDataPilotFields();
261 DPT
.insertNewByName("DataPilotTable", sCellAdress
, DPDsc
);
264 oObj
= (XInterface
) AnyConverter
.toObject(
265 new Type(XInterface
.class), IA
.getByIndex(0));
266 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
268 throw new StatusException("Couldn't get data pilot field", e
);
269 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
271 throw new StatusException("Couldn't get data pilot field", e
);
272 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
274 throw new StatusException("Couldn't get data pilot field", e
);
277 log
.println("Creating object - " +
278 ((oObj
== null) ?
"FAILED" : "OK"));
280 XDataPilotField xDataPilotField
= UnoRuntime
.queryInterface(
281 XDataPilotField
.class, oObj
);
283 XEnumerationAccess xEnumerationAccess
= UnoRuntime
.queryInterface(
284 XEnumerationAccess
.class,
285 xDataPilotField
.getItems());
287 oObj
= xEnumerationAccess
.createEnumeration();
289 TestEnvironment tEnv
= new TestEnvironment(oObj
);
291 log
.println("Implementationname: " + util
.utils
.getImplName(oObj
));
293 // Other parameters required for interface tests
297 private void getSRange(XIndexAccess IA
) {
298 int fieldsAmount
= IA
.getCount() + 1;
300 String
[] fieldsNames
= new String
[fieldsAmount
];
305 while ((++i
) < fieldsAmount
) {
309 field
= IA
.getByIndex(i
);
310 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
311 e
.printStackTrace(log
);
314 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
315 e
.printStackTrace(log
);
320 XNamed named
= UnoRuntime
.queryInterface(XNamed
.class,
322 String name
= named
.getName();
324 log
.println("**Field : '" + name
+ "' ... ");
326 if (!name
.equals("Data")) {
327 fieldsNames
[cnt
] = name
;
329 XPropertySet props
= UnoRuntime
.queryInterface(
330 XPropertySet
.class, field
);
335 props
.setPropertyValue("Orientation",
336 DataPilotFieldOrientation
.COLUMN
);
337 log
.println(" Column");
342 props
.setPropertyValue("Orientation",
343 DataPilotFieldOrientation
.ROW
);
349 props
.setPropertyValue("Orientation",
350 DataPilotFieldOrientation
.DATA
);
351 log
.println(" Data");
356 props
.setPropertyValue("Orientation",
357 DataPilotFieldOrientation
.HIDDEN
);
358 log
.println(" Hidden");
363 props
.setPropertyValue("Orientation",
364 DataPilotFieldOrientation
.PAGE
);
365 log
.println(" Page");
369 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
370 e
.printStackTrace(log
);
373 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
374 e
.printStackTrace(log
);
377 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
378 e
.printStackTrace(log
);
381 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
382 e
.printStackTrace(log
);