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 10cdf0e10cSrcweir * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir package ifc.accessibility; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.accessibility.IllegalAccessibleComponentStateException; 26cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible; 27cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleContext; 28cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleRelationSet; 29cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleStateSet; 30cdf0e10cSrcweir import com.sun.star.lang.Locale; 31cdf0e10cSrcweir 32cdf0e10cSrcweir import lib.MultiMethodTest; 33cdf0e10cSrcweir 34cdf0e10cSrcweir import util.AccessibilityTools; 35cdf0e10cSrcweir 36cdf0e10cSrcweir 37cdf0e10cSrcweir /** 38cdf0e10cSrcweir * Testing <code>com.sun.star.accessibility.XAccessibleContext</code> 39cdf0e10cSrcweir * interface methods : 40cdf0e10cSrcweir * <ul> 41cdf0e10cSrcweir * <li><code> getAccessibleChildCount()</code></li> 42cdf0e10cSrcweir * <li><code> getAccessibleChild()</code></li> 43cdf0e10cSrcweir * <li><code> getAccessibleParent()</code></li> 44cdf0e10cSrcweir * <li><code> getAccessibleIndexInParent()</code></li> 45cdf0e10cSrcweir * <li><code> getAccessibleRole()</code></li> 46cdf0e10cSrcweir * <li><code> getAccessibleDescription()</code></li> 47cdf0e10cSrcweir * <li><code> getAccessibleName()</code></li> 48cdf0e10cSrcweir * <li><code> getAccessibleRelationSet()</code></li> 49cdf0e10cSrcweir * <li><code> getAccessibleStateSet()</code></li> 50cdf0e10cSrcweir * <li><code> getLocale()</code></li> 51cdf0e10cSrcweir * </ul> <p> 52cdf0e10cSrcweir * 53cdf0e10cSrcweir * @see com.sun.star.accessibility.XAccessibleContext 54cdf0e10cSrcweir */ 55cdf0e10cSrcweir public class _XAccessibleContext extends MultiMethodTest { 56cdf0e10cSrcweir private static final String className = "com.sun.star.accessibility.XAccessibleContext"; 57cdf0e10cSrcweir public XAccessibleContext oObj = null; 58cdf0e10cSrcweir private int childCount = 0; 59cdf0e10cSrcweir private XAccessible parent = null; 60cdf0e10cSrcweir 61cdf0e10cSrcweir // temporary while accessibility package is in com.sun.star getTestedClassName()62cdf0e10cSrcweir protected String getTestedClassName() { 63cdf0e10cSrcweir return className; 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir /** 67cdf0e10cSrcweir * Calls the method and stores the number of children. <p> 68cdf0e10cSrcweir * Has <b> OK </b> status if non-negative number rutrned. 69cdf0e10cSrcweir */ _getAccessibleChildCount()70cdf0e10cSrcweir public void _getAccessibleChildCount() { 71cdf0e10cSrcweir childCount = oObj.getAccessibleChildCount(); 72cdf0e10cSrcweir log.println("" + childCount + " children found."); 73cdf0e10cSrcweir tRes.tested("getAccessibleChildCount()", childCount > -1); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir /** 77cdf0e10cSrcweir * Tries to get every child and checks its parent. <p> 78cdf0e10cSrcweir * 79cdf0e10cSrcweir * Has <b> OK </b> status if parent of every child 80cdf0e10cSrcweir * and the tested component are the same objects. 81cdf0e10cSrcweir * 82cdf0e10cSrcweir * The following method tests are to be completed successfully before : 83cdf0e10cSrcweir * <ul> 84cdf0e10cSrcweir * <li> <code> getAccessibleChildCount() </code> : to have a number of 85cdf0e10cSrcweir * children </li> 86cdf0e10cSrcweir * </ul> 87cdf0e10cSrcweir */ _getAccessibleChild()88cdf0e10cSrcweir public void _getAccessibleChild() { 89cdf0e10cSrcweir requiredMethod("getAccessibleChildCount()"); 90cdf0e10cSrcweir 91cdf0e10cSrcweir log.println("testing 'getAccessibleChild()'..."); 92cdf0e10cSrcweir 93cdf0e10cSrcweir boolean bOK = true; 94cdf0e10cSrcweir int counter = childCount; 95cdf0e10cSrcweir 96cdf0e10cSrcweir if (childCount > 500) { 97cdf0e10cSrcweir counter = 500; 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir for (int i = 0; i < counter; i++) { 101cdf0e10cSrcweir try { 102cdf0e10cSrcweir XAccessible ch = oObj.getAccessibleChild(i); 103cdf0e10cSrcweir XAccessibleContext chAC = ch.getAccessibleContext(); 104cdf0e10cSrcweir 105cdf0e10cSrcweir log.println("## Child " + i + ": " + 106cdf0e10cSrcweir chAC.getAccessibleDescription()); 107cdf0e10cSrcweir 108cdf0e10cSrcweir if (!AccessibilityTools.equals(chAC.getAccessibleParent() 109cdf0e10cSrcweir .getAccessibleContext(), 110cdf0e10cSrcweir oObj)) { 111cdf0e10cSrcweir log.println("The parent of child and component " + 112cdf0e10cSrcweir "itself differ."); 113cdf0e10cSrcweir log.println("\tRole:"); 114cdf0e10cSrcweir log.println("Getting: " + 115cdf0e10cSrcweir chAC.getAccessibleParent() 116cdf0e10cSrcweir .getAccessibleContext() 117cdf0e10cSrcweir .getAccessibleRole()); 118cdf0e10cSrcweir log.println("Expected: " + oObj.getAccessibleRole()); 119cdf0e10cSrcweir 120cdf0e10cSrcweir log.println("\tImplementationName:"); 121cdf0e10cSrcweir log.println("Getting: " + 122cdf0e10cSrcweir util.utils.getImplName( 123cdf0e10cSrcweir chAC.getAccessibleParent() 124cdf0e10cSrcweir .getAccessibleContext())); 125cdf0e10cSrcweir log.println("Expected: " + util.utils.getImplName(oObj)); 126cdf0e10cSrcweir 127cdf0e10cSrcweir log.println("\tAccessibleDescription:"); 128cdf0e10cSrcweir log.println("Getting(Description): " + 129cdf0e10cSrcweir chAC.getAccessibleParent() 130cdf0e10cSrcweir .getAccessibleContext() 131cdf0e10cSrcweir .getAccessibleDescription()); 132cdf0e10cSrcweir log.println("Expected(Description): " + 133cdf0e10cSrcweir oObj.getAccessibleDescription()); 134cdf0e10cSrcweir 135cdf0e10cSrcweir log.println("\tAccessibleName:"); 136cdf0e10cSrcweir log.println("Getting(Name): " + 137cdf0e10cSrcweir chAC.getAccessibleParent() 138cdf0e10cSrcweir .getAccessibleContext() 139cdf0e10cSrcweir .getAccessibleName()); 140cdf0e10cSrcweir log.println("Expected(Name): " + 141cdf0e10cSrcweir oObj.getAccessibleName()); 142cdf0e10cSrcweir 143cdf0e10cSrcweir log.println("\tChildCount:"); 144cdf0e10cSrcweir log.println("Getting: " + 145cdf0e10cSrcweir chAC.getAccessibleParent() 146cdf0e10cSrcweir .getAccessibleContext() 147cdf0e10cSrcweir .getAccessibleChildCount()); 148cdf0e10cSrcweir log.println("Expected: " + 149cdf0e10cSrcweir oObj.getAccessibleChildCount()); 150cdf0e10cSrcweir 151cdf0e10cSrcweir log.println("\tParentName:"); 152cdf0e10cSrcweir log.println("Getting (Name): " + 153cdf0e10cSrcweir chAC.getAccessibleParent() 154cdf0e10cSrcweir .getAccessibleContext() 155cdf0e10cSrcweir .getAccessibleParent() 156cdf0e10cSrcweir .getAccessibleContext() 157cdf0e10cSrcweir .getAccessibleName()); 158cdf0e10cSrcweir log.println("Expected(Name): " + 159cdf0e10cSrcweir oObj.getAccessibleParent() 160cdf0e10cSrcweir .getAccessibleContext() 161cdf0e10cSrcweir .getAccessibleName()); 162cdf0e10cSrcweir 163cdf0e10cSrcweir log.println("##"); 164cdf0e10cSrcweir bOK = false; 165cdf0e10cSrcweir } else { 166cdf0e10cSrcweir log.println("Role: " + chAC.getAccessibleRole()); 167cdf0e10cSrcweir log.println("Name: " + chAC.getAccessibleName()); 168cdf0e10cSrcweir log.println("IndexInParent: " + 169cdf0e10cSrcweir chAC.getAccessibleIndexInParent()); 170cdf0e10cSrcweir log.println("ImplementationName: " + 171cdf0e10cSrcweir util.utils.getImplName(chAC)); 172cdf0e10cSrcweir } 173cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 174cdf0e10cSrcweir e.printStackTrace(log); 175cdf0e10cSrcweir bOK = false; 176cdf0e10cSrcweir } 177cdf0e10cSrcweir } 178cdf0e10cSrcweir 179cdf0e10cSrcweir tRes.tested("getAccessibleChild()", bOK); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir /** 183cdf0e10cSrcweir * Just gets the parent. <p> 184cdf0e10cSrcweir * 185cdf0e10cSrcweir * Has <b> OK </b> status if parent is not null. 186cdf0e10cSrcweir */ _getAccessibleParent()187cdf0e10cSrcweir public void _getAccessibleParent() { 188cdf0e10cSrcweir // assume that the component is not ROOT 189cdf0e10cSrcweir parent = oObj.getAccessibleParent(); 190cdf0e10cSrcweir tRes.tested("getAccessibleParent()", parent != null); 191cdf0e10cSrcweir } 192cdf0e10cSrcweir 193cdf0e10cSrcweir /** 194cdf0e10cSrcweir * Retrieves the index of tested component in its parent. 195cdf0e10cSrcweir * Then gets the parent's child by this index and compares 196cdf0e10cSrcweir * it with tested component.<p> 197cdf0e10cSrcweir * 198cdf0e10cSrcweir * Has <b> OK </b> status if the parent's child and the tested 199cdf0e10cSrcweir * component are the same objects. 200cdf0e10cSrcweir * 201cdf0e10cSrcweir * The following method tests are to be completed successfully before : 202cdf0e10cSrcweir * <ul> 203cdf0e10cSrcweir * <li> <code> getAccessibleParent() </code> : to have a parent </li> 204cdf0e10cSrcweir * </ul> 205cdf0e10cSrcweir */ _getAccessibleIndexInParent()206cdf0e10cSrcweir public void _getAccessibleIndexInParent() { 207cdf0e10cSrcweir requiredMethod("getAccessibleParent()"); 208cdf0e10cSrcweir 209cdf0e10cSrcweir boolean bOK = true; 210cdf0e10cSrcweir int idx = oObj.getAccessibleIndexInParent(); 211cdf0e10cSrcweir 212cdf0e10cSrcweir XAccessibleContext parentAC = parent.getAccessibleContext(); 213cdf0e10cSrcweir 214cdf0e10cSrcweir try { 215cdf0e10cSrcweir if (parentAC.getAccessibleChild(idx) == null) { 216cdf0e10cSrcweir log.println("Parent has no child with this index"); 217cdf0e10cSrcweir bOK &= false; 218cdf0e10cSrcweir } else { 219cdf0e10cSrcweir bOK &= AccessibilityTools.equals(parentAC.getAccessibleChild( 220cdf0e10cSrcweir idx) 221cdf0e10cSrcweir .getAccessibleContext(), 222cdf0e10cSrcweir oObj); 223cdf0e10cSrcweir } 224cdf0e10cSrcweir 225cdf0e10cSrcweir if (!bOK) { 226cdf0e10cSrcweir log.println("Expected: " + util.utils.getImplName(oObj)); 227cdf0e10cSrcweir 228cdf0e10cSrcweir if (parentAC.getAccessibleChild(idx) != null) { 229cdf0e10cSrcweir log.println("Getting: " + 230cdf0e10cSrcweir util.utils.getImplName( 231cdf0e10cSrcweir parentAC.getAccessibleChild(idx) 232cdf0e10cSrcweir .getAccessibleContext())); 233cdf0e10cSrcweir } 234cdf0e10cSrcweir } 235cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 236cdf0e10cSrcweir e.printStackTrace(log); 237cdf0e10cSrcweir bOK = false; 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240cdf0e10cSrcweir tRes.tested("getAccessibleIndexInParent()", bOK); 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir /** 244cdf0e10cSrcweir * Get the accessible role of component. <p> 245cdf0e10cSrcweir * 246cdf0e10cSrcweir * Has <b> OK </b> status if non-negative number rutrned. 247cdf0e10cSrcweir */ _getAccessibleRole()248cdf0e10cSrcweir public void _getAccessibleRole() { 249cdf0e10cSrcweir short role = oObj.getAccessibleRole(); 250cdf0e10cSrcweir log.println("The role is " + role); 251cdf0e10cSrcweir tRes.tested("getAccessibleRole()", role > -1); 252cdf0e10cSrcweir } 253cdf0e10cSrcweir 254cdf0e10cSrcweir /** 255cdf0e10cSrcweir * Get the accessible name of the component. <p> 256cdf0e10cSrcweir * 257cdf0e10cSrcweir * Has <b> OK </b> status if the name has non-zero length. 258cdf0e10cSrcweir */ _getAccessibleName()259cdf0e10cSrcweir public void _getAccessibleName() { 260cdf0e10cSrcweir String name = oObj.getAccessibleName(); 261cdf0e10cSrcweir log.println("The name is '" + name + "'"); 262cdf0e10cSrcweir tRes.tested("getAccessibleName()", name != null); 263cdf0e10cSrcweir } 264cdf0e10cSrcweir 265cdf0e10cSrcweir /** 266cdf0e10cSrcweir * Get the accessible description of the component. <p> 267cdf0e10cSrcweir * 268cdf0e10cSrcweir * Has <b> OK </b> status if the description has non-zero length. 269cdf0e10cSrcweir */ _getAccessibleDescription()270cdf0e10cSrcweir public void _getAccessibleDescription() { 271cdf0e10cSrcweir String descr = oObj.getAccessibleDescription(); 272cdf0e10cSrcweir log.println("The description is '" + descr + "'"); 273cdf0e10cSrcweir tRes.tested("getAccessibleDescription()", descr != null); 274cdf0e10cSrcweir } 275cdf0e10cSrcweir 276cdf0e10cSrcweir /** 277cdf0e10cSrcweir * Just gets the set. <p> 278cdf0e10cSrcweir * 279cdf0e10cSrcweir * Has <b> OK </b> status if the set is not null. 280cdf0e10cSrcweir */ _getAccessibleRelationSet()281cdf0e10cSrcweir public void _getAccessibleRelationSet() { 282cdf0e10cSrcweir XAccessibleRelationSet set = oObj.getAccessibleRelationSet(); 283cdf0e10cSrcweir tRes.tested("getAccessibleRelationSet()", true); 284cdf0e10cSrcweir } 285cdf0e10cSrcweir 286cdf0e10cSrcweir /** 287cdf0e10cSrcweir * Just gets the set. <p> 288cdf0e10cSrcweir * 289cdf0e10cSrcweir * Has <b> OK </b> status if the set is not null. 290cdf0e10cSrcweir */ _getAccessibleStateSet()291cdf0e10cSrcweir public void _getAccessibleStateSet() { 292cdf0e10cSrcweir XAccessibleStateSet set = oObj.getAccessibleStateSet(); 293cdf0e10cSrcweir boolean res = true; 294cdf0e10cSrcweir String[] expectedStateNames = (String[]) tEnv.getObjRelation( 295cdf0e10cSrcweir "expectedStateNames"); 296cdf0e10cSrcweir short[] expectedStates = (short[]) tEnv.getObjRelation( 297cdf0e10cSrcweir "expectedStates"); 298cdf0e10cSrcweir 299cdf0e10cSrcweir if ((expectedStateNames != null) && (expectedStates != null)) { 300cdf0e10cSrcweir res = checkStates(expectedStateNames, expectedStates, set); 301cdf0e10cSrcweir } else { 302cdf0e10cSrcweir res = set != null; 303cdf0e10cSrcweir } 304cdf0e10cSrcweir 305cdf0e10cSrcweir tRes.tested("getAccessibleStateSet()", res); 306cdf0e10cSrcweir } 307cdf0e10cSrcweir 308cdf0e10cSrcweir /** 309cdf0e10cSrcweir * Gets the locale. <p> 310cdf0e10cSrcweir * 311cdf0e10cSrcweir * Has <b> OK </b> status if <code>Country</code> and 312cdf0e10cSrcweir * <code>Language</code> fields of locale structure 313cdf0e10cSrcweir * are not empty. 314cdf0e10cSrcweir */ _getLocale()315cdf0e10cSrcweir public void _getLocale() { 316cdf0e10cSrcweir Locale loc = null; 317cdf0e10cSrcweir 318cdf0e10cSrcweir try { 319cdf0e10cSrcweir loc = oObj.getLocale(); 320cdf0e10cSrcweir log.println("The locale is " + loc.Language + "," + loc.Country); 321cdf0e10cSrcweir } catch (IllegalAccessibleComponentStateException e) { 322cdf0e10cSrcweir e.printStackTrace(log); 323cdf0e10cSrcweir } 324cdf0e10cSrcweir 325cdf0e10cSrcweir tRes.tested("getLocale()", 326cdf0e10cSrcweir (loc != null) && (loc.Language.length() > 0)); 327cdf0e10cSrcweir } 328cdf0e10cSrcweir checkStates(String[] expectedStateNames, short[] expectedStates, XAccessibleStateSet set)329cdf0e10cSrcweir protected boolean checkStates(String[] expectedStateNames, 330cdf0e10cSrcweir short[] expectedStates, 331cdf0e10cSrcweir XAccessibleStateSet set) { 332cdf0e10cSrcweir boolean works = true; 333cdf0e10cSrcweir 334cdf0e10cSrcweir for (int k = 0; k < expectedStateNames.length; k++) { 335cdf0e10cSrcweir boolean contains = set.contains(expectedStates[k]); 336cdf0e10cSrcweir 337cdf0e10cSrcweir if (contains) { 338cdf0e10cSrcweir log.println("Set contains " + expectedStateNames[k] + 339cdf0e10cSrcweir " ... OK"); 340cdf0e10cSrcweir works &= true; 341cdf0e10cSrcweir } else { 342cdf0e10cSrcweir log.println("Set doesn't contain " + expectedStateNames[k] + 343cdf0e10cSrcweir " ... FAILED"); 344cdf0e10cSrcweir works &= false; 345cdf0e10cSrcweir } 346cdf0e10cSrcweir } 347cdf0e10cSrcweir 348cdf0e10cSrcweir return works; 349cdf0e10cSrcweir } 350cdf0e10cSrcweir } 351