Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / accessibility / _XAccessibleValue.java
bloba11b868615c2e0f0d3eefbdca0f5385029b648a4
1 /*
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;
23 import lib.Status;
24 import lib.StatusException;
26 import com.sun.star.accessibility.XAccessibleValue;
28 /**
29 * Testing <code>com.sun.star.accessibility.XAccessibleValue</code>
30 * interface methods :
31 * <ul>
32 * <li><code> getCurrentValue()</code></li>
33 * <li><code> setCurrentValue()</code></li>
34 * <li><code> getMaximumValue()</code></li>
35 * <li><code> getMinimumValue()</code></li>
36 * </ul> <p>
38 * This test needs the following object relations :
39 * <ul>
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>
43 * </ul><p>
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;
56 @Override
57 protected void before() {
58 anotherFromGroup = (XAccessibleValue)tEnv.getObjRelation(
59 "XAccessibleValue.anotherFromGroup");
62 /**
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
66 * values. <p>
68 * The following method tests are to be executed before :
69 * <ul>
70 * <li> <code> getMaximumValue </code> </li>
71 * <li> <code> getMinimumValue </code> </li>
72 * </ul>
74 public void _getCurrentValue() {
75 executeMethod("getMaximumValue()");
76 executeMethod("getMinimumValue()");
78 boolean result = true;
80 double curVal ;
81 val = oObj.getCurrentValue() ;
82 if (util.utils.isVoid(val)) {
83 val = Integer.valueOf(0);
84 curVal = 0;
85 } else {
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 + "]");
93 result = false;
96 tRes.tested("getCurrentValue()", result) ;
99 /**
100 * Performs testing for following cases :
101 * <ul>
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>
105 * </ul> <p>
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 :
118 * <ul>
119 * <li> <code> getCurrentValue() </code> </li>
120 * </ul>
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));
133 return;
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);
147 if (!result) {
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"+
174 "the thumb");
175 //using abitrary Value, since we can't determine the resulting value
176 partResult = resVal > 10;
179 result &=partResult;
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"+
198 "the thumb");
199 //using abitrary Value, since we can't determine the resulting value
200 partResult = resVal > 10;
203 result &=partResult;
204 log.println("\t works: "+partResult);
205 } else {
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: " +
211 curValAnother);
212 log.println("Set value of base component to " + curValAnother);
213 if (tEnv.getTestCase().getObjectName().equals("AccessibleRadioButton")) {
214 anotherFromGroup.setCurrentValue(Integer.valueOf(curValBase));
215 } else {
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: " +
225 newValAnother);
226 log.println("Expected value of another component from group: " +
227 curValBase);
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 :
243 * <ul>
244 * <li> <code> getMinimumValue() </code> : to compare with </li>
245 * </ul>
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 ;
255 result = false;
256 } else {
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 ;
278 result = false;
279 } else {
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();
290 } else {
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)) {
310 return Double.NaN;
312 else {
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);
331 else {
332 throw new StatusException
333 (Status.failed("Unexpected class: " + clazz));
338 * Disposes test environment.
340 @Override
341 protected void after() {
342 disposeEnvironment();