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: _XNamedRange.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 java
.util
.Random
;
34 import java
.util
.StringTokenizer
;
36 import lib
.MultiMethodTest
;
38 import com
.sun
.star
.sheet
.NamedRangeFlag
;
39 import com
.sun
.star
.sheet
.XNamedRange
;
40 import com
.sun
.star
.table
.CellAddress
;
43 * Testing <code>com.sun.star.sheet.XNamedRange</code>
46 * <li><code> getContent()</code></li>
47 * <li><code> setContent()</code></li>
48 * <li><code> getReferencePosition()</code></li>
49 * <li><code> setReferencePosition()</code></li>
50 * <li><code> getType()</code></li>
51 * <li><code> setType()</code></li>
53 * After test completion object environment has to be recreated.
54 * @see com.sun.star.sheet.XNamedRange
56 public class _XNamedRange
extends MultiMethodTest
{
58 public XNamedRange oObj
= null;
61 CellAddress CA
= null;
64 * Test calls the method and compares returned value to value that was set
65 * by method <code>setContent()</code>. <p>
66 * Has <b> OK </b> status if values are equal. <p>
67 * The following method tests are to be completed successfully before :
69 * <li> <code> setContent() </code> : to have current content </li>
72 public void _getContent() {
73 requiredMethod("setContent()");
74 String content
= oObj
.getContent();
75 log
.println("Returned content is \"" + content
+ "\"");
76 boolean bResult
= content
.equals(sContent
);
77 tRes
.tested("getContent()", bResult
);
81 * Test creates and stores random content and calls the method. <p>
82 * Has <b> OK </b> status if the method successfully returns. <p>
84 public void _setContent() {
85 sContent
= getRandomContent("A1;A4:C5;=B2");
86 log
.println("Set content to \"" + sContent
+ "\"");
87 oObj
.setContent(sContent
);
89 tRes
.tested("setContent()", true);
93 * Test calls the method and compares returned value to value that was set
94 * by method <code>setType()</code>. <p>
95 * Has <b> OK </b> status if values are equal. <p>
96 * The following method tests are to be completed successfully before :
98 * <li> <code> setType() </code> : to have current type </li>
101 public void _getType() {
102 requiredMethod("setType()");
104 int rtype
= oObj
.getType();
105 log
.println("Returned type is " + rtype
);
107 tRes
.tested("getType()", type
== rtype
);
111 * Test sets random type and stores it. <p>
112 * Has <b> OK </b> status if the method successfully returns. <p>
114 public void _setType() {
116 * The type must be 0 or a combination of the NamedRangeFlag
117 * constants and controls if the named range is listed in
118 * dialogs prompting for special ranges
120 * NamedRangeFlag: COLUMN_HEADER
126 boolean bResult
= true;
128 NamedRangeFlag
.COLUMN_HEADER
,
129 NamedRangeFlag
.FILTER_CRITERIA
,
130 NamedRangeFlag
.PRINT_AREA
,
131 NamedRangeFlag
.ROW_HEADER
134 Random rnd
= new Random();
135 type
= types
[rnd
.nextInt(5)];
138 log
.println("The type was set to " + type
);
140 tRes
.tested("setType()", bResult
);
144 * Test calls the method and compares returned value to value that was set
145 * by method <code>setReferencePosition()</code>. <p>
146 * Has <b> OK </b> status if all fields of values are equal. <p>
147 * The following method tests are to be completed successfully before :
149 * <li> <code> setReferencePosition() </code> : to have current reference
153 public void _getReferencePosition() {
154 requiredMethod("setReferencePosition()");
156 CellAddress rCA
= oObj
.getReferencePosition();
157 log
.println("getReferencePosition returned (" +
159 rCA
.Column
+ ", " + rCA
.Row
+ ")" );
161 boolean bResult
= rCA
.Sheet
== CA
.Sheet
;
162 bResult
&= rCA
.Column
== CA
.Column
;
163 bResult
&= rCA
.Row
== CA
.Row
;
165 tRes
.tested("getReferencePosition()", bResult
);
169 * Test creates and stores cell address and calls the method. <p>
170 * Has <b> OK </b> status if the method successfully returns. <p>
172 public void _setReferencePosition() {
173 CA
= new CellAddress((short)0, 2, 3);
174 oObj
.setReferencePosition(CA
);
175 log
.println("ReferencePosition was set to (" +
177 CA
.Column
+ ", " + CA
.Row
+ ")");
179 tRes
.tested("setReferencePosition()", true);
184 * Method make string of random content.
185 * @return string of random content
187 String
getRandomContent(String str
) {
190 Random rnd
= new Random();
192 StringTokenizer ST
= new StringTokenizer(str
, ";");
193 int nr
= rnd
.nextInt(ST
.countTokens());
196 for (int i
= 1; i
< nr
+ 1; i
++)
197 gRS
= ST
.nextToken();
204 * Forces object environment recreation.
206 protected void after() {
207 disposeEnvironment();