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