1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.text;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.table.XCell;
29 import com.sun.star.text.XTextTableCursor;
30 
31 
32 /**
33  * Testing <code>com.sun.star.text.XTextTableCursor</code>
34  * interface methods :
35  * <ul>
36  *  <li><code> getRangeName()</code></li>
37  *  <li><code> gotoCellByName()</code></li>
38  *  <li><code> goLeft()</code></li>
39  *  <li><code> goRight()</code></li>
40  *  <li><code> goUp()</code></li>
41  *  <li><code> goDown()</code></li>
42  *  <li><code> gotoStart()</code></li>
43  *  <li><code> gotoEnd()</code></li>
44  *  <li><code> mergeRange()</code></li>
45  *  <li><code> splitRange()</code></li>
46  * </ul> <p>
47  *
48  * <b>Prerequisites : </b> the table must have a size
49  * 2x2 and current cursor position must be in the upper
50  * left cell. <p>
51  *
52  * Test is <b> NOT </b> multithread compilant. <p>
53  *
54  * After test completion object environment has to be recreated
55  * because after merging and splitting cells their names
56  * differ from initial.
57  *
58  * @see com.sun.star.text.XTextTableCursor
59  */
60 public class _XTextTableCursor extends MultiMethodTest {
61 
62     public XTextTableCursor oObj = null;    // oObj filled by MultiMethodTest
63 
64     XCell oCell = null;
65 
66     /**
67      * Moves the cursor to upper-left cell and checks
68      * its range name. <p>
69      *
70      * Has <b>OK</b> status if the name returned is 'A1'.
71      */
_getRangeName()72     public void _getRangeName(){
73         log.println( "test for getRangeName()" );
74         oObj.gotoStart(false);
75         String oCellName = oObj.getRangeName();
76         log.println( "CellName = " + oCellName );
77 
78         tRes.tested("getRangeName()", oCellName.equals("A1") );
79     }
80 
81     /**
82      * Calls the method which moves the cursor down by 1 cell,
83      * after that returns cursor to the old position. <p>
84      *
85      * Has <b>OK</b> status if the method returns
86      * <code>true</code>.
87      */
_goDown()88     public void _goDown(){
89         boolean bDown = false;
90         log.println( "test for goDown()" );
91         short i = 1;
92 
93         bDown = oObj.goDown(i,false);
94 
95         tRes.tested("goDown()", bDown );
96         oObj.goUp(i,false);
97     }
98 
99     /**
100      * Calls the method which moves the cursor to the right by 1 cell,
101      * after that returns cursor to the old position. <p>
102      *
103      * Has <b>OK</b> status if the method returns
104      * <code>true</code>.
105      */
_goRight()106     public void _goRight(){
107         boolean bRight = false;
108         log.println( "test for goRight()" );
109         short i = 1;
110 
111         bRight = oObj.goRight(i,false);
112 
113         tRes.tested("goRight()", bRight );
114         oObj.goLeft(i,false);
115     }
116 
117     /**
118      * Calls the method which moves the cursor to the left by 1 cell,
119      * after that returns cursor to the old position. <p>
120      *
121      * Has <b>OK</b> status if the method returns
122      * <code>true</code>.
123      */
_goLeft()124     public void _goLeft(){
125         boolean bLeft = false;
126         log.println( "test for goLeft()" );
127         short i = 1;
128 
129         oObj.goRight(i,false);
130         bLeft = oObj.goLeft(i,false);
131 
132         tRes.tested("goLeft()", bLeft );
133     }
134 
135     /**
136      * Calls the method which moves the cursor up by 1 cell,
137      * after that returns cursor to the old position. <p>
138      *
139      * Has <b>OK</b> status if the method returns
140      * <code>true</code>.
141      */
_goUp()142     public void _goUp(){
143         boolean bUp = false;
144         log.println( "test for goUp()" );
145         short i = 1;
146 
147         oObj.gotoEnd(true);
148 
149         bUp = oObj.goUp(i,false);
150         tRes.tested("goUp()", bUp );
151     }
152 
153     /**
154      * Moves the cursor to the cell with name 'B1', then
155      * checks the current range name. <p>
156      * Has <b>OK</b> status if the returned range name is
157      * 'B1'.
158      */
_gotoCellByName()159     public void _gotoCellByName(){
160         log.println( "test for gotoCellByName()" );
161 
162         oObj.gotoCellByName("B1",false);
163         String oCellName = oObj.getRangeName();
164 
165         tRes.tested("gotoCellByName()", oCellName.equals("B1") );
166     }
167 
168     /**
169      * Moves cursor to the start (upper-left cell). Then
170      * checks the current range name. <p>
171      *
172      * Has <b>OK</b> status if current range name is 'A1'.
173      */
_gotoStart()174     public void _gotoStart(){
175         log.println( "test for gotoStart()" );
176 
177         oObj.gotoStart(false);
178         String oCellName = oObj.getRangeName();
179 
180         tRes.tested("gotoStart()", oCellName.equals("A1") );
181     }
182 
183     /**
184      * Moves cursor to the end (lower-right cell). Then
185      * checks the current range name. <p>
186      *
187      * Has <b>OK</b> status if current range name is 'B2'
188      * (the table is assumed to be of size 2x2).
189      */
_gotoEnd()190     public void _gotoEnd(){
191         log.println( "test for gotoEnd()" );
192 
193         oObj.gotoEnd(false);
194         String oCellName = oObj.getRangeName();
195 
196         tRes.tested("gotoEnd()", oCellName.equals("B2") );
197     }
198 
199     /**
200      * Selects all cells in the table and merges them.
201      * Finally move the cursor to the end and checks
202      * current range name.<p>
203      *
204      * Has <b>OK</b> status if the end cell has a name
205      * 'A1'.
206      *
207      * The following method tests are to be executed before :
208      * <ul>
209      *  <li> <code> getRangeName(), gotoStart(),  gotoEnd()
210      *    goLeft(), goRight(), goUp(), goDown(), gotoCellByName()</code>
211      *    : these methods must be completed before all cells of the
212      *    table are merged into one cell </li>
213      * </ul>
214      */
_mergeRange()215     public void _mergeRange(){
216         executeMethod("getRangeName()") ;
217         executeMethod("gotoStart()") ;
218         executeMethod("gotoEnd()") ;
219         executeMethod("goLeft()") ;
220         executeMethod("goRight()") ;
221         executeMethod("goUp()") ;
222         executeMethod("goDown()") ;
223         executeMethod("gotoCellByName()") ;
224 
225         boolean bMerge = false;
226         log.println( "test for mergeRange()" );
227 
228         oObj.gotoStart(false);
229         oObj.gotoEnd(true);
230         bMerge = oObj.mergeRange();
231 
232         oObj.gotoEnd(false);
233 
234         String curName = oObj.getRangeName() ;
235         bMerge &= "A1".equals(curName) ;
236 
237         tRes.tested("mergeRange()", bMerge );
238     }
239 
240     /**
241      * First splits the cell horyzontally. Then the end cell
242      * name is checked. Second split all cells vertically and
243      * again the end cell name is checked<p>
244      *
245      * Has <b> OK </b> status if in the first case the end cell name
246      * is not 'A1', and in the second case the end cell name is not
247      * equal to the name gotten in the first case. <p>
248      *
249      * The following method tests are to be completed successfully before :
250      * <ul>
251      *  <li> <code> mergeRange() </code> : to have one cell in a table
252      *    which this test splits. </li>
253      * </ul>
254      */
_splitRange()255     public void _splitRange(){
256         requiredMethod("mergeRange()") ;
257 
258         boolean bSplit = true ;
259         log.println( "test for splitRange" ) ;
260         short i = 1 ;
261 
262         bSplit &= oObj.splitRange(i, true) ;
263 
264         oObj.gotoEnd(false);
265         String horName = oObj.getRangeName() ;
266         log.println("The end cell after horiz. split : " + horName) ;
267         bSplit &= !"A1".equals(horName) ;
268 
269         oObj.gotoStart(false);
270         oObj.gotoEnd(true);
271         bSplit &= oObj.splitRange(i, false) ;
272 
273         oObj.gotoEnd(false);
274         String vertName = oObj.getRangeName() ;
275         log.println("The end cell after vert. split : " + vertName) ;
276         bSplit &= !horName.equals(vertName) ;
277 
278         tRes.tested("splitRange()", bSplit ) ;
279     }
280 
281     /**
282      * Forces object environment recreation.
283      */
after()284     public void after() {
285         disposeEnvironment() ;
286     }
287 
288  }  // finish class _XTextTableCursor
289 
290 
291