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: _XCellRangeMovement.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 com
.sun
.star
.sheet
.CellDeleteMode
;
36 import com
.sun
.star
.sheet
.CellInsertMode
;
37 import com
.sun
.star
.sheet
.XCellRangeAddressable
;
38 import com
.sun
.star
.sheet
.XCellRangeMovement
;
39 import com
.sun
.star
.sheet
.XSpreadsheet
;
40 import com
.sun
.star
.table
.CellAddress
;
41 import com
.sun
.star
.table
.CellRangeAddress
;
42 import com
.sun
.star
.table
.XColumnRowRange
;
43 import com
.sun
.star
.table
.XTableRows
;
44 import com
.sun
.star
.uno
.UnoRuntime
;
47 * Testing <code>com.sun.star.sheet.XCellRangeMovement</code>
50 * <li><code> insertCells()</code></li>
51 * <li><code> removeRange()</code></li>
52 * <li><code> moveRange()</code></li>
53 * <li><code> copyRange()</code></li>
55 * Test object must implements interfaces <code>XCellRangeAddressable</code>
56 * and <code>XSpreadsheet</code> also. <p>
57 * @see com.sun.star.sheet.XCellRangeMovement
58 * @see com.sun.star.sheet.XSpreadsheet
59 * @see com.sun.star.sheet.XCellRangeAddressable
61 public class _XCellRangeMovement
extends MultiMethodTest
{
63 public XCellRangeMovement oObj
= null;
66 * Test sets specific values to cells in the range, copies this cell range
67 * to another position in document and checks cell's values in new position.<p>
68 * Has <b> OK </b> status if cell's values in source range are equal to
69 * cell's values in destination range and no exceptions were thrown. <p>
71 public void _copyRange(){
72 log
.println("Prepare cells before test methods.");
73 XSpreadsheet oSheet
= (XSpreadsheet
)
74 UnoRuntime
.queryInterface(XSpreadsheet
.class, oObj
);
76 oSheet
.getCellByPosition(1,1).setValue(100);
77 oSheet
.getCellByPosition(1,2).setValue(200);
78 oSheet
.getCellByPosition(2,1).setValue(300);
79 oSheet
.getCellByPosition(2,2).setValue(400);
80 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
81 e
.printStackTrace(log
);
82 tRes
.tested("copyRange()", false);
85 XCellRangeAddressable oAddr
=
86 (XCellRangeAddressable
)
87 UnoRuntime
.queryInterface (XCellRangeAddressable
.class, oObj
);
88 short iSheet
= oAddr
.getRangeAddress().Sheet
;
90 CellRangeAddress sSrc
;
92 sSrc
= new CellRangeAddress(iSheet
, 1, 1, 2, 2);
93 sDest
= new CellAddress(iSheet
, 1, 10);
94 boolean result
= true;
95 boolean loc_result
= true;
97 oObj
.copyRange(sDest
, sSrc
);
99 loc_result
= (oSheet
.getCellByPosition(1, 10).getValue() == 100);
100 loc_result
&= (oSheet
.getCellByPosition(1, 11).getValue() == 200);
101 loc_result
&= (oSheet
.getCellByPosition(2, 10).getValue() == 300);
102 loc_result
&= (oSheet
.getCellByPosition(2, 11).getValue() == 400);
103 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
104 e
.printStackTrace(log
);
105 tRes
.tested("copyRange()", false);
108 result
&= loc_result
;
109 tRes
.tested("copyRange()", result
);
113 * Test sets specific values to cells in the two contiguous rows, inserts
114 * new empty row between them and checks value in
115 * one cell of the inserted row. <p>
116 * Has <b> OK </b> status if value of cell in the inserted row is zero
117 * and no exceptions were thrown. <p>
119 public void _insertCells(){
120 boolean result
= false;
122 XSpreadsheet oSheet
= (XSpreadsheet
)
123 UnoRuntime
.queryInterface(XSpreadsheet
.class, oObj
);
124 XCellRangeAddressable oAddr
= (XCellRangeAddressable
)
125 UnoRuntime
.queryInterface (XCellRangeAddressable
.class, oObj
);
126 short iSheet
= oAddr
.getRangeAddress().Sheet
;
128 oSheet
.getCellByPosition(0,20).setValue(100);
129 oSheet
.getCellByPosition(1,20).setValue(100);
130 oSheet
.getCellByPosition(2,20).setValue(100);
131 oSheet
.getCellByPosition(3,20).setValue(100);
132 oSheet
.getCellByPosition(0,21).setValue(200);
133 oSheet
.getCellByPosition(1,21).setValue(200);
134 oSheet
.getCellByPosition(2,21).setValue(200);
135 oSheet
.getCellByPosition(3,21).setValue(200);
137 // catch some sleight of hand threads
138 if (oSheet
.getCellByPosition(1,21).getValue() == 200){
139 //log.println("Rows closed.");
142 log
.println("Cells were already inserted. "+
143 "Delete old cells now");
144 XColumnRowRange oColumnRowRange
= (XColumnRowRange
)
145 UnoRuntime
.queryInterface(XColumnRowRange
.class, oSheet
);
147 XTableRows oRows
= (XTableRows
) oColumnRowRange
.getRows();
148 oRows
.removeByIndex(21,1);
150 CellRangeAddress sSrc
= new CellRangeAddress(iSheet
, 0, 21, 5, 21);
151 oObj
.insertCells (sSrc
, CellInsertMode
.DOWN
) ;
154 double res
= oSheet
.getCellByPosition(1, 21).getValue();
158 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
159 e
.printStackTrace(log
);
163 tRes
.tested("insertCells()", result
);
167 * Test sets specific values to cells in the range, moves this cell range
168 * to another position in document and checks cell's values in new position.
169 * <p>Has <b>OK</b> status if sum of values in source range is equal to sum
170 * of values in destination range and no exceptions were thrown. <p>
172 public void _moveRange(){
173 boolean result
= false;
175 XSpreadsheet oSheet
= (XSpreadsheet
)
176 UnoRuntime
.queryInterface(XSpreadsheet
.class, oObj
);
178 XCellRangeAddressable oAddr
= (XCellRangeAddressable
)
179 UnoRuntime
.queryInterface (XCellRangeAddressable
.class, oObj
);
181 short iSheet
= oAddr
.getRangeAddress().Sheet
;
182 //prepare source range
184 oSheet
.getCellByPosition(4,0).setValue(111);
185 oSheet
.getCellByPosition(4,1).setValue(222);
187 CellRangeAddress sSrc
= new CellRangeAddress(iSheet
, 4, 0, 4, 1);
188 CellAddress sDest
= new CellAddress(iSheet
, 4, 4);
189 oObj
.moveRange(sDest
, sSrc
);
193 cntA
= oSheet
.getCellByPosition(4, 4).getValue();
194 cntB
= oSheet
.getCellByPosition(4, 5).getValue();
195 if (cntA
+ cntB
== 333.0){ result
= true; }
197 oSheet
.getCellByPosition(4,4).setValue(0);
198 oSheet
.getCellByPosition(4,5).setValue(0);
199 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
200 e
.printStackTrace(log
);
204 tRes
.tested("moveRange()", result
);
209 * Test sets specific values to cells in the range, deletes this cell range
210 * from document and checks values of cells in position
211 * of the deleted range.
212 * <p>Has <b>OK</b> status if sum of cell values in position of the deleted
213 * range is equal to zero and no exceptions were thrown. <p>
215 public void _removeRange(){
216 boolean result
= false;
218 XSpreadsheet oSheet
= (XSpreadsheet
)
219 UnoRuntime
.queryInterface(XSpreadsheet
.class, oObj
);
220 XCellRangeAddressable oAddr
= (XCellRangeAddressable
)
221 UnoRuntime
.queryInterface (XCellRangeAddressable
.class, oObj
);
222 short iSheet
= oAddr
.getRangeAddress().Sheet
;
224 //prepare source range
225 oSheet
.getCellByPosition(5, 0).setValue(333);
226 oSheet
.getCellByPosition(5, 1).setValue(444);
228 CellRangeAddress sSrc
= new CellRangeAddress(iSheet
, 5, 0, 5, 1);
229 oObj
.removeRange(sSrc
, CellDeleteMode
.UP
);
233 cntA
= oSheet
.getCellByPosition(5, 0).getValue();
234 cntB
= oSheet
.getCellByPosition(5, 1).getValue();
235 if (cntA
+ cntB
== 0.0){ result
= true; }
238 oSheet
.getCellByPosition(5, 0).setValue(0);
239 oSheet
.getCellByPosition(5, 1).setValue(0);
240 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
241 e
.printStackTrace(log
);
245 tRes
.tested("removeRange()", result
);
248 } // EOC _XCellRangeMovement