bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _svtools / AccessibleIconChoiceCtrl.java
blobac07154757cd75a145221f1933c47c5d717e6093
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._svtools;
20 import java.io.PrintWriter;
22 import lib.StatusException;
23 import lib.TestCase;
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.lang.XMultiServiceFactory;
44 import com.sun.star.text.XTextDocument;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.uno.XInterface;
47 import com.sun.star.util.URL;
48 import com.sun.star.util.XURLTransformer;
51 /**
52 * Test for object that implements the following interfaces :
53 * <ul>
54 * <li><code>
55 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
56 * <li><code>
57 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
58 * </code></li>
59 * <li><code>
60 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
61 * <li><code>
62 * ::com::sun::star::accessibility::XAccessibleSelection</code></li>
63 * </ul> <p>
65 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
66 * @see com.sun.star.accessibility.XAccessibleContext
67 * @see com.sun.star.accessibility.XAccessibleComponent
68 * @see com.sun.star.accessibility.XAccessibleSelection
69 * @see ifc.accessibility._XAccessibleEventBroadcaster
70 * @see ifc.accessibility._XAccessibleContext
71 * @see ifc.accessibility._XAccessibleComponent
72 * @see ifc.accessibility._XAccessibleSelection
74 public class AccessibleIconChoiceCtrl extends TestCase {
75 static XDesktop the_Desk;
76 static XTextDocument xTextDoc;
77 static XAccessibleAction accCloseButton = null;
79 /**
80 * 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(
85 (XMultiServiceFactory) Param.getMSF()));
88 /**
89 * Closes the Hyperlink dialog.
90 * Disposes the document, if exists, created in
91 * <code>createTestEnvironment</code> method.
93 protected void cleanup(TestParameters Param, PrintWriter log) {
94 log.println("closing HyperlinkDialog");
96 try {
97 if (accCloseButton != null) {
98 accCloseButton.doAccessibleAction(0);
100 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
101 e.printStackTrace(log);
104 log.println("disposing xTextDoc");
106 if (xTextDoc != null) {
107 xTextDoc.dispose();
112 * Creates a text document. Opens the Hyperlink dialog.
113 * Creates an instance of the service
114 * <code>com.sun.star.awt.Toolkit</code> and gets active top window.
115 * Then obtains an accessible object with the role
116 * <code>AccessibleRole.TREE</code>.
117 * Object relations created :
118 * <ul>
119 * <li> <code>'EventProducer'</code> for
120 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
121 * method <code>fireEvent()</code> selects accessible children
122 * </li>
123 * </ul>
125 * @param tParam test parameters
126 * @param log writer to log information while testing
128 * @see com.sun.star.awt.Toolkit
129 * @see com.sun.star.accessibility.AccessibleRole
130 * @see ifc.accessibility._XAccessibleEventBroadcaster
131 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
133 protected TestEnvironment createTestEnvironment(TestParameters tParam,
134 PrintWriter log) {
135 log.println("creating a test environment");
137 if (xTextDoc != null) {
138 xTextDoc.dispose();
141 // get a soffice factory object
142 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF());
144 try {
145 log.println("creating a text document");
146 xTextDoc = SOF.createTextDoc(null);
147 } catch (com.sun.star.uno.Exception e) {
148 // Some exception occurs.FAILED
149 e.printStackTrace(log);
150 throw new StatusException("Couldn't create document", e);
153 shortWait();
155 XModel aModel1 = UnoRuntime.queryInterface(XModel.class,
156 xTextDoc);
158 XController secondController = aModel1.getCurrentController();
160 XDispatchProvider aProv = UnoRuntime.queryInterface(
161 XDispatchProvider.class,
162 secondController);
164 XURLTransformer urlTransf = null;
166 try {
167 XInterface transf = (XInterface) ( (XMultiServiceFactory) tParam.getMSF())
168 .createInstance("com.sun.star.util.URLTransformer");
169 urlTransf = UnoRuntime.queryInterface(
170 XURLTransformer.class, transf);
171 } catch (com.sun.star.uno.Exception e) {
172 e.printStackTrace(log);
173 throw new StatusException("Couldn't create URLTransformer", e);
176 XDispatch getting = null;
177 log.println("opening HyperlinkDialog");
179 URL[] url = new URL[1];
180 url[0] = new URL();
181 url[0].Complete = ".uno:HyperlinkDialog";
182 urlTransf.parseStrict(url);
183 getting = aProv.queryDispatch(url[0], "", 0);
185 PropertyValue[] noArgs = new PropertyValue[0];
186 getting.dispatch(url[0], noArgs);
188 shortWait();
190 XInterface oObj = null;
192 try {
193 oObj = (XInterface) ( (XMultiServiceFactory) tParam.getMSF())
194 .createInstance("com.sun.star.awt.Toolkit");
195 } catch (com.sun.star.uno.Exception e) {
196 log.println("Couldn't get toolkit");
197 e.printStackTrace(log);
198 throw new StatusException("Couldn't get toolkit", e);
201 XExtendedToolkit tk = UnoRuntime.queryInterface(
202 XExtendedToolkit.class, oObj);
204 AccessibilityTools at = new AccessibilityTools();
206 shortWait();
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,
217 "Close");
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",
226 new Boolean(false));
227 tEnv.addObjRelation("XAccessibleSelection.OneAlwaysSelected",
228 new Boolean(true));
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,
251 oObj);
253 tEnv.addObjRelation("EventProducer",
254 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
255 public void fireEvent() {
256 try {
257 selection.selectAccessibleChild(1);
258 selection.selectAccessibleChild(0);
259 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
264 return tEnv;
268 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
269 * reset</code> call.
271 private void shortWait() {
272 try {
273 Thread.sleep(5000);
274 } catch (InterruptedException e) {
275 System.out.println("While waiting :" + e);