merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _svtools / AccessibleBrowseBox.java
blobee9242692376556cf83ac6525d4e39ee74981c93
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: AccessibleBrowseBox.java,v $
10 * $Revision: 1.7.8.2 $
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 java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
38 import util.AccessibilityTools;
39 import util.DesktopTools;
40 import util.SOfficeFactory;
42 import com.sun.star.accessibility.AccessibleRole;
43 import com.sun.star.accessibility.XAccessible;
44 import com.sun.star.awt.XExtendedToolkit;
45 import com.sun.star.awt.XWindow;
46 import com.sun.star.beans.PropertyValue;
47 import com.sun.star.frame.XController;
48 import com.sun.star.frame.XDesktop;
49 import com.sun.star.frame.XDispatch;
50 import com.sun.star.frame.XDispatchProvider;
51 import com.sun.star.frame.XFrame;
52 import com.sun.star.frame.XModel;
53 import com.sun.star.lang.XMultiServiceFactory;
54 import com.sun.star.text.XTextDocument;
55 import com.sun.star.uno.UnoRuntime;
56 import com.sun.star.uno.XInterface;
57 import com.sun.star.util.URL;
58 import com.sun.star.view.XSelectionSupplier;
60 public class AccessibleBrowseBox extends TestCase {
62 static XDesktop the_Desk;
63 static XTextDocument xTextDoc;
65 /**
66 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
68 protected void initialize(TestParameters Param, PrintWriter log) {
69 the_Desk = (XDesktop) UnoRuntime.queryInterface(
70 XDesktop.class, DesktopTools.createDesktop((XMultiServiceFactory) Param.getMSF()));
73 /**
74 * Disposes the document, if exists, created in
75 * <code>createTestEnvironment</code> method.
77 protected void cleanup(TestParameters Param, PrintWriter log) {
79 log.println("disposing xTextDoc");
81 if (xTextDoc != null) {
82 xTextDoc.dispose();
86 /**
87 * Called to create an instance of <code>TestEnvironment</code> with an
88 * object to test and related objects. Subclasses should implement this
89 * method to provide the implementation and related objects. The method is
90 * called from <code>getTestEnvironment()</code>.
92 * @param tParam test parameters
93 * @param log writer to log information while testing
95 * @see TestEnvironment
96 * @see #getTestEnvironment()
98 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
100 log.println("creating a test environment");
102 if (xTextDoc != null) {
103 xTextDoc.dispose(); // get a soffice factory object
105 SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory) tParam.getMSF());
107 try {
108 log.println("creating a text document");
109 xTextDoc = SOF.createTextDoc(null);
110 } catch (com.sun.star.uno.Exception e) {
111 // Some exception occures.FAILED
112 e.printStackTrace(log);
113 throw new StatusException("Couldn't create document", e);
116 shortWait();
118 XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class, xTextDoc);
120 XController secondController = aModel1.getCurrentController();
123 XDispatchProvider aProv = (XDispatchProvider) UnoRuntime.queryInterface(XDispatchProvider.class,
124 secondController);
126 XDispatch getting = null;
128 log.println("opening DatasourceBrowser");
129 URL the_url = new URL();
130 the_url.Complete = ".component:DB/DataSourceBrowser";
131 getting = aProv.queryDispatch(the_url, "_beamer", 12);
132 PropertyValue[] noArgs = new PropertyValue[0];
133 getting.dispatch(the_url, noArgs);
135 shortWait();
137 XFrame the_frame1 = the_Desk.getCurrentFrame();
139 if (the_frame1 == null) {
140 log.println("Current frame was not found !!!");
143 XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);
145 the_frame2.setName("DatasourceBrowser");
147 XInterface oObj = null;
149 final XSelectionSupplier xSelect = (XSelectionSupplier) UnoRuntime.queryInterface(
150 XSelectionSupplier.class, the_frame2.getController());
152 PropertyValue[] params = new PropertyValue[]{new PropertyValue(), new PropertyValue(), new PropertyValue()};
153 params[0].Name = "DataSourceName";
154 params[0].Value = "Bibliography";
155 params[1].Name = "CommandType";
156 params[1].Value = new Integer(com.sun.star.sdb.CommandType.TABLE);
157 params[2].Name = "Command";
158 params[2].Value = "biblio";
160 final PropertyValue[] fParams = params;
162 shortWait();
164 try {
165 oObj = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance("com.sun.star.awt.Toolkit");
166 } catch (com.sun.star.uno.Exception e) {
167 log.println("Couldn't get toolkit");
168 e.printStackTrace(log);
169 throw new StatusException("Couldn't get toolkit", e);
173 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface(XExtendedToolkit.class, oObj);
176 AccessibilityTools at = new AccessibilityTools();
178 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, tk.getActiveTopWindow());
180 XAccessible xRoot = at.getAccessibleObject(xWindow);
182 at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
184 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL, "", "AccessibleBrowseBox");
186 log.println("ImplementationName: " + util.utils.getImplName(oObj));
188 TestEnvironment tEnv = new TestEnvironment(oObj);
191 tEnv.addObjRelation("EventProducer",
192 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
194 public void fireEvent() {
195 try {
196 xSelect.select(fParams);
197 } catch (com.sun.star.uno.Exception e) {
198 e.printStackTrace();
203 return tEnv;
207 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
208 * reset</code> call.
210 private void shortWait() {
211 try {
212 Thread.sleep(5000);
214 } catch (InterruptedException e) {
215 System.out.println("While waiting :" + e);