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