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 .
20 import com
.sun
.star
.accessibility
.AccessibleRole
;
21 import com
.sun
.star
.accessibility
.XAccessible
;
22 import com
.sun
.star
.accessibility
.XAccessibleAction
;
23 import com
.sun
.star
.accessibility
.XAccessibleContext
;
24 import com
.sun
.star
.accessibility
.XAccessibleSelection
;
25 import com
.sun
.star
.awt
.XExtendedToolkit
;
26 import com
.sun
.star
.awt
.XWindow
;
27 import com
.sun
.star
.beans
.PropertyValue
;
28 import com
.sun
.star
.frame
.XController
;
29 import com
.sun
.star
.frame
.XDesktop
;
30 import com
.sun
.star
.frame
.XDispatch
;
31 import com
.sun
.star
.frame
.XDispatchProvider
;
32 import com
.sun
.star
.frame
.XModel
;
33 import com
.sun
.star
.lang
.XMultiServiceFactory
;
34 import com
.sun
.star
.text
.XTextDocument
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
36 import com
.sun
.star
.uno
.XInterface
;
37 import com
.sun
.star
.util
.URL
;
38 import com
.sun
.star
.util
.XURLTransformer
;
40 import java
.io
.PrintWriter
;
42 import lib
.StatusException
;
44 import lib
.TestEnvironment
;
45 import lib
.TestParameters
;
47 import util
.AccessibilityTools
;
48 import util
.DesktopTools
;
49 import util
.SOfficeFactory
;
53 * Test for object that implements the following interfaces :
56 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
58 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
61 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
63 * ::com::sun::star::accessibility::XAccessibleExtendedComponent
66 * ::com::sun::star::accessibility::XAccessibleSelection
70 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
71 * @see com.sun.star.accessibility.XAccessibleContext
72 * @see com.sun.star.accessibility.XAccessibleComponent
73 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
74 * @see com.sun.star.accessibility.XAccessibleSelection
75 * @see ifc.accessibility._XAccessibleEventBroadcaster
76 * @see ifc.accessibility._XAccessibleContext
77 * @see ifc.accessibility._XAccessibleComponent
78 * @see ifc.accessibility._XAccessibleExtendedComponent
79 * @see ifc.accessibility._XAccessibleSelection
81 public class AccessibleTabControl
extends TestCase
{
82 private static XTextDocument xTextDoc
;
83 private static XAccessibleAction accCloseButton
= null;
86 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
88 protected void initialize(TestParameters Param
, PrintWriter log
) {
89 UnoRuntime
.queryInterface(XDesktop
.class,
90 DesktopTools
.createDesktop(
91 (XMultiServiceFactory
) Param
.getMSF()));
95 * Closes an InsertFields dialog, disposes the document, if exists, created in
96 * <code>createTestEnvironment</code> method.
98 protected void cleanup(TestParameters Param
, PrintWriter log
) {
100 if (accCloseButton
!= null) {
101 log
.println("closing InsertFields Dialog");
102 accCloseButton
.doAccessibleAction(0);
104 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
105 e
.printStackTrace(log
);
108 log
.println("disposing xTextDoc");
110 if (xTextDoc
!= null) {
111 util
.DesktopTools
.closeDoc(xTextDoc
);
116 * Creates a text document, opens an InsertField dialog.
117 * Then obtains an accessible object with
118 * the role <code>AccessibleRole.PAGETABLIST</code>.
119 * Object relations created :
121 * <li> <code>'EventProducer'</code> for
122 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
123 * selects items </li>
124 * <li> <code>'XAccessibleSelection.multiSelection'</code>
125 * of type <code>Boolean</code> for
126 * {@link ifc.accessibility._XAccessibleSelection}:
127 * indicates that component supports single selection mode.</li>
130 * @param tParam test parameters
131 * @param log writer to log information while testing
133 * @see com.sun.star.awt.Toolkit
134 * @see com.sun.star.accessibility.AccessibleRole
135 * @see ifc.accessibility._XAccessibleEventBroadcaster
136 * @see ifc.accessibility._XAccessibleSelection
137 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
138 * @see com.sun.star.accessibility.XAccessibleSelection
140 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
142 log
.println("creating a test environment");
144 if (xTextDoc
!= null) {
145 util
.DesktopTools
.closeDoc(xTextDoc
);
148 // get a soffice factory object
149 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
150 (XMultiServiceFactory
) tParam
.getMSF());
153 log
.println("creating a text document");
154 xTextDoc
= SOF
.createTextDoc(null);
155 } catch (com
.sun
.star
.uno
.Exception e
) {
156 // Some exception occurs.FAILED
157 e
.printStackTrace(log
);
158 throw new StatusException("Couldn't create document", e
);
163 XModel aModel1
= UnoRuntime
.queryInterface(XModel
.class,
166 XController secondController
= aModel1
.getCurrentController();
168 XDispatchProvider aProv
= UnoRuntime
.queryInterface(
169 XDispatchProvider
.class,
172 XURLTransformer urlTransf
= null;
175 XInterface transf
= (XInterface
) ((XMultiServiceFactory
) tParam
.getMSF()).createInstance(
176 "com.sun.star.util.URLTransformer");
177 urlTransf
= UnoRuntime
.queryInterface(
178 XURLTransformer
.class, transf
);
179 } catch (com
.sun
.star
.uno
.Exception e
) {
180 e
.printStackTrace(log
);
181 throw new StatusException("Couldn't create URLTransformer", e
);
184 XDispatch getting
= null;
185 log
.println("opening InsertField dialog");
187 URL
[] url
= new URL
[1];
189 url
[0].Complete
= ".uno:InsertField";
190 urlTransf
.parseStrict(url
);
191 getting
= aProv
.queryDispatch(url
[0], "", 0);
193 PropertyValue
[] noArgs
= new PropertyValue
[0];
194 getting
.dispatch(url
[0], noArgs
);
198 XInterface oObj
= null;
201 oObj
= (XInterface
) ((XMultiServiceFactory
) tParam
.getMSF()).createInstance(
202 "com.sun.star.awt.Toolkit");
203 } catch (com
.sun
.star
.uno
.Exception e
) {
204 log
.println("Couldn't get toolkit");
205 e
.printStackTrace(log
);
206 throw new StatusException("Couldn't get toolkit", e
);
209 XExtendedToolkit tk
= UnoRuntime
.queryInterface(
210 XExtendedToolkit
.class, oObj
);
212 AccessibilityTools at
= new AccessibilityTools();
216 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
217 tk
.getActiveTopWindow());
219 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
221 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
222 AccessibleRole
.PAGE_TAB_LIST
);
224 XAccessibleContext closeButton
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
225 AccessibleRole
.PUSH_BUTTON
,
228 accCloseButton
= UnoRuntime
.queryInterface(
229 XAccessibleAction
.class, closeButton
);
231 log
.println("ImplementationName: " + util
.utils
.getImplName(oObj
));
233 TestEnvironment tEnv
= new TestEnvironment(oObj
);
235 final XAccessibleSelection selection
= UnoRuntime
.queryInterface(
236 XAccessibleSelection
.class,
239 tEnv
.addObjRelation("EventProducer",
240 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
241 public void fireEvent() {
243 selection
.selectAccessibleChild(1);
244 selection
.selectAccessibleChild(0);
245 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
250 tEnv
.addObjRelation("XAccessibleSelection.OneAlwaysSelected",
253 tEnv
.addObjRelation("XAccessibleSelection.multiSelection",
260 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
263 private void shortWait() {
266 } catch (InterruptedException e
) {
267 System
.out
.println("While waiting :" + e
);