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
.XDataPilotField
;
27 import com
.sun
.star
.sheet
.XDataPilotTables
;
28 import com
.sun
.star
.sheet
.XDataPilotTablesSupplier
;
29 import com
.sun
.star
.sheet
.XSpreadsheet
;
30 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
31 import com
.sun
.star
.sheet
.XSpreadsheets
;
32 import com
.sun
.star
.table
.CellAddress
;
33 import com
.sun
.star
.table
.CellRangeAddress
;
34 import com
.sun
.star
.uno
.AnyConverter
;
35 import com
.sun
.star
.uno
.Type
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
37 import com
.sun
.star
.uno
.XInterface
;
39 import java
.io
.PrintWriter
;
41 import lib
.StatusException
;
43 import lib
.TestEnvironment
;
44 import lib
.TestParameters
;
46 import util
.SOfficeFactory
;
50 * Test for object which is represented by service
51 * <code>com.sun.star.sheet.DataPilotField</code>. <p>
52 * Object implements the following interfaces :
54 * <li> <code>com::sun::star::container::XNamed</code></li>
55 * <li> <code>com::sun::star::sheet::DataPilotField</code></li>
56 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
58 * @see com.sun.star.sheet.DataPilotField
59 * @see com.sun.star.container.XNamed
60 * @see com.sun.star.sheet.DataPilotField
61 * @see com.sun.star.beans.XPropertySet
62 * @see ifc.container._XNamed
63 * @see ifc.sheet._DataPilotField
64 * @see ifc.beans._XPropertySet
66 public class ScDataPilotItemsObj
extends TestCase
{
67 private XSpreadsheetDocument xSheetDoc
= null;
70 * A field is filled some values. This integer determines the size of the
71 * field in x and y direction.
73 private static final int mMaxFieldIndex
= 6;
76 * Creates Spreadsheet document.
79 protected void initialize(TestParameters tParam
, PrintWriter log
) {
80 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
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.
97 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
98 log
.println(" disposing xSheetDoc ");
100 XComponent oComp
= UnoRuntime
.queryInterface(
101 XComponent
.class, xSheetDoc
);
102 util
.DesktopTools
.closeDoc(oComp
);
106 * Creating a Testenvironment for the interfaces to be tested.
107 * Retrieves a collection of spreadsheets from a document
108 * and takes one of them. Fills some table in the spreadsheet.
109 * Obtains the collection of data pilot tables using the interface
110 * <code>XDataPilotTablesSupplier</code>. Creates a data pilot descriptor
111 * for the filled table and inserts new data pilot table with this descriptor
112 * to the collection. Obtains the collection of all the data pilot fields
113 * using the interface <code>XDataPilotDescriptor</code>. Retrieves from
114 * the collection the data pilot field with index 0. This data pilot field
115 * is the instance of the service <code>com.sun.star.sheet.DataPilotField</code>.
116 * @see com.sun.star.sheet.DataPilotField
117 * @see com.sun.star.sheet.XDataPilotTablesSupplier
118 * @see com.sun.star.sheet.XDataPilotDescriptor
121 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
,
123 XInterface oObj
= null;
126 // creation of testobject here
127 // first we write what we are intend to do to log file
128 log
.println("Creating a test environment");
131 CellRangeAddress sCellRangeAdress
= new CellRangeAddress();
132 sCellRangeAdress
.Sheet
= 0;
133 sCellRangeAdress
.StartColumn
= 1;
134 sCellRangeAdress
.StartRow
= 0;
135 sCellRangeAdress
.EndColumn
= mMaxFieldIndex
- 1;
136 sCellRangeAdress
.EndRow
= mMaxFieldIndex
- 1;
138 // position of the data pilot table
139 CellAddress sCellAdress
= new CellAddress();
140 sCellAdress
.Sheet
= 0;
141 sCellAdress
.Column
= 7;
144 log
.println("Getting a sheet");
146 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets();
147 XSpreadsheet oSheet
= null;
148 XSpreadsheet oSheet2
= null;
149 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(
150 XIndexAccess
.class, xSpreadsheets
);
151 // Make sure there are at least two sheets
152 xSpreadsheets
.insertNewByName("Some Sheet", (short)0);
155 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
156 new Type(XSpreadsheet
.class),
157 oIndexAccess
.getByIndex(0));
158 oSheet2
= (XSpreadsheet
) AnyConverter
.toObject(
159 new Type(XSpreadsheet
.class),
160 oIndexAccess
.getByIndex(1));
161 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
163 throw new StatusException("Couldn't get a spreadsheet", e
);
164 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
166 throw new StatusException("Couldn't get a spreadsheet", e
);
167 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
169 throw new StatusException("Couldn't get a spreadsheet", e
);
173 log
.println("Filling a table");
175 for (int i
= 1; i
< mMaxFieldIndex
; i
++) {
176 oSheet
.getCellByPosition(i
, 0).setFormula("Col" + i
);
177 oSheet
.getCellByPosition(0, i
).setFormula("Row" + i
);
178 oSheet2
.getCellByPosition(i
, 0).setFormula("Col" + i
);
179 oSheet2
.getCellByPosition(0, i
).setFormula("Row" + i
);
182 for (int i
= 1; i
< mMaxFieldIndex
; i
++)
183 for (int j
= 1; j
< mMaxFieldIndex
; j
++) {
184 oSheet
.getCellByPosition(i
, j
).setValue(i
* (j
+ 1));
185 oSheet2
.getCellByPosition(i
, j
).setValue(i
* (j
+ 2));
187 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
189 throw new StatusException("Couldn't fill some cells", e
);
193 oSheet
.getCellByPosition(1, 5);
195 int x
= sCellAdress
.Column
;
196 int y
= sCellAdress
.Row
+ 3;
199 oSheet
.getCellByPosition(x
, y
);
201 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
203 throw new StatusException("Couldn't get cells for changing.", e
);
207 // create the test objects
208 log
.println("Getting test objects");
210 XDataPilotTablesSupplier DPTS
= UnoRuntime
.queryInterface(
211 XDataPilotTablesSupplier
.class,
213 XDataPilotTables DPT
= DPTS
.getDataPilotTables();
214 XDataPilotDescriptor DPDsc
= DPT
.createDataPilotDescriptor();
215 DPDsc
.setSourceRange(sCellRangeAdress
);
217 XPropertySet fieldPropSet
= null;
220 Object oDataPilotField
= DPDsc
.getDataPilotFields().getByIndex(0);
221 fieldPropSet
= UnoRuntime
.queryInterface(
222 XPropertySet
.class, oDataPilotField
);
223 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
225 throw new StatusException("Couldn't create a test environment", e
);
226 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
228 throw new StatusException("Couldn't create a test environment", e
);
232 fieldPropSet
.setPropertyValue("Function",
233 com
.sun
.star
.sheet
.GeneralFunction
.SUM
);
234 fieldPropSet
.setPropertyValue("Orientation",
235 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.DATA
);
236 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
238 throw new StatusException("Couldn't create a test environment", e
);
239 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
241 throw new StatusException("Couldn't create a test environment", e
);
242 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
244 throw new StatusException("Couldn't create a test environment", e
);
245 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
247 throw new StatusException("Couldn't create a test environment", e
);
250 log
.println("Insert the DataPilotTable");
252 if (DPT
.hasByName("DataPilotTable")) {
253 DPT
.removeByName("DataPilotTable");
256 XIndexAccess IA
= DPDsc
.getDataPilotFields();
259 DPT
.insertNewByName("DataPilotTable", sCellAdress
, DPDsc
);
262 oObj
= (XInterface
) AnyConverter
.toObject(
263 new Type(XInterface
.class), IA
.getByIndex(0));
264 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
266 throw new StatusException("Couldn't get data pilot field", e
);
267 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
269 throw new StatusException("Couldn't get data pilot field", e
);
270 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
272 throw new StatusException("Couldn't get data pilot field", e
);
275 log
.println("Creating object - " +
276 ((oObj
== null) ?
"FAILED" : "OK"));
278 XDataPilotField xDataPilotField
= UnoRuntime
.queryInterface(
279 XDataPilotField
.class, oObj
);
281 oObj
= xDataPilotField
.getItems();
283 TestEnvironment tEnv
= new TestEnvironment(oObj
);
285 log
.println("Implementationname: " + util
.utils
.getImplName(oObj
));
287 // Other parameters required for interface tests
291 private void getSRange(XIndexAccess IA
) {
292 int fieldsAmount
= IA
.getCount() + 1;
294 String
[] fieldsNames
= new String
[fieldsAmount
];
299 while ((++i
) < fieldsAmount
) {
303 field
= IA
.getByIndex(i
);
304 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
305 e
.printStackTrace(log
);
308 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
309 e
.printStackTrace(log
);
314 XNamed named
= UnoRuntime
.queryInterface(XNamed
.class,
316 String name
= named
.getName();
318 log
.println("**Field : '" + name
+ "' ... ");
320 if (!name
.equals("Data")) {
321 fieldsNames
[cnt
] = name
;
323 XPropertySet props
= UnoRuntime
.queryInterface(
324 XPropertySet
.class, field
);
329 props
.setPropertyValue("Orientation",
330 DataPilotFieldOrientation
.COLUMN
);
331 log
.println(" Column");
336 props
.setPropertyValue("Orientation",
337 DataPilotFieldOrientation
.ROW
);
343 props
.setPropertyValue("Orientation",
344 DataPilotFieldOrientation
.DATA
);
345 log
.println(" Data");
350 props
.setPropertyValue("Orientation",
351 DataPilotFieldOrientation
.HIDDEN
);
352 log
.println(" Hidden");
357 props
.setPropertyValue("Orientation",
358 DataPilotFieldOrientation
.PAGE
);
359 log
.println(" Page");
363 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
364 e
.printStackTrace(log
);
367 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
368 e
.printStackTrace(log
);
371 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
372 e
.printStackTrace(log
);
375 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
376 e
.printStackTrace(log
);