Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XDatabaseRange.java
blobd8b0bf69e2348949bcf0f507dcccdd05ef1d5a65
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 @Override
68 protected void before() {
69 oldCRA = (CellRangeAddress)tEnv.getObjRelation("DATAAREA");
70 if (oldCRA == null) {
71 throw new StatusException(Status.failed
72 ("Relation 'DATAAREA' not found"));
74 xCellRange = (XCellRange)tEnv.getObjRelation("XCELLRANGE");
75 if (xCellRange == null) {
76 throw new StatusException(Status.failed
77 ("Relation 'XCELLRANGE' not found"));
81 /**
82 * Test calls the method and compares returned cell range address with
83 * cell range address obtained by object relation <code>'DATAAREA'</code>.<p>
84 * Has <b> OK </b> status if all fields of cell range addresses are equal. <p>
86 public void _getDataArea() {
87 boolean bResult = true;
88 CellRangeAddress objCRA = oObj.getDataArea();
89 bResult &= objCRA.EndColumn == oldCRA.EndColumn;
90 bResult &= objCRA.EndRow == oldCRA.EndRow;
91 bResult &= objCRA.Sheet == oldCRA.Sheet;
92 bResult &= objCRA.StartColumn == oldCRA.StartColumn;
93 bResult &= objCRA.StartRow == oldCRA.StartRow;
94 tRes.tested("getDataArea()", bResult);
97 /**
98 * Test calls the method and checks returned value. <p>
99 * Has <b> OK </b> status if returned value isn't null. <p>
101 public void _getFilterDescriptor() {
102 XSheetFilterDescriptor FD = oObj.getFilterDescriptor();
103 tRes.tested("getFilterDescriptor()", FD != null);
107 * Test calls the method and checks returned value. <p>
108 * Has <b> OK </b> status if returned value isn't null. <p>
110 public void _getImportDescriptor() {
111 PropertyValue[] pva = oObj.getImportDescriptor();
112 tRes.tested("getImportDescriptor()", pva != null);
116 * Test calls the method and checks returned value. <p>
117 * Has <b> OK </b> status if returned value isn't null. <p>
119 public void _getSortDescriptor() {
120 PropertyValue[] pva = oObj.getSortDescriptor();
121 tRes.tested("getSortDescriptor()", pva != null);
125 * Test calls the method and checks returned value. <p>
126 * Has <b> OK </b> status if returned value isn't null. <p>
128 public void _getSubTotalDescriptor() {
129 STD = oObj.getSubTotalDescriptor();
130 tRes.tested("getSubTotalDescriptor()", STD != null);
133 XSubTotalDescriptor STD = null;
136 * Test adds new SubTotalDescriptor and checks value of cell with
137 * subtotal sum after refresh() call. <p>
138 * Has <b> OK </b> if value of cell with subtotal sum was changed
139 * after refresh() call.<p>
141 public void _refresh() {
142 requiredMethod("getSubTotalDescriptor()");
143 requiredMethod("setDataArea()");
145 for(int i = STARTROW; i < ENDROW+1; i++) {
146 try {
147 XCell cell = xCellRange.getCellByPosition(COL, i);
148 cell.setValue(i);
149 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
150 log.println("Unexpected exception");
151 e.printStackTrace(log);
152 tRes.tested("refresh()", false);
156 SubTotalColumn[] STC = new SubTotalColumn[1];
157 STC[0] = new SubTotalColumn();
158 STC[0].Column = COL;
159 STC[0].Function = com.sun.star.sheet.GeneralFunction.SUM;
161 double oldVal = 0;
162 try {
163 XCell checkCell = xCellRange.getCellByPosition(COL, ENDROW);
164 oldVal = checkCell.getValue();
165 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
166 log.println("Unexpected exception");
167 e.printStackTrace(log);
168 tRes.tested("refresh()", false);
170 log.println("Value of the cell (" + COL + ", " + ENDROW +
171 ") : " + oldVal );
173 log.println("Set new SubTotal descriptor...");
175 STD.clear();
176 STD.addNew(STC, 1);
178 double valBeforeRefresh = 0;
179 try {
180 XCell checkCell = xCellRange.getCellByPosition(COL, ENDROW);
181 valBeforeRefresh = checkCell.getValue();
182 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
183 log.println("Unexpected exception");
184 e.printStackTrace(log);
185 tRes.tested("refresh()", false);
187 log.println("Value of the cell (" + COL + ", " + ENDROW +
188 ") : " + valBeforeRefresh );
190 log.println("Now call refresh()...");
191 oObj.refresh();
193 double valAfterRefresh = 0;
194 try {
195 XCell checkCell = xCellRange.getCellByPosition(COL, ENDROW);
196 valAfterRefresh = checkCell.getValue();
197 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
198 log.println("Unexpected exception");
199 e.printStackTrace(log);
200 tRes.tested("refresh()", false);
202 log.println("Value of the cell (" + COL + ", " + ENDROW +
203 ") : " + valAfterRefresh );
205 tRes.tested("refresh()", oldVal != valAfterRefresh &&
206 oldVal == valBeforeRefresh);
209 static final short COL = 0;
210 static final short STARTROW = 0;
211 static final short ENDROW = 5;
214 * Test creates new cell range address and calls the method. <p>
215 * Has <b> OK </b> status if the method successfully returns. <p>
217 public void _setDataArea() {
218 executeMethod("getDataArea()");
219 CellRangeAddress newCRA = new CellRangeAddress();
220 newCRA.Sheet = oldCRA.Sheet;
221 newCRA.StartColumn = COL;
222 newCRA.EndColumn = COL;
223 newCRA.StartRow = STARTROW;
224 newCRA.EndRow = ENDROW;
226 oObj.setDataArea(newCRA);
228 tRes.tested("setDataArea()", true);
231 @Override
232 protected void after() {
233 disposeEnvironment();