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: _XAccessibleValue.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 ************************************************************************/
31 package ifc
.accessibility
;
34 import lib
.MultiMethodTest
;
36 import lib
.StatusException
;
38 import com
.sun
.star
.accessibility
.XAccessibleValue
;
41 * Testing <code>com.sun.star.accessibility.XAccessibleValue</code>
44 * <li><code> getCurrentValue()</code></li>
45 * <li><code> setCurrentValue()</code></li>
46 * <li><code> getMaximumValue()</code></li>
47 * <li><code> getMinimumValue()</code></li>
50 * This test needs the following object relations :
52 * <li> <code>'XAccessibleValue.anotherFromGroup'</code>
53 * (of type <code>XAccessibleValue</code>) <b> optional </b>:
54 * another component from the group(e.g. radio button group)</li>
56 * @see com.sun.star.accessibility.XAccessibleValue
58 public class _XAccessibleValue
extends MultiMethodTest
{
60 public XAccessibleValue oObj
= null;
62 private double minVal
= 0;
63 private double maxVal
= 0;
64 private double curVal
= 0;
65 private Object val
= null;
66 XAccessibleValue anotherFromGroup
= null;
68 protected void before() {
69 anotherFromGroup
= (XAccessibleValue
)tEnv
.getObjRelation(
70 "XAccessibleValue.anotherFromGroup");
74 * Gets current value and stores it as double. <p>
76 * Has <b> OK </b> status if the current value is between Min and Max
79 * The following method tests are to be executed before :
81 * <li> <code> getMaximumValue </code> </li>
82 * <li> <code> getMinimumValue </code> </li>
85 public void _getCurrentValue() {
86 executeMethod("getMaximumValue()");
87 executeMethod("getMinimumValue()");
89 boolean result
= true;
92 val
= oObj
.getCurrentValue() ;
93 if (util
.utils
.isVoid(val
)) {
97 curVal
= getDoubleValue(val
);
100 if (curVal
< minVal
|| maxVal
< curVal
) {
101 log
.println("" + (curVal
- minVal
) + "," + (maxVal
- curVal
));
102 log
.println("Current value " + curVal
+ " is not in range ["
103 + minVal
+ "," + maxVal
+ "]");
107 tRes
.tested("getCurrentValue()", result
) ;
111 * Performs testing for following cases :
113 * <li> Creates new value in valid range and sets it. </li>
114 * <li> Sets maximum and minimum values. </li>
115 * <li> Sets Min - 1, and Max + 1 values </li>
118 * Has <b> OK </b> status if for the first case the value returned
119 * is the same as was set and the method <code>setCurrentValue</code>
120 * returns <code>true</code>.
122 * In the second if Max and Min values are set and method
123 * <code>setCurrentValue</code> returns <code>true</code>.
125 * In the third case invalid values are truncated to Min and Max
126 * values accordingly. <p>
128 * The following method tests are to be executed before :
130 * <li> <code> getCurrentValue() </code> </li>
133 public void _setCurrentValue() {
134 executeMethod("getCurrentValue()");
136 boolean result
= true ;
137 boolean partResult
=true;
138 String noMax
= "com.sun.star.comp.toolkit.AccessibleScrollBar";
139 String implName
= util
.utils
.getImplName(oObj
);
141 if (tEnv
.getObjRelation("ValueNotPersitent")!=null) {
142 log
.println("Excluded since it works like AccessibleAction");
143 tRes
.tested("setCurrentValue()",Status
.skipped(true));
147 if (anotherFromGroup
== null) {
148 double newVal
= curVal
+ 1;
149 if (newVal
> maxVal
) newVal
-= 2;
150 if (newVal
< minVal
) newVal
+= 1;
152 log
.println("New value is " + newVal
);
154 Object setVal
= getObjectValue(newVal
, val
.getClass());
156 result
&= oObj
.setCurrentValue(setVal
);
159 log
.println("The value can't be set");
160 throw new StatusException(Status
.skipped(true));
163 double resVal
= getDoubleValue(oObj
.getCurrentValue());
164 log
.println("Res value is " + resVal
);
166 result
&= Math
.abs(newVal
- resVal
) < 0.00001;
168 log
.println("Checking min/max values");
169 result
&= oObj
.setCurrentValue(getObjectValue(minVal
, val
.getClass()));
170 log
.println("Setting to "+ getObjectValue(minVal
, val
.getClass()));
171 resVal
= getDoubleValue(oObj
.getCurrentValue());
172 log
.println("Result min value is " + resVal
);
173 result
&= Math
.abs(minVal
- resVal
) < 0.00001;
174 log
.println("\t works: "+(Math
.abs(minVal
- resVal
) < 0.00001));
176 result
&= oObj
.setCurrentValue(getObjectValue(maxVal
, val
.getClass()));
177 log
.println("Setting to "+ getObjectValue(maxVal
, val
.getClass()));
178 resVal
= getDoubleValue(oObj
.getCurrentValue());
179 log
.println("Result max value is " + resVal
);
180 partResult
= Math
.abs(maxVal
- resVal
) < 0.00001;
182 if (implName
.equals(noMax
)) {
183 log
.println("If one sets the maximum value of a scroll bar with XScrollBar::setMaximum(),"+
184 "then XScrollBar::getValue() returns the maximum value minus the visible size of"+
186 //using abitrary Value, since we can't determine the resulting value
187 partResult
= resVal
> 10;
191 log
.println("\t works: "+partResult
);
193 log
.println("Checking truncating of min/max values");
194 oObj
.setCurrentValue(getObjectValue(minVal
- 1, val
.getClass()));
195 log
.println("Setting to "+ getObjectValue(minVal
-1 , val
.getClass()));
196 resVal
= getDoubleValue(oObj
.getCurrentValue());
197 log
.println("Result min value is " + resVal
);
198 result
&= Math
.abs(minVal
- resVal
) < 0.00001;
199 log
.println("\t works: "+(Math
.abs(minVal
- resVal
) < 0.00001));
201 oObj
.setCurrentValue(getObjectValue(maxVal
+ 1, val
.getClass()));
202 log
.println("Setting to "+ getObjectValue(maxVal
+1 , val
.getClass()));
203 resVal
= getDoubleValue(oObj
.getCurrentValue());
204 log
.println("Result max value is " + resVal
);
205 partResult
= Math
.abs(maxVal
- resVal
) < 0.00001;
206 if (implName
.equals(noMax
)) {
207 log
.println("If one sets the maximum value of a scroll bar with XScrollBar::setMaximum(),"+
208 "then XScrollBar::getValue() returns the maximum value minus the visible size of"+
210 //using abitrary Value, since we can't determine the resulting value
211 partResult
= resVal
> 10;
215 log
.println("\t works: "+partResult
);
217 int curValBase
= getIntegerValue(val
);
218 Object valAnotherFromGroup
= anotherFromGroup
.getCurrentValue();
219 int curValAnother
= getIntegerValue(valAnotherFromGroup
);
220 log
.println("Current value of base component: " + curValBase
);
221 log
.println("Current value of another component from group: " +
223 log
.println("Set value of base component to " + curValAnother
);
224 if (tEnv
.getTestCase().getObjectName().equals("AccessibleRadioButton")) {
225 anotherFromGroup
.setCurrentValue(new Integer(curValBase
));
227 oObj
.setCurrentValue(valAnotherFromGroup
);
229 log
.println("Checking of values...");
230 int newValBase
= getIntegerValue(oObj
.getCurrentValue());
231 int newValAnother
= getIntegerValue(
232 anotherFromGroup
.getCurrentValue());
233 log
.println("New value of base component: " + newValBase
);
234 log
.println("Expected value of base component: " + curValAnother
);
235 log
.println("New value of another component from group: " +
237 log
.println("Expected value of another component from group: " +
240 result
= (newValBase
== curValAnother
) &&
241 (newValAnother
== curValBase
);
244 tRes
.tested("setCurrentValue()", result
);
248 * Gets and stores maximal value. <p>
250 * Has <b> OK </b> status if non empty value returned and
251 * Max value is greater than Min value.
253 * The following method tests are to be completed successfully before :
255 * <li> <code> getMinimumValue() </code> : to compare with </li>
258 public void _getMaximumValue() {
259 requiredMethod("getMinimumValue()");
261 boolean result
= true ;
263 Object val
= oObj
.getMaximumValue();
264 if (util
.utils
.isVoid(val
)) {
265 maxVal
= Double
.MAX_VALUE
;
268 maxVal
= getDoubleValue(val
);
270 log
.println("Max is " + val
.getClass()+ " = " + maxVal
);
272 result
&= maxVal
>= minVal
;
274 tRes
.tested("getMaximumValue()", result
) ;
278 * Gets and stores minimal value. <p>
280 * Has <b> OK </b> status if non empty value returned. <p>
283 public void _getMinimumValue() {
284 boolean result
= true ;
286 Object val
= oObj
.getMinimumValue() ;
287 if (util
.utils
.isVoid(val
)) {
288 minVal
= - Double
.MAX_VALUE
;
291 minVal
= getDoubleValue(val
);
293 log
.println("Min is " + val
.getClass()+ " = " + minVal
);
295 tRes
.tested("getMinimumValue()", result
) ;
298 private int getIntegerValue(Object val
) {
299 if (val
instanceof Integer
) {
300 return ((Integer
) val
).intValue();
302 throw new StatusException
303 (Status
.failed("Unexpected value type: " + val
.getClass()));
307 private double getDoubleValue(Object val
) {
308 if (val
instanceof Integer
) {
309 return ((Integer
) val
).doubleValue();
311 else if (val
instanceof Short
) {
312 return ((Short
) val
).doubleValue();
314 else if (val
instanceof Float
) {
315 return ((Float
) val
).doubleValue();
317 else if (val
instanceof Double
) {
318 return ((Double
) val
).doubleValue();
320 else if (util
.utils
.isVoid(val
)) {
324 throw new StatusException
325 (Status
.failed("Undetected value type: " + val
.getClass()));
329 private Object
getObjectValue(double val
, Class clazz
) {
330 if (clazz
.equals(Integer
.class)) {
331 return new Integer((int)val
);
333 else if (clazz
.equals(Short
.class)) {
334 return new Short((short)val
);
336 else if (clazz
.equals(Float
.class)) {
337 return new Float((float)val
);
339 else if (clazz
.equals(Double
.class)) {
340 return new Double(val
);
343 throw new StatusException
344 (Status
.failed("Unexpected class: " + clazz
));
349 * Disposes test environment.
351 protected void after() {
352 disposeEnvironment();