1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 package ifc.accessibility; 29 30 31 import lib.MultiMethodTest; 32 import lib.Status; 33 import lib.StatusException; 34 35 import com.sun.star.accessibility.XAccessibleValue; 36 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> 46 * 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 54 */ 55 public class _XAccessibleValue extends MultiMethodTest { 56 57 public XAccessibleValue oObj = null; 58 59 private double minVal = 0; 60 private double maxVal = 0; 61 private double curVal = 0; 62 private Object val = null; 63 XAccessibleValue anotherFromGroup = null; 64 65 protected void before() { 66 anotherFromGroup = (XAccessibleValue)tEnv.getObjRelation( 67 "XAccessibleValue.anotherFromGroup"); 68 } 69 70 /** 71 * Gets current value and stores it as double. <p> 72 * 73 * Has <b> OK </b> status if the current value is between Min and Max 74 * values. <p> 75 * 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> 81 */ 82 public void _getCurrentValue() { 83 executeMethod("getMaximumValue()"); 84 executeMethod("getMinimumValue()"); 85 86 boolean result = true; 87 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); 95 } 96 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; 102 } 103 104 tRes.tested("getCurrentValue()", result) ; 105 } 106 107 /** 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> 114 * 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>. 118 * 119 * In the second if Max and Min values are set and method 120 * <code>setCurrentValue</code> returns <code>true</code>. 121 * 122 * In the third case invalid values are truncated to Min and Max 123 * values accordingly. <p> 124 * 125 * The following method tests are to be executed before : 126 * <ul> 127 * <li> <code> getCurrentValue() </code> </li> 128 * </ul> 129 */ 130 public void _setCurrentValue() { 131 executeMethod("getCurrentValue()"); 132 133 boolean result = true ; 134 boolean partResult=true; 135 String noMax = "com.sun.star.comp.toolkit.AccessibleScrollBar"; 136 String implName = util.utils.getImplName(oObj); 137 138 if (tEnv.getObjRelation("ValueNotPersitent")!=null) { 139 log.println("Excluded since it works like AccessibleAction"); 140 tRes.tested("setCurrentValue()",Status.skipped(true)); 141 return; 142 } 143 144 if (anotherFromGroup == null) { 145 double newVal = curVal + 1; 146 if (newVal > maxVal) newVal -= 2; 147 if (newVal < minVal) newVal += 1; 148 149 log.println("New value is " + newVal); 150 151 Object setVal = getObjectValue(newVal, val.getClass()); 152 153 result &= oObj.setCurrentValue(setVal); 154 155 if (!result) { 156 log.println("The value can't be set"); 157 throw new StatusException(Status.skipped(true)); 158 } 159 160 double resVal = getDoubleValue(oObj.getCurrentValue()); 161 log.println("Res value is " + resVal); 162 163 result &= Math.abs(newVal - resVal) < 0.00001; 164 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)); 172 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; 178 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; 185 } 186 187 result &=partResult; 188 log.println("\t works: "+partResult); 189 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)); 197 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; 209 } 210 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); 225 } 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); 236 237 result = (newValBase == curValAnother) && 238 (newValAnother == curValBase); 239 } 240 241 tRes.tested("setCurrentValue()", result); 242 } 243 244 /** 245 * Gets and stores maximal value. <p> 246 * 247 * Has <b> OK </b> status if non empty value returned and 248 * Max value is greater than Min value. 249 * 250 * The following method tests are to be completed successfully before : 251 * <ul> 252 * <li> <code> getMinimumValue() </code> : to compare with </li> 253 * </ul> 254 */ 255 public void _getMaximumValue() { 256 requiredMethod("getMinimumValue()"); 257 258 boolean result = true ; 259 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); 266 } 267 log.println("Max is " + val.getClass()+ " = " + maxVal); 268 269 result &= maxVal >= minVal; 270 271 tRes.tested("getMaximumValue()", result) ; 272 } 273 274 /** 275 * Gets and stores minimal value. <p> 276 * 277 * Has <b> OK </b> status if non empty value returned. <p> 278 * 279 */ 280 public void _getMinimumValue() { 281 boolean result = true ; 282 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); 289 } 290 log.println("Min is " + val.getClass()+ " = " + minVal); 291 292 tRes.tested("getMinimumValue()", result) ; 293 } 294 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())); 301 } 302 } 303 304 private double getDoubleValue(Object val) { 305 if (val instanceof Integer) { 306 return ((Integer) val).doubleValue(); 307 } 308 else if (val instanceof Short) { 309 return ((Short) val).doubleValue(); 310 } 311 else if (val instanceof Float) { 312 return ((Float) val).doubleValue(); 313 } 314 else if (val instanceof Double) { 315 return ((Double) val).doubleValue(); 316 } 317 else if (util.utils.isVoid(val)) { 318 return Double.NaN; 319 } 320 else { 321 throw new StatusException 322 (Status.failed("Undetected value type: " + val.getClass())); 323 } 324 } 325 326 private Object getObjectValue(double val, Class clazz) { 327 if (clazz.equals(Integer.class)) { 328 return new Integer((int)val); 329 } 330 else if (clazz.equals(Short.class)) { 331 return new Short((short)val); 332 } 333 else if (clazz.equals(Float.class)) { 334 return new Float((float)val); 335 } 336 else if (clazz.equals(Double.class)) { 337 return new Double(val); 338 } 339 else { 340 throw new StatusException 341 (Status.failed("Unexpected class: " + clazz)); 342 } 343 } 344 345 /** 346 * Disposes test environment. 347 */ 348 protected void after() { 349 disposeEnvironment(); 350 } 351 } 352