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 import lib.Status;
28 import lib.StatusException;
29 
30 import com.sun.star.sheet.XCellRangeAddressable;
31 import com.sun.star.sheet.XCellRangeReferrer;
32 import com.sun.star.table.CellRangeAddress;
33 import com.sun.star.table.XCellRange;
34 import com.sun.star.uno.UnoRuntime;
35 
36 /**
37 * Testing <code>com.sun.star.sheet.XCellRangeReferrer</code>
38 * interface methods :
39 * <ul>
40 *  <li><code> getReferredCells() </code></li>
41 * </ul> <p>
42 * This test needs the following object relations :
43 * <ul>
44 *  <li> <code>'DATAAREA'</code> (of type <code>CellRangeAddress</code>):
45 *   to have cell range address </li>
46 * <ul> <p>
47 * @see com.sun.star.sheet.XCellRangeReferrer
48 * @see com.sun.star.table.CellRangeAddress
49 */
50 public class _XCellRangeReferrer extends MultiMethodTest {
51 
52     public XCellRangeReferrer oObj = null;
53 
54     /**
55     * Test calls the method and compares cell range address of returned cell range
56     * with cell range address gotten by relation <code>'DATAAREA'</code>. <p>
57     * Has <b> OK </b> status if all fields of cell range addresses are equal. <p>
58     */
_getReferredCells()59     public void _getReferredCells() {
60         boolean bResult = true;
61 
62         CellRangeAddress oldCRA = (CellRangeAddress)
63                                     tEnv.getObjRelation("DATAAREA");
64         if (oldCRA == null) throw new StatusException(Status.failed
65             ("Relation 'DATAAREA' not found"));
66 
67         XCellRange cr = oObj.getReferredCells();
68         log.println(cr.toString());
69 
70         if (cr == null) {
71             log.println("getReferredCells returned NULL.");
72             tRes.tested("getReferredCells()", false);
73             return;
74         }
75 
76         XCellRangeAddressable xCRA = (XCellRangeAddressable)
77                 UnoRuntime.queryInterface(XCellRangeAddressable.class, cr);
78 
79         CellRangeAddress objCRA = xCRA.getRangeAddress();
80 
81         log.println("The named range was 'ANamedRange A1:B2'");
82         log.println("Expected CellRangeAddress: (" + oldCRA.Sheet +
83             "," + oldCRA.StartColumn + "," + oldCRA.StartRow + "," +
84             oldCRA.EndColumn + "," + objCRA.EndRow + ")");
85         log.println("CellRangeAddress gotten: (" + objCRA.Sheet + ","
86             + objCRA.StartColumn + "," + objCRA.StartRow + "," +
87             objCRA.EndColumn + "," + objCRA.EndRow + ")");
88 
89         bResult &= objCRA.EndColumn   == oldCRA.EndColumn;
90         bResult &= objCRA.EndRow       == oldCRA.EndRow;
91         bResult &= objCRA.Sheet       == oldCRA.Sheet;
92         bResult &= objCRA.StartColumn == oldCRA.StartColumn;
93         bResult &= objCRA.StartRow       == oldCRA.StartRow;
94 
95         tRes.tested("getReferredCells()", bResult);
96     }
97 }
98 
99 
100