merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _svtools / AccessibleBrowseBoxHeaderBar.java
blob126fc9232d4d2956a38e3f9377bb22a57318f240
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: AccessibleBrowseBoxHeaderBar.java,v $
10 * $Revision: 1.9.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.awt.Robot;
34 import java.awt.event.InputEvent;
35 import java.io.PrintWriter;
37 import lib.StatusException;
38 import lib.TestCase;
39 import lib.TestEnvironment;
40 import lib.TestParameters;
41 import util.AccessibilityTools;
42 import util.DesktopTools;
43 import util.SOfficeFactory;
45 import com.sun.star.accessibility.AccessibleRole;
46 import com.sun.star.accessibility.XAccessible;
47 import com.sun.star.accessibility.XAccessibleComponent;
48 import com.sun.star.awt.Point;
49 import com.sun.star.awt.XExtendedToolkit;
50 import com.sun.star.awt.XWindow;
51 import com.sun.star.beans.PropertyValue;
52 import com.sun.star.frame.XController;
53 import com.sun.star.frame.XDesktop;
54 import com.sun.star.frame.XDispatch;
55 import com.sun.star.frame.XDispatchProvider;
56 import com.sun.star.frame.XFrame;
57 import com.sun.star.frame.XModel;
58 import com.sun.star.lang.XMultiServiceFactory;
59 import com.sun.star.text.XTextDocument;
60 import com.sun.star.uno.UnoRuntime;
61 import com.sun.star.uno.XInterface;
62 import com.sun.star.util.URL;
65 /**
66 * Test for object that implements the following interfaces :
67 * <ul>
68 * <li>
69 * <code>::com::sun::star::accessibility::XAccessibleContext
70 * </code></li>
71 * <li>
72 * <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
73 * </code></li>
74 * </ul> <p>
76 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
77 * @see com.sun.star.accessibility.XAccessibleContext
78 * @see ifc.accessibility._XAccessibleEventBroadcaster
79 * @see ifc.accessibility._XAccessibleContext
81 public class AccessibleBrowseBoxHeaderBar extends TestCase {
82 static XDesktop the_Desk;
83 static XTextDocument xTextDoc;
85 /**
86 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
88 protected void initialize(TestParameters Param, PrintWriter log) {
89 the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class,
90 DesktopTools.createDesktop(
91 (XMultiServiceFactory) Param.getMSF()));
94 /**
95 * Disposes the document, if exists, created in
96 * <code>createTestEnvironment</code> method.
98 protected void cleanup(TestParameters Param, PrintWriter log) {
99 log.println("disposing xTextDoc");
101 if (xTextDoc != null) {
102 xTextDoc.dispose();
107 * Creates a text document. Opens the DataSource browser.
108 * Creates an instance of the service <code>com.sun.star.awt.Toolkit</code>
109 * and gets active top window. Then obtains an accessible object with
110 * the role <code>AccessibleRole.TABLE</code>.
111 * Object relations created :
112 * <ul>
113 * <li> <code>'EventProducer'</code> for
114 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
115 * </li>
116 * </ul>
118 * @param tParam test parameters
119 * @param log writer to log information while testing
121 * @see com.sun.star.awt.Toolkit
122 * @see com.sun.star.accessibility.AccessibleRole
123 * @see ifc.accessibility._XAccessibleEventBroadcaster
124 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
126 protected TestEnvironment createTestEnvironment(TestParameters tParam,
127 PrintWriter log) {
128 log.println("creating a test environment");
130 if (xTextDoc != null) {
131 xTextDoc.dispose();
134 // get a soffice factory object
135 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF());
137 try {
138 log.println("creating a text document");
139 xTextDoc = SOF.createTextDoc(null);
140 } catch (com.sun.star.uno.Exception e) {
141 // Some exception occures.FAILED
142 e.printStackTrace(log);
143 throw new StatusException("Couldn't create document", e);
146 shortWait();
148 XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class,
149 xTextDoc);
151 XController secondController = aModel1.getCurrentController();
153 XDispatchProvider aProv = (XDispatchProvider) UnoRuntime.queryInterface(
154 XDispatchProvider.class,
155 secondController);
157 XDispatch getting = null;
159 log.println("opening DatasourceBrowser");
161 URL the_url = new URL();
162 the_url.Complete = ".component:DB/DataSourceBrowser";
163 getting = aProv.queryDispatch(the_url, "_beamer", 12);
165 //am controller ein XSelectionSupplier->mit params rufen
166 PropertyValue[] noArgs = new PropertyValue[0];
167 getting.dispatch(the_url, noArgs);
169 PropertyValue[] params = new PropertyValue[3];
170 PropertyValue param1 = new PropertyValue();
171 param1.Name = "DataSourceName";
172 param1.Value = "Bibliography";
173 params[0] = param1;
175 PropertyValue param2 = new PropertyValue();
176 param2.Name = "CommandType";
177 param2.Value = new Integer(com.sun.star.sdb.CommandType.TABLE);
178 params[1] = param2;
180 PropertyValue param3 = new PropertyValue();
181 param3.Name = "Command";
182 param3.Value = "biblio";
183 params[2] = param3;
185 shortWait();
187 XFrame the_frame1 = the_Desk.getCurrentFrame();
189 if (the_frame1 == null) {
190 log.println("Current frame was not found !!!");
193 XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);
195 the_frame2.setName("DatasourceBrowser");
197 XController xCont = the_frame2.getController();
199 XSelectionSupplier xSelect = (XSelectionSupplier) UnoRuntime.queryInterface(
200 XSelectionSupplier.class, xCont);
202 try {
203 xSelect.select(params);
204 } catch (com.sun.star.lang.IllegalArgumentException ex) {
205 throw new StatusException("Could not select Biblio-Database", ex);
208 XInterface oObj = null;
210 try {
211 oObj = (XInterface) ( (XMultiServiceFactory) tParam.getMSF())
212 .createInstance("com.sun.star.awt.Toolkit");
213 } catch (com.sun.star.uno.Exception e) {
214 throw new StatusException("Couldn't get toolkit", e);
217 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface(
218 XExtendedToolkit.class, oObj);
220 AccessibilityTools at = new AccessibilityTools();
222 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class,
223 tk.getActiveTopWindow());
225 XAccessible xRoot = at.getAccessibleObject(xWindow);
227 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE);
229 at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
230 log.println("ImplementationName: " + util.utils.getImplName(oObj));
232 TestEnvironment tEnv = new TestEnvironment(oObj);
234 shortWait();
236 XAccessibleComponent accComp = (XAccessibleComponent) UnoRuntime.queryInterface(
237 XAccessibleComponent.class,
238 oObj);
239 final Point point = accComp.getLocationOnScreen();
241 shortWait();
243 tEnv.addObjRelation("EventProducer",
244 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
245 public void fireEvent() {
246 try {
247 Robot rob = new Robot();
248 rob.mouseMove(point.X + 5, point.Y + 5);
249 rob.mousePress(InputEvent.BUTTON1_MASK);
250 } catch (java.awt.AWTException e) {
251 System.out.println("couldn't fire event");
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(5000);;
266 } catch (InterruptedException e) {
267 System.out.println("While waiting :" + e);