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