1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScCellRangesObj.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.beans
.XPropertySet
;
42 import com
.sun
.star
.container
.XIndexAccess
;
43 import com
.sun
.star
.container
.XNameContainer
;
44 import com
.sun
.star
.lang
.XComponent
;
45 import com
.sun
.star
.lang
.XMultiServiceFactory
;
46 import com
.sun
.star
.sheet
.XSpreadsheet
;
47 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
48 import com
.sun
.star
.sheet
.XSpreadsheets
;
49 import com
.sun
.star
.uno
.AnyConverter
;
50 import com
.sun
.star
.uno
.Type
;
51 import com
.sun
.star
.uno
.UnoRuntime
;
52 import com
.sun
.star
.uno
.XInterface
;
53 import ifc
.sheet
._XCellRangesQuery
;
57 * Test for object which is represented by service
58 * <code>com.sun.star.sheet.SheetCellRanges</code>. <p>
59 * Object implements the following interfaces :
61 * <li> <code>com::sun::star::table::CellProperties</code></li>
62 * <li> <code>com::sun::star::container::XNameReplace</code></li>
63 * <li> <code>com::sun::star::container::XNameContainer</code></li>
64 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
65 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
66 * <li> <code>com::sun::star::container::XElementAccess</code></li>
67 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
68 * <li> <code>com::sun::star::sheet::XSheetCellRangeContainer</code></li>
69 * <li> <code>com::sun::star::sheet::XSheetOperation</code></li>
70 * <li> <code>com::sun::star::sheet::XSheetCellRanges</code></li>
71 * <li> <code>com::sun::star::container::XNameAccess</code></li>
73 * @see com.sun.star.sheet.SheetCellRanges
74 * @see com.sun.star.table.CellProperties
75 * @see com.sun.star.container.XNameReplace
76 * @see com.sun.star.container.XNameContainer
77 * @see com.sun.star.beans.XPropertySet
78 * @see com.sun.star.container.XIndexAccess
79 * @see com.sun.star.container.XElementAccess
80 * @see com.sun.star.container.XEnumerationAccess
81 * @see com.sun.star.sheet.XSheetCellRangeContainer
82 * @see com.sun.star.sheet.XSheetOperation
83 * @see com.sun.star.sheet.XSheetCellRanges
84 * @see com.sun.star.container.XNameAccess
85 * @see ifc.table._CellProperties
86 * @see ifc.container._XNameReplace
87 * @see ifc.container._XNameContainer
88 * @see ifc.beans._XPropertySet
89 * @see ifc.container._XIndexAccess
90 * @see ifc.container._XElementAccess
91 * @see ifc.container._XEnumerationAccess
92 * @see ifc.sheet._XSheetCellRangeContainer
93 * @see ifc.sheet._XSheetOperation
94 * @see ifc.sheet._XSheetCellRanges
95 * @see ifc.container._XNameAccess
97 public class ScCellRangesObj
extends TestCase
{
98 static XSpreadsheetDocument xSheetDoc
= null;
101 * Creates Spreadsheet document.
103 protected void initialize( TestParameters tParam
, PrintWriter log
) {
105 // get a soffice factory object
106 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
109 log
.println( "creating a sheetdocument" );
110 xSheetDoc
= SOF
.createCalcDoc(null);;
111 } catch (com
.sun
.star
.uno
.Exception e
) {
112 // Some exception occures.FAILED
113 e
.printStackTrace( log
);
114 throw new StatusException( "Couldn't create document", e
);
119 * Disposes Spreadsheet document.
121 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
122 log
.println( " disposing xSheetDoc " );
124 (XComponent
) UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
);
125 util
.DesktopTools
.closeDoc(oComp
);
129 * Creating a Testenvironment for the interfaces to be tested.
130 * Creates an instance of the service
131 * <code>com.sun.star.sheet.SheetCellRanges</code> and fills some cells.
132 * Object relations created :
134 * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for
135 * {@link ifc.container._XNameReplace},
136 * {@link ifc.container._XNameContainer} (type of
137 * <code>XCellRange</code>)</li>
138 * <li> <code>'THRCNT'</code> for
139 * {@link ifc.container._XNameReplace}(the number of the running threads
140 * that was retrieved from the method parameter <code>Param</code>)</li>
141 * <li> <code>'NameReplaceIndex'</code> for
142 * {@link ifc.container._XNameReplace} </li>
144 * @see com.sun.star.table.XCellRange
146 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
148 XInterface oObj
= null;
149 Object oRange
= null ;
151 // creation of testobject here
152 // first we write what we are intend to do to log file
153 log
.println( "Creating a test environment" );
155 // get a soffice factory object
156 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)Param
.getMSF() );
158 log
.println("Getting test object ");
160 XComponent oComp
= (XComponent
)
161 UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
);
164 SOF
.createInstance(oComp
, "com.sun.star.sheet.SheetCellRanges");
166 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
167 XIndexAccess oIndSheets
= (XIndexAccess
)
168 UnoRuntime
.queryInterface (XIndexAccess
.class, oSheets
);
169 XSpreadsheet oSheet
= null;
171 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
172 new Type(XSpreadsheet
.class), oIndSheets
.getByIndex(0));
173 XNameContainer oRanges
= (XNameContainer
)
174 UnoRuntime
.queryInterface(XNameContainer
.class, oObj
);
176 oRange
= oSheet
.getCellRangeByName("C1:D4");
177 oRanges
.insertByName("Range1", oRange
);
178 oRange
= oSheet
.getCellRangeByName("E2:F5");
179 oRanges
.insertByName("Range2", oRange
);
180 oRange
= oSheet
.getCellRangeByName("G2:H3");
181 oRanges
.insertByName("Range3", oRange
);
182 oRange
= oSheet
.getCellRangeByName("I7:J8");
183 oRanges
.insertByName("Range4", oRange
);
184 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
185 e
.printStackTrace(log
);
186 throw new StatusException("Couldn't create test object", e
);
187 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
188 e
.printStackTrace(log
);
189 throw new StatusException("Couldn't create test object", e
);
190 } catch(com
.sun
.star
.container
.ElementExistException e
) {
191 e
.printStackTrace(log
);
192 throw new StatusException("Couldn't create test object", e
);
193 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
194 e
.printStackTrace(log
);
195 throw new StatusException("Couldn't create test object", e
);
198 log
.println("filling some cells");
200 for (int i
= 0; i
< 10; i
++) {
201 for (int j
= 0; j
< 5; j
++) {
202 oSheet
.getCellByPosition(i
, j
).setFormula("a");
205 for (int i
= 0; i
< 10; i
++) {
206 for (int j
= 5; j
< 10; j
++) {
207 oSheet
.getCellByPosition(i
, j
).setValue(i
+ j
);
210 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
211 e
.printStackTrace(log
);
212 throw new StatusException (
213 "Exception occurred while filling cells", e
);
217 TestEnvironment tEnv
= new TestEnvironment( oObj
);
219 // NameReplaceIndex : _XNameReplace
220 log
.println( "adding NameReplaceIndex as mod relation to environment" );
221 tEnv
.addObjRelation("NameReplaceIndex", "0");
223 // INSTANCEn : _XNameContainer; _XNameReplace
224 log
.println( "adding INSTANCEn as mod relation to environment" );
227 if ((String
)Param
.get("THRCNT") != null) {
228 THRCNT
= Integer
.parseInt((String
)Param
.get("THRCNT"));
232 for (int n
= 1; n
< (THRCNT
+ 1) ; n
++) {
235 oRange
= oSheet
.getCellRangeByName("A" + a
+ ":B" + b
);
237 "adding INSTANCE" + n
+ " as mod relation to environment" );
239 tEnv
.addObjRelation("INSTANCE" + n
, oRange
);
242 XPropertySet PropSet
= (XPropertySet
)
243 UnoRuntime
.queryInterface(XPropertySet
.class, oObj
);
244 tEnv
.addObjRelation("PropSet",PropSet
);
245 tEnv
.addObjRelation("SHEET", oSheet
);
246 // add expected results for the XCellRangesQuery interface test
247 String
[]expectedResults
= new String
[7];
248 expectedResults
[_XCellRangesQuery
.QUERYCOLUMNDIFFERENCES
] = "Sheet1.I7:J8";
249 expectedResults
[_XCellRangesQuery
.QUERYCONTENTCELLS
] = "";
250 expectedResults
[_XCellRangesQuery
.QUERYEMPTYCELLS
] = "";
251 expectedResults
[_XCellRangesQuery
.QUERYFORMULACELLS
] = "";
252 expectedResults
[_XCellRangesQuery
.QUERYINTERSECTION
] = "Sheet1.D4";
253 expectedResults
[_XCellRangesQuery
.QUERYROWDIFFERENCES
] = "Sheet1.I7:J8";
254 expectedResults
[_XCellRangesQuery
.QUERYVISIBLECELLS
] = "Sheet1.C2:D4"; // first range, first line invisible
255 tEnv
.addObjRelation("XCellRangesQuery.EXPECTEDRESULTS", expectedResults
);
257 // for XSearchable and XReplaceable interface test
258 tEnv
.addObjRelation("SEARCHSTRING", "15");
260 // for XFormulaQuery interface test
261 tEnv
.addObjRelation("EXPECTEDDEPENDENTVALUES", new int[]{4,5,1,4});
262 tEnv
.addObjRelation("EXPECTEDPRECEDENTVALUES", new int[]{4,5,1,4});
266 } // finish class ScCellRangesObj