tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScCellRangesObj.java
blob1dfbcfc1e6f47463fd1c5d64a55ee417a9ce041e
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.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.SOfficeFactory;
28 import com.sun.star.beans.XPropertySet;
29 import com.sun.star.container.XIndexAccess;
30 import com.sun.star.container.XNameContainer;
31 import com.sun.star.lang.XComponent;
32 import com.sun.star.sheet.XSpreadsheet;
33 import com.sun.star.sheet.XSpreadsheetDocument;
34 import com.sun.star.sheet.XSpreadsheets;
35 import com.sun.star.uno.AnyConverter;
36 import com.sun.star.uno.Type;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
39 import ifc.sheet._XCellRangesQuery;
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.sheet.SheetCellRanges</code>. <p>
45 * Object implements the following interfaces :
46 * <ul>
47 * <li> <code>com::sun::star::table::CellProperties</code></li>
48 * <li> <code>com::sun::star::container::XNameReplace</code></li>
49 * <li> <code>com::sun::star::container::XNameContainer</code></li>
50 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
51 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
52 * <li> <code>com::sun::star::container::XElementAccess</code></li>
53 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
54 * <li> <code>com::sun::star::sheet::XSheetCellRangeContainer</code></li>
55 * <li> <code>com::sun::star::sheet::XSheetOperation</code></li>
56 * <li> <code>com::sun::star::sheet::XSheetCellRanges</code></li>
57 * <li> <code>com::sun::star::container::XNameAccess</code></li>
58 * </ul>
59 * @see com.sun.star.sheet.SheetCellRanges
60 * @see com.sun.star.table.CellProperties
61 * @see com.sun.star.container.XNameReplace
62 * @see com.sun.star.container.XNameContainer
63 * @see com.sun.star.beans.XPropertySet
64 * @see com.sun.star.container.XIndexAccess
65 * @see com.sun.star.container.XElementAccess
66 * @see com.sun.star.container.XEnumerationAccess
67 * @see com.sun.star.sheet.XSheetCellRangeContainer
68 * @see com.sun.star.sheet.XSheetOperation
69 * @see com.sun.star.sheet.XSheetCellRanges
70 * @see com.sun.star.container.XNameAccess
71 * @see ifc.table._CellProperties
72 * @see ifc.container._XNameReplace
73 * @see ifc.container._XNameContainer
74 * @see ifc.beans._XPropertySet
75 * @see ifc.container._XIndexAccess
76 * @see ifc.container._XElementAccess
77 * @see ifc.container._XEnumerationAccess
78 * @see ifc.sheet._XSheetCellRangeContainer
79 * @see ifc.sheet._XSheetOperation
80 * @see ifc.sheet._XSheetCellRanges
81 * @see ifc.container._XNameAccess
83 public class ScCellRangesObj extends TestCase {
84 private XSpreadsheetDocument xSheetDoc = null;
86 /**
87 * Creates Spreadsheet document.
89 @Override
90 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
91 // get a soffice factory object
92 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
93 log.println( "creating a sheetdocument" );
94 xSheetDoc = SOF.createCalcDoc(null);
97 /**
98 * Disposes Spreadsheet document.
100 @Override
101 protected void cleanup( TestParameters tParam, PrintWriter log ) {
102 log.println( " disposing xSheetDoc " );
103 XComponent oComp =
104 UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
105 util.DesktopTools.closeDoc(oComp);
109 * Creating a TestEnvironment for the interfaces to be tested.
110 * Creates an instance of the service
111 * <code>com.sun.star.sheet.SheetCellRanges</code> and fills some cells.
112 * Object relations created :
113 * <ul>
114 * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for
115 * {@link ifc.container._XNameReplace},
116 * {@link ifc.container._XNameContainer} (type of
117 * <code>XCellRange</code>)</li>
118 * <li> <code>'THRCNT'</code> for
119 * {@link ifc.container._XNameReplace}(the number of the running threads
120 * that was retrieved from the method parameter <code>Param</code>)</li>
121 * <li> <code>'NameReplaceIndex'</code> for
122 * {@link ifc.container._XNameReplace} </li>
123 * </ul>
124 * @see com.sun.star.table.XCellRange
126 @Override
127 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) throws Exception {
129 XInterface oObj = null;
130 Object oRange = null ;
132 // creation of testobject here
133 // first we write what we are intend to do to log file
134 log.println( "Creating a test environment" );
136 // get a soffice factory object
137 SOfficeFactory SOF = SOfficeFactory.getFactory( Param.getMSF() );
139 log.println("Getting test object ");
141 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
143 oObj = (XInterface)
144 SOF.createInstance(oComp, "com.sun.star.sheet.SheetCellRanges");
146 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
147 XIndexAccess oIndSheets = UnoRuntime.queryInterface (XIndexAccess.class, oSheets);
148 XSpreadsheet oSheet = null;
149 oSheet = (XSpreadsheet) AnyConverter.toObject(
150 new Type(XSpreadsheet.class), oIndSheets.getByIndex(0));
151 XNameContainer oRanges = UnoRuntime.queryInterface(XNameContainer.class, oObj);
153 oRange = oSheet.getCellRangeByName("C1:D4");
154 oRanges.insertByName("Range1", oRange);
155 oRange = oSheet.getCellRangeByName("E2:F5");
156 oRanges.insertByName("Range2", oRange);
157 oRange = oSheet.getCellRangeByName("G2:H3");
158 oRanges.insertByName("Range3", oRange);
159 oRange = oSheet.getCellRangeByName("I7:J8");
160 oRanges.insertByName("Range4", oRange);
162 log.println("filling some cells");
163 for (int i = 0; i < 10; i++) {
164 for (int j = 0; j < 5; j++) {
165 oSheet.getCellByPosition(i, j).setFormula("a");
168 for (int i = 0; i < 10; i++) {
169 for (int j = 5; j < 10; j++) {
170 oSheet.getCellByPosition(i, j).setValue(i + j);
175 TestEnvironment tEnv = new TestEnvironment( oObj );
177 // NameReplaceIndex : _XNameReplace
178 log.println( "adding NameReplaceIndex as mod relation to environment" );
179 tEnv.addObjRelation("NameReplaceIndex", "0");
181 // INSTANCEn : _XNameContainer; _XNameReplace
182 log.println( "adding INSTANCEn as mod relation to environment" );
184 int THRCNT = 1;
185 if ((String)Param.get("THRCNT") != null) {
186 THRCNT= Integer.parseInt((String)Param.get("THRCNT"));
188 int a = 0;
189 int b = 0;
190 for (int n = 1; n < (THRCNT + 1) ; n++) {
191 a = n * 2;
192 b = a + 1;
193 oRange = oSheet.getCellRangeByName("A" + a + ":B" + b);
194 log.println(
195 "adding INSTANCE" + n + " as mod relation to environment" );
197 tEnv.addObjRelation("INSTANCE" + n, oRange);
200 XPropertySet PropSet = UnoRuntime.queryInterface(XPropertySet.class, oObj);
201 tEnv.addObjRelation("PropSet",PropSet);
202 tEnv.addObjRelation("SHEET", oSheet);
203 // add expected results for the XCellRangesQuery interface test
204 String[]expectedResults = new String[7];
205 expectedResults[_XCellRangesQuery.QUERYCOLUMNDIFFERENCES] = "Sheet1.I7:J8";
206 expectedResults[_XCellRangesQuery.QUERYCONTENTCELLS] = "";
207 expectedResults[_XCellRangesQuery.QUERYEMPTYCELLS] = "";
208 expectedResults[_XCellRangesQuery.QUERYFORMULACELLS] = "";
209 expectedResults[_XCellRangesQuery.QUERYINTERSECTION] = "Sheet1.D4";
210 expectedResults[_XCellRangesQuery.QUERYROWDIFFERENCES] = "Sheet1.I7:J8";
211 expectedResults[_XCellRangesQuery.QUERYVISIBLECELLS] = "Sheet1.C2:D4"; // first range, first line invisible
212 tEnv.addObjRelation("XCellRangesQuery.EXPECTEDRESULTS", expectedResults);
214 // for XSearchable and XReplaceable interface test
215 tEnv.addObjRelation("SEARCHSTRING", "15");
217 // for XFormulaQuery interface test
218 tEnv.addObjRelation("EXPECTEDDEPENDENTVALUES", new int[]{4,5,1,4});
219 tEnv.addObjRelation("EXPECTEDPRECEDENTVALUES", new int[]{4,5,1,4});
220 return tEnv ;
223 } // finish class ScCellRangesObj