tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScCellCursorObj.java
blobfe155bba875890e98531c7830a3201f2b30ba78c
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.lang.XComponent;
29 import com.sun.star.sheet.XSheetCellRange;
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.SheetCellCursor</code>. <p>
45 * Object implements the following interfaces :
46 * <ul>
47 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
48 * <li> <code>com::sun::star::sheet::XUsedAreaCursor</code></li>
49 * <li> <code>com::sun::star::table::CellProperties</code></li>
50 * <li> <code>com::sun::star::table::XCellRange</code></li>
51 * <li> <code>com::sun::star::sheet::XCellRangeAddressable</code></li>
52 * <li> <code>com::sun::star::table::XCellCursor</code></li>
53 * <li> <code>com::sun::star::sheet::XSheetCellCursor</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::sheet::XArrayFormulaRange</code></li>
57 * <li> <code>com::sun::star::sheet::XSheetCellRange</code></li>
58 * <li> <code>com::sun::star::sheet::SheetCellRange</code></li>
59 * <li> <code>com::sun::star::chart::XChartData</code></li>
60 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
61 * <li> <code>com::sun::star::util::XMergeable</code></li>
62 * <li> <code>com::sun::star::table::XColumnRowRange</code></li>
63 * </ul>
64 * @see com.sun.star.sheet.SheetCellCursor
65 * @see com.sun.star.style.ParagraphProperties
66 * @see com.sun.star.sheet.XUsedAreaCursor
67 * @see com.sun.star.table.CellProperties
68 * @see com.sun.star.table.XCellRange
69 * @see com.sun.star.sheet.XCellRangeAddressable
70 * @see com.sun.star.table.XCellCursor
71 * @see com.sun.star.sheet.XSheetCellCursor
72 * @see com.sun.star.style.CharacterProperties
73 * @see com.sun.star.sheet.XSheetOperation
74 * @see com.sun.star.sheet.XArrayFormulaRange
75 * @see com.sun.star.sheet.XSheetCellRange
76 * @see com.sun.star.sheet.SheetCellRange
77 * @see com.sun.star.chart.XChartData
78 * @see com.sun.star.beans.XPropertySet
79 * @see com.sun.star.util.XMergeable
80 * @see com.sun.star.table.XColumnRowRange
81 * @see ifc.style._ParagraphProperties
82 * @see ifc.sheet._XUsedAreaCursor
83 * @see ifc.table._CellProperties
84 * @see ifc.table._XCellRange
85 * @see ifc.sheet._XCellRangeAddressable
86 * @see ifc.table._XCellCursor
87 * @see ifc.sheet._XSheetCellCursor
88 * @see ifc.style._CharacterProperties
89 * @see ifc.sheet._XSheetOperation
90 * @see ifc.sheet._XArrayFormulaRange
91 * @see ifc.sheet._XSheetCellRange
92 * @see ifc.sheet._SheetCellRange
93 * @see ifc.chart._XChartData
94 * @see ifc.beans._XPropertySet
95 * @see ifc.util._XMergeable
96 * @see ifc.table._XColumnRowRange
98 public class ScCellCursorObj extends TestCase {
99 private XSpreadsheetDocument xSheetDoc = null;
102 * Creates Spreadsheet document.
104 @Override
105 protected void initialize(TestParameters tParam, PrintWriter log) throws Exception {
106 SOfficeFactory SOF = SOfficeFactory.getFactory(
107 tParam.getMSF());
109 log.println("creating a Spreadsheet document");
110 xSheetDoc = SOF.createCalcDoc(null);
114 * Disposes Spreadsheet document.
116 @Override
117 protected void cleanup(TestParameters tParam, PrintWriter log) {
118 log.println(" disposing xSheetDoc ");
120 XComponent oComp = UnoRuntime.queryInterface(
121 XComponent.class, xSheetDoc);
123 util.DesktopTools.closeDoc(oComp);
127 * Creating a TestEnvironment for the interfaces to be tested.
128 * Retrieves a collection of spreadsheets from a document,
129 * and takes one of them, retrieves some cell range and creates cursor range
130 * that is instance of the service
131 * <code>com.sun.star.sheet.SheetCellCursor</code>,
132 * fills some cells in the cell range.
133 * Object relations created :
134 * <ul>
135 * <li> <code>'SHEET'</code> for
136 * {@link ifc.table._XCellCursor},
137 * {@link ifc.sheet._XArrayFormulaRange} (the spreadsheet that was
138 * retrieved from collection)</li>
139 * </ul>
141 @Override
142 protected TestEnvironment createTestEnvironment(TestParameters Param,
143 PrintWriter log) throws Exception {
144 XInterface oObj = null;
145 TestEnvironment tEnv = null;
146 XSpreadsheet oSheet = null;
147 XCellRange testRange = null;
150 // creation of testobject here
151 // first we write what we are intend to do to log file
152 log.println("Creating a test environment");
154 XSpreadsheets oSpreadsheets = UnoRuntime.queryInterface(
155 XSpreadsheetDocument.class,
156 xSheetDoc).getSheets();
158 oSheet = (XSpreadsheet) AnyConverter.toObject(
159 new Type(XSpreadsheet.class),
160 oSpreadsheets.getByName(
161 oSpreadsheets.getElementNames()[0]));
163 testRange = oSheet.getCellRangeByName("$A$1:$D$4");
165 XSheetCellRange testSheetRange = UnoRuntime.queryInterface(
166 XSheetCellRange.class,
167 testRange);
168 oObj = oSheet.createCursorByRange(testSheetRange);
169 oSheet.getCellByPosition(1, 1).setValue(1);
170 oSheet.getCellByPosition(4, 5).setValue(1);
171 oSheet.getCellByPosition(3, 2).setFormula("xTextDoc");
172 oSheet.getCellByPosition(3, 3).setFormula("xTextDoc");
174 log.println("Test object successfully created.");
176 tEnv = new TestEnvironment(oObj);
178 tEnv.addObjRelation("CRDESC",
179 "Column and RowDescriptions can't be changed for this Object");
181 tEnv.addObjRelation("SHEET", oSheet);
182 // add expected results for the XCellRangesQuery interface test
183 String[]expectedResults = new String[7];
184 expectedResults[_XCellRangesQuery.QUERYCOLUMNDIFFERENCES] = "Sheet1.B1";
185 expectedResults[_XCellRangesQuery.QUERYCONTENTCELLS] = "Sheet1.B2";
186 expectedResults[_XCellRangesQuery.QUERYEMPTYCELLS] = "Sheet1.A1 ... Sheet1.B1 ... Sheet1.B3 ... Sheet1.C1 ... Sheet1.D1";
187 expectedResults[_XCellRangesQuery.QUERYFORMULACELLS] = "";
188 expectedResults[_XCellRangesQuery.QUERYINTERSECTION] = "Sheet1.D4";
189 expectedResults[_XCellRangesQuery.QUERYROWDIFFERENCES] = "Sheet1.A2;Sheet1.C2";
190 expectedResults[_XCellRangesQuery.QUERYVISIBLECELLS] = "Sheet1.A2";
191 tEnv.addObjRelation("XCellRangesQuery.EXPECTEDRESULTS", expectedResults);
193 tEnv.addObjRelation("NewData",
194 new Object[][]
196 { "", "", "", "" },
197 { "", "2", "3", "4" },
198 { "", "2", "3", "4" },
199 { "", "2", "3", "4" }
202 XPropertySet PropSet = UnoRuntime.queryInterface(
203 XPropertySet.class, oObj);
204 tEnv.addObjRelation("PropSet", PropSet);
206 //Adding relation for util.XSortable
207 final PrintWriter finalLog = log;
208 final XCellRange oTable = testRange;
209 tEnv.addObjRelation("SORTCHECKER",
210 new ifc.util._XSortable.XSortChecker() {
211 PrintWriter out = finalLog;
213 public void setPrintWriter(PrintWriter log) {
214 out = log;
217 public void prepareToSort() {
218 try {
219 oTable.getCellByPosition(0, 0).setValue(4);
220 oTable.getCellByPosition(0, 1).setFormula("b");
221 oTable.getCellByPosition(0, 2).setValue(3);
222 oTable.getCellByPosition(0, 3).setValue(23);
223 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
224 out.println("Exception while checking sort");
228 public boolean checkSort(boolean isSortNumbering,
229 boolean isSortAscending) {
230 out.println("Sort checking...");
232 boolean res = false;
233 String[] value = new String[4];
235 for (int i = 0; i < 4; i++) {
236 try {
237 XCell cell = oTable.getCellByPosition(0, i);
238 value[i] = cell.getFormula();
239 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
240 out.println("Exception while checking sort");
244 if (isSortNumbering) {
245 if (isSortAscending) {
246 out.println("Sorting ascending");
248 String[] rightVal = { "3", "4", "23", "b" };
249 String[] vals = { value[0], value[1], value[2], value[3] };
250 res = ValueComparer.equalValue(vals, rightVal);
251 out.println("Expected 3, 4, 23, b");
252 out.println("getting: " + value[0] + ", " +
253 value[1] + ", " + value[2] + ", " +
254 value[3]);
255 } else {
256 String[] rightVal = { "b", "23", "4", "3" };
257 String[] vals = { value[0], value[1], value[2], value[3] };
258 res = ValueComparer.equalValue(vals, rightVal);
259 out.println("Expected b, 23, 4, 3");
260 out.println("getting: " + value[0] + ", " +
261 value[1] + ", " + value[2] + ", " +
262 value[3]);
264 } else {
265 if (isSortAscending) {
266 String[] rightVal = { "3", "4", "23", "b" };
267 res = ValueComparer.equalValue(value, rightVal);
268 out.println("Expected 3, 4, 23, b");
269 out.println("getting: " + value[0] + ", " +
270 value[1] + ", " + value[2] + ", " +
271 value[3]);
272 } else {
273 String[] rightVal = { "b", "23", "4", "3" };
274 res = ValueComparer.equalValue(value, rightVal);
275 out.println("Expected b, 23, 4, 3");
276 out.println("getting: " + value[0] + ", " +
277 value[1] + ", " + value[2] + ", " +
278 value[3]);
282 if (res) {
283 out.println("Sorted correctly");
284 } else {
285 out.println("Sorted incorrectly");
288 return res;
292 return tEnv;
294 } // finish class ScCellCursorObj