Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / accessibility / _XAccessibleContext.java
blobcabf818af527802fdfc8e9b4a5993d917c3bbcab
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 @Override
57 protected String getTestedClassName() {
58 return className;
61 /**
62 * Calls the method and stores the number of children. <p>
63 * Has <b> OK </b> status if non-negative number rutrned.
65 public void _getAccessibleChildCount() {
66 childCount = oObj.getAccessibleChildCount();
67 log.println(childCount + " children found.");
68 tRes.tested("getAccessibleChildCount()", childCount > -1);
71 /**
72 * Tries to get every child and checks its parent. <p>
74 * Has <b> OK </b> status if parent of every child
75 * and the tested component are the same objects.
77 * The following method tests are to be completed successfully before :
78 * <ul>
79 * <li> <code> getAccessibleChildCount() </code> : to have a number of
80 * children </li>
81 * </ul>
83 public void _getAccessibleChild() {
84 requiredMethod("getAccessibleChildCount()");
86 log.println("testing 'getAccessibleChild()'...");
88 boolean bOK = true;
89 int counter = childCount;
91 if (childCount > 500) {
92 counter = 500;
95 for (int i = 0; i < counter; i++) {
96 try {
97 XAccessible ch = oObj.getAccessibleChild(i);
98 XAccessibleContext chAC = ch.getAccessibleContext();
100 log.println("## Child " + i + ": " +
101 chAC.getAccessibleDescription());
103 if (!AccessibilityTools.equals(chAC.getAccessibleParent()
104 .getAccessibleContext(),
105 oObj)) {
106 log.println("The parent of child and component " +
107 "itself differ.");
108 log.println("\tRole:");
109 log.println("Getting: " +
110 chAC.getAccessibleParent()
111 .getAccessibleContext()
112 .getAccessibleRole());
113 log.println("Expected: " + oObj.getAccessibleRole());
115 log.println("\tImplementationName:");
116 log.println("Getting: " +
117 util.utils.getImplName(
118 chAC.getAccessibleParent()
119 .getAccessibleContext()));
120 log.println("Expected: " + util.utils.getImplName(oObj));
122 log.println("\tAccessibleDescription:");
123 log.println("Getting(Description): " +
124 chAC.getAccessibleParent()
125 .getAccessibleContext()
126 .getAccessibleDescription());
127 log.println("Expected(Description): " +
128 oObj.getAccessibleDescription());
130 log.println("\tAccessibleName:");
131 log.println("Getting(Name): " +
132 chAC.getAccessibleParent()
133 .getAccessibleContext()
134 .getAccessibleName());
135 log.println("Expected(Name): " +
136 oObj.getAccessibleName());
138 log.println("\tChildCount:");
139 log.println("Getting: " +
140 chAC.getAccessibleParent()
141 .getAccessibleContext()
142 .getAccessibleChildCount());
143 log.println("Expected: " +
144 oObj.getAccessibleChildCount());
146 log.println("\tParentName:");
147 log.println("Getting (Name): " +
148 chAC.getAccessibleParent()
149 .getAccessibleContext()
150 .getAccessibleParent()
151 .getAccessibleContext()
152 .getAccessibleName());
153 log.println("Expected(Name): " +
154 oObj.getAccessibleParent()
155 .getAccessibleContext()
156 .getAccessibleName());
158 log.println("##");
159 bOK = false;
160 } else {
161 log.println("Role: " + chAC.getAccessibleRole());
162 log.println("Name: " + chAC.getAccessibleName());
163 log.println("IndexInParent: " +
164 chAC.getAccessibleIndexInParent());
165 log.println("ImplementationName: " +
166 util.utils.getImplName(chAC));
168 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
169 e.printStackTrace(log);
170 bOK = false;
174 tRes.tested("getAccessibleChild()", bOK);
178 * Just gets the parent. <p>
180 * Has <b> OK </b> status if parent is not null.
182 public void _getAccessibleParent() {
183 // assume that the component is not ROOT
184 parent = oObj.getAccessibleParent();
185 tRes.tested("getAccessibleParent()", parent != null);
189 * Retrieves the index of tested component in its parent.
190 * Then gets the parent's child by this index and compares
191 * it with tested component.<p>
193 * Has <b> OK </b> status if the parent's child and the tested
194 * component are the same objects.
196 * The following method tests are to be completed successfully before :
197 * <ul>
198 * <li> <code> getAccessibleParent() </code> : to have a parent </li>
199 * </ul>
201 public void _getAccessibleIndexInParent() {
202 requiredMethod("getAccessibleParent()");
204 boolean bOK = true;
205 int idx = oObj.getAccessibleIndexInParent();
207 XAccessibleContext parentAC = parent.getAccessibleContext();
209 try {
210 XAccessible child = parentAC.getAccessibleChild(idx);
211 XAccessibleContext childAC = null;
212 if (child == null) {
213 log.println("Parent has no child with this index");
214 bOK &= false;
215 } else {
216 childAC = child.getAccessibleContext();
217 bOK &= AccessibilityTools.equals(childAC, oObj);
220 if (!bOK) {
221 log.println("Expected: " + util.utils.getImplName(oObj));
223 if (childAC != null) {
224 log.println("Getting: " + util.utils.getImplName(childAC));
227 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
228 e.printStackTrace(log);
229 bOK = false;
232 tRes.tested("getAccessibleIndexInParent()", bOK);
236 * Get the accessible role of component. <p>
238 * Has <b> OK </b> status if non-negative number rutrned.
240 public void _getAccessibleRole() {
241 short role = oObj.getAccessibleRole();
242 log.println("The role is " + role);
243 tRes.tested("getAccessibleRole()", role > -1);
247 * Get the accessible name of the component. <p>
249 * Has <b> OK </b> status if the name has non-zero length.
251 public void _getAccessibleName() {
252 String name = oObj.getAccessibleName();
253 log.println("The name is '" + name + "'");
254 tRes.tested("getAccessibleName()", name != null);
258 * Get the accessible description of the component. <p>
260 * Has <b> OK </b> status if the description has non-zero length.
262 public void _getAccessibleDescription() {
263 String descr = oObj.getAccessibleDescription();
264 log.println("The description is '" + descr + "'");
265 tRes.tested("getAccessibleDescription()", descr != null);
269 * Just gets the set. <p>
271 * Has <b> OK </b> status if the set is not null.
273 public void _getAccessibleRelationSet() {
274 oObj.getAccessibleRelationSet();
275 tRes.tested("getAccessibleRelationSet()", true);
279 * Just gets the set. <p>
281 * Has <b> OK </b> status if the set is not null.
283 public void _getAccessibleStateSet() {
284 XAccessibleStateSet set = oObj.getAccessibleStateSet();
285 boolean res = true;
286 String[] expectedStateNames = (String[]) tEnv.getObjRelation(
287 "expectedStateNames");
288 short[] expectedStates = (short[]) tEnv.getObjRelation(
289 "expectedStates");
291 if ((expectedStateNames != null) && (expectedStates != null)) {
292 res = checkStates(expectedStateNames, expectedStates, set);
293 } else {
294 res = set != null;
297 tRes.tested("getAccessibleStateSet()", res);
301 * Gets the locale. <p>
303 * Has <b> OK </b> status if <code>Country</code> and
304 * <code>Language</code> fields of locale structure
305 * are not empty.
307 public void _getLocale() {
308 Locale loc = null;
310 try {
311 loc = oObj.getLocale();
312 log.println("The locale is " + loc.Language + "," + loc.Country);
313 } catch (IllegalAccessibleComponentStateException e) {
314 e.printStackTrace(log);
317 tRes.tested("getLocale()",
318 (loc != null) && (loc.Language.length() > 0));
321 protected boolean checkStates(String[] expectedStateNames,
322 short[] expectedStates,
323 XAccessibleStateSet set) {
324 boolean works = true;
326 for (int k = 0; k < expectedStateNames.length; k++) {
327 boolean contains = set.contains(expectedStates[k]);
329 if (contains) {
330 log.println("Set contains " + expectedStateNames[k] +
331 " ... OK");
332 works &= true;
333 } else {
334 log.println("Set doesn't contain " + expectedStateNames[k] +
335 " ... FAILED");
336 works &= false;
340 return works;