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