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 .
21 import lib
.MultiMethodTest
;
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
;
34 * Testing <code>com.sun.star.sheet.XDataPilotDescriptor</code>
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>
49 * This test needs the following object relations :
51 * <li> <code>'FIELDSAMOUNT'</code> (of type <code>Integer</code>):
52 * to have number of fields </li>
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";
64 int tEnvFieldsAmount
= 0;
67 * Retrieves object relations.
68 * @throws StatusException If one of relations not found.
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();
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 :
84 * <li> <code> setSourceRange() </code> : to have current source range </li>
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 :
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>
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 :
133 * <li> <code> setTag() </code> : to have current tag </li>
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(){
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();
170 log
.println("Returned value is null.");
171 tRes
.tested("getDataPilotFields()", false);
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);
180 } else {log
.println("count of returned fields -- OK");}
182 fieldsNames
= new String
[tEnvFieldsAmount
];
185 while (++i
< fieldsAmount
) {
188 field
= IA
.getByIndex(i
);
189 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
190 e
.printStackTrace(log
);
191 tRes
.tested("getDataPilotFields()", false);
193 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
194 e
.printStackTrace(log
);
195 tRes
.tested("getDataPilotFields()", false);
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
);
213 props
.setPropertyValue("Orientation",
214 DataPilotFieldOrientation
.COLUMN
);
215 log
.println(" Column") ;
218 props
.setPropertyValue("Orientation",
219 DataPilotFieldOrientation
.ROW
);
220 log
.println(" Row") ;
223 props
.setPropertyValue("Orientation",
224 DataPilotFieldOrientation
.DATA
);
225 log
.println(" Data") ;
228 props
.setPropertyValue("Orientation",
229 DataPilotFieldOrientation
.HIDDEN
);
230 log
.println(" Hidden") ;
233 props
.setPropertyValue("Orientation",
234 DataPilotFieldOrientation
.PAGE
);
235 log
.println(" Page") ;
237 } } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
238 e
.printStackTrace(log
);
239 tRes
.tested("getDataPilotFields()", false);
241 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
242 e
.printStackTrace(log
);
243 tRes
.tested("getDataPilotFields()", false);
245 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
246 e
.printStackTrace(log
);
247 tRes
.tested("getDataPilotFields()", false);
249 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
250 e
.printStackTrace(log
);
251 tRes
.tested("getDataPilotFields()", false);
254 if (++cnt
> 4) break;
256 tRes
.tested("getDataPilotFields()", false);
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 :
271 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
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 :
288 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
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 :
305 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
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 :
322 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
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
336 * The following method tests are to be completed successfully before :
338 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
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;
366 * @see com.sun.star.container.XNamed
368 boolean CheckNames(XIndexAccess IA
, int rem
) {
372 log
.println("Null retruned.") ;
376 if (fieldsNames
[rem
] == null) {
377 log
.println("No fields were set to this orientation - cann't check result") ;
381 if (IA
.getCount() == 0) {
382 log
.println("No fields found. Must be at least '"
383 + fieldsNames
[rem
] + "'") ;
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") ;
400 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
401 e
.printStackTrace(log
) ;
403 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
404 e
.printStackTrace(log
) ;
407 log
.println(" - FAILED (field " + fieldsNames
[rem
] + " was not found.") ;
412 * Recreates object(to back old orientations of the fields).
415 protected void after() {
416 disposeEnvironment();