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