bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScCellRangesObj.java
blob1e0d2fc09dd71b9c0cbad5d07f31d6c7b63f896a
1 /*
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 package mod._sc;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.beans.XPropertySet;
30 import com.sun.star.container.XIndexAccess;
31 import com.sun.star.container.XNameContainer;
32 import com.sun.star.lang.XComponent;
33 import com.sun.star.sheet.XSpreadsheet;
34 import com.sun.star.sheet.XSpreadsheetDocument;
35 import com.sun.star.sheet.XSpreadsheets;
36 import com.sun.star.uno.AnyConverter;
37 import com.sun.star.uno.Type;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
40 import ifc.sheet._XCellRangesQuery;
43 /**
44 * Test for object which is represented by service
45 * <code>com.sun.star.sheet.SheetCellRanges</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>com::sun::star::table::CellProperties</code></li>
49 * <li> <code>com::sun::star::container::XNameReplace</code></li>
50 * <li> <code>com::sun::star::container::XNameContainer</code></li>
51 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
52 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
53 * <li> <code>com::sun::star::container::XElementAccess</code></li>
54 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
55 * <li> <code>com::sun::star::sheet::XSheetCellRangeContainer</code></li>
56 * <li> <code>com::sun::star::sheet::XSheetOperation</code></li>
57 * <li> <code>com::sun::star::sheet::XSheetCellRanges</code></li>
58 * <li> <code>com::sun::star::container::XNameAccess</code></li>
59 * </ul>
60 * @see com.sun.star.sheet.SheetCellRanges
61 * @see com.sun.star.table.CellProperties
62 * @see com.sun.star.container.XNameReplace
63 * @see com.sun.star.container.XNameContainer
64 * @see com.sun.star.beans.XPropertySet
65 * @see com.sun.star.container.XIndexAccess
66 * @see com.sun.star.container.XElementAccess
67 * @see com.sun.star.container.XEnumerationAccess
68 * @see com.sun.star.sheet.XSheetCellRangeContainer
69 * @see com.sun.star.sheet.XSheetOperation
70 * @see com.sun.star.sheet.XSheetCellRanges
71 * @see com.sun.star.container.XNameAccess
72 * @see ifc.table._CellProperties
73 * @see ifc.container._XNameReplace
74 * @see ifc.container._XNameContainer
75 * @see ifc.beans._XPropertySet
76 * @see ifc.container._XIndexAccess
77 * @see ifc.container._XElementAccess
78 * @see ifc.container._XEnumerationAccess
79 * @see ifc.sheet._XSheetCellRangeContainer
80 * @see ifc.sheet._XSheetOperation
81 * @see ifc.sheet._XSheetCellRanges
82 * @see ifc.container._XNameAccess
84 public class ScCellRangesObj extends TestCase {
85 private XSpreadsheetDocument xSheetDoc = null;
87 /**
88 * Creates Spreadsheet document.
90 @Override
91 protected void initialize( TestParameters tParam, PrintWriter log ) {
93 // get a soffice factory object
94 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
96 try {
97 log.println( "creating a sheetdocument" );
98 xSheetDoc = SOF.createCalcDoc(null);
99 } catch (com.sun.star.uno.Exception e) {
100 // Some exception occurs.FAILED
101 e.printStackTrace( log );
102 throw new StatusException( "Couldn't create document", e );
107 * Disposes Spreadsheet document.
109 @Override
110 protected void cleanup( TestParameters tParam, PrintWriter log ) {
111 log.println( " disposing xSheetDoc " );
112 XComponent oComp =
113 UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
114 util.DesktopTools.closeDoc(oComp);
118 * Creating a Testenvironment for the interfaces to be tested.
119 * Creates an instance of the service
120 * <code>com.sun.star.sheet.SheetCellRanges</code> and fills some cells.
121 * Object relations created :
122 * <ul>
123 * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for
124 * {@link ifc.container._XNameReplace},
125 * {@link ifc.container._XNameContainer} (type of
126 * <code>XCellRange</code>)</li>
127 * <li> <code>'THRCNT'</code> for
128 * {@link ifc.container._XNameReplace}(the number of the running threads
129 * that was retrieved from the method parameter <code>Param</code>)</li>
130 * <li> <code>'NameReplaceIndex'</code> for
131 * {@link ifc.container._XNameReplace} </li>
132 * </ul>
133 * @see com.sun.star.table.XCellRange
135 @Override
136 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
138 XInterface oObj = null;
139 Object oRange = null ;
141 // creation of testobject here
142 // first we write what we are intend to do to log file
143 log.println( "Creating a test environment" );
145 // get a soffice factory object
146 SOfficeFactory SOF = SOfficeFactory.getFactory( Param.getMSF() );
148 log.println("Getting test object ");
150 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
152 oObj = (XInterface)
153 SOF.createInstance(oComp, "com.sun.star.sheet.SheetCellRanges");
155 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
156 XIndexAccess oIndSheets = UnoRuntime.queryInterface (XIndexAccess.class, oSheets);
157 XSpreadsheet oSheet = null;
158 try {
159 oSheet = (XSpreadsheet) AnyConverter.toObject(
160 new Type(XSpreadsheet.class), oIndSheets.getByIndex(0));
161 XNameContainer oRanges = UnoRuntime.queryInterface(XNameContainer.class, oObj);
163 oRange = oSheet.getCellRangeByName("C1:D4");
164 oRanges.insertByName("Range1", oRange);
165 oRange = oSheet.getCellRangeByName("E2:F5");
166 oRanges.insertByName("Range2", oRange);
167 oRange = oSheet.getCellRangeByName("G2:H3");
168 oRanges.insertByName("Range3", oRange);
169 oRange = oSheet.getCellRangeByName("I7:J8");
170 oRanges.insertByName("Range4", oRange);
171 } catch(com.sun.star.lang.WrappedTargetException e) {
172 e.printStackTrace(log);
173 throw new StatusException("Couldn't create test object", e);
174 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
175 e.printStackTrace(log);
176 throw new StatusException("Couldn't create test object", e);
177 } catch(com.sun.star.container.ElementExistException e) {
178 e.printStackTrace(log);
179 throw new StatusException("Couldn't create test object", e);
180 } catch(com.sun.star.lang.IllegalArgumentException e) {
181 e.printStackTrace(log);
182 throw new StatusException("Couldn't create test object", e);
185 log.println("filling some cells");
186 try {
187 for (int i = 0; i < 10; i++) {
188 for (int j = 0; j < 5; j++) {
189 oSheet.getCellByPosition(i, j).setFormula("a");
192 for (int i = 0; i < 10; i++) {
193 for (int j = 5; j < 10; j++) {
194 oSheet.getCellByPosition(i, j).setValue(i + j);
197 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
198 e.printStackTrace(log);
199 throw new StatusException (
200 "Exception occurred while filling cells", e);
204 TestEnvironment tEnv = new TestEnvironment( oObj );
206 // NameReplaceIndex : _XNameReplace
207 log.println( "adding NameReplaceIndex as mod relation to environment" );
208 tEnv.addObjRelation("NameReplaceIndex", "0");
210 // INSTANCEn : _XNameContainer; _XNameReplace
211 log.println( "adding INSTANCEn as mod relation to environment" );
213 int THRCNT = 1;
214 if ((String)Param.get("THRCNT") != null) {
215 THRCNT= Integer.parseInt((String)Param.get("THRCNT"));
217 int a = 0;
218 int b = 0;
219 for (int n = 1; n < (THRCNT + 1) ; n++) {
220 a = n * 2;
221 b = a + 1;
222 oRange = oSheet.getCellRangeByName("A" + a + ":B" + b);
223 log.println(
224 "adding INSTANCE" + n + " as mod relation to environment" );
226 tEnv.addObjRelation("INSTANCE" + n, oRange);
229 XPropertySet PropSet = UnoRuntime.queryInterface(XPropertySet.class, oObj);
230 tEnv.addObjRelation("PropSet",PropSet);
231 tEnv.addObjRelation("SHEET", oSheet);
232 // add expected results for the XCellRangesQuery interface test
233 String[]expectedResults = new String[7];
234 expectedResults[_XCellRangesQuery.QUERYCOLUMNDIFFERENCES] = "Sheet1.I7:J8";
235 expectedResults[_XCellRangesQuery.QUERYCONTENTCELLS] = "";
236 expectedResults[_XCellRangesQuery.QUERYEMPTYCELLS] = "";
237 expectedResults[_XCellRangesQuery.QUERYFORMULACELLS] = "";
238 expectedResults[_XCellRangesQuery.QUERYINTERSECTION] = "Sheet1.D4";
239 expectedResults[_XCellRangesQuery.QUERYROWDIFFERENCES] = "Sheet1.I7:J8";
240 expectedResults[_XCellRangesQuery.QUERYVISIBLECELLS] = "Sheet1.C2:D4"; // first range, first line invisible
241 tEnv.addObjRelation("XCellRangesQuery.EXPECTEDRESULTS", expectedResults);
243 // for XSearchable and XReplaceable interface test
244 tEnv.addObjRelation("SEARCHSTRING", "15");
246 // for XFormulaQuery interface test
247 tEnv.addObjRelation("EXPECTEDDEPENDENTVALUES", new int[]{4,5,1,4});
248 tEnv.addObjRelation("EXPECTEDPRECEDENTVALUES", new int[]{4,5,1,4});
249 return tEnv ;
252 } // finish class ScCellRangesObj