xref: /AOO41X/main/qadevOOo/tests/java/ifc/accessibility/_XAccessibleSelection.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir package ifc.accessibility;
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleRole;
30*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible;
31*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleContext;
32*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleSelection;
33*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir import lib.MultiMethodTest;
36*cdf0e10cSrcweir import lib.Status;
37*cdf0e10cSrcweir import lib.StatusException;
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir /**
41*cdf0e10cSrcweir  * Testing <code>com.sun.star.accessibility.XAccessibleSelection</code>
42*cdf0e10cSrcweir  * interface methods :
43*cdf0e10cSrcweir  * <ul>
44*cdf0e10cSrcweir  *  <li><code>selectAccessibleChild()</code></li>
45*cdf0e10cSrcweir  *  <li><code>isAccessibleChildSelected()</code></li>
46*cdf0e10cSrcweir  *  <li><code>clearAccessibleSelection()</code></li>
47*cdf0e10cSrcweir  *  <li><code>selectAllAccessibleChildren()</code></li>
48*cdf0e10cSrcweir  *  <li><code>getSelectedAccessibleChildCount()</code></li>
49*cdf0e10cSrcweir  *  <li><code>getSelectedAccessibleChild()</code></li>
50*cdf0e10cSrcweir  *  <li><code>deselectAccessibleChild()</code></li>
51*cdf0e10cSrcweir  * </ul> <p>
52*cdf0e10cSrcweir  *
53*cdf0e10cSrcweir  * This test needs the following object relations :
54*cdf0e10cSrcweir  * <ul>
55*cdf0e10cSrcweir  *  <li> <code>'XAccessibleSelection.multiSelection'</code>
56*cdf0e10cSrcweir  *  (of type <code>Boolean</code>) <b> optional </b>:
57*cdf0e10cSrcweir  *   Indicates whether or not mutiply children could be selected.
58*cdf0e10cSrcweir  *   If the relation is <code>false</code> then more than 1 child
59*cdf0e10cSrcweir  *   couldn't be selected. </li>
60*cdf0e10cSrcweir  * </ul> <p>
61*cdf0e10cSrcweir  *
62*cdf0e10cSrcweir  * @see com.sun.star.accessibility.XAccessibleSelection
63*cdf0e10cSrcweir  */
64*cdf0e10cSrcweir public class _XAccessibleSelection extends MultiMethodTest {
65*cdf0e10cSrcweir     private static final String className = "com.sun.star.accessibility.XAccessibleSelection";
66*cdf0e10cSrcweir     public XAccessibleSelection oObj = null;
67*cdf0e10cSrcweir     XAccessibleContext xAC = null;
68*cdf0e10cSrcweir     int childCount;
69*cdf0e10cSrcweir     protected boolean multiSelection = true;
70*cdf0e10cSrcweir     protected boolean OneAlwaysSelected = false;
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir     // temporary while accessibility package is in com.sun.star
73*cdf0e10cSrcweir     protected String getTestedClassName() {
74*cdf0e10cSrcweir         return className;
75*cdf0e10cSrcweir     }
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir     /**
78*cdf0e10cSrcweir      * Retrieves the interface <code>XAccessibleContext</code>
79*cdf0e10cSrcweir      * and object relation.
80*cdf0e10cSrcweir      * @see com.sun.star.accessibility.XAccessibleContext
81*cdf0e10cSrcweir      * @see ifc.accessibility.XAccessibleContext
82*cdf0e10cSrcweir      */
83*cdf0e10cSrcweir     protected void before() {
84*cdf0e10cSrcweir         xAC = (XAccessibleContext) UnoRuntime.queryInterface(
85*cdf0e10cSrcweir                       XAccessibleContext.class, oObj);
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir         if (xAC == null) {
88*cdf0e10cSrcweir             throw new StatusException(Status.failed(
89*cdf0e10cSrcweir                                               "Couldn't query XAccessibleContext. Test must be modified"));
90*cdf0e10cSrcweir         }
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir         Boolean b = (Boolean) tEnv.getObjRelation(
93*cdf0e10cSrcweir                             "XAccessibleSelection.multiSelection");
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir         if (b != null) {
96*cdf0e10cSrcweir             multiSelection = b.booleanValue();
97*cdf0e10cSrcweir         }
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir         Boolean b2 = (Boolean) tEnv.getObjRelation(
100*cdf0e10cSrcweir                              "XAccessibleSelection.OneAlwaysSelected");
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir         if (b2 != null) {
103*cdf0e10cSrcweir             OneAlwaysSelected = b2.booleanValue();
104*cdf0e10cSrcweir         }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir         childCount = xAC.getAccessibleChildCount();
107*cdf0e10cSrcweir         log.println("Child count: " + childCount);
108*cdf0e10cSrcweir     }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir     /**
111*cdf0e10cSrcweir      * Selects accessible child with index some wrong indexes
112*cdf0e10cSrcweir      * and with legal index.
113*cdf0e10cSrcweir      * Has OK status if exception was thrown for wrong indexes
114*cdf0e10cSrcweir      * and if exception wasn't thrown for correct index.
115*cdf0e10cSrcweir      */
116*cdf0e10cSrcweir     public void _selectAccessibleChild() {
117*cdf0e10cSrcweir         boolean res = true;
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir         try {
120*cdf0e10cSrcweir             log.println("Try to select child with index " + childCount);
121*cdf0e10cSrcweir             oObj.selectAccessibleChild(childCount);
122*cdf0e10cSrcweir             log.println("Exception was expected");
123*cdf0e10cSrcweir             res = false;
124*cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
125*cdf0e10cSrcweir             log.println("Expected exception");
126*cdf0e10cSrcweir             res = true;
127*cdf0e10cSrcweir         }
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir         try {
130*cdf0e10cSrcweir             log.println("Try to select child with index -1");
131*cdf0e10cSrcweir             oObj.selectAccessibleChild(-1);
132*cdf0e10cSrcweir             log.println("Exception was expected");
133*cdf0e10cSrcweir             res = false;
134*cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
135*cdf0e10cSrcweir             log.println("Expected exception");
136*cdf0e10cSrcweir             res &= true;
137*cdf0e10cSrcweir         }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir         log.println("ChildCount: " + childCount);
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir         int usedChilds = childCount;
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir         if (childCount > 500) {
144*cdf0e10cSrcweir             log.println("Restricting to 500");
145*cdf0e10cSrcweir             usedChilds = 500;
146*cdf0e10cSrcweir         }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir         if (usedChilds > 0) {
149*cdf0e10cSrcweir             try {
150*cdf0e10cSrcweir                 for (int i = 0; i < usedChilds; i++) {
151*cdf0e10cSrcweir                     log.print("Trying to select child with index " + i + ": ");
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir                     if (isSelectable(tEnv.getTestObject(), i)) {
154*cdf0e10cSrcweir                         oObj.selectAccessibleChild(i);
155*cdf0e10cSrcweir                         log.println("OK");
156*cdf0e10cSrcweir                     } else {
157*cdf0e10cSrcweir                         log.println("Child isn't selectable");
158*cdf0e10cSrcweir                     }
159*cdf0e10cSrcweir                 }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir                 res &= true;
162*cdf0e10cSrcweir             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
163*cdf0e10cSrcweir                 log.println("Unexpected exception");
164*cdf0e10cSrcweir                 e.printStackTrace(log);
165*cdf0e10cSrcweir                 res = false;
166*cdf0e10cSrcweir             }
167*cdf0e10cSrcweir         }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir         tRes.tested("selectAccessibleChild()", res);
170*cdf0e10cSrcweir     }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     /**
173*cdf0e10cSrcweir      * Calls the method with the wrong index and with the correct index.
174*cdf0e10cSrcweir      * Has OK status if exception was thrown for wrong index and
175*cdf0e10cSrcweir      * if exception wasn't thrown for the correct index.
176*cdf0e10cSrcweir      */
177*cdf0e10cSrcweir     public void _isAccessibleChildSelected() {
178*cdf0e10cSrcweir         executeMethod("selectAccessibleChild()");
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir         boolean res = true;
181*cdf0e10cSrcweir         boolean isSelected = false;
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir         try {
184*cdf0e10cSrcweir             log.print("isAccessibleChildSelected(-1)? ");
185*cdf0e10cSrcweir             isSelected = oObj.isAccessibleChildSelected(-1);
186*cdf0e10cSrcweir             log.println(res);
187*cdf0e10cSrcweir             log.println("Exception was expected");
188*cdf0e10cSrcweir             res = false;
189*cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
190*cdf0e10cSrcweir             log.println("Expected exception");
191*cdf0e10cSrcweir             res = true;
192*cdf0e10cSrcweir         }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir         try {
195*cdf0e10cSrcweir             log.print("isAccessibleChildSelected(" + childCount + ")? ");
196*cdf0e10cSrcweir             isSelected = oObj.isAccessibleChildSelected(childCount);
197*cdf0e10cSrcweir             log.println(isSelected);
198*cdf0e10cSrcweir             log.println("Exception was expected");
199*cdf0e10cSrcweir             res = false;
200*cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
201*cdf0e10cSrcweir             log.println("Expected exception");
202*cdf0e10cSrcweir             res &= true;
203*cdf0e10cSrcweir         }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir         int SelectableChildCount = chkSelectable(tEnv.getTestObject());
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir         if (SelectableChildCount > 500) {
208*cdf0e10cSrcweir             SelectableChildCount = 500;
209*cdf0e10cSrcweir         }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir         log.println("SelectableChildCount: " + SelectableChildCount);
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir         if (SelectableChildCount > 0) {
214*cdf0e10cSrcweir             try {
215*cdf0e10cSrcweir                 oObj.selectAllAccessibleChildren();
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir                 for (int k = 0; k < SelectableChildCount; k++) {
218*cdf0e10cSrcweir                     log.println("Trying to select child with index " + k);
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir                     if (isSelectable(tEnv.getTestObject(), k)) {
221*cdf0e10cSrcweir                         oObj.selectAccessibleChild(k);
222*cdf0e10cSrcweir                         shortWait();
223*cdf0e10cSrcweir                         isSelected = oObj.isAccessibleChildSelected(k);
224*cdf0e10cSrcweir                         log.println("isAccessibleChildSelected - " +
225*cdf0e10cSrcweir                                     isSelected);
226*cdf0e10cSrcweir                         res &= isSelected;
227*cdf0e10cSrcweir                     } else {
228*cdf0e10cSrcweir                         log.println("Child isn't selectable");
229*cdf0e10cSrcweir                     }
230*cdf0e10cSrcweir                 }
231*cdf0e10cSrcweir             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
232*cdf0e10cSrcweir                 log.println("Unexpected exception");
233*cdf0e10cSrcweir                 e.printStackTrace(log);
234*cdf0e10cSrcweir                 res = false;
235*cdf0e10cSrcweir             }
236*cdf0e10cSrcweir         }
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir         tRes.tested("isAccessibleChildSelected()", res);
239*cdf0e10cSrcweir     }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir     /**
242*cdf0e10cSrcweir      * Calls the method.
243*cdf0e10cSrcweir      * Has OK status if the method <code>isAccessibleChildSelected()</code>
244*cdf0e10cSrcweir      * returned <code>false</code>.
245*cdf0e10cSrcweir      */
246*cdf0e10cSrcweir     public void _clearAccessibleSelection() {
247*cdf0e10cSrcweir         executeMethod("isAccessibleChildSelected()");
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir         boolean res = true;
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir         log.println("clearAccessibleSelection");
252*cdf0e10cSrcweir         oObj.clearAccessibleSelection();
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir         // clearAccessibleSelection() call is oneway so we need
256*cdf0e10cSrcweir         // some waiting
257*cdf0e10cSrcweir         shortWait();
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir         if ((childCount > 0) && !OneAlwaysSelected) {
260*cdf0e10cSrcweir             try {
261*cdf0e10cSrcweir                 log.print("isAccessibleChildSelected(" + (childCount - 1) +
262*cdf0e10cSrcweir                           ")? ");
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir                 boolean isSel = oObj.isAccessibleChildSelected(childCount - 1);
265*cdf0e10cSrcweir                 log.println(isSel);
266*cdf0e10cSrcweir                 res = !isSel;
267*cdf0e10cSrcweir             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
268*cdf0e10cSrcweir                 log.println("Unexpected exception");
269*cdf0e10cSrcweir                 e.printStackTrace(log);
270*cdf0e10cSrcweir                 res = false;
271*cdf0e10cSrcweir             }
272*cdf0e10cSrcweir         } else if (OneAlwaysSelected) {
273*cdf0e10cSrcweir             log.println("Can't clear selection, one child is always selected");
274*cdf0e10cSrcweir         }
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir         tRes.tested("clearAccessibleSelection()", res);
277*cdf0e10cSrcweir     }
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir     /**
280*cdf0e10cSrcweir      * Calls the method.
281*cdf0e10cSrcweir      * Has OK status if the method <code>isAccessibleChildSelected()</code>
282*cdf0e10cSrcweir      * returns <code>true</code> for first and for last accessible child
283*cdf0e10cSrcweir      * or if multiselection is not allowed.
284*cdf0e10cSrcweir      */
285*cdf0e10cSrcweir     public void _selectAllAccessibleChildren() {
286*cdf0e10cSrcweir         executeMethod("clearAccessibleSelection()");
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir         log.println("selectAllAccessibleChildren...");
289*cdf0e10cSrcweir         oObj.selectAllAccessibleChildren();
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir         // selectAllAccessibleChildren() call is oneway so we need
293*cdf0e10cSrcweir         // some waiting
294*cdf0e10cSrcweir         shortWait();
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir         boolean res = true;
297*cdf0e10cSrcweir         boolean isSelected = true;
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir         int SelectableChildCount = chkSelectable(tEnv.getTestObject());
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir         if ((SelectableChildCount > 0) && multiSelection) {
302*cdf0e10cSrcweir             try {
303*cdf0e10cSrcweir                 log.print("isAccessibleChildSelected(1)? ");
304*cdf0e10cSrcweir                 isSelected = oObj.isAccessibleChildSelected(1);
305*cdf0e10cSrcweir                 log.println(isSelected);
306*cdf0e10cSrcweir                 res = isSelected;
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir                 log.print("isAccessibleChildSelected(" + (childCount - 1) +
309*cdf0e10cSrcweir                           ")? ");
310*cdf0e10cSrcweir                 isSelected = oObj.isAccessibleChildSelected(childCount - 1);
311*cdf0e10cSrcweir                 log.println(isSelected);
312*cdf0e10cSrcweir                 res &= isSelected;
313*cdf0e10cSrcweir             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
314*cdf0e10cSrcweir                 log.println("Unexpected exception");
315*cdf0e10cSrcweir                 e.printStackTrace(log);
316*cdf0e10cSrcweir                 res = false;
317*cdf0e10cSrcweir             }
318*cdf0e10cSrcweir         }
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir         tRes.tested("selectAllAccessibleChildren()", res);
321*cdf0e10cSrcweir     }
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir     /**
324*cdf0e10cSrcweir      * Calls the method. Clears accessible selection and calls the method again.
325*cdf0e10cSrcweir      * <p>
326*cdf0e10cSrcweir      * Has OK status if the method returns number equal to number of accessible
327*cdf0e10cSrcweir      * child count after first call if multiselection allowed, or
328*cdf0e10cSrcweir      * 1 returned if multiselection not allowed.
329*cdf0e10cSrcweir      * And if the method returns a zero after clearing selection.
330*cdf0e10cSrcweir      */
331*cdf0e10cSrcweir     public void _getSelectedAccessibleChildCount() {
332*cdf0e10cSrcweir         log.println("getSelectedAccessibleChildCount():");
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir         if (multiSelection) {
335*cdf0e10cSrcweir             oObj.selectAllAccessibleChildren();
336*cdf0e10cSrcweir         } else {
337*cdf0e10cSrcweir             int usedChilds = childCount;
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir             if (childCount > 500) {
340*cdf0e10cSrcweir                 log.println("Restricting to 500");
341*cdf0e10cSrcweir                 usedChilds = 500;
342*cdf0e10cSrcweir             }
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir             if (usedChilds > 0) {
345*cdf0e10cSrcweir                 try {
346*cdf0e10cSrcweir                     for (int i = 0; i < usedChilds; i++) {
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir                         if (isSelectable(tEnv.getTestObject(), i)) {
349*cdf0e10cSrcweir                             log.print("Trying to select child with index "+i+": ");
350*cdf0e10cSrcweir                             oObj.selectAccessibleChild(i);
351*cdf0e10cSrcweir                             long curtime = System.currentTimeMillis();
352*cdf0e10cSrcweir                             long checktime = System.currentTimeMillis();
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir                             while (!oObj.isAccessibleChildSelected(i) && (checktime-curtime<5000)) {
355*cdf0e10cSrcweir                                 checktime = System.currentTimeMillis();
356*cdf0e10cSrcweir                             }
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir                             log.println("OK");
359*cdf0e10cSrcweir                         }
360*cdf0e10cSrcweir                     }
361*cdf0e10cSrcweir                 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
362*cdf0e10cSrcweir                     log.println("Unexpected exception");
363*cdf0e10cSrcweir                     e.printStackTrace(log);
364*cdf0e10cSrcweir                 }
365*cdf0e10cSrcweir             }
366*cdf0e10cSrcweir         }
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir         int sCount = chkSelectable(tEnv.getTestObject());
369*cdf0e10cSrcweir         log.println("Found " + sCount + " selectable Childs");
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir         int selectedCount = oObj.getSelectedAccessibleChildCount();
372*cdf0e10cSrcweir         log.println("After selecting all accessible " + selectedCount +
373*cdf0e10cSrcweir                     " are selected");
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir         boolean res = true;
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir         if (multiSelection) {
378*cdf0e10cSrcweir             res &= (selectedCount == sCount);
379*cdf0e10cSrcweir         } else {
380*cdf0e10cSrcweir             res &= (selectedCount == 1);
381*cdf0e10cSrcweir         }
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir         log.println("clearAccessibleSelection...");
384*cdf0e10cSrcweir         oObj.clearAccessibleSelection();
385*cdf0e10cSrcweir         log.print("getSelectedAccessibleChildCount: ");
386*cdf0e10cSrcweir         selectedCount = oObj.getSelectedAccessibleChildCount();
387*cdf0e10cSrcweir         log.println(selectedCount);
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir         if (OneAlwaysSelected) {
390*cdf0e10cSrcweir             res &= (selectedCount == 1);
391*cdf0e10cSrcweir         } else {
392*cdf0e10cSrcweir             res &= (selectedCount == 0);
393*cdf0e10cSrcweir         }
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir         tRes.tested("getSelectedAccessibleChildCount()", res);
396*cdf0e10cSrcweir     }
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir     /**
399*cdf0e10cSrcweir      * Calls the method with wrong and correct indexes.
400*cdf0e10cSrcweir      * Has OK status if exception was thrown for the wrong indexes,
401*cdf0e10cSrcweir      * if exception wasn't thrown for the correct index and
402*cdf0e10cSrcweir      * if the method have returned a not null for the correct index.
403*cdf0e10cSrcweir      */
404*cdf0e10cSrcweir     public void _getSelectedAccessibleChild() {
405*cdf0e10cSrcweir         executeMethod("getSelectedAccessibleChildCount()");
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir         boolean res = true;
408*cdf0e10cSrcweir         int selectedCount = oObj.getSelectedAccessibleChildCount();
409*cdf0e10cSrcweir         log.println("getSelectedAccessibleChildCount: " + selectedCount);
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir         try {
412*cdf0e10cSrcweir             log.println("getSelectedAccessibleChild(-1)");
413*cdf0e10cSrcweir             oObj.getSelectedAccessibleChild(-1);
414*cdf0e10cSrcweir             log.println("Exception was expected");
415*cdf0e10cSrcweir             res = false;
416*cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
417*cdf0e10cSrcweir             log.println("Expected exception");
418*cdf0e10cSrcweir             res = true;
419*cdf0e10cSrcweir         }
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir         try {
422*cdf0e10cSrcweir             log.println("getSelectedAccessibleChild(" + selectedCount + ")");
423*cdf0e10cSrcweir             oObj.getSelectedAccessibleChild(selectedCount);
424*cdf0e10cSrcweir             log.println("Exception was expected");
425*cdf0e10cSrcweir             res &= false;
426*cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
427*cdf0e10cSrcweir             log.println("Expected exception");
428*cdf0e10cSrcweir             res &= true;
429*cdf0e10cSrcweir         }
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir         int SelectableChildCount = chkSelectable(tEnv.getTestObject());
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir         if (SelectableChildCount > 500) {
434*cdf0e10cSrcweir             SelectableChildCount = 500;
435*cdf0e10cSrcweir         }
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir         if (SelectableChildCount > 0) {
438*cdf0e10cSrcweir             int k = 0;
439*cdf0e10cSrcweir             try {
440*cdf0e10cSrcweir                 for (k = 0; k < SelectableChildCount; k++) {
441*cdf0e10cSrcweir                     log.println("Trying to select child with index " + k);
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir                     if (isSelectable(tEnv.getTestObject(), k)) {
444*cdf0e10cSrcweir                         oObj.selectAccessibleChild(k);
445*cdf0e10cSrcweir                         shortWait();
446*cdf0e10cSrcweir                         log.println("selected child count: " +
447*cdf0e10cSrcweir                                     oObj.getSelectedAccessibleChildCount());
448*cdf0e10cSrcweir                         XAccessible selChild = oObj.getSelectedAccessibleChild(0);
449*cdf0e10cSrcweir                         res &= (selChild != null);
450*cdf0e10cSrcweir                         log.println("valid child - " + (selChild != null));
451*cdf0e10cSrcweir                     } else {
452*cdf0e10cSrcweir                         log.println("Child isn't selectable");
453*cdf0e10cSrcweir                     }
454*cdf0e10cSrcweir                 }
455*cdf0e10cSrcweir             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
456*cdf0e10cSrcweir                 log.println("Unexpected exception: Last relevant calls:\n " +
457*cdf0e10cSrcweir                             "\toObj.selectAccessibleChild("+k+")\n" +
458*cdf0e10cSrcweir                             "\toObj.getSelectedAccessibleChild(0)");
459*cdf0e10cSrcweir                 e.printStackTrace(log);
460*cdf0e10cSrcweir                 res = false;
461*cdf0e10cSrcweir             }
462*cdf0e10cSrcweir         }
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir         tRes.tested("getSelectedAccessibleChild()", res);
465*cdf0e10cSrcweir     }
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir     /**
468*cdf0e10cSrcweir      * Calls the method with wrong and with correct indexes.
469*cdf0e10cSrcweir      * Has OK status if exceptions were thrown for the calls with
470*cdf0e10cSrcweir      * the wrong indexes, if exception wasn't thrown for the call
471*cdf0e10cSrcweir      * with correct index and if number of selected child was
472*cdf0e10cSrcweir      * decreased after the correct call.
473*cdf0e10cSrcweir      */
474*cdf0e10cSrcweir     public void _deselectAccessibleChild() {
475*cdf0e10cSrcweir         executeMethod("getSelectedAccessibleChild()");
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir         boolean res = true;
478*cdf0e10cSrcweir         int selCount = oObj.getSelectedAccessibleChildCount();
479*cdf0e10cSrcweir         log.println("getSelectedAccessibleChildCount():" + selCount);
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir         try {
482*cdf0e10cSrcweir             log.println("deselectAccessibleChild(-1)");
483*cdf0e10cSrcweir             oObj.deselectAccessibleChild(-1);
484*cdf0e10cSrcweir             log.println("Exception was expected");
485*cdf0e10cSrcweir             res = false;
486*cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
487*cdf0e10cSrcweir             log.println("Expected exception");
488*cdf0e10cSrcweir             res &= true;
489*cdf0e10cSrcweir         }
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir         try {
492*cdf0e10cSrcweir             log.println("deselectAccessibleChild(" + (childCount + 1) + ")");
493*cdf0e10cSrcweir             oObj.deselectAccessibleChild(childCount + 1);
494*cdf0e10cSrcweir             log.println("Exception was expected");
495*cdf0e10cSrcweir             res = false;
496*cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
497*cdf0e10cSrcweir             log.println("Expected exception");
498*cdf0e10cSrcweir             res &= true;
499*cdf0e10cSrcweir         }
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir         log.println("#################");
502*cdf0e10cSrcweir         log.println("Selecting all accessible");
503*cdf0e10cSrcweir         oObj.selectAllAccessibleChildren();
504*cdf0e10cSrcweir         selCount = oObj.getSelectedAccessibleChildCount();
505*cdf0e10cSrcweir         log.println("getSelectedAccessibleChildCount():" + selCount);
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir         if ((childCount > 0) && (selCount > 0)) {
508*cdf0e10cSrcweir             try {
509*cdf0e10cSrcweir                 int maxCount = chkSelectable(tEnv.getTestObject());
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir                 if (childCount > 100) {
512*cdf0e10cSrcweir                     maxCount = 100;
513*cdf0e10cSrcweir                 }
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir                 for (int k = 0; k < maxCount; k++) {
516*cdf0e10cSrcweir                     log.println("deselectAccessibleChild(" + k + ")");
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir                     if (oObj.isAccessibleChildSelected(k)) {
519*cdf0e10cSrcweir                         oObj.deselectAccessibleChild(k);
520*cdf0e10cSrcweir                     }
521*cdf0e10cSrcweir                 }
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir                 int newSelCount = oObj.getSelectedAccessibleChildCount();
524*cdf0e10cSrcweir                 log.println("getSelectedAccessibleChildCount():" +
525*cdf0e10cSrcweir                             newSelCount);
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir                 if (OneAlwaysSelected && (selCount == 1)) {
528*cdf0e10cSrcweir                     log.println("One Child is always selected");
529*cdf0e10cSrcweir                     res &= true;
530*cdf0e10cSrcweir                 } else {
531*cdf0e10cSrcweir                     res &= (selCount > newSelCount);
532*cdf0e10cSrcweir                 }
533*cdf0e10cSrcweir             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
534*cdf0e10cSrcweir                 log.println("Unexpected exception");
535*cdf0e10cSrcweir                 e.printStackTrace(log);
536*cdf0e10cSrcweir                 res = false;
537*cdf0e10cSrcweir             }
538*cdf0e10cSrcweir         }
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir         tRes.tested("deselectAccessibleChild()", res);
541*cdf0e10cSrcweir     }
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir     protected static int chkSelectable(Object Testcase) {
544*cdf0e10cSrcweir         int ret = 0;
545*cdf0e10cSrcweir         XAccessibleContext accCon = (XAccessibleContext) UnoRuntime.queryInterface(
546*cdf0e10cSrcweir                                             XAccessibleContext.class, Testcase);
547*cdf0e10cSrcweir         int cc = accCon.getAccessibleChildCount();
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir         if (cc > 500) {
550*cdf0e10cSrcweir             return cc;
551*cdf0e10cSrcweir         }
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir         for (int i = 0; i < cc; i++) {
554*cdf0e10cSrcweir             try {
555*cdf0e10cSrcweir                 if (accCon.getAccessibleChild(i).getAccessibleContext()
556*cdf0e10cSrcweir                           .getAccessibleStateSet()
557*cdf0e10cSrcweir                           .contains(com.sun.star.accessibility.AccessibleStateType.SELECTABLE)) {
558*cdf0e10cSrcweir                     ret = ret + 1;
559*cdf0e10cSrcweir                     System.out.println("Child " + i + " is selectable");
560*cdf0e10cSrcweir                 }
561*cdf0e10cSrcweir             } catch (com.sun.star.lang.IndexOutOfBoundsException iab) {
562*cdf0e10cSrcweir             }
563*cdf0e10cSrcweir         }
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir         return ret;
566*cdf0e10cSrcweir     }
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir     protected static boolean isSelectable(Object Testcase, int index) {
569*cdf0e10cSrcweir         XAccessibleContext accCon = (XAccessibleContext) UnoRuntime.queryInterface(
570*cdf0e10cSrcweir                                             XAccessibleContext.class, Testcase);
571*cdf0e10cSrcweir         boolean res = false;
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir         try {
574*cdf0e10cSrcweir             if (accCon.getAccessibleChild(index).getAccessibleContext()
575*cdf0e10cSrcweir                       .getAccessibleStateSet()
576*cdf0e10cSrcweir                       .contains(com.sun.star.accessibility.AccessibleStateType.SELECTABLE)) {
577*cdf0e10cSrcweir                 res = true;
578*cdf0e10cSrcweir             }
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir             //selecting menuitems or the separator will lead to closing the menu
581*cdf0e10cSrcweir             if ((accCon.getAccessibleChild(index).getAccessibleContext()
582*cdf0e10cSrcweir                        .getAccessibleRole() == AccessibleRole.MENU_ITEM) ||
583*cdf0e10cSrcweir                     (accCon.getAccessibleChild(index).getAccessibleContext()
584*cdf0e10cSrcweir                            .getAccessibleRole() == AccessibleRole.SEPARATOR)) {
585*cdf0e10cSrcweir                 res = false;
586*cdf0e10cSrcweir             }
587*cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
588*cdf0e10cSrcweir             System.out.println("Exception while checking for selectability");
589*cdf0e10cSrcweir         }
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir         return res;
592*cdf0e10cSrcweir     }
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir     private void shortWait() {
595*cdf0e10cSrcweir         try {
596*cdf0e10cSrcweir             Thread.sleep(500);
597*cdf0e10cSrcweir         } catch (InterruptedException ex) {
598*cdf0e10cSrcweir         }
599*cdf0e10cSrcweir     }
600*cdf0e10cSrcweir }