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 import java
.io
.PrintWriter
;
21 import lib
.StatusException
;
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
.lang
.XMultiServiceFactory
;
31 import com
.sun
.star
.sheet
.XSheetCellRange
;
32 import com
.sun
.star
.sheet
.XSpreadsheet
;
33 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
34 import com
.sun
.star
.sheet
.XSpreadsheets
;
35 import com
.sun
.star
.table
.XCell
;
36 import com
.sun
.star
.table
.XCellRange
;
37 import com
.sun
.star
.uno
.AnyConverter
;
38 import com
.sun
.star
.uno
.Type
;
39 import com
.sun
.star
.uno
.UnoRuntime
;
40 import com
.sun
.star
.uno
.XInterface
;
41 import ifc
.sheet
._XCellRangesQuery
;
45 * Test for object which is represented by service
46 * <code>com.sun.star.sheet.SheetCellCursor</code>. <p>
47 * Object implements the following interfaces :
49 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
50 * <li> <code>com::sun::star::sheet::XUsedAreaCursor</code></li>
51 * <li> <code>com::sun::star::table::CellProperties</code></li>
52 * <li> <code>com::sun::star::table::XCellRange</code></li>
53 * <li> <code>com::sun::star::sheet::XCellRangeAddressable</code></li>
54 * <li> <code>com::sun::star::table::XCellCursor</code></li>
55 * <li> <code>com::sun::star::sheet::XSheetCellCursor</code></li>
56 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
57 * <li> <code>com::sun::star::sheet::XSheetOperation</code></li>
58 * <li> <code>com::sun::star::sheet::XArrayFormulaRange</code></li>
59 * <li> <code>com::sun::star::sheet::XSheetCellRange</code></li>
60 * <li> <code>com::sun::star::sheet::SheetCellRange</code></li>
61 * <li> <code>com::sun::star::chart::XChartData</code></li>
62 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
63 * <li> <code>com::sun::star::util::XMergeable</code></li>
64 * <li> <code>com::sun::star::table::XColumnRowRange</code></li>
66 * @see com.sun.star.sheet.SheetCellCursor
67 * @see com.sun.star.style.ParagraphProperties
68 * @see com.sun.star.sheet.XUsedAreaCursor
69 * @see com.sun.star.table.CellProperties
70 * @see com.sun.star.table.XCellRange
71 * @see com.sun.star.sheet.XCellRangeAddressable
72 * @see com.sun.star.table.XCellCursor
73 * @see com.sun.star.sheet.XSheetCellCursor
74 * @see com.sun.star.style.CharacterProperties
75 * @see com.sun.star.sheet.XSheetOperation
76 * @see com.sun.star.sheet.XArrayFormulaRange
77 * @see com.sun.star.sheet.XSheetCellRange
78 * @see com.sun.star.sheet.SheetCellRange
79 * @see com.sun.star.chart.XChartData
80 * @see com.sun.star.beans.XPropertySet
81 * @see com.sun.star.util.XMergeable
82 * @see com.sun.star.table.XColumnRowRange
83 * @see ifc.style._ParagraphProperties
84 * @see ifc.sheet._XUsedAreaCursor
85 * @see ifc.table._CellProperties
86 * @see ifc.table._XCellRange
87 * @see ifc.sheet._XCellRangeAddressable
88 * @see ifc.table._XCellCursor
89 * @see ifc.sheet._XSheetCellCursor
90 * @see ifc.style._CharacterProperties
91 * @see ifc.sheet._XSheetOperation
92 * @see ifc.sheet._XArrayFormulaRange
93 * @see ifc.sheet._XSheetCellRange
94 * @see ifc.sheet._SheetCellRange
95 * @see ifc.chart._XChartData
96 * @see ifc.beans._XPropertySet
97 * @see ifc.util._XMergeable
98 * @see ifc.table._XColumnRowRange
100 public class ScCellCursorObj
extends TestCase
{
101 private XSpreadsheetDocument xSheetDoc
= null;
104 * Creates Spreadsheet document.
106 protected void initialize(TestParameters tParam
, PrintWriter log
) {
107 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
108 (XMultiServiceFactory
) tParam
.getMSF());
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 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
124 log
.println(" disposing xSheetDoc ");
126 XComponent oComp
= UnoRuntime
.queryInterface(
127 XComponent
.class, xSheetDoc
);
129 util
.DesktopTools
.closeDoc(oComp
);
133 * Creating a Testenvironment for the interfaces to be tested.
134 * Retrieves a collection of spreadsheets from a document,
135 * and takes one of them, retrieves some cell range and creates cursor range
136 * that is instance of the service
137 * <code>com.sun.star.sheet.SheetCellCursor</code>,
138 * fills some cells in the cell range.
139 * Object relations created :
141 * <li> <code>'SHEET'</code> for
142 * {@link ifc.table._XCellCursor},
143 * {@link ifc.sheet._XArrayFormulaRange} (the spreadsheet that was
144 * retieved from collection)</li>
147 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
,
149 XInterface oObj
= null;
150 TestEnvironment tEnv
= null;
151 XSpreadsheet oSheet
= null;
152 XCellRange testRange
= null;
155 // creation of testobject here
156 // first we write what we are intend to do to log file
157 log
.println("Creating a test environment");
159 XSpreadsheets oSpreadsheets
= UnoRuntime
.queryInterface(
160 XSpreadsheetDocument
.class,
161 xSheetDoc
).getSheets();
164 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
165 new Type(XSpreadsheet
.class),
166 oSpreadsheets
.getByName(
167 oSpreadsheets
.getElementNames()[0]));
169 testRange
= oSheet
.getCellRangeByName("$A$1:$D$4");
171 XSheetCellRange testSheetRange
= UnoRuntime
.queryInterface(
172 XSheetCellRange
.class,
174 oObj
= oSheet
.createCursorByRange(testSheetRange
);
175 oSheet
.getCellByPosition(1, 1).setValue(1);
176 oSheet
.getCellByPosition(4, 5).setValue(1);
177 oSheet
.getCellByPosition(3, 2).setFormula("xTextDoc");
178 oSheet
.getCellByPosition(3, 3).setFormula("xTextDoc");
179 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
180 log
.println("Exception occurred while creating test object:");
181 e
.printStackTrace(log
);
182 throw new StatusException("Couldn't create test object", e
);
183 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
184 log
.println("Exception occurred while creating test object:");
185 e
.printStackTrace(log
);
186 throw new StatusException("Couldn't create test object", e
);
187 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
188 log
.println("Exception occurred while creating test object:");
189 e
.printStackTrace(log
);
190 throw new StatusException("Couldn't create test object", e
);
191 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
192 log
.println("Exception occurred while creating test object:");
193 e
.printStackTrace(log
);
194 throw new StatusException("Couldn't create test object", e
);
197 log
.println("Test object successfully created.");
199 tEnv
= new TestEnvironment(oObj
);
201 tEnv
.addObjRelation("CRDESC",
202 "Column and RowDescriptions can't be changed for this Object");
204 tEnv
.addObjRelation("SHEET", oSheet
);
205 // add expected results for the XCellRangesQuery interface test
206 String
[]expectedResults
= new String
[7];
207 expectedResults
[_XCellRangesQuery
.QUERYCOLUMNDIFFERENCES
] = "Sheet1.B1";
208 expectedResults
[_XCellRangesQuery
.QUERYCONTENTCELLS
] = "Sheet1.B2";
209 expectedResults
[_XCellRangesQuery
.QUERYEMPTYCELLS
] = "Sheet1.A1 ... Sheet1.B1 ... Sheet1.B3 ... Sheet1.C1 ... Sheet1.D1";
210 expectedResults
[_XCellRangesQuery
.QUERYFORMULACELLS
] = "";
211 expectedResults
[_XCellRangesQuery
.QUERYINTERSECTION
] = "Sheet1.D4";
212 expectedResults
[_XCellRangesQuery
.QUERYROWDIFFERENCES
] = "Sheet1.A2;Sheet1.C2";
213 expectedResults
[_XCellRangesQuery
.QUERYVISIBLECELLS
] = "Sheet1.A2";
214 tEnv
.addObjRelation("XCellRangesQuery.EXPECTEDRESULTS", expectedResults
);
216 tEnv
.addObjRelation("NewData",
220 { "", "2", "3", "4" },
221 { "", "2", "3", "4" },
222 { "", "2", "3", "4" }
225 XPropertySet PropSet
= UnoRuntime
.queryInterface(
226 XPropertySet
.class, oObj
);
227 tEnv
.addObjRelation("PropSet", PropSet
);
229 //Adding relation for util.XSortable
230 final PrintWriter finalLog
= log
;
231 final XCellRange oTable
= testRange
;
232 tEnv
.addObjRelation("SORTCHECKER",
233 new ifc
.util
._XSortable
.XSortChecker() {
234 PrintWriter out
= finalLog
;
236 public void setPrintWriter(PrintWriter log
) {
240 public void prepareToSort() {
242 oTable
.getCellByPosition(0, 0).setValue(4);
243 oTable
.getCellByPosition(0, 1).setFormula("b");
244 oTable
.getCellByPosition(0, 2).setValue(3);
245 oTable
.getCellByPosition(0, 3).setValue(23);
246 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
247 out
.println("Exception while checking sort");
251 public boolean checkSort(boolean isSortNumbering
,
252 boolean isSortAscending
) {
253 out
.println("Sort checking...");
256 String
[] value
= new String
[4];
258 for (int i
= 0; i
< 4; i
++) {
260 XCell cell
= oTable
.getCellByPosition(0, i
);
261 value
[i
] = cell
.getFormula();
262 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
263 out
.println("Exception while checking sort");
267 if (isSortNumbering
) {
268 if (isSortAscending
) {
269 out
.println("Sorting ascending");
271 String
[] rightVal
= { "3", "4", "23", "b" };
272 String
[] vals
= { value
[0], value
[1], value
[2], value
[3] };
273 res
= ValueComparer
.equalValue(vals
, rightVal
);
274 out
.println("Expected 3, 4, 23, b");
275 out
.println("getting: " + value
[0] + ", " +
276 value
[1] + ", " + value
[2] + ", " +
279 String
[] rightVal
= { "b", "23", "4", "3" };
280 String
[] vals
= { value
[0], value
[1], value
[2], value
[3] };
281 res
= ValueComparer
.equalValue(vals
, rightVal
);
282 out
.println("Expected b, 23, 4, 3");
283 out
.println("getting: " + value
[0] + ", " +
284 value
[1] + ", " + value
[2] + ", " +
288 if (isSortAscending
) {
289 String
[] rightVal
= { "3", "4", "23", "b" };
290 res
= ValueComparer
.equalValue(value
, rightVal
);
291 out
.println("Expected 3, 4, 23, b");
292 out
.println("getting: " + value
[0] + ", " +
293 value
[1] + ", " + value
[2] + ", " +
296 String
[] rightVal
= { "b", "23", "4", "3" };
297 res
= ValueComparer
.equalValue(value
, rightVal
);
298 out
.println("Expected b, 23, 4, 3");
299 out
.println("getting: " + value
[0] + ", " +
300 value
[1] + ", " + value
[2] + ", " +
306 out
.println("Sorted correctly");
308 out
.println("Sorted uncorrectly");
317 } // finish class ScCellCursorObj