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 .
19 package ifc
.accessibility
;
22 import lib
.MultiMethodTest
;
24 import lib
.StatusException
;
26 import com
.sun
.star
.accessibility
.XAccessibleValue
;
29 * Testing <code>com.sun.star.accessibility.XAccessibleValue</code>
32 * <li><code> getCurrentValue()</code></li>
33 * <li><code> setCurrentValue()</code></li>
34 * <li><code> getMaximumValue()</code></li>
35 * <li><code> getMinimumValue()</code></li>
38 * This test needs the following object relations :
40 * <li> <code>'XAccessibleValue.anotherFromGroup'</code>
41 * (of type <code>XAccessibleValue</code>) <b> optional </b>:
42 * another component from the group(e.g. radio button group)</li>
44 * @see com.sun.star.accessibility.XAccessibleValue
46 public class _XAccessibleValue
extends MultiMethodTest
{
48 public XAccessibleValue oObj
= null;
50 private double minVal
= 0;
51 private double maxVal
= 0;
52 private static final double curVal
= 0;
53 private Object val
= null;
54 XAccessibleValue anotherFromGroup
= null;
57 protected void before() {
58 anotherFromGroup
= (XAccessibleValue
)tEnv
.getObjRelation(
59 "XAccessibleValue.anotherFromGroup");
63 * Gets current value and stores it as double. <p>
65 * Has <b> OK </b> status if the current value is between Min and Max
68 * The following method tests are to be executed before :
70 * <li> <code> getMaximumValue </code> </li>
71 * <li> <code> getMinimumValue </code> </li>
74 public void _getCurrentValue() {
75 executeMethod("getMaximumValue()");
76 executeMethod("getMinimumValue()");
78 boolean result
= true;
81 val
= oObj
.getCurrentValue() ;
82 if (util
.utils
.isVoid(val
)) {
83 val
= Integer
.valueOf(0);
86 curVal
= getDoubleValue(val
);
89 if (curVal
< minVal
|| maxVal
< curVal
) {
90 log
.println((curVal
- minVal
) + "," + (maxVal
- curVal
));
91 log
.println("Current value " + curVal
+ " is not in range ["
92 + minVal
+ "," + maxVal
+ "]");
96 tRes
.tested("getCurrentValue()", result
) ;
100 * Performs testing for following cases :
102 * <li> Creates new value in valid range and sets it. </li>
103 * <li> Sets maximum and minimum values. </li>
104 * <li> Sets Min - 1, and Max + 1 values </li>
107 * Has <b> OK </b> status if for the first case the value returned
108 * is the same as was set and the method <code>setCurrentValue</code>
109 * returns <code>true</code>.
111 * In the second if Max and Min values are set and method
112 * <code>setCurrentValue</code> returns <code>true</code>.
114 * In the third case invalid values are truncated to Min and Max
115 * values accordingly. <p>
117 * The following method tests are to be executed before :
119 * <li> <code> getCurrentValue() </code> </li>
122 public void _setCurrentValue() {
123 executeMethod("getCurrentValue()");
125 boolean result
= true ;
126 boolean partResult
=true;
127 String noMax
= "com.sun.star.comp.toolkit.AccessibleScrollBar";
128 String implName
= util
.utils
.getImplName(oObj
);
130 if (tEnv
.getObjRelation("ValueNotPersitent")!=null) {
131 log
.println("Excluded since it works like AccessibleAction");
132 tRes
.tested("setCurrentValue()",Status
.skipped(true));
136 if (anotherFromGroup
== null) {
137 double newVal
= curVal
+ 1;
138 if (newVal
> maxVal
) newVal
-= 2;
139 if (newVal
< minVal
) newVal
+= 1;
141 log
.println("New value is " + newVal
);
143 Object setVal
= getObjectValue(newVal
, val
.getClass());
145 result
&= oObj
.setCurrentValue(setVal
);
148 log
.println("The value can't be set");
149 throw new StatusException(Status
.skipped(true));
152 double resVal
= getDoubleValue(oObj
.getCurrentValue());
153 log
.println("Res value is " + resVal
);
155 result
&= Math
.abs(newVal
- resVal
) < 0.00001;
157 log
.println("Checking min/max values");
158 result
&= oObj
.setCurrentValue(getObjectValue(minVal
, val
.getClass()));
159 log
.println("Setting to "+ getObjectValue(minVal
, val
.getClass()));
160 resVal
= getDoubleValue(oObj
.getCurrentValue());
161 log
.println("Result min value is " + resVal
);
162 result
&= Math
.abs(minVal
- resVal
) < 0.00001;
163 log
.println("\t works: "+(Math
.abs(minVal
- resVal
) < 0.00001));
165 result
&= oObj
.setCurrentValue(getObjectValue(maxVal
, val
.getClass()));
166 log
.println("Setting to "+ getObjectValue(maxVal
, val
.getClass()));
167 resVal
= getDoubleValue(oObj
.getCurrentValue());
168 log
.println("Result max value is " + resVal
);
169 partResult
= Math
.abs(maxVal
- resVal
) < 0.00001;
171 if (implName
.equals(noMax
)) {
172 log
.println("If one sets the maximum value of a scroll bar with XScrollBar::setMaximum(),"+
173 "then XScrollBar::getValue() returns the maximum value minus the visible size of"+
175 //using abitrary Value, since we can't determine the resulting value
176 partResult
= resVal
> 10;
180 log
.println("\t works: "+partResult
);
182 log
.println("Checking truncating of min/max values");
183 oObj
.setCurrentValue(getObjectValue(minVal
- 1, val
.getClass()));
184 log
.println("Setting to "+ getObjectValue(minVal
-1 , val
.getClass()));
185 resVal
= getDoubleValue(oObj
.getCurrentValue());
186 log
.println("Result min value is " + resVal
);
187 result
&= Math
.abs(minVal
- resVal
) < 0.00001;
188 log
.println("\t works: "+(Math
.abs(minVal
- resVal
) < 0.00001));
190 oObj
.setCurrentValue(getObjectValue(maxVal
+ 1, val
.getClass()));
191 log
.println("Setting to "+ getObjectValue(maxVal
+1 , val
.getClass()));
192 resVal
= getDoubleValue(oObj
.getCurrentValue());
193 log
.println("Result max value is " + resVal
);
194 partResult
= Math
.abs(maxVal
- resVal
) < 0.00001;
195 if (implName
.equals(noMax
)) {
196 log
.println("If one sets the maximum value of a scroll bar with XScrollBar::setMaximum(),"+
197 "then XScrollBar::getValue() returns the maximum value minus the visible size of"+
199 //using abitrary Value, since we can't determine the resulting value
200 partResult
= resVal
> 10;
204 log
.println("\t works: "+partResult
);
206 int curValBase
= getIntegerValue(val
);
207 Object valAnotherFromGroup
= anotherFromGroup
.getCurrentValue();
208 int curValAnother
= getIntegerValue(valAnotherFromGroup
);
209 log
.println("Current value of base component: " + curValBase
);
210 log
.println("Current value of another component from group: " +
212 log
.println("Set value of base component to " + curValAnother
);
213 if (tEnv
.getTestCase().getObjectName().equals("AccessibleRadioButton")) {
214 anotherFromGroup
.setCurrentValue(Integer
.valueOf(curValBase
));
216 oObj
.setCurrentValue(valAnotherFromGroup
);
218 log
.println("Checking of values...");
219 int newValBase
= getIntegerValue(oObj
.getCurrentValue());
220 int newValAnother
= getIntegerValue(
221 anotherFromGroup
.getCurrentValue());
222 log
.println("New value of base component: " + newValBase
);
223 log
.println("Expected value of base component: " + curValAnother
);
224 log
.println("New value of another component from group: " +
226 log
.println("Expected value of another component from group: " +
229 result
= (newValBase
== curValAnother
) &&
230 (newValAnother
== curValBase
);
233 tRes
.tested("setCurrentValue()", result
);
237 * Gets and stores maximal value. <p>
239 * Has <b> OK </b> status if non empty value returned and
240 * Max value is greater than Min value.
242 * The following method tests are to be completed successfully before :
244 * <li> <code> getMinimumValue() </code> : to compare with </li>
247 public void _getMaximumValue() {
248 requiredMethod("getMinimumValue()");
250 boolean result
= true ;
252 Object val
= oObj
.getMaximumValue();
253 if (util
.utils
.isVoid(val
)) {
254 maxVal
= Double
.MAX_VALUE
;
257 maxVal
= getDoubleValue(val
);
259 log
.println("Max is " + val
.getClass()+ " = " + maxVal
);
261 result
&= maxVal
>= minVal
;
263 tRes
.tested("getMaximumValue()", result
) ;
267 * Gets and stores minimal value. <p>
269 * Has <b> OK </b> status if non empty value returned. <p>
272 public void _getMinimumValue() {
273 boolean result
= true ;
275 Object val
= oObj
.getMinimumValue() ;
276 if (util
.utils
.isVoid(val
)) {
277 minVal
= - Double
.MAX_VALUE
;
280 minVal
= getDoubleValue(val
);
282 log
.println("Min is " + val
.getClass()+ " = " + minVal
);
284 tRes
.tested("getMinimumValue()", result
) ;
287 private int getIntegerValue(Object val
) {
288 if (val
instanceof Integer
) {
289 return ((Integer
) val
).intValue();
291 throw new StatusException
292 (Status
.failed("Unexpected value type: " + val
.getClass()));
296 private double getDoubleValue(Object val
) {
297 if (val
instanceof Integer
) {
298 return ((Integer
) val
).doubleValue();
300 else if (val
instanceof Short
) {
301 return ((Short
) val
).doubleValue();
303 else if (val
instanceof Float
) {
304 return ((Float
) val
).doubleValue();
306 else if (val
instanceof Double
) {
307 return ((Double
) val
).doubleValue();
309 else if (util
.utils
.isVoid(val
)) {
313 throw new StatusException
314 (Status
.failed("Undetected value type: " + val
.getClass()));
318 private Object
getObjectValue(double val
, Class
<?
> clazz
) {
319 if (clazz
.equals(Integer
.class)) {
320 return Integer
.valueOf((int)val
);
322 else if (clazz
.equals(Short
.class)) {
323 return Short
.valueOf((short)val
);
325 else if (clazz
.equals(Float
.class)) {
326 return new Float((float)val
);
328 else if (clazz
.equals(Double
.class)) {
329 return new Double(val
);
332 throw new StatusException
333 (Status
.failed("Unexpected class: " + clazz
));
338 * Disposes test environment.
341 protected void after() {
342 disposeEnvironment();