Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / accessibility / _XAccessibleValue.java
blob44d8129b29b7b8ea0e1cad76877e2db11ca0e125
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XAccessibleValue.java,v $
10 * $Revision: 1.7 $
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;
35 import lib.Status;
36 import lib.StatusException;
38 import com.sun.star.accessibility.XAccessibleValue;
40 /**
41 * Testing <code>com.sun.star.accessibility.XAccessibleValue</code>
42 * interface methods :
43 * <ul>
44 * <li><code> getCurrentValue()</code></li>
45 * <li><code> setCurrentValue()</code></li>
46 * <li><code> getMaximumValue()</code></li>
47 * <li><code> getMinimumValue()</code></li>
48 * </ul> <p>
50 * This test needs the following object relations :
51 * <ul>
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>
55 * </ul><p>
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");
73 /**
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
77 * values. <p>
79 * The following method tests are to be executed before :
80 * <ul>
81 * <li> <code> getMaximumValue </code> </li>
82 * <li> <code> getMinimumValue </code> </li>
83 * </ul>
85 public void _getCurrentValue() {
86 executeMethod("getMaximumValue()");
87 executeMethod("getMinimumValue()");
89 boolean result = true;
91 double curVal ;
92 val = oObj.getCurrentValue() ;
93 if (util.utils.isVoid(val)) {
94 val = new Integer(0);
95 curVal = 0;
96 } else {
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 + "]");
104 result = false;
107 tRes.tested("getCurrentValue()", result) ;
111 * Performs testing for following cases :
112 * <ul>
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>
116 * </ul> <p>
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 :
129 * <ul>
130 * <li> <code> getCurrentValue() </code> </li>
131 * </ul>
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));
144 return;
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);
158 if (!result) {
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"+
185 "the thumb");
186 //using abitrary Value, since we can't determine the resulting value
187 partResult = resVal > 10;
190 result &=partResult;
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"+
209 "the thumb");
210 //using abitrary Value, since we can't determine the resulting value
211 partResult = resVal > 10;
214 result &=partResult;
215 log.println("\t works: "+partResult);
216 } else {
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: " +
222 curValAnother);
223 log.println("Set value of base component to " + curValAnother);
224 if (tEnv.getTestCase().getObjectName().equals("AccessibleRadioButton")) {
225 anotherFromGroup.setCurrentValue(new Integer(curValBase));
226 } else {
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: " +
236 newValAnother);
237 log.println("Expected value of another component from group: " +
238 curValBase);
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 :
254 * <ul>
255 * <li> <code> getMinimumValue() </code> : to compare with </li>
256 * </ul>
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 ;
266 result = false;
267 } else {
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 ;
289 result = false;
290 } else {
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();
301 } else {
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)) {
321 return Double.NaN;
323 else {
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);
342 else {
343 throw new StatusException
344 (Status.failed("Unexpected class: " + clazz));
349 * Disposes test environment.
351 protected void after() {
352 disposeEnvironment();