1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 ************************************************************************/
32 import com
.sun
.star
.view
.XSelectionSupplier
;
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
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
;
64 * Test for object that implements the following interfaces :
66 * <li><code>::com::sun::star::accessibility::XAccessibleComponent
68 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
70 * <li><code>::com::sun::star::accessibility::XAccessibleContext
72 * <li><code>::com::sun::star::accessibility::XAccessibleSelection
74 * <li><code>::com::sun::star::accessibility::XAccessibleAction
76 * <li><code>::com::sun::star::accessibility::XAccessibleText
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
;
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) {
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 :
126 * <li> <code>'EventProducer'</code> for
127 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
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>
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
,
152 log
.println("creating a test environment");
154 if (xTextDoc
!= null) {
158 // get a soffice factory object
159 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
) tParam
.getMSF());
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
);
172 XModel aModel1
= (XModel
) UnoRuntime
.queryInterface(XModel
.class,
175 XController secondController
= aModel1
.getCurrentController();
177 XDispatchProvider aProv
= (XDispatchProvider
) UnoRuntime
.queryInterface(
178 XDispatchProvider
.class,
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
);
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";
216 PropertyValue param2
= new PropertyValue();
217 param2
.Name
= "CommandType";
218 param2
.Value
= new Integer(com
.sun
.star
.sdb
.CommandType
.QUERY
);
221 PropertyValue param3
= new PropertyValue();
222 param3
.Name
= "Command";
223 param3
.Value
= "select * from biblio";
226 XController xCont
= the_frame2
.getController();
228 XSelectionSupplier xSelect
= (XSelectionSupplier
) UnoRuntime
.queryInterface(
229 XSelectionSupplier
.class, xCont
);
232 xSelect
.select(params
);
233 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
234 throw new StatusException("Could not select Biblio-Database", ex
);
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
);
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
,
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",
283 tEnv
.addObjRelation("XAccessibleText.Text", "Bibliography");
289 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
292 private void shortWait() {
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
);
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());