bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleTabControl.java
blobe32fe9405b23cfb2363df89b6532636d7258fe5a
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.XAccessibleContext;
24 import com.sun.star.accessibility.XAccessibleSelection;
25 import com.sun.star.awt.XExtendedToolkit;
26 import com.sun.star.awt.XWindow;
27 import com.sun.star.beans.PropertyValue;
28 import com.sun.star.frame.XController;
29 import com.sun.star.frame.XDesktop;
30 import com.sun.star.frame.XDispatch;
31 import com.sun.star.frame.XDispatchProvider;
32 import com.sun.star.frame.XModel;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.text.XTextDocument;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
37 import com.sun.star.util.URL;
38 import com.sun.star.util.XURLTransformer;
40 import java.io.PrintWriter;
42 import lib.StatusException;
43 import lib.TestCase;
44 import lib.TestEnvironment;
45 import lib.TestParameters;
47 import util.AccessibilityTools;
48 import util.DesktopTools;
49 import util.SOfficeFactory;
52 /**
53 * Test for object that implements the following interfaces :
54 * <ul>
55 * <li><code>
56 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
57 * <li><code>
58 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
59 * </code></li>
60 * <li><code>
61 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
62 * <li><code>
63 * ::com::sun::star::accessibility::XAccessibleExtendedComponent
64 * </code></li>
65 * <li><code>
66 * ::com::sun::star::accessibility::XAccessibleSelection
67 * </code></li>
68 * </ul> <p>
70 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
71 * @see com.sun.star.accessibility.XAccessibleContext
72 * @see com.sun.star.accessibility.XAccessibleComponent
73 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
74 * @see com.sun.star.accessibility.XAccessibleSelection
75 * @see ifc.accessibility._XAccessibleEventBroadcaster
76 * @see ifc.accessibility._XAccessibleContext
77 * @see ifc.accessibility._XAccessibleComponent
78 * @see ifc.accessibility._XAccessibleExtendedComponent
79 * @see ifc.accessibility._XAccessibleSelection
81 public class AccessibleTabControl extends TestCase {
82 private static XTextDocument xTextDoc;
83 private static XAccessibleAction accCloseButton = null;
85 /**
86 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
88 protected void initialize(TestParameters Param, PrintWriter log) {
89 UnoRuntime.queryInterface(XDesktop.class,
90 DesktopTools.createDesktop(
91 (XMultiServiceFactory) Param.getMSF()));
94 /**
95 * Closes an InsertFields dialog, disposes the document, if exists, created in
96 * <code>createTestEnvironment</code> method.
98 protected void cleanup(TestParameters Param, PrintWriter log) {
99 try {
100 if (accCloseButton != null) {
101 log.println("closing InsertFields Dialog");
102 accCloseButton.doAccessibleAction(0);
104 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
105 e.printStackTrace(log);
108 log.println("disposing xTextDoc");
110 if (xTextDoc != null) {
111 util.DesktopTools.closeDoc(xTextDoc);
116 * Creates a text document, opens an InsertField dialog.
117 * Then obtains an accessible object with
118 * the role <code>AccessibleRole.PAGETABLIST</code>.
119 * Object relations created :
120 * <ul>
121 * <li> <code>'EventProducer'</code> for
122 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
123 * selects items </li>
124 * <li> <code>'XAccessibleSelection.multiSelection'</code>
125 * of type <code>Boolean</code> for
126 * {@link ifc.accessibility._XAccessibleSelection}:
127 * indicates that component supports single selection mode.</li>
128 * </ul>
130 * @param tParam test parameters
131 * @param log writer to log information while testing
133 * @see com.sun.star.awt.Toolkit
134 * @see com.sun.star.accessibility.AccessibleRole
135 * @see ifc.accessibility._XAccessibleEventBroadcaster
136 * @see ifc.accessibility._XAccessibleSelection
137 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
138 * @see com.sun.star.accessibility.XAccessibleSelection
140 protected TestEnvironment createTestEnvironment(TestParameters tParam,
141 PrintWriter log) {
142 log.println("creating a test environment");
144 if (xTextDoc != null) {
145 util.DesktopTools.closeDoc(xTextDoc);
148 // get a soffice factory object
149 SOfficeFactory SOF = SOfficeFactory.getFactory(
150 (XMultiServiceFactory) tParam.getMSF());
152 try {
153 log.println("creating a text document");
154 xTextDoc = SOF.createTextDoc(null);
155 } catch (com.sun.star.uno.Exception e) {
156 // Some exception occurs.FAILED
157 e.printStackTrace(log);
158 throw new StatusException("Couldn't create document", e);
161 shortWait();
163 XModel aModel1 = UnoRuntime.queryInterface(XModel.class,
164 xTextDoc);
166 XController secondController = aModel1.getCurrentController();
168 XDispatchProvider aProv = UnoRuntime.queryInterface(
169 XDispatchProvider.class,
170 secondController);
172 XURLTransformer urlTransf = null;
174 try {
175 XInterface transf = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance(
176 "com.sun.star.util.URLTransformer");
177 urlTransf = UnoRuntime.queryInterface(
178 XURLTransformer.class, transf);
179 } catch (com.sun.star.uno.Exception e) {
180 e.printStackTrace(log);
181 throw new StatusException("Couldn't create URLTransformer", e);
184 XDispatch getting = null;
185 log.println("opening InsertField dialog");
187 URL[] url = new URL[1];
188 url[0] = new URL();
189 url[0].Complete = ".uno:InsertField";
190 urlTransf.parseStrict(url);
191 getting = aProv.queryDispatch(url[0], "", 0);
193 PropertyValue[] noArgs = new PropertyValue[0];
194 getting.dispatch(url[0], noArgs);
196 shortWait();
198 XInterface oObj = null;
200 try {
201 oObj = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance(
202 "com.sun.star.awt.Toolkit");
203 } catch (com.sun.star.uno.Exception e) {
204 log.println("Couldn't get toolkit");
205 e.printStackTrace(log);
206 throw new StatusException("Couldn't get toolkit", e);
209 XExtendedToolkit tk = UnoRuntime.queryInterface(
210 XExtendedToolkit.class, oObj);
212 AccessibilityTools at = new AccessibilityTools();
214 shortWait();
216 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class,
217 tk.getActiveTopWindow());
219 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
221 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot,
222 AccessibleRole.PAGE_TAB_LIST);
224 XAccessibleContext closeButton = AccessibilityTools.getAccessibleObjectForRole(xRoot,
225 AccessibleRole.PUSH_BUTTON,
226 "Close");
228 accCloseButton = UnoRuntime.queryInterface(
229 XAccessibleAction.class, closeButton);
231 log.println("ImplementationName: " + util.utils.getImplName(oObj));
233 TestEnvironment tEnv = new TestEnvironment(oObj);
235 final XAccessibleSelection selection = UnoRuntime.queryInterface(
236 XAccessibleSelection.class,
237 oObj);
239 tEnv.addObjRelation("EventProducer",
240 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
241 public void fireEvent() {
242 try {
243 selection.selectAccessibleChild(1);
244 selection.selectAccessibleChild(0);
245 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
250 tEnv.addObjRelation("XAccessibleSelection.OneAlwaysSelected",
251 new Boolean(true));
253 tEnv.addObjRelation("XAccessibleSelection.multiSelection",
254 new Boolean(false));
256 return tEnv;
260 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
261 * reset</code> call.
263 private void shortWait() {
264 try {
265 Thread.sleep(500);
266 } catch (InterruptedException e) {
267 System.out.println("While waiting :" + e);