Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / sheet / _XFormulaQuery.java
blobf7730c7e8589abc8a5550cc6f100aea2b02485fc
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: _XFormulaQuery.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.sheet.XFormulaQuery;
38 import com.sun.star.sheet.XSheetCellRanges;
39 import com.sun.star.sheet.XSpreadsheet;
40 import com.sun.star.table.CellRangeAddress;
41 import com.sun.star.table.XCell;
42 import com.sun.star.uno.UnoRuntime;
44 /**
46 * @author sw93809
48 public class _XFormulaQuery extends MultiMethodTest {
50 public XFormulaQuery oObj;
52 protected XSpreadsheet oSheet = null;
53 private XCell mxCell;
54 private int miQueryThisDependentRange = 1;
55 private int miQueryThisPrecedentRange = 1;
56 private int[] miExpectedDependentValues;
57 private int[] miExpectedPrecedentValues;
59 protected void before() {
60 oSheet = (XSpreadsheet)tEnv.getObjRelation("SHEET");
62 if (oSheet == null) {
63 log.println("Object relation oSheet is missing");
64 log.println("Trying to query the needed Interface");
65 oSheet = (XSpreadsheet) UnoRuntime.queryInterface(
66 XSpreadsheet.class, tEnv.getTestObject());
68 if (oSheet == null) {
69 throw new StatusException(Status.failed(
70 "Object relation oSheet is missing"));
73 Object o = tEnv.getObjRelation("MAKEENTRYINCELL");
74 if (o != null) {
75 mxCell = (XCell)o;
77 else {
78 try {
79 mxCell = oSheet.getCellByPosition(15, 15);
80 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
81 throw new StatusException(
82 Status.failed("Couldn't get initial cell"));
86 o = tEnv.getObjRelation("RANGEINDICES");
87 if (o != null) {
88 int[]index = (int[])o;
89 miQueryThisDependentRange = index[0];
90 miQueryThisPrecedentRange = index[1];
93 o = tEnv.getObjRelation("EXPECTEDDEPENDENTVALUES");
94 if (o != null) {
95 miExpectedDependentValues = (int[])o;
97 else {
98 miExpectedDependentValues = new int[4];
99 miExpectedDependentValues[0] = 15;
100 miExpectedDependentValues[1] = 15;
101 miExpectedDependentValues[2] = 15;
102 miExpectedDependentValues[3] = 15;
105 o = tEnv.getObjRelation("EXPECTEDPRECEDENTVALUES");
106 if (o != null) {
107 miExpectedPrecedentValues = (int[])o;
109 else {
110 miExpectedPrecedentValues = new int[4];
111 miExpectedPrecedentValues[0] = 0;
112 miExpectedPrecedentValues[1] = 0;
113 miExpectedPrecedentValues[2] = 15;
114 miExpectedPrecedentValues[3] = 15;
118 public void _queryDependents() {
119 boolean res = true;
121 try {
122 mxCell.setFormula("=sum(A1:D1)");
123 oSheet.getCellByPosition(0, 0).setValue(1);
124 oSheet.getCellByPosition(1, 0).setValue(1);
125 oSheet.getCellByPosition(2, 0).setValue(1);
126 oSheet.getCellByPosition(3, 0).setValue(1);
128 log.println(
129 "calling oObj.queryDependents(false)");
130 XSheetCellRanges getting = oObj.queryDependents(false);
131 CellRangeAddress[] range = getting.getRangeAddresses();
133 res = ((range[miQueryThisDependentRange].StartColumn==miExpectedDependentValues[0]) &&
134 (range[miQueryThisDependentRange].EndColumn==miExpectedDependentValues[1]) &&
135 (range[miQueryThisDependentRange].StartRow==miExpectedDependentValues[2]) &&
136 (range[miQueryThisDependentRange].EndRow==miExpectedDependentValues[3]));
138 if (!res) {
139 log.println("Getting ("
140 +(range[miQueryThisDependentRange]).StartColumn+","
141 +(range[miQueryThisDependentRange]).EndColumn+","
142 +(range[miQueryThisDependentRange]).StartRow+","
143 +(range[miQueryThisDependentRange]).EndRow+")");
144 log.println("Expected (" + miExpectedDependentValues[0] + "," +
145 miExpectedDependentValues[1] + "," +
146 miExpectedDependentValues[2] + "," +
147 miExpectedDependentValues[3] + ")");
149 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
150 log.println("Couldn't set initial version to cell");
151 res = false;
154 tRes.tested("queryDependents()", res);
157 public void _queryPrecedents() {
158 boolean res = true;
160 try {
161 mxCell.setFormula("=sum(A1:D1)");
162 oSheet.getCellByPosition(0, 0).setValue(1);
163 oSheet.getCellByPosition(1, 0).setValue(1);
164 oSheet.getCellByPosition(2, 0).setValue(1);
165 oSheet.getCellByPosition(3, 0).setValue(1);
166 oSheet.getCellByPosition(1, 2).setFormula("=A16*2");
168 log.println(
169 "calling oObj.queryPrecedents(false)");
170 XSheetCellRanges getting = oObj.queryPrecedents(false);
171 CellRangeAddress[] range = getting.getRangeAddresses();
173 res = ((range[miQueryThisPrecedentRange].StartColumn==miExpectedPrecedentValues[0]) &&
174 (range[miQueryThisPrecedentRange].EndColumn==miExpectedPrecedentValues[1]) &&
175 (range[miQueryThisPrecedentRange].StartRow==miExpectedPrecedentValues[2]) &&
176 (range[miQueryThisPrecedentRange].EndRow==miExpectedPrecedentValues[3]));
178 if (!res) {
179 log.println("Getting ("
180 +(range[miQueryThisPrecedentRange]).StartColumn+","
181 +(range[miQueryThisPrecedentRange]).EndColumn+","
182 +(range[miQueryThisPrecedentRange]).StartRow+","
183 +(range[miQueryThisPrecedentRange]).EndRow+")");
184 log.println("Expected (" + miExpectedPrecedentValues[0] + "," +
185 miExpectedPrecedentValues[1] + "," +
186 miExpectedPrecedentValues[2] + "," +
187 miExpectedPrecedentValues[3] + ")");
189 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
190 log.println("Couldn't set initial version to cell");
191 res = false;
194 tRes.tested("queryPrecedents()", res);
198 * Forces environment recreation.
200 protected void after() {
201 disposeEnvironment();