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 Rectangle bounds
= null;
52 private ArrayList
<Rectangle
> KnownBounds
= new ArrayList
<Rectangle
>();
56 * First checks 4 inner bounds (upper, lower, left and right)
57 * of component bounding box to contain
58 * at least one point of the component. Second 4 outer bounds
59 * are checked to not contain any component points.<p>
61 * Has <b> OK </b> status if inner bounds contain component points
62 * and outer bounds don't contain any component points. <p>
64 * The following method tests are to be completed successfully before :
66 * <li> <code> getBounds() </code> : to have size of a component.</li>
69 public void _containsPoint() {
70 requiredMethod("getBounds()");
72 boolean result
= true;
76 //while (!oObj.containsPoint(new Point(curX, bounds.Y)) && curX < bounds.Width+bounds.X) {
77 while (!oObj
.containsPoint(new Point(curX
, 0)) &&
78 (curX
< bounds
.Width
)) {
82 //if ((bounds.X <= curX) && (curX < bounds.Width+bounds.X)) {
83 if (curX
< bounds
.Width
) {
84 log
.println("Upper bound of box containsPoint point (" + curX
+
88 "Upper bound of box containsPoint no component points - FAILED");
94 //while (!oObj.containsPoint(new Point(curX, bounds.Y+bounds.Height - 1))
95 while (!oObj
.containsPoint(new Point(curX
, bounds
.Height
- 1)) &&
96 (curX
< bounds
.Width
)) {
97 log
.println("containsPoint returns false for (" + curX
+ "," +
102 //if ((bounds.X <= curX) && (curX < bounds.Width+bounds.X)) {
103 if (curX
< bounds
.Width
) {
104 log
.println("Lower bound of box containsPoint point (" + curX
+
105 "," + (bounds
.Height
- 1) + ") - OK");
108 "Lower bound of box containsPoint no component points - FAILED");
114 //while (!oObj.containsPoint(new Point(bounds.X, curY)) && curY < bounds.Height+bounds.Y) {
115 while (!oObj
.containsPoint(new Point(0, curY
)) &&
116 (curY
< bounds
.Height
)) {
120 //if ((bounds.Y <= curY) && (curY < bounds.Height+bounds.Y)) {
121 if (curY
< bounds
.Height
) {
122 log
.println("Left bound of box containsPoint point (0," + curY
+
126 "Left bound of box containsPoint no component points - FAILED");
132 //while (!oObj.containsPoint(new Point(bounds.X+bounds.Width - 1, curY))
133 // && curY < bounds.Height+bounds.Y) {
134 while (!oObj
.containsPoint(new Point(bounds
.Width
- 1, curY
)) &&
135 (curY
< bounds
.Height
)) {
139 //if ((bounds.Y <= curY) && (curY < bounds.Height + bounds.Y)) {
140 if (curY
< bounds
.Height
) {
141 log
.println("Right bound of box containsPoint point (" +
142 (bounds
.Width
- 1) + "," + curY
+ ") - OK");
145 "Right bound of box containsPoint no component points - FAILED");
149 boolean locRes
= true;
151 for (int x
= -1; x
<= bounds
.Width
; x
++) {
152 if (oObj
.containsPoint(new Point(x
, -1))) {
154 "Outer upper and lower bounds CONTAIN some component point"
155 + " (" + x
+ ", -1) - FAILED");
159 if (oObj
.containsPoint(new Point(x
, bounds
.Height
+ bounds
.Y
))) {
161 "Outer upper and lower bounds CONTAIN some component point"
162 + " (" + x
+ ", " + bounds
.Height
+ bounds
.Y
170 log
.println("Outer upper and lower bounds contain no component " +
178 for (int y
= -1; y
<= bounds
.Height
; y
++) {
179 if (oObj
.containsPoint(new Point(-1, y
))) {
181 "Outer left and right bounds CONTAIN some component point"
182 + " (-1, " + y
+ ") - FAILED");
186 if (oObj
.containsPoint(new Point(bounds
.X
+ bounds
.Width
, y
))) {
188 "Outer left and right bounds CONTAIN some component point"
189 + " (" + bounds
.X
+ bounds
.Width
+ ", " + y
+ ") - FAILED");
196 log
.println("Outer left and right bounds contain no component " +
202 tRes
.tested("containsPoint()", result
);
206 * Iterates through all children which implement
207 * <code>XAccessibleComponent</code> (if they exist) determines their
208 * boundaries and tries to get each child by <code>getAccessibleAtPoint</code>
209 * passing point which belongs to the child.
210 * Also the point is checked which doesn't belong to child boundary
213 * Has <b> OK </b> status if in the first cases the right children
214 * are returned, and in the second <code>null</code> or
215 * another child is returned.
217 public void _getAccessibleAtPoint() {
218 boolean result
= true;
219 XAccessibleComponent
[] children
= getChildrenComponents();
221 if (children
.length
> 0) {
222 for (int i
= 0; i
< children
.length
; i
++) {
223 Rectangle chBnd
= children
[i
].getBounds();
229 log
.println("Checking child with bounds " + "(" + chBnd
.X
+
230 "," + chBnd
.Y
+ "),(" + chBnd
.Width
+ "," +
231 chBnd
.Height
+ "): " +
232 util
.AccessibilityTools
.accessibleToString(
235 XAccessibleContext xAc
= UnoRuntime
.queryInterface(
236 XAccessibleContext
.class,
239 boolean MightBeCovered
= false;
240 boolean isShowing
= xAc
.getAccessibleStateSet()
241 .contains(com
.sun
.star
.accessibility
.AccessibleStateType
.SHOWING
);
242 log
.println("\tStateType containsPoint SHOWING: " +
246 log
.println("Child is invisible - OK");
251 log
.println("finding the point which lies on the component");
253 int curX
= chBnd
.Width
/ 2;
254 int curY
= chBnd
.Height
/ 2;
256 while (!children
[i
].containsPoint(new Point(curX
, curY
)) &&
257 (curX
> 0) && (curY
> 0)) {
262 if ((curX
== chBnd
.Width
) && isShowing
) {
263 log
.println("Couldn't find a point with containsPoint");
268 // trying the point laying on child
269 XAccessible xAcc
= oObj
.getAccessibleAtPoint(
270 new Point(chBnd
.X
+ curX
,
274 Point p
= new Point(chBnd
.X
+ curX
,chBnd
.X
+ curX
);
276 if (isCovered(p
) && isShowing
) {
278 "Child might be covered by another and can't be reached");
279 MightBeCovered
= true;
282 KnownBounds
.add(chBnd
);
285 log
.println("The child not found at point (" +
286 (chBnd
.X
+ curX
) + "," + (chBnd
.Y
+ curY
) +
295 XAccessible xAccCh
= UnoRuntime
.queryInterface(
298 XAccessibleContext xAccC
= UnoRuntime
.queryInterface(
299 XAccessibleContext
.class,
301 log
.println("Child found at point (" + (chBnd
.X
+ curX
) +
302 "," + (chBnd
.Y
+ curY
) + ") - OK");
309 if (xAccCh
!= null) {
310 res
= util
.AccessibilityTools
.equals(xAccCh
, xAcc
);
311 expIndex
= xAccCh
.getAccessibleContext()
312 .getAccessibleIndexInParent();
313 expName
= xAccCh
.getAccessibleContext()
314 .getAccessibleName();
315 expDesc
= xAccCh
.getAccessibleContext()
316 .getAccessibleDescription();
318 res
= xAccC
.getAccessibleName()
319 .equals(xAcc
.getAccessibleContext()
320 .getAccessibleName());
321 expIndex
= xAccC
.getAccessibleIndexInParent();
322 expName
= xAccC
.getAccessibleName();
323 expDesc
= xAccC
.getAccessibleDescription();
327 int gotIndex
= xAcc
.getAccessibleContext()
328 .getAccessibleIndexInParent();
330 if (expIndex
< gotIndex
) {
331 log
.println("The children found is not the same");
332 log
.println("The expected child " + expName
);
333 log
.print("is hidden behind the found Child ");
334 log
.println(xAcc
.getAccessibleContext()
335 .getAccessibleName() + " - OK");
338 "The children found is not the same");
339 log
.println("Expected: " + expName
);
340 log
.println("Description: " + expDesc
);
341 log
.println("Found: " +
342 xAcc
.getAccessibleContext()
343 .getAccessibleName());
344 log
.println("Description: " +
345 xAcc
.getAccessibleContext()
346 .getAccessibleDescription());
347 if (MightBeCovered
) {
348 log
.println("... Child is covered by another - OK");
350 log
.println("... FAILED");
359 // trying the point NOT laying on child
360 xAcc
= oObj
.getAccessibleAtPoint(
361 new Point(chBnd
.X
- 1, chBnd
.Y
- 1));
364 log
.println("No children found at point (" +
365 (chBnd
.X
- 1) + "," + (chBnd
.Y
- 1) +
369 XAccessible xAccCh
= UnoRuntime
.queryInterface(
372 boolean res
= util
.AccessibilityTools
.equals(xAccCh
, xAcc
);
375 log
.println("The same child found outside " +
376 "its bounds at (" + (chBnd
.X
- 1) + "," +
377 (chBnd
.Y
- 1) + ") - FAILED");
383 log
.println("There are no children supporting " +
384 "XAccessibleComponent");
387 tRes
.tested("getAccessibleAtPoint()", result
);
391 * Retrieves the component bounds and stores it. <p>
393 * Has <b> OK </b> status if boundary position (x,y) is not negative
394 * and size (Width, Height) is greater than 0.
396 public void _getBounds() {
397 boolean result
= true;
399 bounds
= oObj
.getBounds();
400 result
&= ((bounds
!= null) && (bounds
.X
>= 0) && (bounds
.Y
>= 0) && (bounds
.Width
> 0) && (bounds
.Height
> 0));
402 log
.println("Bounds = " +
404 ?
("(" + bounds
.X
+ "," + bounds
.Y
+ "),(" +
405 bounds
.Width
+ "," + bounds
.Height
+ ")") : "null"));
407 tRes
.tested("getBounds()", result
);
411 * Gets the location. <p>
413 * Has <b> OK </b> status if the location is the same as location
414 * of boundary obtained by <code>getBounds()</code> method.
416 * The following method tests are to be completed successfully before :
418 * <li> <code> getBounds() </code> : to have bounds </li>
421 public void _getLocation() {
422 requiredMethod("getBounds()");
424 boolean result
= true;
425 Point loc
= oObj
.getLocation();
427 result
&= ((loc
.X
== bounds
.X
) && (loc
.Y
== bounds
.Y
));
429 tRes
.tested("getLocation()", result
);
433 * Get the screen location of the component and its parent
434 * (if it exists and supports <code>XAccessibleComponent</code>). <p>
436 * Has <b> OK </b> status if component screen location equals
437 * to screen location of its parent plus location of the component
438 * relative to the parent. <p>
440 * The following method tests are to be completed successfully before :
442 * <li> <code> getBounds() </code> : to have location of the component
443 * relative to its parent</li>
446 public void _getLocationOnScreen() {
447 requiredMethod("getBounds()");
449 XAccessibleComponent parent
= getParentComponent();
451 boolean result
= true;
452 Point loc
= oObj
.getLocationOnScreen();
453 log
.println("Location is (" + loc
.X
+ "," + loc
.Y
+ ")");
455 if (parent
!= null) {
456 Point parLoc
= parent
.getLocationOnScreen();
457 log
.println("Parent location is (" + parLoc
.X
+ "," + parLoc
.Y
+
460 result
&= ((parLoc
.X
+ bounds
.X
) == loc
.X
);
461 result
&= ((parLoc
.Y
+ bounds
.Y
) == loc
.Y
);
464 tRes
.tested("getLocationOnScreen()", result
);
468 * Obtains the size of the component. <p>
470 * Has <b> OK </b> status if the size is the same as in bounds. <p>
472 * The following method tests are to be completed successfully before :
474 * <li> <code> getBounds() </code> </li>
477 public void _getSize() {
478 requiredMethod("getBounds()");
480 boolean result
= true;
481 Size size
= oObj
.getSize();
483 result
&= (size
.Width
== bounds
.Width
);
484 result
&= (size
.Height
== bounds
.Height
);
487 "bounds " + bounds
.Width
+ "x" + bounds
.Height
+ " vs. size "
488 + size
.Width
+ "x" + size
.Height
);
491 tRes
.tested("getSize()", result
);
495 * Just calls the method. <p>
497 * Has <b> OK </b> status if no runtime exceptions occurred.
499 public void _grabFocus() {
500 boolean result
= true;
503 tRes
.tested("grabFocus()", result
);
507 * Retrieves all children (not more than 50) of the current
508 * component which support <code>XAccessibleComponent</code>.
510 * @return The array of children. Empty array returned if
511 * such children were not found or some error occurred.
513 private XAccessibleComponent
[] getChildrenComponents() {
514 XAccessible xAcc
= UnoRuntime
.queryInterface(
515 XAccessible
.class, oObj
);
518 log
.println("Component doesn't support XAccessible.");
520 return new XAccessibleComponent
[0];
523 XAccessibleContext xAccCon
= xAcc
.getAccessibleContext();
524 int cnt
= xAccCon
.getAccessibleChildCount();
526 // for cases when too many children exist checking only first 50
531 ArrayList
<XAccessibleComponent
> childComp
= new ArrayList
<XAccessibleComponent
>();
533 for (int i
= 0; i
< cnt
; i
++) {
535 XAccessible child
= xAccCon
.getAccessibleChild(i
);
536 XAccessibleContext xAccConCh
= child
.getAccessibleContext();
537 XAccessibleComponent xChAccComp
= UnoRuntime
.queryInterface(
538 XAccessibleComponent
.class,
541 if (xChAccComp
!= null) {
542 childComp
.add(xChAccComp
);
544 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
548 return childComp
.toArray(
549 new XAccessibleComponent
[childComp
.size()]);
553 * Gets the parent of the current component which support
554 * <code>XAccessibleComponent</code>.
556 * @return The parent or <code>null</code> if the component
557 * has no parent or some errors occurred.
559 private XAccessibleComponent
getParentComponent() {
560 XAccessible xAcc
= UnoRuntime
.queryInterface(
561 XAccessible
.class, oObj
);
564 log
.println("Component doesn't support XAccessible.");
569 XAccessibleContext xAccCon
= xAcc
.getAccessibleContext();
570 XAccessible xAccPar
= xAccCon
.getAccessibleParent();
572 if (xAccPar
== null) {
573 log
.println("Component has no accessible parent.");
578 XAccessibleContext xAccConPar
= xAccPar
.getAccessibleContext();
579 XAccessibleComponent parent
= UnoRuntime
.queryInterface(
580 XAccessibleComponent
.class,
583 if (parent
== null) {
585 "Accessible parent doesn't support XAccessibleComponent");
594 * Just calls the method.
596 public void _getForeground() {
597 int forColor
= oObj
.getForeground();
598 log
.println("getForeground(): " + forColor
);
599 tRes
.tested("getForeground()", true);
603 * Just calls the method.
605 public void _getBackground() {
606 int backColor
= oObj
.getBackground();
607 log
.println("getBackground(): " + backColor
);
608 tRes
.tested("getBackground()", true);
612 * Restores initial component text.
614 protected void after() {
615 if (tEnv
.getObjRelation("Destroy") != null) {
616 disposeEnvironment();
620 private boolean isCovered(Point p
) {
621 int elements
= KnownBounds
.size();
622 boolean Covered
= false;
623 for (int k
=0;k
<elements
;k
++) {
624 Rectangle known
= KnownBounds
.get(k
);
625 Covered
= (known
.X
< p
.X
);
626 Covered
&= (known
.Y
< p
.Y
);
627 Covered
&= (p
.Y
< known
.Y
+known
.Height
);
628 Covered
&= (p
.X
< known
.X
+known
.Width
);