1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package ifc.sheet; 25 26 import lib.MultiMethodTest; 27 import lib.Status; 28 import lib.StatusException; 29 30 import com.sun.star.sheet.XFormulaQuery; 31 import com.sun.star.sheet.XSheetCellRanges; 32 import com.sun.star.sheet.XSpreadsheet; 33 import com.sun.star.table.CellRangeAddress; 34 import com.sun.star.table.XCell; 35 import com.sun.star.uno.UnoRuntime; 36 37 /** 38 * 39 * @author sw93809 40 */ 41 public class _XFormulaQuery extends MultiMethodTest { 42 43 public XFormulaQuery oObj; 44 45 protected XSpreadsheet oSheet = null; 46 private XCell mxCell; 47 private int miQueryThisDependentRange = 1; 48 private int miQueryThisPrecedentRange = 1; 49 private int[] miExpectedDependentValues; 50 private int[] miExpectedPrecedentValues; 51 before()52 protected void before() { 53 oSheet = (XSpreadsheet)tEnv.getObjRelation("SHEET"); 54 55 if (oSheet == null) { 56 log.println("Object relation oSheet is missing"); 57 log.println("Trying to query the needed Interface"); 58 oSheet = (XSpreadsheet) UnoRuntime.queryInterface( 59 XSpreadsheet.class, tEnv.getTestObject()); 60 61 if (oSheet == null) { 62 throw new StatusException(Status.failed( 63 "Object relation oSheet is missing")); 64 } 65 } 66 Object o = tEnv.getObjRelation("MAKEENTRYINCELL"); 67 if (o != null) { 68 mxCell = (XCell)o; 69 } 70 else { 71 try { 72 mxCell = oSheet.getCellByPosition(15, 15); 73 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 74 throw new StatusException( 75 Status.failed("Couldn't get initial cell")); 76 } 77 } 78 79 o = tEnv.getObjRelation("RANGEINDICES"); 80 if (o != null) { 81 int[]index = (int[])o; 82 miQueryThisDependentRange = index[0]; 83 miQueryThisPrecedentRange = index[1]; 84 } 85 86 o = tEnv.getObjRelation("EXPECTEDDEPENDENTVALUES"); 87 if (o != null) { 88 miExpectedDependentValues = (int[])o; 89 } 90 else { 91 miExpectedDependentValues = new int[4]; 92 miExpectedDependentValues[0] = 15; 93 miExpectedDependentValues[1] = 15; 94 miExpectedDependentValues[2] = 15; 95 miExpectedDependentValues[3] = 15; 96 } 97 98 o = tEnv.getObjRelation("EXPECTEDPRECEDENTVALUES"); 99 if (o != null) { 100 miExpectedPrecedentValues = (int[])o; 101 } 102 else { 103 miExpectedPrecedentValues = new int[4]; 104 miExpectedPrecedentValues[0] = 0; 105 miExpectedPrecedentValues[1] = 0; 106 miExpectedPrecedentValues[2] = 15; 107 miExpectedPrecedentValues[3] = 15; 108 } 109 } 110 _queryDependents()111 public void _queryDependents() { 112 boolean res = true; 113 114 try { 115 mxCell.setFormula("=sum(A1:D1)"); 116 oSheet.getCellByPosition(0, 0).setValue(1); 117 oSheet.getCellByPosition(1, 0).setValue(1); 118 oSheet.getCellByPosition(2, 0).setValue(1); 119 oSheet.getCellByPosition(3, 0).setValue(1); 120 121 log.println( 122 "calling oObj.queryDependents(false)"); 123 XSheetCellRanges getting = oObj.queryDependents(false); 124 CellRangeAddress[] range = getting.getRangeAddresses(); 125 126 res = ((range[miQueryThisDependentRange].StartColumn==miExpectedDependentValues[0]) && 127 (range[miQueryThisDependentRange].EndColumn==miExpectedDependentValues[1]) && 128 (range[miQueryThisDependentRange].StartRow==miExpectedDependentValues[2]) && 129 (range[miQueryThisDependentRange].EndRow==miExpectedDependentValues[3])); 130 131 if (!res) { 132 log.println("Getting (" 133 +(range[miQueryThisDependentRange]).StartColumn+"," 134 +(range[miQueryThisDependentRange]).EndColumn+"," 135 +(range[miQueryThisDependentRange]).StartRow+"," 136 +(range[miQueryThisDependentRange]).EndRow+")"); 137 log.println("Expected (" + miExpectedDependentValues[0] + "," + 138 miExpectedDependentValues[1] + "," + 139 miExpectedDependentValues[2] + "," + 140 miExpectedDependentValues[3] + ")"); 141 } 142 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 143 log.println("Couldn't set initial version to cell"); 144 res = false; 145 } 146 147 tRes.tested("queryDependents()", res); 148 } 149 _queryPrecedents()150 public void _queryPrecedents() { 151 boolean res = true; 152 153 try { 154 mxCell.setFormula("=sum(A1:D1)"); 155 oSheet.getCellByPosition(0, 0).setValue(1); 156 oSheet.getCellByPosition(1, 0).setValue(1); 157 oSheet.getCellByPosition(2, 0).setValue(1); 158 oSheet.getCellByPosition(3, 0).setValue(1); 159 oSheet.getCellByPosition(1, 2).setFormula("=A16*2"); 160 161 log.println( 162 "calling oObj.queryPrecedents(false)"); 163 XSheetCellRanges getting = oObj.queryPrecedents(false); 164 CellRangeAddress[] range = getting.getRangeAddresses(); 165 166 res = ((range[miQueryThisPrecedentRange].StartColumn==miExpectedPrecedentValues[0]) && 167 (range[miQueryThisPrecedentRange].EndColumn==miExpectedPrecedentValues[1]) && 168 (range[miQueryThisPrecedentRange].StartRow==miExpectedPrecedentValues[2]) && 169 (range[miQueryThisPrecedentRange].EndRow==miExpectedPrecedentValues[3])); 170 171 if (!res) { 172 log.println("Getting (" 173 +(range[miQueryThisPrecedentRange]).StartColumn+"," 174 +(range[miQueryThisPrecedentRange]).EndColumn+"," 175 +(range[miQueryThisPrecedentRange]).StartRow+"," 176 +(range[miQueryThisPrecedentRange]).EndRow+")"); 177 log.println("Expected (" + miExpectedPrecedentValues[0] + "," + 178 miExpectedPrecedentValues[1] + "," + 179 miExpectedPrecedentValues[2] + "," + 180 miExpectedPrecedentValues[3] + ")"); 181 } 182 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 183 log.println("Couldn't set initial version to cell"); 184 res = false; 185 } 186 187 tRes.tested("queryPrecedents()", res); 188 } 189 190 /** 191 * Forces environment recreation. 192 */ after()193 protected void after() { 194 disposeEnvironment(); 195 } 196 197 } 198