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
.XNameAccess
;
23 import com
.sun
.star
.container
.XNamed
;
24 import com
.sun
.star
.lang
.XComponent
;
25 import com
.sun
.star
.sheet
.DataPilotFieldGroupInfo
;
26 import com
.sun
.star
.sheet
.XDataPilotDescriptor
;
27 import com
.sun
.star
.sheet
.XDataPilotFieldGrouping
;
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 public class ScDataPilotFieldGroupItemObj
extends TestCase
53 private XSpreadsheetDocument xSheetDoc
= null;
56 * A field is filled some values. This integer determines the size of the
57 * field in x and y direction.
59 private static final int mMaxFieldIndex
= 6;
62 * Creates Spreadsheet document.
65 protected void initialize (TestParameters tParam
, PrintWriter log
)
67 SOfficeFactory SOF
= SOfficeFactory
.getFactory (
72 log
.println ("creating a Spreadsheet document");
73 xSheetDoc
= SOF
.createCalcDoc (null);
75 catch (com
.sun
.star
.uno
.Exception e
)
77 // Some exception occurs.FAILED
78 e
.printStackTrace (log
);
79 throw new StatusException ("Couldn't create document", e
);
84 * Disposes Spreadsheet document.
87 protected void cleanup (TestParameters tParam
, PrintWriter log
)
89 log
.println (" disposing xSheetDoc ");
91 XComponent oComp
= UnoRuntime
.queryInterface (
92 XComponent
.class, xSheetDoc
);
93 util
.DesktopTools
.closeDoc (oComp
);
97 protected synchronized TestEnvironment
createTestEnvironment (TestParameters Param
,
100 XInterface oObj
= null;
101 XInterface datapilotfield
= null;
102 XInterface groups
= null;
104 // creation of testobject here
105 // first we write what we are intend to do to log file
106 log
.println ("Creating a test environment");
109 CellRangeAddress sCellRangeAdress
= new CellRangeAddress ();
110 sCellRangeAdress
.Sheet
= 0;
111 sCellRangeAdress
.StartColumn
= 1;
112 sCellRangeAdress
.StartRow
= 0;
113 sCellRangeAdress
.EndColumn
= mMaxFieldIndex
- 1;
114 sCellRangeAdress
.EndRow
= mMaxFieldIndex
- 1;
116 // position of the data pilot table
117 CellAddress sCellAdress
= new CellAddress ();
118 sCellAdress
.Sheet
= 0;
119 sCellAdress
.Column
= 7;
122 log
.println ("Getting a sheet");
124 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets ();
125 XSpreadsheet oSheet
= null;
126 XSpreadsheet oSheet2
= null;
127 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface (
128 XIndexAccess
.class, xSpreadsheets
);
129 // Make sure there are at least two sheets
130 xSpreadsheets
.insertNewByName("Some Sheet", (short)0);
134 oSheet
= (XSpreadsheet
) AnyConverter
.toObject (
135 new Type (XSpreadsheet
.class),
136 oIndexAccess
.getByIndex (0));
137 oSheet2
= (XSpreadsheet
) AnyConverter
.toObject (
138 new Type (XSpreadsheet
.class),
139 oIndexAccess
.getByIndex (1));
141 catch (com
.sun
.star
.lang
.WrappedTargetException e
)
143 e
.printStackTrace ();
144 throw new StatusException ("Couldn't get a spreadsheet", e
);
146 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
148 e
.printStackTrace ();
149 throw new StatusException ("Couldn't get a spreadsheet", e
);
151 catch (com
.sun
.star
.lang
.IllegalArgumentException e
)
153 e
.printStackTrace ();
154 throw new StatusException ("Couldn't get a spreadsheet", e
);
159 log
.println ("Filling a table");
161 for (int i
= 1; i
< mMaxFieldIndex
; i
++)
163 oSheet
.getCellByPosition (i
, 0).setFormula ("Col" + i
);
164 oSheet
.getCellByPosition (0, i
).setFormula ("Row" + i
);
165 oSheet2
.getCellByPosition (i
, 0).setFormula ("Col" + i
);
166 oSheet2
.getCellByPosition (0, i
).setFormula ("Row" + i
);
169 for (int i
= 1; i
< mMaxFieldIndex
; i
++)
171 for (int j
= 1; j
< mMaxFieldIndex
; j
++)
173 oSheet
.getCellByPosition (i
, j
).setValue (i
* (j
+ 1));
174 oSheet2
.getCellByPosition (i
, j
).setValue (i
* (j
+ 2));
178 oSheet
.getCellByPosition (1, 1).setFormula ("aName");
179 oSheet
.getCellByPosition (1, 2).setFormula ("otherName");
180 oSheet
.getCellByPosition (1, 3).setFormula ("una");
181 oSheet
.getCellByPosition (1, 4).setFormula ("otherName");
182 oSheet
.getCellByPosition (1, 5).setFormula ("somethingelse");
185 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
187 e
.printStackTrace ();
188 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
);
202 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
204 e
.printStackTrace ();
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;
223 Object oDataPilotField
= DPDsc
.getDataPilotFields ().getByIndex (0);
224 fieldPropSet
= UnoRuntime
.queryInterface (
225 XPropertySet
.class, oDataPilotField
);
226 fieldPropSet
.setPropertyValue ("Orientation",
227 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.ROW
);
228 oDataPilotField
= DPDsc
.getDataPilotFields ().getByIndex (1);
229 fieldPropSet
= UnoRuntime
.queryInterface (
230 XPropertySet
.class, oDataPilotField
);
231 fieldPropSet
.setPropertyValue ("Function",
232 com
.sun
.star
.sheet
.GeneralFunction
.SUM
);
233 fieldPropSet
.setPropertyValue ("Orientation",
234 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.DATA
);
235 oDataPilotField
= DPDsc
.getDataPilotFields ().getByIndex (2);
236 fieldPropSet
= UnoRuntime
.queryInterface (
237 XPropertySet
.class, oDataPilotField
);
238 fieldPropSet
.setPropertyValue ("Orientation",
239 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.COLUMN
);
241 catch (com
.sun
.star
.lang
.WrappedTargetException e
)
243 e
.printStackTrace ();
244 throw new StatusException ("Couldn't create a test environment", e
);
246 catch (com
.sun
.star
.lang
.IllegalArgumentException e
)
248 e
.printStackTrace ();
249 throw new StatusException ("Couldn't create a test environment", e
);
251 catch (com
.sun
.star
.beans
.PropertyVetoException e
)
253 e
.printStackTrace ();
254 throw new StatusException ("Couldn't create a test environment", e
);
256 catch (com
.sun
.star
.beans
.UnknownPropertyException e
)
258 e
.printStackTrace ();
259 throw new StatusException ("Couldn't create a test environment", e
);
261 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
263 e
.printStackTrace ();
264 throw new StatusException ("Couldn't create a test environment", e
);
267 log
.println ("Insert the DataPilotTable");
269 if (DPT
.hasByName ("DataPilotTable"))
271 DPT
.removeByName ("DataPilotTable");
274 DPT
.insertNewByName ("DataPilotTable", sCellAdress
, DPDsc
);
275 XIndexAccess xIA
= UnoRuntime
.queryInterface (XIndexAccess
.class,DPTS
.getDataPilotTables ());
276 XIndexAccess IA
= null;
279 XDataPilotDescriptor xDPT
= UnoRuntime
.queryInterface (XDataPilotDescriptor
.class,xIA
.getByIndex (0));
280 IA
= xDPT
.getRowFields ();
281 System
.out
.println ("COUNT: "+IA
.getCount ());
282 datapilotfield
= (XInterface
) AnyConverter
.toObject (
283 new Type (XInterface
.class), IA
.getByIndex (0));
285 catch (com
.sun
.star
.lang
.WrappedTargetException e
)
287 e
.printStackTrace ();
288 throw new StatusException ("Couldn't get data pilot field", e
);
290 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
292 e
.printStackTrace ();
293 throw new StatusException ("Couldn't get data pilot field", e
);
295 catch (com
.sun
.star
.lang
.IllegalArgumentException e
)
297 e
.printStackTrace ();
298 throw new StatusException ("Couldn't get data pilot field", e
);
303 XDataPilotFieldGrouping dpfg
= UnoRuntime
.queryInterface (XDataPilotFieldGrouping
.class, datapilotfield
);
304 String
[] elements
= new String
[]{"aName","otherName"};
305 dpfg
.createNameGroup (elements
);
306 DataPilotFieldGroupInfo dpgi
=null;
307 xIA
= UnoRuntime
.queryInterface (XIndexAccess
.class,DPTS
.getDataPilotTables ());
310 XDataPilotDescriptor xDPT
= UnoRuntime
.queryInterface (XDataPilotDescriptor
.class,xIA
.getByIndex (0));
311 IA
= xDPT
.getRowFields ();
313 catch (com
.sun
.star
.lang
.WrappedTargetException e
)
315 e
.printStackTrace ();
316 throw new StatusException ("Couldn't get data pilot field", e
);
318 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
320 e
.printStackTrace ();
321 throw new StatusException ("Couldn't get data pilot field", e
);
323 for (int i
=0;i
<IA
.getCount ();i
++)
325 datapilotfield
= (XInterface
) AnyConverter
.toObject (
326 new Type (XInterface
.class), IA
.getByIndex (i
));
327 XPropertySet xPropertySet
= UnoRuntime
.queryInterface (XPropertySet
.class, IA
.getByIndex (i
));
328 if (((Boolean
)xPropertySet
.getPropertyValue ("IsGroupField")).booleanValue ())
330 xPropertySet
= UnoRuntime
.queryInterface (XPropertySet
.class, datapilotfield
);
331 XNamed xNamed
= UnoRuntime
.queryInterface (XNamed
.class, IA
.getByIndex (i
));
332 System
.out
.println ("name: "+xNamed
.getName ());
333 dpgi
= (DataPilotFieldGroupInfo
) xPropertySet
.getPropertyValue ("GroupInfo");
336 groups
= dpgi
.Groups
;
337 XIndexAccess groupAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, groups
);
338 XNameAccess groupNames
= UnoRuntime
.queryInterface(XNameAccess
.class, groupAccess
.getByIndex(0));
339 oObj
= UnoRuntime
.queryInterface(XInterface
.class, groupNames
.getByName("aName"));
343 e
.printStackTrace ();
346 log
.println ("Creating object - " +
347 ((oObj
== null) ?
"FAILED" : "OK"));
349 TestEnvironment tEnv
= new TestEnvironment (oObj
);
351 log
.println ("Implementationname: " + util
.utils
.getImplName (oObj
));
353 // Other parameters required for interface tests