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
.XAccessibleComponent
;
24 import com
.sun
.star
.accessibility
.XAccessibleContext
;
25 import com
.sun
.star
.accessibility
.XAccessibleSelection
;
26 import com
.sun
.star
.accessibility
.XAccessibleValue
;
27 import com
.sun
.star
.awt
.XExtendedToolkit
;
28 import com
.sun
.star
.awt
.XWindow
;
29 import com
.sun
.star
.beans
.PropertyValue
;
30 import com
.sun
.star
.frame
.XController
;
31 import com
.sun
.star
.frame
.XDesktop
;
32 import com
.sun
.star
.frame
.XDispatch
;
33 import com
.sun
.star
.frame
.XDispatchProvider
;
34 import com
.sun
.star
.frame
.XModel
;
35 import com
.sun
.star
.text
.XTextDocument
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
37 import com
.sun
.star
.uno
.XInterface
;
38 import com
.sun
.star
.util
.URL
;
39 import com
.sun
.star
.util
.XURLTransformer
;
41 import java
.io
.PrintWriter
;
43 import lib
.StatusException
;
45 import lib
.TestEnvironment
;
46 import lib
.TestParameters
;
48 import util
.AccessibilityTools
;
49 import util
.DesktopTools
;
50 import util
.SOfficeFactory
;
54 * Test for object that implements the following interfaces :
57 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
59 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
62 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
64 * ::com::sun::star::accessibility::XAccessibleExtendedComponent
67 * ::com::sun::star::accessibility::XAccessibleValue</code></li>
69 * ::com::sun::star::accessibility::XAccessibleText</code></li>
72 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
73 * @see com.sun.star.accessibility.XAccessibleContext
74 * @see com.sun.star.accessibility.XAccessibleComponent
75 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
76 * @see com.sun.star.accessibility.XAccessibleValue
77 * @see com.sun.star.accessibility.XAccessibleText
78 * @see ifc.accessibility._XAccessibleEventBroadcaster
79 * @see ifc.accessibility._XAccessibleContext
80 * @see ifc.accessibility._XAccessibleComponent
81 * @see ifc.accessibility._XAccessibleExtendedComponent
82 * @see ifc.accessibility._XAccessibleValue
83 * @see ifc.accessibility._XAccessibleText
85 public class AccessibleRadioButton
extends TestCase
{
86 private static XTextDocument xTextDoc
;
87 private static XAccessibleAction accCloseButton
;
91 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
94 protected void initialize(TestParameters Param
, PrintWriter log
) {
95 UnoRuntime
.queryInterface(XDesktop
.class,
96 DesktopTools
.createDesktop(
101 * Closes a Hyperlink dialog, disposes the document, if exists, created in
102 * <code>createTestEnvironment</code> method.
105 protected void cleanup(TestParameters Param
, PrintWriter log
) {
107 if (accCloseButton
!= null) {
108 log
.println("closing HyperlinkDialog");
109 accCloseButton
.doAccessibleAction(0);
111 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
112 e
.printStackTrace(log
);
113 } catch (com
.sun
.star
.lang
.DisposedException de
) {
114 log
.println("Already disposed");
117 log
.println("disposing xTextDoc");
119 if (xTextDoc
!= null) {
125 * Creates a text document, opens a hypelink dialog, selects a first item
127 * Then obtains an accessible object with
128 * the role <code>AccessibleRole.RADIOBUTTON</code> with the name <code>
130 * Object relations created :
132 * <li> <code>'EventProducer'</code> for
133 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
135 * <li> <code>'XAccessibleText.Text'</code> for
136 * {@link ifc.accessibility._XAccessibleText}:
137 * the text of the component </li>
138 * <li> <code>'XAccessibleValue.anotherFromGroup'</code> for
139 * {@link ifc.accessibility._XAccessibleValue}:
140 * <code>'FTP'</code> button </li>
143 * @param tParam test parameters
144 * @param log writer to log information while testing
146 * @see com.sun.star.awt.Toolkit
147 * @see com.sun.star.accessibility.AccessibleRole
148 * @see ifc.accessibility._XAccessibleEventBroadcaster
149 * @see ifc.accessibility._XAccessibleText
150 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
151 * @see com.sun.star.accessibility.XAccessibleText
154 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
156 log
.println("creating a test environment");
158 // get a soffice factory object
159 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
163 log
.println("creating a text document");
164 xTextDoc
= SOF
.createTextDoc(null);
165 } catch (com
.sun
.star
.uno
.Exception e
) {
166 // Some exception occurs.FAILED
167 e
.printStackTrace(log
);
168 throw new StatusException("Couldn't create document", e
);
171 util
.utils
.pause(2000);
173 XModel aModel1
= UnoRuntime
.queryInterface(XModel
.class,
176 XController secondController
= aModel1
.getCurrentController();
178 XDispatchProvider aProv
= UnoRuntime
.queryInterface(
179 XDispatchProvider
.class,
182 XURLTransformer urlTransf
= null;
185 XInterface transf
= (XInterface
) tParam
.getMSF().createInstance(
186 "com.sun.star.util.URLTransformer");
187 urlTransf
= UnoRuntime
.queryInterface(
188 XURLTransformer
.class, transf
);
189 } catch (com
.sun
.star
.uno
.Exception e
) {
190 e
.printStackTrace(log
);
191 throw new StatusException("Couldn't create URLTransformer", e
);
194 XDispatch getting
= null;
195 log
.println("opening HyperlinkDialog");
197 URL
[] url
= new URL
[1];
199 url
[0].Complete
= ".uno:HyperlinkDialog";
200 urlTransf
.parseStrict(url
);
201 getting
= aProv
.queryDispatch(url
[0], "", 0);
203 PropertyValue
[] noArgs
= new PropertyValue
[0];
204 getting
.dispatch(url
[0], noArgs
);
206 util
.utils
.pause(2000);
208 XInterface oObj
= null;
211 oObj
= (XInterface
) tParam
.getMSF().createInstance(
212 "com.sun.star.awt.Toolkit");
213 } catch (com
.sun
.star
.uno
.Exception e
) {
214 log
.println("Couldn't get toolkit");
215 e
.printStackTrace(log
);
216 throw new StatusException("Couldn't get toolkit", e
);
219 XExtendedToolkit tk
= UnoRuntime
.queryInterface(
220 XExtendedToolkit
.class, oObj
);
222 util
.utils
.pause(2000);
224 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
225 tk
.getActiveTopWindow());
227 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
229 XAccessibleContext iconChoiceCtrl
= AccessibilityTools
.getAccessibleObjectForRole(
230 xRoot
, AccessibleRole
.TREE
,
231 "IconChoiceControl");
233 XAccessibleSelection sel
= UnoRuntime
.queryInterface(
234 XAccessibleSelection
.class,
238 sel
.selectAccessibleChild(0);
239 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
240 log
.println("Unexpected exception");
241 e
.printStackTrace(log
);
244 AccessibilityTools
.printAccessibleTree(log
,xRoot
, tParam
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
246 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
247 AccessibleRole
.RADIO_BUTTON
,
250 XAccessibleContext anotherButton
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
251 AccessibleRole
.RADIO_BUTTON
,
254 XAccessibleContext closeButton
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
255 AccessibleRole
.PUSH_BUTTON
,
259 accCloseButton
= UnoRuntime
.queryInterface(
260 XAccessibleAction
.class, closeButton
);
262 log
.println("ImplementationName: " + util
.utils
.getImplName(oObj
));
264 TestEnvironment tEnv
= new TestEnvironment(oObj
);
266 tEnv
.addObjRelation("EditOnly",
267 "This method isn't supported in this component");
269 tEnv
.addObjRelation("LimitedBounds", "yes");
271 final XAccessibleComponent acomp
= UnoRuntime
.queryInterface(
272 XAccessibleComponent
.class,
275 tEnv
.addObjRelation("EventProducer",
276 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
277 public void fireEvent() {
282 tEnv
.addObjRelation("XAccessibleText.Text", "Web");
284 tEnv
.addObjRelation("EditOnly",
285 "Can't change or select Text in AccessibleRadioButton");
287 XAccessibleValue anotherButtonValue
= UnoRuntime
.queryInterface(
288 XAccessibleValue
.class,
291 tEnv
.addObjRelation("XAccessibleValue.anotherFromGroup",
297 protected void closeDoc() {
298 util
.DesktopTools
.closeDoc(xTextDoc
);