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
.DataPilotFieldGroupInfo
;
25 import com
.sun
.star
.sheet
.XDataPilotDescriptor
;
26 import com
.sun
.star
.sheet
.XDataPilotFieldGrouping
;
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 public class ScDataPilotFieldGroupsObj
extends TestCase
52 private XSpreadsheetDocument xSheetDoc
= null;
55 * A field is filled some values. This integer determines the size of the
56 * field in x and y direction.
58 private static final int mMaxFieldIndex
= 6;
61 * Creates Spreadsheet document.
64 protected void initialize (TestParameters tParam
, PrintWriter log
)
66 SOfficeFactory SOF
= SOfficeFactory
.getFactory (
71 log
.println ("creating a Spreadsheet document");
72 xSheetDoc
= SOF
.createCalcDoc (null);
74 catch (com
.sun
.star
.uno
.Exception e
)
76 // Some exception occurs.FAILED
77 e
.printStackTrace (log
);
78 throw new StatusException ("Couldn't create document", e
);
83 * Disposes Spreadsheet document.
86 protected void cleanup (TestParameters tParam
, PrintWriter log
)
88 log
.println (" disposing xSheetDoc ");
90 XComponent oComp
= UnoRuntime
.queryInterface (
91 XComponent
.class, xSheetDoc
);
92 util
.DesktopTools
.closeDoc (oComp
);
96 protected synchronized TestEnvironment
createTestEnvironment (TestParameters Param
,
99 XInterface oObj
= null;
100 XInterface datapilotfield
= null;
103 // creation of testobject here
104 // first we write what we are intend to do to log file
105 log
.println ("Creating a test environment");
108 CellRangeAddress sCellRangeAdress
= new CellRangeAddress ();
109 sCellRangeAdress
.Sheet
= 0;
110 sCellRangeAdress
.StartColumn
= 1;
111 sCellRangeAdress
.StartRow
= 0;
112 sCellRangeAdress
.EndColumn
= mMaxFieldIndex
- 1;
113 sCellRangeAdress
.EndRow
= mMaxFieldIndex
- 1;
115 // position of the data pilot table
116 CellAddress sCellAdress
= new CellAddress ();
117 sCellAdress
.Sheet
= 0;
118 sCellAdress
.Column
= 7;
121 log
.println ("Getting a sheet");
123 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets ();
124 XSpreadsheet oSheet
= null;
125 XSpreadsheet oSheet2
= null;
126 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface (
127 XIndexAccess
.class, xSpreadsheets
);
128 // Make sure there are at least two sheets
129 xSpreadsheets
.insertNewByName("Some Sheet", (short)0);
133 oSheet
= (XSpreadsheet
) AnyConverter
.toObject (
134 new Type (XSpreadsheet
.class),
135 oIndexAccess
.getByIndex (0));
136 oSheet2
= (XSpreadsheet
) AnyConverter
.toObject (
137 new Type (XSpreadsheet
.class),
138 oIndexAccess
.getByIndex (1));
140 catch (com
.sun
.star
.lang
.WrappedTargetException e
)
142 e
.printStackTrace ();
143 throw new StatusException ("Couldn't get a spreadsheet", e
);
145 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
147 e
.printStackTrace ();
148 throw new StatusException ("Couldn't get a spreadsheet", e
);
150 catch (com
.sun
.star
.lang
.IllegalArgumentException e
)
152 e
.printStackTrace ();
153 throw new StatusException ("Couldn't get a spreadsheet", e
);
158 log
.println ("Filling a table");
160 for (int i
= 1; i
< mMaxFieldIndex
; i
++)
162 oSheet
.getCellByPosition (i
, 0).setFormula ("Col" + i
);
163 oSheet
.getCellByPosition (0, i
).setFormula ("Row" + i
);
164 oSheet2
.getCellByPosition (i
, 0).setFormula ("Col" + i
);
165 oSheet2
.getCellByPosition (0, i
).setFormula ("Row" + i
);
168 for (int i
= 1; i
< mMaxFieldIndex
; i
++)
170 for (int j
= 1; j
< mMaxFieldIndex
; j
++)
172 oSheet
.getCellByPosition (i
, j
).setValue (i
* (j
+ 1));
173 oSheet2
.getCellByPosition (i
, j
).setValue (i
* (j
+ 2));
177 oSheet
.getCellByPosition (1, 1).setFormula ("aName");
178 oSheet
.getCellByPosition (1, 2).setFormula ("otherName");
179 oSheet
.getCellByPosition (1, 3).setFormula ("una");
180 oSheet
.getCellByPosition (1, 4).setFormula ("otherName");
181 oSheet
.getCellByPosition (1, 5).setFormula ("somethingelse");
184 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
186 e
.printStackTrace ();
187 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
);
201 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
203 e
.printStackTrace ();
204 throw new StatusException ("Couldn't get cells for changing.", e
);
208 // create the test objects
209 log
.println ("Getting test objects");
211 XDataPilotTablesSupplier DPTS
= UnoRuntime
.queryInterface (
212 XDataPilotTablesSupplier
.class,
214 XDataPilotTables DPT
= DPTS
.getDataPilotTables ();
215 XDataPilotDescriptor DPDsc
= DPT
.createDataPilotDescriptor ();
216 DPDsc
.setSourceRange (sCellRangeAdress
);
218 XPropertySet fieldPropSet
= null;
222 Object oDataPilotField
= DPDsc
.getDataPilotFields ().getByIndex (0);
223 fieldPropSet
= UnoRuntime
.queryInterface (
224 XPropertySet
.class, oDataPilotField
);
225 fieldPropSet
.setPropertyValue ("Orientation",
226 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.ROW
);
227 oDataPilotField
= DPDsc
.getDataPilotFields ().getByIndex (1);
228 fieldPropSet
= UnoRuntime
.queryInterface (
229 XPropertySet
.class, oDataPilotField
);
230 fieldPropSet
.setPropertyValue ("Function",
231 com
.sun
.star
.sheet
.GeneralFunction
.SUM
);
232 fieldPropSet
.setPropertyValue ("Orientation",
233 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.DATA
);
234 oDataPilotField
= DPDsc
.getDataPilotFields ().getByIndex (2);
235 fieldPropSet
= UnoRuntime
.queryInterface (
236 XPropertySet
.class, oDataPilotField
);
237 fieldPropSet
.setPropertyValue ("Orientation",
238 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.COLUMN
);
240 catch (com
.sun
.star
.lang
.WrappedTargetException e
)
242 e
.printStackTrace ();
243 throw new StatusException ("Couldn't create a test environment", e
);
245 catch (com
.sun
.star
.lang
.IllegalArgumentException e
)
247 e
.printStackTrace ();
248 throw new StatusException ("Couldn't create a test environment", e
);
250 catch (com
.sun
.star
.beans
.PropertyVetoException e
)
252 e
.printStackTrace ();
253 throw new StatusException ("Couldn't create a test environment", e
);
255 catch (com
.sun
.star
.beans
.UnknownPropertyException e
)
257 e
.printStackTrace ();
258 throw new StatusException ("Couldn't create a test environment", e
);
260 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
262 e
.printStackTrace ();
263 throw new StatusException ("Couldn't create a test environment", e
);
266 log
.println ("Insert the DataPilotTable");
268 if (DPT
.hasByName ("DataPilotTable"))
270 DPT
.removeByName ("DataPilotTable");
273 DPT
.insertNewByName ("DataPilotTable", sCellAdress
, DPDsc
);
274 XIndexAccess xIA
= UnoRuntime
.queryInterface (XIndexAccess
.class,DPTS
.getDataPilotTables ());
275 XIndexAccess IA
= null;
278 XDataPilotDescriptor xDPT
= UnoRuntime
.queryInterface (XDataPilotDescriptor
.class,xIA
.getByIndex (0));
279 IA
= xDPT
.getRowFields ();
280 System
.out
.println ("COUNT: "+IA
.getCount ());
281 datapilotfield
= (XInterface
) AnyConverter
.toObject (
282 new Type (XInterface
.class), IA
.getByIndex (0));
284 catch (com
.sun
.star
.lang
.WrappedTargetException e
)
286 e
.printStackTrace ();
287 throw new StatusException ("Couldn't get data pilot field", e
);
289 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
291 e
.printStackTrace ();
292 throw new StatusException ("Couldn't get data pilot field", e
);
294 catch (com
.sun
.star
.lang
.IllegalArgumentException e
)
296 e
.printStackTrace ();
297 throw new StatusException ("Couldn't get data pilot field", e
);
302 XDataPilotFieldGrouping dpfg
= UnoRuntime
.queryInterface (XDataPilotFieldGrouping
.class, datapilotfield
);
303 String
[] elements
= new String
[]{"aName","otherName"};
304 dpfg
.createNameGroup (elements
);
305 DataPilotFieldGroupInfo dpgi
=null;
306 xIA
= UnoRuntime
.queryInterface (XIndexAccess
.class,DPTS
.getDataPilotTables ());
309 XDataPilotDescriptor xDPT
= UnoRuntime
.queryInterface (XDataPilotDescriptor
.class,xIA
.getByIndex (0));
310 IA
= xDPT
.getRowFields ();
312 catch (com
.sun
.star
.lang
.WrappedTargetException e
)
314 e
.printStackTrace ();
315 throw new StatusException ("Couldn't get data pilot field", e
);
317 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
319 e
.printStackTrace ();
320 throw new StatusException ("Couldn't get data pilot field", e
);
322 for (int i
=0;i
<IA
.getCount ();i
++)
324 datapilotfield
= (XInterface
) AnyConverter
.toObject (
325 new Type (XInterface
.class), IA
.getByIndex (i
));
326 XPropertySet xPropertySet
= UnoRuntime
.queryInterface (XPropertySet
.class, IA
.getByIndex (i
));
327 if (((Boolean
)xPropertySet
.getPropertyValue ("IsGroupField")).booleanValue ())
329 xPropertySet
= UnoRuntime
.queryInterface (XPropertySet
.class, datapilotfield
);
330 XNamed xNamed
= UnoRuntime
.queryInterface (XNamed
.class, IA
.getByIndex (i
));
331 System
.out
.println ("name: "+xNamed
.getName ());
332 dpgi
= (DataPilotFieldGroupInfo
) xPropertySet
.getPropertyValue ("GroupInfo");
339 e
.printStackTrace ();
342 log
.println ("Creating object - " +
343 ((oObj
== null) ?
"FAILED" : "OK"));
345 TestEnvironment tEnv
= new TestEnvironment (oObj
);
347 log
.println ("Implementationname: " + util
.utils
.getImplName (oObj
));
349 // Other parameters required for interface tests