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;
30 //import lib.StatusException;
31 import lib
.TestParameters
;
32 // import share.LogWriter;
35 * Testing <code>com.sun.star.sheet.XDataPilotDescriptor</code>
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>
50 * This test needs the following object relations :
52 * <li> <code>'FIELDSAMOUNT'</code> (of type <code>Integer</code>):
53 * to have number of fields </li>
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");
65 int tEnvFieldsAmount
= 0;
70 private TestParameters param
= null;
75 // private LogWriter log = null;
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
) {
90 * Retrieves object relations.
94 public boolean before() {
95 Integer amount
= (Integer
)param
.get("FIELDSAMOUNT");
97 System
.out
.println("Relation 'FIELDSAMOUNT' not found");
100 tEnvFieldsAmount
= amount
.intValue();
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 :
110 * <li> <code> setSourceRange() </code> : to have current source range </li>
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
;
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 :
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>
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
);
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 :
161 * <li> <code> setTag() </code> : to have current tag </li>
165 public boolean _getTag(){
166 // requiredMethod("setTag()");
167 boolean bResult
= true;
169 String objTag
= oObj
.getTag();
170 bResult
&= objTag
.equals(sTag
);
176 * Test just calls the method. <p>
177 * Has <b> OK </b> status if the method successfully returns. <p>
180 public boolean _setTag(){
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>
195 public boolean _getDataPilotFields(){
196 boolean bResult
= true;
197 XIndexAccess IA
= null;
199 IA
= oObj
.getDataPilotFields();
201 System
.out
.println("Returned value is null.");
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.");
209 } else {System
.out
.println("count of returned fields -- OK");}
211 fieldsNames
= new String
[tEnvFieldsAmount
];
214 while (++i
< fieldsAmount
) {
217 field
= IA
.getByIndex(i
);
218 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
221 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
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
;
236 UnoRuntime
.queryInterface(XPropertySet
.class, field
);
241 props
.setPropertyValue("Orientation",
242 DataPilotFieldOrientation
.COLUMN
);
243 System
.out
.println(" Column") ;
246 props
.setPropertyValue("Orientation",
247 DataPilotFieldOrientation
.ROW
);
248 System
.out
.println(" Row") ;
251 props
.setPropertyValue("Orientation",
252 DataPilotFieldOrientation
.DATA
);
253 System
.out
.println(" Data") ;
256 props
.setPropertyValue("Orientation",
257 DataPilotFieldOrientation
.HIDDEN
);
258 System
.out
.println(" Hidden") ;
261 props
.setPropertyValue("Orientation",
262 DataPilotFieldOrientation
.PAGE
);
263 System
.out
.println(" Page") ;
264 props
.setPropertyValue("CurrentPage", "20");
266 } } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
269 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
272 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
275 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
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 :
300 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
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 :
318 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
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 :
336 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
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 :
354 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
358 public boolean _getRowFields(){
359 // requiredMethod("getDataPilotFields()");
360 System
.out
.println("getRowFields") ;
361 XIndexAccess IA
= oObj
.getRowFields();
362 boolean bResult
= CheckNames(IA
, 1);
367 * setting of PageFields isn't supported by StarOffice Calc
368 * Has <b> OK </b> status if the returned IndexAccess
370 * The following method tests are to be completed successfully before :
372 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
376 public boolean _getPageFields(){
377 // requiredMethod("getDataPilotFields()");
378 System
.out
.println("getPageFields") ;
379 XIndexAccess IA
= oObj
.getPageFields();
380 boolean bResult
= CheckNames(IA
, 4);
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>
390 public boolean _getFilterDescriptor(){
391 boolean bResult
= oObj
.getFilterDescriptor() != null;
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;
403 * @see com.sun.star.container.XNamed
405 private boolean CheckNames(XIndexAccess IA
, int rem
) {
409 System
.out
.println("Null retruned.") ;
413 if (fieldsNames
[rem
] == null) {
414 System
.out
.println("No fields were set to this orientation - cann't check result") ;
418 if (IA
.getCount() == 0) {
419 System
.out
.println("No fields found. Must be at least '"
420 + fieldsNames
[rem
] + "'") ;
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") ;
437 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
440 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
444 System
.out
.println(" - FAILED (field " + fieldsNames
[rem
] + " was not found.") ;
449 * Recreates object(to back old orientations of the fields).
451 protected void after() {
452 disposeEnvironment();