bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XCellRangeMovement.java
blob3bb40649889b7cd74ec454a06572e9f935c2d752
1 /*
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 .
19 package ifc.sheet;
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;
34 /**
35 * Testing <code>com.sun.star.sheet.XCellRangeMovement</code>
36 * interface methods :
37 * <ul>
38 * <li><code> insertCells()</code></li>
39 * <li><code> removeRange()</code></li>
40 * <li><code> moveRange()</code></li>
41 * <li><code> copyRange()</code></li>
42 * </ul> <p>
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;
53 /**
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);
62 try {
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;
75 CellAddress sDest;
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);
84 try {
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);
94 result &= loc_result;
95 tRes.tested("copyRange()", result);
98 /**
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;
111 try {
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){
123 //log.println("Rows closed.");
125 else{
126 log.println("Cells were already inserted. "+
127 "Delete old cells now");
128 XColumnRowRange oColumnRowRange = UnoRuntime.queryInterface(XColumnRowRange.class, oSheet);
130 XTableRows oRows = oColumnRowRange.getRows();
131 oRows.removeByIndex(21,1);
133 CellRangeAddress sSrc = new CellRangeAddress(iSheet, 0, 21, 5, 21);
134 oObj.insertCells (sSrc, CellInsertMode.DOWN) ;
136 // check the result
137 double res = oSheet.getCellByPosition(1, 21).getValue();
138 if (res == 0.0) {
139 result = true;
141 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
142 e.printStackTrace(log);
143 result = false;
146 tRes.tested("insertCells()", result);
150 * Test sets specific values to cells in the range, moves this cell range
151 * to another position in document and checks cell's values in new position.
152 * <p>Has <b>OK</b> status if sum of values in source range is equal to sum
153 * of values in destination range and no exceptions were thrown. <p>
155 public void _moveRange(){
156 boolean result = false;
158 XSpreadsheet oSheet = UnoRuntime.queryInterface(XSpreadsheet.class, oObj);
160 XCellRangeAddressable oAddr = UnoRuntime.queryInterface (XCellRangeAddressable.class, oObj);
162 short iSheet = oAddr.getRangeAddress().Sheet;
163 //prepare source range
164 try {
165 oSheet.getCellByPosition(4,0).setValue(111);
166 oSheet.getCellByPosition(4,1).setValue(222);
168 CellRangeAddress sSrc = new CellRangeAddress(iSheet, 4, 0, 4, 1);
169 CellAddress sDest = new CellAddress(iSheet, 4, 4);
170 oObj.moveRange(sDest, sSrc);
172 double cntA = 0;
173 double cntB = 0;
174 cntA = oSheet.getCellByPosition(4, 4).getValue();
175 cntB = oSheet.getCellByPosition(4, 5).getValue();
176 if (cntA + cntB == 333.0){ result = true; }
177 //clean up
178 oSheet.getCellByPosition(4,4).setValue(0);
179 oSheet.getCellByPosition(4,5).setValue(0);
180 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
181 e.printStackTrace(log);
182 result = false;
185 tRes.tested("moveRange()", result);
190 * Test sets specific values to cells in the range, deletes this cell range
191 * from document and checks values of cells in position
192 * of the deleted range.
193 * <p>Has <b>OK</b> status if sum of cell values in position of the deleted
194 * range is equal to zero and no exceptions were thrown. <p>
196 public void _removeRange(){
197 boolean result = false;
199 XSpreadsheet oSheet = UnoRuntime.queryInterface(XSpreadsheet.class, oObj);
200 XCellRangeAddressable oAddr = UnoRuntime.queryInterface (XCellRangeAddressable.class, oObj);
201 short iSheet = oAddr.getRangeAddress().Sheet;
202 try {
203 //prepare source range
204 oSheet.getCellByPosition(5, 0).setValue(333);
205 oSheet.getCellByPosition(5, 1).setValue(444);
207 CellRangeAddress sSrc = new CellRangeAddress(iSheet, 5, 0, 5, 1);
208 oObj.removeRange(sSrc, CellDeleteMode.UP);
210 double cntA = 0;
211 double cntB = 0;
212 cntA = oSheet.getCellByPosition(5, 0).getValue();
213 cntB = oSheet.getCellByPosition(5, 1).getValue();
214 if (cntA + cntB == 0.0){ result = true; }
216 //clean up
217 oSheet.getCellByPosition(5, 0).setValue(0);
218 oSheet.getCellByPosition(5, 1).setValue(0);
219 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
220 e.printStackTrace(log);
221 result = false;
224 tRes.tested("removeRange()", result);
227 } // EOC _XCellRangeMovement