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 com
.sun
.star
.sheet
.CellDeleteMode
;
24 import com
.sun
.star
.sheet
.CellInsertMode
;
25 import com
.sun
.star
.sheet
.XCellRangeAddressable
;
26 import com
.sun
.star
.sheet
.XCellRangeMovement
;
27 import com
.sun
.star
.sheet
.XSpreadsheet
;
28 import com
.sun
.star
.table
.CellAddress
;
29 import com
.sun
.star
.table
.CellRangeAddress
;
30 import com
.sun
.star
.table
.XColumnRowRange
;
31 import com
.sun
.star
.table
.XTableRows
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
35 * Testing <code>com.sun.star.sheet.XCellRangeMovement</code>
38 * <li><code> insertCells()</code></li>
39 * <li><code> removeRange()</code></li>
40 * <li><code> moveRange()</code></li>
41 * <li><code> copyRange()</code></li>
43 * Test object must implements interfaces <code>XCellRangeAddressable</code>
44 * and <code>XSpreadsheet</code> also. <p>
45 * @see com.sun.star.sheet.XCellRangeMovement
46 * @see com.sun.star.sheet.XSpreadsheet
47 * @see com.sun.star.sheet.XCellRangeAddressable
49 public class _XCellRangeMovement
extends MultiMethodTest
{
51 public XCellRangeMovement oObj
= null;
54 * Test sets specific values to cells in the range, copies this cell range
55 * to another position in document and checks cell's values in new position.<p>
56 * Has <b> OK </b> status if cell's values in source range are equal to
57 * cell's values in destination range and no exceptions were thrown. <p>
59 public void _copyRange(){
60 log
.println("Prepare cells before test methods.");
61 XSpreadsheet oSheet
= UnoRuntime
.queryInterface(XSpreadsheet
.class, oObj
);
63 oSheet
.getCellByPosition(1,1).setValue(100);
64 oSheet
.getCellByPosition(1,2).setValue(200);
65 oSheet
.getCellByPosition(2,1).setValue(300);
66 oSheet
.getCellByPosition(2,2).setValue(400);
67 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
68 e
.printStackTrace(log
);
69 tRes
.tested("copyRange()", false);
72 XCellRangeAddressable oAddr
=
73 UnoRuntime
.queryInterface (XCellRangeAddressable
.class, oObj
);
74 short iSheet
= oAddr
.getRangeAddress().Sheet
;
76 CellRangeAddress sSrc
;
78 sSrc
= new CellRangeAddress(iSheet
, 1, 1, 2, 2);
79 sDest
= new CellAddress(iSheet
, 1, 10);
80 boolean result
= true;
81 boolean loc_result
= true;
83 oObj
.copyRange(sDest
, sSrc
);
85 loc_result
= (oSheet
.getCellByPosition(1, 10).getValue() == 100);
86 loc_result
&= (oSheet
.getCellByPosition(1, 11).getValue() == 200);
87 loc_result
&= (oSheet
.getCellByPosition(2, 10).getValue() == 300);
88 loc_result
&= (oSheet
.getCellByPosition(2, 11).getValue() == 400);
89 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
90 e
.printStackTrace(log
);
91 tRes
.tested("copyRange()", false);
95 tRes
.tested("copyRange()", result
);
99 * Test sets specific values to cells in the two contiguous rows, inserts
100 * new empty row between them and checks value in
101 * one cell of the inserted row. <p>
102 * Has <b> OK </b> status if value of cell in the inserted row is zero
103 * and no exceptions were thrown. <p>
105 public void _insertCells(){
106 boolean result
= false;
108 XSpreadsheet oSheet
= UnoRuntime
.queryInterface(XSpreadsheet
.class, oObj
);
109 XCellRangeAddressable oAddr
= UnoRuntime
.queryInterface (XCellRangeAddressable
.class, oObj
);
110 short iSheet
= oAddr
.getRangeAddress().Sheet
;
112 oSheet
.getCellByPosition(0,20).setValue(100);
113 oSheet
.getCellByPosition(1,20).setValue(100);
114 oSheet
.getCellByPosition(2,20).setValue(100);
115 oSheet
.getCellByPosition(3,20).setValue(100);
116 oSheet
.getCellByPosition(0,21).setValue(200);
117 oSheet
.getCellByPosition(1,21).setValue(200);
118 oSheet
.getCellByPosition(2,21).setValue(200);
119 oSheet
.getCellByPosition(3,21).setValue(200);
121 // catch some sleight of hand threads
122 if (oSheet
.getCellByPosition(1,21).getValue() == 200){
125 log
.println("Cells were already inserted. "+
126 "Delete old cells now");
127 XColumnRowRange oColumnRowRange
= UnoRuntime
.queryInterface(XColumnRowRange
.class, oSheet
);
129 XTableRows oRows
= oColumnRowRange
.getRows();
130 oRows
.removeByIndex(21,1);
132 CellRangeAddress sSrc
= new CellRangeAddress(iSheet
, 0, 21, 5, 21);
133 oObj
.insertCells (sSrc
, CellInsertMode
.DOWN
) ;
136 double res
= oSheet
.getCellByPosition(1, 21).getValue();
140 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
141 e
.printStackTrace(log
);
145 tRes
.tested("insertCells()", result
);
149 * Test sets specific values to cells in the range, moves this cell range
150 * to another position in document and checks cell's values in new position.
151 * <p>Has <b>OK</b> status if sum of values in source range is equal to sum
152 * of values in destination range and no exceptions were thrown. <p>
154 public void _moveRange(){
155 boolean result
= false;
157 XSpreadsheet oSheet
= UnoRuntime
.queryInterface(XSpreadsheet
.class, oObj
);
159 XCellRangeAddressable oAddr
= UnoRuntime
.queryInterface (XCellRangeAddressable
.class, oObj
);
161 short iSheet
= oAddr
.getRangeAddress().Sheet
;
162 //prepare source range
164 oSheet
.getCellByPosition(4,0).setValue(111);
165 oSheet
.getCellByPosition(4,1).setValue(222);
167 CellRangeAddress sSrc
= new CellRangeAddress(iSheet
, 4, 0, 4, 1);
168 CellAddress sDest
= new CellAddress(iSheet
, 4, 4);
169 oObj
.moveRange(sDest
, sSrc
);
173 cntA
= oSheet
.getCellByPosition(4, 4).getValue();
174 cntB
= oSheet
.getCellByPosition(4, 5).getValue();
175 if (cntA
+ cntB
== 333.0){ result
= true; }
177 oSheet
.getCellByPosition(4,4).setValue(0);
178 oSheet
.getCellByPosition(4,5).setValue(0);
179 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
180 e
.printStackTrace(log
);
184 tRes
.tested("moveRange()", result
);
189 * Test sets specific values to cells in the range, deletes this cell range
190 * from document and checks values of cells in position
191 * of the deleted range.
192 * <p>Has <b>OK</b> status if sum of cell values in position of the deleted
193 * range is equal to zero and no exceptions were thrown. <p>
195 public void _removeRange(){
196 boolean result
= false;
198 XSpreadsheet oSheet
= UnoRuntime
.queryInterface(XSpreadsheet
.class, oObj
);
199 XCellRangeAddressable oAddr
= UnoRuntime
.queryInterface (XCellRangeAddressable
.class, oObj
);
200 short iSheet
= oAddr
.getRangeAddress().Sheet
;
202 //prepare source range
203 oSheet
.getCellByPosition(5, 0).setValue(333);
204 oSheet
.getCellByPosition(5, 1).setValue(444);
206 CellRangeAddress sSrc
= new CellRangeAddress(iSheet
, 5, 0, 5, 1);
207 oObj
.removeRange(sSrc
, CellDeleteMode
.UP
);
211 cntA
= oSheet
.getCellByPosition(5, 0).getValue();
212 cntB
= oSheet
.getCellByPosition(5, 1).getValue();
213 if (cntA
+ cntB
== 0.0){ result
= true; }
216 oSheet
.getCellByPosition(5, 0).setValue(0);
217 oSheet
.getCellByPosition(5, 1).setValue(0);
218 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
219 e
.printStackTrace(log
);
223 tRes
.tested("removeRange()", result
);
226 } // EOC _XCellRangeMovement