tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScCellRangeObj.java
bloba4cbdeb5499c96e2ca65f2c717f34331cd50201a
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 .
18 package mod._sc;
19 import java.io.PrintWriter;
21 import lib.TestCase;
22 import lib.TestEnvironment;
23 import lib.TestParameters;
24 import util.SOfficeFactory;
25 import util.ValueComparer;
27 import com.sun.star.beans.XPropertySet;
28 import com.sun.star.container.XNameAccess;
29 import com.sun.star.lang.XComponent;
30 import com.sun.star.sheet.XSpreadsheet;
31 import com.sun.star.sheet.XSpreadsheetDocument;
32 import com.sun.star.sheet.XSpreadsheets;
33 import com.sun.star.table.XCell;
34 import com.sun.star.table.XCellRange;
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.SheetCellRange</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::util::XMergeable</code></li>
49 * <li> <code>com::sun::star::sheet::XCellRangeAddressable</code></li>
50 * <li> <code>com::sun::star::sheet::XArrayFormulaRange</code></li>
51 * <li> <code>com::sun::star::chart::XChartData</code></li>
52 * <li> <code>com::sun::star::table::XColumnRowRange</code></li>
53 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
54 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
55 * <li> <code>com::sun::star::sheet::XSheetOperation</code></li>
56 * <li> <code>com::sun::star::table::XCellRange</code></li>
57 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
58 * <li> <code>com::sun::star::sheet::SheetCellRange</code></li>
59 * </ul>
60 * @see com.sun.star.sheet.SheetCellRange
61 * @see com.sun.star.table.CellProperties
62 * @see com.sun.star.util.XMergeable
63 * @see com.sun.star.sheet.XCellRangeAddressable
64 * @see com.sun.star.sheet.XArrayFormulaRange
65 * @see com.sun.star.chart.XChartData
66 * @see com.sun.star.table.XColumnRowRange
67 * @see com.sun.star.beans.XPropertySet
68 * @see com.sun.star.style.CharacterProperties
69 * @see com.sun.star.sheet.XSheetOperation
70 * @see com.sun.star.table.XCellRange
71 * @see com.sun.star.style.ParagraphProperties
72 * @see com.sun.star.sheet.SheetCellRange
73 * @see ifc.table._CellProperties
74 * @see ifc.util._XMergeable
75 * @see ifc.sheet._XCellRangeAddressable
76 * @see ifc.sheet._XArrayFormulaRange
77 * @see ifc.chart._XChartData
78 * @see ifc.table._XColumnRowRange
79 * @see ifc.beans._XPropertySet
80 * @see ifc.style._CharacterProperties
81 * @see ifc.sheet._XSheetOperation
82 * @see ifc.table._XCellRange
83 * @see ifc.style._ParagraphProperties
84 * @see ifc.sheet._SheetCellRange
86 public class ScCellRangeObj extends TestCase {
87 XSpreadsheetDocument xSheetDoc = null;
89 /**
90 * Creates Spreadsheet document.
92 @Override
93 protected void initialize(TestParameters tParam, PrintWriter log) throws Exception {
94 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
96 log.println("creating a Spreadsheet document");
97 xSheetDoc = SOF.createCalcDoc(null);
101 * Disposes Spreadsheet document.
103 @Override
104 protected void cleanup(TestParameters tParam, PrintWriter log) {
105 log.println(" disposing xSheetDoc ");
107 XComponent oComp = UnoRuntime.queryInterface(
108 XComponent.class, xSheetDoc);
109 util.DesktopTools.closeDoc(oComp);
113 * Creating a TestEnvironment for the interfaces to be tested.
114 * Retrieves a collection of spreadsheets from a document,
115 * and takes one of them. Retrieves some cell range from the spreadsheet.
116 * The retrieved cell range is instance of the service
117 * <code>com.sun.star.sheet.SheetCellRange</code>.
118 * Object relations created :
119 * <ul>
120 * <li> <code>'SHEET'</code> for
121 * {@link ifc.sheet._XArrayFormulaRange} (the spreadsheet which the cell
122 * range was retrieved from)</li>
123 * </ul>
124 * @see com.sun.star.sheet.XSpreadsheet
126 @Override
127 protected TestEnvironment createTestEnvironment(TestParameters Param,
128 PrintWriter log) throws Exception {
129 XInterface oObj = null;
130 XCellRange testRange;
133 // creation of testobject here
134 // first we write what we are intend to do to log file
135 log.println("Creating a test environment");
137 XSpreadsheets oSpreadsheets = UnoRuntime.queryInterface(
138 XSpreadsheetDocument.class,
139 xSheetDoc).getSheets();
140 XNameAccess oNames = UnoRuntime.queryInterface(
141 XNameAccess.class, oSpreadsheets);
143 XSpreadsheet oSheet = null;
145 oSheet = (XSpreadsheet) AnyConverter.toObject(
146 new Type(XSpreadsheet.class),
147 oNames.getByName(oNames.getElementNames()[0]));
149 oObj = oSheet.getCellRangeByPosition(0, 0, 3, 4);
150 testRange = UnoRuntime.queryInterface(
151 XCellRange.class, oObj);
153 TestEnvironment tEnv = new TestEnvironment(oObj);
155 tEnv.addObjRelation("SHEET", oSheet);
156 // add expected results for the XCellRangesQuery interface test
157 String[]expectedResults = new String[7];
158 expectedResults[_XCellRangesQuery.QUERYCOLUMNDIFFERENCES] = "Sheet1.B1:C1;Sheet1.B3";
159 expectedResults[_XCellRangesQuery.QUERYCONTENTCELLS] = "Sheet1.B2:B3";
160 expectedResults[_XCellRangesQuery.QUERYEMPTYCELLS] = "Sheet1.A1 ... Sheet1.B1 ... Sheet1.B5 ... Sheet1.C3 ... Sheet1.D1";
161 expectedResults[_XCellRangesQuery.QUERYFORMULACELLS] = "Sheet1.C2";
162 expectedResults[_XCellRangesQuery.QUERYINTERSECTION] = "Sheet1.D4";
163 expectedResults[_XCellRangesQuery.QUERYROWDIFFERENCES] = "Sheet1.A2:A4;Sheet1.C2:D4";
164 expectedResults[_XCellRangesQuery.QUERYVISIBLECELLS] = "Sheet1.A2";
165 tEnv.addObjRelation("XCellRangesQuery.EXPECTEDRESULTS", expectedResults);
166 tEnv.addObjRelation("XCellRangesQuery.CREATEENTRIES", Boolean.TRUE);
168 XPropertySet PropSet = UnoRuntime.queryInterface(
169 XPropertySet.class, oObj);
170 tEnv.addObjRelation("PropSet", PropSet);
172 // XSearchable: Add a cell to make a searchable entry
173 try {
174 tEnv.addObjRelation("XSearchable.MAKEENTRYINCELL", new XCell[] {
175 testRange.getCellByPosition(0,0), testRange.getCellByPosition(0,1)});
177 catch(com.sun.star.lang.IndexOutOfBoundsException e){
178 e.printStackTrace(log);
179 log.println("Cannot make required object relation 'XSearchable.MAKEENTRYINCELL'.");
182 // XCellRangeData
183 /* Object[][] newData = new Object[5][4];
184 for (int i=0; i<newData.length; i++) {
185 for (int j=0; j<newData[i].length; j++) {
186 newData[i][j] = Double.valueOf(i*10+j);
189 tEnv.addObjRelation("NewData", newData); */
191 //Adding relation for util.XSortable
192 final PrintWriter finalLog = log;
193 final XCellRange oTable = testRange;
194 tEnv.addObjRelation("SORTCHECKER",
195 new ifc.util._XSortable.XSortChecker() {
196 PrintWriter out = finalLog;
198 public void setPrintWriter(PrintWriter log) {
199 out = log;
202 public void prepareToSort() {
203 try {
204 oTable.getCellByPosition(0, 0).setValue(4);
205 oTable.getCellByPosition(0, 1).setFormula("b");
206 oTable.getCellByPosition(0, 2).setValue(3);
207 oTable.getCellByPosition(0, 3).setValue(23);
208 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
209 out.println("Exception while checking sort");
213 public boolean checkSort(boolean isSortNumbering,
214 boolean isSortAscending) {
215 out.println("Sort checking...");
217 boolean res = false;
218 String[] value = new String[4];
220 for (int i = 0; i < 4; i++) {
221 try {
222 XCell cell = oTable.getCellByPosition(0, i);
223 value[i] = cell.getFormula();
224 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
225 out.println("Exception while checking sort");
229 if (isSortNumbering) {
230 if (isSortAscending) {
231 out.println("Sorting ascending");
233 String[] rightVal = { "3", "4", "23", "b" };
234 String[] vals = { value[0], value[1], value[2], value[3] };
235 res = ValueComparer.equalValue(vals, rightVal);
236 out.println("Expected 3, 4, 23, b");
237 out.println("getting: " + value[0] + ", " +
238 value[1] + ", " + value[2] + ", " +
239 value[3]);
240 } else {
241 String[] rightVal = { "b", "23", "4", "3" };
242 String[] vals = { value[0], value[1], value[2], value[3] };
243 res = ValueComparer.equalValue(vals, rightVal);
244 out.println("Expected b, 23, 4, 3");
245 out.println("getting: " + value[0] + ", " +
246 value[1] + ", " + value[2] + ", " +
247 value[3]);
249 } else {
250 if (isSortAscending) {
251 String[] rightVal = { "3", "4", "23", "b" };
252 res = ValueComparer.equalValue(value, rightVal);
253 out.println("Expected 3, 4, 23, b");
254 out.println("getting: " + value[0] + ", " +
255 value[1] + ", " + value[2] + ", " +
256 value[3]);
257 } else {
258 String[] rightVal = { "b", "23", "4", "3" };
259 res = ValueComparer.equalValue(value, rightVal);
260 out.println("Expected b, 23, 4, 3");
261 out.println("getting: " + value[0] + ", " +
262 value[1] + ", " + value[2] + ", " +
263 value[3]);
267 if (res) {
268 out.println("Sorted correctly");
269 } else {
270 out.println("Sorted incorrectly");
273 return res;
277 return tEnv;
279 } // finish class ScCellRangeObj