1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 import lib
.MultiMethodTest
;
32 import lib
.StatusException
;
34 import com
.sun
.star
.beans
.XPropertySet
;
35 import com
.sun
.star
.container
.XIndexAccess
;
36 import com
.sun
.star
.container
.XNamed
;
37 import com
.sun
.star
.sheet
.DataPilotFieldOrientation
;
38 import com
.sun
.star
.sheet
.XDataPilotDescriptor
;
39 import com
.sun
.star
.table
.CellRangeAddress
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
43 * Testing <code>com.sun.star.sheet.XDataPilotDescriptor</code>
46 * <li><code> getTag()</code></li>
47 * <li><code> setTag()</code></li>
48 * <li><code> getSourceRange()</code></li>
49 * <li><code> setSourceRange()</code></li>
50 * <li><code> getFilterDescriptor()</code></li>
51 * <li><code> getDataPilotFields()</code></li>
52 * <li><code> getColumnFields()</code></li>
53 * <li><code> getRowFields()</code></li>
54 * <li><code> getPageFields()</code></li>
55 * <li><code> getDataFields()</code></li>
56 * <li><code> getHiddenFields()</code></li>
58 * This test needs the following object relations :
60 * <li> <code>'FIELDSAMOUNT'</code> (of type <code>Integer</code>):
61 * to have number of fields </li>
63 * @see com.sun.star.sheet.XDataPilotDescriptor
65 public class _XDataPilotDescriptor
extends MultiMethodTest
{
67 public XDataPilotDescriptor oObj
= null;
68 CellRangeAddress CRA
= new CellRangeAddress((short)1, 1, 1, 5, 5);
69 CellRangeAddress oldCRA
= null ;
70 String sTag
= new String ("XDataPilotDescriptor_Tag");
73 int tEnvFieldsAmount
= 0;
76 * Retrieves object relations.
77 * @throws StatusException If one of relations not found.
79 protected void before() {
80 Integer amount
= (Integer
)tEnv
.getObjRelation("FIELDSAMOUNT");
81 if (amount
== null) throw new StatusException(Status
.failed
82 ("Relation 'FIELDSAMOUNT' not found"));
83 tEnvFieldsAmount
= amount
.intValue();
87 * Test calls the method and compares returned value with value that was set
88 * in method <code>setSourceRange()</code>. <p>
89 * Has <b> OK </b> status if all fields of cell range addresses are equal. <p>
90 * The following method tests are to be completed successfully before :
92 * <li> <code> setSourceRange() </code> : to have current source range </li>
95 public void _getSourceRange(){
96 requiredMethod("setSourceRange()");
97 boolean bResult
= true;
99 CellRangeAddress objRA
= oObj
.getSourceRange();
100 bResult
&= objRA
.Sheet
== CRA
.Sheet
;
101 bResult
&= objRA
.StartRow
== CRA
.StartRow
;
102 bResult
&= objRA
.StartColumn
== CRA
.StartColumn
;
103 bResult
&= objRA
.EndRow
== CRA
.EndRow
;
104 bResult
&= objRA
.EndColumn
== CRA
.EndColumn
;
106 tRes
.tested("getSourceRange()", bResult
);
110 * Test gets the current source range, stores it and sets new source range.<p>
111 * Has <b> OK </b> status if the method successfully returns. <p>
112 * The following method tests are to be executed before :
114 * <li> <code> getColumnFields() </code> </li>
115 * <li> <code> getRowFields() </code> </li>
116 * <li> <code> getDataFields() </code> </li>
117 * <li> <code> getHiddenFields() </code> </li>
118 * <li> <code> getPageFields() </code> </li>
121 public void _setSourceRange(){
122 executeMethod("getColumnFields()") ;
123 executeMethod("getRowFields()") ;
124 executeMethod("getDataFields()") ;
125 executeMethod("getHiddenFields()") ;
126 executeMethod("getPageFields()") ;
128 oldCRA
= oObj
.getSourceRange() ;
129 oObj
.setSourceRange(CRA
);
131 tRes
.tested("setSourceRange()", 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 :
141 * <li> <code> setTag() </code> : to have current tag </li>
144 public void _getTag(){
145 requiredMethod("setTag()");
146 boolean bResult
= true;
148 String objTag
= oObj
.getTag();
149 bResult
&= objTag
.equals(sTag
);
151 tRes
.tested("getTag()", bResult
);
155 * Test just calls the method. <p>
156 * Has <b> OK </b> status if the method successfully returns. <p>
158 public void _setTag(){
160 tRes
.tested("setTag()", true);
164 * Test calls the method , checks returned value, compares
165 * number of fields goten from returned value and obtained by object
166 * relation <code>'FIELDSAMOUNT'</code> and set property
167 * <code>Orientation</code> to one of DataPilotFieldOrientation values. <p>
168 * Has <b> OK </b> status if returned value isn't null, number of fields
169 * goten from returned value is less than number of fields obtained by relation
170 * and no exceptions were thrown. <p>
172 public void _getDataPilotFields(){
173 boolean bResult
= true;
174 XIndexAccess IA
= null;
176 IA
= oObj
.getDataPilotFields();
178 log
.println("Returned value is null.");
179 tRes
.tested("getDataPilotFields()", false);
181 } else {log
.println("getDataPilotFields returned not Null value -- OK");}
183 fieldsAmount
= IA
.getCount();
184 if (fieldsAmount
< tEnvFieldsAmount
) {
185 log
.println("Number of fields is less than number goten by relation.");
186 tRes
.tested("getDataPilotFields()", false);
188 } else {log
.println("count of returned fields -- OK");}
190 fieldsNames
= new String
[tEnvFieldsAmount
];
193 while (++i
< fieldsAmount
) {
196 field
= IA
.getByIndex(i
);
197 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
198 e
.printStackTrace(log
);
199 tRes
.tested("getDataPilotFields()", false);
201 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
202 e
.printStackTrace(log
);
203 tRes
.tested("getDataPilotFields()", false);
207 XNamed named
= (XNamed
)
208 UnoRuntime
.queryInterface(XNamed
.class, field
);
209 String name
= named
.getName();
211 log
.print("Field : '" + name
+ "' ... ") ;
213 if (!name
.equals("Data")) {
215 fieldsNames
[cnt
] = name
;
217 XPropertySet props
= (XPropertySet
)
218 UnoRuntime
.queryInterface(XPropertySet
.class, field
);
223 props
.setPropertyValue("Orientation",
224 DataPilotFieldOrientation
.COLUMN
);
225 log
.println(" Column") ;
228 props
.setPropertyValue("Orientation",
229 DataPilotFieldOrientation
.ROW
);
230 log
.println(" Row") ;
233 props
.setPropertyValue("Orientation",
234 DataPilotFieldOrientation
.DATA
);
235 log
.println(" Data") ;
238 props
.setPropertyValue("Orientation",
239 DataPilotFieldOrientation
.HIDDEN
);
240 log
.println(" Hidden") ;
243 props
.setPropertyValue("Orientation",
244 DataPilotFieldOrientation
.PAGE
);
245 log
.println(" Page") ;
247 } } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
248 e
.printStackTrace(log
);
249 tRes
.tested("getDataPilotFields()", false);
251 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
252 e
.printStackTrace(log
);
253 tRes
.tested("getDataPilotFields()", false);
255 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
256 e
.printStackTrace(log
);
257 tRes
.tested("getDataPilotFields()", false);
259 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
260 e
.printStackTrace(log
);
261 tRes
.tested("getDataPilotFields()", false);
264 if (++cnt
> 4) break;
266 tRes
.tested("getDataPilotFields()", false);
271 tRes
.tested("getDataPilotFields()", bResult
);
275 * Test calls the method and checks returned collection using the method
276 * <code>CheckNames()</code>. <p>
277 * Has <b> OK </b> status if the method <code>CheckNames()</code> returns true
278 * and no exceptions were thrown. <p>
279 * The following method tests are to be completed successfully before :
281 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
284 public void _getColumnFields(){
285 requiredMethod("getDataPilotFields()");
286 XIndexAccess IA
= oObj
.getColumnFields();
287 boolean bResult
= CheckNames(IA
, 0);
288 tRes
.tested("getColumnFields()", bResult
);
292 * Test calls the method and checks returned collection using the method
293 * <code>CheckNames()</code>. <p>
294 * Has <b> OK </b> status if the method <code>CheckNames()</code> returned true
295 * and no exceptions were thrown. <p>
296 * The following method tests are to be completed successfully before :
298 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
301 public void _getDataFields(){
302 requiredMethod("getDataPilotFields()");
303 XIndexAccess IA
= oObj
.getDataFields();
304 boolean bResult
= CheckNames(IA
, 2);
305 tRes
.tested("getDataFields()", bResult
);
309 * Test calls the method and checks returned collection using the method
310 * <code>CheckNames()</code>. <p>
311 * Has <b> OK </b> status if the method <code>CheckNames()</code> returned true
312 * and no exceptions were thrown. <p>
313 * The following method tests are to be completed successfully before :
315 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
318 public void _getHiddenFields(){
319 requiredMethod("getDataPilotFields()");
320 XIndexAccess IA
= oObj
.getHiddenFields();
321 boolean bResult
= CheckNames(IA
, 3);
322 tRes
.tested("getHiddenFields()", bResult
);
326 * Test calls the method and checks returned collection using the method
327 * <code>CheckNames()</code>. <p>
328 * Has <b> OK </b> status if the method <code>CheckNames()</code> returned true
329 * and no exceptions were thrown. <p>
330 * The following method tests are to be completed successfully before :
332 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
335 public void _getRowFields(){
336 requiredMethod("getDataPilotFields()");
337 XIndexAccess IA
= oObj
.getRowFields();
338 boolean bResult
= CheckNames(IA
, 1);
339 tRes
.tested("getRowFields()", bResult
);
343 * setting of PageFields isn't supported by StarOffice Calc
344 * Has <b> OK </b> status if the returned IndexAccess
346 * The following method tests are to be completed successfully before :
348 * <li> <code> getDataPilotFields() </code> : to have array of field names </li>
351 public void _getPageFields(){
352 requiredMethod("getDataPilotFields()");
353 XIndexAccess IA
= oObj
.getPageFields();
354 boolean bResult
= (IA
!= null);
355 // boolean bResult = CheckNames(IA, 4);
356 tRes
.tested("getPageFields()", bResult
);
360 * Test calls the method and checks returned value. <p>
361 * Has <b> OK </b> status if returned value isn't null
362 * and no exceptions were thrown. <p>
364 public void _getFilterDescriptor(){
365 boolean bResult
= oObj
.getFilterDescriptor() != null;
366 tRes
.tested("getFilterDescriptor()", bResult
);
370 * Method checks that the field with index <code>rem</code> exists
371 * in the array <code>IA</code>.
372 * @param IA collection of elements that support interface <code>XNamed</code>
373 * @param rem index of field in the array of field names that was stored in
374 * the method <code>getDataPilotFields()</code>
375 * @return true if required field name exists in passed collection;
377 * @see com.sun.star.container.XNamed
379 boolean CheckNames(XIndexAccess IA
, int rem
) {
383 log
.println("Null retruned.") ;
387 if (fieldsNames
[rem
] == null) {
388 log
.println("No fields were set to this orientation - cann't check result") ;
392 if (IA
.getCount() == 0) {
393 log
.println("No fields found. Must be at least '"
394 + fieldsNames
[rem
] + "'") ;
399 log
.print("Fields returned ") ;
400 for (int i
= 0; i
< IA
.getCount(); i
++) {
401 Object field
= IA
.getByIndex(i
);
402 XNamed named
= (XNamed
)UnoRuntime
.queryInterface
403 (XNamed
.class, field
);
404 name
= named
.getName();
405 log
.print(" " + name
) ;
406 if (fieldsNames
[rem
].equals(name
)) {
407 log
.println(" - OK") ;
411 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
412 e
.printStackTrace(log
) ;
414 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
415 e
.printStackTrace(log
) ;
418 log
.println(" - FAILED (field " + fieldsNames
[rem
] + " was not found.") ;
423 * Recreates object(to back old orientations of the fields).
425 protected void after() {
426 disposeEnvironment();