Update ooo320-m1
[ooovba.git] / sc / qa / complex / dataPilot / CheckDataPilot.java
blob0c58897aaa1ca6c791f795db2acb28fb0e83be42
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CheckDataPilot.java,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
31 package complex.dataPilot;
33 import com.sun.star.beans.XPropertySet;
34 import com.sun.star.container.XIndexAccess;
35 import com.sun.star.container.XNamed;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.sheet.TableFilterField;
38 import com.sun.star.sheet.XDataPilotDescriptor;
39 import com.sun.star.sheet.XDataPilotTable;
40 import com.sun.star.sheet.XDataPilotTables;
41 import com.sun.star.sheet.XDataPilotTablesSupplier;
42 import com.sun.star.sheet.XSheetFilterDescriptor;
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;
52 import complex.dataPilot.interfaceTests.beans._XPropertySet;
53 import complex.dataPilot.interfaceTests.container._XNamed;
54 import complex.dataPilot.interfaceTests.sheet._XDataPilotDescriptor;
55 import complex.dataPilot.interfaceTests.sheet._XDataPilotTable;
56 import complexlib.ComplexTestCase;
57 import lib.StatusException;
58 import util.SOfficeFactory;
60 /**
61 * check the DataPilot of Calc.
63 public class CheckDataPilot extends ComplexTestCase {
64 /** The data pilot field object **/
65 private XInterface mDataPilotFieldObject = null;
66 /** The data pilot table object **/
67 private XInterface mDataPilotTableObject = null;
69 /**
70 * A field is filled some values. This integer determines the size of the
71 * field in x and y direction.
73 private int mMaxFieldIndex = 6;
76 /**
77 * Get all test methods
78 * @return The test methods
80 public String[] getTestMethodNames() {
81 return new String[]{"testDataPilotTableObject",
82 "testDataPilotFieldObject"};
85 /**
86 * Test the data pilot field object:
87 * simply execute the interface tests in a row
89 public void testDataPilotFieldObject() {
90 log.println("Starting 'testDataPilotFieldObject'");
91 // _XNamed
92 XNamed xNamed = (XNamed)UnoRuntime.queryInterface(
93 XNamed.class, mDataPilotFieldObject);
95 _XNamed _xNamed = new _XNamed(xNamed, log, param);
96 assure("_getName failed.",_xNamed._getName());
97 assure("_setName failed.",_xNamed._setName());
99 // _XPropertySet
100 XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(
101 XPropertySet.class, mDataPilotFieldObject);
102 _XPropertySet _xProp = new _XPropertySet(xProp, log, param);
103 assure("_getPropertySetInfo failed.",_xProp._getPropertySetInfo());
104 assure("_addPropertyChangeListener failed.",_xProp._addPropertyChangeListener());
105 assure("_addVetoableChangeListener failed.",_xProp._addVetoableChangeListener());
106 assure("_setPropertyValue failed.",_xProp._setPropertyValue());
107 assure("_getPropertyValue failed.",_xProp._getPropertyValue());
108 assure("_removePropertyChangeListener failed.",_xProp._removePropertyChangeListener());
109 assure("_removeVetoableChangeListener failed.",_xProp._removeVetoableChangeListener());
114 * Test the data pilot table object:
115 * simply execute the interface tests in a row
117 public void testDataPilotTableObject() {
118 log.println("Starting 'testDataPilotTableObject'");
119 // _XNamed
120 XNamed xNamed = (XNamed)UnoRuntime.queryInterface(
121 XNamed.class, mDataPilotTableObject);
122 _XNamed _xNamed = new _XNamed(xNamed, log, param);
123 assure("_getName failed.",_xNamed._getName());
124 assure("_setName failed.",_xNamed._setName());
126 // _XDataPilotTable
127 XDataPilotTable xDataPilotTable = (XDataPilotTable)
128 UnoRuntime.queryInterface(XDataPilotTable.class,
129 mDataPilotTableObject);
130 _XDataPilotTable _xDataPilotTable =
131 new _XDataPilotTable(xDataPilotTable, log, param);
132 assure("before failed.", _xDataPilotTable.before());
133 assure("_getOutputRange failed.", _xDataPilotTable._getOutputRange()) ;
134 assure("_refresh failed.", _xDataPilotTable._refresh()) ;
136 // _XDataPilotDescriptor
137 XDataPilotDescriptor xDataPilotDescriptor = (XDataPilotDescriptor)
138 UnoRuntime.queryInterface(XDataPilotDescriptor.class,
139 mDataPilotTableObject);
140 _XDataPilotDescriptor _xDataPilotDescriptor =
141 new _XDataPilotDescriptor(xDataPilotDescriptor, log, param);
142 assure("before failed.", _xDataPilotDescriptor.before());
143 assure("_setTag failed.", _xDataPilotDescriptor._setTag()) ;
144 assure("_getTag failed.", _xDataPilotDescriptor._getTag()) ;
145 assure("_getFilterDescriptor failed.", _xDataPilotDescriptor._getFilterDescriptor()) ;
146 assure("_getDataPilotFields failed.", _xDataPilotDescriptor._getDataPilotFields()) ;
147 assure("_getColumnFields failed.", _xDataPilotDescriptor._getColumnFields()) ;
148 assure("_getRowFields failed.", _xDataPilotDescriptor._getRowFields()) ;
149 assure("_getDataFields failed.", _xDataPilotDescriptor._getDataFields()) ;
150 assure("_getHiddenFields failed.", _xDataPilotDescriptor._getHiddenFields()) ;
151 assure("_getPageFields failed.", _xDataPilotDescriptor._getPageFields()) ;
152 assure("_setSourceRange failed.", _xDataPilotDescriptor._setSourceRange()) ;
153 assure("_getSourceRange failed.", _xDataPilotDescriptor._getSourceRange()) ;
157 * create an environment for the test
159 public void before() {
160 Object oInterface = null;
161 XSpreadsheetDocument xSheetDoc = null;
163 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)param.getMSF() );
165 // the cell range
166 CellRangeAddress sCellRangeAdress = new CellRangeAddress();
167 sCellRangeAdress.Sheet = 0;
168 sCellRangeAdress.StartColumn = 1;
169 sCellRangeAdress.StartRow = 0;
170 sCellRangeAdress.EndColumn = mMaxFieldIndex-1;
171 sCellRangeAdress.EndRow = mMaxFieldIndex - 1;
173 // position of the data pilot table
174 CellAddress sCellAdress = new CellAddress();
175 sCellAdress.Sheet = 0;
176 sCellAdress.Column = 7;
177 sCellAdress.Row = 8;
179 try {
180 log.println( "Creating a Spreadsheet document" );
181 xSheetDoc = SOF.createCalcDoc(null);
182 } catch (com.sun.star.uno.Exception e) {
183 // Some exception occures.FAILED
184 e.printStackTrace();
185 throw new StatusException( "Couldn't create document", e );
188 log.println("Getting a sheet");
189 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSheetDoc.getSheets();
190 XSpreadsheet oSheet = null;
191 XSpreadsheet oSheet2 = null;
192 XIndexAccess oIndexAccess = (XIndexAccess)
193 UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
195 try {
196 oSheet = (XSpreadsheet) AnyConverter.toObject(
197 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
198 oSheet2 = (XSpreadsheet) AnyConverter.toObject(
199 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(1));
200 } catch (com.sun.star.lang.WrappedTargetException e) {
201 e.printStackTrace();
202 throw new StatusException( "Couldn't get a spreadsheet", e);
203 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
204 e.printStackTrace();
205 throw new StatusException( "Couldn't get a spreadsheet", e);
206 } catch (com.sun.star.lang.IllegalArgumentException e) {
207 e.printStackTrace();
208 throw new StatusException( "Couldn't get a spreadsheet", e);
211 try {
212 log.println("Filling a table");
213 for (int i = 1; i < mMaxFieldIndex; i++) {
214 oSheet.getCellByPosition(i, 0).setFormula("Col" + i);
215 oSheet.getCellByPosition(0, i).setFormula("Row" + i);
216 oSheet2.getCellByPosition(i, 0).setFormula("Col" + i);
217 oSheet2.getCellByPosition(0, i).setFormula("Row" + i);
220 for (int i = 1; i < mMaxFieldIndex; i++)
221 for (int j = 1; j < mMaxFieldIndex; j++) {
222 oSheet.getCellByPosition(i, j).setValue(i * (j + 1));
223 oSheet2.getCellByPosition(i, j).setValue(i * (j + 2));
225 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
226 e.printStackTrace();
227 throw new StatusException("Couldn't fill some cells", e);
230 // change a value of a cell and check the change in the data pilot
231 // (for the XDataPilotTable.refresh() test)
232 Object oChangeCell = null;
233 Object oCheckCell = null;
234 Integer aChangeValue = null;
235 try {
236 // cell of data
237 oChangeCell = oSheet.getCellByPosition(1, 5);
238 int x = sCellAdress.Column;
239 int y = sCellAdress.Row + 3;
240 // cell of the data pilot output
241 oCheckCell = oSheet.getCellByPosition(x, y);
242 aChangeValue = new Integer(27);
243 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
244 e.printStackTrace();
245 throw new StatusException( "Couldn't get cells for changeing.", e);
249 // create the test objects
250 log.println("Getting test objects") ;
251 XDataPilotTablesSupplier DPTS = (XDataPilotTablesSupplier)
252 UnoRuntime.queryInterface(XDataPilotTablesSupplier.class, oSheet);
253 XDataPilotTables DPT = DPTS.getDataPilotTables();
254 XDataPilotDescriptor DPDsc = DPT.createDataPilotDescriptor();
255 DPDsc.setSourceRange(sCellRangeAdress);
257 XPropertySet fieldPropSet = null;
258 try {
259 Object oDataPilotField = DPDsc.getDataPilotFields().getByIndex(0);
260 fieldPropSet = (XPropertySet)
261 UnoRuntime.queryInterface(XPropertySet.class, oDataPilotField);
262 } catch (com.sun.star.lang.WrappedTargetException e) {
263 e.printStackTrace();
264 throw new StatusException("Couldn't create a test environment", e);
265 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
266 e.printStackTrace();
267 throw new StatusException("Couldn't create a test environment", e);
270 try {
271 fieldPropSet.setPropertyValue("Function",
272 com.sun.star.sheet.GeneralFunction.SUM);
273 fieldPropSet.setPropertyValue("Orientation",
274 com.sun.star.sheet.DataPilotFieldOrientation.DATA);
275 } catch(com.sun.star.lang.WrappedTargetException e) {
276 e.printStackTrace();
277 throw new StatusException("Couldn't create a test environment", e);
278 } catch(com.sun.star.lang.IllegalArgumentException e) {
279 e.printStackTrace();
280 throw new StatusException("Couldn't create a test environment", e);
281 } catch(com.sun.star.beans.PropertyVetoException e) {
282 e.printStackTrace();
283 throw new StatusException("Couldn't create a test environment", e);
284 } catch(com.sun.star.beans.UnknownPropertyException e) {
285 e.printStackTrace();
286 throw new StatusException("Couldn't create a test environment", e);
289 log.println("Insert the DataPilotTable");
290 if (DPT.hasByName("DataPilotTable")) {
291 DPT.removeByName("DataPilotTable");
293 DPT.insertNewByName("DataPilotTable", sCellAdress, DPDsc);
294 try {
295 mDataPilotTableObject = (XInterface) AnyConverter.toObject(
296 new Type(XInterface.class),DPT.getByName(DPT.getElementNames()[0]));
297 } catch (com.sun.star.lang.WrappedTargetException e) {
298 e.printStackTrace();
299 throw new StatusException("Couldn't create a test environment", e);
300 } catch (com.sun.star.container.NoSuchElementException e) {
301 e.printStackTrace();
302 throw new StatusException("Couldn't create a test environment", e);
303 } catch (com.sun.star.lang.IllegalArgumentException e) {
304 e.printStackTrace();
305 throw new StatusException("Couldn't create a test environment", e);
308 XIndexAccess IA = DPDsc.getDataPilotFields();
309 try {
310 mDataPilotFieldObject = (XInterface)AnyConverter.toObject(
311 new Type(XInterface.class),IA.getByIndex(0));
312 } catch (com.sun.star.lang.WrappedTargetException e) {
313 e.printStackTrace();
314 throw new StatusException("Couldn't get data pilot field", e);
315 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
316 e.printStackTrace();
317 throw new StatusException("Couldn't get data pilot field", e);
318 } catch (com.sun.star.lang.IllegalArgumentException e) {
319 e.printStackTrace();
320 throw new StatusException("Couldn't get data pilot field", e);
323 // Other parameters required for interface tests
324 param.put("OUTPUTRANGE", sCellAdress);
325 param.put("CELLFORCHANGE", oChangeCell);
326 param.put("CELLFORCHECK", oCheckCell);
327 param.put("CHANGEVALUE", aChangeValue);
328 param.put("FIELDSAMOUNT", new Integer(5));