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 double curVal
= 0;
53 private Object val
= null;
54 XAccessibleValue anotherFromGroup
= null;
56 protected void before() {
57 anotherFromGroup
= (XAccessibleValue
)tEnv
.getObjRelation(
58 "XAccessibleValue.anotherFromGroup");
62 * Gets current value and stores it as double. <p>
64 * Has <b> OK </b> status if the current value is between Min and Max
67 * The following method tests are to be executed before :
69 * <li> <code> getMaximumValue </code> </li>
70 * <li> <code> getMinimumValue </code> </li>
73 public void _getCurrentValue() {
74 executeMethod("getMaximumValue()");
75 executeMethod("getMinimumValue()");
77 boolean result
= true;
80 val
= oObj
.getCurrentValue() ;
81 if (util
.utils
.isVoid(val
)) {
85 curVal
= getDoubleValue(val
);
88 if (curVal
< minVal
|| maxVal
< curVal
) {
89 log
.println("" + (curVal
- minVal
) + "," + (maxVal
- curVal
));
90 log
.println("Current value " + curVal
+ " is not in range ["
91 + minVal
+ "," + maxVal
+ "]");
95 tRes
.tested("getCurrentValue()", result
) ;
99 * Performs testing for following cases :
101 * <li> Creates new value in valid range and sets it. </li>
102 * <li> Sets maximum and minimum values. </li>
103 * <li> Sets Min - 1, and Max + 1 values </li>
106 * Has <b> OK </b> status if for the first case the value returned
107 * is the same as was set and the method <code>setCurrentValue</code>
108 * returns <code>true</code>.
110 * In the second if Max and Min values are set and method
111 * <code>setCurrentValue</code> returns <code>true</code>.
113 * In the third case invalid values are truncated to Min and Max
114 * values accordingly. <p>
116 * The following method tests are to be executed before :
118 * <li> <code> getCurrentValue() </code> </li>
121 public void _setCurrentValue() {
122 executeMethod("getCurrentValue()");
124 boolean result
= true ;
125 boolean partResult
=true;
126 String noMax
= "com.sun.star.comp.toolkit.AccessibleScrollBar";
127 String implName
= util
.utils
.getImplName(oObj
);
129 if (tEnv
.getObjRelation("ValueNotPersitent")!=null) {
130 log
.println("Excluded since it works like AccessibleAction");
131 tRes
.tested("setCurrentValue()",Status
.skipped(true));
135 if (anotherFromGroup
== null) {
136 double newVal
= curVal
+ 1;
137 if (newVal
> maxVal
) newVal
-= 2;
138 if (newVal
< minVal
) newVal
+= 1;
140 log
.println("New value is " + newVal
);
142 Object setVal
= getObjectValue(newVal
, val
.getClass());
144 result
&= oObj
.setCurrentValue(setVal
);
147 log
.println("The value can't be set");
148 throw new StatusException(Status
.skipped(true));
151 double resVal
= getDoubleValue(oObj
.getCurrentValue());
152 log
.println("Res value is " + resVal
);
154 result
&= Math
.abs(newVal
- resVal
) < 0.00001;
156 log
.println("Checking min/max values");
157 result
&= oObj
.setCurrentValue(getObjectValue(minVal
, val
.getClass()));
158 log
.println("Setting to "+ getObjectValue(minVal
, val
.getClass()));
159 resVal
= getDoubleValue(oObj
.getCurrentValue());
160 log
.println("Result min value is " + resVal
);
161 result
&= Math
.abs(minVal
- resVal
) < 0.00001;
162 log
.println("\t works: "+(Math
.abs(minVal
- resVal
) < 0.00001));
164 result
&= oObj
.setCurrentValue(getObjectValue(maxVal
, val
.getClass()));
165 log
.println("Setting to "+ getObjectValue(maxVal
, val
.getClass()));
166 resVal
= getDoubleValue(oObj
.getCurrentValue());
167 log
.println("Result max value is " + resVal
);
168 partResult
= Math
.abs(maxVal
- resVal
) < 0.00001;
170 if (implName
.equals(noMax
)) {
171 log
.println("If one sets the maximum value of a scroll bar with XScrollBar::setMaximum(),"+
172 "then XScrollBar::getValue() returns the maximum value minus the visible size of"+
174 //using abitrary Value, since we can't determine the resulting value
175 partResult
= resVal
> 10;
179 log
.println("\t works: "+partResult
);
181 log
.println("Checking truncating of min/max values");
182 oObj
.setCurrentValue(getObjectValue(minVal
- 1, val
.getClass()));
183 log
.println("Setting to "+ getObjectValue(minVal
-1 , val
.getClass()));
184 resVal
= getDoubleValue(oObj
.getCurrentValue());
185 log
.println("Result min value is " + resVal
);
186 result
&= Math
.abs(minVal
- resVal
) < 0.00001;
187 log
.println("\t works: "+(Math
.abs(minVal
- resVal
) < 0.00001));
189 oObj
.setCurrentValue(getObjectValue(maxVal
+ 1, val
.getClass()));
190 log
.println("Setting to "+ getObjectValue(maxVal
+1 , val
.getClass()));
191 resVal
= getDoubleValue(oObj
.getCurrentValue());
192 log
.println("Result max value is " + resVal
);
193 partResult
= Math
.abs(maxVal
- resVal
) < 0.00001;
194 if (implName
.equals(noMax
)) {
195 log
.println("If one sets the maximum value of a scroll bar with XScrollBar::setMaximum(),"+
196 "then XScrollBar::getValue() returns the maximum value minus the visible size of"+
198 //using abitrary Value, since we can't determine the resulting value
199 partResult
= resVal
> 10;
203 log
.println("\t works: "+partResult
);
205 int curValBase
= getIntegerValue(val
);
206 Object valAnotherFromGroup
= anotherFromGroup
.getCurrentValue();
207 int curValAnother
= getIntegerValue(valAnotherFromGroup
);
208 log
.println("Current value of base component: " + curValBase
);
209 log
.println("Current value of another component from group: " +
211 log
.println("Set value of base component to " + curValAnother
);
212 if (tEnv
.getTestCase().getObjectName().equals("AccessibleRadioButton")) {
213 anotherFromGroup
.setCurrentValue(new Integer(curValBase
));
215 oObj
.setCurrentValue(valAnotherFromGroup
);
217 log
.println("Checking of values...");
218 int newValBase
= getIntegerValue(oObj
.getCurrentValue());
219 int newValAnother
= getIntegerValue(
220 anotherFromGroup
.getCurrentValue());
221 log
.println("New value of base component: " + newValBase
);
222 log
.println("Expected value of base component: " + curValAnother
);
223 log
.println("New value of another component from group: " +
225 log
.println("Expected value of another component from group: " +
228 result
= (newValBase
== curValAnother
) &&
229 (newValAnother
== curValBase
);
232 tRes
.tested("setCurrentValue()", result
);
236 * Gets and stores maximal value. <p>
238 * Has <b> OK </b> status if non empty value returned and
239 * Max value is greater than Min value.
241 * The following method tests are to be completed successfully before :
243 * <li> <code> getMinimumValue() </code> : to compare with </li>
246 public void _getMaximumValue() {
247 requiredMethod("getMinimumValue()");
249 boolean result
= true ;
251 Object val
= oObj
.getMaximumValue();
252 if (util
.utils
.isVoid(val
)) {
253 maxVal
= Double
.MAX_VALUE
;
256 maxVal
= getDoubleValue(val
);
258 log
.println("Max is " + val
.getClass()+ " = " + maxVal
);
260 result
&= maxVal
>= minVal
;
262 tRes
.tested("getMaximumValue()", result
) ;
266 * Gets and stores minimal value. <p>
268 * Has <b> OK </b> status if non empty value returned. <p>
271 public void _getMinimumValue() {
272 boolean result
= true ;
274 Object val
= oObj
.getMinimumValue() ;
275 if (util
.utils
.isVoid(val
)) {
276 minVal
= - Double
.MAX_VALUE
;
279 minVal
= getDoubleValue(val
);
281 log
.println("Min is " + val
.getClass()+ " = " + minVal
);
283 tRes
.tested("getMinimumValue()", result
) ;
286 private int getIntegerValue(Object val
) {
287 if (val
instanceof Integer
) {
288 return ((Integer
) val
).intValue();
290 throw new StatusException
291 (Status
.failed("Unexpected value type: " + val
.getClass()));
295 private double getDoubleValue(Object val
) {
296 if (val
instanceof Integer
) {
297 return ((Integer
) val
).doubleValue();
299 else if (val
instanceof Short
) {
300 return ((Short
) val
).doubleValue();
302 else if (val
instanceof Float
) {
303 return ((Float
) val
).doubleValue();
305 else if (val
instanceof Double
) {
306 return ((Double
) val
).doubleValue();
308 else if (util
.utils
.isVoid(val
)) {
312 throw new StatusException
313 (Status
.failed("Undetected value type: " + val
.getClass()));
317 private Object
getObjectValue(double val
, Class
<?
> clazz
) {
318 if (clazz
.equals(Integer
.class)) {
319 return new Integer((int)val
);
321 else if (clazz
.equals(Short
.class)) {
322 return new Short((short)val
);
324 else if (clazz
.equals(Float
.class)) {
325 return new Float((float)val
);
327 else if (clazz
.equals(Double
.class)) {
328 return new Double(val
);
331 throw new StatusException
332 (Status
.failed("Unexpected class: " + clazz
));
337 * Disposes test environment.
339 protected void after() {
340 disposeEnvironment();