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.XAreaLink;
33 import com.sun.star.table.CellRangeAddress;
34 
35 /**
36 * Testing <code>com.sun.star.sheet.XAreaLink</code>
37 * interface methods :
38 * <ul>
39 *  <li><code> getSourceArea()</code></li>
40 *  <li><code> setSourceArea()</code></li>
41 *  <li><code> getDestArea()</code></li>
42 *  <li><code> setDestArea()</code></li>
43 * </ul> <p>
44 * Test is <b> NOT </b> multithread compilant. <p>
45 * @see com.sun.star.sheet.XAreaLink
46 */
47 public class _XAreaLink extends MultiMethodTest {
48 
49     public XAreaLink oObj = null;
50     CellRangeAddress oORAdd, oNRAdd, oCRAdd = null;
51 
52     /**
53     * Just calls the method and checks the value returned.
54     * (More complicated testing done in <code>setDestArea</code>)<p>
55     * Has <b>OK</b> status if not null value returned.
56     */
57     public void _getDestArea(){
58         log.println("testing getDestArea()");
59         boolean bResult = false;
60         oORAdd = oObj.getDestArea();
61         if (!(oORAdd == null)){ bResult = true; }
62         tRes.tested("getDestArea()", bResult) ;
63     }
64 
65     /**
66     * Just calls the method and checks the value returned.
67     * (More complicated testing done in <code>setSourceArea</code>)<p>
68     * Has <b>OK</b> status if not null value returned.
69     */
70     public void _getSourceArea(){
71         log.println("testing getSourceArea()");
72         boolean bResult = false;
73         String src = null;
74         src = oObj.getSourceArea() ;
75         if (!(src == null)){ bResult = true; }
76         tRes.tested("getSourceArea()", bResult) ;
77     }
78 
79     /**
80     * Creates a new desination CellRange address and sets it for
81     * the link object. <p>
82     * After setting the DestArea, the link is refreshed and the area is
83     * adjusted to the size of the source data.
84     * Therefore EndCol and EndRow will change after setting. <p>
85     * Has <b>OK</b> status if Sheet, Starting Column and Row
86     * of the destination range is changed correctly.
87     */
88     public void _setDestArea(){
89         log.println("testing setDestArea()");
90         boolean bResult = false;
91         int newStartCol = 3, newStartRow = 4, newEndCol = 5, newEndRow = 8 ;
92         oORAdd = oObj.getDestArea();
93         log.print("Getting: ");
94         log.println(getCRA(oORAdd));
95         oNRAdd = new CellRangeAddress ((short) 2, newStartCol, newStartRow,
96                                                     newEndCol, newEndRow) ;
97         oObj.setDestArea(oNRAdd) ;
98         log.print("Setting: ");
99         log.println(getCRA(oNRAdd));
100         oCRAdd = oObj.getDestArea();
101         log.print("Getting: ");
102         log.println(getCRA(oCRAdd));
103         // After setting the DestArea, the link is refreshed and the area is
104         // adjusted to the size of the source data.
105         // Therefore EndCol and EndRow will change after setting.
106         log.println("After setting the DestArea, the link is refreshed "+
107             "and the area is");
108         log.println("adjusted to the size of the source data.");
109         log.println("Therefore only 'Sheet', 'StartCol' and 'StartRow' "+
110             "are compared.");
111         if ((oCRAdd.StartColumn == oNRAdd.StartColumn) &&
112                 (oCRAdd.Sheet == oNRAdd.Sheet) &&
113                 (oCRAdd.StartRow == oNRAdd.StartRow)){
114             bResult = true;
115             oObj.setDestArea(oORAdd);
116         }
117         tRes.tested("setDestArea()", bResult) ;
118     }
119 
120     /**
121     * Sets a new source area for the link and then check
122     * it using <code>getSourceArea</code>  method. <p>
123     * Has <b>OK</b> status if areas set and get are equal.
124     */
125     public void _setSourceArea(){
126         log.println("testing setSourceArea()");
127         boolean bResult = false;
128         String oSrc = oObj.getSourceArea() ;
129         String nSrc = "a1:b2";
130         oObj.setSourceArea(nSrc);
131         String cSrc = oObj.getSourceArea();
132         if( nSrc.equals(cSrc)){
133             bResult = true;
134             oObj.setSourceArea(oSrc);
135         }
136         tRes.tested("setSourceArea()", bResult) ;
137     }
138 
139     /**
140     * Prints cell range structure to LOG
141     */
142     public String getCRA ( CellRangeAddress oCRA ) {
143         String res = "( Sheet: ";
144         res += oCRA.Sheet;
145         res += ";StartColumn: ";
146         res += oCRA.StartColumn;
147         res += ";StartRow: ";
148         res += oCRA.StartRow;
149         res += ";EndColumn: ";
150         res += oCRA.EndColumn;
151         res += ";EndRow: ";
152         res += oCRA.EndRow;
153         res += " )";
154         return res;
155     }
156 
157 } // EOC _XAreaLink
158 
159 
160