merged tag ooo/OOO330_m14
[LibreOffice.git] / sc / qa / complex / dataPilot / CheckDataPilot.java
blobd013daa24e1fc0a9179782aaa9b36a403ec1a70f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package complex.dataPilot;
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.container.XIndexAccess;
32 import com.sun.star.container.XNamed;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.sheet.TableFilterField;
35 import com.sun.star.sheet.XDataPilotDescriptor;
36 import com.sun.star.sheet.XDataPilotTable;
37 import com.sun.star.sheet.XDataPilotTables;
38 import com.sun.star.sheet.XDataPilotTablesSupplier;
39 import com.sun.star.sheet.XSheetFilterDescriptor;
40 import com.sun.star.sheet.XSpreadsheet;
41 import com.sun.star.sheet.XSpreadsheetDocument;
42 import com.sun.star.sheet.XSpreadsheets;
43 import com.sun.star.table.CellAddress;
44 import com.sun.star.table.CellRangeAddress;
45 import com.sun.star.uno.AnyConverter;
46 import com.sun.star.uno.Type;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
49 import complex.dataPilot.interfaceTests.beans._XPropertySet;
50 import complex.dataPilot.interfaceTests.container._XNamed;
51 import complex.dataPilot.interfaceTests.sheet._XDataPilotDescriptor;
52 import complex.dataPilot.interfaceTests.sheet._XDataPilotTable;
53 import complexlib.ComplexTestCase;
54 import lib.StatusException;
55 import util.SOfficeFactory;
57 /**
58 * check the DataPilot of Calc.
60 public class CheckDataPilot extends ComplexTestCase {
61 /** The data pilot field object **/
62 private XInterface mDataPilotFieldObject = null;
63 /** The data pilot table object **/
64 private XInterface mDataPilotTableObject = null;
66 /**
67 * A field is filled some values. This integer determines the size of the
68 * field in x and y direction.
70 private int mMaxFieldIndex = 6;
73 /**
74 * Get all test methods
75 * @return The test methods
77 public String[] getTestMethodNames() {
78 return new String[]{"testDataPilotTableObject",
79 "testDataPilotFieldObject"};
82 /**
83 * Test the data pilot field object:
84 * simply execute the interface tests in a row
86 public void testDataPilotFieldObject() {
87 log.println("Starting 'testDataPilotFieldObject'");
88 // _XNamed
89 XNamed xNamed = (XNamed)UnoRuntime.queryInterface(
90 XNamed.class, mDataPilotFieldObject);
92 _XNamed _xNamed = new _XNamed(xNamed, log, param);
93 assure("_getName failed.",_xNamed._getName());
94 assure("_setName failed.",_xNamed._setName());
96 // _XPropertySet
97 XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(
98 XPropertySet.class, mDataPilotFieldObject);
99 _XPropertySet _xProp = new _XPropertySet(xProp, log, param);
100 assure("_getPropertySetInfo failed.",_xProp._getPropertySetInfo());
101 assure("_addPropertyChangeListener failed.",_xProp._addPropertyChangeListener());
102 assure("_addVetoableChangeListener failed.",_xProp._addVetoableChangeListener());
103 assure("_setPropertyValue failed.",_xProp._setPropertyValue());
104 assure("_getPropertyValue failed.",_xProp._getPropertyValue());
105 assure("_removePropertyChangeListener failed.",_xProp._removePropertyChangeListener());
106 assure("_removeVetoableChangeListener failed.",_xProp._removeVetoableChangeListener());
111 * Test the data pilot table object:
112 * simply execute the interface tests in a row
114 public void testDataPilotTableObject() {
115 log.println("Starting 'testDataPilotTableObject'");
116 // _XNamed
117 XNamed xNamed = (XNamed)UnoRuntime.queryInterface(
118 XNamed.class, mDataPilotTableObject);
119 _XNamed _xNamed = new _XNamed(xNamed, log, param);
120 assure("_getName failed.",_xNamed._getName());
121 assure("_setName failed.",_xNamed._setName());
123 // _XDataPilotTable
124 XDataPilotTable xDataPilotTable = (XDataPilotTable)
125 UnoRuntime.queryInterface(XDataPilotTable.class,
126 mDataPilotTableObject);
127 _XDataPilotTable _xDataPilotTable =
128 new _XDataPilotTable(xDataPilotTable, log, param);
129 assure("before failed.", _xDataPilotTable.before());
130 assure("_getOutputRange failed.", _xDataPilotTable._getOutputRange()) ;
131 assure("_refresh failed.", _xDataPilotTable._refresh()) ;
133 // _XDataPilotDescriptor
134 XDataPilotDescriptor xDataPilotDescriptor = (XDataPilotDescriptor)
135 UnoRuntime.queryInterface(XDataPilotDescriptor.class,
136 mDataPilotTableObject);
137 _XDataPilotDescriptor _xDataPilotDescriptor =
138 new _XDataPilotDescriptor(xDataPilotDescriptor, log, param);
139 assure("before failed.", _xDataPilotDescriptor.before());
140 assure("_setTag failed.", _xDataPilotDescriptor._setTag()) ;
141 assure("_getTag failed.", _xDataPilotDescriptor._getTag()) ;
142 assure("_getFilterDescriptor failed.", _xDataPilotDescriptor._getFilterDescriptor()) ;
143 assure("_getDataPilotFields failed.", _xDataPilotDescriptor._getDataPilotFields()) ;
144 assure("_getColumnFields failed.", _xDataPilotDescriptor._getColumnFields()) ;
145 assure("_getRowFields failed.", _xDataPilotDescriptor._getRowFields()) ;
146 assure("_getDataFields failed.", _xDataPilotDescriptor._getDataFields()) ;
147 assure("_getHiddenFields failed.", _xDataPilotDescriptor._getHiddenFields()) ;
148 assure("_getPageFields failed.", _xDataPilotDescriptor._getPageFields()) ;
149 assure("_setSourceRange failed.", _xDataPilotDescriptor._setSourceRange()) ;
150 assure("_getSourceRange failed.", _xDataPilotDescriptor._getSourceRange()) ;
154 * create an environment for the test
156 public void before() {
157 Object oInterface = null;
158 XSpreadsheetDocument xSheetDoc = null;
160 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)param.getMSF() );
162 // the cell range
163 CellRangeAddress sCellRangeAdress = new CellRangeAddress();
164 sCellRangeAdress.Sheet = 0;
165 sCellRangeAdress.StartColumn = 1;
166 sCellRangeAdress.StartRow = 0;
167 sCellRangeAdress.EndColumn = mMaxFieldIndex-1;
168 sCellRangeAdress.EndRow = mMaxFieldIndex - 1;
170 // position of the data pilot table
171 CellAddress sCellAdress = new CellAddress();
172 sCellAdress.Sheet = 0;
173 sCellAdress.Column = 7;
174 sCellAdress.Row = 8;
176 try {
177 log.println( "Creating a Spreadsheet document" );
178 xSheetDoc = SOF.createCalcDoc(null);
179 } catch (com.sun.star.uno.Exception e) {
180 // Some exception occures.FAILED
181 e.printStackTrace();
182 throw new StatusException( "Couldn't create document", e );
185 log.println("Getting a sheet");
186 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSheetDoc.getSheets();
187 XSpreadsheet oSheet = null;
188 XSpreadsheet oSheet2 = null;
189 XIndexAccess oIndexAccess = (XIndexAccess)
190 UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
192 try {
193 oSheet = (XSpreadsheet) AnyConverter.toObject(
194 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
195 oSheet2 = (XSpreadsheet) AnyConverter.toObject(
196 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(1));
197 } catch (com.sun.star.lang.WrappedTargetException e) {
198 e.printStackTrace();
199 throw new StatusException( "Couldn't get a spreadsheet", e);
200 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
201 e.printStackTrace();
202 throw new StatusException( "Couldn't get a spreadsheet", e);
203 } catch (com.sun.star.lang.IllegalArgumentException e) {
204 e.printStackTrace();
205 throw new StatusException( "Couldn't get a spreadsheet", e);
208 try {
209 log.println("Filling a table");
210 for (int i = 1; i < mMaxFieldIndex; i++) {
211 oSheet.getCellByPosition(i, 0).setFormula("Col" + i);
212 oSheet.getCellByPosition(0, i).setFormula("Row" + i);
213 oSheet2.getCellByPosition(i, 0).setFormula("Col" + i);
214 oSheet2.getCellByPosition(0, i).setFormula("Row" + i);
217 for (int i = 1; i < mMaxFieldIndex; i++)
218 for (int j = 1; j < mMaxFieldIndex; j++) {
219 oSheet.getCellByPosition(i, j).setValue(i * (j + 1));
220 oSheet2.getCellByPosition(i, j).setValue(i * (j + 2));
222 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
223 e.printStackTrace();
224 throw new StatusException("Couldn't fill some cells", e);
227 // change a value of a cell and check the change in the data pilot
228 // (for the XDataPilotTable.refresh() test)
229 Object oChangeCell = null;
230 Object oCheckCell = null;
231 Integer aChangeValue = null;
232 try {
233 // cell of data
234 oChangeCell = oSheet.getCellByPosition(1, 5);
235 int x = sCellAdress.Column;
236 int y = sCellAdress.Row + 3;
237 // cell of the data pilot output
238 oCheckCell = oSheet.getCellByPosition(x, y);
239 aChangeValue = new Integer(27);
240 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
241 e.printStackTrace();
242 throw new StatusException( "Couldn't get cells for changeing.", e);
246 // create the test objects
247 log.println("Getting test objects") ;
248 XDataPilotTablesSupplier DPTS = (XDataPilotTablesSupplier)
249 UnoRuntime.queryInterface(XDataPilotTablesSupplier.class, oSheet);
250 XDataPilotTables DPT = DPTS.getDataPilotTables();
251 XDataPilotDescriptor DPDsc = DPT.createDataPilotDescriptor();
252 DPDsc.setSourceRange(sCellRangeAdress);
254 XPropertySet fieldPropSet = null;
255 try {
256 Object oDataPilotField = DPDsc.getDataPilotFields().getByIndex(0);
257 fieldPropSet = (XPropertySet)
258 UnoRuntime.queryInterface(XPropertySet.class, oDataPilotField);
259 } catch (com.sun.star.lang.WrappedTargetException e) {
260 e.printStackTrace();
261 throw new StatusException("Couldn't create a test environment", e);
262 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
263 e.printStackTrace();
264 throw new StatusException("Couldn't create a test environment", e);
267 try {
268 fieldPropSet.setPropertyValue("Function",
269 com.sun.star.sheet.GeneralFunction.SUM);
270 fieldPropSet.setPropertyValue("Orientation",
271 com.sun.star.sheet.DataPilotFieldOrientation.DATA);
272 } catch(com.sun.star.lang.WrappedTargetException e) {
273 e.printStackTrace();
274 throw new StatusException("Couldn't create a test environment", e);
275 } catch(com.sun.star.lang.IllegalArgumentException e) {
276 e.printStackTrace();
277 throw new StatusException("Couldn't create a test environment", e);
278 } catch(com.sun.star.beans.PropertyVetoException e) {
279 e.printStackTrace();
280 throw new StatusException("Couldn't create a test environment", e);
281 } catch(com.sun.star.beans.UnknownPropertyException e) {
282 e.printStackTrace();
283 throw new StatusException("Couldn't create a test environment", e);
286 log.println("Insert the DataPilotTable");
287 if (DPT.hasByName("DataPilotTable")) {
288 DPT.removeByName("DataPilotTable");
290 DPT.insertNewByName("DataPilotTable", sCellAdress, DPDsc);
291 try {
292 mDataPilotTableObject = (XInterface) AnyConverter.toObject(
293 new Type(XInterface.class),DPT.getByName(DPT.getElementNames()[0]));
294 } catch (com.sun.star.lang.WrappedTargetException e) {
295 e.printStackTrace();
296 throw new StatusException("Couldn't create a test environment", e);
297 } catch (com.sun.star.container.NoSuchElementException e) {
298 e.printStackTrace();
299 throw new StatusException("Couldn't create a test environment", e);
300 } catch (com.sun.star.lang.IllegalArgumentException e) {
301 e.printStackTrace();
302 throw new StatusException("Couldn't create a test environment", e);
305 XIndexAccess IA = DPDsc.getDataPilotFields();
306 try {
307 mDataPilotFieldObject = (XInterface)AnyConverter.toObject(
308 new Type(XInterface.class),IA.getByIndex(0));
309 } catch (com.sun.star.lang.WrappedTargetException e) {
310 e.printStackTrace();
311 throw new StatusException("Couldn't get data pilot field", e);
312 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
313 e.printStackTrace();
314 throw new StatusException("Couldn't get data pilot field", e);
315 } catch (com.sun.star.lang.IllegalArgumentException e) {
316 e.printStackTrace();
317 throw new StatusException("Couldn't get data pilot field", e);
320 // Other parameters required for interface tests
321 param.put("OUTPUTRANGE", sCellAdress);
322 param.put("CELLFORCHANGE", oChangeCell);
323 param.put("CELLFORCHECK", oCheckCell);
324 param.put("CHANGEVALUE", aChangeValue);
325 param.put("FIELDSAMOUNT", new Integer(5));