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
.sheet
.XArrayFormulaRange
;
26 import com
.sun
.star
.sheet
.XCellRangeAddressable
;
27 import com
.sun
.star
.sheet
.XSpreadsheet
;
28 import com
.sun
.star
.table
.CellRangeAddress
;
29 import com
.sun
.star
.table
.XCell
;
30 import com
.sun
.star
.uno
.UnoRuntime
;
33 * Testing <code>com.sun.star.sheet.XArrayFormulaRange</code>
36 * <li><code> getArrayFormula()</code></li>
37 * <li><code> setArrayFormula()</code></li>
39 * This test needs the following object relations :
41 * <li> <code>'SHEET'</code> (of type <code>XSpreadsheet</code>):
42 * to check contents of spreadsheet </li>
43 * <li> <code>'noArray'</code> (of type <code>Object</code>):
44 * if the relation is null then given component doesn't really support
45 * this interface </li>
47 * Test object must implements interface <code>XCellRangeAddressable</code> also.
48 * @see com.sun.star.sheet.XArrayFormulaRange
49 * @see com.sun.star.sheet.XSpreadsheet
50 * @see com.sun.star.sheet.XCellRangeAddressable
52 public class _XArrayFormulaRange
extends MultiMethodTest
{
54 public XArrayFormulaRange oObj
= null;
55 String formula
= "=1 + 2 * 5";
58 * Test calls the method and then checks content sof spreadsheet using
59 * object relation <code>'SHEET'</code>. <p>
60 * Has <b> OK </b> status if values in cells of spreadsheet are equal to 11
61 * or ArrayFormula not supported.<p>
63 public void _setArrayFormula() {
64 Object noArray
= tEnv
.getObjRelation("noArray");
65 if (noArray
!= null) {
66 log
.println("Component " + noArray
.toString() +
67 " doesn't really support this Interface");
68 log
.println("It doesn't make sense to set an ArrayFormula over"
69 + " the whole sheet");
70 tRes
.tested("setArrayFormula()", true);
74 boolean result
= true;
77 log
.println("setArrayFormula() ...");
79 oObj
.setArrayFormula(formula
);
81 log
.println("checking that formula was set correctly...");
82 XCellRangeAddressable crAddr
=
83 UnoRuntime
.queryInterface(XCellRangeAddressable
.class, oObj
);
84 CellRangeAddress addr
= crAddr
.getRangeAddress() ;
85 XSpreadsheet oSheet
= (XSpreadsheet
)tEnv
.getObjRelation("SHEET");
86 if (oSheet
== null) throw new StatusException(Status
.failed
87 ("Relation 'SHEET' not found"));
92 for (int i
= addr
.StartColumn
; i
<= addr
.EndColumn
; i
++)
93 for (int j
= addr
.StartRow
; j
<= addr
.EndRow
; j
++) {
95 oCell
= oSheet
.getCellByPosition(i
, j
);
96 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
97 e
.printStackTrace(log
);
102 value
= oCell
.getValue();
103 result
&= (value
== dresult
);
106 tRes
.tested("setArrayFormula()", result
) ;
108 } // end setArrayFormula()
111 * Test calls the method and compare formula that set by method
112 * <code>setArrayFormula</code> with returned value ignoring spaces. <p>
114 * Has <b> OK </b> status if values are equal or
115 * ArrayFormula not supported. <p>
117 * The following method tests are to be completed successfully before :
119 * <li> <code> setArrayFormula </code> : to set formula </li>
122 public void _getArrayFormula() {
124 Object noArray
= tEnv
.getObjRelation("noArray");
125 if (noArray
!= null) {
126 log
.println("Component "+noArray
.toString()+" doesn't really support this Interface");
127 log
.println("It doesn't make sense to set an ArrayFormula over the whole sheet");
128 log
.println("and therefore 'getArrayFormula()' won't work");
129 tRes
.tested("getArrayFormula()",true);
133 requiredMethod("setArrayFormula()");
134 boolean result
= true;
135 log
.println("Testing getArrayFormula() ...");
136 String gFormula
= oObj
.getArrayFormula() ;
137 result
&= equalIgnoreSpaces("{" + formula
+ "}", gFormula
);
139 log
.println("Method returned : '" + oObj
.getArrayFormula() + "'") ;
140 tRes
.tested("getArrayFormula()", result
) ;
142 } // end getArrayFormula()
145 * Method compares two string ignoring spaces.
146 * @return <code>true</code> if the argument
147 * is not null and the Strings are equal,
148 * ignoring spaces; <code>false</code> otherwise.
150 private boolean equalIgnoreSpaces(String s1
, String s2
) {
154 while (p1
< s1
.length() && p2
< s2
.length()) {
155 while (s1
.charAt(p1
) == ' ') { p1
++; }
156 while (s2
.charAt(p2
) == ' ') { p2
++; }
157 if (s1
.charAt(p1
) != s2
.charAt(p2
)) return false ;
162 return p1
== s1
.length() && p2
== s2
.length() ;
166 * Forces environment recreation.
169 protected void after() {
170 disposeEnvironment();