merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _svtools / AccessibleIconChoiceCtrlEntry.java
blob80a27fb514726932ab7ef5381a6b09314de6ea20
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: AccessibleIconChoiceCtrlEntry.java,v $
10 * $Revision: 1.7.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 ************************************************************************/
31 package mod._svtools;
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.accessibility.XAccessibleAction;
46 import com.sun.star.accessibility.XAccessibleContext;
47 import com.sun.star.awt.XExtendedToolkit;
48 import com.sun.star.awt.XWindow;
49 import com.sun.star.beans.PropertyValue;
50 import com.sun.star.frame.XController;
51 import com.sun.star.frame.XDesktop;
52 import com.sun.star.frame.XDispatch;
53 import com.sun.star.frame.XDispatchProvider;
54 import com.sun.star.frame.XModel;
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.XURLTransformer;
62 /**
63 * Test for object that implements the following interfaces :
64 * <ul>
65 * <li><code>
66 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
67 * <li><code>
68 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
69 * </code></li>
70 * <li><code>
71 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
72 * <li><code>
73 * ::com::sun::star::accessibility::XAccessibleText</code></li>
74 * </ul> <p>
76 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
77 * @see com.sun.star.accessibility.XAccessibleContext
78 * @see com.sun.star.accessibility.XAccessibleComponent
79 * @see com.sun.star.accessibility.XAccessibleText
80 * @see ifc.accessibility._XAccessibleEventBroadcaster
81 * @see ifc.accessibility._XAccessibleContext
82 * @see ifc.accessibility._XAccessibleComponent
83 * @see ifc.accessibility.XAccessibleText
85 public class AccessibleIconChoiceCtrlEntry extends TestCase {
87 static XDesktop the_Desk;
88 static XTextDocument xTextDoc;
89 static XAccessibleAction accCloseButton = null;
91 /**
92 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
94 protected void initialize(TestParameters Param, PrintWriter log) {
95 the_Desk = (XDesktop) UnoRuntime.queryInterface(
96 XDesktop.class, DesktopTools.createDesktop((XMultiServiceFactory)Param.getMSF()));
99 /**
100 * Closes the Hyperlink dialog.
101 * Disposes the document, if exists, created in
102 * <code>createTestEnvironment</code> method.
104 protected void cleanup( TestParameters Param, PrintWriter log) {
106 log.println("closing HyperlinkDialog");
108 try {
109 if (accCloseButton != null) {
110 accCloseButton.doAccessibleAction(0);
112 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
113 e.printStackTrace(log);
116 log.println("disposing xTextDoc");
118 if (xTextDoc != null) {
119 xTextDoc.dispose();
124 * Creates a text document. Opens the Hyperlink dialog.
125 * Creates an instance of the service
126 * <code>com.sun.star.awt.Toolkit</code> and gets active top window.
127 * Then obtains an accessible object with the role
128 * <code>AccessibleRole.LABEL</code> and with the name
129 * <code>"Internet"</code>.
130 * Object relations created :
131 * <ul>
132 * <li> <code>'EventProducer'</code> for
133 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
134 * method <code>fireEvent()</code> is empty because object is transient
135 * </li>
136 * <li> <code>'XAccessibleText.Text'</code> for
137 * {@link ifc.accessibility._XAccessibleText}:
138 * the string representation of the item text
139 * </li>
140 * </ul>
142 * @param tParam test parameters
143 * @param log writer to log information while testing
145 * @see com.sun.star.awt.Toolkit
146 * @see com.sun.star.accessibility.AccessibleRole
147 * @see ifc.accessibility._XAccessibleEventBroadcaster
148 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
150 protected TestEnvironment createTestEnvironment(
151 TestParameters tParam, PrintWriter log) {
153 log.println( "creating a test environment" );
155 if (xTextDoc != null) xTextDoc.dispose();
157 // get a soffice factory object
158 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
160 try {
161 log.println( "creating a text document" );
162 xTextDoc = SOF.createTextDoc(null);
163 } catch ( com.sun.star.uno.Exception e ) {
164 // Some exception occures.FAILED
165 e.printStackTrace( log );
166 throw new StatusException( "Couldn't create document", e );
169 shortWait();
171 XModel aModel1 = (XModel)
172 UnoRuntime.queryInterface(XModel.class, xTextDoc);
174 XController secondController = aModel1.getCurrentController();
176 XDispatchProvider aProv = (XDispatchProvider)UnoRuntime.
177 queryInterface(XDispatchProvider.class, secondController);
179 XURLTransformer urlTransf = null;
181 try {
182 XInterface transf = (XInterface)((XMultiServiceFactory)tParam.getMSF()).createInstance
183 ("com.sun.star.util.URLTransformer");
184 urlTransf = (XURLTransformer)UnoRuntime.queryInterface
185 (XURLTransformer.class, transf);
186 } catch (com.sun.star.uno.Exception e) {
187 e.printStackTrace(log);
188 throw new StatusException("Couldn't create URLTransformer", e );
191 XDispatch getting = null;
192 log.println( "opening HyperlinkDialog" );
193 URL[] url = new URL[1];
194 url[0] = new URL();
195 url[0].Complete = ".uno:HyperlinkDialog";
196 urlTransf.parseStrict(url);
197 getting = aProv.queryDispatch(url[0], "", 0);
198 PropertyValue[] noArgs = new PropertyValue[0];
199 getting.dispatch(url[0], noArgs);
201 shortWait();
203 XInterface oObj = null;
204 try {
205 oObj = (XInterface) ((XMultiServiceFactory)tParam.getMSF()).createInstance
206 ("com.sun.star.awt.Toolkit") ;
207 } catch (com.sun.star.uno.Exception e) {
208 log.println("Couldn't get toolkit");
209 e.printStackTrace(log);
210 throw new StatusException("Couldn't get toolkit", e );
213 XExtendedToolkit tk = (XExtendedToolkit)
214 UnoRuntime.queryInterface(XExtendedToolkit.class, oObj);
216 AccessibilityTools at = new AccessibilityTools();
218 shortWait();
220 XWindow xWindow = (XWindow)
221 UnoRuntime.queryInterface(XWindow.class, tk.getActiveTopWindow());
223 XAccessible xRoot = at.getAccessibleObject(xWindow);
225 oObj = at.getAccessibleObjectForRole(xRoot,
226 AccessibleRole.LABEL, "Internet");
228 XAccessibleContext closeButton = at.getAccessibleObjectForRole(xRoot,
229 AccessibleRole.PUSH_BUTTON, "Close");
231 accCloseButton = (XAccessibleAction)
232 UnoRuntime.queryInterface(XAccessibleAction.class, closeButton);
234 log.println("ImplementationName: "+ util.utils.getImplName(oObj));
236 TestEnvironment tEnv = new TestEnvironment(oObj);
238 tEnv.addObjRelation("EventProducer",
239 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
240 public void fireEvent() {
244 tEnv.addObjRelation("XAccessibleText.Text", "Internet");
246 tEnv.addObjRelation("EditOnly",
247 "This method isn't supported in this dialog");
249 tEnv.addObjRelation("LimitedBounds",
250 "only delivers senseful values for getCharacterBounds(0,length-1)");
252 return tEnv;
256 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
257 * reset</code> call.
259 private void shortWait() {
260 try {
261 Thread.sleep(5000); ;
262 } catch (InterruptedException e) {
263 System.out.println("While waiting :" + e) ;