Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / sc / qa / complex / dataPilot / _XDataPilotDescriptor.java
blobb75267439e2953fd144eb4448ef40871a23a1ad2
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 complex.dataPilot;
21 import com.sun.star.beans.XPropertySet;
22 import com.sun.star.container.XIndexAccess;
23 import com.sun.star.container.XNamed;
24 import com.sun.star.sheet.DataPilotFieldOrientation;
25 import com.sun.star.sheet.XDataPilotDescriptor;
26 import com.sun.star.table.CellRangeAddress;
27 import com.sun.star.uno.UnoRuntime;
28 import lib.TestParameters;
30 /**
31 * Testing <code>com.sun.star.sheet.XDataPilotDescriptor</code>
32 * interface methods :
33 * <ul>
34 * <li><code> getTag()</code></li>
35 * <li><code> setTag()</code></li>
36 * <li><code> getSourceRange()</code></li>
37 * <li><code> setSourceRange()</code></li>
38 * <li><code> getFilterDescriptor()</code></li>
39 * <li><code> getDataPilotFields()</code></li>
40 * <li><code> getColumnFields()</code></li>
41 * <li><code> getRowFields()</code></li>
42 * <li><code> getPageFields()</code></li>
43 * <li><code> getDataFields()</code></li>
44 * <li><code> getHiddenFields()</code></li>
45 * </ul> <p>
46 * This test needs the following object relations :
47 * <ul>
48 * <li> <code>'FIELDSAMOUNT'</code> (of type <code>Integer</code>):
49 * to have number of fields </li>
50 * <ul> <p>
51 * @see com.sun.star.sheet.XDataPilotDescriptor
53 public class _XDataPilotDescriptor {
55 private final XDataPilotDescriptor oObj;
56 private final CellRangeAddress CRA = new CellRangeAddress((short)1, 0, 0, 5, 5);
58 private static final String sTag = "XDataPilotDescriptor_Tag";
59 private String fieldsNames[];
60 private int tEnvFieldsAmount = 0;
62 /**
63 * The test parameters
65 private final TestParameters param;
67 /**
68 * Constructor: gets the object to test, a logger and the test parameters
69 * @param xObj The test object
70 * @param param The test parameters
72 public _XDataPilotDescriptor(XDataPilotDescriptor xObj/*,
73 LogWriter log*/, TestParameters param) {
74 oObj = xObj;
75 this.param = param;
78 /**
79 * Retrieves object relations.
82 public boolean before() {
83 Integer amount = (Integer)param.get("FIELDSAMOUNT");
84 if (amount == null) {
85 System.out.println("Relation 'FIELDSAMOUNT' not found");
86 return false;
88 tEnvFieldsAmount = amount.intValue();
89 return true;
92 /**
93 * Test calls the method and compares returned value with value that was set
94 * in method <code>setSourceRange()</code>. <p>
95 * Has <b> OK </b> status if all fields of cell range addresses are equal. <p>
96 * The following method tests are to be completed successfully before :
97 * <ul>
98 * <li> <code> setSourceRange() </code> : to have current source range </li>
99 * </ul>
101 public boolean _getSourceRange(){
102 // requiredMethod("setSourceRange()");
103 boolean bResult = true;
105 CellRangeAddress objRA = oObj.getSourceRange();
106 bResult &= objRA.Sheet == CRA.Sheet;
107 bResult &= objRA.StartRow == CRA.StartRow;
108 bResult &= objRA.StartColumn == CRA.StartColumn;
109 bResult &= objRA.EndRow == CRA.EndRow;
110 bResult &= objRA.EndColumn == CRA.EndColumn;
112 return bResult;
116 * Test gets the current source range, stores it and sets new source range.<p>
117 * Has <b> OK </b> status if the method successfully returns. <p>
118 * The following method tests are to be executed before :
119 * <ul>
120 * <li> <code> getColumnFields() </code> </li>
121 * <li> <code> getRowFields() </code> </li>
122 * <li> <code> getDataFields() </code> </li>
123 * <li> <code> getHiddenFields() </code> </li>
124 * <li> <code> getPageFields() </code> </li>
125 * </ul>
127 public boolean _setSourceRange(){
129 oObj.setSourceRange(CRA);
131 return true;
135 * Test calls the method and checks returned value with value that was set
136 * by method <code>setTag()</code>. <p>
137 * Has <b> OK </b> status if returned value is equal to value that was set
138 * by method <code>setTag()</code>. <p>
139 * The following method tests are to be completed successfully before :
140 * <ul>
141 * <li> <code> setTag() </code> : to have current tag </li>
142 * </ul>
144 public boolean _getTag(){
145 boolean bResult = true;
147 String objTag = oObj.getTag();
148 bResult &= objTag.equals(sTag);
150 return bResult;
154 * Test just calls the method. <p>
155 * Has <b> OK </b> status if the method successfully returns. <p>
157 public boolean _setTag(){
158 oObj.setTag(sTag);
159 return true;
163 * Test calls the method , checks returned value, compares
164 * number of fields goten from returned value and obtained by object
165 * relation <code>'FIELDSAMOUNT'</code> and set property
166 * <code>Orientation</code> to one of DataPilotFieldOrientation values. <p>
167 * Has <b> OK </b> status if returned value isn't null, number of fields
168 * goten from returned value is less than number of fields obtained by relation
169 * and no exceptions were thrown. <p>
171 public boolean _getDataPilotFields(){
172 boolean bResult = true;
173 XIndexAccess IA = null;
175 IA = oObj.getDataPilotFields();
176 if (IA == null) {
177 System.out.println("Returned value is null.");
178 return false;
179 } else {System.out.println("getDataPilotFields returned not Null value -- OK");}
181 int fieldsAmount = IA.getCount();
182 if (fieldsAmount < tEnvFieldsAmount) {
183 System.out.println("Number of fields is less than number goten by relation.");
184 return false;
185 } else {System.out.println("count of returned fields -- OK");}
187 fieldsNames = new String[tEnvFieldsAmount];
188 int i = -1 ;
189 int cnt = 0 ;
190 while (++i < fieldsAmount) {
191 Object field;
192 try {
193 field = IA.getByIndex(i);
194 } catch(com.sun.star.lang.WrappedTargetException e) {
195 e.printStackTrace();
196 return false;
197 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
198 e.printStackTrace();
199 return false;
202 XNamed named = UnoRuntime.queryInterface(XNamed.class, field);
203 String name = named.getName();
205 System.out.println("Field : '" + name + "' ... ") ;
207 if (!name.equals("Data")) {
209 fieldsNames[cnt] = name ;
211 XPropertySet props =
212 UnoRuntime.queryInterface(XPropertySet.class, field);
214 try {
215 switch (cnt % 5) {
216 case 0 :
217 props.setPropertyValue("Orientation",
218 DataPilotFieldOrientation.COLUMN);
219 System.out.println(" Column") ;
220 break;
221 case 1 :
222 props.setPropertyValue("Orientation",
223 DataPilotFieldOrientation.ROW);
224 System.out.println(" Row") ;
225 break;
226 case 2 :
227 props.setPropertyValue("Orientation",
228 DataPilotFieldOrientation.DATA);
229 System.out.println(" Data") ;
230 break;
231 case 3 :
232 props.setPropertyValue("Orientation",
233 DataPilotFieldOrientation.HIDDEN);
234 System.out.println(" Hidden") ;
235 break;
236 case 4 :
237 props.setPropertyValue("Orientation",
238 DataPilotFieldOrientation.PAGE);
239 System.out.println(" Page") ;
240 props.setPropertyValue("CurrentPage", "20");
241 break;
242 } } catch (com.sun.star.lang.WrappedTargetException e) {
243 e.printStackTrace();
244 return false;
245 } catch (com.sun.star.lang.IllegalArgumentException e) {
246 e.printStackTrace();
247 return false;
248 } catch (com.sun.star.beans.PropertyVetoException e) {
249 e.printStackTrace();
250 return false;
251 } catch (com.sun.star.beans.UnknownPropertyException e) {
252 e.printStackTrace();
253 return false;
255 if (++cnt > 4)
257 break;
260 else
262 return false;
266 return bResult;
270 * Test calls the method and checks returned collection using the method
271 * <code>CheckNames()</code>. <p>
272 * Has <b> OK </b> status if the method <code>CheckNames()</code> returns true
273 * and no exceptions were thrown. <p>
274 * The following method tests are to be completed successfully before :
275 * <ul>
276 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
277 * </ul>
279 public boolean _getColumnFields(){
280 System.out.println("getColumnFields") ;
281 XIndexAccess IA = oObj.getColumnFields();
282 return CheckNames(IA, 0);
286 * Test calls the method and checks returned collection using the method
287 * <code>CheckNames()</code>. <p>
288 * Has <b> OK </b> status if the method <code>CheckNames()</code> returned true
289 * and no exceptions were thrown. <p>
290 * The following method tests are to be completed successfully before :
291 * <ul>
292 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
293 * </ul>
295 public boolean _getDataFields(){
296 System.out.println("getDataFields") ;
297 XIndexAccess IA = oObj.getDataFields();
298 return CheckNames(IA, 2);
302 * Test calls the method and checks returned collection using the method
303 * <code>CheckNames()</code>. <p>
304 * Has <b> OK </b> status if the method <code>CheckNames()</code> returned true
305 * and no exceptions were thrown. <p>
306 * The following method tests are to be completed successfully before :
307 * <ul>
308 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
309 * </ul>
311 public boolean _getHiddenFields(){
312 System.out.println("getHiddenFields") ;
313 XIndexAccess IA = oObj.getHiddenFields();
314 return CheckNames(IA, 3);
318 * Test calls the method and checks returned collection using the method
319 * <code>CheckNames()</code>. <p>
320 * Has <b> OK </b> status if the method <code>CheckNames()</code> returned true
321 * and no exceptions were thrown. <p>
322 * The following method tests are to be completed successfully before :
323 * <ul>
324 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
325 * </ul>
327 public boolean _getRowFields(){
328 System.out.println("getRowFields") ;
329 XIndexAccess IA = oObj.getRowFields();
330 boolean bResult = CheckNames(IA, 1);
331 return bResult;
335 * setting of PageFields isn't supported by StarOffice Calc
336 * Has <b> OK </b> status if the returned IndexAccess
337 * isn't NULL. <p>
338 * The following method tests are to be completed successfully before :
339 * <ul>
340 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
341 * </ul>
343 public boolean _getPageFields(){
344 System.out.println("getPageFields") ;
345 XIndexAccess IA = oObj.getPageFields();
346 boolean bResult = CheckNames(IA, 4);
347 return bResult;
351 * Test calls the method and checks returned value. <p>
352 * Has <b> OK </b> status if returned value isn't null
353 * and no exceptions were thrown. <p>
355 public boolean _getFilterDescriptor(){
356 boolean bResult = oObj.getFilterDescriptor() != null;
357 return bResult;
361 * Method checks that the field with index <code>rem</code> exists
362 * in the array <code>IA</code>.
363 * @param IA collection of elements that support interface <code>XNamed</code>
364 * @param rem index of field in the array of field names that was stored in
365 * the method <code>getDataPilotFields()</code>
366 * @return true if required field name exists in passed collection;
367 * false otherwise
368 * @see com.sun.star.container.XNamed
370 private boolean CheckNames(XIndexAccess IA, int rem) {
371 String name = null;
373 if (IA == null) {
374 System.out.println("Null returned.") ;
375 return false ;
378 if (fieldsNames[rem] == null) {
379 System.out.println("No fields were set to this orientation - can't check result") ;
380 return true ;
383 if (IA.getCount() == 0) {
384 System.out.println("No fields found. Must be at least '"
385 + fieldsNames[rem] + "'") ;
386 return false ;
389 try {
390 System.out.println("Fields returned ") ;
391 for (int i = 0; i < IA.getCount(); i++) {
392 Object field = IA.getByIndex(i);
393 XNamed named = UnoRuntime.queryInterface
394 (XNamed.class, field);
395 name = named.getName();
396 System.out.println(" " + name) ;
397 if (fieldsNames[rem].equals(name)) {
398 System.out.println(" - OK") ;
399 return true ;
402 } catch (com.sun.star.lang.WrappedTargetException e) {
403 e.printStackTrace();
404 return false ;
405 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
406 e.printStackTrace();
407 return false ;
409 System.out.println(" - FAILED (field " + fieldsNames[rem] + " was not found.") ;
410 return false ;
414 * Recreates object(to back old orientations of the fields).
416 protected void after() {
417 disposeEnvironment();