xref: /AOO41X/main/qadevOOo/tests/java/ifc/accessibility/_XAccessibleComponent.java (revision 47148b3bc50811ceb41802e4cc50a5db21535900)
1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package ifc.accessibility;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import java.util.Vector;
26cdf0e10cSrcweir 
27cdf0e10cSrcweir import lib.MultiMethodTest;
28cdf0e10cSrcweir 
29cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible;
30cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleComponent;
31cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleContext;
32cdf0e10cSrcweir import com.sun.star.awt.Point;
33cdf0e10cSrcweir import com.sun.star.awt.Rectangle;
34cdf0e10cSrcweir import com.sun.star.awt.Size;
35cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir 
38cdf0e10cSrcweir /**
39cdf0e10cSrcweir  * Testing <code>com.sun.star.accessibility.XAccessibleComponent</code>
40cdf0e10cSrcweir  * interface methods :
41cdf0e10cSrcweir  * <ul>
42cdf0e10cSrcweir  *  <li><code> containsPoint()</code></li>
43cdf0e10cSrcweir  *  <li><code> getAccessibleAtPoint()</code></li>
44cdf0e10cSrcweir  *  <li><code> getBounds()</code></li>
45cdf0e10cSrcweir  *  <li><code> getLocation()</code></li>
46cdf0e10cSrcweir  *  <li><code> getLocationOnScreen()</code></li>
47cdf0e10cSrcweir  *  <li><code> getSize()</code></li>
48cdf0e10cSrcweir  *  <li><code> grabFocus()</code></li>
49cdf0e10cSrcweir  *  <li><code> getAccessibleKeyBinding()</code></li>
50cdf0e10cSrcweir  * </ul> <p>
51cdf0e10cSrcweir  *
52cdf0e10cSrcweir  * @see com.sun.star.accessibility.XAccessibleComponent
53cdf0e10cSrcweir  */
54cdf0e10cSrcweir public class _XAccessibleComponent extends MultiMethodTest {
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     public XAccessibleComponent oObj = null;
57cdf0e10cSrcweir     private Rectangle bounds = null;
58cdf0e10cSrcweir     private Vector KnownBounds = new Vector();
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     /**
62cdf0e10cSrcweir      * First checks 4 inner bounds (upper, lower, left and right)
63cdf0e10cSrcweir      * of component bounding box to contain
64cdf0e10cSrcweir      * at least one point of the component. Second 4 outer bounds
65cdf0e10cSrcweir      * are checked to not contain any component points.<p>
66cdf0e10cSrcweir      *
67cdf0e10cSrcweir      * Has <b> OK </b> status if inner bounds contain component points
68cdf0e10cSrcweir      * and outer bounds don't contain any component points. <p>
69cdf0e10cSrcweir      *
70cdf0e10cSrcweir      * The following method tests are to be completed successfully before :
71cdf0e10cSrcweir      * <ul>
72cdf0e10cSrcweir      *  <li> <code> getBounds() </code> : to have size of a component.</li>
73cdf0e10cSrcweir      * </ul>
74cdf0e10cSrcweir      */
_containsPoint()75cdf0e10cSrcweir     public void _containsPoint() {
76cdf0e10cSrcweir         requiredMethod("getBounds()");
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         boolean result = true;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir         int curX = 0;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir         //while (!oObj.containsPoint(new Point(curX, bounds.Y)) && curX < bounds.Width+bounds.X) {
83cdf0e10cSrcweir         while (!oObj.containsPoint(new Point(curX, 0)) &&
84cdf0e10cSrcweir                (curX < bounds.Width)) {
85cdf0e10cSrcweir             curX++;
86cdf0e10cSrcweir         }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir         //if ((bounds.X <= curX) && (curX < bounds.Width+bounds.X)) {
89cdf0e10cSrcweir         if (curX < bounds.Width) {
90cdf0e10cSrcweir             log.println("Upper bound of box containsPoint point (" + curX +
91cdf0e10cSrcweir                         ",0) - OK");
92cdf0e10cSrcweir         } else {
93cdf0e10cSrcweir             log.println(
94cdf0e10cSrcweir                     "Upper bound of box containsPoint no component points - FAILED");
95cdf0e10cSrcweir             result = false;
96cdf0e10cSrcweir         }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir         curX = 0;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         //while (!oObj.containsPoint(new Point(curX, bounds.Y+bounds.Height - 1))
101cdf0e10cSrcweir         while (!oObj.containsPoint(new Point(curX, bounds.Height - 1)) &&
102cdf0e10cSrcweir                (curX < bounds.Width)) {
103cdf0e10cSrcweir             log.println("containsPoint returns false for (" + curX + "," +
104cdf0e10cSrcweir                         bounds.Height + ")");
105cdf0e10cSrcweir             curX++;
106cdf0e10cSrcweir         }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir         //if ((bounds.X <= curX) && (curX < bounds.Width+bounds.X)) {
109cdf0e10cSrcweir         if (curX < bounds.Width) {
110cdf0e10cSrcweir             log.println("Lower bound of box containsPoint point (" + curX +
111cdf0e10cSrcweir                         "," + (bounds.Height - 1) + ") - OK");
112cdf0e10cSrcweir         } else {
113cdf0e10cSrcweir             log.println(
114cdf0e10cSrcweir                     "Lower bound of box containsPoint no component points - FAILED");
115cdf0e10cSrcweir             result = false;
116cdf0e10cSrcweir         }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         int curY = 0;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         //while (!oObj.containsPoint(new Point(bounds.X, curY)) && curY < bounds.Height+bounds.Y) {
121cdf0e10cSrcweir         while (!oObj.containsPoint(new Point(0, curY)) &&
122cdf0e10cSrcweir                (curY < bounds.Height)) {
123cdf0e10cSrcweir             curY++;
124cdf0e10cSrcweir         }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         //if ((bounds.Y <= curY) && (curY < bounds.Height+bounds.Y)) {
127cdf0e10cSrcweir         if (curY < bounds.Height) {
128cdf0e10cSrcweir             log.println("Left bound of box containsPoint point (0," + curY +
129cdf0e10cSrcweir                         ") - OK");
130cdf0e10cSrcweir         } else {
131cdf0e10cSrcweir             log.println(
132cdf0e10cSrcweir                     "Left bound of box containsPoint no component points - FAILED");
133cdf0e10cSrcweir             result = false;
134cdf0e10cSrcweir         }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir         curY = 0;
137cdf0e10cSrcweir 
138cdf0e10cSrcweir         //while (!oObj.containsPoint(new Point(bounds.X+bounds.Width - 1, curY))
139cdf0e10cSrcweir         //       && curY < bounds.Height+bounds.Y) {
140cdf0e10cSrcweir         while (!oObj.containsPoint(new Point(bounds.Width - 1, curY)) &&
141cdf0e10cSrcweir                (curY < bounds.Height)) {
142cdf0e10cSrcweir             curY++;
143cdf0e10cSrcweir         }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         //if ((bounds.Y <= curY) && (curY < bounds.Height + bounds.Y)) {
146cdf0e10cSrcweir         if (curY < bounds.Height) {
147cdf0e10cSrcweir             log.println("Right bound of box containsPoint point (" +
148cdf0e10cSrcweir                         (bounds.Width - 1) + "," + curY + ") - OK");
149cdf0e10cSrcweir         } else {
150cdf0e10cSrcweir             log.println(
151cdf0e10cSrcweir                     "Right bound of box containsPoint no component points - FAILED");
152cdf0e10cSrcweir             result = false;
153cdf0e10cSrcweir         }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         boolean locRes = true;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir         for (int x = -1; x <= bounds.Width; x++) {
158cdf0e10cSrcweir             if (oObj.containsPoint(new Point(x, -1))) {
159cdf0e10cSrcweir                 log.println(
160cdf0e10cSrcweir                     "Outer upper and lower bounds CONTAIN some component point"
161cdf0e10cSrcweir                     + " (" + x + ", -1) - FAILED");
162cdf0e10cSrcweir                 locRes = false;
163cdf0e10cSrcweir                 break;
164cdf0e10cSrcweir             }
165cdf0e10cSrcweir             if (oObj.containsPoint(new Point(x, bounds.Height + bounds.Y))) {
166cdf0e10cSrcweir                 log.println(
167cdf0e10cSrcweir                     "Outer upper and lower bounds CONTAIN some component point"
168cdf0e10cSrcweir                     + " (" + x + ", " + bounds.Height + bounds.Y
169cdf0e10cSrcweir                     + ") - FAILED");
170cdf0e10cSrcweir                 locRes = false;
171cdf0e10cSrcweir                 break;
172cdf0e10cSrcweir             }
173cdf0e10cSrcweir         }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         if (locRes) {
176cdf0e10cSrcweir             log.println("Outer upper and lower bounds contain no component " +
177cdf0e10cSrcweir                         "points - OK");
178cdf0e10cSrcweir         } else {
179cdf0e10cSrcweir             result = false;
180cdf0e10cSrcweir         }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         locRes = true;
183cdf0e10cSrcweir 
184cdf0e10cSrcweir         for (int y = -1; y <= bounds.Height; y++) {
185cdf0e10cSrcweir             if (oObj.containsPoint(new Point(-1, y))) {
186cdf0e10cSrcweir                 log.println(
187cdf0e10cSrcweir                     "Outer left and right bounds CONTAIN some component point"
188cdf0e10cSrcweir                     + " (-1, " + y + ") - FAILED");
189cdf0e10cSrcweir                 locRes = false;
190cdf0e10cSrcweir                 break;
191cdf0e10cSrcweir             }
192cdf0e10cSrcweir             if (oObj.containsPoint(new Point(bounds.X + bounds.Width, y))) {
193cdf0e10cSrcweir                 log.println(
194cdf0e10cSrcweir                     "Outer left and right bounds CONTAIN some component point"
195cdf0e10cSrcweir                     + " (" + bounds.X + bounds.Width + ", " + y + ") - FAILED");
196cdf0e10cSrcweir                 locRes = false;
197cdf0e10cSrcweir                 break;
198cdf0e10cSrcweir             }
199cdf0e10cSrcweir         }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir         if (locRes) {
202cdf0e10cSrcweir             log.println("Outer left and right bounds contain no component " +
203cdf0e10cSrcweir                         "points - OK");
204cdf0e10cSrcweir         } else {
205cdf0e10cSrcweir             result = false;
206cdf0e10cSrcweir         }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir         tRes.tested("containsPoint()", result);
209cdf0e10cSrcweir     }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir     /**
212cdf0e10cSrcweir      * Iterates through all children which implement
213cdf0e10cSrcweir      * <code>XAccessibleComponent</code> (if they exist) determines their
214cdf0e10cSrcweir      * boundaries and tries to get each child by <code>getAccessibleAtPoint</code>
215cdf0e10cSrcweir      * passing point which belongs to the child.
216cdf0e10cSrcweir      * Also the point is checked which doesn't belong to child boundary
217cdf0e10cSrcweir      * box. <p>
218cdf0e10cSrcweir      *
219cdf0e10cSrcweir      * Has <b> OK </b> status if in the first cases the right children
220cdf0e10cSrcweir      * are returned, and in the second <code>null</code> or
221cdf0e10cSrcweir      * another child is returned.
222cdf0e10cSrcweir      */
_getAccessibleAtPoint()223cdf0e10cSrcweir     public void _getAccessibleAtPoint() {
224cdf0e10cSrcweir         boolean result = true;
225cdf0e10cSrcweir         XAccessibleComponent[] children = getChildrenComponents();
226cdf0e10cSrcweir 
227cdf0e10cSrcweir         if (children.length > 0) {
228cdf0e10cSrcweir             for (int i = 0; i < children.length; i++) {
229cdf0e10cSrcweir                 Rectangle chBnd = children[i].getBounds();
230cdf0e10cSrcweir 
231cdf0e10cSrcweir                 if (chBnd.X == -1) {
232cdf0e10cSrcweir                     continue;
233cdf0e10cSrcweir                 }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir                 log.println("Checking child with bounds " + "(" + chBnd.X +
236cdf0e10cSrcweir                             "," + chBnd.Y + "),(" + chBnd.Width + "," +
237cdf0e10cSrcweir                             chBnd.Height + "): " +
238cdf0e10cSrcweir                             util.AccessibilityTools.accessibleToString(
239cdf0e10cSrcweir                                     children[i]));
240cdf0e10cSrcweir 
241cdf0e10cSrcweir                 XAccessibleContext xAc = (XAccessibleContext) UnoRuntime.queryInterface(
242cdf0e10cSrcweir                                                  XAccessibleContext.class,
243cdf0e10cSrcweir                                                  children[i]);
244cdf0e10cSrcweir 
245cdf0e10cSrcweir                 boolean MightBeCovered = false;
246cdf0e10cSrcweir                 boolean isShowing = xAc.getAccessibleStateSet()
247cdf0e10cSrcweir                                        .contains(com.sun.star.accessibility.AccessibleStateType.SHOWING);
248cdf0e10cSrcweir                 log.println("\tStateType containsPoint SHOWING: " +
249cdf0e10cSrcweir                             isShowing);
250cdf0e10cSrcweir 
251cdf0e10cSrcweir                 if (!isShowing) {
252cdf0e10cSrcweir                     log.println("Child is invisible - OK");
253cdf0e10cSrcweir 
254cdf0e10cSrcweir                     continue;
255cdf0e10cSrcweir                 }
256cdf0e10cSrcweir 
257cdf0e10cSrcweir                 log.println("finding the point which lies on the component");
258cdf0e10cSrcweir 
259cdf0e10cSrcweir                 int curX = chBnd.Width / 2;
260cdf0e10cSrcweir                 int curY = chBnd.Height / 2;
261cdf0e10cSrcweir 
262cdf0e10cSrcweir                 while (!children[i].containsPoint(new Point(curX, curY)) &&
263cdf0e10cSrcweir                        (curX > 0) && (curY > 0)) {
264cdf0e10cSrcweir                     curX--;
265cdf0e10cSrcweir                     curY--;
266cdf0e10cSrcweir                 }
267cdf0e10cSrcweir 
268cdf0e10cSrcweir                 if ((curX == chBnd.Width) && isShowing) {
269cdf0e10cSrcweir                     log.println("Couldn't find a point with containsPoint");
270cdf0e10cSrcweir 
271cdf0e10cSrcweir                     continue;
272cdf0e10cSrcweir                 }
273cdf0e10cSrcweir 
274cdf0e10cSrcweir                 // trying the point laying on child
275cdf0e10cSrcweir                 XAccessible xAcc = oObj.getAccessibleAtPoint(
276cdf0e10cSrcweir                                            new Point(chBnd.X + curX,
277cdf0e10cSrcweir                                                      chBnd.Y + curY));
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 
280cdf0e10cSrcweir                 Point p = new Point(chBnd.X + curX,chBnd.X + curX);
281cdf0e10cSrcweir 
282cdf0e10cSrcweir                 if (isCovered(p) && isShowing) {
283cdf0e10cSrcweir                     log.println(
284cdf0e10cSrcweir                             "Child might be covered by another and can't be reached");
285cdf0e10cSrcweir                     MightBeCovered = true;
286cdf0e10cSrcweir                 }
287cdf0e10cSrcweir 
288cdf0e10cSrcweir                 KnownBounds.add(chBnd);
289cdf0e10cSrcweir 
290cdf0e10cSrcweir                 if (xAcc == null) {
291cdf0e10cSrcweir                     log.println("The child not found at point (" +
292cdf0e10cSrcweir                                 (chBnd.X + curX) + "," + (chBnd.Y + curY) +
293cdf0e10cSrcweir                                 ") - FAILED");
294cdf0e10cSrcweir 
295cdf0e10cSrcweir                     if (isShowing) {
296cdf0e10cSrcweir                         result = false;
297cdf0e10cSrcweir                     } else {
298cdf0e10cSrcweir                         result &= true;
299cdf0e10cSrcweir                     }
300cdf0e10cSrcweir                 } else {
301cdf0e10cSrcweir                     XAccessible xAccCh = (XAccessible) UnoRuntime.queryInterface(
302cdf0e10cSrcweir                                                  XAccessible.class,
303cdf0e10cSrcweir                                                  children[i]);
304cdf0e10cSrcweir                     XAccessibleContext xAccC = (XAccessibleContext) UnoRuntime.queryInterface(
305cdf0e10cSrcweir                                                        XAccessibleContext.class,
306cdf0e10cSrcweir                                                        children[i]);
307cdf0e10cSrcweir                     log.println("Child found at point (" + (chBnd.X + curX) +
308cdf0e10cSrcweir                                 "," + (chBnd.Y + curY) + ") - OK");
309cdf0e10cSrcweir 
310cdf0e10cSrcweir                     boolean res = false;
311cdf0e10cSrcweir                     int expIndex;
312cdf0e10cSrcweir                     String expName;
313cdf0e10cSrcweir                     String expDesc;
314cdf0e10cSrcweir 
315cdf0e10cSrcweir                     if (xAccCh != null) {
316cdf0e10cSrcweir                         res = util.AccessibilityTools.equals(xAccCh, xAcc);
317cdf0e10cSrcweir                         expIndex = xAccCh.getAccessibleContext()
318cdf0e10cSrcweir                                          .getAccessibleIndexInParent();
319cdf0e10cSrcweir                         expName = xAccCh.getAccessibleContext()
320cdf0e10cSrcweir                                         .getAccessibleName();
321cdf0e10cSrcweir                         expDesc = xAccCh.getAccessibleContext()
322cdf0e10cSrcweir                                         .getAccessibleDescription();
323cdf0e10cSrcweir                     } else {
324cdf0e10cSrcweir                         res = xAccC.getAccessibleName()
325cdf0e10cSrcweir                                    .equals(xAcc.getAccessibleContext()
326cdf0e10cSrcweir                                                .getAccessibleName());
327cdf0e10cSrcweir                         expIndex = xAccC.getAccessibleIndexInParent();
328cdf0e10cSrcweir                         expName = xAccC.getAccessibleName();
329cdf0e10cSrcweir                         expDesc = xAccC.getAccessibleDescription();
330cdf0e10cSrcweir                     }
331cdf0e10cSrcweir 
332cdf0e10cSrcweir                     if (!res) {
333cdf0e10cSrcweir                         int gotIndex = xAcc.getAccessibleContext()
334cdf0e10cSrcweir                                            .getAccessibleIndexInParent();
335cdf0e10cSrcweir 
336cdf0e10cSrcweir                         if (expIndex < gotIndex) {
337cdf0e10cSrcweir                             log.println("The children found is not the same");
338cdf0e10cSrcweir                             log.println("The expected child " + expName);
339cdf0e10cSrcweir                             log.print("is hidden behind the found Child ");
340cdf0e10cSrcweir                             log.println(xAcc.getAccessibleContext()
341cdf0e10cSrcweir                                             .getAccessibleName() + " - OK");
342cdf0e10cSrcweir                         } else {
343cdf0e10cSrcweir                             log.println(
344cdf0e10cSrcweir                                     "The children found is not the same");
345cdf0e10cSrcweir                             log.println("Expected: " + expName);
346cdf0e10cSrcweir                             log.println("Description:  " + expDesc);
347cdf0e10cSrcweir                             log.println("Found: " +
348cdf0e10cSrcweir                                         xAcc.getAccessibleContext()
349cdf0e10cSrcweir                                             .getAccessibleName());
350cdf0e10cSrcweir                             log.println("Description:  " +
351cdf0e10cSrcweir                                         xAcc.getAccessibleContext()
352cdf0e10cSrcweir                                             .getAccessibleDescription());
353cdf0e10cSrcweir                             if (MightBeCovered) {
354cdf0e10cSrcweir                                 log.println("... Child is covered by another - OK");
355cdf0e10cSrcweir                             } else {
356cdf0e10cSrcweir                                 log.println("... FAILED");
357cdf0e10cSrcweir                                 result = false;
358cdf0e10cSrcweir                             }
359cdf0e10cSrcweir 
360cdf0e10cSrcweir                         }
361cdf0e10cSrcweir                     }
362cdf0e10cSrcweir                 }
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 
365cdf0e10cSrcweir                 // trying the point NOT laying on child
366cdf0e10cSrcweir                 xAcc = oObj.getAccessibleAtPoint(
367cdf0e10cSrcweir                                new Point(chBnd.X - 1, chBnd.Y - 1));
368cdf0e10cSrcweir 
369cdf0e10cSrcweir                 if (xAcc == null) {
370cdf0e10cSrcweir                     log.println("No children found at point (" +
371cdf0e10cSrcweir                                 (chBnd.X - 1) + "," + (chBnd.Y - 1) +
372cdf0e10cSrcweir                                 ") - OK");
373cdf0e10cSrcweir                     result &= true;
374cdf0e10cSrcweir                 } else {
375cdf0e10cSrcweir                     XAccessible xAccCh = (XAccessible) UnoRuntime.queryInterface(
376cdf0e10cSrcweir                                                  XAccessible.class,
377cdf0e10cSrcweir                                                  children[i]);
378cdf0e10cSrcweir                     boolean res = util.AccessibilityTools.equals(xAccCh, xAcc);
379cdf0e10cSrcweir 
380cdf0e10cSrcweir                     if (res) {
381cdf0e10cSrcweir                         log.println("The same child found outside " +
382cdf0e10cSrcweir                                     "its bounds at (" + (chBnd.X - 1) + "," +
383cdf0e10cSrcweir                                     (chBnd.Y - 1) + ") - FAILED");
384cdf0e10cSrcweir                         result = false;
385cdf0e10cSrcweir                     }
386cdf0e10cSrcweir                 }
387cdf0e10cSrcweir             }
388cdf0e10cSrcweir         } else {
389cdf0e10cSrcweir             log.println("There are no children supporting " +
390cdf0e10cSrcweir                         "XAccessibleComponent");
391cdf0e10cSrcweir         }
392cdf0e10cSrcweir 
393cdf0e10cSrcweir         tRes.tested("getAccessibleAtPoint()", result);
394cdf0e10cSrcweir     }
395cdf0e10cSrcweir 
396cdf0e10cSrcweir     /**
397cdf0e10cSrcweir      * Retrieves the component bounds and stores it. <p>
398cdf0e10cSrcweir      *
399cdf0e10cSrcweir      * Has <b> OK </b> status if boundary position (x,y) is not negative
400cdf0e10cSrcweir      * and size (Width, Height) is greater than 0.
401cdf0e10cSrcweir      */
_getBounds()402cdf0e10cSrcweir     public void _getBounds() {
403cdf0e10cSrcweir         boolean result = true;
404cdf0e10cSrcweir 
405cdf0e10cSrcweir         bounds = oObj.getBounds();
406cdf0e10cSrcweir         result &= ((bounds != null) && (bounds.X >= 0) && (bounds.Y >= 0) && (bounds.Width > 0) && (bounds.Height > 0));
407cdf0e10cSrcweir 
408cdf0e10cSrcweir         log.println("Bounds = " +
409cdf0e10cSrcweir                     ((bounds != null)
410cdf0e10cSrcweir                      ? ("(" + bounds.X + "," + bounds.Y + "),(" +
411cdf0e10cSrcweir                                bounds.Width + "," + bounds.Height + ")") : "null"));
412cdf0e10cSrcweir 
413cdf0e10cSrcweir         tRes.tested("getBounds()", result);
414cdf0e10cSrcweir     }
415cdf0e10cSrcweir 
416cdf0e10cSrcweir     /**
417cdf0e10cSrcweir      * Gets the location. <p>
418cdf0e10cSrcweir      *
419cdf0e10cSrcweir      * Has <b> OK </b> status if the location is the same as location
420cdf0e10cSrcweir      * of boundary obtained by <code>getBounds()</code> method.
421cdf0e10cSrcweir      *
422cdf0e10cSrcweir      * The following method tests are to be completed successfully before :
423cdf0e10cSrcweir      * <ul>
424cdf0e10cSrcweir      *  <li> <code> getBounds() </code> : to have bounds </li>
425cdf0e10cSrcweir      * </ul>
426cdf0e10cSrcweir      */
_getLocation()427cdf0e10cSrcweir     public void _getLocation() {
428cdf0e10cSrcweir         requiredMethod("getBounds()");
429cdf0e10cSrcweir 
430cdf0e10cSrcweir         boolean result = true;
431cdf0e10cSrcweir         Point loc = oObj.getLocation();
432cdf0e10cSrcweir 
433cdf0e10cSrcweir         result &= ((loc.X == bounds.X) && (loc.Y == bounds.Y));
434cdf0e10cSrcweir 
435cdf0e10cSrcweir         tRes.tested("getLocation()", result);
436cdf0e10cSrcweir     }
437cdf0e10cSrcweir 
438cdf0e10cSrcweir     /**
439cdf0e10cSrcweir      * Get the screen location of the component and its parent
440cdf0e10cSrcweir      * (if it exists and supports <code>XAccessibleComponent</code>). <p>
441cdf0e10cSrcweir      *
442cdf0e10cSrcweir      * Has <b> OK </b> status if component screen location equals
443cdf0e10cSrcweir      * to screen location of its parent plus location of the component
444cdf0e10cSrcweir      * relative to the parent. <p>
445cdf0e10cSrcweir      *
446cdf0e10cSrcweir      * The following method tests are to be completed successfully before :
447cdf0e10cSrcweir      * <ul>
448cdf0e10cSrcweir      *  <li> <code> getBounds() </code> : to have location of the component
449cdf0e10cSrcweir      *      relative to its parent</li>
450cdf0e10cSrcweir      * </ul>
451cdf0e10cSrcweir      */
_getLocationOnScreen()452cdf0e10cSrcweir     public void _getLocationOnScreen() {
453cdf0e10cSrcweir         requiredMethod("getBounds()");
454cdf0e10cSrcweir 
455cdf0e10cSrcweir         XAccessibleComponent parent = getParentComponent();
456cdf0e10cSrcweir 
457cdf0e10cSrcweir         boolean result = true;
458cdf0e10cSrcweir         Point loc = oObj.getLocationOnScreen();
459cdf0e10cSrcweir         log.println("Location is (" + loc.X + "," + loc.Y + ")");
460cdf0e10cSrcweir 
461cdf0e10cSrcweir         if (parent != null) {
462cdf0e10cSrcweir             Point parLoc = parent.getLocationOnScreen();
463cdf0e10cSrcweir             log.println("Parent location is (" + parLoc.X + "," + parLoc.Y +
464cdf0e10cSrcweir                         ")");
465cdf0e10cSrcweir 
466cdf0e10cSrcweir             result &= ((parLoc.X + bounds.X) == loc.X);
467cdf0e10cSrcweir             result &= ((parLoc.Y + bounds.Y) == loc.Y);
468cdf0e10cSrcweir         }
469cdf0e10cSrcweir 
470cdf0e10cSrcweir         tRes.tested("getLocationOnScreen()", result);
471cdf0e10cSrcweir     }
472cdf0e10cSrcweir 
473cdf0e10cSrcweir     /**
474cdf0e10cSrcweir      * Obtains the size of the component. <p>
475cdf0e10cSrcweir      *
476cdf0e10cSrcweir      * Has <b> OK </b> status if the size is the same as in bounds. <p>
477cdf0e10cSrcweir      *
478cdf0e10cSrcweir      * The following method tests are to be completed successfully before :
479cdf0e10cSrcweir      * <ul>
480cdf0e10cSrcweir      *  <li> <code> getBounds() </code>  </li>
481cdf0e10cSrcweir      * </ul>
482cdf0e10cSrcweir      */
_getSize()483cdf0e10cSrcweir     public void _getSize() {
484cdf0e10cSrcweir         requiredMethod("getBounds()");
485cdf0e10cSrcweir 
486cdf0e10cSrcweir         boolean result = true;
487cdf0e10cSrcweir         Size size = oObj.getSize();
488cdf0e10cSrcweir 
489cdf0e10cSrcweir         result &= (size.Width == bounds.Width);
490cdf0e10cSrcweir         result &= (size.Height == bounds.Height);
491cdf0e10cSrcweir 
492cdf0e10cSrcweir         tRes.tested("getSize()", result);
493cdf0e10cSrcweir     }
494cdf0e10cSrcweir 
495cdf0e10cSrcweir     /**
496cdf0e10cSrcweir      * Just calls the method. <p>
497cdf0e10cSrcweir      *
498cdf0e10cSrcweir      * Has <b> OK </b> status if no runtime exceptions occured.
499cdf0e10cSrcweir      */
_grabFocus()500cdf0e10cSrcweir     public void _grabFocus() {
501cdf0e10cSrcweir         boolean result = true;
502cdf0e10cSrcweir         oObj.grabFocus();
503cdf0e10cSrcweir 
504cdf0e10cSrcweir         tRes.tested("grabFocus()", result);
505cdf0e10cSrcweir     }
506cdf0e10cSrcweir 
507cdf0e10cSrcweir     /**
508cdf0e10cSrcweir      * Retrieves all children (not more than 50) of the current
509cdf0e10cSrcweir      * component which support <code>XAccessibleComponent</code>.
510cdf0e10cSrcweir      *
511cdf0e10cSrcweir      * @return The array of children. Empty array returned if
512cdf0e10cSrcweir      * such children were not found or some error occured.
513cdf0e10cSrcweir      */
getChildrenComponents()514cdf0e10cSrcweir     private XAccessibleComponent[] getChildrenComponents() {
515cdf0e10cSrcweir         XAccessible xAcc = (XAccessible) UnoRuntime.queryInterface(
516cdf0e10cSrcweir                                    XAccessible.class, oObj);
517cdf0e10cSrcweir 
518cdf0e10cSrcweir         if (xAcc == null) {
519cdf0e10cSrcweir             log.println("Component doesn't support XAccessible.");
520cdf0e10cSrcweir 
521cdf0e10cSrcweir             return new XAccessibleComponent[0];
522cdf0e10cSrcweir         }
523cdf0e10cSrcweir 
524cdf0e10cSrcweir         XAccessibleContext xAccCon = xAcc.getAccessibleContext();
525cdf0e10cSrcweir         int cnt = xAccCon.getAccessibleChildCount();
526cdf0e10cSrcweir 
527cdf0e10cSrcweir         // for cases when too many children exist checking only first 50
528cdf0e10cSrcweir         if (cnt > 50) {
529cdf0e10cSrcweir             cnt = 50;
530cdf0e10cSrcweir         }
531cdf0e10cSrcweir 
532cdf0e10cSrcweir         Vector childComp = new Vector();
533cdf0e10cSrcweir 
534cdf0e10cSrcweir         for (int i = 0; i < cnt; i++) {
535cdf0e10cSrcweir             try {
536cdf0e10cSrcweir                 XAccessible child = xAccCon.getAccessibleChild(i);
537cdf0e10cSrcweir                 XAccessibleContext xAccConCh = child.getAccessibleContext();
538cdf0e10cSrcweir                 XAccessibleComponent xChAccComp = (XAccessibleComponent) UnoRuntime.queryInterface(
539cdf0e10cSrcweir                                                           XAccessibleComponent.class,
540cdf0e10cSrcweir                                                           xAccConCh);
541cdf0e10cSrcweir 
542cdf0e10cSrcweir                 if (xChAccComp != null) {
543cdf0e10cSrcweir                     childComp.add(xChAccComp);
544cdf0e10cSrcweir                 }
545cdf0e10cSrcweir             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
546cdf0e10cSrcweir             }
547cdf0e10cSrcweir         }
548cdf0e10cSrcweir 
549cdf0e10cSrcweir         return (XAccessibleComponent[]) childComp.toArray(
550cdf0e10cSrcweir                          new XAccessibleComponent[childComp.size()]);
551cdf0e10cSrcweir     }
552cdf0e10cSrcweir 
553cdf0e10cSrcweir     /**
554cdf0e10cSrcweir      * Gets the parent of the current component which support
555cdf0e10cSrcweir      * <code>XAccessibleComponent</code>.
556cdf0e10cSrcweir      *
557cdf0e10cSrcweir      * @return The parent or <code>null</code> if the component
558cdf0e10cSrcweir      * has no parent or some errors occured.
559cdf0e10cSrcweir      */
getParentComponent()560cdf0e10cSrcweir     private XAccessibleComponent getParentComponent() {
561cdf0e10cSrcweir         XAccessible xAcc = (XAccessible) UnoRuntime.queryInterface(
562cdf0e10cSrcweir                                    XAccessible.class, oObj);
563cdf0e10cSrcweir 
564cdf0e10cSrcweir         if (xAcc == null) {
565cdf0e10cSrcweir             log.println("Component doesn't support XAccessible.");
566cdf0e10cSrcweir 
567cdf0e10cSrcweir             return null;
568cdf0e10cSrcweir         }
569cdf0e10cSrcweir 
570cdf0e10cSrcweir         XAccessibleContext xAccCon = xAcc.getAccessibleContext();
571cdf0e10cSrcweir         XAccessible xAccPar = xAccCon.getAccessibleParent();
572cdf0e10cSrcweir 
573cdf0e10cSrcweir         if (xAccPar == null) {
574cdf0e10cSrcweir             log.println("Component has no accessible parent.");
575cdf0e10cSrcweir 
576cdf0e10cSrcweir             return null;
577cdf0e10cSrcweir         }
578cdf0e10cSrcweir 
579cdf0e10cSrcweir         XAccessibleContext xAccConPar = xAccPar.getAccessibleContext();
580cdf0e10cSrcweir         XAccessibleComponent parent = (XAccessibleComponent) UnoRuntime.queryInterface(
581cdf0e10cSrcweir                                               XAccessibleComponent.class,
582cdf0e10cSrcweir                                               xAccConPar);
583cdf0e10cSrcweir 
584cdf0e10cSrcweir         if (parent == null) {
585cdf0e10cSrcweir             log.println(
586cdf0e10cSrcweir                     "Accessible parent doesn't support XAccessibleComponent");
587cdf0e10cSrcweir 
588cdf0e10cSrcweir             return null;
589cdf0e10cSrcweir         }
590cdf0e10cSrcweir 
591cdf0e10cSrcweir         return parent;
592cdf0e10cSrcweir     }
593cdf0e10cSrcweir 
594cdf0e10cSrcweir     /**
595cdf0e10cSrcweir      * Just calls the method.
596cdf0e10cSrcweir      */
_getForeground()597cdf0e10cSrcweir     public void _getForeground() {
598cdf0e10cSrcweir         int forColor = oObj.getForeground();
599cdf0e10cSrcweir         log.println("getForeground(): " + forColor);
600cdf0e10cSrcweir         tRes.tested("getForeground()", true);
601cdf0e10cSrcweir     }
602cdf0e10cSrcweir 
603cdf0e10cSrcweir     /**
604cdf0e10cSrcweir      * Just calls the method.
605cdf0e10cSrcweir      */
_getBackground()606cdf0e10cSrcweir     public void _getBackground() {
607cdf0e10cSrcweir         int backColor = oObj.getBackground();
608cdf0e10cSrcweir         log.println("getBackground(): " + backColor);
609cdf0e10cSrcweir         tRes.tested("getBackground()", true);
610cdf0e10cSrcweir     }
611cdf0e10cSrcweir 
612cdf0e10cSrcweir     /**
613cdf0e10cSrcweir      * Restores initial component text.
614cdf0e10cSrcweir      */
after()615cdf0e10cSrcweir     protected void after() {
616cdf0e10cSrcweir         if (tEnv.getObjRelation("Destroy") != null) {
617cdf0e10cSrcweir             disposeEnvironment();
618cdf0e10cSrcweir         }
619cdf0e10cSrcweir     }
620cdf0e10cSrcweir 
isCovered(Point p)621cdf0e10cSrcweir     private boolean isCovered(Point p) {
622cdf0e10cSrcweir         int elements = KnownBounds.size();
623cdf0e10cSrcweir         boolean Covered = false;
624cdf0e10cSrcweir         for (int k=0;k<elements;k++) {
625cdf0e10cSrcweir             Rectangle known = (Rectangle) KnownBounds.get(k);
626cdf0e10cSrcweir             Covered = (known.X < p.X);
627cdf0e10cSrcweir             Covered &= (known.Y < p.Y);
628cdf0e10cSrcweir             Covered &= (p.Y < known.Y+known.Height);
629cdf0e10cSrcweir             Covered &= (p.X < known.X+known.Width);
630cdf0e10cSrcweir 
631cdf0e10cSrcweir             if (Covered) {
632cdf0e10cSrcweir                 break;
633cdf0e10cSrcweir             }
634cdf0e10cSrcweir         }
635cdf0e10cSrcweir         return Covered;
636cdf0e10cSrcweir     }
637cdf0e10cSrcweir }
638