1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package mod._sc;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
26cdf0e10cSrcweir import com.sun.star.container.XIndexAccess;
27cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
28cdf0e10cSrcweir import com.sun.star.sheet.XScenariosSupplier;
29cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheet;
30cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheetDocument;
31cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheets;
32cdf0e10cSrcweir import com.sun.star.table.CellAddress;
33cdf0e10cSrcweir import com.sun.star.table.CellRangeAddress;
34cdf0e10cSrcweir import com.sun.star.table.XCell;
35cdf0e10cSrcweir import com.sun.star.table.XCellRange;
36cdf0e10cSrcweir import com.sun.star.uno.AnyConverter;
37cdf0e10cSrcweir import com.sun.star.uno.Type;
38cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
39cdf0e10cSrcweir import com.sun.star.uno.XInterface;
40cdf0e10cSrcweir import com.sun.star.util.XCloseable;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir import ifc.sheet._XCellRangesQuery;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir import java.io.PrintWriter;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir import lib.StatusException;
47cdf0e10cSrcweir import lib.TestCase;
48cdf0e10cSrcweir import lib.TestEnvironment;
49cdf0e10cSrcweir import lib.TestParameters;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir import util.SOfficeFactory;
52cdf0e10cSrcweir import util.ValueComparer;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 
55cdf0e10cSrcweir /**
56cdf0e10cSrcweir * Test for object which is represented by service
57cdf0e10cSrcweir * <code>com.sun.star.sheet.Spreadsheet</code>. <p>
58cdf0e10cSrcweir * Object implements the following interfaces :
59cdf0e10cSrcweir * <ul>
60cdf0e10cSrcweir *  <li> <code>com::sun::star::style::ParagraphProperties</code></li>
61cdf0e10cSrcweir *  <li> <code>com::sun::star::table::XTableChartsSupplier</code></li>
62cdf0e10cSrcweir *  <li> <code>com::sun::star::sheet::XSpreadsheet</code></li>
63cdf0e10cSrcweir *  <li> <code>com::sun::star::table::CellProperties</code></li>
64cdf0e10cSrcweir *  <li> <code>com::sun::star::sheet::XSheetAnnotationsSupplier</code></li>
65cdf0e10cSrcweir *  <li> <code>com::sun::star::table::XCellRange</code></li>
66cdf0e10cSrcweir *  <li> <code>com::sun::star::sheet::XCellRangeAddressable</code></li>
67cdf0e10cSrcweir *  <li> <code>com::sun::star::sheet::XDataPilotTablesSupplier</code></li>
68cdf0e10cSrcweir *  <li> <code>com::sun::star::sheet::Spreadsheet</code></li>
69cdf0e10cSrcweir *  <li> <code>com::sun::star::sheet::XCellRangeMovement</code></li>
70cdf0e10cSrcweir *  <li> <code>com::sun::star::style::CharacterProperties</code></li>
71cdf0e10cSrcweir *  <li> <code>com::sun::star::sheet::XSheetOperation</code></li>
72cdf0e10cSrcweir *  <li> <code>com::sun::star::sheet::XScenariosSupplier</code></li>
73cdf0e10cSrcweir *  <li> <code>com::sun::star::sheet::XSheetPageBreak</code></li>
74cdf0e10cSrcweir *  <li> <code>com::sun::star::sheet::XArrayFormulaRange</code></li>
75cdf0e10cSrcweir *  <li> <code>com::sun::star::sheet::XSheetCellRange</code></li>
76cdf0e10cSrcweir *  <li> <code>com::sun::star::container::XNamed</code></li>
77cdf0e10cSrcweir *  <li> <code>com::sun::star::sheet::SheetCellRange</code></li>
78cdf0e10cSrcweir *  <li> <code>com::sun::star::chart::XChartData</code></li>
79cdf0e10cSrcweir *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
80cdf0e10cSrcweir *  <li> <code>com::sun::star::util::XMergeable</code></li>
81cdf0e10cSrcweir *  <li> <code>com::sun::star::table::XColumnRowRange</code></li>
82cdf0e10cSrcweir * </ul>
83cdf0e10cSrcweir * @see com.sun.star.style.ParagraphProperties
84cdf0e10cSrcweir * @see com.sun.star.table.XTableChartsSupplier
85cdf0e10cSrcweir * @see com.sun.star.sheet.XSpreadsheet
86cdf0e10cSrcweir * @see com.sun.star.table.CellProperties
87cdf0e10cSrcweir * @see com.sun.star.sheet.XSheetAnnotationsSupplier
88cdf0e10cSrcweir * @see com.sun.star.table.XCellRange
89cdf0e10cSrcweir * @see com.sun.star.sheet.XCellRangeAddressable
90cdf0e10cSrcweir * @see com.sun.star.sheet.XDataPilotTablesSupplier
91cdf0e10cSrcweir * @see com.sun.star.sheet.Spreadsheet
92cdf0e10cSrcweir * @see com.sun.star.sheet.XCellRangeMovement
93cdf0e10cSrcweir * @see com.sun.star.style.CharacterProperties
94cdf0e10cSrcweir * @see com.sun.star.sheet.XSheetOperation
95cdf0e10cSrcweir * @see com.sun.star.sheet.XScenariosSupplier
96cdf0e10cSrcweir * @see com.sun.star.sheet.XSheetPageBreak
97cdf0e10cSrcweir * @see com.sun.star.sheet.XArrayFormulaRange
98cdf0e10cSrcweir * @see com.sun.star.sheet.XSheetCellRange
99cdf0e10cSrcweir * @see com.sun.star.container.XNamed
100cdf0e10cSrcweir * @see com.sun.star.sheet.SheetCellRange
101cdf0e10cSrcweir * @see com.sun.star.chart.XChartData
102cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet
103cdf0e10cSrcweir * @see com.sun.star.util.XMergeable
104cdf0e10cSrcweir * @see com.sun.star.table.XColumnRowRange
105cdf0e10cSrcweir * @see ifc.style._ParagraphProperties
106cdf0e10cSrcweir * @see ifc.table._XTableChartsSupplier
107cdf0e10cSrcweir * @see ifc.sheet._XSpreadsheet
108cdf0e10cSrcweir * @see ifc.table._CellProperties
109cdf0e10cSrcweir * @see ifc.sheet._XSheetAnnotationsSupplier
110cdf0e10cSrcweir * @see ifc.table._XCellRange
111cdf0e10cSrcweir * @see ifc.sheet._XCellRangeAddressable
112cdf0e10cSrcweir * @see ifc.sheet._XDataPilotTablesSupplier
113cdf0e10cSrcweir * @see ifc.sheet._Spreadsheet
114cdf0e10cSrcweir * @see ifc.sheet._XCellRangeMovement
115cdf0e10cSrcweir * @see ifc.style._CharacterProperties
116cdf0e10cSrcweir * @see ifc.sheet._XSheetOperation
117cdf0e10cSrcweir * @see ifc.sheet._XScenariosSupplier
118cdf0e10cSrcweir * @see ifc.sheet._XSheetPageBreak
119cdf0e10cSrcweir * @see ifc.sheet._XArrayFormulaRange
120cdf0e10cSrcweir * @see ifc.sheet._XSheetCellRange
121cdf0e10cSrcweir * @see ifc.container._XNamed
122cdf0e10cSrcweir * @see ifc.sheet._SheetCellRange
123cdf0e10cSrcweir * @see ifc.chart._XChartData
124cdf0e10cSrcweir * @see ifc.beans._XPropertySet
125cdf0e10cSrcweir * @see ifc.util._XMergeable
126cdf0e10cSrcweir * @see ifc.table._XColumnRowRange
127cdf0e10cSrcweir */
128cdf0e10cSrcweir public class ScTableSheetObj extends TestCase {
129cdf0e10cSrcweir     static XSpreadsheetDocument xSheetDoc = null;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     /**
132cdf0e10cSrcweir     * Creates Spreadsheet document.
133cdf0e10cSrcweir     */
initialize(TestParameters tParam, PrintWriter log)134cdf0e10cSrcweir     protected void initialize(TestParameters tParam, PrintWriter log) {
135cdf0e10cSrcweir         // get a soffice factory object
136cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory(
137cdf0e10cSrcweir                                      (XMultiServiceFactory) tParam.getMSF());
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         try {
140cdf0e10cSrcweir             log.println("creating a sheetdocument");
141cdf0e10cSrcweir             xSheetDoc = SOF.createCalcDoc(null);
142cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
143cdf0e10cSrcweir             // Some exception occures.FAILED
144cdf0e10cSrcweir             e.printStackTrace(log);
145cdf0e10cSrcweir             throw new StatusException("Couldn't create document", e);
146cdf0e10cSrcweir         }
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     /**
150cdf0e10cSrcweir     * Disposes Spreadsheet document.
151cdf0e10cSrcweir     */
cleanup(TestParameters tParam, PrintWriter log)152cdf0e10cSrcweir     protected void cleanup(TestParameters tParam, PrintWriter log) {
153cdf0e10cSrcweir         log.println("    disposing xSheetDoc ");
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         try {
156cdf0e10cSrcweir             XCloseable oCloser = (XCloseable) UnoRuntime.queryInterface(
157cdf0e10cSrcweir                                          XCloseable.class, xSheetDoc);
158cdf0e10cSrcweir             oCloser.close(true);
159cdf0e10cSrcweir         } catch (com.sun.star.util.CloseVetoException e) {
160cdf0e10cSrcweir             log.println("Couldn't close document");
161cdf0e10cSrcweir         } catch (com.sun.star.lang.DisposedException e) {
162cdf0e10cSrcweir             log.println("Document already disposed");
163cdf0e10cSrcweir         } catch (java.lang.NullPointerException e) {
164cdf0e10cSrcweir             log.println("Couldn't get XCloseable");
165cdf0e10cSrcweir         }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir         try {
168cdf0e10cSrcweir             log.println("Sleeping 500 Millis");
169cdf0e10cSrcweir             Thread.sleep(500);
170cdf0e10cSrcweir         } catch (InterruptedException ex) {
171cdf0e10cSrcweir         }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir         log.println("... Done");
174cdf0e10cSrcweir     }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     /**
177cdf0e10cSrcweir     * Creating a Testenvironment for the interfaces to be tested.
178cdf0e10cSrcweir     * Retrieves a collection of spreadsheets from the document and takes one of
179cdf0e10cSrcweir     * them. Fills some cell in the spreadsheet. The retrieved spreadsheet is the
180cdf0e10cSrcweir     * instance of the service <code>com.sun.star.sheet.Spreadsheet</code>.
181cdf0e10cSrcweir     * Object relations created :
182cdf0e10cSrcweir     * <ul>
183cdf0e10cSrcweir     *  <li> <code>'noArray'</code> for
184cdf0e10cSrcweir     *      {@link ifc.sheet._XArrayFormulaRange}(to avoid the test of
185cdf0e10cSrcweir     *      the interface <code>XArrayFormulaRange</code>)</li>
186cdf0e10cSrcweir     * </ul>
187cdf0e10cSrcweir     * @see com.sun.star.sheet.XArrayFormulaRange
188cdf0e10cSrcweir     */
createTestEnvironment(TestParameters Param, PrintWriter log)189cdf0e10cSrcweir     protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
190cdf0e10cSrcweir                                                                  PrintWriter log) {
191cdf0e10cSrcweir         XInterface oObj = null;
192cdf0e10cSrcweir 
193cdf0e10cSrcweir         log.println("getting sheets");
194cdf0e10cSrcweir 
195cdf0e10cSrcweir         XSpreadsheets xSpreadsheets = (XSpreadsheets) xSheetDoc.getSheets();
196cdf0e10cSrcweir 
197cdf0e10cSrcweir         log.println("getting a sheet");
198cdf0e10cSrcweir 
199cdf0e10cSrcweir         XSpreadsheet oSheet = null;
200cdf0e10cSrcweir         XIndexAccess oIndexAccess = (XIndexAccess) UnoRuntime.queryInterface(
201cdf0e10cSrcweir                                             XIndexAccess.class, xSpreadsheets);
202cdf0e10cSrcweir 
203cdf0e10cSrcweir         try {
204cdf0e10cSrcweir             oSheet = (XSpreadsheet) AnyConverter.toObject(
205cdf0e10cSrcweir                              new Type(XSpreadsheet.class),
206cdf0e10cSrcweir                              oIndexAccess.getByIndex(0));
207cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
208cdf0e10cSrcweir             e.printStackTrace(log);
209cdf0e10cSrcweir             throw new StatusException("Couldn't get a spreadsheet", e);
210cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
211cdf0e10cSrcweir             e.printStackTrace(log);
212cdf0e10cSrcweir             throw new StatusException("Couldn't get a spreadsheet", e);
213cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
214cdf0e10cSrcweir             e.printStackTrace(log);
215cdf0e10cSrcweir             throw new StatusException("Couldn't get a spreadsheet", e);
216cdf0e10cSrcweir         }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir         log.println("filling some cells");
219cdf0e10cSrcweir 
220cdf0e10cSrcweir         try {
221cdf0e10cSrcweir             oSheet.getCellByPosition(5, 5).setValue(15);
222cdf0e10cSrcweir             oSheet.getCellByPosition(1, 4).setValue(10);
223cdf0e10cSrcweir             oSheet.getCellByPosition(2, 0).setValue(-5.15);
224cdf0e10cSrcweir             oSheet.getCellByPosition(8, 8).setFormula("= B5 + C1");
225cdf0e10cSrcweir             // fill cells for XSheetOtline::autoutline
226cdf0e10cSrcweir             oSheet.getCellByPosition(6, 6).setValue(3);
227cdf0e10cSrcweir             oSheet.getCellByPosition(7, 6).setValue(3);
228cdf0e10cSrcweir             oSheet.getCellByPosition(8, 6).setFormula("= SUM(G7:H7)");
229cdf0e10cSrcweir             oSheet.getCellByPosition(9, 6).setFormula("= G7*I7");
230cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
231cdf0e10cSrcweir             e.printStackTrace(log);
232cdf0e10cSrcweir             throw new StatusException("Exception occurred while filling cells", e);
233cdf0e10cSrcweir         }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir         oObj = (XInterface) UnoRuntime.queryInterface(XInterface.class, oSheet);
236cdf0e10cSrcweir 
237cdf0e10cSrcweir         log.println("creating a new environment for object");
238cdf0e10cSrcweir 
239cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment(oObj);
240cdf0e10cSrcweir 
241cdf0e10cSrcweir         // do not execute com::sun::star::sheets::XCellSeries::fillAuto()
242cdf0e10cSrcweir         tEnv.addObjRelation("XCELLSERIES_FILLAUTO", new Boolean(false));
243cdf0e10cSrcweir 
244cdf0e10cSrcweir         // set the adress ranges of the cells (see values set above): for e.g. XSheetOutline test
245cdf0e10cSrcweir         tEnv.addObjRelation("CellRangeAddress",
246cdf0e10cSrcweir             new CellRangeAddress((short)0, 6, 6, 8, 8));
247cdf0e10cSrcweir         tEnv.addObjRelation("CellRangeSubAddress",
248cdf0e10cSrcweir             new CellRangeAddress((short)0, 6, 6, 7, 8));
249cdf0e10cSrcweir         // pick a cell with a formula for XSheetAuditing, a dependent cell and a precedent cell
250cdf0e10cSrcweir         tEnv.addObjRelation("XSheetAuditing.CellAddress", new CellAddress((short)0, 8, 6));
251cdf0e10cSrcweir         tEnv.addObjRelation("XSheetAuditing.PrecedentCellAddress", new CellAddress((short)0, 7, 6));
252cdf0e10cSrcweir         tEnv.addObjRelation("XSheetAuditing.DependentCellAddress", new CellAddress((short)0, 9, 6));
253cdf0e10cSrcweir 
254cdf0e10cSrcweir         // add an existing sheet for linking
255cdf0e10cSrcweir         tEnv.addObjRelation("XSheetLinkable.LinkSheet", "ScSheetLinksObj.sdc");
256cdf0e10cSrcweir 
257cdf0e10cSrcweir         //adding Scenario and with that a ScenarioSheet-Relation for Scenario and XScenarioEnhanced
258cdf0e10cSrcweir         XScenariosSupplier scene = (XScenariosSupplier) UnoRuntime.queryInterface(
259cdf0e10cSrcweir                                            XScenariosSupplier.class,
260cdf0e10cSrcweir                                            tEnv.getTestObject());
261cdf0e10cSrcweir         scene.getScenarios()
262cdf0e10cSrcweir              .addNewByName("Scenario",
263cdf0e10cSrcweir                            new CellRangeAddress[] {
264cdf0e10cSrcweir             new CellRangeAddress((short) 0, 0, 0, 10, 10)
265cdf0e10cSrcweir         }, "Comment");
266cdf0e10cSrcweir 
267cdf0e10cSrcweir         XSpreadsheet sSheet = null;
268cdf0e10cSrcweir 
269cdf0e10cSrcweir         try {
270cdf0e10cSrcweir             sSheet = (XSpreadsheet) UnoRuntime.queryInterface(
271cdf0e10cSrcweir                              XSpreadsheet.class,
272cdf0e10cSrcweir                              xSpreadsheets.getByName("Scenario"));
273cdf0e10cSrcweir         } catch (com.sun.star.container.NoSuchElementException e) {
274cdf0e10cSrcweir             log.println("Couldn't get Scenario");
275cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
276cdf0e10cSrcweir             log.println("Couldn't get Scenario");
277cdf0e10cSrcweir         }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir         tEnv.addObjRelation("ScenarioSheet", sSheet);
280cdf0e10cSrcweir 
281cdf0e10cSrcweir         log.println("adding ObjRelation 'noArray' to avoid the test" +
282cdf0e10cSrcweir                     " 'XArrayFormulaRange'");
283cdf0e10cSrcweir         tEnv.addObjRelation("noArray", "ScTableSheetObj");
284cdf0e10cSrcweir 
285cdf0e10cSrcweir         XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(
286cdf0e10cSrcweir                                        XPropertySet.class, oObj);
287cdf0e10cSrcweir         tEnv.addObjRelation("PropSet", PropSet);
288cdf0e10cSrcweir         tEnv.addObjRelation("SHEET", oSheet);
289cdf0e10cSrcweir 
290cdf0e10cSrcweir         // add expected results for the XCellRangesQuery interface test
291cdf0e10cSrcweir         String[] expectedResults = new String[7];
292cdf0e10cSrcweir         expectedResults[_XCellRangesQuery.QUERYCOLUMNDIFFERENCES] = "Sheet1.B5;Sheet1.C1";
293cdf0e10cSrcweir         expectedResults[_XCellRangesQuery.QUERYCONTENTCELLS] = "Sheet1.B5;Sheet1.C1;Sheet1.F6";
294cdf0e10cSrcweir         expectedResults[_XCellRangesQuery.QUERYEMPTYCELLS] = "Sheet1.A1 ... Sheet1.B1 ... Sheet1.B6 ... Sheet1.C2 ... Sheet1.D1 ... Sheet1.F1 ... Sheet1.F7 ... Sheet1.G1";
295cdf0e10cSrcweir         expectedResults[_XCellRangesQuery.QUERYFORMULACELLS] = "Sheet1.I7:J7;Sheet1.I9";
296cdf0e10cSrcweir         expectedResults[_XCellRangesQuery.QUERYINTERSECTION] = "Sheet1.D4";
297cdf0e10cSrcweir         expectedResults[_XCellRangesQuery.QUERYROWDIFFERENCES] = "Sheet1.A5;Sheet1.C1";
298cdf0e10cSrcweir         expectedResults[_XCellRangesQuery.QUERYVISIBLECELLS] = "Sheet1.A2";
299cdf0e10cSrcweir         tEnv.addObjRelation("XCellRangesQuery.EXPECTEDRESULTS",
300cdf0e10cSrcweir                             expectedResults);
301cdf0e10cSrcweir 
302cdf0e10cSrcweir         // for XFormulaQuery interface test
303cdf0e10cSrcweir         try {
304cdf0e10cSrcweir             tEnv.addObjRelation("MAKEENTRYINCELL",
305cdf0e10cSrcweir                                 oSheet.getCellByPosition(15, 15));
306cdf0e10cSrcweir             tEnv.addObjRelation("RANGEINDICES", new int[] { 0, 0 });
307cdf0e10cSrcweir             tEnv.addObjRelation("EXPECTEDDEPENDENTVALUES",
308cdf0e10cSrcweir                                 new int[] { 0, 255, 0, 65535 });
309cdf0e10cSrcweir             tEnv.addObjRelation("EXPECTEDPRECEDENTVALUES",
310cdf0e10cSrcweir                                 new int[] { 0, 255, 0, 65535 });
311cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
312cdf0e10cSrcweir             log.println(
313cdf0e10cSrcweir                     "Cannot add the necessary object relation for XFormulaQuery test.");
314cdf0e10cSrcweir         }
315cdf0e10cSrcweir 
316cdf0e10cSrcweir         // XSearchable interface test
317cdf0e10cSrcweir         try {
318cdf0e10cSrcweir             tEnv.addObjRelation("XSearchable.MAKEENTRYINCELL",
319cdf0e10cSrcweir                                 new XCell[] {
320cdf0e10cSrcweir                 oSheet.getCellByPosition(15, 15),
321cdf0e10cSrcweir                 oSheet.getCellByPosition(15, 16)
322cdf0e10cSrcweir             });
323cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
324cdf0e10cSrcweir             e.printStackTrace((PrintWriter) log);
325cdf0e10cSrcweir             log.println(
326cdf0e10cSrcweir                     "Cannot make required object relation 'XSearchable.MAKEENTRYINCELL'.");
327cdf0e10cSrcweir         }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir         //Adding relation for util.XSortable
330cdf0e10cSrcweir         final PrintWriter finalLog = log;
331cdf0e10cSrcweir         final XCellRange oTable = oSheet;
332cdf0e10cSrcweir         tEnv.addObjRelation("SORTCHECKER",
333cdf0e10cSrcweir                             new ifc.util._XSortable.XSortChecker() {
334cdf0e10cSrcweir             PrintWriter out = finalLog;
335cdf0e10cSrcweir 
336cdf0e10cSrcweir             public void setPrintWriter(PrintWriter log) {
337cdf0e10cSrcweir                 out = log;
338cdf0e10cSrcweir             }
339cdf0e10cSrcweir 
340cdf0e10cSrcweir             public void prepareToSort() {
341cdf0e10cSrcweir                 try {
342cdf0e10cSrcweir                     oTable.getCellByPosition(0, 0).setValue(4);
343cdf0e10cSrcweir                     oTable.getCellByPosition(0, 1).setFormula("b");
344cdf0e10cSrcweir                     oTable.getCellByPosition(0, 2).setValue(3);
345cdf0e10cSrcweir                     oTable.getCellByPosition(0, 3).setValue(23);
346cdf0e10cSrcweir                 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
347cdf0e10cSrcweir                     out.println("Exception while checking sort");
348cdf0e10cSrcweir                 }
349cdf0e10cSrcweir             }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir             public boolean checkSort(boolean isSortNumbering,
352cdf0e10cSrcweir                                      boolean isSortAscending) {
353cdf0e10cSrcweir                 out.println("Sort checking...");
354cdf0e10cSrcweir 
355cdf0e10cSrcweir                 boolean res = false;
356cdf0e10cSrcweir                 String[] value = new String[4];
357cdf0e10cSrcweir 
358cdf0e10cSrcweir                 for (int i = 0; i < 4; i++) {
359cdf0e10cSrcweir                     try {
360cdf0e10cSrcweir                         XCell cell = oTable.getCellByPosition(0, i);
361cdf0e10cSrcweir                         value[i] = cell.getFormula();
362cdf0e10cSrcweir                     } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
363cdf0e10cSrcweir                         out.println("Exception while checking sort");
364cdf0e10cSrcweir                     }
365cdf0e10cSrcweir                 }
366cdf0e10cSrcweir 
367cdf0e10cSrcweir                 if (isSortNumbering) {
368cdf0e10cSrcweir                     if (isSortAscending) {
369cdf0e10cSrcweir                         out.println("Sorting ascending");
370cdf0e10cSrcweir 
371cdf0e10cSrcweir                         String[] rightVal = { "3", "4", "23", "b" };
372cdf0e10cSrcweir                         String[] vals = { value[0], value[1], value[2], value[3] };
373cdf0e10cSrcweir                         res = ValueComparer.equalValue(vals, rightVal);
374cdf0e10cSrcweir                         out.println("Expected 3, 4, 23, b");
375cdf0e10cSrcweir                         out.println("getting: " + value[0] + ", " +
376cdf0e10cSrcweir                                         value[1] + ", " + value[2] + ", " +
377cdf0e10cSrcweir                                         value[3]);
378cdf0e10cSrcweir                     } else {
379cdf0e10cSrcweir                         String[] rightVal = { "b", "23", "4", "3" };
380cdf0e10cSrcweir                         String[] vals = { value[0], value[1], value[2], value[3] };
381cdf0e10cSrcweir                         res = ValueComparer.equalValue(vals, rightVal);
382cdf0e10cSrcweir                         out.println("Expected b, 23, 4, 3");
383cdf0e10cSrcweir                         out.println("getting: " + value[0] + ", " +
384cdf0e10cSrcweir                                         value[1] + ", " + value[2] + ", " +
385cdf0e10cSrcweir                                         value[3]);
386cdf0e10cSrcweir                     }
387cdf0e10cSrcweir                 } else {
388cdf0e10cSrcweir                     if (isSortAscending) {
389cdf0e10cSrcweir                         String[] rightVal = { "3", "4", "23", "b" };
390cdf0e10cSrcweir                         res = ValueComparer.equalValue(value, rightVal);
391cdf0e10cSrcweir                         out.println("Expected 3, 4, 23, b");
392cdf0e10cSrcweir                         out.println("getting: " + value[0] + ", " +
393cdf0e10cSrcweir                                         value[1] + ", " + value[2] + ", " +
394cdf0e10cSrcweir                                         value[3]);
395cdf0e10cSrcweir                     } else {
396cdf0e10cSrcweir                         String[] rightVal = { "b", "23", "4", "3" };
397cdf0e10cSrcweir                         res = ValueComparer.equalValue(value, rightVal);
398cdf0e10cSrcweir                         out.println("Expected b, 23, 4, 3");
399cdf0e10cSrcweir                         out.println("getting: " + value[0] + ", " +
400cdf0e10cSrcweir                                         value[1] + ", " + value[2] + ", " +
401cdf0e10cSrcweir                                         value[3]);
402cdf0e10cSrcweir                     }
403cdf0e10cSrcweir                 }
404cdf0e10cSrcweir 
405cdf0e10cSrcweir                 if (res) {
406cdf0e10cSrcweir                     out.println("Sorted correctly");
407cdf0e10cSrcweir                 } else {
408cdf0e10cSrcweir                     out.println("Sorted uncorrectly");
409cdf0e10cSrcweir                 }
410cdf0e10cSrcweir 
411cdf0e10cSrcweir                 return res;
412cdf0e10cSrcweir             }
413cdf0e10cSrcweir         });
414cdf0e10cSrcweir 
415cdf0e10cSrcweir         return tEnv;
416cdf0e10cSrcweir     }
417cdf0e10cSrcweir }
418