1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScDataPilotFieldGroupItemObj.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import com
.sun
.star
.beans
.XPropertySet
;
33 import com
.sun
.star
.container
.XIndexAccess
;
34 import com
.sun
.star
.container
.XNameAccess
;
35 import com
.sun
.star
.container
.XNamed
;
36 import com
.sun
.star
.lang
.XComponent
;
37 import com
.sun
.star
.lang
.XMultiServiceFactory
;
38 import com
.sun
.star
.sheet
.DataPilotFieldGroupInfo
;
39 import com
.sun
.star
.sheet
.XDataPilotDescriptor
;
40 import com
.sun
.star
.sheet
.XDataPilotFieldGrouping
;
41 import com
.sun
.star
.sheet
.XDataPilotTables
;
42 import com
.sun
.star
.sheet
.XDataPilotTablesSupplier
;
43 import com
.sun
.star
.sheet
.XSpreadsheet
;
44 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
45 import com
.sun
.star
.sheet
.XSpreadsheets
;
46 import com
.sun
.star
.table
.CellAddress
;
47 import com
.sun
.star
.table
.CellRangeAddress
;
48 import com
.sun
.star
.uno
.AnyConverter
;
49 import com
.sun
.star
.uno
.Type
;
50 import com
.sun
.star
.uno
.UnoRuntime
;
51 import com
.sun
.star
.uno
.XInterface
;
53 import java
.io
.PrintWriter
;
55 import lib
.StatusException
;
57 import lib
.TestEnvironment
;
58 import lib
.TestParameters
;
60 import util
.SOfficeFactory
;
64 public class ScDataPilotFieldGroupItemObj
extends TestCase
66 static 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 int mMaxFieldIndex
= 6;
75 * Creates Spreadsheet document.
77 protected void initialize (TestParameters tParam
, PrintWriter log
)
79 SOfficeFactory SOF
= SOfficeFactory
.getFactory (
80 (XMultiServiceFactory
) tParam
.getMSF ());
84 log
.println ("creating a Spreadsheet document");
85 xSheetDoc
= SOF
.createCalcDoc (null);
87 catch (com
.sun
.star
.uno
.Exception e
)
89 // Some exception occures.FAILED
90 e
.printStackTrace (log
);
91 throw new StatusException ("Couldn't create document", e
);
96 * Disposes Spreadsheet document.
98 protected void cleanup (TestParameters tParam
, PrintWriter log
)
100 log
.println (" disposing xSheetDoc ");
102 XComponent oComp
= (XComponent
) UnoRuntime
.queryInterface (
103 XComponent
.class, xSheetDoc
);
104 util
.DesktopTools
.closeDoc (oComp
);
107 protected synchronized TestEnvironment
createTestEnvironment (TestParameters Param
,
110 XInterface oObj
= null;
111 XInterface datapilotfield
= null;
112 XInterface groups
= null;
114 // creation of testobject here
115 // first we write what we are intend to do to log file
116 log
.println ("Creating a test environment");
119 CellRangeAddress sCellRangeAdress
= new CellRangeAddress ();
120 sCellRangeAdress
.Sheet
= 0;
121 sCellRangeAdress
.StartColumn
= 1;
122 sCellRangeAdress
.StartRow
= 0;
123 sCellRangeAdress
.EndColumn
= mMaxFieldIndex
- 1;
124 sCellRangeAdress
.EndRow
= mMaxFieldIndex
- 1;
126 // position of the data pilot table
127 CellAddress sCellAdress
= new CellAddress ();
128 sCellAdress
.Sheet
= 0;
129 sCellAdress
.Column
= 7;
132 log
.println ("Getting a sheet");
134 XSpreadsheets xSpreadsheets
= (XSpreadsheets
) xSheetDoc
.getSheets ();
135 XSpreadsheet oSheet
= null;
136 XSpreadsheet oSheet2
= null;
137 XIndexAccess oIndexAccess
= (XIndexAccess
) UnoRuntime
.queryInterface (
138 XIndexAccess
.class, xSpreadsheets
);
142 oSheet
= (XSpreadsheet
) AnyConverter
.toObject (
143 new Type (XSpreadsheet
.class),
144 oIndexAccess
.getByIndex (0));
145 oSheet2
= (XSpreadsheet
) AnyConverter
.toObject (
146 new Type (XSpreadsheet
.class),
147 oIndexAccess
.getByIndex (1));
149 catch (com
.sun
.star
.lang
.WrappedTargetException e
)
151 e
.printStackTrace ();
152 throw new StatusException ("Couldn't get a spreadsheet", e
);
154 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
156 e
.printStackTrace ();
157 throw new StatusException ("Couldn't get a spreadsheet", e
);
159 catch (com
.sun
.star
.lang
.IllegalArgumentException e
)
161 e
.printStackTrace ();
162 throw new StatusException ("Couldn't get a spreadsheet", e
);
167 log
.println ("Filling a table");
169 for (int i
= 1; i
< mMaxFieldIndex
; i
++)
171 oSheet
.getCellByPosition (i
, 0).setFormula ("Col" + i
);
172 oSheet
.getCellByPosition (0, i
).setFormula ("Row" + i
);
173 oSheet2
.getCellByPosition (i
, 0).setFormula ("Col" + i
);
174 oSheet2
.getCellByPosition (0, i
).setFormula ("Row" + i
);
177 for (int i
= 1; i
< mMaxFieldIndex
; i
++)
179 for (int j
= 1; j
< mMaxFieldIndex
; j
++)
181 oSheet
.getCellByPosition (i
, j
).setValue (i
* (j
+ 1));
182 oSheet2
.getCellByPosition (i
, j
).setValue (i
* (j
+ 2));
186 oSheet
.getCellByPosition (1, 1).setFormula ("aName");
187 oSheet
.getCellByPosition (1, 2).setFormula ("otherName");
188 oSheet
.getCellByPosition (1, 3).setFormula ("una");
189 oSheet
.getCellByPosition (1, 4).setFormula ("otherName");
190 oSheet
.getCellByPosition (1, 5).setFormula ("somethingelse");
193 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
195 e
.printStackTrace ();
196 throw new StatusException ("Couldn't fill some cells", e
);
199 // change a value of a cell and check the change in the data pilot
200 // (for the XDataPilotTable.refresh() test)
201 Object oChangeCell
= null;
202 Object oCheckCell
= null;
203 Integer aChangeValue
= null;
208 oChangeCell
= oSheet
.getCellByPosition (1, 5);
210 int x
= sCellAdress
.Column
;
211 int y
= sCellAdress
.Row
+ 3;
214 // cell of the data pilot output
215 oCheckCell
= oSheet
.getCellByPosition (x
, y
);
216 aChangeValue
= new Integer (27);
218 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
220 e
.printStackTrace ();
221 throw new StatusException ("Couldn't get cells for changeing.", e
);
225 // create the test objects
226 log
.println ("Getting test objects");
228 XDataPilotTablesSupplier DPTS
= (XDataPilotTablesSupplier
) UnoRuntime
.queryInterface (
229 XDataPilotTablesSupplier
.class,
231 XDataPilotTables DPT
= DPTS
.getDataPilotTables ();
232 XDataPilotDescriptor DPDsc
= DPT
.createDataPilotDescriptor ();
233 DPDsc
.setSourceRange (sCellRangeAdress
);
235 XPropertySet fieldPropSet
= null;
239 Object oDataPilotField
= DPDsc
.getDataPilotFields ().getByIndex (0);
240 fieldPropSet
= (XPropertySet
) UnoRuntime
.queryInterface (
241 XPropertySet
.class, oDataPilotField
);
242 fieldPropSet
.setPropertyValue ("Orientation",
243 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.ROW
);
244 oDataPilotField
= DPDsc
.getDataPilotFields ().getByIndex (1);
245 fieldPropSet
= (XPropertySet
) UnoRuntime
.queryInterface (
246 XPropertySet
.class, oDataPilotField
);
247 fieldPropSet
.setPropertyValue ("Function",
248 com
.sun
.star
.sheet
.GeneralFunction
.SUM
);
249 fieldPropSet
.setPropertyValue ("Orientation",
250 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.DATA
);
251 oDataPilotField
= DPDsc
.getDataPilotFields ().getByIndex (2);
252 fieldPropSet
= (XPropertySet
) UnoRuntime
.queryInterface (
253 XPropertySet
.class, oDataPilotField
);
254 fieldPropSet
.setPropertyValue ("Orientation",
255 com
.sun
.star
.sheet
.DataPilotFieldOrientation
.COLUMN
);
257 catch (com
.sun
.star
.lang
.WrappedTargetException e
)
259 e
.printStackTrace ();
260 throw new StatusException ("Couldn't create a test environment", e
);
262 catch (com
.sun
.star
.lang
.IllegalArgumentException e
)
264 e
.printStackTrace ();
265 throw new StatusException ("Couldn't create a test environment", e
);
267 catch (com
.sun
.star
.beans
.PropertyVetoException e
)
269 e
.printStackTrace ();
270 throw new StatusException ("Couldn't create a test environment", e
);
272 catch (com
.sun
.star
.beans
.UnknownPropertyException e
)
274 e
.printStackTrace ();
275 throw new StatusException ("Couldn't create a test environment", e
);
277 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
279 e
.printStackTrace ();
280 throw new StatusException ("Couldn't create a test environment", e
);
283 log
.println ("Insert the DataPilotTable");
285 if (DPT
.hasByName ("DataPilotTable"))
287 DPT
.removeByName ("DataPilotTable");
290 DPT
.insertNewByName ("DataPilotTable", sCellAdress
, DPDsc
);
291 XIndexAccess xIA
= (XIndexAccess
) UnoRuntime
.queryInterface (XIndexAccess
.class,DPTS
.getDataPilotTables ());
292 XIndexAccess IA
= null;
295 XDataPilotDescriptor xDPT
= (XDataPilotDescriptor
) UnoRuntime
.queryInterface (XDataPilotDescriptor
.class,xIA
.getByIndex (0));
296 IA
= xDPT
.getRowFields ();
298 System
.out
.println ("COUNT: "+IA
.getCount ());
299 datapilotfield
= (XInterface
) AnyConverter
.toObject (
300 new Type (XInterface
.class), IA
.getByIndex (0));
302 catch (com
.sun
.star
.lang
.WrappedTargetException e
)
304 e
.printStackTrace ();
305 throw new StatusException ("Couldn't get data pilot field", e
);
307 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
309 e
.printStackTrace ();
310 throw new StatusException ("Couldn't get data pilot field", e
);
312 catch (com
.sun
.star
.lang
.IllegalArgumentException e
)
314 e
.printStackTrace ();
315 throw new StatusException ("Couldn't get data pilot field", e
);
320 XDataPilotFieldGrouping dpfg
= (XDataPilotFieldGrouping
) UnoRuntime
.queryInterface (XDataPilotFieldGrouping
.class, datapilotfield
);
321 String
[] elements
= new String
[]{"aName","otherName"};
322 dpfg
.createNameGroup (elements
);
323 DataPilotFieldGroupInfo dpgi
=null;
324 xIA
= (XIndexAccess
) UnoRuntime
.queryInterface (XIndexAccess
.class,DPTS
.getDataPilotTables ());
327 XDataPilotDescriptor xDPT
= (XDataPilotDescriptor
) UnoRuntime
.queryInterface (XDataPilotDescriptor
.class,xIA
.getByIndex (0));
328 IA
= xDPT
.getRowFields ();
330 catch (com
.sun
.star
.lang
.WrappedTargetException e
)
332 e
.printStackTrace ();
333 throw new StatusException ("Couldn't get data pilot field", e
);
335 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
337 e
.printStackTrace ();
338 throw new StatusException ("Couldn't get data pilot field", e
);
340 for (int i
=0;i
<IA
.getCount ();i
++)
342 datapilotfield
= (XInterface
) AnyConverter
.toObject (
343 new Type (XInterface
.class), IA
.getByIndex (i
));
344 XPropertySet xPropertySet
= (XPropertySet
) UnoRuntime
.queryInterface (XPropertySet
.class, IA
.getByIndex (i
));
345 if (((Boolean
)xPropertySet
.getPropertyValue ("IsGroupField")).booleanValue ())
347 xPropertySet
= (XPropertySet
) UnoRuntime
.queryInterface (XPropertySet
.class, datapilotfield
);
348 XNamed xNamed
= (XNamed
) UnoRuntime
.queryInterface (XNamed
.class, IA
.getByIndex (i
));
349 System
.out
.println ("name: "+xNamed
.getName ());
350 dpgi
= (DataPilotFieldGroupInfo
) xPropertySet
.getPropertyValue ("GroupInfo");
353 groups
= dpgi
.Groups
;
354 XIndexAccess groupAccess
= (XIndexAccess
) UnoRuntime
.queryInterface(XIndexAccess
.class, groups
);
355 XNameAccess groupNames
= (XNameAccess
) UnoRuntime
.queryInterface(XNameAccess
.class, groupAccess
.getByIndex(0));
356 oObj
= (XInterface
) UnoRuntime
.queryInterface(XInterface
.class, groupNames
.getByName("aName"));
360 e
.printStackTrace ();
363 log
.println ("Creating object - " +
364 ((oObj
== null) ?
"FAILED" : "OK"));
366 TestEnvironment tEnv
= new TestEnvironment (oObj
);
368 log
.println ("Implementationname: " + util
.utils
.getImplName (oObj
));
370 // Other parameters required for interface tests