2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.util
.Random
;
22 import java
.util
.StringTokenizer
;
24 import lib
.MultiMethodTest
;
26 import com
.sun
.star
.sheet
.NamedRangeFlag
;
27 import com
.sun
.star
.sheet
.XNamedRange
;
28 import com
.sun
.star
.table
.CellAddress
;
31 * Testing <code>com.sun.star.sheet.XNamedRange</code>
34 * <li><code> getContent()</code></li>
35 * <li><code> setContent()</code></li>
36 * <li><code> getReferencePosition()</code></li>
37 * <li><code> setReferencePosition()</code></li>
38 * <li><code> getType()</code></li>
39 * <li><code> setType()</code></li>
41 * After test completion object environment has to be recreated.
42 * @see com.sun.star.sheet.XNamedRange
44 public class _XNamedRange
extends MultiMethodTest
{
46 public XNamedRange oObj
= null;
49 CellAddress CA
= null;
52 * Test calls the method and compares returned value to value that was set
53 * by method <code>setContent()</code>. <p>
54 * Has <b> OK </b> status if values are equal. <p>
55 * The following method tests are to be completed successfully before :
57 * <li> <code> setContent() </code> : to have current content </li>
60 public void _getContent() {
61 requiredMethod("setContent()");
62 String content
= oObj
.getContent();
63 log
.println("Returned content is \"" + content
+ "\"");
64 boolean bResult
= content
.equals(sContent
);
65 tRes
.tested("getContent()", bResult
);
69 * Test creates and stores random content and calls the method. <p>
70 * Has <b> OK </b> status if the method successfully returns. <p>
72 public void _setContent() {
73 sContent
= getRandomContent("A1;A4:C5;=B2");
74 log
.println("Set content to \"" + sContent
+ "\"");
75 oObj
.setContent(sContent
);
77 tRes
.tested("setContent()", true);
81 * Test calls the method and compares returned value to value that was set
82 * by method <code>setType()</code>. <p>
83 * Has <b> OK </b> status if values are equal. <p>
84 * The following method tests are to be completed successfully before :
86 * <li> <code> setType() </code> : to have current type </li>
89 public void _getType() {
90 requiredMethod("setType()");
92 int rtype
= oObj
.getType();
93 log
.println("Returned type is " + rtype
);
95 tRes
.tested("getType()", type
== rtype
);
99 * Test sets random type and stores it. <p>
100 * Has <b> OK </b> status if the method successfully returns. <p>
102 public void _setType() {
104 * The type must be 0 or a combination of the NamedRangeFlag
105 * constants and controls if the named range is listed in
106 * dialogs prompting for special ranges
108 * NamedRangeFlag: COLUMN_HEADER
114 boolean bResult
= true;
116 NamedRangeFlag
.COLUMN_HEADER
,
117 NamedRangeFlag
.FILTER_CRITERIA
,
118 NamedRangeFlag
.PRINT_AREA
,
119 NamedRangeFlag
.ROW_HEADER
122 Random rnd
= new Random();
123 type
= types
[rnd
.nextInt(5)];
126 log
.println("The type was set to " + type
);
128 tRes
.tested("setType()", bResult
);
132 * Test calls the method and compares returned value to value that was set
133 * by method <code>setReferencePosition()</code>. <p>
134 * Has <b> OK </b> status if all fields of values are equal. <p>
135 * The following method tests are to be completed successfully before :
137 * <li> <code> setReferencePosition() </code> : to have current reference
141 public void _getReferencePosition() {
142 requiredMethod("setReferencePosition()");
144 CellAddress rCA
= oObj
.getReferencePosition();
145 log
.println("getReferencePosition returned (" +
147 rCA
.Column
+ ", " + rCA
.Row
+ ")" );
149 boolean bResult
= rCA
.Sheet
== CA
.Sheet
;
150 bResult
&= rCA
.Column
== CA
.Column
;
151 bResult
&= rCA
.Row
== CA
.Row
;
153 tRes
.tested("getReferencePosition()", bResult
);
157 * Test creates and stores cell address and calls the method. <p>
158 * Has <b> OK </b> status if the method successfully returns. <p>
160 public void _setReferencePosition() {
161 CA
= new CellAddress((short)0, 2, 3);
162 oObj
.setReferencePosition(CA
);
163 log
.println("ReferencePosition was set to (" +
165 CA
.Column
+ ", " + CA
.Row
+ ")");
167 tRes
.tested("setReferencePosition()", true);
172 * Method make string of random content.
173 * @return string of random content
175 String
getRandomContent(String str
) {
178 Random rnd
= new Random();
180 StringTokenizer ST
= new StringTokenizer(str
, ";");
181 int nr
= rnd
.nextInt(ST
.countTokens());
184 for (int i
= 1; i
< nr
+ 1; i
++)
185 gRS
= ST
.nextToken();
192 * Forces object environment recreation.
195 protected void after() {
196 disposeEnvironment();