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 java
.util
.ArrayList
;
21 import lib
.MultiMethodTest
;
23 import com
.sun
.star
.accessibility
.XAccessible
;
24 import com
.sun
.star
.accessibility
.XAccessibleComponent
;
25 import com
.sun
.star
.accessibility
.XAccessibleContext
;
26 import com
.sun
.star
.awt
.Point
;
27 import com
.sun
.star
.awt
.Rectangle
;
28 import com
.sun
.star
.awt
.Size
;
29 import com
.sun
.star
.uno
.UnoRuntime
;
33 * Testing <code>com.sun.star.accessibility.XAccessibleComponent</code>
36 * <li><code> containsPoint()</code></li>
37 * <li><code> getAccessibleAtPoint()</code></li>
38 * <li><code> getBounds()</code></li>
39 * <li><code> getLocation()</code></li>
40 * <li><code> getLocationOnScreen()</code></li>
41 * <li><code> getSize()</code></li>
42 * <li><code> grabFocus()</code></li>
43 * <li><code> getAccessibleKeyBinding()</code></li>
46 * @see com.sun.star.accessibility.XAccessibleComponent
48 public class _XAccessibleComponent
extends MultiMethodTest
{
50 public XAccessibleComponent oObj
= null;
51 private final ArrayList
<Rectangle
> KnownBounds
= new ArrayList
<Rectangle
>();
55 * First checks 4 inner bounds (upper, lower, left and right)
56 * of component bounding box to contain
57 * at least one point of the component. Second 4 outer bounds
58 * are checked to not contain any component points.<p>
60 * Has <b> OK </b> status if inner bounds contain component points
61 * and outer bounds don't contain any component points. <p>
63 * The following method tests are to be completed successfully before :
65 * <li> <code> getBounds() </code> : to have size of a component.</li>
68 public void _containsPoint() {
69 Rectangle bounds
= oObj
.getBounds();
71 boolean result
= true;
75 while (!oObj
.containsPoint(new Point(curX
, 0)) &&
76 (curX
< bounds
.Width
)) {
80 if (curX
< bounds
.Width
) {
81 log
.println("Upper bound of box containsPoint point (" + curX
+
85 "Upper bound of box containsPoint no component points - FAILED");
91 while (!oObj
.containsPoint(new Point(curX
, bounds
.Height
- 1)) &&
92 (curX
< bounds
.Width
)) {
93 log
.println("containsPoint returns false for (" + curX
+ "," +
98 if (curX
< bounds
.Width
) {
99 log
.println("Lower bound of box containsPoint point (" + curX
+
100 "," + (bounds
.Height
- 1) + ") - OK");
103 "Lower bound of box containsPoint no component points - FAILED");
109 while (!oObj
.containsPoint(new Point(0, curY
)) &&
110 (curY
< bounds
.Height
)) {
114 if (curY
< bounds
.Height
) {
115 log
.println("Left bound of box containsPoint point (0," + curY
+
119 "Left bound of box containsPoint no component points - FAILED");
125 while (!oObj
.containsPoint(new Point(bounds
.Width
- 1, curY
)) &&
126 (curY
< bounds
.Height
)) {
130 if (curY
< bounds
.Height
) {
131 log
.println("Right bound of box containsPoint point (" +
132 (bounds
.Width
- 1) + "," + curY
+ ") - OK");
135 "Right bound of box containsPoint no component points - FAILED");
139 boolean locRes
= true;
141 for (int x
= -1; x
<= bounds
.Width
; x
++) {
142 if (oObj
.containsPoint(new Point(x
, -1))) {
144 "Outer upper and lower bounds CONTAIN some component point"
145 + " (" + x
+ ", -1) - FAILED");
149 if (oObj
.containsPoint(new Point(x
, bounds
.Height
+ bounds
.Y
))) {
151 "Outer upper and lower bounds CONTAIN some component point"
152 + " (" + x
+ ", " + (bounds
.Height
+ bounds
.Y
)
160 log
.println("Outer upper and lower bounds contain no component " +
168 for (int y
= -1; y
<= bounds
.Height
; y
++) {
169 if (oObj
.containsPoint(new Point(-1, y
))) {
171 "Outer left and right bounds CONTAIN some component point"
172 + " (-1, " + y
+ ") - FAILED");
176 if (oObj
.containsPoint(new Point(bounds
.X
+ bounds
.Width
, y
))) {
178 "Outer left and right bounds CONTAIN some component point"
179 + " (" + (bounds
.X
+ bounds
.Width
) + ", " + y
+ ") - FAILED");
186 log
.println("Outer left and right bounds contain no component " +
192 tRes
.tested("containsPoint()", result
);
196 * Iterates through all children which implement
197 * <code>XAccessibleComponent</code> (if they exist) determines their
198 * boundaries and tries to get each child by <code>getAccessibleAtPoint</code>
199 * passing point which belongs to the child.
200 * Also the point is checked which doesn't belong to child boundary
203 * Has <b> OK </b> status if in the first cases the right children
204 * are returned, and in the second <code>null</code> or
205 * another child is returned.
207 public void _getAccessibleAtPoint() {
208 boolean result
= true;
209 XAccessibleComponent
[] children
= getChildrenComponents();
211 if (children
.length
== 0) {
212 log
.println("There are no children supporting XAccessibleComponent");
213 tRes
.tested("getAccessibleAtPoint()", result
);
217 for (int i
= 0; i
< children
.length
; i
++) {
218 Rectangle chBnd
= children
[i
].getBounds();
224 log
.println("Checking child with bounds " + "(" + chBnd
.X
+
225 "," + chBnd
.Y
+ "),(" + chBnd
.Width
+ "," +
226 chBnd
.Height
+ "): " +
227 util
.AccessibilityTools
.accessibleToString(
230 XAccessibleContext xAc
= UnoRuntime
.queryInterface(
231 XAccessibleContext
.class,
234 boolean MightBeCovered
= false;
235 boolean isShowing
= (xAc
.getAccessibleStateSet() &
236 com
.sun
.star
.accessibility
.AccessibleStateType
.SHOWING
) != 0;
237 log
.println("\tStateType containsPoint SHOWING: " +
241 log
.println("Child is invisible - OK");
245 log
.println("finding the point which lies on the component");
247 int curX
= chBnd
.Width
/ 2;
248 int curY
= chBnd
.Height
/ 2;
250 while (!children
[i
].containsPoint(new Point(curX
, curY
)) &&
251 (curX
> 0) && (curY
> 0)) {
256 if (curX
== chBnd
.Width
) {
257 log
.println("Couldn't find a point with containsPoint");
262 // trying the point laying on child
263 XAccessible xAcc
= oObj
.getAccessibleAtPoint(
264 new Point(chBnd
.X
+ curX
,
268 Point p
= new Point(chBnd
.X
+ curX
,chBnd
.Y
+ curY
);
272 "Child might be covered by another and can't be reached");
273 MightBeCovered
= true;
276 KnownBounds
.add(chBnd
);
279 log
.println("The child not found at point (" +
280 (chBnd
.X
+ curX
) + "," + (chBnd
.Y
+ curY
) +
285 XAccessible xAccCh
= UnoRuntime
.queryInterface(
288 XAccessibleContext xAccC
= UnoRuntime
.queryInterface(
289 XAccessibleContext
.class,
291 log
.println("Child found at point (" + (chBnd
.X
+ curX
) +
292 "," + (chBnd
.Y
+ curY
) + ") - OK");
299 if (xAccCh
!= null) {
300 res
= util
.AccessibilityTools
.equals(xAccCh
, xAcc
);
301 expIndex
= xAccCh
.getAccessibleContext()
302 .getAccessibleIndexInParent();
303 expName
= xAccCh
.getAccessibleContext()
304 .getAccessibleName();
305 expDesc
= xAccCh
.getAccessibleContext()
306 .getAccessibleDescription();
308 res
= xAccC
.getAccessibleName()
309 .equals(xAcc
.getAccessibleContext()
310 .getAccessibleName());
311 expIndex
= xAccC
.getAccessibleIndexInParent();
312 expName
= xAccC
.getAccessibleName();
313 expDesc
= xAccC
.getAccessibleDescription();
317 long gotIndex
= xAcc
.getAccessibleContext()
318 .getAccessibleIndexInParent();
320 if (expIndex
< gotIndex
) {
321 log
.println("The children found is not the same");
322 log
.println("The expected child " + expName
);
323 log
.print("is hidden behind the found Child ");
324 log
.println(xAcc
.getAccessibleContext()
325 .getAccessibleName() + " - OK");
328 "The children found is not the same");
329 log
.println("Expected: " + expName
);
330 log
.println("Description: " + expDesc
);
331 log
.println("Found: " +
332 xAcc
.getAccessibleContext()
333 .getAccessibleName());
334 log
.println("Description: " +
335 xAcc
.getAccessibleContext()
336 .getAccessibleDescription());
337 if (MightBeCovered
) {
338 log
.println("... Child is covered by another - OK");
341 "(xAccCh==null: " + (xAccCh
== null) + "; expIndex: " + expIndex
342 + "; gotIndex: " + gotIndex
+ ")");
343 log
.println("... FAILED");
352 // trying the point NOT laying on child
353 xAcc
= oObj
.getAccessibleAtPoint(
354 new Point(chBnd
.X
- 1, chBnd
.Y
- 1));
357 log
.println("No children found at point (" +
358 (chBnd
.X
- 1) + "," + (chBnd
.Y
- 1) +
362 XAccessible xAccCh
= UnoRuntime
.queryInterface(
365 boolean res
= util
.AccessibilityTools
.equals(xAccCh
, xAcc
);
368 log
.println("The same child found outside " +
369 "its bounds at (" + (chBnd
.X
- 1) + "," +
370 (chBnd
.Y
- 1) + ") - FAILED");
376 tRes
.tested("getAccessibleAtPoint()", result
);
380 * Retrieves the component bounds and discards it. <p>
382 * Has <b> OK </b> status if boundary position (x,y) is not negative
383 * and size (Width, Height) is greater than 0.
385 public void _getBounds() {
386 boolean result
= true;
388 Rectangle bounds
= oObj
.getBounds();
389 result
&= ((bounds
!= null) && (bounds
.X
>= 0) && (bounds
.Y
>= 0) && (bounds
.Width
> 0) && (bounds
.Height
> 0));
391 log
.println("Bounds = " +
393 ?
("(" + bounds
.X
+ "," + bounds
.Y
+ "),(" +
394 bounds
.Width
+ "," + bounds
.Height
+ ")") : "null"));
396 tRes
.tested("getBounds()", result
);
400 * Gets the location. <p>
402 * Has <b> OK </b> status if the location is the same as location
403 * of boundary obtained by <code>getBounds()</code> method.
405 public void _getLocation() {
406 Rectangle bounds
= oObj
.getBounds();
407 Point loc
= oObj
.getLocation();
408 boolean result
= loc
.X
== bounds
.X
&& loc
.Y
== bounds
.Y
;
410 "loc.X=" + loc
.X
+ " vs. bounds.X=" + bounds
.X
+ ", loc.Y="
411 + loc
.Y
+ " vs. bounds.Y=" + bounds
.Y
);
412 tRes
.tested("getLocation()", result
);
416 * Get the screen location of the component and its parent
417 * (if it exists and supports <code>XAccessibleComponent</code>). <p>
419 * Has <b> OK </b> status if component screen location equals
420 * to screen location of its parent plus location of the component
421 * relative to the parent. <p>
423 public void _getLocationOnScreen() {
424 XAccessibleComponent parent
= getParentComponent();
426 boolean result
= true;
427 Rectangle bounds
= oObj
.getBounds();
428 Point loc
= oObj
.getLocationOnScreen();
429 log
.println("Location is (" + loc
.X
+ "," + loc
.Y
+ ")");
431 if (parent
!= null) {
432 Point parLoc
= parent
.getLocationOnScreen();
433 log
.println("Parent location is (" + parLoc
.X
+ "," + parLoc
.Y
+
436 result
&= ((parLoc
.X
+ bounds
.X
) == loc
.X
);
437 result
&= ((parLoc
.Y
+ bounds
.Y
) == loc
.Y
);
440 tRes
.tested("getLocationOnScreen()", result
);
444 * Obtains the size of the component. <p>
446 * Has <b> OK </b> status if the size is the same as in bounds. <p>
448 public void _getSize() {
449 requiredMethod("getBounds()");
451 boolean result
= true;
452 Rectangle bounds
= oObj
.getBounds();
453 Size size
= oObj
.getSize();
455 result
&= (size
.Width
== bounds
.Width
);
456 result
&= (size
.Height
== bounds
.Height
);
458 tRes
.tested("getSize()", result
);
462 * Just calls the method. <p>
464 * Has <b> OK </b> status if no runtime exceptions occurred.
466 public void _grabFocus() {
467 boolean result
= true;
470 tRes
.tested("grabFocus()", result
);
474 * Retrieves all children (not more than 50) of the current
475 * component which support <code>XAccessibleComponent</code>.
477 * @return The array of children. Empty array returned if
478 * such children were not found or some error occurred.
480 private XAccessibleComponent
[] getChildrenComponents() {
481 XAccessible xAcc
= UnoRuntime
.queryInterface(
482 XAccessible
.class, oObj
);
485 log
.println("Component doesn't support XAccessible.");
487 return new XAccessibleComponent
[0];
490 XAccessibleContext xAccCon
= xAcc
.getAccessibleContext();
491 long cnt
= xAccCon
.getAccessibleChildCount();
493 // for cases when too many children exist checking only first 50
498 ArrayList
<XAccessibleComponent
> childComp
= new ArrayList
<XAccessibleComponent
>();
500 for (long i
= 0; i
< cnt
; i
++) {
502 XAccessible child
= xAccCon
.getAccessibleChild(i
);
503 XAccessibleContext xAccConCh
= child
.getAccessibleContext();
504 XAccessibleComponent xChAccComp
= UnoRuntime
.queryInterface(
505 XAccessibleComponent
.class,
508 if (xChAccComp
!= null) {
509 childComp
.add(xChAccComp
);
511 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
515 return childComp
.toArray(
516 new XAccessibleComponent
[childComp
.size()]);
520 * Gets the parent of the current component which support
521 * <code>XAccessibleComponent</code>.
523 * @return The parent or <code>null</code> if the component
524 * has no parent or some errors occurred.
526 private XAccessibleComponent
getParentComponent() {
527 XAccessible xAcc
= UnoRuntime
.queryInterface(
528 XAccessible
.class, oObj
);
531 log
.println("Component doesn't support XAccessible.");
536 XAccessibleContext xAccCon
= xAcc
.getAccessibleContext();
537 XAccessible xAccPar
= xAccCon
.getAccessibleParent();
539 if (xAccPar
== null) {
540 log
.println("Component has no accessible parent.");
545 XAccessibleContext xAccConPar
= xAccPar
.getAccessibleContext();
546 XAccessibleComponent parent
= UnoRuntime
.queryInterface(
547 XAccessibleComponent
.class,
550 if (parent
== null) {
552 "Accessible parent doesn't support XAccessibleComponent");
561 * Just calls the method.
563 public void _getForeground() {
564 int forColor
= oObj
.getForeground();
565 log
.println("getForeground(): " + forColor
);
566 tRes
.tested("getForeground()", true);
570 * Just calls the method.
572 public void _getBackground() {
573 int backColor
= oObj
.getBackground();
574 log
.println("getBackground(): " + backColor
);
575 tRes
.tested("getBackground()", true);
579 * Restores initial component text.
582 protected void after() {
583 if (tEnv
.getObjRelation("Destroy") != null) {
584 disposeEnvironment();
588 private boolean isCovered(Point p
) {
589 int elements
= KnownBounds
.size();
590 boolean Covered
= false;
591 for (int k
=0;k
<elements
;k
++) {
592 Rectangle known
= KnownBounds
.get(k
);
593 Covered
= (known
.X
< p
.X
);
594 Covered
&= (known
.Y
< p
.Y
);
595 Covered
&= (p
.Y
< known
.Y
+known
.Height
);
596 Covered
&= (p
.X
< known
.X
+known
.Width
);