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 package ifc.sheet; 24*b1cdbd2cSJim Jagielski 25*b1cdbd2cSJim Jagielski import com.sun.star.awt.Point; 26*b1cdbd2cSJim Jagielski import com.sun.star.sheet.TableOperationMode; 27*b1cdbd2cSJim Jagielski import com.sun.star.sheet.XCellAddressable; 28*b1cdbd2cSJim Jagielski import com.sun.star.sheet.XCellRangeAddressable; 29*b1cdbd2cSJim Jagielski import com.sun.star.sheet.XMultipleOperation; 30*b1cdbd2cSJim Jagielski import com.sun.star.sheet.XSpreadsheet; 31*b1cdbd2cSJim Jagielski import com.sun.star.table.XCell; 32*b1cdbd2cSJim Jagielski import com.sun.star.table.XCellRange; 33*b1cdbd2cSJim Jagielski import com.sun.star.uno.UnoRuntime; 34*b1cdbd2cSJim Jagielski 35*b1cdbd2cSJim Jagielski import lib.MultiMethodTest; 36*b1cdbd2cSJim Jagielski import lib.Status; 37*b1cdbd2cSJim Jagielski import lib.StatusException; 38*b1cdbd2cSJim Jagielski 39*b1cdbd2cSJim Jagielski 40*b1cdbd2cSJim Jagielski public class _XMultipleOperation extends MultiMethodTest { 41*b1cdbd2cSJim Jagielski public XMultipleOperation oObj = null; 42*b1cdbd2cSJim Jagielski protected XSpreadsheet oSheet = null; 43*b1cdbd2cSJim Jagielski boolean both = true; 44*b1cdbd2cSJim Jagielski before()45*b1cdbd2cSJim Jagielski protected void before() { 46*b1cdbd2cSJim Jagielski oSheet = (XSpreadsheet) tEnv.getObjRelation("SHEET"); 47*b1cdbd2cSJim Jagielski 48*b1cdbd2cSJim Jagielski if (oSheet == null) { 49*b1cdbd2cSJim Jagielski throw new StatusException(Status.failed( 50*b1cdbd2cSJim Jagielski "Object relation oSheet is missing")); 51*b1cdbd2cSJim Jagielski } 52*b1cdbd2cSJim Jagielski 53*b1cdbd2cSJim Jagielski if (UnoRuntime.queryInterface(XSpreadsheet.class, tEnv.getTestObject()) != null) { 54*b1cdbd2cSJim Jagielski log.println("We have a sheet and won't do TableOperationMode.BOTH"); 55*b1cdbd2cSJim Jagielski both = false; 56*b1cdbd2cSJim Jagielski } 57*b1cdbd2cSJim Jagielski } 58*b1cdbd2cSJim Jagielski _setTableOperation()59*b1cdbd2cSJim Jagielski public void _setTableOperation() { 60*b1cdbd2cSJim Jagielski boolean res = true; 61*b1cdbd2cSJim Jagielski XCellRange cellRange = oSheet.getCellRangeByName("$A$17:$A$17"); 62*b1cdbd2cSJim Jagielski XCellRangeAddressable CRA = (XCellRangeAddressable) UnoRuntime.queryInterface( 63*b1cdbd2cSJim Jagielski XCellRangeAddressable.class, 64*b1cdbd2cSJim Jagielski cellRange); 65*b1cdbd2cSJim Jagielski XCell cell = null; 66*b1cdbd2cSJim Jagielski XCell cell2 = null; 67*b1cdbd2cSJim Jagielski 68*b1cdbd2cSJim Jagielski try { 69*b1cdbd2cSJim Jagielski cell = oSheet.getCellByPosition(0, 16); 70*b1cdbd2cSJim Jagielski cell.setFormula("=a15+a16"); 71*b1cdbd2cSJim Jagielski cell = oSheet.getCellByPosition(0, 14); 72*b1cdbd2cSJim Jagielski cell2 = oSheet.getCellByPosition(0, 15); 73*b1cdbd2cSJim Jagielski } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 74*b1cdbd2cSJim Jagielski log.println("Exception while getting Cell " + e.getMessage()); 75*b1cdbd2cSJim Jagielski } 76*b1cdbd2cSJim Jagielski 77*b1cdbd2cSJim Jagielski XCellAddressable CA = (XCellAddressable) UnoRuntime.queryInterface( 78*b1cdbd2cSJim Jagielski XCellAddressable.class, cell); 79*b1cdbd2cSJim Jagielski XCellAddressable CA2 = (XCellAddressable) UnoRuntime.queryInterface( 80*b1cdbd2cSJim Jagielski XCellAddressable.class, cell2); 81*b1cdbd2cSJim Jagielski Point[] cellCoords = new Point[3]; 82*b1cdbd2cSJim Jagielski double[] cellValues = new double[3]; 83*b1cdbd2cSJim Jagielski 84*b1cdbd2cSJim Jagielski log.println("filling cells"); 85*b1cdbd2cSJim Jagielski fillCells(); 86*b1cdbd2cSJim Jagielski log.println("setting TableOperation with parameter ROW"); 87*b1cdbd2cSJim Jagielski oObj.setTableOperation(CRA.getRangeAddress(), TableOperationMode.ROW, 88*b1cdbd2cSJim Jagielski CA.getCellAddress(), CA2.getCellAddress()); 89*b1cdbd2cSJim Jagielski log.println("checking values"); 90*b1cdbd2cSJim Jagielski cellCoords = new Point[] { 91*b1cdbd2cSJim Jagielski new Point(1, 1), new Point(2, 1), new Point(3, 1) 92*b1cdbd2cSJim Jagielski }; 93*b1cdbd2cSJim Jagielski cellValues = new double[] { 5, 10, 15 }; 94*b1cdbd2cSJim Jagielski res &= checkValues(cellCoords, cellValues); 95*b1cdbd2cSJim Jagielski 96*b1cdbd2cSJim Jagielski log.println("filling cells"); 97*b1cdbd2cSJim Jagielski fillCells(); 98*b1cdbd2cSJim Jagielski log.println("setting TableOperation with parameter COLUMN"); 99*b1cdbd2cSJim Jagielski oObj.setTableOperation(CRA.getRangeAddress(), 100*b1cdbd2cSJim Jagielski TableOperationMode.COLUMN, CA.getCellAddress(), 101*b1cdbd2cSJim Jagielski CA2.getCellAddress()); 102*b1cdbd2cSJim Jagielski log.println("checking values"); 103*b1cdbd2cSJim Jagielski cellCoords = new Point[] { 104*b1cdbd2cSJim Jagielski new Point(1, 1), new Point(1, 2), new Point(1, 3) 105*b1cdbd2cSJim Jagielski }; 106*b1cdbd2cSJim Jagielski cellValues = new double[] { 12, 24, 36 }; 107*b1cdbd2cSJim Jagielski res &= checkValues(cellCoords, cellValues); 108*b1cdbd2cSJim Jagielski 109*b1cdbd2cSJim Jagielski if (both) { 110*b1cdbd2cSJim Jagielski log.println("filling cells"); 111*b1cdbd2cSJim Jagielski fillCells(); 112*b1cdbd2cSJim Jagielski log.println("setting TableOperation with parameter BOTH"); 113*b1cdbd2cSJim Jagielski oObj.setTableOperation(CRA.getRangeAddress(), 114*b1cdbd2cSJim Jagielski TableOperationMode.BOTH, 115*b1cdbd2cSJim Jagielski CA.getCellAddress(), CA2.getCellAddress()); 116*b1cdbd2cSJim Jagielski log.println("checking values"); 117*b1cdbd2cSJim Jagielski cellCoords = new Point[] { 118*b1cdbd2cSJim Jagielski new Point(1, 1), new Point(2, 2), new Point(3, 3) 119*b1cdbd2cSJim Jagielski }; 120*b1cdbd2cSJim Jagielski cellValues = new double[] { 17, 34, 51 }; 121*b1cdbd2cSJim Jagielski res &= checkValues(cellCoords, cellValues); 122*b1cdbd2cSJim Jagielski } 123*b1cdbd2cSJim Jagielski 124*b1cdbd2cSJim Jagielski tRes.tested("setTableOperation()", res); 125*b1cdbd2cSJim Jagielski } 126*b1cdbd2cSJim Jagielski fillCells()127*b1cdbd2cSJim Jagielski protected void fillCells() { 128*b1cdbd2cSJim Jagielski XCell cell = null; 129*b1cdbd2cSJim Jagielski 130*b1cdbd2cSJim Jagielski try { 131*b1cdbd2cSJim Jagielski for (int k = 1; k < 5; k++) { 132*b1cdbd2cSJim Jagielski cell = oSheet.getCellByPosition(0, k); 133*b1cdbd2cSJim Jagielski cell.setValue(k * 12); 134*b1cdbd2cSJim Jagielski cell = oSheet.getCellByPosition(k, 0); 135*b1cdbd2cSJim Jagielski cell.setValue(k * 5); 136*b1cdbd2cSJim Jagielski } 137*b1cdbd2cSJim Jagielski } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 138*b1cdbd2cSJim Jagielski log.println("Exception while filling Cells " + e.getMessage()); 139*b1cdbd2cSJim Jagielski } 140*b1cdbd2cSJim Jagielski } 141*b1cdbd2cSJim Jagielski checkValues(Point[] cellCoords, double[] cellValues)142*b1cdbd2cSJim Jagielski protected boolean checkValues(Point[] cellCoords, double[] cellValues) { 143*b1cdbd2cSJim Jagielski boolean res = true; 144*b1cdbd2cSJim Jagielski 145*b1cdbd2cSJim Jagielski for (int i = 0; i < cellValues.length; i++) { 146*b1cdbd2cSJim Jagielski try { 147*b1cdbd2cSJim Jagielski boolean locres = oSheet.getCellByPosition(cellCoords[i].X, 148*b1cdbd2cSJim Jagielski cellCoords[i].Y) 149*b1cdbd2cSJim Jagielski .getValue() == cellValues[i]; 150*b1cdbd2cSJim Jagielski res &= locres; 151*b1cdbd2cSJim Jagielski 152*b1cdbd2cSJim Jagielski if (!locres) { 153*b1cdbd2cSJim Jagielski log.println("Result differs for cell (" + 154*b1cdbd2cSJim Jagielski cellCoords[i].X + "," + cellCoords[i].Y + 155*b1cdbd2cSJim Jagielski ")"); 156*b1cdbd2cSJim Jagielski log.println("Expected: " + cellValues[i]); 157*b1cdbd2cSJim Jagielski log.println("Getting: " + 158*b1cdbd2cSJim Jagielski oSheet.getCellByPosition(cellCoords[i].X, 159*b1cdbd2cSJim Jagielski cellCoords[i].Y) 160*b1cdbd2cSJim Jagielski .getValue()); 161*b1cdbd2cSJim Jagielski } 162*b1cdbd2cSJim Jagielski } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 163*b1cdbd2cSJim Jagielski log.println("Exception while checking Values " + 164*b1cdbd2cSJim Jagielski e.getMessage()); 165*b1cdbd2cSJim Jagielski res &= false; 166*b1cdbd2cSJim Jagielski } 167*b1cdbd2cSJim Jagielski } 168*b1cdbd2cSJim Jagielski 169*b1cdbd2cSJim Jagielski return res; 170*b1cdbd2cSJim Jagielski } 171*b1cdbd2cSJim Jagielski 172*b1cdbd2cSJim Jagielski /** 173*b1cdbd2cSJim Jagielski * Restores initial component text. 174*b1cdbd2cSJim Jagielski */ after()175*b1cdbd2cSJim Jagielski protected void after() { 176*b1cdbd2cSJim Jagielski disposeEnvironment(); 177*b1cdbd2cSJim Jagielski } 178*b1cdbd2cSJim Jagielski }