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