1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir package ifc.sheet; 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir import com.sun.star.awt.Point; 30*cdf0e10cSrcweir import com.sun.star.sheet.TableOperationMode; 31*cdf0e10cSrcweir import com.sun.star.sheet.XCellAddressable; 32*cdf0e10cSrcweir import com.sun.star.sheet.XCellRangeAddressable; 33*cdf0e10cSrcweir import com.sun.star.sheet.XMultipleOperation; 34*cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheet; 35*cdf0e10cSrcweir import com.sun.star.table.XCell; 36*cdf0e10cSrcweir import com.sun.star.table.XCellRange; 37*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir import lib.MultiMethodTest; 40*cdf0e10cSrcweir import lib.Status; 41*cdf0e10cSrcweir import lib.StatusException; 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir public class _XMultipleOperation extends MultiMethodTest { 45*cdf0e10cSrcweir public XMultipleOperation oObj = null; 46*cdf0e10cSrcweir protected XSpreadsheet oSheet = null; 47*cdf0e10cSrcweir boolean both = true; 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir protected void before() { 50*cdf0e10cSrcweir oSheet = (XSpreadsheet) tEnv.getObjRelation("SHEET"); 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir if (oSheet == null) { 53*cdf0e10cSrcweir throw new StatusException(Status.failed( 54*cdf0e10cSrcweir "Object relation oSheet is missing")); 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir if (UnoRuntime.queryInterface(XSpreadsheet.class, tEnv.getTestObject()) != null) { 58*cdf0e10cSrcweir log.println("We have a sheet and won't do TableOperationMode.BOTH"); 59*cdf0e10cSrcweir both = false; 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir } 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir public void _setTableOperation() { 64*cdf0e10cSrcweir boolean res = true; 65*cdf0e10cSrcweir XCellRange cellRange = oSheet.getCellRangeByName("$A$17:$A$17"); 66*cdf0e10cSrcweir XCellRangeAddressable CRA = (XCellRangeAddressable) UnoRuntime.queryInterface( 67*cdf0e10cSrcweir XCellRangeAddressable.class, 68*cdf0e10cSrcweir cellRange); 69*cdf0e10cSrcweir XCell cell = null; 70*cdf0e10cSrcweir XCell cell2 = null; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir try { 73*cdf0e10cSrcweir cell = oSheet.getCellByPosition(0, 16); 74*cdf0e10cSrcweir cell.setFormula("=a15+a16"); 75*cdf0e10cSrcweir cell = oSheet.getCellByPosition(0, 14); 76*cdf0e10cSrcweir cell2 = oSheet.getCellByPosition(0, 15); 77*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 78*cdf0e10cSrcweir log.println("Exception while getting Cell " + e.getMessage()); 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir XCellAddressable CA = (XCellAddressable) UnoRuntime.queryInterface( 82*cdf0e10cSrcweir XCellAddressable.class, cell); 83*cdf0e10cSrcweir XCellAddressable CA2 = (XCellAddressable) UnoRuntime.queryInterface( 84*cdf0e10cSrcweir XCellAddressable.class, cell2); 85*cdf0e10cSrcweir Point[] cellCoords = new Point[3]; 86*cdf0e10cSrcweir double[] cellValues = new double[3]; 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir log.println("filling cells"); 89*cdf0e10cSrcweir fillCells(); 90*cdf0e10cSrcweir log.println("setting TableOperation with parameter ROW"); 91*cdf0e10cSrcweir oObj.setTableOperation(CRA.getRangeAddress(), TableOperationMode.ROW, 92*cdf0e10cSrcweir CA.getCellAddress(), CA2.getCellAddress()); 93*cdf0e10cSrcweir log.println("checking values"); 94*cdf0e10cSrcweir cellCoords = new Point[] { 95*cdf0e10cSrcweir new Point(1, 1), new Point(2, 1), new Point(3, 1) 96*cdf0e10cSrcweir }; 97*cdf0e10cSrcweir cellValues = new double[] { 5, 10, 15 }; 98*cdf0e10cSrcweir res &= checkValues(cellCoords, cellValues); 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir log.println("filling cells"); 101*cdf0e10cSrcweir fillCells(); 102*cdf0e10cSrcweir log.println("setting TableOperation with parameter COLUMN"); 103*cdf0e10cSrcweir oObj.setTableOperation(CRA.getRangeAddress(), 104*cdf0e10cSrcweir TableOperationMode.COLUMN, CA.getCellAddress(), 105*cdf0e10cSrcweir CA2.getCellAddress()); 106*cdf0e10cSrcweir log.println("checking values"); 107*cdf0e10cSrcweir cellCoords = new Point[] { 108*cdf0e10cSrcweir new Point(1, 1), new Point(1, 2), new Point(1, 3) 109*cdf0e10cSrcweir }; 110*cdf0e10cSrcweir cellValues = new double[] { 12, 24, 36 }; 111*cdf0e10cSrcweir res &= checkValues(cellCoords, cellValues); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir if (both) { 114*cdf0e10cSrcweir log.println("filling cells"); 115*cdf0e10cSrcweir fillCells(); 116*cdf0e10cSrcweir log.println("setting TableOperation with parameter BOTH"); 117*cdf0e10cSrcweir oObj.setTableOperation(CRA.getRangeAddress(), 118*cdf0e10cSrcweir TableOperationMode.BOTH, 119*cdf0e10cSrcweir CA.getCellAddress(), CA2.getCellAddress()); 120*cdf0e10cSrcweir log.println("checking values"); 121*cdf0e10cSrcweir cellCoords = new Point[] { 122*cdf0e10cSrcweir new Point(1, 1), new Point(2, 2), new Point(3, 3) 123*cdf0e10cSrcweir }; 124*cdf0e10cSrcweir cellValues = new double[] { 17, 34, 51 }; 125*cdf0e10cSrcweir res &= checkValues(cellCoords, cellValues); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir tRes.tested("setTableOperation()", res); 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir protected void fillCells() { 132*cdf0e10cSrcweir XCell cell = null; 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir try { 135*cdf0e10cSrcweir for (int k = 1; k < 5; k++) { 136*cdf0e10cSrcweir cell = oSheet.getCellByPosition(0, k); 137*cdf0e10cSrcweir cell.setValue(k * 12); 138*cdf0e10cSrcweir cell = oSheet.getCellByPosition(k, 0); 139*cdf0e10cSrcweir cell.setValue(k * 5); 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 142*cdf0e10cSrcweir log.println("Exception while filling Cells " + e.getMessage()); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir protected boolean checkValues(Point[] cellCoords, double[] cellValues) { 147*cdf0e10cSrcweir boolean res = true; 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir for (int i = 0; i < cellValues.length; i++) { 150*cdf0e10cSrcweir try { 151*cdf0e10cSrcweir boolean locres = oSheet.getCellByPosition(cellCoords[i].X, 152*cdf0e10cSrcweir cellCoords[i].Y) 153*cdf0e10cSrcweir .getValue() == cellValues[i]; 154*cdf0e10cSrcweir res &= locres; 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir if (!locres) { 157*cdf0e10cSrcweir log.println("Result differs for cell (" + 158*cdf0e10cSrcweir cellCoords[i].X + "," + cellCoords[i].Y + 159*cdf0e10cSrcweir ")"); 160*cdf0e10cSrcweir log.println("Expected: " + cellValues[i]); 161*cdf0e10cSrcweir log.println("Getting: " + 162*cdf0e10cSrcweir oSheet.getCellByPosition(cellCoords[i].X, 163*cdf0e10cSrcweir cellCoords[i].Y) 164*cdf0e10cSrcweir .getValue()); 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 167*cdf0e10cSrcweir log.println("Exception while checking Values " + 168*cdf0e10cSrcweir e.getMessage()); 169*cdf0e10cSrcweir res &= false; 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir return res; 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir /** 177*cdf0e10cSrcweir * Restores initial component text. 178*cdf0e10cSrcweir */ 179*cdf0e10cSrcweir protected void after() { 180*cdf0e10cSrcweir disposeEnvironment(); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir }