1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XArrayFormulaRange.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import lib
.StatusException
;
37 import com
.sun
.star
.sheet
.XArrayFormulaRange
;
38 import com
.sun
.star
.sheet
.XCellRangeAddressable
;
39 import com
.sun
.star
.sheet
.XSpreadsheet
;
40 import com
.sun
.star
.table
.CellRangeAddress
;
41 import com
.sun
.star
.table
.XCell
;
42 import com
.sun
.star
.uno
.UnoRuntime
;
45 * Testing <code>com.sun.star.sheet.XArrayFormulaRange</code>
48 * <li><code> getArrayFormula()</code></li>
49 * <li><code> setArrayFormula()</code></li>
51 * This test needs the following object relations :
53 * <li> <code>'SHEET'</code> (of type <code>XSpreadsheet</code>):
54 * to check contents of spreadsheet </li>
55 * <li> <code>'noArray'</code> (of type <code>Object</code>):
56 * if the relation is null then given component doesn't really support
57 * this interface </li>
59 * Test object must implements interface <code>XCellRangeAddressable</code> also.
60 * @see com.sun.star.sheet.XArrayFormulaRange
61 * @see com.sun.star.sheet.XSpreadsheet
62 * @see com.sun.star.sheet.XCellRangeAddressable
64 public class _XArrayFormulaRange
extends MultiMethodTest
{
66 public XArrayFormulaRange oObj
= null;
67 String formula
= "=1 + 2 * 5";
70 * Test calls the method and then checks content sof spreadsheet using
71 * object relation <code>'SHEET'</code>. <p>
72 * Has <b> OK </b> status if values in cells of spreadsheet are equal to 11
73 * or ArrayFormula not supported.<p>
75 public void _setArrayFormula() {
76 Object noArray
= tEnv
.getObjRelation("noArray");
77 if (noArray
!= null) {
78 log
.println("Component " + noArray
.toString() +
79 " doesn't really support this Interface");
80 log
.println("It doesn't make sense to set an ArrayFormula over"
81 + " the whole sheet");
82 tRes
.tested("setArrayFormula()", true);
86 boolean result
= true;
89 log
.println("setArrayFormula() ...");
91 oObj
.setArrayFormula(formula
);
93 log
.println("checking that formula was set correctly...");
94 XCellRangeAddressable crAddr
=
95 (XCellRangeAddressable
)
96 UnoRuntime
.queryInterface(XCellRangeAddressable
.class, oObj
);
97 CellRangeAddress addr
= crAddr
.getRangeAddress() ;
98 XSpreadsheet oSheet
= (XSpreadsheet
)tEnv
.getObjRelation("SHEET");
99 if (oSheet
== null) throw new StatusException(Status
.failed
100 ("Relation 'SHEET' not found"));
105 for (int i
= addr
.StartColumn
; i
<= addr
.EndColumn
; i
++)
106 for (int j
= addr
.StartRow
; j
<= addr
.EndRow
; j
++) {
108 oCell
= oSheet
.getCellByPosition(i
, j
);
109 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
110 e
.printStackTrace(log
);
115 value
= oCell
.getValue();
116 result
&= (value
== dresult
);
119 tRes
.tested("setArrayFormula()", result
) ;
121 } // end setArrayFormula()
124 * Test calls the method and compare formula that set by method
125 * <code>setArrayFormula</code> with returned value ignoring spaces. <p>
127 * Has <b> OK </b> status if values are equal or
128 * ArrayFormula not supported. <p>
130 * The following method tests are to be completed successfully before :
132 * <li> <code> setArrayFormula </code> : to set formula </li>
135 public void _getArrayFormula() {
137 Object noArray
= tEnv
.getObjRelation("noArray");
138 if (noArray
!= null) {
139 log
.println("Component "+noArray
.toString()+" doesn't really support this Interface");
140 log
.println("It doesn't make sense to set an ArrayFormula over the whole sheet");
141 log
.println("and therefore 'getArrayFormula()' won't work");
142 tRes
.tested("getArrayFormula()",true);
146 requiredMethod("setArrayFormula()");
147 boolean result
= true;
148 log
.println("Testing getArrayFormula() ...");
149 String gFormula
= oObj
.getArrayFormula() ;
150 result
&= equalIgnoreSpaces("{" + formula
+ "}", gFormula
);
152 log
.println("Method returned : '" + oObj
.getArrayFormula() + "'") ;
153 tRes
.tested("getArrayFormula()", result
) ;
155 } // end getArrayFormula()
158 * Method compares two string ignoring spaces.
159 * @return <code>true</code> if the argument
160 * is not null and the Strings are equal,
161 * ignoring spaces; <code>false</code> otherwise.
163 private boolean equalIgnoreSpaces(String s1
, String s2
) {
167 while (p1
< s1
.length() && p2
< s2
.length()) {
168 while (s1
.charAt(p1
) == ' ') p1
++ ;
169 while (s2
.charAt(p2
) == ' ') p2
++ ;
170 if (s1
.charAt(p1
) != s2
.charAt(p2
)) return false ;
175 return p1
== s1
.length() && p2
== s2
.length() ;
179 * Forces environment recreation.
181 protected void after() {
182 disposeEnvironment();