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 com
.sun
.star
.sheet
.CellDeleteMode
;
33 import com
.sun
.star
.sheet
.CellInsertMode
;
34 import com
.sun
.star
.sheet
.XCellRangeAddressable
;
35 import com
.sun
.star
.sheet
.XCellRangeMovement
;
36 import com
.sun
.star
.sheet
.XSpreadsheet
;
37 import com
.sun
.star
.table
.CellAddress
;
38 import com
.sun
.star
.table
.CellRangeAddress
;
39 import com
.sun
.star
.table
.XColumnRowRange
;
40 import com
.sun
.star
.table
.XTableRows
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
44 * Testing <code>com.sun.star.sheet.XCellRangeMovement</code>
47 * <li><code> insertCells()</code></li>
48 * <li><code> removeRange()</code></li>
49 * <li><code> moveRange()</code></li>
50 * <li><code> copyRange()</code></li>
52 * Test object must implements interfaces <code>XCellRangeAddressable</code>
53 * and <code>XSpreadsheet</code> also. <p>
54 * @see com.sun.star.sheet.XCellRangeMovement
55 * @see com.sun.star.sheet.XSpreadsheet
56 * @see com.sun.star.sheet.XCellRangeAddressable
58 public class _XCellRangeMovement
extends MultiMethodTest
{
60 public XCellRangeMovement oObj
= null;
63 * Test sets specific values to cells in the range, copies this cell range
64 * to another position in document and checks cell's values in new position.<p>
65 * Has <b> OK </b> status if cell's values in source range are equal to
66 * cell's values in destination range and no exceptions were thrown. <p>
68 public void _copyRange(){
69 log
.println("Prepare cells before test methods.");
70 XSpreadsheet oSheet
= (XSpreadsheet
)
71 UnoRuntime
.queryInterface(XSpreadsheet
.class, oObj
);
73 oSheet
.getCellByPosition(1,1).setValue(100);
74 oSheet
.getCellByPosition(1,2).setValue(200);
75 oSheet
.getCellByPosition(2,1).setValue(300);
76 oSheet
.getCellByPosition(2,2).setValue(400);
77 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
78 e
.printStackTrace(log
);
79 tRes
.tested("copyRange()", false);
82 XCellRangeAddressable oAddr
=
83 (XCellRangeAddressable
)
84 UnoRuntime
.queryInterface (XCellRangeAddressable
.class, oObj
);
85 short iSheet
= oAddr
.getRangeAddress().Sheet
;
87 CellRangeAddress sSrc
;
89 sSrc
= new CellRangeAddress(iSheet
, 1, 1, 2, 2);
90 sDest
= new CellAddress(iSheet
, 1, 10);
91 boolean result
= true;
92 boolean loc_result
= true;
94 oObj
.copyRange(sDest
, sSrc
);
96 loc_result
= (oSheet
.getCellByPosition(1, 10).getValue() == 100);
97 loc_result
&= (oSheet
.getCellByPosition(1, 11).getValue() == 200);
98 loc_result
&= (oSheet
.getCellByPosition(2, 10).getValue() == 300);
99 loc_result
&= (oSheet
.getCellByPosition(2, 11).getValue() == 400);
100 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
101 e
.printStackTrace(log
);
102 tRes
.tested("copyRange()", false);
105 result
&= loc_result
;
106 tRes
.tested("copyRange()", result
);
110 * Test sets specific values to cells in the two contiguous rows, inserts
111 * new empty row between them and checks value in
112 * one cell of the inserted row. <p>
113 * Has <b> OK </b> status if value of cell in the inserted row is zero
114 * and no exceptions were thrown. <p>
116 public void _insertCells(){
117 boolean result
= false;
119 XSpreadsheet oSheet
= (XSpreadsheet
)
120 UnoRuntime
.queryInterface(XSpreadsheet
.class, oObj
);
121 XCellRangeAddressable oAddr
= (XCellRangeAddressable
)
122 UnoRuntime
.queryInterface (XCellRangeAddressable
.class, oObj
);
123 short iSheet
= oAddr
.getRangeAddress().Sheet
;
125 oSheet
.getCellByPosition(0,20).setValue(100);
126 oSheet
.getCellByPosition(1,20).setValue(100);
127 oSheet
.getCellByPosition(2,20).setValue(100);
128 oSheet
.getCellByPosition(3,20).setValue(100);
129 oSheet
.getCellByPosition(0,21).setValue(200);
130 oSheet
.getCellByPosition(1,21).setValue(200);
131 oSheet
.getCellByPosition(2,21).setValue(200);
132 oSheet
.getCellByPosition(3,21).setValue(200);
134 // catch some sleight of hand threads
135 if (oSheet
.getCellByPosition(1,21).getValue() == 200){
136 //log.println("Rows closed.");
139 log
.println("Cells were already inserted. "+
140 "Delete old cells now");
141 XColumnRowRange oColumnRowRange
= (XColumnRowRange
)
142 UnoRuntime
.queryInterface(XColumnRowRange
.class, oSheet
);
144 XTableRows oRows
= (XTableRows
) oColumnRowRange
.getRows();
145 oRows
.removeByIndex(21,1);
147 CellRangeAddress sSrc
= new CellRangeAddress(iSheet
, 0, 21, 5, 21);
148 oObj
.insertCells (sSrc
, CellInsertMode
.DOWN
) ;
151 double res
= oSheet
.getCellByPosition(1, 21).getValue();
155 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
156 e
.printStackTrace(log
);
160 tRes
.tested("insertCells()", result
);
164 * Test sets specific values to cells in the range, moves this cell range
165 * to another position in document and checks cell's values in new position.
166 * <p>Has <b>OK</b> status if sum of values in source range is equal to sum
167 * of values in destination range and no exceptions were thrown. <p>
169 public void _moveRange(){
170 boolean result
= false;
172 XSpreadsheet oSheet
= (XSpreadsheet
)
173 UnoRuntime
.queryInterface(XSpreadsheet
.class, oObj
);
175 XCellRangeAddressable oAddr
= (XCellRangeAddressable
)
176 UnoRuntime
.queryInterface (XCellRangeAddressable
.class, oObj
);
178 short iSheet
= oAddr
.getRangeAddress().Sheet
;
179 //prepare source range
181 oSheet
.getCellByPosition(4,0).setValue(111);
182 oSheet
.getCellByPosition(4,1).setValue(222);
184 CellRangeAddress sSrc
= new CellRangeAddress(iSheet
, 4, 0, 4, 1);
185 CellAddress sDest
= new CellAddress(iSheet
, 4, 4);
186 oObj
.moveRange(sDest
, sSrc
);
190 cntA
= oSheet
.getCellByPosition(4, 4).getValue();
191 cntB
= oSheet
.getCellByPosition(4, 5).getValue();
192 if (cntA
+ cntB
== 333.0){ result
= true; }
194 oSheet
.getCellByPosition(4,4).setValue(0);
195 oSheet
.getCellByPosition(4,5).setValue(0);
196 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
197 e
.printStackTrace(log
);
201 tRes
.tested("moveRange()", result
);
206 * Test sets specific values to cells in the range, deletes this cell range
207 * from document and checks values of cells in position
208 * of the deleted range.
209 * <p>Has <b>OK</b> status if sum of cell values in position of the deleted
210 * range is equal to zero and no exceptions were thrown. <p>
212 public void _removeRange(){
213 boolean result
= false;
215 XSpreadsheet oSheet
= (XSpreadsheet
)
216 UnoRuntime
.queryInterface(XSpreadsheet
.class, oObj
);
217 XCellRangeAddressable oAddr
= (XCellRangeAddressable
)
218 UnoRuntime
.queryInterface (XCellRangeAddressable
.class, oObj
);
219 short iSheet
= oAddr
.getRangeAddress().Sheet
;
221 //prepare source range
222 oSheet
.getCellByPosition(5, 0).setValue(333);
223 oSheet
.getCellByPosition(5, 1).setValue(444);
225 CellRangeAddress sSrc
= new CellRangeAddress(iSheet
, 5, 0, 5, 1);
226 oObj
.removeRange(sSrc
, CellDeleteMode
.UP
);
230 cntA
= oSheet
.getCellByPosition(5, 0).getValue();
231 cntB
= oSheet
.getCellByPosition(5, 1).getValue();
232 if (cntA
+ cntB
== 0.0){ result
= true; }
235 oSheet
.getCellByPosition(5, 0).setValue(0);
236 oSheet
.getCellByPosition(5, 1).setValue(0);
237 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
238 e
.printStackTrace(log
);
242 tRes
.tested("removeRange()", result
);
245 } // EOC _XCellRangeMovement