1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski  *
3*b1cdbd2cSJim Jagielski  * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski  * or more contributor license agreements.  See the NOTICE file
5*b1cdbd2cSJim Jagielski  * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski  * regarding copyright ownership.  The ASF licenses this file
7*b1cdbd2cSJim Jagielski  * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski  * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski  * with the License.  You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski  *
11*b1cdbd2cSJim Jagielski  *   http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski  *
13*b1cdbd2cSJim Jagielski  * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski  * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski  * KIND, either express or implied.  See the License for the
17*b1cdbd2cSJim Jagielski  * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski  * under the License.
19*b1cdbd2cSJim Jagielski  *
20*b1cdbd2cSJim Jagielski  *************************************************************/
21*b1cdbd2cSJim Jagielski 
22*b1cdbd2cSJim Jagielski 
23*b1cdbd2cSJim Jagielski 
24*b1cdbd2cSJim Jagielski package ifc.sheet;
25*b1cdbd2cSJim Jagielski 
26*b1cdbd2cSJim Jagielski import lib.MultiMethodTest;
27*b1cdbd2cSJim Jagielski import lib.Status;
28*b1cdbd2cSJim Jagielski import lib.StatusException;
29*b1cdbd2cSJim Jagielski 
30*b1cdbd2cSJim Jagielski import com.sun.star.sheet.XCellRangeAddressable;
31*b1cdbd2cSJim Jagielski import com.sun.star.sheet.XCellRangeReferrer;
32*b1cdbd2cSJim Jagielski import com.sun.star.table.CellRangeAddress;
33*b1cdbd2cSJim Jagielski import com.sun.star.table.XCellRange;
34*b1cdbd2cSJim Jagielski import com.sun.star.uno.UnoRuntime;
35*b1cdbd2cSJim Jagielski 
36*b1cdbd2cSJim Jagielski /**
37*b1cdbd2cSJim Jagielski * Testing <code>com.sun.star.sheet.XCellRangeReferrer</code>
38*b1cdbd2cSJim Jagielski * interface methods :
39*b1cdbd2cSJim Jagielski * <ul>
40*b1cdbd2cSJim Jagielski *  <li><code> getReferredCells() </code></li>
41*b1cdbd2cSJim Jagielski * </ul> <p>
42*b1cdbd2cSJim Jagielski * This test needs the following object relations :
43*b1cdbd2cSJim Jagielski * <ul>
44*b1cdbd2cSJim Jagielski *  <li> <code>'DATAAREA'</code> (of type <code>CellRangeAddress</code>):
45*b1cdbd2cSJim Jagielski *   to have cell range address </li>
46*b1cdbd2cSJim Jagielski * <ul> <p>
47*b1cdbd2cSJim Jagielski * @see com.sun.star.sheet.XCellRangeReferrer
48*b1cdbd2cSJim Jagielski * @see com.sun.star.table.CellRangeAddress
49*b1cdbd2cSJim Jagielski */
50*b1cdbd2cSJim Jagielski public class _XCellRangeReferrer extends MultiMethodTest {
51*b1cdbd2cSJim Jagielski 
52*b1cdbd2cSJim Jagielski     public XCellRangeReferrer oObj = null;
53*b1cdbd2cSJim Jagielski 
54*b1cdbd2cSJim Jagielski     /**
55*b1cdbd2cSJim Jagielski     * Test calls the method and compares cell range address of returned cell range
56*b1cdbd2cSJim Jagielski     * with cell range address gotten by relation <code>'DATAAREA'</code>. <p>
57*b1cdbd2cSJim Jagielski     * Has <b> OK </b> status if all fields of cell range addresses are equal. <p>
58*b1cdbd2cSJim Jagielski     */
_getReferredCells()59*b1cdbd2cSJim Jagielski     public void _getReferredCells() {
60*b1cdbd2cSJim Jagielski         boolean bResult = true;
61*b1cdbd2cSJim Jagielski 
62*b1cdbd2cSJim Jagielski         CellRangeAddress oldCRA = (CellRangeAddress)
63*b1cdbd2cSJim Jagielski                                     tEnv.getObjRelation("DATAAREA");
64*b1cdbd2cSJim Jagielski         if (oldCRA == null) throw new StatusException(Status.failed
65*b1cdbd2cSJim Jagielski             ("Relation 'DATAAREA' not found"));
66*b1cdbd2cSJim Jagielski 
67*b1cdbd2cSJim Jagielski         XCellRange cr = oObj.getReferredCells();
68*b1cdbd2cSJim Jagielski         log.println(cr.toString());
69*b1cdbd2cSJim Jagielski 
70*b1cdbd2cSJim Jagielski         if (cr == null) {
71*b1cdbd2cSJim Jagielski             log.println("getReferredCells returned NULL.");
72*b1cdbd2cSJim Jagielski             tRes.tested("getReferredCells()", false);
73*b1cdbd2cSJim Jagielski             return;
74*b1cdbd2cSJim Jagielski         }
75*b1cdbd2cSJim Jagielski 
76*b1cdbd2cSJim Jagielski         XCellRangeAddressable xCRA = (XCellRangeAddressable)
77*b1cdbd2cSJim Jagielski                 UnoRuntime.queryInterface(XCellRangeAddressable.class, cr);
78*b1cdbd2cSJim Jagielski 
79*b1cdbd2cSJim Jagielski         CellRangeAddress objCRA = xCRA.getRangeAddress();
80*b1cdbd2cSJim Jagielski 
81*b1cdbd2cSJim Jagielski         log.println("The named range was 'ANamedRange A1:B2'");
82*b1cdbd2cSJim Jagielski         log.println("Expected CellRangeAddress: (" + oldCRA.Sheet +
83*b1cdbd2cSJim Jagielski             "," + oldCRA.StartColumn + "," + oldCRA.StartRow + "," +
84*b1cdbd2cSJim Jagielski             oldCRA.EndColumn + "," + objCRA.EndRow + ")");
85*b1cdbd2cSJim Jagielski         log.println("CellRangeAddress gotten: (" + objCRA.Sheet + ","
86*b1cdbd2cSJim Jagielski             + objCRA.StartColumn + "," + objCRA.StartRow + "," +
87*b1cdbd2cSJim Jagielski             objCRA.EndColumn + "," + objCRA.EndRow + ")");
88*b1cdbd2cSJim Jagielski 
89*b1cdbd2cSJim Jagielski         bResult &= objCRA.EndColumn   == oldCRA.EndColumn;
90*b1cdbd2cSJim Jagielski         bResult &= objCRA.EndRow       == oldCRA.EndRow;
91*b1cdbd2cSJim Jagielski         bResult &= objCRA.Sheet       == oldCRA.Sheet;
92*b1cdbd2cSJim Jagielski         bResult &= objCRA.StartColumn == oldCRA.StartColumn;
93*b1cdbd2cSJim Jagielski         bResult &= objCRA.StartRow       == oldCRA.StartRow;
94*b1cdbd2cSJim Jagielski 
95*b1cdbd2cSJim Jagielski         tRes.tested("getReferredCells()", bResult);
96*b1cdbd2cSJim Jagielski     }
97*b1cdbd2cSJim Jagielski }
98*b1cdbd2cSJim Jagielski 
99*b1cdbd2cSJim Jagielski 
100