update credits
[LibreOffice.git] / qadevOOo / tests / java / ifc / accessibility / _XAccessibleContext.java
blob7ec0c584a8ccfc4167b30934acfe59ec87c10bac
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 .
18 package ifc.accessibility;
20 import com.sun.star.accessibility.IllegalAccessibleComponentStateException;
21 import com.sun.star.accessibility.XAccessible;
22 import com.sun.star.accessibility.XAccessibleContext;
23 import com.sun.star.accessibility.XAccessibleStateSet;
24 import com.sun.star.lang.Locale;
26 import lib.MultiMethodTest;
28 import util.AccessibilityTools;
31 /**
32 * Testing <code>com.sun.star.accessibility.XAccessibleContext</code>
33 * interface methods :
34 * <ul>
35 * <li><code> getAccessibleChildCount()</code></li>
36 * <li><code> getAccessibleChild()</code></li>
37 * <li><code> getAccessibleParent()</code></li>
38 * <li><code> getAccessibleIndexInParent()</code></li>
39 * <li><code> getAccessibleRole()</code></li>
40 * <li><code> getAccessibleDescription()</code></li>
41 * <li><code> getAccessibleName()</code></li>
42 * <li><code> getAccessibleRelationSet()</code></li>
43 * <li><code> getAccessibleStateSet()</code></li>
44 * <li><code> getLocale()</code></li>
45 * </ul> <p>
47 * @see com.sun.star.accessibility.XAccessibleContext
49 public class _XAccessibleContext extends MultiMethodTest {
50 private static final String className = "com.sun.star.accessibility.XAccessibleContext";
51 public XAccessibleContext oObj = null;
52 private int childCount = 0;
53 private XAccessible parent = null;
55 // temporary while accessibility package is in com.sun.star
56 protected String getTestedClassName() {
57 return className;
60 /**
61 * Calls the method and stores the number of children. <p>
62 * Has <b> OK </b> status if non-negative number rutrned.
64 public void _getAccessibleChildCount() {
65 childCount = oObj.getAccessibleChildCount();
66 log.println("" + childCount + " children found.");
67 tRes.tested("getAccessibleChildCount()", childCount > -1);
70 /**
71 * Tries to get every child and checks its parent. <p>
73 * Has <b> OK </b> status if parent of every child
74 * and the tested component are the same objects.
76 * The following method tests are to be completed successfully before :
77 * <ul>
78 * <li> <code> getAccessibleChildCount() </code> : to have a number of
79 * children </li>
80 * </ul>
82 public void _getAccessibleChild() {
83 requiredMethod("getAccessibleChildCount()");
85 log.println("testing 'getAccessibleChild()'...");
87 boolean bOK = true;
88 int counter = childCount;
90 if (childCount > 500) {
91 counter = 500;
94 for (int i = 0; i < counter; i++) {
95 try {
96 XAccessible ch = oObj.getAccessibleChild(i);
97 XAccessibleContext chAC = ch.getAccessibleContext();
99 log.println("## Child " + i + ": " +
100 chAC.getAccessibleDescription());
102 if (!AccessibilityTools.equals(chAC.getAccessibleParent()
103 .getAccessibleContext(),
104 oObj)) {
105 log.println("The parent of child and component " +
106 "itself differ.");
107 log.println("\tRole:");
108 log.println("Getting: " +
109 chAC.getAccessibleParent()
110 .getAccessibleContext()
111 .getAccessibleRole());
112 log.println("Expected: " + oObj.getAccessibleRole());
114 log.println("\tImplementationName:");
115 log.println("Getting: " +
116 util.utils.getImplName(
117 chAC.getAccessibleParent()
118 .getAccessibleContext()));
119 log.println("Expected: " + util.utils.getImplName(oObj));
121 log.println("\tAccessibleDescription:");
122 log.println("Getting(Description): " +
123 chAC.getAccessibleParent()
124 .getAccessibleContext()
125 .getAccessibleDescription());
126 log.println("Expected(Description): " +
127 oObj.getAccessibleDescription());
129 log.println("\tAccessibleName:");
130 log.println("Getting(Name): " +
131 chAC.getAccessibleParent()
132 .getAccessibleContext()
133 .getAccessibleName());
134 log.println("Expected(Name): " +
135 oObj.getAccessibleName());
137 log.println("\tChildCount:");
138 log.println("Getting: " +
139 chAC.getAccessibleParent()
140 .getAccessibleContext()
141 .getAccessibleChildCount());
142 log.println("Expected: " +
143 oObj.getAccessibleChildCount());
145 log.println("\tParentName:");
146 log.println("Getting (Name): " +
147 chAC.getAccessibleParent()
148 .getAccessibleContext()
149 .getAccessibleParent()
150 .getAccessibleContext()
151 .getAccessibleName());
152 log.println("Expected(Name): " +
153 oObj.getAccessibleParent()
154 .getAccessibleContext()
155 .getAccessibleName());
157 log.println("##");
158 bOK = false;
159 } else {
160 log.println("Role: " + chAC.getAccessibleRole());
161 log.println("Name: " + chAC.getAccessibleName());
162 log.println("IndexInParent: " +
163 chAC.getAccessibleIndexInParent());
164 log.println("ImplementationName: " +
165 util.utils.getImplName(chAC));
167 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
168 e.printStackTrace(log);
169 bOK = false;
173 tRes.tested("getAccessibleChild()", bOK);
177 * Just gets the parent. <p>
179 * Has <b> OK </b> status if parent is not null.
181 public void _getAccessibleParent() {
182 // assume that the component is not ROOT
183 parent = oObj.getAccessibleParent();
184 tRes.tested("getAccessibleParent()", parent != null);
188 * Retrieves the index of tested component in its parent.
189 * Then gets the parent's child by this index and compares
190 * it with tested component.<p>
192 * Has <b> OK </b> status if the parent's child and the tested
193 * component are the same objects.
195 * The following method tests are to be completed successfully before :
196 * <ul>
197 * <li> <code> getAccessibleParent() </code> : to have a parent </li>
198 * </ul>
200 public void _getAccessibleIndexInParent() {
201 requiredMethod("getAccessibleParent()");
203 boolean bOK = true;
204 int idx = oObj.getAccessibleIndexInParent();
206 XAccessibleContext parentAC = parent.getAccessibleContext();
208 try {
209 if (parentAC.getAccessibleChild(idx) == null) {
210 log.println("Parent has no child with this index");
211 bOK &= false;
212 } else {
213 bOK &= AccessibilityTools.equals(parentAC.getAccessibleChild(
214 idx)
215 .getAccessibleContext(),
216 oObj);
219 if (!bOK) {
220 log.println("Expected: " + util.utils.getImplName(oObj));
222 if (parentAC.getAccessibleChild(idx) != null) {
223 log.println("Getting: " +
224 util.utils.getImplName(
225 parentAC.getAccessibleChild(idx)
226 .getAccessibleContext()));
229 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
230 e.printStackTrace(log);
231 bOK = false;
234 tRes.tested("getAccessibleIndexInParent()", bOK);
238 * Get the accessible role of component. <p>
240 * Has <b> OK </b> status if non-negative number rutrned.
242 public void _getAccessibleRole() {
243 short role = oObj.getAccessibleRole();
244 log.println("The role is " + role);
245 tRes.tested("getAccessibleRole()", role > -1);
249 * Get the accessible name of the component. <p>
251 * Has <b> OK </b> status if the name has non-zero length.
253 public void _getAccessibleName() {
254 String name = oObj.getAccessibleName();
255 log.println("The name is '" + name + "'");
256 tRes.tested("getAccessibleName()", name != null);
260 * Get the accessible description of the component. <p>
262 * Has <b> OK </b> status if the description has non-zero length.
264 public void _getAccessibleDescription() {
265 String descr = oObj.getAccessibleDescription();
266 log.println("The description is '" + descr + "'");
267 tRes.tested("getAccessibleDescription()", descr != null);
271 * Just gets the set. <p>
273 * Has <b> OK </b> status if the set is not null.
275 public void _getAccessibleRelationSet() {
276 oObj.getAccessibleRelationSet();
277 tRes.tested("getAccessibleRelationSet()", true);
281 * Just gets the set. <p>
283 * Has <b> OK </b> status if the set is not null.
285 public void _getAccessibleStateSet() {
286 XAccessibleStateSet set = oObj.getAccessibleStateSet();
287 boolean res = true;
288 String[] expectedStateNames = (String[]) tEnv.getObjRelation(
289 "expectedStateNames");
290 short[] expectedStates = (short[]) tEnv.getObjRelation(
291 "expectedStates");
293 if ((expectedStateNames != null) && (expectedStates != null)) {
294 res = checkStates(expectedStateNames, expectedStates, set);
295 } else {
296 res = set != null;
299 tRes.tested("getAccessibleStateSet()", res);
303 * Gets the locale. <p>
305 * Has <b> OK </b> status if <code>Country</code> and
306 * <code>Language</code> fields of locale structure
307 * are not empty.
309 public void _getLocale() {
310 Locale loc = null;
312 try {
313 loc = oObj.getLocale();
314 log.println("The locale is " + loc.Language + "," + loc.Country);
315 } catch (IllegalAccessibleComponentStateException e) {
316 e.printStackTrace(log);
319 tRes.tested("getLocale()",
320 (loc != null) && (loc.Language.length() > 0));
323 protected boolean checkStates(String[] expectedStateNames,
324 short[] expectedStates,
325 XAccessibleStateSet set) {
326 boolean works = true;
328 for (int k = 0; k < expectedStateNames.length; k++) {
329 boolean contains = set.contains(expectedStates[k]);
331 if (contains) {
332 log.println("Set contains " + expectedStateNames[k] +
333 " ... OK");
334 works &= true;
335 } else {
336 log.println("Set doesn't contain " + expectedStateNames[k] +
337 " ... FAILED");
338 works &= false;
342 return works;