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 .
20 import com
.sun
.star
.beans
.XPropertySet
;
21 import com
.sun
.star
.container
.XIndexAccess
;
22 import com
.sun
.star
.sheet
.XScenariosSupplier
;
23 import com
.sun
.star
.sheet
.XSpreadsheet
;
24 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
25 import com
.sun
.star
.sheet
.XSpreadsheets
;
26 import com
.sun
.star
.table
.CellAddress
;
27 import com
.sun
.star
.table
.CellRangeAddress
;
28 import com
.sun
.star
.table
.XCell
;
29 import com
.sun
.star
.table
.XCellRange
;
30 import com
.sun
.star
.uno
.AnyConverter
;
31 import com
.sun
.star
.uno
.Type
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.uno
.XInterface
;
34 import com
.sun
.star
.util
.XCloseable
;
36 import ifc
.sheet
._XCellRangesQuery
;
38 import java
.io
.PrintWriter
;
41 import lib
.TestEnvironment
;
42 import lib
.TestParameters
;
44 import util
.SOfficeFactory
;
45 import util
.ValueComparer
;
49 * Test for object which is represented by service
50 * <code>com.sun.star.sheet.Spreadsheet</code>. <p>
51 * Object implements the following interfaces :
53 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
54 * <li> <code>com::sun::star::table::XTableChartsSupplier</code></li>
55 * <li> <code>com::sun::star::sheet::XSpreadsheet</code></li>
56 * <li> <code>com::sun::star::table::CellProperties</code></li>
57 * <li> <code>com::sun::star::sheet::XSheetAnnotationsSupplier</code></li>
58 * <li> <code>com::sun::star::table::XCellRange</code></li>
59 * <li> <code>com::sun::star::sheet::XCellRangeAddressable</code></li>
60 * <li> <code>com::sun::star::sheet::XDataPilotTablesSupplier</code></li>
61 * <li> <code>com::sun::star::sheet::Spreadsheet</code></li>
62 * <li> <code>com::sun::star::sheet::XCellRangeMovement</code></li>
63 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
64 * <li> <code>com::sun::star::sheet::XSheetOperation</code></li>
65 * <li> <code>com::sun::star::sheet::XScenariosSupplier</code></li>
66 * <li> <code>com::sun::star::sheet::XSheetPageBreak</code></li>
67 * <li> <code>com::sun::star::sheet::XArrayFormulaRange</code></li>
68 * <li> <code>com::sun::star::sheet::XSheetCellRange</code></li>
69 * <li> <code>com::sun::star::container::XNamed</code></li>
70 * <li> <code>com::sun::star::sheet::SheetCellRange</code></li>
71 * <li> <code>com::sun::star::chart::XChartData</code></li>
72 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
73 * <li> <code>com::sun::star::util::XMergeable</code></li>
74 * <li> <code>com::sun::star::table::XColumnRowRange</code></li>
76 * @see com.sun.star.style.ParagraphProperties
77 * @see com.sun.star.table.XTableChartsSupplier
78 * @see com.sun.star.sheet.XSpreadsheet
79 * @see com.sun.star.table.CellProperties
80 * @see com.sun.star.sheet.XSheetAnnotationsSupplier
81 * @see com.sun.star.table.XCellRange
82 * @see com.sun.star.sheet.XCellRangeAddressable
83 * @see com.sun.star.sheet.XDataPilotTablesSupplier
84 * @see com.sun.star.sheet.Spreadsheet
85 * @see com.sun.star.sheet.XCellRangeMovement
86 * @see com.sun.star.style.CharacterProperties
87 * @see com.sun.star.sheet.XSheetOperation
88 * @see com.sun.star.sheet.XScenariosSupplier
89 * @see com.sun.star.sheet.XSheetPageBreak
90 * @see com.sun.star.sheet.XArrayFormulaRange
91 * @see com.sun.star.sheet.XSheetCellRange
92 * @see com.sun.star.container.XNamed
93 * @see com.sun.star.sheet.SheetCellRange
94 * @see com.sun.star.chart.XChartData
95 * @see com.sun.star.beans.XPropertySet
96 * @see com.sun.star.util.XMergeable
97 * @see com.sun.star.table.XColumnRowRange
98 * @see ifc.style._ParagraphProperties
99 * @see ifc.table._XTableChartsSupplier
100 * @see ifc.sheet._XSpreadsheet
101 * @see ifc.table._CellProperties
102 * @see ifc.sheet._XSheetAnnotationsSupplier
103 * @see ifc.table._XCellRange
104 * @see ifc.sheet._XCellRangeAddressable
105 * @see ifc.sheet._XDataPilotTablesSupplier
106 * @see ifc.sheet._Spreadsheet
107 * @see ifc.sheet._XCellRangeMovement
108 * @see ifc.style._CharacterProperties
109 * @see ifc.sheet._XSheetOperation
110 * @see ifc.sheet._XScenariosSupplier
111 * @see ifc.sheet._XSheetPageBreak
112 * @see ifc.sheet._XArrayFormulaRange
113 * @see ifc.sheet._XSheetCellRange
114 * @see ifc.container._XNamed
115 * @see ifc.sheet._SheetCellRange
116 * @see ifc.chart._XChartData
117 * @see ifc.beans._XPropertySet
118 * @see ifc.util._XMergeable
119 * @see ifc.table._XColumnRowRange
121 public class ScTableSheetObj
extends TestCase
{
122 private XSpreadsheetDocument xSheetDoc
= null;
125 * Creates Spreadsheet document.
128 protected void initialize(TestParameters tParam
, PrintWriter log
) throws Exception
{
129 // get a soffice factory object
130 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
133 log
.println("creating a sheetdocument");
134 xSheetDoc
= SOF
.createCalcDoc(null);
138 * Disposes Spreadsheet document.
141 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
142 log
.println(" disposing xSheetDoc ");
145 XCloseable oCloser
= UnoRuntime
.queryInterface(
146 XCloseable
.class, xSheetDoc
);
148 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
149 log
.println("Couldn't close document");
150 } catch (com
.sun
.star
.lang
.DisposedException e
) {
151 log
.println("Document already disposed");
154 util
.utils
.pause(500);
156 log
.println("... Done");
160 * Creating a TestEnvironment for the interfaces to be tested.
161 * Retrieves a collection of spreadsheets from the document and takes one of
162 * them. Fills some cell in the spreadsheet. The retrieved spreadsheet is the
163 * instance of the service <code>com.sun.star.sheet.Spreadsheet</code>.
164 * Object relations created :
166 * <li> <code>'noArray'</code> for
167 * {@link ifc.sheet._XArrayFormulaRange}(to avoid the test of
168 * the interface <code>XArrayFormulaRange</code>)</li>
170 * @see com.sun.star.sheet.XArrayFormulaRange
173 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
174 PrintWriter log
) throws Exception
{
175 XInterface oObj
= null;
177 log
.println("getting sheets");
179 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets();
181 log
.println("getting a sheet");
183 XSpreadsheet oSheet
= null;
184 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(
185 XIndexAccess
.class, xSpreadsheets
);
187 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
188 new Type(XSpreadsheet
.class),
189 oIndexAccess
.getByIndex(0));
191 log
.println("filling some cells");
193 oSheet
.getCellByPosition(5, 5).setValue(15);
194 oSheet
.getCellByPosition(1, 4).setValue(10);
195 oSheet
.getCellByPosition(2, 0).setValue(-5.15);
196 oSheet
.getCellByPosition(8, 8).setFormula("= B5 + C1");
197 // fill cells for XSheetOtline::autooutline
198 oSheet
.getCellByPosition(6, 6).setValue(3);
199 oSheet
.getCellByPosition(7, 6).setValue(3);
200 oSheet
.getCellByPosition(8, 6).setFormula("= SUM(G7:H7)");
201 oSheet
.getCellByPosition(9, 6).setFormula("= G7*I7");
203 oObj
= UnoRuntime
.queryInterface(XInterface
.class, oSheet
);
205 log
.println("creating a new environment for object");
207 TestEnvironment tEnv
= new TestEnvironment(oObj
);
209 // set the address ranges of the cells (see values set above): for e.g. XSheetOutline test
210 tEnv
.addObjRelation("CellRangeAddress",
211 new CellRangeAddress((short)0, 6, 6, 8, 8));
212 tEnv
.addObjRelation("CellRangeSubAddress",
213 new CellRangeAddress((short)0, 6, 6, 7, 8));
214 // pick a cell with a formula for XSheetAuditing, a dependent cell and a precedent cell
215 tEnv
.addObjRelation("XSheetAuditing.CellAddress", new CellAddress((short)0, 8, 6));
216 tEnv
.addObjRelation("XSheetAuditing.PrecedentCellAddress", new CellAddress((short)0, 7, 6));
217 tEnv
.addObjRelation("XSheetAuditing.DependentCellAddress", new CellAddress((short)0, 9, 6));
219 // add an existing sheet for linking
220 tEnv
.addObjRelation("XSheetLinkable.LinkSheet", "ScSheetLinksObj.ods");
222 //adding Scenario and with that a ScenarioSheet-Relation for Scenario and XScenarioEnhanced
223 XScenariosSupplier scene
= UnoRuntime
.queryInterface(
224 XScenariosSupplier
.class,
225 tEnv
.getTestObject());
227 .addNewByName("Scenario",
228 new CellRangeAddress
[] {
229 new CellRangeAddress((short) 0, 0, 0, 10, 10)
232 XSpreadsheet sSheet
= null;
235 sSheet
= UnoRuntime
.queryInterface(
237 xSpreadsheets
.getByName("Scenario"));
238 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
239 log
.println("Couldn't get Scenario");
240 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
241 log
.println("Couldn't get Scenario");
244 tEnv
.addObjRelation("ScenarioSheet", sSheet
);
246 log
.println("adding ObjRelation 'noArray' to avoid the test" +
247 " 'XArrayFormulaRange'");
248 tEnv
.addObjRelation("noArray", "ScTableSheetObj");
250 XPropertySet PropSet
= UnoRuntime
.queryInterface(
251 XPropertySet
.class, oObj
);
252 tEnv
.addObjRelation("PropSet", PropSet
);
253 tEnv
.addObjRelation("SHEET", oSheet
);
255 // add expected results for the XCellRangesQuery interface test
256 String
[] expectedResults
= new String
[7];
257 expectedResults
[_XCellRangesQuery
.QUERYCOLUMNDIFFERENCES
] = "Sheet1.B5;Sheet1.C1";
258 expectedResults
[_XCellRangesQuery
.QUERYCONTENTCELLS
] = "Sheet1.B5;Sheet1.C1;Sheet1.F6";
259 expectedResults
[_XCellRangesQuery
.QUERYEMPTYCELLS
] = "Sheet1.A1 ... Sheet1.B1 ... Sheet1.B6 ... Sheet1.C2 ... Sheet1.D1 ... Sheet1.F1 ... Sheet1.F7 ... Sheet1.G1";
260 expectedResults
[_XCellRangesQuery
.QUERYFORMULACELLS
] = "Sheet1.I7:J7;Sheet1.I9";
261 expectedResults
[_XCellRangesQuery
.QUERYINTERSECTION
] = "Sheet1.D4";
262 expectedResults
[_XCellRangesQuery
.QUERYROWDIFFERENCES
] = "Sheet1.A5;Sheet1.C1";
263 expectedResults
[_XCellRangesQuery
.QUERYVISIBLECELLS
] = "Sheet1.A2";
264 tEnv
.addObjRelation("XCellRangesQuery.EXPECTEDRESULTS",
267 // for XFormulaQuery interface test
269 tEnv
.addObjRelation("MAKEENTRYINCELL",
270 oSheet
.getCellByPosition(15, 15));
271 tEnv
.addObjRelation("RANGEINDICES", new int[] { 0, 0 });
272 tEnv
.addObjRelation("EXPECTEDDEPENDENTVALUES",
273 new int[] { 0, 255, 0, 65535 });
274 tEnv
.addObjRelation("EXPECTEDPRECEDENTVALUES",
275 new int[] { 0, 255, 0, 65535 });
276 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
278 "Cannot add the necessary object relation for XFormulaQuery test.");
281 // XSearchable interface test
283 tEnv
.addObjRelation("XSearchable.MAKEENTRYINCELL",
285 oSheet
.getCellByPosition(15, 15),
286 oSheet
.getCellByPosition(15, 16)
288 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
289 e
.printStackTrace(log
);
291 "Cannot make required object relation 'XSearchable.MAKEENTRYINCELL'.");
294 //Adding relation for util.XSortable
295 final PrintWriter finalLog
= log
;
296 final XCellRange oTable
= oSheet
;
297 tEnv
.addObjRelation("SORTCHECKER",
298 new ifc
.util
._XSortable
.XSortChecker() {
299 PrintWriter out
= finalLog
;
301 public void setPrintWriter(PrintWriter log
) {
305 public void prepareToSort() {
307 oTable
.getCellByPosition(0, 0).setValue(4);
308 oTable
.getCellByPosition(0, 1).setFormula("b");
309 oTable
.getCellByPosition(0, 2).setValue(3);
310 oTable
.getCellByPosition(0, 3).setValue(23);
311 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
312 out
.println("Exception while checking sort");
316 public boolean checkSort(boolean isSortNumbering
,
317 boolean isSortAscending
) {
318 out
.println("Sort checking...");
321 String
[] value
= new String
[4];
323 for (int i
= 0; i
< 4; i
++) {
325 XCell cell
= oTable
.getCellByPosition(0, i
);
326 value
[i
] = cell
.getFormula();
327 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
328 out
.println("Exception while checking sort");
332 if (isSortNumbering
) {
333 if (isSortAscending
) {
334 out
.println("Sorting ascending");
336 String
[] rightVal
= { "3", "4", "23", "b" };
337 String
[] vals
= { value
[0], value
[1], value
[2], value
[3] };
338 res
= ValueComparer
.equalValue(vals
, rightVal
);
339 out
.println("Expected 3, 4, 23, b");
340 out
.println("getting: " + value
[0] + ", " +
341 value
[1] + ", " + value
[2] + ", " +
344 String
[] rightVal
= { "b", "23", "4", "3" };
345 String
[] vals
= { value
[0], value
[1], value
[2], value
[3] };
346 res
= ValueComparer
.equalValue(vals
, rightVal
);
347 out
.println("Expected b, 23, 4, 3");
348 out
.println("getting: " + value
[0] + ", " +
349 value
[1] + ", " + value
[2] + ", " +
353 if (isSortAscending
) {
354 String
[] rightVal
= { "3", "4", "23", "b" };
355 res
= ValueComparer
.equalValue(value
, rightVal
);
356 out
.println("Expected 3, 4, 23, b");
357 out
.println("getting: " + value
[0] + ", " +
358 value
[1] + ", " + value
[2] + ", " +
361 String
[] rightVal
= { "b", "23", "4", "3" };
362 res
= ValueComparer
.equalValue(value
, rightVal
);
363 out
.println("Expected b, 23, 4, 3");
364 out
.println("getting: " + value
[0] + ", " +
365 value
[1] + ", " + value
[2] + ", " +
371 out
.println("Sorted correctly");
373 out
.println("Sorted incorrectly");