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
;
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 ScDataPilotItemObj
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
) throws Exception
{
79 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
82 log
.println("creating a Spreadsheet document");
83 xSheetDoc
= SOF
.createCalcDoc(null);
87 * Disposes Spreadsheet document.
90 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
91 log
.println(" disposing xSheetDoc ");
93 XComponent oComp
= UnoRuntime
.queryInterface(
94 XComponent
.class, xSheetDoc
);
95 util
.DesktopTools
.closeDoc(oComp
);
99 * Creating a TestEnvironment for the interfaces to be tested.
100 * Retrieves a collection of spreadsheets from a document
101 * and takes one of them. Fills some table in the spreadsheet.
102 * Obtains the collection of data pilot tables using the interface
103 * <code>XDataPilotTablesSupplier</code>. Creates a data pilot descriptor
104 * for the filled table and inserts new data pilot table with this descriptor
105 * to the collection. Obtains the collection of all the data pilot fields
106 * using the interface <code>XDataPilotDescriptor</code>. Retrieves from
107 * the collection the data pilot field with index 0. This data pilot field
108 * is the instance of the service <code>com.sun.star.sheet.DataPilotField</code>.
109 * @see com.sun.star.sheet.DataPilotField
110 * @see com.sun.star.sheet.XDataPilotTablesSupplier
111 * @see com.sun.star.sheet.XDataPilotDescriptor
114 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
115 PrintWriter log
) throws Exception
{
116 XInterface oObj
= null;
119 // creation of testobject here
120 // first we write what we are intend to do to log file
121 log
.println("Creating a test environment");
124 CellRangeAddress sCellRangeAddress
= new CellRangeAddress();
125 sCellRangeAddress
.Sheet
= 0;
126 sCellRangeAddress
.StartColumn
= 1;
127 sCellRangeAddress
.StartRow
= 0;
128 sCellRangeAddress
.EndColumn
= mMaxFieldIndex
- 1;
129 sCellRangeAddress
.EndRow
= mMaxFieldIndex
- 1;
131 // position of the data pilot table
132 CellAddress sCellAddress
= new CellAddress();
133 sCellAddress
.Sheet
= 0;
134 sCellAddress
.Column
= 7;
135 sCellAddress
.Row
= 8;
137 log
.println("Getting a sheet");
139 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets();
140 XSpreadsheet oSheet
= null;
141 XSpreadsheet oSheet2
= null;
142 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(
143 XIndexAccess
.class, xSpreadsheets
);
144 // Make sure there are at least two sheets
145 xSpreadsheets
.insertNewByName("Some Sheet", (short)0);
147 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
148 new Type(XSpreadsheet
.class),
149 oIndexAccess
.getByIndex(0));
150 oSheet2
= (XSpreadsheet
) AnyConverter
.toObject(
151 new Type(XSpreadsheet
.class),
152 oIndexAccess
.getByIndex(1));
154 log
.println("Filling a table");
156 for (int i
= 1; i
< mMaxFieldIndex
; i
++) {
157 oSheet
.getCellByPosition(i
, 0).setFormula("Col" + i
);
158 oSheet
.getCellByPosition(0, i
).setFormula("Row" + i
);
159 oSheet2
.getCellByPosition(i
, 0).setFormula("Col" + i
);
160 oSheet2
.getCellByPosition(0, i
).setFormula("Row" + i
);
163 for (int i
= 1; i
< mMaxFieldIndex
; i
++)
164 for (int j
= 1; j
< mMaxFieldIndex
; j
++) {
165 oSheet
.getCellByPosition(i
, j
).setValue(i
* (j
+ 1));
166 oSheet2
.getCellByPosition(i
, j
).setValue(i
* (j
+ 2));
169 oSheet
.getCellByPosition(1, 5);
171 int x
= sCellAddress
.Column
;
172 int y
= sCellAddress
.Row
+ 3;
175 oSheet
.getCellByPosition(x
, y
);
178 // create the test objects
179 log
.println("Getting test objects");
181 XDataPilotTablesSupplier DPTS
= UnoRuntime
.queryInterface(
182 XDataPilotTablesSupplier
.class,
184 XDataPilotTables DPT
= DPTS
.getDataPilotTables();
185 XDataPilotDescriptor DPDsc
= DPT
.createDataPilotDescriptor();
186 DPDsc
.setSourceRange(sCellRangeAddress
);
188 XPropertySet fieldPropSet
= null;
190 Object oDataPilotField
= DPDsc
.getDataPilotFields().getByIndex(0);
191 fieldPropSet
= UnoRuntime
.queryInterface(
192 XPropertySet
.class, oDataPilotField
);
194 fieldPropSet
.setPropertyValue("Function",
195 com
.sun
.star
.sheet
.GeneralFunction
.SUM
);
196 fieldPropSet
.setPropertyValue("Orientation",
197 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.DATA
);
199 log
.println("Insert the DataPilotTable");
201 if (DPT
.hasByName("DataPilotTable")) {
202 DPT
.removeByName("DataPilotTable");
205 XIndexAccess IA
= DPDsc
.getDataPilotFields();
208 DPT
.insertNewByName("DataPilotTable", sCellAddress
, DPDsc
);
210 oObj
= (XInterface
) AnyConverter
.toObject(
211 new Type(XInterface
.class), IA
.getByIndex(0));
213 log
.println("Creating object - " +
214 ((oObj
== null) ?
"FAILED" : "OK"));
216 XDataPilotField xDataPilotField
= UnoRuntime
.queryInterface(
217 XDataPilotField
.class, oObj
);
219 XIndexAccess xIA
= xDataPilotField
.getItems();
221 oObj
= UnoRuntime
.queryInterface(XInterface
.class,
224 TestEnvironment tEnv
= new TestEnvironment(oObj
);
226 log
.println("Implementationname: " + util
.utils
.getImplName(oObj
));
228 // Other parameters required for interface tests
229 tEnv
.addObjRelation("NoSetName", "ScDataPilotItemObj");
233 private void getSRange(XIndexAccess IA
) {
234 int fieldsAmount
= IA
.getCount() + 1;
239 while ((++i
) < fieldsAmount
) {
243 field
= IA
.getByIndex(i
);
244 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
245 e
.printStackTrace(log
);
248 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
249 e
.printStackTrace(log
);
254 XNamed named
= UnoRuntime
.queryInterface(XNamed
.class,
256 String name
= named
.getName();
258 log
.println("**Field : '" + name
+ "' ... ");
260 if (!name
.equals("Data")) {
262 XPropertySet props
= UnoRuntime
.queryInterface(
263 XPropertySet
.class, field
);
268 props
.setPropertyValue("Orientation",
269 DataPilotFieldOrientation
.COLUMN
);
270 log
.println(" Column");
275 props
.setPropertyValue("Orientation",
276 DataPilotFieldOrientation
.ROW
);
282 props
.setPropertyValue("Orientation",
283 DataPilotFieldOrientation
.DATA
);
284 log
.println(" Data");
289 props
.setPropertyValue("Orientation",
290 DataPilotFieldOrientation
.HIDDEN
);
291 log
.println(" Hidden");
296 props
.setPropertyValue("Orientation",
297 DataPilotFieldOrientation
.PAGE
);
298 log
.println(" Page");
302 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
303 e
.printStackTrace(log
);
306 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
307 e
.printStackTrace(log
);
310 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
311 e
.printStackTrace(log
);
314 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
315 e
.printStackTrace(log
);