Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / ifc / text / _XTextTableCursor.java
blobac95453d0de1884ed8b4a73fa1a144e1ce42585f
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.text;
21 import lib.MultiMethodTest;
23 import com.sun.star.text.XTextTableCursor;
26 /**
27 * Testing <code>com.sun.star.text.XTextTableCursor</code>
28 * interface methods :
29 * <ul>
30 * <li><code> getRangeName()</code></li>
31 * <li><code> gotoCellByName()</code></li>
32 * <li><code> goLeft()</code></li>
33 * <li><code> goRight()</code></li>
34 * <li><code> goUp()</code></li>
35 * <li><code> goDown()</code></li>
36 * <li><code> gotoStart()</code></li>
37 * <li><code> gotoEnd()</code></li>
38 * <li><code> mergeRange()</code></li>
39 * <li><code> splitRange()</code></li>
40 * </ul> <p>
42 * <b>Prerequisites : </b> the table must have a size
43 * 2x2 and current cursor position must be in the upper
44 * left cell. <p>
46 * Test is <b> NOT </b> multithread compliant. <p>
48 * After test completion object environment has to be recreated
49 * because after merging and splitting cells their names
50 * differ from initial.
52 * @see com.sun.star.text.XTextTableCursor
54 public class _XTextTableCursor extends MultiMethodTest {
56 public XTextTableCursor oObj = null; // oObj filled by MultiMethodTest
58 /**
59 * Moves the cursor to upper-left cell and checks
60 * its range name. <p>
62 * Has <b>OK</b> status if the name returned is 'A1'.
64 public void _getRangeName(){
65 log.println( "test for getRangeName()" );
66 oObj.gotoStart(false);
67 String oCellName = oObj.getRangeName();
68 log.println( "CellName = " + oCellName );
70 tRes.tested("getRangeName()", oCellName.equals("A1") );
73 /**
74 * Calls the method which moves the cursor down by 1 cell,
75 * after that returns cursor to the old position. <p>
77 * Has <b>OK</b> status if the method returns
78 * <code>true</code>.
80 public void _goDown(){
81 boolean bDown = false;
82 log.println( "test for goDown()" );
83 short i = 1;
85 bDown = oObj.goDown(i,false);
87 tRes.tested("goDown()", bDown );
88 oObj.goUp(i,false);
91 /**
92 * Calls the method which moves the cursor to the right by 1 cell,
93 * after that returns cursor to the old position. <p>
95 * Has <b>OK</b> status if the method returns
96 * <code>true</code>.
98 public void _goRight(){
99 boolean bRight = false;
100 log.println( "test for goRight()" );
101 short i = 1;
103 bRight = oObj.goRight(i,false);
105 tRes.tested("goRight()", bRight );
106 oObj.goLeft(i,false);
110 * Calls the method which moves the cursor to the left by 1 cell,
111 * after that returns cursor to the old position. <p>
113 * Has <b>OK</b> status if the method returns
114 * <code>true</code>.
116 public void _goLeft(){
117 boolean bLeft = false;
118 log.println( "test for goLeft()" );
119 short i = 1;
121 oObj.goRight(i,false);
122 bLeft = oObj.goLeft(i,false);
124 tRes.tested("goLeft()", bLeft );
128 * Calls the method which moves the cursor up by 1 cell,
129 * after that returns cursor to the old position. <p>
131 * Has <b>OK</b> status if the method returns
132 * <code>true</code>.
134 public void _goUp(){
135 boolean bUp = false;
136 log.println( "test for goUp()" );
137 short i = 1;
139 oObj.gotoEnd(true);
141 bUp = oObj.goUp(i,false);
142 tRes.tested("goUp()", bUp );
146 * Moves the cursor to the cell with name 'B1', then
147 * checks the current range name. <p>
148 * Has <b>OK</b> status if the returned range name is
149 * 'B1'.
151 public void _gotoCellByName(){
152 log.println( "test for gotoCellByName()" );
154 oObj.gotoCellByName("B1",false);
155 String oCellName = oObj.getRangeName();
157 tRes.tested("gotoCellByName()", oCellName.equals("B1") );
161 * Moves cursor to the start (upper-left cell). Then
162 * checks the current range name. <p>
164 * Has <b>OK</b> status if current range name is 'A1'.
166 public void _gotoStart(){
167 log.println( "test for gotoStart()" );
169 oObj.gotoStart(false);
170 String oCellName = oObj.getRangeName();
172 tRes.tested("gotoStart()", oCellName.equals("A1") );
176 * Moves cursor to the end (lower-right cell). Then
177 * checks the current range name. <p>
179 * Has <b>OK</b> status if current range name is 'B2'
180 * (the table is assumed to be of size 2x2).
182 public void _gotoEnd(){
183 log.println( "test for gotoEnd()" );
185 oObj.gotoEnd(false);
186 String oCellName = oObj.getRangeName();
188 tRes.tested("gotoEnd()", oCellName.equals("B2") );
192 * Selects all cells in the table and merges them.
193 * Finally move the cursor to the end and checks
194 * current range name.<p>
196 * Has <b>OK</b> status if the end cell has a name
197 * 'A1'.
199 * The following method tests are to be executed before :
200 * <ul>
201 * <li> <code> getRangeName(), gotoStart(), gotoEnd()
202 * goLeft(), goRight(), goUp(), goDown(), gotoCellByName()</code>
203 * : these methods must be completed before all cells of the
204 * table are merged into one cell </li>
205 * </ul>
207 public void _mergeRange(){
208 executeMethod("getRangeName()") ;
209 executeMethod("gotoStart()") ;
210 executeMethod("gotoEnd()") ;
211 executeMethod("goLeft()") ;
212 executeMethod("goRight()") ;
213 executeMethod("goUp()") ;
214 executeMethod("goDown()") ;
215 executeMethod("gotoCellByName()") ;
217 boolean bMerge = false;
218 log.println( "test for mergeRange()" );
220 oObj.gotoStart(false);
221 oObj.gotoEnd(true);
222 bMerge = oObj.mergeRange();
224 oObj.gotoEnd(false);
226 String curName = oObj.getRangeName() ;
227 bMerge &= "A1".equals(curName) ;
229 tRes.tested("mergeRange()", bMerge );
233 * First splits the cell horizontally. Then the end cell
234 * name is checked. Second split all cells vertically and
235 * again the end cell name is checked<p>
237 * Has <b> OK </b> status if in the first case the end cell name
238 * is not 'A1', and in the second case the end cell name is not
239 * equal to the name gotten in the first case. <p>
241 * The following method tests are to be completed successfully before :
242 * <ul>
243 * <li> <code> mergeRange() </code> : to have one cell in a table
244 * which this test splits. </li>
245 * </ul>
247 public void _splitRange(){
248 requiredMethod("mergeRange()") ;
250 boolean bSplit = true ;
251 log.println( "test for splitRange" ) ;
252 short i = 1 ;
254 bSplit &= oObj.splitRange(i, true) ;
256 oObj.gotoEnd(false);
257 String horName = oObj.getRangeName() ;
258 log.println("The end cell after horiz. split : " + horName) ;
259 bSplit &= !"A1".equals(horName) ;
261 oObj.gotoStart(false);
262 oObj.gotoEnd(true);
263 bSplit &= oObj.splitRange(i, false) ;
265 oObj.gotoEnd(false);
266 String vertName = oObj.getRangeName() ;
267 log.println("The end cell after vert. split : " + vertName) ;
268 bSplit &= !horName.equals(vertName) ;
270 tRes.tested("splitRange()", bSplit ) ;
274 * Forces object environment recreation.
276 @Override
277 public void after() {
278 disposeEnvironment() ;
281 } // finish class _XTextTableCursor