merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / sheet / _XCellRangeMovement.java
bloba35394c929be0d0989a3c3135cfdd7242e6b7b16
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XCellRangeMovement.java,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
31 package ifc.sheet;
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;
46 /**
47 * Testing <code>com.sun.star.sheet.XCellRangeMovement</code>
48 * interface methods :
49 * <ul>
50 * <li><code> insertCells()</code></li>
51 * <li><code> removeRange()</code></li>
52 * <li><code> moveRange()</code></li>
53 * <li><code> copyRange()</code></li>
54 * </ul> <p>
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;
65 /**
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);
75 try {
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;
89 CellAddress sDest;
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);
98 try {
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;
127 try {
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.");
141 else{
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) ;
153 // check the result
154 double res = oSheet.getCellByPosition(1, 21).getValue();
155 if (res == 0.0) {
156 result = true;
158 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
159 e.printStackTrace(log);
160 result = false;
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
183 try {
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);
191 double cntA = 0;
192 double cntB = 0;
193 cntA = oSheet.getCellByPosition(4, 4).getValue();
194 cntB = oSheet.getCellByPosition(4, 5).getValue();
195 if (cntA + cntB == 333.0){ result = true; }
196 //clean up
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);
201 result = false;
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;
223 try {
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);
231 double cntA = 0;
232 double cntB = 0;
233 cntA = oSheet.getCellByPosition(5, 0).getValue();
234 cntB = oSheet.getCellByPosition(5, 1).getValue();
235 if (cntA + cntB == 0.0){ result = true; }
237 //clean up
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);
242 result = false;
245 tRes.tested("removeRange()", result);
248 } // EOC _XCellRangeMovement