Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XDataPilotDescriptor.java
blobc0265af60709f1f4e67d910d2e34811d67dce702
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 = "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 @Override
71 protected void before() {
72 Integer amount = (Integer)tEnv.getObjRelation("FIELDSAMOUNT");
73 if (amount == null) throw new StatusException(Status.failed
74 ("Relation 'FIELDSAMOUNT' not found"));
75 tEnvFieldsAmount = amount.intValue();
78 /**
79 * Test calls the method and compares returned value with value that was set
80 * in method <code>setSourceRange()</code>. <p>
81 * Has <b> OK </b> status if all fields of cell range addresses are equal. <p>
82 * The following method tests are to be completed successfully before :
83 * <ul>
84 * <li> <code> setSourceRange() </code> : to have current source range </li>
85 * </ul>
87 public void _getSourceRange(){
88 requiredMethod("setSourceRange()");
89 boolean bResult = true;
91 CellRangeAddress objRA = oObj.getSourceRange();
92 bResult &= objRA.Sheet == CRA.Sheet;
93 bResult &= objRA.StartRow == CRA.StartRow;
94 bResult &= objRA.StartColumn == CRA.StartColumn;
95 bResult &= objRA.EndRow == CRA.EndRow;
96 bResult &= objRA.EndColumn == CRA.EndColumn;
98 tRes.tested("getSourceRange()", bResult);
102 * Test gets the current source range, stores it and sets new source range.<p>
103 * Has <b> OK </b> status if the method successfully returns. <p>
104 * The following method tests are to be executed before :
105 * <ul>
106 * <li> <code> getColumnFields() </code> </li>
107 * <li> <code> getRowFields() </code> </li>
108 * <li> <code> getDataFields() </code> </li>
109 * <li> <code> getHiddenFields() </code> </li>
110 * <li> <code> getPageFields() </code> </li>
111 * </ul>
113 public void _setSourceRange(){
114 executeMethod("getColumnFields()") ;
115 executeMethod("getRowFields()") ;
116 executeMethod("getDataFields()") ;
117 executeMethod("getHiddenFields()") ;
118 executeMethod("getPageFields()") ;
120 oldCRA = oObj.getSourceRange() ;
121 oObj.setSourceRange(CRA);
123 tRes.tested("setSourceRange()", true);
127 * Test calls the method and checks returned value with value that was set
128 * by method <code>setTag()</code>. <p>
129 * Has <b> OK </b> status if returned value is equal to value that was set
130 * by method <code>setTag()</code>. <p>
131 * The following method tests are to be completed successfully before :
132 * <ul>
133 * <li> <code> setTag() </code> : to have current tag </li>
134 * </ul>
136 public void _getTag(){
137 requiredMethod("setTag()");
138 boolean bResult = true;
140 String objTag = oObj.getTag();
141 bResult &= objTag.equals(sTag);
143 tRes.tested("getTag()", bResult);
147 * Test just calls the method. <p>
148 * Has <b> OK </b> status if the method successfully returns. <p>
150 public void _setTag(){
151 oObj.setTag(sTag);
152 tRes.tested("setTag()", true);
156 * Test calls the method , checks returned value, compares
157 * number of fields goten from returned value and obtained by object
158 * relation <code>'FIELDSAMOUNT'</code> and set property
159 * <code>Orientation</code> to one of DataPilotFieldOrientation values. <p>
160 * Has <b> OK </b> status if returned value isn't null, number of fields
161 * goten from returned value is less than number of fields obtained by relation
162 * and no exceptions were thrown. <p>
164 public void _getDataPilotFields(){
165 boolean bResult = true;
166 XIndexAccess IA = null;
168 IA = oObj.getDataPilotFields();
169 if (IA == null) {
170 log.println("Returned value is null.");
171 tRes.tested("getDataPilotFields()", false);
172 return;
173 } else {log.println("getDataPilotFields returned not Null value -- OK");}
175 fieldsAmount = IA.getCount();
176 if (fieldsAmount < tEnvFieldsAmount) {
177 log.println("Number of fields is less than number goten by relation.");
178 tRes.tested("getDataPilotFields()", false);
179 return;
180 } else {log.println("count of returned fields -- OK");}
182 fieldsNames = new String[tEnvFieldsAmount];
183 int i = -1 ;
184 int cnt = 0 ;
185 while (++i < fieldsAmount) {
186 Object field;
187 try {
188 field = IA.getByIndex(i);
189 } catch(com.sun.star.lang.WrappedTargetException e) {
190 e.printStackTrace(log);
191 tRes.tested("getDataPilotFields()", false);
192 return;
193 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
194 e.printStackTrace(log);
195 tRes.tested("getDataPilotFields()", false);
196 return;
199 XNamed named = UnoRuntime.queryInterface(XNamed.class, field);
200 String name = named.getName();
202 log.print("Field : '" + name + "' ... ") ;
204 if (!name.equals("Data")) {
206 fieldsNames[cnt] = name ;
208 XPropertySet props = UnoRuntime.queryInterface(XPropertySet.class, field);
210 try {
211 switch (cnt % 5) {
212 case 0 :
213 props.setPropertyValue("Orientation",
214 DataPilotFieldOrientation.COLUMN);
215 log.println(" Column") ;
216 break;
217 case 1 :
218 props.setPropertyValue("Orientation",
219 DataPilotFieldOrientation.ROW);
220 log.println(" Row") ;
221 break;
222 case 2 :
223 props.setPropertyValue("Orientation",
224 DataPilotFieldOrientation.DATA);
225 log.println(" Data") ;
226 break;
227 case 3 :
228 props.setPropertyValue("Orientation",
229 DataPilotFieldOrientation.HIDDEN);
230 log.println(" Hidden") ;
231 break;
232 case 4 :
233 props.setPropertyValue("Orientation",
234 DataPilotFieldOrientation.PAGE);
235 log.println(" Page") ;
236 break;
237 } } catch (com.sun.star.lang.WrappedTargetException e) {
238 e.printStackTrace(log);
239 tRes.tested("getDataPilotFields()", false);
240 return;
241 } catch (com.sun.star.lang.IllegalArgumentException e) {
242 e.printStackTrace(log);
243 tRes.tested("getDataPilotFields()", false);
244 return;
245 } catch (com.sun.star.beans.PropertyVetoException e) {
246 e.printStackTrace(log);
247 tRes.tested("getDataPilotFields()", false);
248 return;
249 } catch (com.sun.star.beans.UnknownPropertyException e) {
250 e.printStackTrace(log);
251 tRes.tested("getDataPilotFields()", false);
252 return;
254 if (++cnt > 4) break;
255 } else {
256 tRes.tested("getDataPilotFields()", false);
257 return;
261 tRes.tested("getDataPilotFields()", bResult);
265 * Test calls the method and checks returned collection using the method
266 * <code>CheckNames()</code>. <p>
267 * Has <b> OK </b> status if the method <code>CheckNames()</code> returns true
268 * and no exceptions were thrown. <p>
269 * The following method tests are to be completed successfully before :
270 * <ul>
271 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
272 * </ul>
274 public void _getColumnFields(){
275 requiredMethod("getDataPilotFields()");
276 XIndexAccess IA = oObj.getColumnFields();
277 boolean bResult = CheckNames(IA, 0);
278 tRes.tested("getColumnFields()", bResult);
282 * Test calls the method and checks returned collection using the method
283 * <code>CheckNames()</code>. <p>
284 * Has <b> OK </b> status if the method <code>CheckNames()</code> returned true
285 * and no exceptions were thrown. <p>
286 * The following method tests are to be completed successfully before :
287 * <ul>
288 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
289 * </ul>
291 public void _getDataFields(){
292 requiredMethod("getDataPilotFields()");
293 XIndexAccess IA = oObj.getDataFields();
294 boolean bResult = CheckNames(IA, 2);
295 tRes.tested("getDataFields()", bResult);
299 * Test calls the method and checks returned collection using the method
300 * <code>CheckNames()</code>. <p>
301 * Has <b> OK </b> status if the method <code>CheckNames()</code> returned true
302 * and no exceptions were thrown. <p>
303 * The following method tests are to be completed successfully before :
304 * <ul>
305 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
306 * </ul>
308 public void _getHiddenFields(){
309 requiredMethod("getDataPilotFields()");
310 XIndexAccess IA = oObj.getHiddenFields();
311 boolean bResult = CheckNames(IA, 3);
312 tRes.tested("getHiddenFields()", bResult);
316 * Test calls the method and checks returned collection using the method
317 * <code>CheckNames()</code>. <p>
318 * Has <b> OK </b> status if the method <code>CheckNames()</code> returned true
319 * and no exceptions were thrown. <p>
320 * The following method tests are to be completed successfully before :
321 * <ul>
322 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
323 * </ul>
325 public void _getRowFields(){
326 requiredMethod("getDataPilotFields()");
327 XIndexAccess IA = oObj.getRowFields();
328 boolean bResult = CheckNames(IA, 1);
329 tRes.tested("getRowFields()", bResult);
333 * setting of PageFields isn't supported by StarOffice Calc
334 * Has <b> OK </b> status if the returned IndexAccess
335 * isn't NULL. <p>
336 * The following method tests are to be completed successfully before :
337 * <ul>
338 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
339 * </ul>
341 public void _getPageFields(){
342 requiredMethod("getDataPilotFields()");
343 XIndexAccess IA = oObj.getPageFields();
344 boolean bResult = (IA != null);
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 @Override
415 protected void after() {
416 disposeEnvironment();