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