1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.accessibility;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir 
27cdf0e10cSrcweir import lib.MultiMethodTest;
28cdf0e10cSrcweir import lib.Status;
29cdf0e10cSrcweir import lib.StatusException;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleValue;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir /**
34cdf0e10cSrcweir  * Testing <code>com.sun.star.accessibility.XAccessibleValue</code>
35cdf0e10cSrcweir  * interface methods :
36cdf0e10cSrcweir  * <ul>
37cdf0e10cSrcweir  *  <li><code> getCurrentValue()</code></li>
38cdf0e10cSrcweir  *  <li><code> setCurrentValue()</code></li>
39cdf0e10cSrcweir  *  <li><code> getMaximumValue()</code></li>
40cdf0e10cSrcweir  *  <li><code> getMinimumValue()</code></li>
41cdf0e10cSrcweir  * </ul> <p>
42cdf0e10cSrcweir  *
43cdf0e10cSrcweir  * This test needs the following object relations :
44cdf0e10cSrcweir  * <ul>
45cdf0e10cSrcweir  *  <li> <code>'XAccessibleValue.anotherFromGroup'</code>
46cdf0e10cSrcweir  *  (of type <code>XAccessibleValue</code>) <b> optional </b>:
47cdf0e10cSrcweir  *   another component from the group(e.g. radio button group)</li>
48cdf0e10cSrcweir  *  </ul><p>
49cdf0e10cSrcweir  * @see com.sun.star.accessibility.XAccessibleValue
50cdf0e10cSrcweir  */
51cdf0e10cSrcweir public class _XAccessibleValue extends MultiMethodTest {
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     public XAccessibleValue oObj = null;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     private double minVal = 0;
56cdf0e10cSrcweir     private double maxVal = 0;
57cdf0e10cSrcweir     private double curVal = 0;
58cdf0e10cSrcweir     private Object val = null;
59cdf0e10cSrcweir     XAccessibleValue anotherFromGroup = null;
60cdf0e10cSrcweir 
before()61cdf0e10cSrcweir     protected void before() {
62cdf0e10cSrcweir         anotherFromGroup = (XAccessibleValue)tEnv.getObjRelation(
63cdf0e10cSrcweir             "XAccessibleValue.anotherFromGroup");
64cdf0e10cSrcweir     }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     /**
67cdf0e10cSrcweir      * Gets current value and stores it as double. <p>
68cdf0e10cSrcweir      *
69cdf0e10cSrcweir      * Has <b> OK </b> status if the current value is between Min and Max
70cdf0e10cSrcweir      * values. <p>
71cdf0e10cSrcweir      *
72cdf0e10cSrcweir      * The following method tests are to be executed before :
73cdf0e10cSrcweir      * <ul>
74cdf0e10cSrcweir      *  <li> <code> getMaximumValue </code> </li>
75cdf0e10cSrcweir      *  <li> <code> getMinimumValue </code> </li>
76cdf0e10cSrcweir      * </ul>
77cdf0e10cSrcweir      */
_getCurrentValue()78cdf0e10cSrcweir     public void _getCurrentValue() {
79cdf0e10cSrcweir         executeMethod("getMaximumValue()");
80cdf0e10cSrcweir         executeMethod("getMinimumValue()");
81cdf0e10cSrcweir 
82cdf0e10cSrcweir         boolean result = true;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir         double curVal ;
85cdf0e10cSrcweir         val = oObj.getCurrentValue() ;
86cdf0e10cSrcweir         if (util.utils.isVoid(val)) {
87cdf0e10cSrcweir             val = new Integer(0);
88cdf0e10cSrcweir             curVal = 0;
89cdf0e10cSrcweir         } else  {
90cdf0e10cSrcweir             curVal = getDoubleValue(val);
91cdf0e10cSrcweir         }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         if (curVal < minVal || maxVal < curVal) {
94cdf0e10cSrcweir             log.println("" + (curVal - minVal) + "," + (maxVal - curVal));
95cdf0e10cSrcweir             log.println("Current value " + curVal + " is not in range ["
96cdf0e10cSrcweir                 + minVal + "," + maxVal + "]");
97cdf0e10cSrcweir             result = false;
98cdf0e10cSrcweir         }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         tRes.tested("getCurrentValue()", result) ;
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     /**
104cdf0e10cSrcweir      * Performs testing for following cases :
105cdf0e10cSrcweir      * <ul>
106cdf0e10cSrcweir      *  <li> Creates new value in valid range and sets it. </li>
107cdf0e10cSrcweir      *  <li> Sets maximum and minimum values. </li>
108cdf0e10cSrcweir      *  <li> Sets Min - 1, and Max + 1 values </li>
109cdf0e10cSrcweir      * </ul> <p>
110cdf0e10cSrcweir      *
111cdf0e10cSrcweir      * Has <b> OK </b> status if for the first case the value returned
112cdf0e10cSrcweir      * is the same as was set and the method <code>setCurrentValue</code>
113cdf0e10cSrcweir      * returns <code>true</code>.
114cdf0e10cSrcweir      *
115cdf0e10cSrcweir      * In the second if Max and Min values are set and method
116cdf0e10cSrcweir      * <code>setCurrentValue</code> returns <code>true</code>.
117cdf0e10cSrcweir      *
118cdf0e10cSrcweir      * In the third case invalid values are truncated to Min and Max
119cdf0e10cSrcweir      * values accordingly. <p>
120cdf0e10cSrcweir      *
121cdf0e10cSrcweir      * The following method tests are to be executed before :
122cdf0e10cSrcweir      * <ul>
123cdf0e10cSrcweir      *  <li> <code> getCurrentValue() </code> </li>
124cdf0e10cSrcweir      * </ul>
125cdf0e10cSrcweir      */
_setCurrentValue()126cdf0e10cSrcweir     public void _setCurrentValue() {
127cdf0e10cSrcweir         executeMethod("getCurrentValue()");
128cdf0e10cSrcweir 
129cdf0e10cSrcweir         boolean result = true ;
130cdf0e10cSrcweir 		boolean partResult=true;
131cdf0e10cSrcweir 		String noMax = "com.sun.star.comp.toolkit.AccessibleScrollBar";
132cdf0e10cSrcweir 		String implName = util.utils.getImplName(oObj);
133cdf0e10cSrcweir 
134cdf0e10cSrcweir         if (tEnv.getObjRelation("ValueNotPersitent")!=null) {
135cdf0e10cSrcweir             log.println("Excluded since it works like AccessibleAction");
136cdf0e10cSrcweir             tRes.tested("setCurrentValue()",Status.skipped(true));
137cdf0e10cSrcweir             return;
138cdf0e10cSrcweir         }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir         if (anotherFromGroup == null) {
141cdf0e10cSrcweir             double newVal = curVal + 1;
142cdf0e10cSrcweir             if (newVal > maxVal) newVal -= 2;
143cdf0e10cSrcweir             if (newVal < minVal) newVal += 1;
144cdf0e10cSrcweir 
145cdf0e10cSrcweir             log.println("New value is " + newVal);
146cdf0e10cSrcweir 
147cdf0e10cSrcweir             Object setVal = getObjectValue(newVal, val.getClass());
148cdf0e10cSrcweir 
149cdf0e10cSrcweir             result &= oObj.setCurrentValue(setVal);
150cdf0e10cSrcweir 
151cdf0e10cSrcweir             if (!result) {
152cdf0e10cSrcweir                 log.println("The value can't be set");
153cdf0e10cSrcweir                 throw new StatusException(Status.skipped(true));
154cdf0e10cSrcweir             }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir             double resVal = getDoubleValue(oObj.getCurrentValue());
157cdf0e10cSrcweir             log.println("Res value is " + resVal);
158cdf0e10cSrcweir 
159cdf0e10cSrcweir             result &= Math.abs(newVal - resVal) < 0.00001;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir             log.println("Checking min/max values");
162cdf0e10cSrcweir             result &= oObj.setCurrentValue(getObjectValue(minVal, val.getClass()));
163cdf0e10cSrcweir             log.println("Setting to "+ getObjectValue(minVal, val.getClass()));
164cdf0e10cSrcweir             resVal = getDoubleValue(oObj.getCurrentValue());
165cdf0e10cSrcweir             log.println("Result min value is " + resVal);
166cdf0e10cSrcweir             result &= Math.abs(minVal - resVal) < 0.00001;
167cdf0e10cSrcweir 			log.println("\t works: "+(Math.abs(minVal - resVal) < 0.00001));
168cdf0e10cSrcweir 
169cdf0e10cSrcweir             result &= oObj.setCurrentValue(getObjectValue(maxVal, val.getClass()));
170cdf0e10cSrcweir             log.println("Setting to "+ getObjectValue(maxVal, val.getClass()));
171cdf0e10cSrcweir             resVal = getDoubleValue(oObj.getCurrentValue());
172cdf0e10cSrcweir             log.println("Result max value is " + resVal);
173cdf0e10cSrcweir             partResult = Math.abs(maxVal - resVal) < 0.00001;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 			if (implName.equals(noMax)) {
176cdf0e10cSrcweir 				log.println("If one sets the maximum value of a scroll bar with XScrollBar::setMaximum(),"+
177cdf0e10cSrcweir 				"then XScrollBar::getValue() returns the maximum value minus the visible size of"+
178cdf0e10cSrcweir 				"the thumb");
179cdf0e10cSrcweir 				//using abitrary Value, since we can't determine the resulting value
180cdf0e10cSrcweir 				partResult = resVal > 10;
181cdf0e10cSrcweir 			}
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 			result &=partResult;
184cdf0e10cSrcweir 			log.println("\t works: "+partResult);
185cdf0e10cSrcweir 
186cdf0e10cSrcweir             log.println("Checking truncating of min/max values");
187cdf0e10cSrcweir             oObj.setCurrentValue(getObjectValue(minVal - 1, val.getClass()));
188cdf0e10cSrcweir             log.println("Setting to "+ getObjectValue(minVal -1 , val.getClass()));
189cdf0e10cSrcweir             resVal = getDoubleValue(oObj.getCurrentValue());
190cdf0e10cSrcweir             log.println("Result min value is " + resVal);
191cdf0e10cSrcweir             result &= Math.abs(minVal - resVal) < 0.00001;
192cdf0e10cSrcweir 			log.println("\t works: "+(Math.abs(minVal - resVal) < 0.00001));
193cdf0e10cSrcweir 
194cdf0e10cSrcweir             oObj.setCurrentValue(getObjectValue(maxVal + 1, val.getClass()));
195cdf0e10cSrcweir             log.println("Setting to "+ getObjectValue(maxVal +1 , val.getClass()));
196cdf0e10cSrcweir             resVal = getDoubleValue(oObj.getCurrentValue());
197cdf0e10cSrcweir             log.println("Result max value is " + resVal);
198cdf0e10cSrcweir             partResult = Math.abs(maxVal - resVal) < 0.00001;
199cdf0e10cSrcweir 			if (implName.equals(noMax)) {
200cdf0e10cSrcweir 				log.println("If one sets the maximum value of a scroll bar with XScrollBar::setMaximum(),"+
201cdf0e10cSrcweir 				"then XScrollBar::getValue() returns the maximum value minus the visible size of"+
202cdf0e10cSrcweir 				"the thumb");
203cdf0e10cSrcweir 				//using abitrary Value, since we can't determine the resulting value
204cdf0e10cSrcweir 				partResult = resVal > 10;
205cdf0e10cSrcweir 			}
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 			result &=partResult;
208cdf0e10cSrcweir 			log.println("\t works: "+partResult);
209cdf0e10cSrcweir         } else {
210cdf0e10cSrcweir             int curValBase = getIntegerValue(val);
211cdf0e10cSrcweir             Object valAnotherFromGroup = anotherFromGroup.getCurrentValue();
212cdf0e10cSrcweir             int curValAnother = getIntegerValue(valAnotherFromGroup);
213cdf0e10cSrcweir             log.println("Current value of base component: " + curValBase);
214cdf0e10cSrcweir             log.println("Current value of another component from group: " +
215cdf0e10cSrcweir                 curValAnother);
216cdf0e10cSrcweir             log.println("Set value of base component to " + curValAnother);
217cdf0e10cSrcweir             if (tEnv.getTestCase().getObjectName().equals("AccessibleRadioButton")) {
218cdf0e10cSrcweir                 anotherFromGroup.setCurrentValue(new Integer(curValBase));
219cdf0e10cSrcweir             } else {
220cdf0e10cSrcweir                 oObj.setCurrentValue(valAnotherFromGroup);
221cdf0e10cSrcweir             }
222cdf0e10cSrcweir             log.println("Checking of values...");
223cdf0e10cSrcweir             int newValBase = getIntegerValue(oObj.getCurrentValue());
224cdf0e10cSrcweir             int newValAnother = getIntegerValue(
225cdf0e10cSrcweir                 anotherFromGroup.getCurrentValue());
226cdf0e10cSrcweir             log.println("New value of base component: " + newValBase);
227cdf0e10cSrcweir             log.println("Expected value of base component: " + curValAnother);
228cdf0e10cSrcweir             log.println("New value of another component from group: " +
229cdf0e10cSrcweir                 newValAnother);
230cdf0e10cSrcweir             log.println("Expected value of another component from group: " +
231cdf0e10cSrcweir                 curValBase);
232cdf0e10cSrcweir 
233cdf0e10cSrcweir             result = (newValBase == curValAnother) &&
234cdf0e10cSrcweir                 (newValAnother == curValBase);
235cdf0e10cSrcweir         }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir         tRes.tested("setCurrentValue()", result);
238cdf0e10cSrcweir     }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir     /**
241cdf0e10cSrcweir      * Gets and stores maximal value. <p>
242cdf0e10cSrcweir      *
243cdf0e10cSrcweir      * Has <b> OK </b> status if non empty value returned and
244cdf0e10cSrcweir      * Max value is greater than Min value.
245cdf0e10cSrcweir      *
246cdf0e10cSrcweir      * The following method tests are to be completed successfully before :
247cdf0e10cSrcweir      * <ul>
248cdf0e10cSrcweir      *  <li> <code> getMinimumValue() </code> : to compare with </li>
249cdf0e10cSrcweir      * </ul>
250cdf0e10cSrcweir      */
251cdf0e10cSrcweir     public void _getMaximumValue() {
252cdf0e10cSrcweir         requiredMethod("getMinimumValue()");
253cdf0e10cSrcweir 
254cdf0e10cSrcweir         boolean result = true ;
255cdf0e10cSrcweir 
256cdf0e10cSrcweir         Object val = oObj.getMaximumValue();
257cdf0e10cSrcweir         if (util.utils.isVoid(val)) {
258cdf0e10cSrcweir             maxVal = Double.MAX_VALUE ;
259cdf0e10cSrcweir             result = false;
260cdf0e10cSrcweir         } else {
261cdf0e10cSrcweir             maxVal = getDoubleValue(val);
262cdf0e10cSrcweir         }
263cdf0e10cSrcweir         log.println("Max is " + val.getClass()+ " = " + maxVal);
264cdf0e10cSrcweir 
265cdf0e10cSrcweir         result &= maxVal >= minVal;
266cdf0e10cSrcweir 
267cdf0e10cSrcweir         tRes.tested("getMaximumValue()", result) ;
268cdf0e10cSrcweir     }
269cdf0e10cSrcweir 
270cdf0e10cSrcweir     /**
271cdf0e10cSrcweir      * Gets and stores minimal value. <p>
272cdf0e10cSrcweir      *
273cdf0e10cSrcweir      * Has <b> OK </b> status if non empty value returned. <p>
274cdf0e10cSrcweir      *
275cdf0e10cSrcweir      */
276cdf0e10cSrcweir     public void _getMinimumValue() {
277cdf0e10cSrcweir         boolean result = true ;
278cdf0e10cSrcweir 
279cdf0e10cSrcweir         Object val = oObj.getMinimumValue() ;
280cdf0e10cSrcweir         if (util.utils.isVoid(val)) {
281cdf0e10cSrcweir             minVal = - Double.MAX_VALUE ;
282cdf0e10cSrcweir             result = false;
283cdf0e10cSrcweir         } else {
284cdf0e10cSrcweir             minVal = getDoubleValue(val);
285cdf0e10cSrcweir         }
286cdf0e10cSrcweir         log.println("Min is " + val.getClass()+ " = " + minVal);
287cdf0e10cSrcweir 
288cdf0e10cSrcweir         tRes.tested("getMinimumValue()", result) ;
289cdf0e10cSrcweir     }
290cdf0e10cSrcweir 
291cdf0e10cSrcweir     private int getIntegerValue(Object val) {
292cdf0e10cSrcweir         if (val instanceof Integer) {
293cdf0e10cSrcweir             return ((Integer) val).intValue();
294cdf0e10cSrcweir         } else {
295cdf0e10cSrcweir             throw new StatusException
296cdf0e10cSrcweir                 (Status.failed("Unexpected value type: " + val.getClass()));
297cdf0e10cSrcweir         }
298cdf0e10cSrcweir     }
299cdf0e10cSrcweir 
300cdf0e10cSrcweir     private double getDoubleValue(Object val) {
301cdf0e10cSrcweir         if (val instanceof Integer) {
302cdf0e10cSrcweir             return ((Integer) val).doubleValue();
303cdf0e10cSrcweir         }
304cdf0e10cSrcweir         else if (val instanceof Short) {
305cdf0e10cSrcweir             return ((Short) val).doubleValue();
306cdf0e10cSrcweir         }
307cdf0e10cSrcweir         else if (val instanceof Float) {
308cdf0e10cSrcweir             return ((Float) val).doubleValue();
309cdf0e10cSrcweir         }
310cdf0e10cSrcweir         else if (val instanceof Double) {
311cdf0e10cSrcweir             return ((Double) val).doubleValue();
312cdf0e10cSrcweir         }
313cdf0e10cSrcweir         else if (util.utils.isVoid(val)) {
314cdf0e10cSrcweir             return Double.NaN;
315cdf0e10cSrcweir         }
316cdf0e10cSrcweir         else {
317cdf0e10cSrcweir             throw new StatusException
318cdf0e10cSrcweir                 (Status.failed("Undetected value type: " + val.getClass()));
319cdf0e10cSrcweir         }
320cdf0e10cSrcweir     }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir     private Object getObjectValue(double val, Class clazz) {
323cdf0e10cSrcweir         if (clazz.equals(Integer.class)) {
324cdf0e10cSrcweir             return new Integer((int)val);
325cdf0e10cSrcweir         }
326cdf0e10cSrcweir         else if (clazz.equals(Short.class)) {
327cdf0e10cSrcweir             return new Short((short)val);
328cdf0e10cSrcweir         }
329cdf0e10cSrcweir         else if (clazz.equals(Float.class)) {
330cdf0e10cSrcweir             return new Float((float)val);
331cdf0e10cSrcweir         }
332cdf0e10cSrcweir         else if (clazz.equals(Double.class)) {
333cdf0e10cSrcweir             return new Double(val);
334cdf0e10cSrcweir         }
335cdf0e10cSrcweir         else {
336cdf0e10cSrcweir             throw new StatusException
337cdf0e10cSrcweir                 (Status.failed("Unexpected class: " + clazz));
338cdf0e10cSrcweir         }
339cdf0e10cSrcweir     }
340cdf0e10cSrcweir 
341cdf0e10cSrcweir     /**
342cdf0e10cSrcweir      * Disposes test environment.
343cdf0e10cSrcweir      */
344cdf0e10cSrcweir     protected void after() {
345cdf0e10cSrcweir         disposeEnvironment();
346cdf0e10cSrcweir     }
347cdf0e10cSrcweir }
348