tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / accessibility / _XAccessibleContext.java
blob8ce5e16478553814575e11a75142bd5f783c5a3f
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.lang.Locale;
25 import lib.MultiMethodTest;
27 import util.AccessibilityTools;
30 /**
31 * Testing <code>com.sun.star.accessibility.XAccessibleContext</code>
32 * interface methods :
33 * <ul>
34 * <li><code> getAccessibleChildCount()</code></li>
35 * <li><code> getAccessibleChild()</code></li>
36 * <li><code> getAccessibleParent()</code></li>
37 * <li><code> getAccessibleIndexInParent()</code></li>
38 * <li><code> getAccessibleRole()</code></li>
39 * <li><code> getAccessibleDescription()</code></li>
40 * <li><code> getAccessibleName()</code></li>
41 * <li><code> getAccessibleRelationSet()</code></li>
42 * <li><code> getAccessibleStateSet()</code></li>
43 * <li><code> getLocale()</code></li>
44 * </ul> <p>
46 * @see com.sun.star.accessibility.XAccessibleContext
48 public class _XAccessibleContext extends MultiMethodTest {
49 private static final String className = "com.sun.star.accessibility.XAccessibleContext";
50 public XAccessibleContext oObj = null;
51 private long childCount = 0;
52 private XAccessible parent = null;
54 // temporary while accessibility package is in com.sun.star
55 @Override
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 long counter = childCount;
90 if (childCount > 500) {
91 counter = 500;
94 for (long 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 long idx = oObj.getAccessibleIndexInParent();
206 XAccessibleContext parentAC = parent.getAccessibleContext();
208 try {
209 XAccessible child = parentAC.getAccessibleChild(idx);
210 XAccessibleContext childAC = null;
211 if (child == null) {
212 log.println("Parent has no child with this index");
213 bOK &= false;
214 } else {
215 childAC = child.getAccessibleContext();
216 bOK &= AccessibilityTools.equals(childAC, oObj);
219 if (!bOK) {
220 log.println("Expected: " + util.utils.getImplName(oObj));
222 if (childAC != null) {
223 log.println("Getting: " + util.utils.getImplName(childAC));
226 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
227 e.printStackTrace(log);
228 bOK = false;
231 tRes.tested("getAccessibleIndexInParent()", bOK);
235 * Get the accessible role of component. <p>
237 * Has <b> OK </b> status if non-negative number rutrned.
239 public void _getAccessibleRole() {
240 short role = oObj.getAccessibleRole();
241 log.println("The role is " + role);
242 tRes.tested("getAccessibleRole()", role > -1);
246 * Get the accessible name of the component. <p>
248 * Has <b> OK </b> status if the name has non-zero length.
250 public void _getAccessibleName() {
251 String name = oObj.getAccessibleName();
252 log.println("The name is '" + name + "'");
253 tRes.tested("getAccessibleName()", name != null);
257 * Get the accessible description of the component. <p>
259 * Has <b> OK </b> status if the description has non-zero length.
261 public void _getAccessibleDescription() {
262 String descr = oObj.getAccessibleDescription();
263 log.println("The description is '" + descr + "'");
264 tRes.tested("getAccessibleDescription()", descr != null);
268 * Just gets the set. <p>
270 * Has <b> OK </b> status if the set is not null.
272 public void _getAccessibleRelationSet() {
273 oObj.getAccessibleRelationSet();
274 tRes.tested("getAccessibleRelationSet()", true);
278 * Just gets the set. <p>
280 * Has <b> OK </b> status if the set is not null.
282 public void _getAccessibleStateSet() {
283 long set = oObj.getAccessibleStateSet();
284 boolean res = true;
285 String[] expectedStateNames = (String[]) tEnv.getObjRelation(
286 "expectedStateNames");
287 long[] expectedStates = (long[]) tEnv.getObjRelation(
288 "expectedStates");
290 if ((expectedStateNames != null) && (expectedStates != null)) {
291 res = checkStates(expectedStateNames, expectedStates, set);
294 tRes.tested("getAccessibleStateSet()", res);
298 * Gets the locale. <p>
300 * Has <b> OK </b> status if <code>Country</code> and
301 * <code>Language</code> fields of locale structure
302 * are not empty.
304 public void _getLocale() {
305 Locale loc = null;
307 try {
308 loc = oObj.getLocale();
309 log.println("The locale is " + loc.Language + "," + loc.Country);
310 } catch (IllegalAccessibleComponentStateException e) {
311 e.printStackTrace(log);
314 tRes.tested("getLocale()",
315 (loc != null) && (loc.Language.length() > 0));
318 protected boolean checkStates(String[] expectedStateNames,
319 long[] expectedStates,
320 long set) {
321 boolean works = true;
323 for (int k = 0; k < expectedStateNames.length; k++) {
324 boolean contains = (set & expectedStates[k]) != 0;
326 if (contains) {
327 log.println("Set contains " + expectedStateNames[k] +
328 " ... OK");
329 works &= true;
330 } else {
331 log.println("Set doesn't contain " + expectedStateNames[k] +
332 " ... FAILED");
333 works &= false;
337 return works;