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.table;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.sheet.XCellRangeAddressable;
29 import com.sun.star.sheet.XSheetCellCursor;
30 import com.sun.star.sheet.XSheetCellRange;
31 import com.sun.star.sheet.XSpreadsheet;
32 import com.sun.star.table.CellRangeAddress;
33 import com.sun.star.table.XCellCursor;
34 import com.sun.star.table.XCellRange;
35 import com.sun.star.uno.UnoRuntime;
36 
37 /**
38 * Testing <code>com.sun.star.table.XCellCursor</code>
39 * interface methods :
40 * <ul>
41 *  <li><code> gotoStart()</code></li>
42 *  <li><code> gotoEnd()</code></li>
43 *  <li><code> gotoNext()</code></li>
44 *  <li><code> gotoPrevious()</code></li>
45 *  <li><code> gotoOffset()</code></li>
46 * </ul> <p>
47 * This test needs the following object relations :
48 * <ul>
49 *  <li> <code>'SHEET'</code> (of type <code>XSpreadsheet</code>):
50 *   is used for creating a new cell range.</li>
51 * <ul> <p>
52 *
53 * The component tested <b>must implement</b>
54 * <code>XCellRangeAddressable</code> interface. <p>
55 *
56 * Test is <b> NOT </b> multithread compilant. <p>
57 * After test completion object environment has to be recreated.
58 * @see com.sun.star.table.XCellCursor
59 */
60 public class _XCellCursor extends MultiMethodTest {
61 
62     public static XCellCursor oObj = null;
63     public static XSpreadsheet oSheet = null;
64 
65     /**
66      * <code>XCellRangeAddressable</code> interface is queried
67      * first for getting current position of cursor. The cursor
68      * is moved to next cell. Address of cursor obtained before
69      * and after moving. <p>
70      * Has <b> OK </b> status if cursor column is changed after
71      * movement. <p>
72      */
_gotoNext()73     public void _gotoNext(){
74         boolean bResult = false;
75         int startCol, endCol, startRow, endRow = 0;
76         int startCol2, endCol2, startRow2, endRow2 = 0;
77 
78         XCellRangeAddressable oRange = (XCellRangeAddressable)
79             UnoRuntime.queryInterface(XCellRangeAddressable.class, oObj);
80         CellRangeAddress oAddr = oRange.getRangeAddress();
81         startRow = oAddr.StartRow;
82         startCol = oAddr.StartColumn;
83         endRow = oAddr.EndRow;
84         endCol = oAddr.EndColumn;
85 
86         oObj.gotoNext();
87 
88         oAddr = oRange.getRangeAddress();
89         startRow2 = oAddr.StartRow;
90         startCol2 = oAddr.StartColumn;
91         endRow2 = oAddr.EndRow;
92         endCol2 = oAddr.EndColumn;
93 
94         if (!(startCol == startCol2)){
95             bResult = true;
96         }
97         tRes.tested( "gotoNext()", bResult );
98     }
99 
100     /**
101      * <code>XCellRangeAddressable</code> interface is queried
102      * first for getting current position of cursor. The cursor
103      * is moved then. Address of cursor obtained before
104      * and after moving. <p>
105      * Has <b> OK </b> status if starting column and row of
106      * cursor is changed after movement. <p>
107      */
_gotoOffset()108     public void _gotoOffset(){
109         boolean bResult = false;
110         int startCol, endCol, startRow, endRow = 0;
111         int startCol2, endCol2, startRow2, endRow2 = 0;
112 
113         XCellRangeAddressable oRange = (XCellRangeAddressable)
114             UnoRuntime.queryInterface(XCellRangeAddressable.class, oObj);
115         CellRangeAddress oAddr = oRange.getRangeAddress();
116         startRow = oAddr.StartRow;
117         startCol = oAddr.StartColumn;
118         endRow = oAddr.EndRow;
119         endCol = oAddr.EndColumn;
120 
121         oObj.gotoOffset(4,4);
122 
123         oAddr = oRange.getRangeAddress();
124         startRow2 = oAddr.StartRow;
125         startCol2 = oAddr.StartColumn;
126         endRow2 = oAddr.EndRow;
127         endCol2 = oAddr.EndColumn;
128         if (!(startCol == startCol2) || (startRow == startRow2)){
129             bResult = true;
130         }
131         tRes.tested( "gotoOffset()", bResult );
132     }
133 
134     /**
135      * <code>XCellRangeAddressable</code> interface is queried
136      * first for getting current position of cursor. The cursor
137      * is moved to previous cell. Address of cursor obtained before
138      * and after moving. <p>
139      * Has <b> OK </b> status if cursor column is changed after
140      * movement. <p>
141      */
_gotoPrevious()142     public void _gotoPrevious(){
143         boolean bResult = false;
144         int startCol, endCol, startRow, endRow = 0;
145         int startCol2, endCol2, startRow2, endRow2 = 0;
146 
147         XCellRangeAddressable oRange = (XCellRangeAddressable)
148                   UnoRuntime.queryInterface(XCellRangeAddressable.class, oObj);
149         CellRangeAddress oAddr = oRange.getRangeAddress();
150         startRow = oAddr.StartRow;
151         startCol = oAddr.StartColumn;
152         endRow = oAddr.EndRow;
153         endCol = oAddr.EndColumn;
154 
155         oObj.gotoPrevious();
156 
157         oAddr = oRange.getRangeAddress();
158         startRow2 = oAddr.StartRow;
159         startCol2 = oAddr.StartColumn;
160         endRow2 = oAddr.EndRow;
161         endCol2 = oAddr.EndColumn;
162 
163         if (!(startCol == startCol2)){
164             bResult = true;
165         }
166         tRes.tested( "gotoPrevious()", bResult );
167     }
168 
169     /**
170      * <code>XCellRangeAddressable</code> interface is queried
171      * first for getting current position of cursor. The cursor
172      * is moved to the start of its range .
173      * Address of cursor obtained before and after moving. <p>
174      * Has <b> OK </b> status if cursor was collapsed to a single
175      * cell (i.e. start column is the same as end column) after
176      * movement. <p>
177      */
_gotoStart()178     public void _gotoStart(){
179         boolean bResult = false;
180         int startCol, endCol, startRow, endRow = 0;
181 
182         XCellRangeAddressable oRange = (XCellRangeAddressable)
183                 UnoRuntime.queryInterface(XCellRangeAddressable.class, oObj);
184         oObj.gotoStart();
185         CellRangeAddress oAddr = oRange.getRangeAddress();
186         startRow = oAddr.StartRow;
187         startCol = oAddr.StartColumn;
188         endRow = oAddr.EndRow;
189         endCol = oAddr.EndColumn;
190         if ((startCol == endCol) && (endRow == startRow)){
191             bResult = true;
192         }
193 
194         tRes.tested( "gotoStart()", bResult );
195     }
196 
197     /**
198      * A new cell range is created using spreadsheet passed by relation.
199      * The method is tested on that range. <code>gotoEnd</code> is
200      * called and range address is checked.<p>
201      * Has <b> OK </b> status if cursor was collapsed to a single
202      * cell (i.e. start column is the same as end column) after
203      * movement. <p>
204      */
_gotoEnd()205     public void _gotoEnd(){
206         //gotoEnd gets it's own cursor to see a change
207         oSheet = (XSpreadsheet) tEnv.getObjRelation("SHEET");
208         XCellRange testRange = oSheet.getCellRangeByName("$A$1:$g$7") ;
209         XSheetCellRange testSheetRange = (XSheetCellRange)
210                     UnoRuntime.queryInterface(XSheetCellRange.class,testRange);
211         XSheetCellCursor oCellCursor = oSheet.createCursorByRange
212             (testSheetRange);
213         XCellCursor oCursor = (XCellCursor)
214             UnoRuntime.queryInterface(XCellCursor.class,oCellCursor);
215 
216         boolean bResult = false;
217         int startCol, endCol, startRow, endRow = 0;
218 
219         XCellRangeAddressable oRange = (XCellRangeAddressable)
220             UnoRuntime.queryInterface(XCellRangeAddressable.class, oCursor);
221         oCursor.gotoEnd();
222         CellRangeAddress oAddr = oRange.getRangeAddress();
223         startRow = oAddr.StartRow;
224         startCol = oAddr.StartColumn;
225         endRow = oAddr.EndRow;
226         endCol = oAddr.EndColumn;
227         if ((startCol == endCol) && (endRow == startRow)){
228             bResult = true;
229         }
230 
231         tRes.tested( "gotoEnd()", bResult );
232     }
233 
234     /**
235     * Forces object environment recreation.
236     */
after()237     protected void after() {
238         disposeEnvironment();
239     }
240 
241 
242 } //EOC _XCellCursor
243 
244