merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _svtools / AccessibleTreeListBoxEntry.java
blob4e2fdf5441a10637c24c7096b1ff9d2daa73a488
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: AccessibleTreeListBoxEntry.java,v $
10 * $Revision: 1.11.8.1 $
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._svtools;
32 import com.sun.star.view.XSelectionSupplier;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.AccessibilityTools;
40 import util.DesktopTools;
41 import util.SOfficeFactory;
43 import com.sun.star.accessibility.AccessibleRole;
44 import com.sun.star.accessibility.XAccessible;
45 import com.sun.star.awt.XExtendedToolkit;
46 import com.sun.star.awt.XWindow;
47 import com.sun.star.beans.PropertyValue;
48 import com.sun.star.frame.XController;
49 import com.sun.star.frame.XDesktop;
50 import com.sun.star.frame.XDispatch;
51 import com.sun.star.frame.XDispatchProvider;
52 import com.sun.star.frame.XFrame;
53 import com.sun.star.frame.XModel;
54 import com.sun.star.lang.XInitialization;
55 import com.sun.star.lang.XMultiServiceFactory;
56 import com.sun.star.text.XTextDocument;
57 import com.sun.star.uno.UnoRuntime;
58 import com.sun.star.uno.XInterface;
59 import com.sun.star.util.URL;
60 import com.sun.star.util.XCloseable;
63 /**
64 * Test for object that implements the following interfaces :
65 * <ul>
66 * <li><code>::com::sun::star::accessibility::XAccessibleComponent
67 * </code></li>
68 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
69 * </code></li>
70 * <li><code>::com::sun::star::accessibility::XAccessibleContext
71 * </code></li>
72 * <li><code>::com::sun::star::accessibility::XAccessibleSelection
73 * </code></li>
74 * <li><code>::com::sun::star::accessibility::XAccessibleAction
75 * </code></li>
76 * <li><code>::com::sun::star::accessibility::XAccessibleText
77 * </code></li>
78 * </ul> <p>
80 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
81 * @see com.sun.star.accessibility.XAccessibleContext
82 * @see com.sun.star.accessibility.XAccessibleComponent
83 * @see com.sun.star.accessibility.XAccessibleSelection
84 * @see com.sun.star.accessibility.XAccessibleAction
85 * @see com.sun.star.accessibility.XAccessibleText
86 * @see ifc.accessibility._XAccessibleEventBroadcaster
87 * @see ifc.accessibility._XAccessibleContext
88 * @see ifc.accessibility._XAccessibleComponent
89 * @see ifc.accessibility._XAccessibleSelection
90 * @see ifc.accessibility._XAccessibleAction
91 * @see ifc.accessibility._XAccessibleText
93 public class AccessibleTreeListBoxEntry extends TestCase {
94 static XDesktop the_Desk;
95 static XTextDocument xTextDoc;
97 /**
98 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
100 protected void initialize(TestParameters Param, PrintWriter log) {
101 the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class,
102 DesktopTools.createDesktop(
103 (XMultiServiceFactory) Param.getMSF()));
107 * Disposes the document, if exists, created in
108 * <code>createTestEnvironment</code> method.
110 protected void cleanup(TestParameters Param, PrintWriter log) {
111 log.println("disposing xTextDoc");
113 if (xTextDoc != null) {
114 closeDoc();
119 * Creates a text document. Opens the DataSource browser.
120 * Creates an instance of the service <code>com.sun.star.awt.Toolkit</code>
121 * and gets active top window. Then obtains an accessible object with
122 * the role <code>AccessibleRole.LABEL</code> and with the name
123 * <code>"Bibliography"</code>.
124 * Object relations created :
125 * <ul>
126 * <li> <code>'EventProducer'</code> for
127 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
128 * </li>
129 * <li> <code>'XAccessibleSelection.multiSelection'</code>
130 * of type <code>Boolean</code> for
131 * {@link ifc.accessibility._XAccessibleSelection}:
132 * indicates that component supports single selection mode.</li>
133 * <li> <code>'XAccessibleText.Text'</code> for
134 * {@link ifc.accessibility._XAccessibleText}:
135 * the text of the component</li>
136 * </ul>
138 * @param tParam test parameters
139 * @param log writer to log information while testing
141 * @see com.sun.star.awt.Toolkit
142 * @see com.sun.star.accessibility.AccessibleRole
143 * @see ifc.accessibility._XAccessibleEventBroadcaster
144 * @see ifc.accessibility._XAccessibleSelection
145 * @see ifc.accessibility._XAccessibleText
146 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
147 * @see com.sun.star.accessibility.XAccessibleSelection
148 * @see com.sun.star.accessibility.XAccessibleText
150 protected TestEnvironment createTestEnvironment(TestParameters tParam,
151 PrintWriter log) {
152 log.println("creating a test environment");
154 if (xTextDoc != null) {
155 closeDoc();
158 // get a soffice factory object
159 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF());
161 try {
162 log.println("creating a text document");
163 xTextDoc = SOF.createTextDoc(null);
164 } catch (com.sun.star.uno.Exception e) {
165 // Some exception occures.FAILED
166 e.printStackTrace(log);
167 throw new StatusException("Couldn't create document", e);
170 shortWait();
172 XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class,
173 xTextDoc);
175 XController secondController = aModel1.getCurrentController();
177 XDispatchProvider aProv = (XDispatchProvider) UnoRuntime.queryInterface(
178 XDispatchProvider.class,
179 secondController);
181 XDispatch getting = null;
183 log.println("opening DatasourceBrowser");
185 URL the_url = new URL();
186 the_url.Complete = ".component:DB/DataSourceBrowser";
187 getting = aProv.queryDispatch(the_url, "_beamer", 12);
189 PropertyValue[] noArgs = new PropertyValue[0];
190 getting.dispatch(the_url, noArgs);
192 shortWait();
194 XFrame the_frame1 = the_Desk.getCurrentFrame();
196 if (the_frame1 == null) {
197 log.println("Current frame was not found !!!");
200 XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);
202 the_frame2.setName("DatasourceBrowser");
204 XInterface oObj = null;
206 XInitialization xInit = (XInitialization) UnoRuntime.queryInterface(
207 XInitialization.class,
208 the_frame2.getController());
210 PropertyValue[] params = new PropertyValue[3];
211 PropertyValue param1 = new PropertyValue();
212 param1.Name = "DataSourceName";
213 param1.Value = "Bibliography";
214 params[0] = param1;
216 PropertyValue param2 = new PropertyValue();
217 param2.Name = "CommandType";
218 param2.Value = new Integer(com.sun.star.sdb.CommandType.QUERY);
219 params[1] = param2;
221 PropertyValue param3 = new PropertyValue();
222 param3.Name = "Command";
223 param3.Value = "select * from biblio";
224 params[2] = param3;
226 XController xCont = the_frame2.getController();
228 XSelectionSupplier xSelect = (XSelectionSupplier) UnoRuntime.queryInterface(
229 XSelectionSupplier.class, xCont);
231 try {
232 xSelect.select(params);
233 } catch (com.sun.star.lang.IllegalArgumentException ex) {
234 throw new StatusException("Could not select Biblio-Database", ex);
238 try {
239 shortWait();
240 oObj = (XInterface) ( (XMultiServiceFactory) tParam.getMSF())
241 .createInstance("com.sun.star.awt.Toolkit");
242 } catch (com.sun.star.uno.Exception e) {
243 throw new StatusException("Couldn't get toolkit", e);
246 shortWait();
248 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface(
249 XExtendedToolkit.class, oObj);
251 AccessibilityTools at = new AccessibilityTools();
253 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class,
254 tk.getActiveTopWindow());
256 XAccessible xRoot = at.getAccessibleObject(xWindow);
258 at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
260 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.LABEL,
261 "Bibliography");
263 log.println("ImplementationName: " + util.utils.getImplName(oObj));
265 TestEnvironment tEnv = new TestEnvironment(oObj);
267 tEnv.addObjRelation("EditOnly",
268 "This method isn't supported in this component");
270 //adding ObjectRelation for XAccessibleText
271 tEnv.addObjRelation("LimitedBounds", "true");
274 tEnv.addObjRelation("EventProducer",
275 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
276 public void fireEvent() {
280 tEnv.addObjRelation("XAccessibleSelection.multiSelection",
281 new Boolean(false));
283 tEnv.addObjRelation("XAccessibleText.Text", "Bibliography");
285 return tEnv;
289 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
290 * reset</code> call.
292 private void shortWait() {
293 try {
294 Thread.sleep(5000);
295 } catch (InterruptedException e) {
296 System.out.println("While waiting :" + e);
300 protected void closeDoc() {
301 XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
302 XCloseable.class, xTextDoc);
304 try {
305 closer.close(true);
306 } catch (com.sun.star.util.CloseVetoException e) {
307 log.println("Couldn't close document " + e.getMessage());
308 } catch (com.sun.star.lang.DisposedException e) {
309 log.println("Couldn't close document " + e.getMessage());