Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / accessibility / _XAccessibleContext.java
blobaeb383dc5f2b962b620892457c146ff65a5c62be
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XAccessibleContext.java,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package ifc.accessibility;
32 import com.sun.star.accessibility.IllegalAccessibleComponentStateException;
33 import com.sun.star.accessibility.XAccessible;
34 import com.sun.star.accessibility.XAccessibleContext;
35 import com.sun.star.accessibility.XAccessibleRelationSet;
36 import com.sun.star.accessibility.XAccessibleStateSet;
37 import com.sun.star.lang.Locale;
39 import lib.MultiMethodTest;
41 import util.AccessibilityTools;
44 /**
45 * Testing <code>com.sun.star.accessibility.XAccessibleContext</code>
46 * interface methods :
47 * <ul>
48 * <li><code> getAccessibleChildCount()</code></li>
49 * <li><code> getAccessibleChild()</code></li>
50 * <li><code> getAccessibleParent()</code></li>
51 * <li><code> getAccessibleIndexInParent()</code></li>
52 * <li><code> getAccessibleRole()</code></li>
53 * <li><code> getAccessibleDescription()</code></li>
54 * <li><code> getAccessibleName()</code></li>
55 * <li><code> getAccessibleRelationSet()</code></li>
56 * <li><code> getAccessibleStateSet()</code></li>
57 * <li><code> getLocale()</code></li>
58 * </ul> <p>
60 * @see com.sun.star.accessibility.XAccessibleContext
62 public class _XAccessibleContext extends MultiMethodTest {
63 private static final String className = "com.sun.star.accessibility.XAccessibleContext";
64 public XAccessibleContext oObj = null;
65 private int childCount = 0;
66 private XAccessible parent = null;
68 // temporary while accessibility package is in com.sun.star
69 protected String getTestedClassName() {
70 return className;
73 /**
74 * Calls the method and stores the number of children. <p>
75 * Has <b> OK </b> status if non-negative number rutrned.
77 public void _getAccessibleChildCount() {
78 childCount = oObj.getAccessibleChildCount();
79 log.println("" + childCount + " children found.");
80 tRes.tested("getAccessibleChildCount()", childCount > -1);
83 /**
84 * Tries to get every child and checks its parent. <p>
86 * Has <b> OK </b> status if parent of every child
87 * and the tested component are the same objects.
89 * The following method tests are to be completed successfully before :
90 * <ul>
91 * <li> <code> getAccessibleChildCount() </code> : to have a number of
92 * children </li>
93 * </ul>
95 public void _getAccessibleChild() {
96 requiredMethod("getAccessibleChildCount()");
98 log.println("testing 'getAccessibleChild()'...");
100 boolean bOK = true;
101 int counter = childCount;
103 if (childCount > 500) {
104 counter = 500;
107 for (int i = 0; i < counter; i++) {
108 try {
109 XAccessible ch = oObj.getAccessibleChild(i);
110 XAccessibleContext chAC = ch.getAccessibleContext();
112 log.println("## Child " + i + ": " +
113 chAC.getAccessibleDescription());
115 if (!AccessibilityTools.equals(chAC.getAccessibleParent()
116 .getAccessibleContext(),
117 oObj)) {
118 log.println("The parent of child and component " +
119 "itself differ.");
120 log.println("\tRole:");
121 log.println("Getting: " +
122 chAC.getAccessibleParent()
123 .getAccessibleContext()
124 .getAccessibleRole());
125 log.println("Expected: " + oObj.getAccessibleRole());
127 log.println("\tImplementationName:");
128 log.println("Getting: " +
129 util.utils.getImplName(
130 chAC.getAccessibleParent()
131 .getAccessibleContext()));
132 log.println("Expected: " + util.utils.getImplName(oObj));
134 log.println("\tAccessibleDescription:");
135 log.println("Getting(Description): " +
136 chAC.getAccessibleParent()
137 .getAccessibleContext()
138 .getAccessibleDescription());
139 log.println("Expected(Description): " +
140 oObj.getAccessibleDescription());
142 log.println("\tAccessibleName:");
143 log.println("Getting(Name): " +
144 chAC.getAccessibleParent()
145 .getAccessibleContext()
146 .getAccessibleName());
147 log.println("Expected(Name): " +
148 oObj.getAccessibleName());
150 log.println("\tChildCount:");
151 log.println("Getting: " +
152 chAC.getAccessibleParent()
153 .getAccessibleContext()
154 .getAccessibleChildCount());
155 log.println("Expected: " +
156 oObj.getAccessibleChildCount());
158 log.println("\tParentName:");
159 log.println("Getting (Name): " +
160 chAC.getAccessibleParent()
161 .getAccessibleContext()
162 .getAccessibleParent()
163 .getAccessibleContext()
164 .getAccessibleName());
165 log.println("Expected(Name): " +
166 oObj.getAccessibleParent()
167 .getAccessibleContext()
168 .getAccessibleName());
170 log.println("##");
171 bOK = false;
172 } else {
173 log.println("Role: " + chAC.getAccessibleRole());
174 log.println("Name: " + chAC.getAccessibleName());
175 log.println("IndexInParent: " +
176 chAC.getAccessibleIndexInParent());
177 log.println("ImplementationName: " +
178 util.utils.getImplName(chAC));
180 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
181 e.printStackTrace(log);
182 bOK = false;
186 tRes.tested("getAccessibleChild()", bOK);
190 * Just gets the parent. <p>
192 * Has <b> OK </b> status if parent is not null.
194 public void _getAccessibleParent() {
195 // assume that the component is not ROOT
196 parent = oObj.getAccessibleParent();
197 tRes.tested("getAccessibleParent()", parent != null);
201 * Retrieves the index of tested component in its parent.
202 * Then gets the parent's child by this index and compares
203 * it with tested component.<p>
205 * Has <b> OK </b> status if the parent's child and the tested
206 * component are the same objects.
208 * The following method tests are to be completed successfully before :
209 * <ul>
210 * <li> <code> getAccessibleParent() </code> : to have a parent </li>
211 * </ul>
213 public void _getAccessibleIndexInParent() {
214 requiredMethod("getAccessibleParent()");
216 boolean bOK = true;
217 int idx = oObj.getAccessibleIndexInParent();
219 XAccessibleContext parentAC = parent.getAccessibleContext();
221 try {
222 if (parentAC.getAccessibleChild(idx) == null) {
223 log.println("Parent has no child with this index");
224 bOK &= false;
225 } else {
226 bOK &= AccessibilityTools.equals(parentAC.getAccessibleChild(
227 idx)
228 .getAccessibleContext(),
229 oObj);
232 if (!bOK) {
233 log.println("Expected: " + util.utils.getImplName(oObj));
235 if (parentAC.getAccessibleChild(idx) != null) {
236 log.println("Getting: " +
237 util.utils.getImplName(
238 parentAC.getAccessibleChild(idx)
239 .getAccessibleContext()));
242 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
243 e.printStackTrace(log);
244 bOK = false;
247 tRes.tested("getAccessibleIndexInParent()", bOK);
251 * Get the accessible role of component. <p>
253 * Has <b> OK </b> status if non-negative number rutrned.
255 public void _getAccessibleRole() {
256 short role = oObj.getAccessibleRole();
257 log.println("The role is " + role);
258 tRes.tested("getAccessibleRole()", role > -1);
262 * Get the accessible name of the component. <p>
264 * Has <b> OK </b> status if the name has non-zero length.
266 public void _getAccessibleName() {
267 String name = oObj.getAccessibleName();
268 log.println("The name is '" + name + "'");
269 tRes.tested("getAccessibleName()", name != null);
273 * Get the accessible description of the component. <p>
275 * Has <b> OK </b> status if the description has non-zero length.
277 public void _getAccessibleDescription() {
278 String descr = oObj.getAccessibleDescription();
279 log.println("The description is '" + descr + "'");
280 tRes.tested("getAccessibleDescription()", descr != null);
284 * Just gets the set. <p>
286 * Has <b> OK </b> status if the set is not null.
288 public void _getAccessibleRelationSet() {
289 XAccessibleRelationSet set = oObj.getAccessibleRelationSet();
290 tRes.tested("getAccessibleRelationSet()", true);
294 * Just gets the set. <p>
296 * Has <b> OK </b> status if the set is not null.
298 public void _getAccessibleStateSet() {
299 XAccessibleStateSet set = oObj.getAccessibleStateSet();
300 boolean res = true;
301 String[] expectedStateNames = (String[]) tEnv.getObjRelation(
302 "expectedStateNames");
303 short[] expectedStates = (short[]) tEnv.getObjRelation(
304 "expectedStates");
306 if ((expectedStateNames != null) && (expectedStates != null)) {
307 res = checkStates(expectedStateNames, expectedStates, set);
308 } else {
309 res = set != null;
312 tRes.tested("getAccessibleStateSet()", res);
316 * Gets the locale. <p>
318 * Has <b> OK </b> status if <code>Country</code> and
319 * <code>Language</code> fields of locale structure
320 * are not empty.
322 public void _getLocale() {
323 Locale loc = null;
325 try {
326 loc = oObj.getLocale();
327 log.println("The locale is " + loc.Language + "," + loc.Country);
328 } catch (IllegalAccessibleComponentStateException e) {
329 e.printStackTrace(log);
332 tRes.tested("getLocale()",
333 (loc != null) && (loc.Language.length() > 0) &&
334 (loc.Country.length() > 0));
337 protected boolean checkStates(String[] expectedStateNames,
338 short[] expectedStates,
339 XAccessibleStateSet set) {
340 boolean works = true;
342 for (int k = 0; k < expectedStateNames.length; k++) {
343 boolean contains = set.contains(expectedStates[k]);
345 if (contains) {
346 log.println("Set contains " + expectedStateNames[k] +
347 " ... OK");
348 works &= true;
349 } else {
350 log.println("Set doesn't contain " + expectedStateNames[k] +
351 " ... FAILED");
352 works &= false;
356 return works;