tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / table / _XTableColumns.java
blobd0d1b03bf66e922a6ad5f680d45f549cb3aff4cb
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 ifc.table;
21 import lib.MultiMethodTest;
22 import lib.Status;
23 import lib.StatusException;
25 import com.sun.star.table.XCell;
26 import com.sun.star.table.XCellRange;
27 import com.sun.star.table.XTableColumns;
28 import com.sun.star.text.XSimpleText;
29 import com.sun.star.uno.UnoRuntime;
31 /**
32 * Testing <code>com.sun.star.table.XTableColumns</code>
33 * interface methods :
34 * <ul>
35 * <li><code> insertByIndex()</code></li>
36 * <li><code> removeByIndex()</code></li>
37 * </ul> <p>
39 * This test needs the following object relations :
40 * <ul>
41 * <li> <code>'XTableColumns.XCellRange'</code> : <code>
42 * com.sun.star.table.XCellRange</code> the cell range of
43 * columns.</li>
44 * <ul> <p>
46 * Test is multithread compliant. <p>
47 * @see com.sun.star.table.XTableColumns
49 public class _XTableColumns extends MultiMethodTest {
51 public XTableColumns oObj = null;
52 private XCellRange xCellRange = null;
53 private int lastColumn = 0;
55 @Override
56 public void before() {
57 xCellRange = (XCellRange)
58 tEnv.getObjRelation("XTableColumns.XCellRange") ;
60 if (xCellRange == null) throw new
61 StatusException(Status.failed("Relation missing"));
63 lastColumn = oObj.getCount() - 1 ;
66 /**
67 * First a number of cells in cell range are filled with data.
69 * Then columns inserted to valid positions : 1 column at 1,
70 * 1 column at 0, 2 columns at 0. <p>
72 * Then columns inserted to invalid positions : position -1,
73 * the column after last, and 0 columns inserted. <p>
75 * Has <b> OK </b> status if for valid cases :
76 * <ul>
77 * <li> content of other cells are properly shifted </li>
78 * <li> inserted columns are empty </li>
79 * <li> number of columns increases (in case if it is not the whole
80 * spreadsheet) by proper number. </li>
81 * </ul>
82 * and for invalid cases exception is thrown.
84 public void _insertByIndex() {
86 boolean result = true;
87 int origCnt = oObj.getCount();
89 try {
90 log.println("Filling range ... ");
91 fillRange(xCellRange);
93 log.println("Inserting 1 column at position 1 ...");
94 oObj.insertByIndex(1,1);
96 result &= checkColumn(0, 0);
97 result &= checkColumnEmpty(1);
98 result &= checkColumn(2, 1);
99 result &= checkColumn(3, 2);
100 result &= checkColumnEmpty(4);
102 if (lastColumn < 200) {
103 result &= checkColumn(lastColumn + 1, lastColumn);
104 result &= oObj.getCount() == origCnt + 1;
105 } else {
106 result &= checkColumnEmpty(lastColumn);
109 log.println("Inserting 1 column at position 0 ...");
110 oObj.insertByIndex(0,1);
112 result &= checkColumnEmpty(0);
113 result &= checkColumn(1, 0);
114 result &= checkColumnEmpty(2);
115 result &= checkColumn(3, 1);
116 result &= checkColumn(4, 2);
117 result &= checkColumnEmpty(5);
118 if (lastColumn < 200) {
119 result &= checkColumn(lastColumn + 2, lastColumn);
120 result &= oObj.getCount() == origCnt + 2;
123 log.println("Inserting 2 columns at position 0 ...");
124 oObj.insertByIndex(0,2);
126 result &= checkColumnEmpty(0);
127 result &= checkColumnEmpty(1);
128 result &= checkColumnEmpty(2);
129 result &= checkColumn(3, 0);
130 result &= checkColumnEmpty(4);
131 result &= checkColumn(5, 1);
132 result &= checkColumn(6, 2);
133 result &= checkColumnEmpty(7);
134 if (lastColumn < 200) {
135 result &= checkColumn(lastColumn + 4, lastColumn);
138 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
139 e.printStackTrace(log);
140 result = false;
144 // spreadsheet supports 256 columns and after inserting
145 // or removing a column their number remains the same
146 if (origCnt < 200) {
147 log.println("Checking that number of column increased.");
148 result &= oObj.getCount() == origCnt + 4;
149 log.println("Before: " + origCnt + ", After: " + oObj.getCount());
150 } else {
151 log.println("Number of columns is " + origCnt + ",") ;
152 log.println("supposing that this is the whole spreadsheet and ");
153 log.println("number of columns should not change.");
156 try {
157 oObj.insertByIndex(-1,1);
158 log.println("No Exception occurred while inserting column at -1");
159 result &= false;
160 } catch (Exception e) {
161 log.println("Inserting column at Index -1 ... OK");
162 result &= true;
165 int cnt = oObj.getCount();
166 try {
167 oObj.insertByIndex(cnt, 1);
168 log.println("No Exception occurred while inserting column at "
169 + cnt);
170 result &= false;
171 } catch (Exception e) {
172 log.println("Inserting column at Index " + cnt + " ... OK");
173 result &= true;
176 if (tEnv.getTestCase().getObjectName().equals("ScTableColumnsObj")) {
178 try {
179 oObj.insertByIndex(0,0);
180 log.println("No Exception occurred while inserting 0 columns");
181 result &= false;
182 } catch (Exception e) {
183 log.println("Inserting 0 columns ... OK");
184 result &= true;
189 tRes.tested( "insertByIndex()", result );
191 } // end insertByIndex()
194 * Columns removed from valid positions : 1 column at 1,
195 * 1 column at 0, 2 columns at 0. <p>
197 * Then columns removed from invalid positions : position -1,
198 * the column after last, and 0 columns removed. <p>
200 * Has <b> OK </b> status if for valid cases :
201 * <ul>
202 * <li> content of other cells are properly shifted </li>
203 * <li> columns which are shifted left are empty </li>
204 * <li> number of columns decreases (in case if it is not the whole
205 * spreadsheet) by proper number. </li>
206 * </ul>
207 * and for invalid cases exception is thrown.
209 public void _removeByIndex() {
210 executeMethod("insertByIndex()");
212 boolean result = true;
213 int origCnt = oObj.getCount();
215 try {
216 log.println("Filling range ... ");
218 log.println("Removing 2 columns at position 0 ...");
219 oObj.removeByIndex(0,2);
221 result &= checkColumnEmpty(0);
222 result &= checkColumn(1, 0);
223 result &= checkColumnEmpty(2);
224 result &= checkColumn(3, 1);
225 result &= checkColumn(4, 2);
226 result &= checkColumnEmpty(5);
227 if (lastColumn < 200) {
228 result &= checkColumn(lastColumn + 2, lastColumn);
229 result &= oObj.getCount() == origCnt - 2;
232 log.println("Removing 1 column at position 0 ...");
233 oObj.removeByIndex(0,1);
235 result &= checkColumn(0, 0);
236 result &= checkColumnEmpty(1);
237 result &= checkColumn(2, 1);
238 result &= checkColumn(3, 2);
239 result &= checkColumnEmpty(4);
240 if (lastColumn < 200) {
241 result &= checkColumn(lastColumn + 1, lastColumn);
242 result &= oObj.getCount() == origCnt - 3;
245 log.println("Removing 1 column at position 1 ...");
246 oObj.removeByIndex(1,1);
248 result &= checkColumn(0, 0);
249 result &= checkColumn(1, 1);
250 result &= checkColumn(2, 2);
251 result &= checkColumnEmpty(3);
252 if (lastColumn < 200) {
253 result &= checkColumn(lastColumn, lastColumn);
256 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
257 e.printStackTrace(log);
258 result = false;
262 // spreadsheet supports 256 columns and after inserting
263 // or removing a column their number remains the same
264 if (origCnt < 200) {
265 log.println("Checking that number of column increased.");
266 result &= oObj.getCount() == origCnt - 4;
267 log.println("Before: " + origCnt + ", After: " + oObj.getCount());
268 } else {
269 log.println("Number of columns is " + origCnt + ",") ;
270 log.println("supposing that this is the whole spreadsheet and ");
271 log.println("number of columns should not change.");
274 try {
275 oObj.removeByIndex(-1,1);
276 log.println("No Exception occurred while removing column at -1");
277 result &= false;
278 } catch (Exception e) {
279 log.println("removing column at Index -1 ... OK");
280 result &= true;
283 int cnt = oObj.getCount();
284 try {
285 oObj.removeByIndex(cnt, 1);
286 log.println("No Exception occurred while removing column at "
287 + cnt);
288 result &= false;
289 } catch (Exception e) {
290 log.println("Removing column at Index " + cnt + " ... OK");
291 result &= true;
294 if (tEnv.getTestCase().getObjectName().equals("ScTableColumnsObj")) {
295 try {
296 oObj.removeByIndex(0,0);
297 log.println("No Exception occurred while removing 0 columns");
298 result &= false;
299 } catch (Exception e) {
300 log.println("removing 0 columns ... OK");
301 result &= true;
305 tRes.tested( "removeByIndex()", result );
306 } // end removeByIndex()
308 private void setCellText(XCell cell, String text) {
309 XSimpleText xText = UnoRuntime.queryInterface
310 (XSimpleText.class, cell) ;
311 xText.setString(text);
313 private String getCellText(XCell cell) {
314 XSimpleText xText = UnoRuntime.queryInterface
315 (XSimpleText.class, cell) ;
316 return xText.getString();
320 * Fills the range with some data : two rows and 3 columns, and
321 * some columns are cleared.
323 * @param xRange Range to fill
324 * @throws IndexOutOfBoundsException if any errors occur during filling.
326 private void fillRange(XCellRange xRange)
327 throws com.sun.star.lang.IndexOutOfBoundsException {
329 for (int i = 0; i <= lastColumn && i < 3; i++) {
330 setCellText(xRange.getCellByPosition(i, 0), i + "a");
331 setCellText(xRange.getCellByPosition(i, 1), i + "b");
334 for (int i = 3; i <= lastColumn && i < 10; i++) {
335 setCellText(xRange.getCellByPosition(i, 0), "");
336 setCellText(xRange.getCellByPosition(i, 1), "");
341 * Check the column (first two rows) if it has values with
342 * index specified.
344 * @param col Column to check
345 * @param idx What indexes must be in cells
346 * @return <code>true</code> if expected indexes are found,
347 * <code>false</code> otherwise.
348 * @throws IndexOutOfBoundsException
350 private boolean checkColumn(int col, int idx)
351 throws com.sun.star.lang.IndexOutOfBoundsException {
353 if (col >= oObj.getCount()) return true;
355 String c1 = getCellText(xCellRange.getCellByPosition(col, 0));
356 String c2 = getCellText(xCellRange.getCellByPosition(col, 1));
358 if (!((idx + "a").equals(c1) && (idx + "b").equals(c2))) {
360 log.println("FAILED for column " + col + " and index " + idx + "("
361 + c1 + "," + c2 + ")");
362 return false ;
364 return true;
368 * Checks if the column (first two rows) has no data in its cells.
370 * @param col Column to check
371 * @return <code>true</code> if the column is empty, <code>false</code>
372 * if first two cells contains some strings.
373 * @throws IndexOutOfBoundsException
375 private boolean checkColumnEmpty(int col)
376 throws com.sun.star.lang.IndexOutOfBoundsException {
378 if (col >= oObj.getCount()) return true;
380 String c1 = getCellText(xCellRange.getCellByPosition(col, 0));
381 String c2 = getCellText(xCellRange.getCellByPosition(col, 1));
382 if (!("".equals(c1) && "".equals(c2))) {
383 log.println("FAILED for column " + col + " is not empty ("
384 + c1 + "," + c2 + ")");
385 return false ;
387 return true;
390 } //finish class _XTableColumns