Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / table / _XCellCursor.java
blobcac9607d0e200bc9af1aa7486f8867faff45acdc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XCellCursor.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.table;
33 import lib.MultiMethodTest;
35 import com.sun.star.sheet.XCellRangeAddressable;
36 import com.sun.star.sheet.XSheetCellCursor;
37 import com.sun.star.sheet.XSheetCellRange;
38 import com.sun.star.sheet.XSpreadsheet;
39 import com.sun.star.table.CellRangeAddress;
40 import com.sun.star.table.XCellCursor;
41 import com.sun.star.table.XCellRange;
42 import com.sun.star.uno.UnoRuntime;
44 /**
45 * Testing <code>com.sun.star.table.XCellCursor</code>
46 * interface methods :
47 * <ul>
48 * <li><code> gotoStart()</code></li>
49 * <li><code> gotoEnd()</code></li>
50 * <li><code> gotoNext()</code></li>
51 * <li><code> gotoPrevious()</code></li>
52 * <li><code> gotoOffset()</code></li>
53 * </ul> <p>
54 * This test needs the following object relations :
55 * <ul>
56 * <li> <code>'SHEET'</code> (of type <code>XSpreadsheet</code>):
57 * is used for creating a new cell range.</li>
58 * <ul> <p>
60 * The component tested <b>must implement</b>
61 * <code>XCellRangeAddressable</code> interface. <p>
63 * Test is <b> NOT </b> multithread compilant. <p>
64 * After test completion object environment has to be recreated.
65 * @see com.sun.star.table.XCellCursor
67 public class _XCellCursor extends MultiMethodTest {
69 public static XCellCursor oObj = null;
70 public static XSpreadsheet oSheet = null;
72 /**
73 * <code>XCellRangeAddressable</code> interface is queried
74 * first for getting current position of cursor. The cursor
75 * is moved to next cell. Address of cursor obtained before
76 * and after moving. <p>
77 * Has <b> OK </b> status if cursor column is changed after
78 * movement. <p>
80 public void _gotoNext(){
81 boolean bResult = false;
82 int startCol, endCol, startRow, endRow = 0;
83 int startCol2, endCol2, startRow2, endRow2 = 0;
85 XCellRangeAddressable oRange = (XCellRangeAddressable)
86 UnoRuntime.queryInterface(XCellRangeAddressable.class, oObj);
87 CellRangeAddress oAddr = oRange.getRangeAddress();
88 startRow = oAddr.StartRow;
89 startCol = oAddr.StartColumn;
90 endRow = oAddr.EndRow;
91 endCol = oAddr.EndColumn;
93 oObj.gotoNext();
95 oAddr = oRange.getRangeAddress();
96 startRow2 = oAddr.StartRow;
97 startCol2 = oAddr.StartColumn;
98 endRow2 = oAddr.EndRow;
99 endCol2 = oAddr.EndColumn;
101 if (!(startCol == startCol2)){
102 bResult = true;
104 tRes.tested( "gotoNext()", bResult );
108 * <code>XCellRangeAddressable</code> interface is queried
109 * first for getting current position of cursor. The cursor
110 * is moved then. Address of cursor obtained before
111 * and after moving. <p>
112 * Has <b> OK </b> status if starting column and row of
113 * cursor is changed after movement. <p>
115 public void _gotoOffset(){
116 boolean bResult = false;
117 int startCol, endCol, startRow, endRow = 0;
118 int startCol2, endCol2, startRow2, endRow2 = 0;
120 XCellRangeAddressable oRange = (XCellRangeAddressable)
121 UnoRuntime.queryInterface(XCellRangeAddressable.class, oObj);
122 CellRangeAddress oAddr = oRange.getRangeAddress();
123 startRow = oAddr.StartRow;
124 startCol = oAddr.StartColumn;
125 endRow = oAddr.EndRow;
126 endCol = oAddr.EndColumn;
128 oObj.gotoOffset(4,4);
130 oAddr = oRange.getRangeAddress();
131 startRow2 = oAddr.StartRow;
132 startCol2 = oAddr.StartColumn;
133 endRow2 = oAddr.EndRow;
134 endCol2 = oAddr.EndColumn;
135 if (!(startCol == startCol2) || (startRow == startRow2)){
136 bResult = true;
138 tRes.tested( "gotoOffset()", bResult );
142 * <code>XCellRangeAddressable</code> interface is queried
143 * first for getting current position of cursor. The cursor
144 * is moved to previous cell. Address of cursor obtained before
145 * and after moving. <p>
146 * Has <b> OK </b> status if cursor column is changed after
147 * movement. <p>
149 public void _gotoPrevious(){
150 boolean bResult = false;
151 int startCol, endCol, startRow, endRow = 0;
152 int startCol2, endCol2, startRow2, endRow2 = 0;
154 XCellRangeAddressable oRange = (XCellRangeAddressable)
155 UnoRuntime.queryInterface(XCellRangeAddressable.class, oObj);
156 CellRangeAddress oAddr = oRange.getRangeAddress();
157 startRow = oAddr.StartRow;
158 startCol = oAddr.StartColumn;
159 endRow = oAddr.EndRow;
160 endCol = oAddr.EndColumn;
162 oObj.gotoPrevious();
164 oAddr = oRange.getRangeAddress();
165 startRow2 = oAddr.StartRow;
166 startCol2 = oAddr.StartColumn;
167 endRow2 = oAddr.EndRow;
168 endCol2 = oAddr.EndColumn;
170 if (!(startCol == startCol2)){
171 bResult = true;
173 tRes.tested( "gotoPrevious()", bResult );
177 * <code>XCellRangeAddressable</code> interface is queried
178 * first for getting current position of cursor. The cursor
179 * is moved to the start of its range .
180 * Address of cursor obtained before and after moving. <p>
181 * Has <b> OK </b> status if cursor was collapsed to a single
182 * cell (i.e. start column is the same as end column) after
183 * movement. <p>
185 public void _gotoStart(){
186 boolean bResult = false;
187 int startCol, endCol, startRow, endRow = 0;
189 XCellRangeAddressable oRange = (XCellRangeAddressable)
190 UnoRuntime.queryInterface(XCellRangeAddressable.class, oObj);
191 oObj.gotoStart();
192 CellRangeAddress oAddr = oRange.getRangeAddress();
193 startRow = oAddr.StartRow;
194 startCol = oAddr.StartColumn;
195 endRow = oAddr.EndRow;
196 endCol = oAddr.EndColumn;
197 if ((startCol == endCol) && (endRow == startRow)){
198 bResult = true;
201 tRes.tested( "gotoStart()", bResult );
205 * A new cell range is created using spreadsheet passed by relation.
206 * The method is tested on that range. <code>gotoEnd</code> is
207 * called and range address is checked.<p>
208 * Has <b> OK </b> status if cursor was collapsed to a single
209 * cell (i.e. start column is the same as end column) after
210 * movement. <p>
212 public void _gotoEnd(){
213 //gotoEnd gets it's own cursor to see a change
214 oSheet = (XSpreadsheet) tEnv.getObjRelation("SHEET");
215 XCellRange testRange = oSheet.getCellRangeByName("$A$1:$g$7") ;
216 XSheetCellRange testSheetRange = (XSheetCellRange)
217 UnoRuntime.queryInterface(XSheetCellRange.class,testRange);
218 XSheetCellCursor oCellCursor = oSheet.createCursorByRange
219 (testSheetRange);
220 XCellCursor oCursor = (XCellCursor)
221 UnoRuntime.queryInterface(XCellCursor.class,oCellCursor);
223 boolean bResult = false;
224 int startCol, endCol, startRow, endRow = 0;
226 XCellRangeAddressable oRange = (XCellRangeAddressable)
227 UnoRuntime.queryInterface(XCellRangeAddressable.class, oCursor);
228 oCursor.gotoEnd();
229 CellRangeAddress oAddr = oRange.getRangeAddress();
230 startRow = oAddr.StartRow;
231 startCol = oAddr.StartColumn;
232 endRow = oAddr.EndRow;
233 endCol = oAddr.EndColumn;
234 if ((startCol == endCol) && (endRow == startRow)){
235 bResult = true;
238 tRes.tested( "gotoEnd()", bResult );
242 * Forces object environment recreation.
244 protected void after() {
245 disposeEnvironment();
249 } //EOC _XCellCursor