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