1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski 22*b1cdbd2cSJim Jagielski 23*b1cdbd2cSJim Jagielski 24*b1cdbd2cSJim Jagielski package ifc.sheet; 25*b1cdbd2cSJim Jagielski 26*b1cdbd2cSJim Jagielski import lib.MultiMethodTest; 27*b1cdbd2cSJim Jagielski 28*b1cdbd2cSJim Jagielski import com.sun.star.sheet.CellDeleteMode; 29*b1cdbd2cSJim Jagielski import com.sun.star.sheet.CellInsertMode; 30*b1cdbd2cSJim Jagielski import com.sun.star.sheet.XCellRangeAddressable; 31*b1cdbd2cSJim Jagielski import com.sun.star.sheet.XCellRangeMovement; 32*b1cdbd2cSJim Jagielski import com.sun.star.sheet.XSpreadsheet; 33*b1cdbd2cSJim Jagielski import com.sun.star.table.CellAddress; 34*b1cdbd2cSJim Jagielski import com.sun.star.table.CellRangeAddress; 35*b1cdbd2cSJim Jagielski import com.sun.star.table.XColumnRowRange; 36*b1cdbd2cSJim Jagielski import com.sun.star.table.XTableRows; 37*b1cdbd2cSJim Jagielski import com.sun.star.uno.UnoRuntime; 38*b1cdbd2cSJim Jagielski 39*b1cdbd2cSJim Jagielski /** 40*b1cdbd2cSJim Jagielski * Testing <code>com.sun.star.sheet.XCellRangeMovement</code> 41*b1cdbd2cSJim Jagielski * interface methods : 42*b1cdbd2cSJim Jagielski * <ul> 43*b1cdbd2cSJim Jagielski * <li><code> insertCells()</code></li> 44*b1cdbd2cSJim Jagielski * <li><code> removeRange()</code></li> 45*b1cdbd2cSJim Jagielski * <li><code> moveRange()</code></li> 46*b1cdbd2cSJim Jagielski * <li><code> copyRange()</code></li> 47*b1cdbd2cSJim Jagielski * </ul> <p> 48*b1cdbd2cSJim Jagielski * Test object must implements interfaces <code>XCellRangeAddressable</code> 49*b1cdbd2cSJim Jagielski * and <code>XSpreadsheet</code> also. <p> 50*b1cdbd2cSJim Jagielski * @see com.sun.star.sheet.XCellRangeMovement 51*b1cdbd2cSJim Jagielski * @see com.sun.star.sheet.XSpreadsheet 52*b1cdbd2cSJim Jagielski * @see com.sun.star.sheet.XCellRangeAddressable 53*b1cdbd2cSJim Jagielski */ 54*b1cdbd2cSJim Jagielski public class _XCellRangeMovement extends MultiMethodTest { 55*b1cdbd2cSJim Jagielski 56*b1cdbd2cSJim Jagielski public XCellRangeMovement oObj = null; 57*b1cdbd2cSJim Jagielski 58*b1cdbd2cSJim Jagielski /** 59*b1cdbd2cSJim Jagielski * Test sets specific values to cells in the range, copies this cell range 60*b1cdbd2cSJim Jagielski * to another position in document and checks cell's values in new position.<p> 61*b1cdbd2cSJim Jagielski * Has <b> OK </b> status if cell's values in source range are equal to 62*b1cdbd2cSJim Jagielski * cell's values in destination range and no exceptions were thrown. <p> 63*b1cdbd2cSJim Jagielski */ _copyRange()64*b1cdbd2cSJim Jagielski public void _copyRange(){ 65*b1cdbd2cSJim Jagielski log.println("Prepare cells before test methods."); 66*b1cdbd2cSJim Jagielski XSpreadsheet oSheet = (XSpreadsheet) 67*b1cdbd2cSJim Jagielski UnoRuntime.queryInterface(XSpreadsheet.class, oObj); 68*b1cdbd2cSJim Jagielski try { 69*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(1,1).setValue(100); 70*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(1,2).setValue(200); 71*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(2,1).setValue(300); 72*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(2,2).setValue(400); 73*b1cdbd2cSJim Jagielski } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 74*b1cdbd2cSJim Jagielski e.printStackTrace(log); 75*b1cdbd2cSJim Jagielski tRes.tested("copyRange()", false); 76*b1cdbd2cSJim Jagielski } 77*b1cdbd2cSJim Jagielski 78*b1cdbd2cSJim Jagielski XCellRangeAddressable oAddr = 79*b1cdbd2cSJim Jagielski (XCellRangeAddressable) 80*b1cdbd2cSJim Jagielski UnoRuntime.queryInterface (XCellRangeAddressable.class, oObj); 81*b1cdbd2cSJim Jagielski short iSheet = oAddr.getRangeAddress().Sheet; 82*b1cdbd2cSJim Jagielski CellAddress sDest; 83*b1cdbd2cSJim Jagielski CellRangeAddress sSrc; 84*b1cdbd2cSJim Jagielski 85*b1cdbd2cSJim Jagielski sSrc = new CellRangeAddress(iSheet, 1, 1, 2, 2); 86*b1cdbd2cSJim Jagielski sDest = new CellAddress(iSheet, 1, 10); 87*b1cdbd2cSJim Jagielski boolean result = true; 88*b1cdbd2cSJim Jagielski boolean loc_result = true; 89*b1cdbd2cSJim Jagielski 90*b1cdbd2cSJim Jagielski oObj.copyRange(sDest, sSrc); 91*b1cdbd2cSJim Jagielski try { 92*b1cdbd2cSJim Jagielski loc_result = (oSheet.getCellByPosition(1, 10).getValue() == 100); 93*b1cdbd2cSJim Jagielski loc_result &= (oSheet.getCellByPosition(1, 11).getValue() == 200); 94*b1cdbd2cSJim Jagielski loc_result &= (oSheet.getCellByPosition(2, 10).getValue() == 300); 95*b1cdbd2cSJim Jagielski loc_result &= (oSheet.getCellByPosition(2, 11).getValue() == 400); 96*b1cdbd2cSJim Jagielski } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 97*b1cdbd2cSJim Jagielski e.printStackTrace(log); 98*b1cdbd2cSJim Jagielski tRes.tested("copyRange()", false); 99*b1cdbd2cSJim Jagielski } 100*b1cdbd2cSJim Jagielski 101*b1cdbd2cSJim Jagielski result &= loc_result; 102*b1cdbd2cSJim Jagielski tRes.tested("copyRange()", result); 103*b1cdbd2cSJim Jagielski } 104*b1cdbd2cSJim Jagielski 105*b1cdbd2cSJim Jagielski /** 106*b1cdbd2cSJim Jagielski * Test sets specific values to cells in the two contiguous rows, inserts 107*b1cdbd2cSJim Jagielski * new empty row between them and checks value in 108*b1cdbd2cSJim Jagielski * one cell of the inserted row. <p> 109*b1cdbd2cSJim Jagielski * Has <b> OK </b> status if value of cell in the inserted row is zero 110*b1cdbd2cSJim Jagielski * and no exceptions were thrown. <p> 111*b1cdbd2cSJim Jagielski */ _insertCells()112*b1cdbd2cSJim Jagielski public void _insertCells(){ 113*b1cdbd2cSJim Jagielski boolean result = false; 114*b1cdbd2cSJim Jagielski 115*b1cdbd2cSJim Jagielski XSpreadsheet oSheet = (XSpreadsheet) 116*b1cdbd2cSJim Jagielski UnoRuntime.queryInterface(XSpreadsheet.class, oObj); 117*b1cdbd2cSJim Jagielski XCellRangeAddressable oAddr = (XCellRangeAddressable) 118*b1cdbd2cSJim Jagielski UnoRuntime.queryInterface (XCellRangeAddressable.class, oObj); 119*b1cdbd2cSJim Jagielski short iSheet = oAddr.getRangeAddress().Sheet; 120*b1cdbd2cSJim Jagielski try { 121*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(0,20).setValue(100); 122*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(1,20).setValue(100); 123*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(2,20).setValue(100); 124*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(3,20).setValue(100); 125*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(0,21).setValue(200); 126*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(1,21).setValue(200); 127*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(2,21).setValue(200); 128*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(3,21).setValue(200); 129*b1cdbd2cSJim Jagielski 130*b1cdbd2cSJim Jagielski // catch some sleight of hand threads 131*b1cdbd2cSJim Jagielski if (oSheet.getCellByPosition(1,21).getValue() == 200){ 132*b1cdbd2cSJim Jagielski //log.println("Rows closed."); 133*b1cdbd2cSJim Jagielski } 134*b1cdbd2cSJim Jagielski else{ 135*b1cdbd2cSJim Jagielski log.println("Cells were already inserted. "+ 136*b1cdbd2cSJim Jagielski "Delete old cells now"); 137*b1cdbd2cSJim Jagielski XColumnRowRange oColumnRowRange = (XColumnRowRange) 138*b1cdbd2cSJim Jagielski UnoRuntime.queryInterface(XColumnRowRange.class, oSheet); 139*b1cdbd2cSJim Jagielski 140*b1cdbd2cSJim Jagielski XTableRows oRows = (XTableRows) oColumnRowRange.getRows(); 141*b1cdbd2cSJim Jagielski oRows.removeByIndex(21,1); 142*b1cdbd2cSJim Jagielski } 143*b1cdbd2cSJim Jagielski CellRangeAddress sSrc = new CellRangeAddress(iSheet, 0, 21, 5, 21); 144*b1cdbd2cSJim Jagielski oObj.insertCells (sSrc, CellInsertMode.DOWN) ; 145*b1cdbd2cSJim Jagielski 146*b1cdbd2cSJim Jagielski // check the result 147*b1cdbd2cSJim Jagielski double res = oSheet.getCellByPosition(1, 21).getValue(); 148*b1cdbd2cSJim Jagielski if (res == 0.0) { 149*b1cdbd2cSJim Jagielski result = true; 150*b1cdbd2cSJim Jagielski } 151*b1cdbd2cSJim Jagielski } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 152*b1cdbd2cSJim Jagielski e.printStackTrace(log); 153*b1cdbd2cSJim Jagielski result = false; 154*b1cdbd2cSJim Jagielski } 155*b1cdbd2cSJim Jagielski 156*b1cdbd2cSJim Jagielski tRes.tested("insertCells()", result); 157*b1cdbd2cSJim Jagielski } 158*b1cdbd2cSJim Jagielski 159*b1cdbd2cSJim Jagielski /** 160*b1cdbd2cSJim Jagielski * Test sets specific values to cells in the range, moves this cell range 161*b1cdbd2cSJim Jagielski * to another position in document and checks cell's values in new position. 162*b1cdbd2cSJim Jagielski * <p>Has <b>OK</b> status if sum of values in source range is equal to sum 163*b1cdbd2cSJim Jagielski * of values in destination range and no exceptions were thrown. <p> 164*b1cdbd2cSJim Jagielski */ _moveRange()165*b1cdbd2cSJim Jagielski public void _moveRange(){ 166*b1cdbd2cSJim Jagielski boolean result = false; 167*b1cdbd2cSJim Jagielski 168*b1cdbd2cSJim Jagielski XSpreadsheet oSheet = (XSpreadsheet) 169*b1cdbd2cSJim Jagielski UnoRuntime.queryInterface(XSpreadsheet.class, oObj); 170*b1cdbd2cSJim Jagielski 171*b1cdbd2cSJim Jagielski XCellRangeAddressable oAddr = (XCellRangeAddressable) 172*b1cdbd2cSJim Jagielski UnoRuntime.queryInterface (XCellRangeAddressable.class, oObj); 173*b1cdbd2cSJim Jagielski 174*b1cdbd2cSJim Jagielski short iSheet = oAddr.getRangeAddress().Sheet; 175*b1cdbd2cSJim Jagielski //prepare source range 176*b1cdbd2cSJim Jagielski try { 177*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(4,0).setValue(111); 178*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(4,1).setValue(222); 179*b1cdbd2cSJim Jagielski 180*b1cdbd2cSJim Jagielski CellRangeAddress sSrc = new CellRangeAddress(iSheet, 4, 0, 4, 1); 181*b1cdbd2cSJim Jagielski CellAddress sDest = new CellAddress(iSheet, 4, 4); 182*b1cdbd2cSJim Jagielski oObj.moveRange(sDest, sSrc); 183*b1cdbd2cSJim Jagielski 184*b1cdbd2cSJim Jagielski double cntA = 0; 185*b1cdbd2cSJim Jagielski double cntB = 0; 186*b1cdbd2cSJim Jagielski cntA = oSheet.getCellByPosition(4, 4).getValue(); 187*b1cdbd2cSJim Jagielski cntB = oSheet.getCellByPosition(4, 5).getValue(); 188*b1cdbd2cSJim Jagielski if (cntA + cntB == 333.0){ result = true; } 189*b1cdbd2cSJim Jagielski //clean up 190*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(4,4).setValue(0); 191*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(4,5).setValue(0); 192*b1cdbd2cSJim Jagielski } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 193*b1cdbd2cSJim Jagielski e.printStackTrace(log); 194*b1cdbd2cSJim Jagielski result = false; 195*b1cdbd2cSJim Jagielski } 196*b1cdbd2cSJim Jagielski 197*b1cdbd2cSJim Jagielski tRes.tested("moveRange()", result); 198*b1cdbd2cSJim Jagielski } 199*b1cdbd2cSJim Jagielski 200*b1cdbd2cSJim Jagielski 201*b1cdbd2cSJim Jagielski /** 202*b1cdbd2cSJim Jagielski * Test sets specific values to cells in the range, deletes this cell range 203*b1cdbd2cSJim Jagielski * from document and checks values of cells in position 204*b1cdbd2cSJim Jagielski * of the deleted range. 205*b1cdbd2cSJim Jagielski * <p>Has <b>OK</b> status if sum of cell values in position of the deleted 206*b1cdbd2cSJim Jagielski * range is equal to zero and no exceptions were thrown. <p> 207*b1cdbd2cSJim Jagielski */ _removeRange()208*b1cdbd2cSJim Jagielski public void _removeRange(){ 209*b1cdbd2cSJim Jagielski boolean result = false; 210*b1cdbd2cSJim Jagielski 211*b1cdbd2cSJim Jagielski XSpreadsheet oSheet = (XSpreadsheet) 212*b1cdbd2cSJim Jagielski UnoRuntime.queryInterface(XSpreadsheet.class, oObj); 213*b1cdbd2cSJim Jagielski XCellRangeAddressable oAddr = (XCellRangeAddressable) 214*b1cdbd2cSJim Jagielski UnoRuntime.queryInterface (XCellRangeAddressable.class, oObj); 215*b1cdbd2cSJim Jagielski short iSheet = oAddr.getRangeAddress().Sheet; 216*b1cdbd2cSJim Jagielski try { 217*b1cdbd2cSJim Jagielski //prepare source range 218*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(5, 0).setValue(333); 219*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(5, 1).setValue(444); 220*b1cdbd2cSJim Jagielski 221*b1cdbd2cSJim Jagielski CellRangeAddress sSrc = new CellRangeAddress(iSheet, 5, 0, 5, 1); 222*b1cdbd2cSJim Jagielski oObj.removeRange(sSrc, CellDeleteMode.UP); 223*b1cdbd2cSJim Jagielski 224*b1cdbd2cSJim Jagielski double cntA = 0; 225*b1cdbd2cSJim Jagielski double cntB = 0; 226*b1cdbd2cSJim Jagielski cntA = oSheet.getCellByPosition(5, 0).getValue(); 227*b1cdbd2cSJim Jagielski cntB = oSheet.getCellByPosition(5, 1).getValue(); 228*b1cdbd2cSJim Jagielski if (cntA + cntB == 0.0){ result = true; } 229*b1cdbd2cSJim Jagielski 230*b1cdbd2cSJim Jagielski //clean up 231*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(5, 0).setValue(0); 232*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(5, 1).setValue(0); 233*b1cdbd2cSJim Jagielski } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 234*b1cdbd2cSJim Jagielski e.printStackTrace(log); 235*b1cdbd2cSJim Jagielski result = false; 236*b1cdbd2cSJim Jagielski } 237*b1cdbd2cSJim Jagielski 238*b1cdbd2cSJim Jagielski tRes.tested("removeRange()", result); 239*b1cdbd2cSJim Jagielski } 240*b1cdbd2cSJim Jagielski 241*b1cdbd2cSJim Jagielski } // EOC _XCellRangeMovement 242*b1cdbd2cSJim Jagielski 243