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