bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleRadioButton.java
blobc00e6d340610321d7af4e335d333c003a37c7090
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.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;
44 import lib.TestCase;
45 import lib.TestEnvironment;
46 import lib.TestParameters;
48 import util.AccessibilityTools;
49 import util.DesktopTools;
50 import util.SOfficeFactory;
53 /**
54 * Test for object that implements the following interfaces :
55 * <ul>
56 * <li><code>
57 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
58 * <li><code>
59 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
60 * </code></li>
61 * <li><code>
62 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
63 * <li><code>
64 * ::com::sun::star::accessibility::XAccessibleExtendedComponent
65 * </code></li>
66 * <li><code>
67 * ::com::sun::star::accessibility::XAccessibleValue</code></li>
68 * <li><code>
69 * ::com::sun::star::accessibility::XAccessibleText</code></li>
70 * </ul> <p>
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;
90 /**
91 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
93 @Override
94 protected void initialize(TestParameters Param, PrintWriter log) {
95 UnoRuntime.queryInterface(XDesktop.class,
96 DesktopTools.createDesktop(
97 Param.getMSF()));
101 * Closes a Hyperlink dialog, disposes the document, if exists, created in
102 * <code>createTestEnvironment</code> method.
104 @Override
105 protected void cleanup(TestParameters Param, PrintWriter log) {
106 try {
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) {
120 closeDoc();
125 * Creates a text document, opens a hypelink dialog, selects a first item
126 * in IconChoiceCtrl.
127 * Then obtains an accessible object with
128 * the role <code>AccessibleRole.RADIOBUTTON</code> with the name <code>
129 * "Internet"</code>.
130 * Object relations created :
131 * <ul>
132 * <li> <code>'EventProducer'</code> for
133 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
134 * grabs focus </li>
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>
141 * </ul>
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
153 @Override
154 protected TestEnvironment createTestEnvironment(TestParameters tParam,
155 PrintWriter log) {
156 log.println("creating a test environment");
158 // get a soffice factory object
159 SOfficeFactory SOF = SOfficeFactory.getFactory(
160 tParam.getMSF());
162 try {
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,
174 xTextDoc);
176 XController secondController = aModel1.getCurrentController();
178 XDispatchProvider aProv = UnoRuntime.queryInterface(
179 XDispatchProvider.class,
180 secondController);
182 XURLTransformer urlTransf = null;
184 try {
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];
198 url[0] = new URL();
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;
210 try {
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,
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);