fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sc / qa / complex / dataPilot / _XDataPilotDescriptor.java
blobf530b402b5e5559fab1ed73375f162037ff1ac02
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.MultiMethodTest;
29 // import lib.Status;
30 //import lib.StatusException;
31 import lib.TestParameters;
32 // import share.LogWriter;
34 /**
35 * Testing <code>com.sun.star.sheet.XDataPilotDescriptor</code>
36 * interface methods :
37 * <ul>
38 * <li><code> getTag()</code></li>
39 * <li><code> setTag()</code></li>
40 * <li><code> getSourceRange()</code></li>
41 * <li><code> setSourceRange()</code></li>
42 * <li><code> getFilterDescriptor()</code></li>
43 * <li><code> getDataPilotFields()</code></li>
44 * <li><code> getColumnFields()</code></li>
45 * <li><code> getRowFields()</code></li>
46 * <li><code> getPageFields()</code></li>
47 * <li><code> getDataFields()</code></li>
48 * <li><code> getHiddenFields()</code></li>
49 * </ul> <p>
50 * This test needs the following object relations :
51 * <ul>
52 * <li> <code>'FIELDSAMOUNT'</code> (of type <code>Integer</code>):
53 * to have number of fields </li>
54 * <ul> <p>
55 * @see com.sun.star.sheet.XDataPilotDescriptor
57 public class _XDataPilotDescriptor {
59 public XDataPilotDescriptor oObj = null;
60 CellRangeAddress CRA = new CellRangeAddress((short)1, 0, 0, 5, 5);
61 CellRangeAddress oldCRA = null ;
62 String sTag = new String ("XDataPilotDescriptor_Tag");
63 String fieldsNames[];
64 int fieldsAmount = 0;
65 int tEnvFieldsAmount = 0;
67 /**
68 * The test parameters
70 private TestParameters param = null;
72 /**
73 * The log writer
75 // private LogWriter log = null;
77 /**
78 * Constructor: gets the object to test, a logger and the test parameters
79 * @param xObj The test object
80 * @param param The test parameters
82 public _XDataPilotDescriptor(XDataPilotDescriptor xObj/*,
83 LogWriter log*/, TestParameters param) {
84 oObj = xObj;
85 // this.log = log;
86 this.param = param;
89 /**
90 * Retrieves object relations.
92 * @return
94 public boolean before() {
95 Integer amount = (Integer)param.get("FIELDSAMOUNT");
96 if (amount == null) {
97 System.out.println("Relation 'FIELDSAMOUNT' not found");
98 return false;
100 tEnvFieldsAmount = amount.intValue();
101 return true;
105 * Test calls the method and compares returned value with value that was set
106 * in method <code>setSourceRange()</code>. <p>
107 * Has <b> OK </b> status if all fields of cell range addresses are equal. <p>
108 * The following method tests are to be completed successfully before :
109 * <ul>
110 * <li> <code> setSourceRange() </code> : to have current source range </li>
111 * </ul>
112 * @return
114 public boolean _getSourceRange(){
115 // requiredMethod("setSourceRange()");
116 boolean bResult = true;
118 CellRangeAddress objRA = oObj.getSourceRange();
119 bResult &= objRA.Sheet == CRA.Sheet;
120 bResult &= objRA.StartRow == CRA.StartRow;
121 bResult &= objRA.StartColumn == CRA.StartColumn;
122 bResult &= objRA.EndRow == CRA.EndRow;
123 bResult &= objRA.EndColumn == CRA.EndColumn;
125 return bResult;
129 * Test gets the current source range, stores it and sets new source range.<p>
130 * Has <b> OK </b> status if the method successfully returns. <p>
131 * The following method tests are to be executed before :
132 * <ul>
133 * <li> <code> getColumnFields() </code> </li>
134 * <li> <code> getRowFields() </code> </li>
135 * <li> <code> getDataFields() </code> </li>
136 * <li> <code> getHiddenFields() </code> </li>
137 * <li> <code> getPageFields() </code> </li>
138 * </ul>
139 * @return
141 public boolean _setSourceRange(){
142 /* executeMethod("getColumnFields()") ;
143 executeMethod("getRowFields()") ;
144 executeMethod("getDataFields()") ;
145 executeMethod("getHiddenFields()") ;
146 executeMethod("getPageFields()") ; */
148 oldCRA = oObj.getSourceRange() ;
149 oObj.setSourceRange(CRA);
151 return true;
155 * Test calls the method and checks returned value with value that was set
156 * by method <code>setTag()</code>. <p>
157 * Has <b> OK </b> status if returned value is equal to value that was set
158 * by method <code>setTag()</code>. <p>
159 * The following method tests are to be completed successfully before :
160 * <ul>
161 * <li> <code> setTag() </code> : to have current tag </li>
162 * </ul>
163 * @return
165 public boolean _getTag(){
166 // requiredMethod("setTag()");
167 boolean bResult = true;
169 String objTag = oObj.getTag();
170 bResult &= objTag.equals(sTag);
172 return bResult;
176 * Test just calls the method. <p>
177 * Has <b> OK </b> status if the method successfully returns. <p>
178 * @return
180 public boolean _setTag(){
181 oObj.setTag(sTag);
182 return true;
186 * Test calls the method , checks returned value, compares
187 * number of fields goten from returned value and obtained by object
188 * relation <code>'FIELDSAMOUNT'</code> and set property
189 * <code>Orientation</code> to one of DataPilotFieldOrientation values. <p>
190 * Has <b> OK </b> status if returned value isn't null, number of fields
191 * goten from returned value is less than number of fields obtained by relation
192 * and no exceptions were thrown. <p>
193 * @return
195 public boolean _getDataPilotFields(){
196 boolean bResult = true;
197 XIndexAccess IA = null;
199 IA = oObj.getDataPilotFields();
200 if (IA == null) {
201 System.out.println("Returned value is null.");
202 return false;
203 } else {System.out.println("getDataPilotFields returned not Null value -- OK");}
205 fieldsAmount = IA.getCount();
206 if (fieldsAmount < tEnvFieldsAmount) {
207 System.out.println("Number of fields is less than number goten by relation.");
208 return false;
209 } else {System.out.println("count of returned fields -- OK");}
211 fieldsNames = new String[tEnvFieldsAmount];
212 int i = -1 ;
213 int cnt = 0 ;
214 while (++i < fieldsAmount) {
215 Object field;
216 try {
217 field = IA.getByIndex(i);
218 } catch(com.sun.star.lang.WrappedTargetException e) {
219 e.printStackTrace();
220 return false;
221 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
222 e.printStackTrace();
223 return false;
226 XNamed named = UnoRuntime.queryInterface(XNamed.class, field);
227 String name = named.getName();
229 System.out.println("Field : '" + name + "' ... ") ;
231 if (!name.equals("Data")) {
233 fieldsNames[cnt] = name ;
235 XPropertySet props =
236 UnoRuntime.queryInterface(XPropertySet.class, field);
238 try {
239 switch (cnt % 5) {
240 case 0 :
241 props.setPropertyValue("Orientation",
242 DataPilotFieldOrientation.COLUMN);
243 System.out.println(" Column") ;
244 break;
245 case 1 :
246 props.setPropertyValue("Orientation",
247 DataPilotFieldOrientation.ROW);
248 System.out.println(" Row") ;
249 break;
250 case 2 :
251 props.setPropertyValue("Orientation",
252 DataPilotFieldOrientation.DATA);
253 System.out.println(" Data") ;
254 break;
255 case 3 :
256 props.setPropertyValue("Orientation",
257 DataPilotFieldOrientation.HIDDEN);
258 System.out.println(" Hidden") ;
259 break;
260 case 4 :
261 props.setPropertyValue("Orientation",
262 DataPilotFieldOrientation.PAGE);
263 System.out.println(" Page") ;
264 props.setPropertyValue("CurrentPage", "20");
265 break;
266 } } catch (com.sun.star.lang.WrappedTargetException e) {
267 e.printStackTrace();
268 return false;
269 } catch (com.sun.star.lang.IllegalArgumentException e) {
270 e.printStackTrace();
271 return false;
272 } catch (com.sun.star.beans.PropertyVetoException e) {
273 e.printStackTrace();
274 return false;
275 } catch (com.sun.star.beans.UnknownPropertyException e) {
276 e.printStackTrace();
277 return false;
279 if (++cnt > 4)
281 break;
284 else
286 return false;
290 return bResult;
294 * Test calls the method and checks returned collection using the method
295 * <code>CheckNames()</code>. <p>
296 * Has <b> OK </b> status if the method <code>CheckNames()</code> returns true
297 * and no exceptions were thrown. <p>
298 * The following method tests are to be completed successfully before :
299 * <ul>
300 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
301 * </ul>
302 * @return
304 public boolean _getColumnFields(){
305 // requiredMethod("getDataPilotFields()");
306 System.out.println("getColumnFields") ;
307 XIndexAccess IA = oObj.getColumnFields();
308 return CheckNames(IA, 0);
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>
320 * @return
322 public boolean _getDataFields(){
323 // requiredMethod("getDataPilotFields()");
324 System.out.println("getDataFields") ;
325 XIndexAccess IA = oObj.getDataFields();
326 return CheckNames(IA, 2);
330 * Test calls the method and checks returned collection using the method
331 * <code>CheckNames()</code>. <p>
332 * Has <b> OK </b> status if the method <code>CheckNames()</code> returned true
333 * and no exceptions were thrown. <p>
334 * The following method tests are to be completed successfully before :
335 * <ul>
336 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
337 * </ul>
338 * @return
340 public boolean _getHiddenFields(){
341 // requiredMethod("getDataPilotFields()");
342 System.out.println("getHiddenFields") ;
343 XIndexAccess IA = oObj.getHiddenFields();
344 return CheckNames(IA, 3);
348 * Test calls the method and checks returned collection using the method
349 * <code>CheckNames()</code>. <p>
350 * Has <b> OK </b> status if the method <code>CheckNames()</code> returned true
351 * and no exceptions were thrown. <p>
352 * The following method tests are to be completed successfully before :
353 * <ul>
354 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
355 * </ul>
356 * @return
358 public boolean _getRowFields(){
359 // requiredMethod("getDataPilotFields()");
360 System.out.println("getRowFields") ;
361 XIndexAccess IA = oObj.getRowFields();
362 boolean bResult = CheckNames(IA, 1);
363 return bResult;
367 * setting of PageFields isn't supported by StarOffice Calc
368 * Has <b> OK </b> status if the returned IndexAccess
369 * isn't NULL. <p>
370 * The following method tests are to be completed successfully before :
371 * <ul>
372 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
373 * </ul>
374 * @return
376 public boolean _getPageFields(){
377 // requiredMethod("getDataPilotFields()");
378 System.out.println("getPageFields") ;
379 XIndexAccess IA = oObj.getPageFields();
380 boolean bResult = CheckNames(IA, 4);
381 return bResult;
385 * Test calls the method and checks returned value. <p>
386 * Has <b> OK </b> status if returned value isn't null
387 * and no exceptions were thrown. <p>
388 * @return
390 public boolean _getFilterDescriptor(){
391 boolean bResult = oObj.getFilterDescriptor() != null;
392 return bResult;
396 * Method checks that the field with index <code>rem</code> exists
397 * in the array <code>IA</code>.
398 * @param IA collection of elements that support interface <code>XNamed</code>
399 * @param rem index of field in the array of field names that was stored in
400 * the method <code>getDataPilotFields()</code>
401 * @return true if required field name exists in passed collection;
402 * false otherwise
403 * @see com.sun.star.container.XNamed
405 private boolean CheckNames(XIndexAccess IA, int rem) {
406 String name = null;
408 if (IA == null) {
409 System.out.println("Null retruned.") ;
410 return false ;
413 if (fieldsNames[rem] == null) {
414 System.out.println("No fields were set to this orientation - cann't check result") ;
415 return true ;
418 if (IA.getCount() == 0) {
419 System.out.println("No fields found. Must be at least '"
420 + fieldsNames[rem] + "'") ;
421 return false ;
424 try {
425 System.out.println("Fields returned ") ;
426 for (int i = 0; i < IA.getCount(); i++) {
427 Object field = IA.getByIndex(i);
428 XNamed named = UnoRuntime.queryInterface
429 (XNamed.class, field);
430 name = named.getName();
431 System.out.println(" " + name) ;
432 if (fieldsNames[rem].equals(name)) {
433 System.out.println(" - OK") ;
434 return true ;
437 } catch (com.sun.star.lang.WrappedTargetException e) {
438 e.printStackTrace();
439 return false ;
440 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
441 e.printStackTrace();
442 return false ;
444 System.out.println(" - FAILED (field " + fieldsNames[rem] + " was not found.") ;
445 return false ;
449 * Recreates object(to back old orientations of the fields).
451 protected void after() {
452 disposeEnvironment();