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