Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleTabControl.java
blob0b0b95c488d26abbf91ad16b6fca131a02fa32d1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleTabControl.java,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package mod._toolkit;
32 import com.sun.star.accessibility.AccessibleRole;
33 import com.sun.star.accessibility.XAccessible;
34 import com.sun.star.accessibility.XAccessibleAction;
35 import com.sun.star.accessibility.XAccessibleContext;
36 import com.sun.star.accessibility.XAccessibleSelection;
37 import com.sun.star.awt.XExtendedToolkit;
38 import com.sun.star.awt.XWindow;
39 import com.sun.star.beans.PropertyValue;
40 import com.sun.star.frame.XController;
41 import com.sun.star.frame.XDesktop;
42 import com.sun.star.frame.XDispatch;
43 import com.sun.star.frame.XDispatchProvider;
44 import com.sun.star.frame.XModel;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.text.XTextDocument;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
49 import com.sun.star.util.URL;
50 import com.sun.star.util.XURLTransformer;
52 import java.io.PrintWriter;
54 import lib.StatusException;
55 import lib.TestCase;
56 import lib.TestEnvironment;
57 import lib.TestParameters;
59 import util.AccessibilityTools;
60 import util.DesktopTools;
61 import util.SOfficeFactory;
64 /**
65 * Test for object that implements the following interfaces :
66 * <ul>
67 * <li><code>
68 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
69 * <li><code>
70 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
71 * </code></li>
72 * <li><code>
73 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
74 * <li><code>
75 * ::com::sun::star::accessibility::XAccessibleExtendedComponent
76 * </code></li>
77 * <li><code>
78 * ::com::sun::star::accessibility::XAccessibleSelection
79 * </code></li>
80 * </ul> <p>
82 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
83 * @see com.sun.star.accessibility.XAccessibleContext
84 * @see com.sun.star.accessibility.XAccessibleComponent
85 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
86 * @see com.sun.star.accessibility.XAccessibleSelection
87 * @see ifc.accessibility._XAccessibleEventBroadcaster
88 * @see ifc.accessibility._XAccessibleContext
89 * @see ifc.accessibility._XAccessibleComponent
90 * @see ifc.accessibility.XAccessibleExtendedComponent
91 * @see ifc.accessibility.XAccessibleSelection
93 public class AccessibleTabControl extends TestCase {
94 private static XDesktop the_Desk;
95 private static XTextDocument xTextDoc;
96 private static XAccessibleAction accCloseButton = null;
98 /**
99 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
101 protected void initialize(TestParameters Param, PrintWriter log) {
102 the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class,
103 DesktopTools.createDesktop(
104 (XMultiServiceFactory) Param.getMSF()));
108 * Closes an InsertFields dialog, disposes the document, if exists, created in
109 * <code>createTestEnvironment</code> method.
111 protected void cleanup(TestParameters Param, PrintWriter log) {
112 try {
113 if (accCloseButton != null) {
114 log.println("closing InsertFields Dialog");
115 accCloseButton.doAccessibleAction(0);
117 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
118 e.printStackTrace(log);
121 log.println("disposing xTextDoc");
123 if (xTextDoc != null) {
124 util.DesktopTools.closeDoc(xTextDoc);
130 * Creates a text document, opens an InsertField dialog.
131 * Then obtains an accessible object with
132 * the role <code>AccessibleRole.PAGETABLIST</code>.
133 * Object relations created :
134 * <ul>
135 * <li> <code>'EventProducer'</code> for
136 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
137 * selects items </li>
138 * <li> <code>'XAccessibleSelection.multiSelection'</code>
139 * of type <code>Boolean</code> for
140 * {@link ifc.accessibility._XAccessibleSelection}:
141 * indicates that component supports single selection mode.</li>
142 * </ul>
144 * @param tParam test parameters
145 * @param log writer to log information while testing
147 * @see com.sun.star.awt.Toolkit
148 * @see com.sun.star.accessibility.AccessibleRole
149 * @see ifc.accessibility._XAccessibleEventBroadcaster
150 * @see ifc.accessibility._XAccessibleSelection
151 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
152 * @see com.sun.star.accessibility.XAccessibleSelection
154 protected TestEnvironment createTestEnvironment(TestParameters tParam,
155 PrintWriter log) {
156 log.println("creating a test environment");
158 if (xTextDoc != null) {
159 util.DesktopTools.closeDoc(xTextDoc);
163 // get a soffice factory object
164 SOfficeFactory SOF = SOfficeFactory.getFactory(
165 (XMultiServiceFactory) tParam.getMSF());
167 try {
168 log.println("creating a text document");
169 xTextDoc = SOF.createTextDoc(null);
170 } catch (com.sun.star.uno.Exception e) {
171 // Some exception occures.FAILED
172 e.printStackTrace(log);
173 throw new StatusException("Couldn't create document", e);
176 shortWait();
178 XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class,
179 xTextDoc);
181 XController secondController = aModel1.getCurrentController();
183 XDispatchProvider aProv = (XDispatchProvider) UnoRuntime.queryInterface(
184 XDispatchProvider.class,
185 secondController);
187 XURLTransformer urlTransf = null;
189 try {
190 XInterface transf = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance(
191 "com.sun.star.util.URLTransformer");
192 urlTransf = (XURLTransformer) UnoRuntime.queryInterface(
193 XURLTransformer.class, transf);
194 } catch (com.sun.star.uno.Exception e) {
195 e.printStackTrace(log);
196 throw new StatusException("Couldn't create URLTransformer", e);
199 XDispatch getting = null;
200 log.println("opening InsertField dialog");
202 URL[] url = new URL[1];
203 url[0] = new URL();
204 url[0].Complete = ".uno:InsertField";
205 urlTransf.parseStrict(url);
206 getting = aProv.queryDispatch(url[0], "", 0);
208 PropertyValue[] noArgs = new PropertyValue[0];
209 getting.dispatch(url[0], noArgs);
211 shortWait();
213 XInterface oObj = null;
215 try {
216 oObj = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance(
217 "com.sun.star.awt.Toolkit");
218 } catch (com.sun.star.uno.Exception e) {
219 log.println("Couldn't get toolkit");
220 e.printStackTrace(log);
221 throw new StatusException("Couldn't get toolkit", e);
224 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface(
225 XExtendedToolkit.class, oObj);
227 AccessibilityTools at = new AccessibilityTools();
229 shortWait();
231 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class,
232 tk.getActiveTopWindow());
234 XAccessible xRoot = at.getAccessibleObject(xWindow);
236 oObj = at.getAccessibleObjectForRole(xRoot,
237 AccessibleRole.PAGE_TAB_LIST);
239 XAccessibleContext closeButton = at.getAccessibleObjectForRole(xRoot,
240 AccessibleRole.PUSH_BUTTON,
241 "Close");
243 accCloseButton = (XAccessibleAction) UnoRuntime.queryInterface(
244 XAccessibleAction.class, closeButton);
246 log.println("ImplementationName: " + util.utils.getImplName(oObj));
248 TestEnvironment tEnv = new TestEnvironment(oObj);
250 final XAccessibleSelection selection = (XAccessibleSelection) (XAccessibleSelection) UnoRuntime.queryInterface(
251 XAccessibleSelection.class,
252 oObj);
254 tEnv.addObjRelation("EventProducer",
255 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
256 public void fireEvent() {
257 try {
258 selection.selectAccessibleChild(1);
259 selection.selectAccessibleChild(0);
260 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
265 tEnv.addObjRelation("XAccessibleSelection.OneAlwaysSelected",
266 new Boolean(true));
268 tEnv.addObjRelation("XAccessibleSelection.multiSelection",
269 new Boolean(false));
271 return tEnv;
275 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
276 * reset</code> call.
278 private void shortWait() {
279 try {
280 Thread.currentThread().sleep(500);
281 } catch (InterruptedException e) {
282 System.out.println("While waiting :" + e);