Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / accessibility / _XAccessibleValue.java
blob201d5675ff0c7ebe0feca056e10b29b7856bd501
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package ifc.accessibility;
31 import lib.MultiMethodTest;
32 import lib.Status;
33 import lib.StatusException;
35 import com.sun.star.accessibility.XAccessibleValue;
37 /**
38 * Testing <code>com.sun.star.accessibility.XAccessibleValue</code>
39 * interface methods :
40 * <ul>
41 * <li><code> getCurrentValue()</code></li>
42 * <li><code> setCurrentValue()</code></li>
43 * <li><code> getMaximumValue()</code></li>
44 * <li><code> getMinimumValue()</code></li>
45 * </ul> <p>
47 * This test needs the following object relations :
48 * <ul>
49 * <li> <code>'XAccessibleValue.anotherFromGroup'</code>
50 * (of type <code>XAccessibleValue</code>) <b> optional </b>:
51 * another component from the group(e.g. radio button group)</li>
52 * </ul><p>
53 * @see com.sun.star.accessibility.XAccessibleValue
55 public class _XAccessibleValue extends MultiMethodTest {
57 public XAccessibleValue oObj = null;
59 private double minVal = 0;
60 private double maxVal = 0;
61 private double curVal = 0;
62 private Object val = null;
63 XAccessibleValue anotherFromGroup = null;
65 protected void before() {
66 anotherFromGroup = (XAccessibleValue)tEnv.getObjRelation(
67 "XAccessibleValue.anotherFromGroup");
70 /**
71 * Gets current value and stores it as double. <p>
73 * Has <b> OK </b> status if the current value is between Min and Max
74 * values. <p>
76 * The following method tests are to be executed before :
77 * <ul>
78 * <li> <code> getMaximumValue </code> </li>
79 * <li> <code> getMinimumValue </code> </li>
80 * </ul>
82 public void _getCurrentValue() {
83 executeMethod("getMaximumValue()");
84 executeMethod("getMinimumValue()");
86 boolean result = true;
88 double curVal ;
89 val = oObj.getCurrentValue() ;
90 if (util.utils.isVoid(val)) {
91 val = new Integer(0);
92 curVal = 0;
93 } else {
94 curVal = getDoubleValue(val);
97 if (curVal < minVal || maxVal < curVal) {
98 log.println("" + (curVal - minVal) + "," + (maxVal - curVal));
99 log.println("Current value " + curVal + " is not in range ["
100 + minVal + "," + maxVal + "]");
101 result = false;
104 tRes.tested("getCurrentValue()", result) ;
108 * Performs testing for following cases :
109 * <ul>
110 * <li> Creates new value in valid range and sets it. </li>
111 * <li> Sets maximum and minimum values. </li>
112 * <li> Sets Min - 1, and Max + 1 values </li>
113 * </ul> <p>
115 * Has <b> OK </b> status if for the first case the value returned
116 * is the same as was set and the method <code>setCurrentValue</code>
117 * returns <code>true</code>.
119 * In the second if Max and Min values are set and method
120 * <code>setCurrentValue</code> returns <code>true</code>.
122 * In the third case invalid values are truncated to Min and Max
123 * values accordingly. <p>
125 * The following method tests are to be executed before :
126 * <ul>
127 * <li> <code> getCurrentValue() </code> </li>
128 * </ul>
130 public void _setCurrentValue() {
131 executeMethod("getCurrentValue()");
133 boolean result = true ;
134 boolean partResult=true;
135 String noMax = "com.sun.star.comp.toolkit.AccessibleScrollBar";
136 String implName = util.utils.getImplName(oObj);
138 if (tEnv.getObjRelation("ValueNotPersitent")!=null) {
139 log.println("Excluded since it works like AccessibleAction");
140 tRes.tested("setCurrentValue()",Status.skipped(true));
141 return;
144 if (anotherFromGroup == null) {
145 double newVal = curVal + 1;
146 if (newVal > maxVal) newVal -= 2;
147 if (newVal < minVal) newVal += 1;
149 log.println("New value is " + newVal);
151 Object setVal = getObjectValue(newVal, val.getClass());
153 result &= oObj.setCurrentValue(setVal);
155 if (!result) {
156 log.println("The value can't be set");
157 throw new StatusException(Status.skipped(true));
160 double resVal = getDoubleValue(oObj.getCurrentValue());
161 log.println("Res value is " + resVal);
163 result &= Math.abs(newVal - resVal) < 0.00001;
165 log.println("Checking min/max values");
166 result &= oObj.setCurrentValue(getObjectValue(minVal, val.getClass()));
167 log.println("Setting to "+ getObjectValue(minVal, val.getClass()));
168 resVal = getDoubleValue(oObj.getCurrentValue());
169 log.println("Result min value is " + resVal);
170 result &= Math.abs(minVal - resVal) < 0.00001;
171 log.println("\t works: "+(Math.abs(minVal - resVal) < 0.00001));
173 result &= oObj.setCurrentValue(getObjectValue(maxVal, val.getClass()));
174 log.println("Setting to "+ getObjectValue(maxVal, val.getClass()));
175 resVal = getDoubleValue(oObj.getCurrentValue());
176 log.println("Result max value is " + resVal);
177 partResult = Math.abs(maxVal - resVal) < 0.00001;
179 if (implName.equals(noMax)) {
180 log.println("If one sets the maximum value of a scroll bar with XScrollBar::setMaximum(),"+
181 "then XScrollBar::getValue() returns the maximum value minus the visible size of"+
182 "the thumb");
183 //using abitrary Value, since we can't determine the resulting value
184 partResult = resVal > 10;
187 result &=partResult;
188 log.println("\t works: "+partResult);
190 log.println("Checking truncating of min/max values");
191 oObj.setCurrentValue(getObjectValue(minVal - 1, val.getClass()));
192 log.println("Setting to "+ getObjectValue(minVal -1 , val.getClass()));
193 resVal = getDoubleValue(oObj.getCurrentValue());
194 log.println("Result min value is " + resVal);
195 result &= Math.abs(minVal - resVal) < 0.00001;
196 log.println("\t works: "+(Math.abs(minVal - resVal) < 0.00001));
198 oObj.setCurrentValue(getObjectValue(maxVal + 1, val.getClass()));
199 log.println("Setting to "+ getObjectValue(maxVal +1 , val.getClass()));
200 resVal = getDoubleValue(oObj.getCurrentValue());
201 log.println("Result max value is " + resVal);
202 partResult = Math.abs(maxVal - resVal) < 0.00001;
203 if (implName.equals(noMax)) {
204 log.println("If one sets the maximum value of a scroll bar with XScrollBar::setMaximum(),"+
205 "then XScrollBar::getValue() returns the maximum value minus the visible size of"+
206 "the thumb");
207 //using abitrary Value, since we can't determine the resulting value
208 partResult = resVal > 10;
211 result &=partResult;
212 log.println("\t works: "+partResult);
213 } else {
214 int curValBase = getIntegerValue(val);
215 Object valAnotherFromGroup = anotherFromGroup.getCurrentValue();
216 int curValAnother = getIntegerValue(valAnotherFromGroup);
217 log.println("Current value of base component: " + curValBase);
218 log.println("Current value of another component from group: " +
219 curValAnother);
220 log.println("Set value of base component to " + curValAnother);
221 if (tEnv.getTestCase().getObjectName().equals("AccessibleRadioButton")) {
222 anotherFromGroup.setCurrentValue(new Integer(curValBase));
223 } else {
224 oObj.setCurrentValue(valAnotherFromGroup);
226 log.println("Checking of values...");
227 int newValBase = getIntegerValue(oObj.getCurrentValue());
228 int newValAnother = getIntegerValue(
229 anotherFromGroup.getCurrentValue());
230 log.println("New value of base component: " + newValBase);
231 log.println("Expected value of base component: " + curValAnother);
232 log.println("New value of another component from group: " +
233 newValAnother);
234 log.println("Expected value of another component from group: " +
235 curValBase);
237 result = (newValBase == curValAnother) &&
238 (newValAnother == curValBase);
241 tRes.tested("setCurrentValue()", result);
245 * Gets and stores maximal value. <p>
247 * Has <b> OK </b> status if non empty value returned and
248 * Max value is greater than Min value.
250 * The following method tests are to be completed successfully before :
251 * <ul>
252 * <li> <code> getMinimumValue() </code> : to compare with </li>
253 * </ul>
255 public void _getMaximumValue() {
256 requiredMethod("getMinimumValue()");
258 boolean result = true ;
260 Object val = oObj.getMaximumValue();
261 if (util.utils.isVoid(val)) {
262 maxVal = Double.MAX_VALUE ;
263 result = false;
264 } else {
265 maxVal = getDoubleValue(val);
267 log.println("Max is " + val.getClass()+ " = " + maxVal);
269 result &= maxVal >= minVal;
271 tRes.tested("getMaximumValue()", result) ;
275 * Gets and stores minimal value. <p>
277 * Has <b> OK </b> status if non empty value returned. <p>
280 public void _getMinimumValue() {
281 boolean result = true ;
283 Object val = oObj.getMinimumValue() ;
284 if (util.utils.isVoid(val)) {
285 minVal = - Double.MAX_VALUE ;
286 result = false;
287 } else {
288 minVal = getDoubleValue(val);
290 log.println("Min is " + val.getClass()+ " = " + minVal);
292 tRes.tested("getMinimumValue()", result) ;
295 private int getIntegerValue(Object val) {
296 if (val instanceof Integer) {
297 return ((Integer) val).intValue();
298 } else {
299 throw new StatusException
300 (Status.failed("Unexpected value type: " + val.getClass()));
304 private double getDoubleValue(Object val) {
305 if (val instanceof Integer) {
306 return ((Integer) val).doubleValue();
308 else if (val instanceof Short) {
309 return ((Short) val).doubleValue();
311 else if (val instanceof Float) {
312 return ((Float) val).doubleValue();
314 else if (val instanceof Double) {
315 return ((Double) val).doubleValue();
317 else if (util.utils.isVoid(val)) {
318 return Double.NaN;
320 else {
321 throw new StatusException
322 (Status.failed("Undetected value type: " + val.getClass()));
326 private Object getObjectValue(double val, Class clazz) {
327 if (clazz.equals(Integer.class)) {
328 return new Integer((int)val);
330 else if (clazz.equals(Short.class)) {
331 return new Short((short)val);
333 else if (clazz.equals(Float.class)) {
334 return new Float((float)val);
336 else if (clazz.equals(Double.class)) {
337 return new Double(val);
339 else {
340 throw new StatusException
341 (Status.failed("Unexpected class: " + clazz));
346 * Disposes test environment.
348 protected void after() {
349 disposeEnvironment();