bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XDataPilotDescriptor.java
blob99d4856903cfe8e6637d2a0757050939bc3c1421
1 /*
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 .
19 package ifc.sheet;
21 import lib.MultiMethodTest;
22 import lib.Status;
23 import lib.StatusException;
25 import com.sun.star.beans.XPropertySet;
26 import com.sun.star.container.XIndexAccess;
27 import com.sun.star.container.XNamed;
28 import com.sun.star.sheet.DataPilotFieldOrientation;
29 import com.sun.star.sheet.XDataPilotDescriptor;
30 import com.sun.star.table.CellRangeAddress;
31 import com.sun.star.uno.UnoRuntime;
33 /**
34 * Testing <code>com.sun.star.sheet.XDataPilotDescriptor</code>
35 * interface methods :
36 * <ul>
37 * <li><code> getTag()</code></li>
38 * <li><code> setTag()</code></li>
39 * <li><code> getSourceRange()</code></li>
40 * <li><code> setSourceRange()</code></li>
41 * <li><code> getFilterDescriptor()</code></li>
42 * <li><code> getDataPilotFields()</code></li>
43 * <li><code> getColumnFields()</code></li>
44 * <li><code> getRowFields()</code></li>
45 * <li><code> getPageFields()</code></li>
46 * <li><code> getDataFields()</code></li>
47 * <li><code> getHiddenFields()</code></li>
48 * </ul> <p>
49 * This test needs the following object relations :
50 * <ul>
51 * <li> <code>'FIELDSAMOUNT'</code> (of type <code>Integer</code>):
52 * to have number of fields </li>
53 * <ul> <p>
54 * @see com.sun.star.sheet.XDataPilotDescriptor
56 public class _XDataPilotDescriptor extends MultiMethodTest {
58 public XDataPilotDescriptor oObj = null;
59 CellRangeAddress CRA = new CellRangeAddress((short)1, 1, 1, 5, 5);
60 CellRangeAddress oldCRA = null ;
61 String sTag = new String ("XDataPilotDescriptor_Tag");
62 String fieldsNames[];
63 int fieldsAmount = 0;
64 int tEnvFieldsAmount = 0;
66 /**
67 * Retrieves object relations.
68 * @throws StatusException If one of relations not found.
70 protected void before() {
71 Integer amount = (Integer)tEnv.getObjRelation("FIELDSAMOUNT");
72 if (amount == null) throw new StatusException(Status.failed
73 ("Relation 'FIELDSAMOUNT' not found"));
74 tEnvFieldsAmount = amount.intValue();
77 /**
78 * Test calls the method and compares returned value with value that was set
79 * in method <code>setSourceRange()</code>. <p>
80 * Has <b> OK </b> status if all fields of cell range addresses are equal. <p>
81 * The following method tests are to be completed successfully before :
82 * <ul>
83 * <li> <code> setSourceRange() </code> : to have current source range </li>
84 * </ul>
86 public void _getSourceRange(){
87 requiredMethod("setSourceRange()");
88 boolean bResult = true;
90 CellRangeAddress objRA = oObj.getSourceRange();
91 bResult &= objRA.Sheet == CRA.Sheet;
92 bResult &= objRA.StartRow == CRA.StartRow;
93 bResult &= objRA.StartColumn == CRA.StartColumn;
94 bResult &= objRA.EndRow == CRA.EndRow;
95 bResult &= objRA.EndColumn == CRA.EndColumn;
97 tRes.tested("getSourceRange()", bResult);
101 * Test gets the current source range, stores it and sets new source range.<p>
102 * Has <b> OK </b> status if the method successfully returns. <p>
103 * The following method tests are to be executed before :
104 * <ul>
105 * <li> <code> getColumnFields() </code> </li>
106 * <li> <code> getRowFields() </code> </li>
107 * <li> <code> getDataFields() </code> </li>
108 * <li> <code> getHiddenFields() </code> </li>
109 * <li> <code> getPageFields() </code> </li>
110 * </ul>
112 public void _setSourceRange(){
113 executeMethod("getColumnFields()") ;
114 executeMethod("getRowFields()") ;
115 executeMethod("getDataFields()") ;
116 executeMethod("getHiddenFields()") ;
117 executeMethod("getPageFields()") ;
119 oldCRA = oObj.getSourceRange() ;
120 oObj.setSourceRange(CRA);
122 tRes.tested("setSourceRange()", true);
126 * Test calls the method and checks returned value with value that was set
127 * by method <code>setTag()</code>. <p>
128 * Has <b> OK </b> status if returned value is equal to value that was set
129 * by method <code>setTag()</code>. <p>
130 * The following method tests are to be completed successfully before :
131 * <ul>
132 * <li> <code> setTag() </code> : to have current tag </li>
133 * </ul>
135 public void _getTag(){
136 requiredMethod("setTag()");
137 boolean bResult = true;
139 String objTag = oObj.getTag();
140 bResult &= objTag.equals(sTag);
142 tRes.tested("getTag()", bResult);
146 * Test just calls the method. <p>
147 * Has <b> OK </b> status if the method successfully returns. <p>
149 public void _setTag(){
150 oObj.setTag(sTag);
151 tRes.tested("setTag()", true);
155 * Test calls the method , checks returned value, compares
156 * number of fields goten from returned value and obtained by object
157 * relation <code>'FIELDSAMOUNT'</code> and set property
158 * <code>Orientation</code> to one of DataPilotFieldOrientation values. <p>
159 * Has <b> OK </b> status if returned value isn't null, number of fields
160 * goten from returned value is less than number of fields obtained by relation
161 * and no exceptions were thrown. <p>
163 public void _getDataPilotFields(){
164 boolean bResult = true;
165 XIndexAccess IA = null;
167 IA = oObj.getDataPilotFields();
168 if (IA == null) {
169 log.println("Returned value is null.");
170 tRes.tested("getDataPilotFields()", false);
171 return;
172 } else {log.println("getDataPilotFields returned not Null value -- OK");}
174 fieldsAmount = IA.getCount();
175 if (fieldsAmount < tEnvFieldsAmount) {
176 log.println("Number of fields is less than number goten by relation.");
177 tRes.tested("getDataPilotFields()", false);
178 return;
179 } else {log.println("count of returned fields -- OK");}
181 fieldsNames = new String[tEnvFieldsAmount];
182 int i = -1 ;
183 int cnt = 0 ;
184 while (++i < fieldsAmount) {
185 Object field;
186 try {
187 field = IA.getByIndex(i);
188 } catch(com.sun.star.lang.WrappedTargetException e) {
189 e.printStackTrace(log);
190 tRes.tested("getDataPilotFields()", false);
191 return;
192 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
193 e.printStackTrace(log);
194 tRes.tested("getDataPilotFields()", false);
195 return;
198 XNamed named = UnoRuntime.queryInterface(XNamed.class, field);
199 String name = named.getName();
201 log.print("Field : '" + name + "' ... ") ;
203 if (!name.equals("Data")) {
205 fieldsNames[cnt] = name ;
207 XPropertySet props = UnoRuntime.queryInterface(XPropertySet.class, field);
209 try {
210 switch (cnt % 5) {
211 case 0 :
212 props.setPropertyValue("Orientation",
213 DataPilotFieldOrientation.COLUMN);
214 log.println(" Column") ;
215 break;
216 case 1 :
217 props.setPropertyValue("Orientation",
218 DataPilotFieldOrientation.ROW);
219 log.println(" Row") ;
220 break;
221 case 2 :
222 props.setPropertyValue("Orientation",
223 DataPilotFieldOrientation.DATA);
224 log.println(" Data") ;
225 break;
226 case 3 :
227 props.setPropertyValue("Orientation",
228 DataPilotFieldOrientation.HIDDEN);
229 log.println(" Hidden") ;
230 break;
231 case 4 :
232 props.setPropertyValue("Orientation",
233 DataPilotFieldOrientation.PAGE);
234 log.println(" Page") ;
235 break;
236 } } catch (com.sun.star.lang.WrappedTargetException e) {
237 e.printStackTrace(log);
238 tRes.tested("getDataPilotFields()", false);
239 return;
240 } catch (com.sun.star.lang.IllegalArgumentException e) {
241 e.printStackTrace(log);
242 tRes.tested("getDataPilotFields()", false);
243 return;
244 } catch (com.sun.star.beans.PropertyVetoException e) {
245 e.printStackTrace(log);
246 tRes.tested("getDataPilotFields()", false);
247 return;
248 } catch (com.sun.star.beans.UnknownPropertyException e) {
249 e.printStackTrace(log);
250 tRes.tested("getDataPilotFields()", false);
251 return;
253 if (++cnt > 4) break;
254 } else {
255 tRes.tested("getDataPilotFields()", false);
256 return;
260 tRes.tested("getDataPilotFields()", bResult);
264 * Test calls the method and checks returned collection using the method
265 * <code>CheckNames()</code>. <p>
266 * Has <b> OK </b> status if the method <code>CheckNames()</code> returns true
267 * and no exceptions were thrown. <p>
268 * The following method tests are to be completed successfully before :
269 * <ul>
270 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
271 * </ul>
273 public void _getColumnFields(){
274 requiredMethod("getDataPilotFields()");
275 XIndexAccess IA = oObj.getColumnFields();
276 boolean bResult = CheckNames(IA, 0);
277 tRes.tested("getColumnFields()", bResult);
281 * Test calls the method and checks returned collection using the method
282 * <code>CheckNames()</code>. <p>
283 * Has <b> OK </b> status if the method <code>CheckNames()</code> returned true
284 * and no exceptions were thrown. <p>
285 * The following method tests are to be completed successfully before :
286 * <ul>
287 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
288 * </ul>
290 public void _getDataFields(){
291 requiredMethod("getDataPilotFields()");
292 XIndexAccess IA = oObj.getDataFields();
293 boolean bResult = CheckNames(IA, 2);
294 tRes.tested("getDataFields()", bResult);
298 * Test calls the method and checks returned collection using the method
299 * <code>CheckNames()</code>. <p>
300 * Has <b> OK </b> status if the method <code>CheckNames()</code> returned true
301 * and no exceptions were thrown. <p>
302 * The following method tests are to be completed successfully before :
303 * <ul>
304 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
305 * </ul>
307 public void _getHiddenFields(){
308 requiredMethod("getDataPilotFields()");
309 XIndexAccess IA = oObj.getHiddenFields();
310 boolean bResult = CheckNames(IA, 3);
311 tRes.tested("getHiddenFields()", bResult);
315 * Test calls the method and checks returned collection using the method
316 * <code>CheckNames()</code>. <p>
317 * Has <b> OK </b> status if the method <code>CheckNames()</code> returned true
318 * and no exceptions were thrown. <p>
319 * The following method tests are to be completed successfully before :
320 * <ul>
321 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
322 * </ul>
324 public void _getRowFields(){
325 requiredMethod("getDataPilotFields()");
326 XIndexAccess IA = oObj.getRowFields();
327 boolean bResult = CheckNames(IA, 1);
328 tRes.tested("getRowFields()", bResult);
332 * setting of PageFields isn't supported by StarOffice Calc
333 * Has <b> OK </b> status if the returned IndexAccess
334 * isn't NULL. <p>
335 * The following method tests are to be completed successfully before :
336 * <ul>
337 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
338 * </ul>
340 public void _getPageFields(){
341 requiredMethod("getDataPilotFields()");
342 XIndexAccess IA = oObj.getPageFields();
343 boolean bResult = (IA != null);
344 // boolean bResult = CheckNames(IA, 4);
345 tRes.tested("getPageFields()", bResult);
349 * Test calls the method and checks returned value. <p>
350 * Has <b> OK </b> status if returned value isn't null
351 * and no exceptions were thrown. <p>
353 public void _getFilterDescriptor(){
354 boolean bResult = oObj.getFilterDescriptor() != null;
355 tRes.tested("getFilterDescriptor()", bResult);
359 * Method checks that the field with index <code>rem</code> exists
360 * in the array <code>IA</code>.
361 * @param IA collection of elements that support interface <code>XNamed</code>
362 * @param rem index of field in the array of field names that was stored in
363 * the method <code>getDataPilotFields()</code>
364 * @return true if required field name exists in passed collection;
365 * false otherwise
366 * @see com.sun.star.container.XNamed
368 boolean CheckNames(XIndexAccess IA, int rem) {
369 String name = null;
371 if (IA == null) {
372 log.println("Null retruned.") ;
373 return false ;
376 if (fieldsNames[rem] == null) {
377 log.println("No fields were set to this orientation - cann't check result") ;
378 return true ;
381 if (IA.getCount() == 0) {
382 log.println("No fields found. Must be at least '"
383 + fieldsNames[rem] + "'") ;
384 return false ;
387 try {
388 log.print("Fields returned ") ;
389 for (int i = 0; i < IA.getCount(); i++) {
390 Object field = IA.getByIndex(i);
391 XNamed named = UnoRuntime.queryInterface
392 (XNamed.class, field);
393 name = named.getName();
394 log.print(" " + name) ;
395 if (fieldsNames[rem].equals(name)) {
396 log.println(" - OK") ;
397 return true ;
400 } catch (com.sun.star.lang.WrappedTargetException e) {
401 e.printStackTrace(log) ;
402 return false ;
403 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
404 e.printStackTrace(log) ;
405 return false ;
407 log.println(" - FAILED (field " + fieldsNames[rem] + " was not found.") ;
408 return false ;
412 * Recreates object(to back old orientations of the fields).
414 protected void after() {
415 disposeEnvironment();