1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package ifc.sheet; 29 30 import lib.MultiMethodTest; 31 import lib.Status; 32 import lib.StatusException; 33 34 import com.sun.star.beans.PropertyValue; 35 import com.sun.star.sheet.SubTotalColumn; 36 import com.sun.star.sheet.XDatabaseRange; 37 import com.sun.star.sheet.XSheetFilterDescriptor; 38 import com.sun.star.sheet.XSubTotalDescriptor; 39 import com.sun.star.table.CellRangeAddress; 40 import com.sun.star.table.XCell; 41 import com.sun.star.table.XCellRange; 42 43 /** 44 * Testing <code>com.sun.star.sheet.XDatabaseRange</code> 45 * interface methods : 46 * <ul> 47 * <li><code> getDataArea()</code></li> 48 * <li><code> setDataArea()</code></li> 49 * <li><code> getSortDescriptor()</code></li> 50 * <li><code> getFilterDescriptor()</code></li> 51 * <li><code> getSubTotalDescriptor()</code></li> 52 * <li><code> getImportDescriptor()</code></li> 53 * <li><code> refresh()</code></li> 54 * </ul> <p> 55 * This test needs the following object relations : 56 * <ul> 57 * <li> <code>'DATAAREA'</code> (of type <code>CellRangeAddress</code>): 58 * to have cell range address for test of method <code>getDataArea()</code></li> 59 * <li> <code>'XCELLRANGE'</code> (of type <code>XCellRange</code>): 60 * cell range of the spreadsheet with database range, 61 * to get values of cell</li> 62 * <ul> <p> 63 * @see com.sun.star.sheet.XDatabaseRange 64 * @see com.sun.star.table.CellRangeAddress 65 */ 66 public class _XDatabaseRange extends MultiMethodTest { 67 68 public XDatabaseRange oObj = null; 69 CellRangeAddress oldCRA = null; 70 XCellRange xCellRange = null; 71 72 /** 73 * Retrieves object relations. 74 * @throws StatusException If one of relations not found. 75 */ 76 protected void before() { 77 oldCRA = (CellRangeAddress)tEnv.getObjRelation("DATAAREA"); 78 if (oldCRA == null) { 79 throw new StatusException(Status.failed 80 ("Relation 'DATAAREA' not found")); 81 } 82 xCellRange = (XCellRange)tEnv.getObjRelation("XCELLRANGE"); 83 if (xCellRange == null) { 84 throw new StatusException(Status.failed 85 ("Relation 'XCELLRANGE' not found")); 86 } 87 } 88 89 /** 90 * Test calls the method and compares returned cell range address with 91 * cell range address obtained by object relation <code>'DATAAREA'</code>.<p> 92 * Has <b> OK </b> status if all fields of cell range addresses are equal. <p> 93 */ 94 public void _getDataArea() { 95 boolean bResult = true; 96 CellRangeAddress objCRA = oObj.getDataArea(); 97 bResult &= objCRA.EndColumn == oldCRA.EndColumn; 98 bResult &= objCRA.EndRow == oldCRA.EndRow; 99 bResult &= objCRA.Sheet == oldCRA.Sheet; 100 bResult &= objCRA.StartColumn == oldCRA.StartColumn; 101 bResult &= objCRA.StartRow == oldCRA.StartRow; 102 tRes.tested("getDataArea()", bResult); 103 } 104 105 /** 106 * Test calls the method and checks returned value. <p> 107 * Has <b> OK </b> status if returned value isn't null. <p> 108 */ 109 public void _getFilterDescriptor() { 110 XSheetFilterDescriptor FD = oObj.getFilterDescriptor(); 111 tRes.tested("getFilterDescriptor()", FD != null); 112 } 113 114 /** 115 * Test calls the method and checks returned value. <p> 116 * Has <b> OK </b> status if returned value isn't null. <p> 117 */ 118 public void _getImportDescriptor() { 119 PropertyValue[] pva = oObj.getImportDescriptor(); 120 tRes.tested("getImportDescriptor()", pva != null); 121 } 122 123 /** 124 * Test calls the method and checks returned value. <p> 125 * Has <b> OK </b> status if returned value isn't null. <p> 126 */ 127 public void _getSortDescriptor() { 128 PropertyValue[] pva = oObj.getSortDescriptor(); 129 tRes.tested("getSortDescriptor()", pva != null); 130 } 131 132 /** 133 * Test calls the method and checks returned value. <p> 134 * Has <b> OK </b> status if returned value isn't null. <p> 135 */ 136 public void _getSubTotalDescriptor() { 137 STD = oObj.getSubTotalDescriptor(); 138 tRes.tested("getSubTotalDescriptor()", STD != null); 139 } 140 141 XSubTotalDescriptor STD = null; 142 143 /** 144 * Test adds new SubTotalDescriptor and checks value of cell with 145 * subtotal sum after refresh() call. <p> 146 * Has <b> OK </b> if value of cell with subtotal sum was changed 147 * after refresh() call.<p> 148 */ 149 public void _refresh() { 150 requiredMethod("getSubTotalDescriptor()"); 151 requiredMethod("setDataArea()"); 152 153 for(int i = STARTROW; i < ENDROW+1; i++) { 154 try { 155 XCell cell = xCellRange.getCellByPosition(COL, i); 156 cell.setValue(i); 157 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 158 log.println("Unexpected exception"); 159 e.printStackTrace(log); 160 tRes.tested("refresh()", false); 161 } 162 } 163 164 SubTotalColumn[] STC = new SubTotalColumn[1]; 165 STC[0] = new SubTotalColumn(); 166 STC[0].Column = COL; 167 STC[0].Function = com.sun.star.sheet.GeneralFunction.SUM; 168 169 double oldVal = 0; 170 try { 171 XCell checkCell = xCellRange.getCellByPosition(COL, ENDROW); 172 oldVal = checkCell.getValue(); 173 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 174 log.println("Unexpected exception"); 175 e.printStackTrace(log); 176 tRes.tested("refresh()", false); 177 } 178 log.println("Value of the cell (" + COL + ", " + ENDROW + 179 ") : " + oldVal ); 180 181 log.println("Set new SubTotal descriptor..."); 182 183 STD.clear(); 184 STD.addNew(STC, 1); 185 186 double valBeforeRefresh = 0; 187 try { 188 XCell checkCell = xCellRange.getCellByPosition(COL, ENDROW); 189 valBeforeRefresh = checkCell.getValue(); 190 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 191 log.println("Unexpected exception"); 192 e.printStackTrace(log); 193 tRes.tested("refresh()", false); 194 } 195 log.println("Value of the cell (" + COL + ", " + ENDROW + 196 ") : " + valBeforeRefresh ); 197 198 log.println("Now call refresh()..."); 199 oObj.refresh(); 200 201 double valAfterRefresh = 0; 202 try { 203 XCell checkCell = xCellRange.getCellByPosition(COL, ENDROW); 204 valAfterRefresh = checkCell.getValue(); 205 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 206 log.println("Unexpected exception"); 207 e.printStackTrace(log); 208 tRes.tested("refresh()", false); 209 } 210 log.println("Value of the cell (" + COL + ", " + ENDROW + 211 ") : " + valAfterRefresh ); 212 213 tRes.tested("refresh()", oldVal != valAfterRefresh && 214 oldVal == valBeforeRefresh); 215 } 216 217 final short COL = 0; 218 final short STARTROW = 0; 219 final short ENDROW = 5; 220 221 /** 222 * Test creates new cell range address and calls the method. <p> 223 * Has <b> OK </b> status if the method successfully returns. <p> 224 */ 225 public void _setDataArea() { 226 executeMethod("getDataArea()"); 227 CellRangeAddress newCRA = new CellRangeAddress(); 228 newCRA.Sheet = oldCRA.Sheet; 229 newCRA.StartColumn = COL; 230 newCRA.EndColumn = COL; 231 newCRA.StartRow = STARTROW; 232 newCRA.EndRow = ENDROW; 233 234 oObj.setDataArea(newCRA); 235 236 tRes.tested("setDataArea()", true); 237 } 238 239 protected void after() { 240 disposeEnvironment(); 241 } 242 } 243 244 245