1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XAreaLink.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import com
.sun
.star
.sheet
.XAreaLink
;
36 import com
.sun
.star
.table
.CellRangeAddress
;
39 * Testing <code>com.sun.star.sheet.XAreaLink</code>
42 * <li><code> getSourceArea()</code></li>
43 * <li><code> setSourceArea()</code></li>
44 * <li><code> getDestArea()</code></li>
45 * <li><code> setDestArea()</code></li>
47 * Test is <b> NOT </b> multithread compilant. <p>
48 * @see com.sun.star.sheet.XAreaLink
50 public class _XAreaLink
extends MultiMethodTest
{
52 public XAreaLink oObj
= null;
53 CellRangeAddress oORAdd
, oNRAdd
, oCRAdd
= null;
56 * Just calls the method and checks the value returned.
57 * (More complicated testing done in <code>setDestArea</code>)<p>
58 * Has <b>OK</b> status if not null value returned.
60 public void _getDestArea(){
61 log
.println("testing getDestArea()");
62 boolean bResult
= false;
63 oORAdd
= oObj
.getDestArea();
64 if (!(oORAdd
== null)){ bResult
= true; }
65 tRes
.tested("getDestArea()", bResult
) ;
69 * Just calls the method and checks the value returned.
70 * (More complicated testing done in <code>setSourceArea</code>)<p>
71 * Has <b>OK</b> status if not null value returned.
73 public void _getSourceArea(){
74 log
.println("testing getSourceArea()");
75 boolean bResult
= false;
77 src
= oObj
.getSourceArea() ;
78 if (!(src
== null)){ bResult
= true; }
79 tRes
.tested("getSourceArea()", bResult
) ;
83 * Creates a new desination CellRange address and sets it for
84 * the link object. <p>
85 * After setting the DestArea, the link is refreshed and the area is
86 * adjusted to the size of the source data.
87 * Therefore EndCol and EndRow will change after setting. <p>
88 * Has <b>OK</b> status if Sheet, Starting Column and Row
89 * of the destination range is changed correctly.
91 public void _setDestArea(){
92 log
.println("testing setDestArea()");
93 boolean bResult
= false;
94 int newStartCol
= 3, newStartRow
= 4, newEndCol
= 5, newEndRow
= 8 ;
95 oORAdd
= oObj
.getDestArea();
96 log
.print("Getting: ");
97 log
.println(getCRA(oORAdd
));
98 oNRAdd
= new CellRangeAddress ((short) 2, newStartCol
, newStartRow
,
99 newEndCol
, newEndRow
) ;
100 oObj
.setDestArea(oNRAdd
) ;
101 log
.print("Setting: ");
102 log
.println(getCRA(oNRAdd
));
103 oCRAdd
= oObj
.getDestArea();
104 log
.print("Getting: ");
105 log
.println(getCRA(oCRAdd
));
106 // After setting the DestArea, the link is refreshed and the area is
107 // adjusted to the size of the source data.
108 // Therefore EndCol and EndRow will change after setting.
109 log
.println("After setting the DestArea, the link is refreshed "+
111 log
.println("adjusted to the size of the source data.");
112 log
.println("Therefore only 'Sheet', 'StartCol' and 'StartRow' "+
114 if ((oCRAdd
.StartColumn
== oNRAdd
.StartColumn
) &&
115 (oCRAdd
.Sheet
== oNRAdd
.Sheet
) &&
116 (oCRAdd
.StartRow
== oNRAdd
.StartRow
)){
118 oObj
.setDestArea(oORAdd
);
120 tRes
.tested("setDestArea()", bResult
) ;
124 * Sets a new source area for the link and then check
125 * it using <code>getSourceArea</code> method. <p>
126 * Has <b>OK</b> status if areas set and get are equal.
128 public void _setSourceArea(){
129 log
.println("testing setSourceArea()");
130 boolean bResult
= false;
131 String oSrc
= oObj
.getSourceArea() ;
132 String nSrc
= "a1:b2";
133 oObj
.setSourceArea(nSrc
);
134 String cSrc
= oObj
.getSourceArea();
135 if( nSrc
.equals(cSrc
)){
137 oObj
.setSourceArea(oSrc
);
139 tRes
.tested("setSourceArea()", bResult
) ;
143 * Prints cell range structure to LOG
145 public String
getCRA ( CellRangeAddress oCRA
) {
146 String res
= "( Sheet: ";
148 res
+= ";StartColumn: ";
149 res
+= oCRA
.StartColumn
;
150 res
+= ";StartRow: ";
151 res
+= oCRA
.StartRow
;
152 res
+= ";EndColumn: ";
153 res
+= oCRA
.EndColumn
;