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 java
.io
.PrintWriter
;
22 import lib
.StatusException
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.AccessibilityTools
;
27 import util
.DesktopTools
;
28 import util
.SOfficeFactory
;
30 import com
.sun
.star
.accessibility
.AccessibleRole
;
31 import com
.sun
.star
.accessibility
.XAccessible
;
32 import com
.sun
.star
.accessibility
.XAccessibleAction
;
33 import com
.sun
.star
.accessibility
.XAccessibleContext
;
34 import com
.sun
.star
.accessibility
.XAccessibleSelection
;
35 import com
.sun
.star
.awt
.XExtendedToolkit
;
36 import com
.sun
.star
.awt
.XWindow
;
37 import com
.sun
.star
.beans
.PropertyValue
;
38 import com
.sun
.star
.frame
.XController
;
39 import com
.sun
.star
.frame
.XDesktop
;
40 import com
.sun
.star
.frame
.XDispatch
;
41 import com
.sun
.star
.frame
.XDispatchProvider
;
42 import com
.sun
.star
.frame
.XModel
;
43 import com
.sun
.star
.text
.XTextDocument
;
44 import com
.sun
.star
.uno
.UnoRuntime
;
45 import com
.sun
.star
.uno
.XInterface
;
46 import com
.sun
.star
.util
.URL
;
47 import com
.sun
.star
.util
.XURLTransformer
;
51 * Test for object that implements the following interfaces :
54 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
56 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
59 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
61 * ::com::sun::star::accessibility::XAccessibleSelection</code></li>
64 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
65 * @see com.sun.star.accessibility.XAccessibleContext
66 * @see com.sun.star.accessibility.XAccessibleComponent
67 * @see com.sun.star.accessibility.XAccessibleSelection
68 * @see ifc.accessibility._XAccessibleEventBroadcaster
69 * @see ifc.accessibility._XAccessibleContext
70 * @see ifc.accessibility._XAccessibleComponent
71 * @see ifc.accessibility._XAccessibleSelection
73 public class AccessibleIconChoiceCtrl
extends TestCase
{
74 static XDesktop the_Desk
;
75 static XTextDocument xTextDoc
;
76 static XAccessibleAction accCloseButton
= null;
79 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
82 protected void initialize(TestParameters Param
, PrintWriter log
) {
83 the_Desk
= UnoRuntime
.queryInterface(XDesktop
.class,
84 DesktopTools
.createDesktop(
89 * Closes the Hyperlink dialog.
90 * Disposes the document, if exists, created in
91 * <code>createTestEnvironment</code> method.
94 protected void cleanup(TestParameters Param
, PrintWriter log
) {
95 log
.println("closing HyperlinkDialog");
98 if (accCloseButton
!= null) {
99 accCloseButton
.doAccessibleAction(0);
101 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
102 e
.printStackTrace(log
);
105 log
.println("disposing xTextDoc");
107 if (xTextDoc
!= null) {
113 * Creates a text document. Opens the Hyperlink dialog.
114 * Creates an instance of the service
115 * <code>com.sun.star.awt.Toolkit</code> and gets active top window.
116 * Then obtains an accessible object with the role
117 * <code>AccessibleRole.TREE</code>.
118 * Object relations created :
120 * <li> <code>'EventProducer'</code> for
121 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
122 * method <code>fireEvent()</code> selects accessible children
126 * @param tParam test parameters
127 * @param log writer to log information while testing
129 * @see com.sun.star.awt.Toolkit
130 * @see com.sun.star.accessibility.AccessibleRole
131 * @see ifc.accessibility._XAccessibleEventBroadcaster
132 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
135 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
137 log
.println("creating a test environment");
139 if (xTextDoc
!= null) {
143 // get a soffice factory object
144 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
147 log
.println("creating a text document");
148 xTextDoc
= SOF
.createTextDoc(null);
149 } catch (com
.sun
.star
.uno
.Exception e
) {
150 // Some exception occurs.FAILED
151 e
.printStackTrace(log
);
152 throw new StatusException("Couldn't create document", e
);
155 util
.utils
.pause(5000);
157 XModel aModel1
= UnoRuntime
.queryInterface(XModel
.class,
160 XController secondController
= aModel1
.getCurrentController();
162 XDispatchProvider aProv
= UnoRuntime
.queryInterface(
163 XDispatchProvider
.class,
166 XURLTransformer urlTransf
= null;
169 XInterface transf
= (XInterface
) tParam
.getMSF()
170 .createInstance("com.sun.star.util.URLTransformer");
171 urlTransf
= UnoRuntime
.queryInterface(
172 XURLTransformer
.class, transf
);
173 } catch (com
.sun
.star
.uno
.Exception e
) {
174 e
.printStackTrace(log
);
175 throw new StatusException("Couldn't create URLTransformer", e
);
178 XDispatch getting
= null;
179 log
.println("opening HyperlinkDialog");
181 URL
[] url
= new URL
[1];
183 url
[0].Complete
= ".uno:HyperlinkDialog";
184 urlTransf
.parseStrict(url
);
185 getting
= aProv
.queryDispatch(url
[0], "", 0);
187 PropertyValue
[] noArgs
= new PropertyValue
[0];
188 getting
.dispatch(url
[0], noArgs
);
190 util
.utils
.pause(5000);
192 XInterface oObj
= null;
195 oObj
= (XInterface
) tParam
.getMSF()
196 .createInstance("com.sun.star.awt.Toolkit");
197 } catch (com
.sun
.star
.uno
.Exception e
) {
198 log
.println("Couldn't get toolkit");
199 e
.printStackTrace(log
);
200 throw new StatusException("Couldn't get toolkit", e
);
203 XExtendedToolkit tk
= UnoRuntime
.queryInterface(
204 XExtendedToolkit
.class, oObj
);
206 util
.utils
.pause(5000);
208 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
209 tk
.getActiveTopWindow());
211 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
213 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.TREE
);
215 XAccessibleContext closeButton
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
216 AccessibleRole
.PUSH_BUTTON
,
219 accCloseButton
= UnoRuntime
.queryInterface(
220 XAccessibleAction
.class, closeButton
);
222 log
.println("ImplementationName: " + util
.utils
.getImplName(oObj
));
224 TestEnvironment tEnv
= new TestEnvironment(oObj
);
225 tEnv
.addObjRelation("XAccessibleSelection.multiSelection",
227 tEnv
.addObjRelation("XAccessibleSelection.OneAlwaysSelected",
230 String
[] expectedStateNames
= new String
[] {
231 "com.sun.star.accessibility.AccessibleStateType.ENABLED",
232 "com.sun.star.accessibility.AccessibleStateType.FOCUSABLE",
233 "com.sun.star.accessibility.AccessibleStateType.SHOWING",
234 "com.sun.star.accessibility.AccessibleStateType.VISIBLE",
235 "com.sun.star.accessibility.AccessibleStateType.MANAGES_DESCENDANTS",
238 short[] expectedStates
= new short[] {
239 com
.sun
.star
.accessibility
.AccessibleStateType
.ENABLED
,
240 com
.sun
.star
.accessibility
.AccessibleStateType
.FOCUSABLE
,
241 com
.sun
.star
.accessibility
.AccessibleStateType
.SHOWING
,
242 com
.sun
.star
.accessibility
.AccessibleStateType
.VISIBLE
,
243 com
.sun
.star
.accessibility
.AccessibleStateType
.MANAGES_DESCENDANTS
,
246 tEnv
.addObjRelation("expectedStateNames", expectedStateNames
);
247 tEnv
.addObjRelation("expectedStates", expectedStates
);
249 final XAccessibleSelection selection
= UnoRuntime
.queryInterface(
250 XAccessibleSelection
.class,
253 tEnv
.addObjRelation("EventProducer",
254 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
255 public void fireEvent() {
257 selection
.selectAccessibleChild(1);
258 selection
.selectAccessibleChild(0);
259 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {