merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScCellCursorObj.java
blobb4efa0abc3b7810a5ec93a05009cf23233b82923
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: ScCellCursorObj.java,v $
10 * $Revision: 1.11 $
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 ************************************************************************/
30 package mod._sc;
31 import java.io.PrintWriter;
33 import lib.StatusException;
34 import lib.TestCase;
35 import lib.TestEnvironment;
36 import lib.TestParameters;
37 import util.SOfficeFactory;
38 import util.ValueComparer;
40 import com.sun.star.beans.XPropertySet;
41 import com.sun.star.lang.XComponent;
42 import com.sun.star.lang.XMultiServiceFactory;
43 import com.sun.star.sheet.XSheetCellRange;
44 import com.sun.star.sheet.XSpreadsheet;
45 import com.sun.star.sheet.XSpreadsheetDocument;
46 import com.sun.star.sheet.XSpreadsheets;
47 import com.sun.star.table.XCell;
48 import com.sun.star.table.XCellRange;
49 import com.sun.star.uno.AnyConverter;
50 import com.sun.star.uno.Type;
51 import com.sun.star.uno.UnoRuntime;
52 import com.sun.star.uno.XInterface;
53 import ifc.sheet._XCellRangesQuery;
56 /**
57 * Test for object which is represented by service
58 * <code>com.sun.star.sheet.SheetCellCursor</code>. <p>
59 * Object implements the following interfaces :
60 * <ul>
61 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
62 * <li> <code>com::sun::star::sheet::XUsedAreaCursor</code></li>
63 * <li> <code>com::sun::star::table::CellProperties</code></li>
64 * <li> <code>com::sun::star::table::XCellRange</code></li>
65 * <li> <code>com::sun::star::sheet::XCellRangeAddressable</code></li>
66 * <li> <code>com::sun::star::table::XCellCursor</code></li>
67 * <li> <code>com::sun::star::sheet::XSheetCellCursor</code></li>
68 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
69 * <li> <code>com::sun::star::sheet::XSheetOperation</code></li>
70 * <li> <code>com::sun::star::sheet::XArrayFormulaRange</code></li>
71 * <li> <code>com::sun::star::sheet::XSheetCellRange</code></li>
72 * <li> <code>com::sun::star::sheet::SheetCellRange</code></li>
73 * <li> <code>com::sun::star::chart::XChartData</code></li>
74 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
75 * <li> <code>com::sun::star::util::XMergeable</code></li>
76 * <li> <code>com::sun::star::table::XColumnRowRange</code></li>
77 * </ul>
78 * @see com.sun.star.sheet.SheetCellCursor
79 * @see com.sun.star.style.ParagraphProperties
80 * @see com.sun.star.sheet.XUsedAreaCursor
81 * @see com.sun.star.table.CellProperties
82 * @see com.sun.star.table.XCellRange
83 * @see com.sun.star.sheet.XCellRangeAddressable
84 * @see com.sun.star.table.XCellCursor
85 * @see com.sun.star.sheet.XSheetCellCursor
86 * @see com.sun.star.style.CharacterProperties
87 * @see com.sun.star.sheet.XSheetOperation
88 * @see com.sun.star.sheet.XArrayFormulaRange
89 * @see com.sun.star.sheet.XSheetCellRange
90 * @see com.sun.star.sheet.SheetCellRange
91 * @see com.sun.star.chart.XChartData
92 * @see com.sun.star.beans.XPropertySet
93 * @see com.sun.star.util.XMergeable
94 * @see com.sun.star.table.XColumnRowRange
95 * @see ifc.style._ParagraphProperties
96 * @see ifc.sheet._XUsedAreaCursor
97 * @see ifc.table._CellProperties
98 * @see ifc.table._XCellRange
99 * @see ifc.sheet._XCellRangeAddressable
100 * @see ifc.table._XCellCursor
101 * @see ifc.sheet._XSheetCellCursor
102 * @see ifc.style._CharacterProperties
103 * @see ifc.sheet._XSheetOperation
104 * @see ifc.sheet._XArrayFormulaRange
105 * @see ifc.sheet._XSheetCellRange
106 * @see ifc.sheet._SheetCellRange
107 * @see ifc.chart._XChartData
108 * @see ifc.beans._XPropertySet
109 * @see ifc.util._XMergeable
110 * @see ifc.table._XColumnRowRange
112 public class ScCellCursorObj extends TestCase {
113 static XSpreadsheetDocument xSheetDoc = null;
116 * Creates Spreadsheet document.
118 protected void initialize(TestParameters tParam, PrintWriter log) {
119 SOfficeFactory SOF = SOfficeFactory.getFactory(
120 (XMultiServiceFactory) tParam.getMSF());
122 try {
123 log.println("creating a Spreadsheet document");
124 xSheetDoc = SOF.createCalcDoc(null);
125 } catch (com.sun.star.uno.Exception e) {
126 // Some exception occures.FAILED
127 e.printStackTrace(log);
128 throw new StatusException("Couldn't create document", e);
133 * Disposes Spreadsheet document.
135 protected void cleanup(TestParameters tParam, PrintWriter log) {
136 log.println(" disposing xSheetDoc ");
138 XComponent oComp = (XComponent) UnoRuntime.queryInterface(
139 XComponent.class, xSheetDoc);
141 util.DesktopTools.closeDoc(oComp);
145 * Creating a Testenvironment for the interfaces to be tested.
146 * Retrieves a collection of spreadsheets from a document,
147 * and takes one of them, retrieves some cell range and creates cursor range
148 * that is instance of the service
149 * <code>com.sun.star.sheet.SheetCellCursor</code>,
150 * fills some cells in the cell range.
151 * Object relations created :
152 * <ul>
153 * <li> <code>'SHEET'</code> for
154 * {@link ifc.table._XCellCursor},
155 * {@link ifc.sheet._XArrayFormulaRange} (the spreadsheet that was
156 * retieved from collection)</li>
157 * </ul>
159 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
160 PrintWriter log) {
161 XInterface oObj = null;
162 TestEnvironment tEnv = null;
163 XSpreadsheet oSheet = null;
164 XCellRange testRange = null;
167 // creation of testobject here
168 // first we write what we are intend to do to log file
169 log.println("Creating a test environment");
171 XSpreadsheets oSpreadsheets = ((XSpreadsheetDocument) UnoRuntime.queryInterface(
172 XSpreadsheetDocument.class,
173 xSheetDoc)).getSheets();
175 try {
176 oSheet = (XSpreadsheet) AnyConverter.toObject(
177 new Type(XSpreadsheet.class),
178 oSpreadsheets.getByName(
179 oSpreadsheets.getElementNames()[0]));
181 testRange = oSheet.getCellRangeByName("$A$1:$D$4");
183 XSheetCellRange testSheetRange = (XSheetCellRange) UnoRuntime.queryInterface(
184 XSheetCellRange.class,
185 testRange);
186 oObj = oSheet.createCursorByRange(testSheetRange);
187 oSheet.getCellByPosition(1, 1).setValue(1);
188 oSheet.getCellByPosition(4, 5).setValue(1);
189 oSheet.getCellByPosition(3, 2).setFormula("xTextDoc");
190 oSheet.getCellByPosition(3, 3).setFormula("xTextDoc");
191 } catch (com.sun.star.lang.WrappedTargetException e) {
192 log.println("Exception occured while creating test object:");
193 e.printStackTrace(log);
194 throw new StatusException("Couldn't create test object", e);
195 } catch (com.sun.star.container.NoSuchElementException e) {
196 log.println("Exception occured while creating test object:");
197 e.printStackTrace(log);
198 throw new StatusException("Couldn't create test object", e);
199 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
200 log.println("Exception occured while creating test object:");
201 e.printStackTrace(log);
202 throw new StatusException("Couldn't create test object", e);
203 } catch (com.sun.star.lang.IllegalArgumentException e) {
204 log.println("Exception occured while creating test object:");
205 e.printStackTrace(log);
206 throw new StatusException("Couldn't create test object", e);
209 log.println("Test object successfully created.");
211 tEnv = new TestEnvironment(oObj);
213 tEnv.addObjRelation("CRDESC",
214 "Column and RowDescriptions can't be changed for this Object");
216 tEnv.addObjRelation("SHEET", oSheet);
217 // add expected results for the XCellRangesQuery interface test
218 String[]expectedResults = new String[7];
219 expectedResults[_XCellRangesQuery.QUERYCOLUMNDIFFERENCES] = "Sheet1.B1";
220 expectedResults[_XCellRangesQuery.QUERYCONTENTCELLS] = "Sheet1.B2";
221 expectedResults[_XCellRangesQuery.QUERYEMPTYCELLS] = "Sheet1.A1 ... Sheet1.B1 ... Sheet1.B3 ... Sheet1.C1 ... Sheet1.D1";
222 expectedResults[_XCellRangesQuery.QUERYFORMULACELLS] = "";
223 expectedResults[_XCellRangesQuery.QUERYINTERSECTION] = "Sheet1.D4";
224 expectedResults[_XCellRangesQuery.QUERYROWDIFFERENCES] = "Sheet1.A2;Sheet1.C2";
225 expectedResults[_XCellRangesQuery.QUERYVISIBLECELLS] = "Sheet1.A2";
226 tEnv.addObjRelation("XCellRangesQuery.EXPECTEDRESULTS", expectedResults);
228 tEnv.addObjRelation("NewData",
229 new Object[][]
231 { "", "", "", "" },
232 { "", "2", "3", "4" },
233 { "", "2", "3", "4" },
234 { "", "2", "3", "4" }
237 XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(
238 XPropertySet.class, oObj);
239 tEnv.addObjRelation("PropSet", PropSet);
241 //Adding relation for util.XSortable
242 final PrintWriter finalLog = log;
243 final XCellRange oTable = testRange;
244 tEnv.addObjRelation("SORTCHECKER",
245 new ifc.util._XSortable.XSortChecker() {
246 PrintWriter out = finalLog;
248 public void setPrintWriter(PrintWriter log) {
249 out = log;
252 public void prepareToSort() {
253 try {
254 oTable.getCellByPosition(0, 0).setValue(4);
255 oTable.getCellByPosition(0, 1).setFormula("b");
256 oTable.getCellByPosition(0, 2).setValue(3);
257 oTable.getCellByPosition(0, 3).setValue(23);
258 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
259 out.println("Exception while checking sort");
263 public boolean checkSort(boolean isSortNumbering,
264 boolean isSortAscending) {
265 out.println("Sort checking...");
267 boolean res = false;
268 String[] value = new String[4];
270 for (int i = 0; i < 4; i++) {
271 try {
272 XCell cell = oTable.getCellByPosition(0, i);
273 value[i] = cell.getFormula();
274 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
275 out.println("Exception while checking sort");
279 if (isSortNumbering) {
280 if (isSortAscending) {
281 out.println("Sorting ascending");
283 String[] rightVal = { "3", "4", "23", "b" };
284 String[] vals = { value[0], value[1], value[2], value[3] };
285 res = ValueComparer.equalValue(vals, rightVal);
286 out.println("Expected 3, 4, 23, b");
287 out.println("getting: " + value[0] + ", " +
288 value[1] + ", " + value[2] + ", " +
289 value[3]);
290 } else {
291 String[] rightVal = { "b", "23", "4", "3" };
292 String[] vals = { value[0], value[1], value[2], value[3] };
293 res = ValueComparer.equalValue(vals, rightVal);
294 out.println("Expected b, 23, 4, 3");
295 out.println("getting: " + value[0] + ", " +
296 value[1] + ", " + value[2] + ", " +
297 value[3]);
299 } else {
300 if (isSortAscending) {
301 String[] rightVal = { "3", "4", "23", "b" };
302 res = ValueComparer.equalValue(value, rightVal);
303 out.println("Expected 3, 4, 23, b");
304 out.println("getting: " + value[0] + ", " +
305 value[1] + ", " + value[2] + ", " +
306 value[3]);
307 } else {
308 String[] rightVal = { "b", "23", "4", "3" };
309 res = ValueComparer.equalValue(value, rightVal);
310 out.println("Expected b, 23, 4, 3");
311 out.println("getting: " + value[0] + ", " +
312 value[1] + ", " + value[2] + ", " +
313 value[3]);
317 if (res) {
318 out.println("Sorted correctly");
319 } else {
320 out.println("Sorted uncorrectly");
323 return res;
327 return tEnv;
329 } // finish class ScCellCursorObj