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
;
31 * Testing <code>com.sun.star.sheet.XDataPilotDescriptor</code>
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>
46 * This test needs the following object relations :
48 * <li> <code>'FIELDSAMOUNT'</code> (of type <code>Integer</code>):
49 * to have number of fields </li>
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;
65 private final TestParameters param
;
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
) {
79 * Retrieves object relations.
82 public boolean before() {
83 Integer amount
= (Integer
)param
.get("FIELDSAMOUNT");
85 System
.out
.println("Relation 'FIELDSAMOUNT' not found");
88 tEnvFieldsAmount
= amount
.intValue();
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 :
98 * <li> <code> setSourceRange() </code> : to have current source range </li>
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
;
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 :
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>
127 public boolean _setSourceRange(){
129 oObj
.setSourceRange(CRA
);
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 :
141 * <li> <code> setTag() </code> : to have current tag </li>
144 public boolean _getTag(){
145 boolean bResult
= true;
147 String objTag
= oObj
.getTag();
148 bResult
&= objTag
.equals(sTag
);
154 * Test just calls the method. <p>
155 * Has <b> OK </b> status if the method successfully returns. <p>
157 public boolean _setTag(){
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();
177 System
.out
.println("Returned value is null.");
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.");
185 } else {System
.out
.println("count of returned fields -- OK");}
187 fieldsNames
= new String
[tEnvFieldsAmount
];
190 while (++i
< fieldsAmount
) {
193 field
= IA
.getByIndex(i
);
194 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
197 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
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
;
212 UnoRuntime
.queryInterface(XPropertySet
.class, field
);
217 props
.setPropertyValue("Orientation",
218 DataPilotFieldOrientation
.COLUMN
);
219 System
.out
.println(" Column") ;
222 props
.setPropertyValue("Orientation",
223 DataPilotFieldOrientation
.ROW
);
224 System
.out
.println(" Row") ;
227 props
.setPropertyValue("Orientation",
228 DataPilotFieldOrientation
.DATA
);
229 System
.out
.println(" Data") ;
232 props
.setPropertyValue("Orientation",
233 DataPilotFieldOrientation
.HIDDEN
);
234 System
.out
.println(" Hidden") ;
237 props
.setPropertyValue("Orientation",
238 DataPilotFieldOrientation
.PAGE
);
239 System
.out
.println(" Page") ;
240 props
.setPropertyValue("CurrentPage", "20");
242 } } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
245 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
248 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
251 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
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 :
276 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
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 :
292 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
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 :
308 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
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 :
324 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
327 public boolean _getRowFields(){
328 System
.out
.println("getRowFields") ;
329 XIndexAccess IA
= oObj
.getRowFields();
330 boolean bResult
= CheckNames(IA
, 1);
335 * setting of PageFields isn't supported by StarOffice Calc
336 * Has <b> OK </b> status if the returned IndexAccess
338 * The following method tests are to be completed successfully before :
340 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
343 public boolean _getPageFields(){
344 System
.out
.println("getPageFields") ;
345 XIndexAccess IA
= oObj
.getPageFields();
346 boolean bResult
= CheckNames(IA
, 4);
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;
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;
368 * @see com.sun.star.container.XNamed
370 private boolean CheckNames(XIndexAccess IA
, int rem
) {
374 System
.out
.println("Null returned.") ;
378 if (fieldsNames
[rem
] == null) {
379 System
.out
.println("No fields were set to this orientation - can't check result") ;
383 if (IA
.getCount() == 0) {
384 System
.out
.println("No fields found. Must be at least '"
385 + fieldsNames
[rem
] + "'") ;
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") ;
402 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
405 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
409 System
.out
.println(" - FAILED (field " + fieldsNames
[rem
] + " was not found.") ;
414 * Recreates object(to back old orientations of the fields).
416 protected void after() {
417 disposeEnvironment();