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
;
32 * Testing <code>com.sun.star.accessibility.XAccessibleContext</code>
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>
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() {
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);
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 :
78 * <li> <code> getAccessibleChildCount() </code> : to have a number of
82 public void _getAccessibleChild() {
83 requiredMethod("getAccessibleChildCount()");
85 log
.println("testing 'getAccessibleChild()'...");
88 int counter
= childCount
;
90 if (childCount
> 500) {
94 for (int i
= 0; i
< counter
; i
++) {
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(),
105 log
.println("The parent of child and component " +
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());
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
);
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 :
197 * <li> <code> getAccessibleParent() </code> : to have a parent </li>
200 public void _getAccessibleIndexInParent() {
201 requiredMethod("getAccessibleParent()");
204 int idx
= oObj
.getAccessibleIndexInParent();
206 XAccessibleContext parentAC
= parent
.getAccessibleContext();
209 if (parentAC
.getAccessibleChild(idx
) == null) {
210 log
.println("Parent has no child with this index");
213 bOK
&= AccessibilityTools
.equals(parentAC
.getAccessibleChild(
215 .getAccessibleContext(),
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
);
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();
288 String
[] expectedStateNames
= (String
[]) tEnv
.getObjRelation(
289 "expectedStateNames");
290 short[] expectedStates
= (short[]) tEnv
.getObjRelation(
293 if ((expectedStateNames
!= null) && (expectedStates
!= null)) {
294 res
= checkStates(expectedStateNames
, expectedStates
, set
);
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
309 public void _getLocale() {
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
]);
332 log
.println("Set contains " + expectedStateNames
[k
] +
336 log
.println("Set doesn't contain " + expectedStateNames
[k
] +