merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / sheet / _XDataPilotDescriptor.java
blob5d2b3298baabee4b96edcb88c1bc4c1458bb9c8b
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: _XDataPilotDescriptor.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 ifc.sheet;
33 import lib.MultiMethodTest;
34 import lib.Status;
35 import lib.StatusException;
37 import com.sun.star.beans.XPropertySet;
38 import com.sun.star.container.XIndexAccess;
39 import com.sun.star.container.XNamed;
40 import com.sun.star.sheet.DataPilotFieldOrientation;
41 import com.sun.star.sheet.XDataPilotDescriptor;
42 import com.sun.star.table.CellRangeAddress;
43 import com.sun.star.uno.UnoRuntime;
45 /**
46 * Testing <code>com.sun.star.sheet.XDataPilotDescriptor</code>
47 * interface methods :
48 * <ul>
49 * <li><code> getTag()</code></li>
50 * <li><code> setTag()</code></li>
51 * <li><code> getSourceRange()</code></li>
52 * <li><code> setSourceRange()</code></li>
53 * <li><code> getFilterDescriptor()</code></li>
54 * <li><code> getDataPilotFields()</code></li>
55 * <li><code> getColumnFields()</code></li>
56 * <li><code> getRowFields()</code></li>
57 * <li><code> getPageFields()</code></li>
58 * <li><code> getDataFields()</code></li>
59 * <li><code> getHiddenFields()</code></li>
60 * </ul> <p>
61 * This test needs the following object relations :
62 * <ul>
63 * <li> <code>'FIELDSAMOUNT'</code> (of type <code>Integer</code>):
64 * to have number of fields </li>
65 * <ul> <p>
66 * @see com.sun.star.sheet.XDataPilotDescriptor
68 public class _XDataPilotDescriptor extends MultiMethodTest {
70 public XDataPilotDescriptor oObj = null;
71 CellRangeAddress CRA = new CellRangeAddress((short)1, 1, 1, 5, 5);
72 CellRangeAddress oldCRA = null ;
73 String sTag = new String ("XDataPilotDescriptor_Tag");
74 String fieldsNames[];
75 int fieldsAmount = 0;
76 int tEnvFieldsAmount = 0;
78 /**
79 * Retrieves object relations.
80 * @throws StatusException If one of relations not found.
82 protected void before() {
83 Integer amount = (Integer)tEnv.getObjRelation("FIELDSAMOUNT");
84 if (amount == null) throw new StatusException(Status.failed
85 ("Relation 'FIELDSAMOUNT' not found"));
86 tEnvFieldsAmount = amount.intValue();
89 /**
90 * Test calls the method and compares returned value with value that was set
91 * in method <code>setSourceRange()</code>. <p>
92 * Has <b> OK </b> status if all fields of cell range addresses are equal. <p>
93 * The following method tests are to be completed successfully before :
94 * <ul>
95 * <li> <code> setSourceRange() </code> : to have current source range </li>
96 * </ul>
98 public void _getSourceRange(){
99 requiredMethod("setSourceRange()");
100 boolean bResult = true;
102 CellRangeAddress objRA = oObj.getSourceRange();
103 bResult &= objRA.Sheet == CRA.Sheet;
104 bResult &= objRA.StartRow == CRA.StartRow;
105 bResult &= objRA.StartColumn == CRA.StartColumn;
106 bResult &= objRA.EndRow == CRA.EndRow;
107 bResult &= objRA.EndColumn == CRA.EndColumn;
109 tRes.tested("getSourceRange()", bResult);
113 * Test gets the current source range, stores it and sets new source range.<p>
114 * Has <b> OK </b> status if the method successfully returns. <p>
115 * The following method tests are to be executed before :
116 * <ul>
117 * <li> <code> getColumnFields() </code> </li>
118 * <li> <code> getRowFields() </code> </li>
119 * <li> <code> getDataFields() </code> </li>
120 * <li> <code> getHiddenFields() </code> </li>
121 * <li> <code> getPageFields() </code> </li>
122 * </ul>
124 public void _setSourceRange(){
125 executeMethod("getColumnFields()") ;
126 executeMethod("getRowFields()") ;
127 executeMethod("getDataFields()") ;
128 executeMethod("getHiddenFields()") ;
129 executeMethod("getPageFields()") ;
131 oldCRA = oObj.getSourceRange() ;
132 oObj.setSourceRange(CRA);
134 tRes.tested("setSourceRange()", true);
138 * Test calls the method and checks returned value with value that was set
139 * by method <code>setTag()</code>. <p>
140 * Has <b> OK </b> status if returned value is equal to value that was set
141 * by method <code>setTag()</code>. <p>
142 * The following method tests are to be completed successfully before :
143 * <ul>
144 * <li> <code> setTag() </code> : to have current tag </li>
145 * </ul>
147 public void _getTag(){
148 requiredMethod("setTag()");
149 boolean bResult = true;
151 String objTag = oObj.getTag();
152 bResult &= objTag.equals(sTag);
154 tRes.tested("getTag()", bResult);
158 * Test just calls the method. <p>
159 * Has <b> OK </b> status if the method successfully returns. <p>
161 public void _setTag(){
162 oObj.setTag(sTag);
163 tRes.tested("setTag()", true);
167 * Test calls the method , checks returned value, compares
168 * number of fields goten from returned value and obtained by object
169 * relation <code>'FIELDSAMOUNT'</code> and set property
170 * <code>Orientation</code> to one of DataPilotFieldOrientation values. <p>
171 * Has <b> OK </b> status if returned value isn't null, number of fields
172 * goten from returned value is less than number of fields obtained by relation
173 * and no exceptions were thrown. <p>
175 public void _getDataPilotFields(){
176 boolean bResult = true;
177 XIndexAccess IA = null;
179 IA = oObj.getDataPilotFields();
180 if (IA == null) {
181 log.println("Returned value is null.");
182 tRes.tested("getDataPilotFields()", false);
183 return;
184 } else {log.println("getDataPilotFields returned not Null value -- OK");}
186 fieldsAmount = IA.getCount();
187 if (fieldsAmount < tEnvFieldsAmount) {
188 log.println("Number of fields is less than number goten by relation.");
189 tRes.tested("getDataPilotFields()", false);
190 return;
191 } else {log.println("count of returned fields -- OK");}
193 fieldsNames = new String[tEnvFieldsAmount];
194 int i = -1 ;
195 int cnt = 0 ;
196 while (++i < fieldsAmount) {
197 Object field;
198 try {
199 field = IA.getByIndex(i);
200 } catch(com.sun.star.lang.WrappedTargetException e) {
201 e.printStackTrace(log);
202 tRes.tested("getDataPilotFields()", false);
203 return;
204 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
205 e.printStackTrace(log);
206 tRes.tested("getDataPilotFields()", false);
207 return;
210 XNamed named = (XNamed)
211 UnoRuntime.queryInterface(XNamed.class, field);
212 String name = named.getName();
214 log.print("Field : '" + name + "' ... ") ;
216 if (!name.equals("Data")) {
218 fieldsNames[cnt] = name ;
220 XPropertySet props = (XPropertySet)
221 UnoRuntime.queryInterface(XPropertySet.class, field);
223 try {
224 switch (cnt % 5) {
225 case 0 :
226 props.setPropertyValue("Orientation",
227 DataPilotFieldOrientation.COLUMN);
228 log.println(" Column") ;
229 break;
230 case 1 :
231 props.setPropertyValue("Orientation",
232 DataPilotFieldOrientation.ROW);
233 log.println(" Row") ;
234 break;
235 case 2 :
236 props.setPropertyValue("Orientation",
237 DataPilotFieldOrientation.DATA);
238 log.println(" Data") ;
239 break;
240 case 3 :
241 props.setPropertyValue("Orientation",
242 DataPilotFieldOrientation.HIDDEN);
243 log.println(" Hidden") ;
244 break;
245 case 4 :
246 props.setPropertyValue("Orientation",
247 DataPilotFieldOrientation.PAGE);
248 log.println(" Page") ;
249 break;
250 } } catch (com.sun.star.lang.WrappedTargetException e) {
251 e.printStackTrace(log);
252 tRes.tested("getDataPilotFields()", false);
253 return;
254 } catch (com.sun.star.lang.IllegalArgumentException e) {
255 e.printStackTrace(log);
256 tRes.tested("getDataPilotFields()", false);
257 return;
258 } catch (com.sun.star.beans.PropertyVetoException e) {
259 e.printStackTrace(log);
260 tRes.tested("getDataPilotFields()", false);
261 return;
262 } catch (com.sun.star.beans.UnknownPropertyException e) {
263 e.printStackTrace(log);
264 tRes.tested("getDataPilotFields()", false);
265 return;
267 if (++cnt > 4) break;
268 } else {
269 tRes.tested("getDataPilotFields()", false);
270 return;
274 tRes.tested("getDataPilotFields()", bResult);
278 * Test calls the method and checks returned collection using the method
279 * <code>CheckNames()</code>. <p>
280 * Has <b> OK </b> status if the method <code>CheckNames()</code> returns true
281 * and no exceptions were thrown. <p>
282 * The following method tests are to be completed successfully before :
283 * <ul>
284 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
285 * </ul>
287 public void _getColumnFields(){
288 requiredMethod("getDataPilotFields()");
289 XIndexAccess IA = oObj.getColumnFields();
290 boolean bResult = CheckNames(IA, 0);
291 tRes.tested("getColumnFields()", bResult);
295 * Test calls the method and checks returned collection using the method
296 * <code>CheckNames()</code>. <p>
297 * Has <b> OK </b> status if the method <code>CheckNames()</code> returned true
298 * and no exceptions were thrown. <p>
299 * The following method tests are to be completed successfully before :
300 * <ul>
301 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
302 * </ul>
304 public void _getDataFields(){
305 requiredMethod("getDataPilotFields()");
306 XIndexAccess IA = oObj.getDataFields();
307 boolean bResult = CheckNames(IA, 2);
308 tRes.tested("getDataFields()", bResult);
312 * Test calls the method and checks returned collection using the method
313 * <code>CheckNames()</code>. <p>
314 * Has <b> OK </b> status if the method <code>CheckNames()</code> returned true
315 * and no exceptions were thrown. <p>
316 * The following method tests are to be completed successfully before :
317 * <ul>
318 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
319 * </ul>
321 public void _getHiddenFields(){
322 requiredMethod("getDataPilotFields()");
323 XIndexAccess IA = oObj.getHiddenFields();
324 boolean bResult = CheckNames(IA, 3);
325 tRes.tested("getHiddenFields()", bResult);
329 * Test calls the method and checks returned collection using the method
330 * <code>CheckNames()</code>. <p>
331 * Has <b> OK </b> status if the method <code>CheckNames()</code> returned true
332 * and no exceptions were thrown. <p>
333 * The following method tests are to be completed successfully before :
334 * <ul>
335 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
336 * </ul>
338 public void _getRowFields(){
339 requiredMethod("getDataPilotFields()");
340 XIndexAccess IA = oObj.getRowFields();
341 boolean bResult = CheckNames(IA, 1);
342 tRes.tested("getRowFields()", bResult);
346 * setting of PageFields isn't supported by StarOffice Calc
347 * Has <b> OK </b> status if the returned IndexAccess
348 * isn't NULL. <p>
349 * The following method tests are to be completed successfully before :
350 * <ul>
351 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
352 * </ul>
354 public void _getPageFields(){
355 requiredMethod("getDataPilotFields()");
356 XIndexAccess IA = oObj.getPageFields();
357 boolean bResult = (IA != null);
358 // boolean bResult = CheckNames(IA, 4);
359 tRes.tested("getPageFields()", bResult);
363 * Test calls the method and checks returned value. <p>
364 * Has <b> OK </b> status if returned value isn't null
365 * and no exceptions were thrown. <p>
367 public void _getFilterDescriptor(){
368 boolean bResult = oObj.getFilterDescriptor() != null;
369 tRes.tested("getFilterDescriptor()", bResult);
373 * Method checks that the field with index <code>rem</code> exists
374 * in the array <code>IA</code>.
375 * @param IA collection of elements that support interface <code>XNamed</code>
376 * @param rem index of field in the array of field names that was stored in
377 * the method <code>getDataPilotFields()</code>
378 * @return true if required field name exists in passed collection;
379 * false otherwise
380 * @see com.sun.star.container.XNamed
382 boolean CheckNames(XIndexAccess IA, int rem) {
383 String name = null;
385 if (IA == null) {
386 log.println("Null retruned.") ;
387 return false ;
390 if (fieldsNames[rem] == null) {
391 log.println("No fields were set to this orientation - cann't check result") ;
392 return true ;
395 if (IA.getCount() == 0) {
396 log.println("No fields found. Must be at least '"
397 + fieldsNames[rem] + "'") ;
398 return false ;
401 try {
402 log.print("Fields returned ") ;
403 for (int i = 0; i < IA.getCount(); i++) {
404 Object field = IA.getByIndex(i);
405 XNamed named = (XNamed)UnoRuntime.queryInterface
406 (XNamed.class, field);
407 name = named.getName();
408 log.print(" " + name) ;
409 if (fieldsNames[rem].equals(name)) {
410 log.println(" - OK") ;
411 return true ;
414 } catch (com.sun.star.lang.WrappedTargetException e) {
415 e.printStackTrace(log) ;
416 return false ;
417 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
418 e.printStackTrace(log) ;
419 return false ;
421 log.println(" - FAILED (field " + fieldsNames[rem] + " was not found.") ;
422 return false ;
426 * Recreates object(to back old orientations of the fields).
428 protected void after() {
429 disposeEnvironment();