Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XFormulaQuery.java
blobb4958937ee2fb927688d352f27ddcb85d759a91b
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.sheet.XFormulaQuery;
26 import com.sun.star.sheet.XSheetCellRanges;
27 import com.sun.star.sheet.XSpreadsheet;
28 import com.sun.star.table.CellRangeAddress;
29 import com.sun.star.table.XCell;
30 import com.sun.star.uno.UnoRuntime;
32 public class _XFormulaQuery extends MultiMethodTest {
34 public XFormulaQuery oObj;
36 protected XSpreadsheet oSheet = null;
37 private XCell mxCell;
38 private int miQueryThisDependentRange = 1;
39 private int miQueryThisPrecedentRange = 1;
40 private int[] miExpectedDependentValues;
41 private int[] miExpectedPrecedentValues;
43 @Override
44 protected void before() {
45 oSheet = (XSpreadsheet)tEnv.getObjRelation("SHEET");
47 if (oSheet == null) {
48 log.println("Object relation oSheet is missing");
49 log.println("Trying to query the needed Interface");
50 oSheet = UnoRuntime.queryInterface(
51 XSpreadsheet.class, tEnv.getTestObject());
53 if (oSheet == null) {
54 throw new StatusException(Status.failed(
55 "Object relation oSheet is missing"));
58 Object o = tEnv.getObjRelation("MAKEENTRYINCELL");
59 if (o != null) {
60 mxCell = (XCell)o;
62 else {
63 try {
64 mxCell = oSheet.getCellByPosition(15, 15);
65 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
66 throw new StatusException(e, Status.failed("Couldn't get initial cell"));
70 o = tEnv.getObjRelation("RANGEINDICES");
71 if (o != null) {
72 int[]index = (int[])o;
73 miQueryThisDependentRange = index[0];
74 miQueryThisPrecedentRange = index[1];
77 o = tEnv.getObjRelation("EXPECTEDDEPENDENTVALUES");
78 if (o != null) {
79 miExpectedDependentValues = (int[])o;
81 else {
82 miExpectedDependentValues = new int[4];
83 miExpectedDependentValues[0] = 15;
84 miExpectedDependentValues[1] = 15;
85 miExpectedDependentValues[2] = 15;
86 miExpectedDependentValues[3] = 15;
89 o = tEnv.getObjRelation("EXPECTEDPRECEDENTVALUES");
90 if (o != null) {
91 miExpectedPrecedentValues = (int[])o;
93 else {
94 miExpectedPrecedentValues = new int[4];
95 miExpectedPrecedentValues[0] = 0;
96 miExpectedPrecedentValues[1] = 0;
97 miExpectedPrecedentValues[2] = 15;
98 miExpectedPrecedentValues[3] = 15;
102 public void _queryDependents() {
103 boolean res = true;
105 try {
106 mxCell.setFormula("=sum(A1:D1)");
107 oSheet.getCellByPosition(0, 0).setValue(1);
108 oSheet.getCellByPosition(1, 0).setValue(1);
109 oSheet.getCellByPosition(2, 0).setValue(1);
110 oSheet.getCellByPosition(3, 0).setValue(1);
112 log.println(
113 "calling oObj.queryDependents(false)");
114 XSheetCellRanges getting = oObj.queryDependents(false);
115 CellRangeAddress[] range = getting.getRangeAddresses();
117 res = ((range[miQueryThisDependentRange].StartColumn==miExpectedDependentValues[0]) &&
118 (range[miQueryThisDependentRange].EndColumn==miExpectedDependentValues[1]) &&
119 (range[miQueryThisDependentRange].StartRow==miExpectedDependentValues[2]) &&
120 (range[miQueryThisDependentRange].EndRow==miExpectedDependentValues[3]));
122 if (!res) {
123 log.println("Getting ("
124 +(range[miQueryThisDependentRange]).StartColumn+","
125 +(range[miQueryThisDependentRange]).EndColumn+","
126 +(range[miQueryThisDependentRange]).StartRow+","
127 +(range[miQueryThisDependentRange]).EndRow+")");
128 log.println("Expected (" + miExpectedDependentValues[0] + "," +
129 miExpectedDependentValues[1] + "," +
130 miExpectedDependentValues[2] + "," +
131 miExpectedDependentValues[3] + ")");
133 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
134 log.println("Couldn't set initial version to cell");
135 res = false;
138 tRes.tested("queryDependents()", res);
141 public void _queryPrecedents() {
142 boolean res = true;
144 try {
145 mxCell.setFormula("=sum(A1:D1)");
146 oSheet.getCellByPosition(0, 0).setValue(1);
147 oSheet.getCellByPosition(1, 0).setValue(1);
148 oSheet.getCellByPosition(2, 0).setValue(1);
149 oSheet.getCellByPosition(3, 0).setValue(1);
150 oSheet.getCellByPosition(1, 2).setFormula("=A16*2");
152 log.println(
153 "calling oObj.queryPrecedents(false)");
154 XSheetCellRanges getting = oObj.queryPrecedents(false);
155 CellRangeAddress[] range = getting.getRangeAddresses();
157 res = ((range[miQueryThisPrecedentRange].StartColumn==miExpectedPrecedentValues[0]) &&
158 (range[miQueryThisPrecedentRange].EndColumn==miExpectedPrecedentValues[1]) &&
159 (range[miQueryThisPrecedentRange].StartRow==miExpectedPrecedentValues[2]) &&
160 (range[miQueryThisPrecedentRange].EndRow==miExpectedPrecedentValues[3]));
162 if (!res) {
163 log.println("Getting ("
164 +(range[miQueryThisPrecedentRange]).StartColumn+","
165 +(range[miQueryThisPrecedentRange]).EndColumn+","
166 +(range[miQueryThisPrecedentRange]).StartRow+","
167 +(range[miQueryThisPrecedentRange]).EndRow+")");
168 log.println("Expected (" + miExpectedPrecedentValues[0] + "," +
169 miExpectedPrecedentValues[1] + "," +
170 miExpectedPrecedentValues[2] + "," +
171 miExpectedPrecedentValues[3] + ")");
173 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
174 log.println("Couldn't set initial version to cell");
175 res = false;
178 tRes.tested("queryPrecedents()", res);
182 * Forces environment recreation.
184 @Override
185 protected void after() {
186 disposeEnvironment();