1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
30 import java
.util
.Random
;
31 import java
.util
.StringTokenizer
;
33 import lib
.MultiMethodTest
;
35 import com
.sun
.star
.sheet
.NamedRangeFlag
;
36 import com
.sun
.star
.sheet
.XNamedRange
;
37 import com
.sun
.star
.table
.CellAddress
;
40 * Testing <code>com.sun.star.sheet.XNamedRange</code>
43 * <li><code> getContent()</code></li>
44 * <li><code> setContent()</code></li>
45 * <li><code> getReferencePosition()</code></li>
46 * <li><code> setReferencePosition()</code></li>
47 * <li><code> getType()</code></li>
48 * <li><code> setType()</code></li>
50 * After test completion object environment has to be recreated.
51 * @see com.sun.star.sheet.XNamedRange
53 public class _XNamedRange
extends MultiMethodTest
{
55 public XNamedRange oObj
= null;
58 CellAddress CA
= null;
61 * Test calls the method and compares returned value to value that was set
62 * by method <code>setContent()</code>. <p>
63 * Has <b> OK </b> status if values are equal. <p>
64 * The following method tests are to be completed successfully before :
66 * <li> <code> setContent() </code> : to have current content </li>
69 public void _getContent() {
70 requiredMethod("setContent()");
71 String content
= oObj
.getContent();
72 log
.println("Returned content is \"" + content
+ "\"");
73 boolean bResult
= content
.equals(sContent
);
74 tRes
.tested("getContent()", bResult
);
78 * Test creates and stores random content and calls the method. <p>
79 * Has <b> OK </b> status if the method successfully returns. <p>
81 public void _setContent() {
82 sContent
= getRandomContent("A1;A4:C5;=B2");
83 log
.println("Set content to \"" + sContent
+ "\"");
84 oObj
.setContent(sContent
);
86 tRes
.tested("setContent()", true);
90 * Test calls the method and compares returned value to value that was set
91 * by method <code>setType()</code>. <p>
92 * Has <b> OK </b> status if values are equal. <p>
93 * The following method tests are to be completed successfully before :
95 * <li> <code> setType() </code> : to have current type </li>
98 public void _getType() {
99 requiredMethod("setType()");
101 int rtype
= oObj
.getType();
102 log
.println("Returned type is " + rtype
);
104 tRes
.tested("getType()", type
== rtype
);
108 * Test sets random type and stores it. <p>
109 * Has <b> OK </b> status if the method successfully returns. <p>
111 public void _setType() {
113 * The type must be 0 or a combination of the NamedRangeFlag
114 * constants and controls if the named range is listed in
115 * dialogs prompting for special ranges
117 * NamedRangeFlag: COLUMN_HEADER
123 boolean bResult
= true;
125 NamedRangeFlag
.COLUMN_HEADER
,
126 NamedRangeFlag
.FILTER_CRITERIA
,
127 NamedRangeFlag
.PRINT_AREA
,
128 NamedRangeFlag
.ROW_HEADER
131 Random rnd
= new Random();
132 type
= types
[rnd
.nextInt(5)];
135 log
.println("The type was set to " + type
);
137 tRes
.tested("setType()", bResult
);
141 * Test calls the method and compares returned value to value that was set
142 * by method <code>setReferencePosition()</code>. <p>
143 * Has <b> OK </b> status if all fields of values are equal. <p>
144 * The following method tests are to be completed successfully before :
146 * <li> <code> setReferencePosition() </code> : to have current reference
150 public void _getReferencePosition() {
151 requiredMethod("setReferencePosition()");
153 CellAddress rCA
= oObj
.getReferencePosition();
154 log
.println("getReferencePosition returned (" +
156 rCA
.Column
+ ", " + rCA
.Row
+ ")" );
158 boolean bResult
= rCA
.Sheet
== CA
.Sheet
;
159 bResult
&= rCA
.Column
== CA
.Column
;
160 bResult
&= rCA
.Row
== CA
.Row
;
162 tRes
.tested("getReferencePosition()", bResult
);
166 * Test creates and stores cell address and calls the method. <p>
167 * Has <b> OK </b> status if the method successfully returns. <p>
169 public void _setReferencePosition() {
170 CA
= new CellAddress((short)0, 2, 3);
171 oObj
.setReferencePosition(CA
);
172 log
.println("ReferencePosition was set to (" +
174 CA
.Column
+ ", " + CA
.Row
+ ")");
176 tRes
.tested("setReferencePosition()", true);
181 * Method make string of random content.
182 * @return string of random content
184 String
getRandomContent(String str
) {
187 Random rnd
= new Random();
189 StringTokenizer ST
= new StringTokenizer(str
, ";");
190 int nr
= rnd
.nextInt(ST
.countTokens());
193 for (int i
= 1; i
< nr
+ 1; i
++)
194 gRS
= ST
.nextToken();
201 * Forces object environment recreation.
203 protected void after() {
204 disposeEnvironment();