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.sheet;
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.XUsedAreaCursor;
35 import com.sun.star.table.CellRangeAddress;
36 import com.sun.star.uno.UnoRuntime;
37 
38 /**
39 * Testing <code>com.sun.star.sheet.XUsedAreaCursor</code>
40 * interface methods :
41 * <ul>
42 *  <li><code> gotoStartOfUsedArea()</code></li>
43 *  <li><code> gotoEndOfUsedArea()</code></li>
44 * </ul> <p>
45 * Component must also implement the following interfaces :
46 * <ul>
47 *  <li> <code> com.sun.star.XCellRangeAddressable </code> : to check the current
48 *  position of the cursor </li>
49 * <ul> <p>
50 * @see com.sun.star.sheet.XUsedAreaCursor
51 */
52 public class _XUsedAreaCursor extends MultiMethodTest {
53 
54     public XUsedAreaCursor oObj = null;
55     public XSheetCellCursor oC = null;
56     CellRangeAddress sAddr = null;
57 
58     /**
59     * Test points the cursor to the start of used area, expands cursor to the
60     * end of the used area, gets and checks current range address, then
61     * points the cursor to the end of the used area, gets and checks current
62     * range address again. <p>
63     * Has <b> OK </b> status if the range address expands at all used area
64     * in first case and if the range address just points to the cell at the end
65     * of the used area in second case. <p>
66     */
67     public void _gotoEndOfUsedArea() {
68         boolean result = true ;
69 
70         XCellRangeAddressable oAddr = (XCellRangeAddressable)
71                 UnoRuntime.queryInterface (XCellRangeAddressable.class, oObj) ;
72 
73         // first with true argument
74         oObj.gotoStartOfUsedArea(false);
75         oObj.gotoEndOfUsedArea(true);
76         sAddr = oAddr.getRangeAddress();
77 
78         result &= (sAddr.StartColumn == 1);
79         result &= (sAddr.StartRow == 1);
80         result &= (sAddr.EndColumn == 4);
81         result &= (sAddr.EndRow == 5);
82 
83         oObj.gotoEndOfUsedArea(false);
84         sAddr = oAddr.getRangeAddress();
85 
86         result &= (sAddr.StartColumn == 4);
87         result &= (sAddr.StartRow == 5);
88         result &= (sAddr.EndColumn == 4);
89         result &= (sAddr.EndRow == 5);
90 
91         tRes.tested("gotoEndOfUsedArea()", result) ;
92     }
93 
94     /**
95     * Test points the cursor to the end of used area, expands cursor to the
96     * start of the used area, gets and checks current range address, then
97     * points the cursor to the start of the used area, gets and checks current
98     * range address again. <p>
99     * Has <b> OK </b> status if the range address expands at all used area
100     * in first case and if the range address just points to the cell at the
101     * start of the used area in second case. <p>
102     */
103     public void _gotoStartOfUsedArea() {
104         XCellRangeAddressable oAddr = (XCellRangeAddressable)
105                 UnoRuntime.queryInterface (XCellRangeAddressable.class, oObj) ;
106 
107         boolean result = true ;
108 
109         // with true parameter first
110         oObj.gotoEndOfUsedArea(false);
111         oObj.gotoStartOfUsedArea(true);
112         sAddr = oAddr.getRangeAddress();
113 
114         result &= (sAddr.StartColumn == 1);
115         result &= (sAddr.StartRow == 1);
116         result &= (sAddr.EndColumn == 4);
117         result &= (sAddr.EndRow == 5);
118 
119         // now testing with false parameter
120         oObj.gotoStartOfUsedArea(false);
121         sAddr = oAddr.getRangeAddress();
122 
123         result &= (sAddr.StartColumn == 1);
124         result &= (sAddr.StartRow == 1);
125         result &= (sAddr.EndColumn == 1);
126         result &= (sAddr.EndRow == 1);
127 
128         tRes.tested("gotoStartOfUsedArea()", result) ;
129     } // finished gotoStartOfUsedArea
130 
131     /**
132     * Forces object environment recreation.
133     */
134     protected void after() {
135         this.disposeEnvironment();
136     }
137 } // finished class _XUsedAreaCursor
138 
139