bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XDatabaseRange.java
blob9f1cea1956096686ea4486f985d1b940b6ec33d4
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc.sheet;
21 import lib.MultiMethodTest;
22 import lib.Status;
23 import lib.StatusException;
25 import com.sun.star.beans.PropertyValue;
26 import com.sun.star.sheet.SubTotalColumn;
27 import com.sun.star.sheet.XDatabaseRange;
28 import com.sun.star.sheet.XSheetFilterDescriptor;
29 import com.sun.star.sheet.XSubTotalDescriptor;
30 import com.sun.star.table.CellRangeAddress;
31 import com.sun.star.table.XCell;
32 import com.sun.star.table.XCellRange;
34 /**
35 * Testing <code>com.sun.star.sheet.XDatabaseRange</code>
36 * interface methods :
37 * <ul>
38 * <li><code> getDataArea()</code></li>
39 * <li><code> setDataArea()</code></li>
40 * <li><code> getSortDescriptor()</code></li>
41 * <li><code> getFilterDescriptor()</code></li>
42 * <li><code> getSubTotalDescriptor()</code></li>
43 * <li><code> getImportDescriptor()</code></li>
44 * <li><code> refresh()</code></li>
45 * </ul> <p>
46 * This test needs the following object relations :
47 * <ul>
48 * <li> <code>'DATAAREA'</code> (of type <code>CellRangeAddress</code>):
49 * to have cell range address for test of method <code>getDataArea()</code></li>
50 * <li> <code>'XCELLRANGE'</code> (of type <code>XCellRange</code>):
51 * cell range of the spreadsheet with database range,
52 * to get values of cell</li>
53 * <ul> <p>
54 * @see com.sun.star.sheet.XDatabaseRange
55 * @see com.sun.star.table.CellRangeAddress
57 public class _XDatabaseRange extends MultiMethodTest {
59 public XDatabaseRange oObj = null;
60 CellRangeAddress oldCRA = null;
61 XCellRange xCellRange = null;
63 /**
64 * Retrieves object relations.
65 * @throws StatusException If one of relations not found.
67 protected void before() {
68 oldCRA = (CellRangeAddress)tEnv.getObjRelation("DATAAREA");
69 if (oldCRA == null) {
70 throw new StatusException(Status.failed
71 ("Relation 'DATAAREA' not found"));
73 xCellRange = (XCellRange)tEnv.getObjRelation("XCELLRANGE");
74 if (xCellRange == null) {
75 throw new StatusException(Status.failed
76 ("Relation 'XCELLRANGE' not found"));
80 /**
81 * Test calls the method and compares returned cell range address with
82 * cell range address obtained by object relation <code>'DATAAREA'</code>.<p>
83 * Has <b> OK </b> status if all fields of cell range addresses are equal. <p>
85 public void _getDataArea() {
86 boolean bResult = true;
87 CellRangeAddress objCRA = oObj.getDataArea();
88 bResult &= objCRA.EndColumn == oldCRA.EndColumn;
89 bResult &= objCRA.EndRow == oldCRA.EndRow;
90 bResult &= objCRA.Sheet == oldCRA.Sheet;
91 bResult &= objCRA.StartColumn == oldCRA.StartColumn;
92 bResult &= objCRA.StartRow == oldCRA.StartRow;
93 tRes.tested("getDataArea()", bResult);
96 /**
97 * Test calls the method and checks returned value. <p>
98 * Has <b> OK </b> status if returned value isn't null. <p>
100 public void _getFilterDescriptor() {
101 XSheetFilterDescriptor FD = oObj.getFilterDescriptor();
102 tRes.tested("getFilterDescriptor()", FD != null);
106 * Test calls the method and checks returned value. <p>
107 * Has <b> OK </b> status if returned value isn't null. <p>
109 public void _getImportDescriptor() {
110 PropertyValue[] pva = oObj.getImportDescriptor();
111 tRes.tested("getImportDescriptor()", pva != null);
115 * Test calls the method and checks returned value. <p>
116 * Has <b> OK </b> status if returned value isn't null. <p>
118 public void _getSortDescriptor() {
119 PropertyValue[] pva = oObj.getSortDescriptor();
120 tRes.tested("getSortDescriptor()", pva != null);
124 * Test calls the method and checks returned value. <p>
125 * Has <b> OK </b> status if returned value isn't null. <p>
127 public void _getSubTotalDescriptor() {
128 STD = oObj.getSubTotalDescriptor();
129 tRes.tested("getSubTotalDescriptor()", STD != null);
132 XSubTotalDescriptor STD = null;
135 * Test adds new SubTotalDescriptor and checks value of cell with
136 * subtotal sum after refresh() call. <p>
137 * Has <b> OK </b> if value of cell with subtotal sum was changed
138 * after refresh() call.<p>
140 public void _refresh() {
141 requiredMethod("getSubTotalDescriptor()");
142 requiredMethod("setDataArea()");
144 for(int i = STARTROW; i < ENDROW+1; i++) {
145 try {
146 XCell cell = xCellRange.getCellByPosition(COL, i);
147 cell.setValue(i);
148 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
149 log.println("Unexpected exception");
150 e.printStackTrace(log);
151 tRes.tested("refresh()", false);
155 SubTotalColumn[] STC = new SubTotalColumn[1];
156 STC[0] = new SubTotalColumn();
157 STC[0].Column = COL;
158 STC[0].Function = com.sun.star.sheet.GeneralFunction.SUM;
160 double oldVal = 0;
161 try {
162 XCell checkCell = xCellRange.getCellByPosition(COL, ENDROW);
163 oldVal = checkCell.getValue();
164 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
165 log.println("Unexpected exception");
166 e.printStackTrace(log);
167 tRes.tested("refresh()", false);
169 log.println("Value of the cell (" + COL + ", " + ENDROW +
170 ") : " + oldVal );
172 log.println("Set new SubTotal descriptor...");
174 STD.clear();
175 STD.addNew(STC, 1);
177 double valBeforeRefresh = 0;
178 try {
179 XCell checkCell = xCellRange.getCellByPosition(COL, ENDROW);
180 valBeforeRefresh = checkCell.getValue();
181 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
182 log.println("Unexpected exception");
183 e.printStackTrace(log);
184 tRes.tested("refresh()", false);
186 log.println("Value of the cell (" + COL + ", " + ENDROW +
187 ") : " + valBeforeRefresh );
189 log.println("Now call refresh()...");
190 oObj.refresh();
192 double valAfterRefresh = 0;
193 try {
194 XCell checkCell = xCellRange.getCellByPosition(COL, ENDROW);
195 valAfterRefresh = checkCell.getValue();
196 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
197 log.println("Unexpected exception");
198 e.printStackTrace(log);
199 tRes.tested("refresh()", false);
201 log.println("Value of the cell (" + COL + ", " + ENDROW +
202 ") : " + valAfterRefresh );
204 tRes.tested("refresh()", oldVal != valAfterRefresh &&
205 oldVal == valBeforeRefresh);
208 final short COL = 0;
209 final short STARTROW = 0;
210 final short ENDROW = 5;
213 * Test creates new cell range address and calls the method. <p>
214 * Has <b> OK </b> status if the method successfully returns. <p>
216 public void _setDataArea() {
217 executeMethod("getDataArea()");
218 CellRangeAddress newCRA = new CellRangeAddress();
219 newCRA.Sheet = oldCRA.Sheet;
220 newCRA.StartColumn = COL;
221 newCRA.EndColumn = COL;
222 newCRA.StartRow = STARTROW;
223 newCRA.EndRow = ENDROW;
225 oObj.setDataArea(newCRA);
227 tRes.tested("setDataArea()", true);
230 protected void after() {
231 disposeEnvironment();