bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleRadioButton.java
blobaabae23a0dd753954d84da3945b668e6f89f8922
1 /*
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 .
18 package mod._toolkit;
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.lang.XMultiServiceFactory;
36 import com.sun.star.text.XTextDocument;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
39 import com.sun.star.util.URL;
40 import com.sun.star.util.XURLTransformer;
42 import java.io.PrintWriter;
44 import lib.StatusException;
45 import lib.TestCase;
46 import lib.TestEnvironment;
47 import lib.TestParameters;
49 import util.AccessibilityTools;
50 import util.DesktopTools;
51 import util.SOfficeFactory;
54 /**
55 * Test for object that implements the following interfaces :
56 * <ul>
57 * <li><code>
58 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
59 * <li><code>
60 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
61 * </code></li>
62 * <li><code>
63 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
64 * <li><code>
65 * ::com::sun::star::accessibility::XAccessibleExtendedComponent
66 * </code></li>
67 * <li><code>
68 * ::com::sun::star::accessibility::XAccessibleValue</code></li>
69 * <li><code>
70 * ::com::sun::star::accessibility::XAccessibleText</code></li>
71 * </ul> <p>
73 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
74 * @see com.sun.star.accessibility.XAccessibleContext
75 * @see com.sun.star.accessibility.XAccessibleComponent
76 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
77 * @see com.sun.star.accessibility.XAccessibleValue
78 * @see com.sun.star.accessibility.XAccessibleText
79 * @see ifc.accessibility._XAccessibleEventBroadcaster
80 * @see ifc.accessibility._XAccessibleContext
81 * @see ifc.accessibility._XAccessibleComponent
82 * @see ifc.accessibility._XAccessibleExtendedComponent
83 * @see ifc.accessibility._XAccessibleValue
84 * @see ifc.accessibility._XAccessibleText
86 public class AccessibleRadioButton extends TestCase {
87 private static XTextDocument xTextDoc;
88 private static XAccessibleAction accCloseButton;
91 /**
92 * 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(
97 (XMultiServiceFactory) Param.getMSF()));
101 * Closes a Hyperlink dialog, disposes the document, if exists, created in
102 * <code>createTestEnvironment</code> method.
104 protected void cleanup(TestParameters Param, PrintWriter log) {
105 try {
106 if (accCloseButton != null) {
107 log.println("closing HyperlinkDialog");
108 accCloseButton.doAccessibleAction(0);
110 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
111 e.printStackTrace(log);
112 } catch (com.sun.star.lang.DisposedException de) {
113 log.println("Already disposed");
116 log.println("disposing xTextDoc");
118 if (xTextDoc != null) {
119 closeDoc();
124 * Creates a text document, opens a hypelink dialog, selects a first item
125 * in IconChoiceCtrl.
126 * Then obtains an accessible object with
127 * the role <code>AccessibleRole.RADIOBUTTON</code> with the name <code>
128 * "Internet"</code>.
129 * Object relations created :
130 * <ul>
131 * <li> <code>'EventProducer'</code> for
132 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
133 * grabs focus </li>
134 * <li> <code>'XAccessibleText.Text'</code> for
135 * {@link ifc.accessibility._XAccessibleText}:
136 * the text of the component </li>
137 * <li> <code>'XAccessibleValue.anotherFromGroup'</code> for
138 * {@link ifc.accessibility._XAccessibleValue}:
139 * <code>'FTP'</code> button </li>
140 * </ul>
142 * @param tParam test parameters
143 * @param log writer to log information while testing
145 * @see com.sun.star.awt.Toolkit
146 * @see com.sun.star.accessibility.AccessibleRole
147 * @see ifc.accessibility._XAccessibleEventBroadcaster
148 * @see ifc.accessibility._XAccessibleText
149 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
150 * @see com.sun.star.accessibility.XAccessibleText
152 protected TestEnvironment createTestEnvironment(TestParameters tParam,
153 PrintWriter log) {
154 log.println("creating a test environment");
156 // get a soffice factory object
157 SOfficeFactory SOF = SOfficeFactory.getFactory(
158 (XMultiServiceFactory) tParam.getMSF());
160 try {
161 log.println("creating a text document");
162 xTextDoc = SOF.createTextDoc(null);
163 } catch (com.sun.star.uno.Exception e) {
164 // Some exception occurs.FAILED
165 e.printStackTrace(log);
166 throw new StatusException("Couldn't create document", e);
169 util.utils.shortWait(2000);
171 XModel aModel1 = UnoRuntime.queryInterface(XModel.class,
172 xTextDoc);
174 XController secondController = aModel1.getCurrentController();
176 XDispatchProvider aProv = UnoRuntime.queryInterface(
177 XDispatchProvider.class,
178 secondController);
180 XURLTransformer urlTransf = null;
182 try {
183 XInterface transf = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance(
184 "com.sun.star.util.URLTransformer");
185 urlTransf = UnoRuntime.queryInterface(
186 XURLTransformer.class, transf);
187 } catch (com.sun.star.uno.Exception e) {
188 e.printStackTrace(log);
189 throw new StatusException("Couldn't create URLTransformer", e);
192 XDispatch getting = null;
193 log.println("opening HyperlinkDialog");
195 URL[] url = new URL[1];
196 url[0] = new URL();
197 url[0].Complete = ".uno:HyperlinkDialog";
198 urlTransf.parseStrict(url);
199 getting = aProv.queryDispatch(url[0], "", 0);
201 PropertyValue[] noArgs = new PropertyValue[0];
202 getting.dispatch(url[0], noArgs);
204 util.utils.shortWait(2000);
206 XInterface oObj = null;
208 try {
209 oObj = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance(
210 "com.sun.star.awt.Toolkit");
211 } catch (com.sun.star.uno.Exception e) {
212 log.println("Couldn't get toolkit");
213 e.printStackTrace(log);
214 throw new StatusException("Couldn't get toolkit", e);
217 XExtendedToolkit tk = UnoRuntime.queryInterface(
218 XExtendedToolkit.class, oObj);
220 AccessibilityTools at = new AccessibilityTools();
222 util.utils.shortWait(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,
235 iconChoiceCtrl);
237 try {
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,
248 "Web");
250 XAccessibleContext anotherButton = AccessibilityTools.getAccessibleObjectForRole(xRoot,
251 AccessibleRole.RADIO_BUTTON,
252 "FTP");
254 XAccessibleContext closeButton = AccessibilityTools.getAccessibleObjectForRole(xRoot,
255 AccessibleRole.PUSH_BUTTON,
256 "Close");
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,
273 oObj);
275 tEnv.addObjRelation("EventProducer",
276 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
277 public void fireEvent() {
278 acomp.grabFocus();
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,
289 anotherButton);
291 tEnv.addObjRelation("XAccessibleValue.anotherFromGroup",
292 anotherButtonValue);
294 return tEnv;
297 protected void closeDoc() {
298 util.DesktopTools.closeDoc(xTextDoc);