2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.AccessibilityTools
;
28 import util
.DesktopTools
;
29 import util
.SOfficeFactory
;
31 import com
.sun
.star
.accessibility
.AccessibleRole
;
32 import com
.sun
.star
.accessibility
.XAccessible
;
33 import com
.sun
.star
.awt
.XWindow
;
34 import com
.sun
.star
.beans
.PropertyValue
;
35 import com
.sun
.star
.frame
.XController
;
36 import com
.sun
.star
.frame
.XDesktop
;
37 import com
.sun
.star
.frame
.XDispatch
;
38 import com
.sun
.star
.frame
.XDispatchProvider
;
39 import com
.sun
.star
.frame
.XFrame
;
40 import com
.sun
.star
.frame
.XModel
;
41 import com
.sun
.star
.lang
.XInitialization
;
42 import com
.sun
.star
.lang
.XMultiServiceFactory
;
43 import com
.sun
.star
.text
.XTextDocument
;
44 import com
.sun
.star
.uno
.UnoRuntime
;
45 import com
.sun
.star
.uno
.XInterface
;
46 import com
.sun
.star
.util
.URL
;
49 * Test for object that implements the following interfaces :
51 * <li><code>::com::sun::star::accessibility::XAccessibleComponent
53 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
55 * <li><code>::com::sun::star::accessibility::XAccessibleContext
57 * <li><code>::com::sun::star::accessibility::XAccessibleSelection
61 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
62 * @see com.sun.star.accessibility.XAccessibleContext
63 * @see com.sun.star.accessibility.XAccessibleComponent
64 * @see com.sun.star.accessibility.XAccessibleSelection
65 * @see ifc.accessibility._XAccessibleEventBroadcaster
66 * @see ifc.accessibility._XAccessibleContext
67 * @see ifc.accessibility._XAccessibleComponent
68 * @see ifc.accessibility._XAccessibleSelection
70 public class AccessibleTreeListBox
extends TestCase
{
72 static XDesktop the_Desk
;
73 static XTextDocument xTextDoc
;
76 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
78 protected void initialize(TestParameters Param
, PrintWriter log
) {
79 the_Desk
= UnoRuntime
.queryInterface(
80 XDesktop
.class, DesktopTools
.createDesktop((XMultiServiceFactory
)Param
.getMSF()));
84 * Disposes the document, if exists, created in
85 * <code>createTestEnvironment</code> method.
87 protected void cleanup( TestParameters Param
, PrintWriter log
) {
89 log
.println("disposing xTextDoc");
91 if (xTextDoc
!= null) {
97 * Creates a text document. Opens the DataSource browser.
98 * Creates an instance of the service <code>com.sun.star.awt.Toolkit</code>
99 * and gets active top window. Then obtains an accessible object with
100 * the role <code>AccessibleRole.TREE</code>.
101 * Object relations created :
103 * <li> <code>'EventProducer'</code> for
104 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
106 * <li> <code>'XAccessibleSelection.multiSelection'</code>
107 * of type <code>Boolean</code> for
108 * {@link ifc.accessibility._XAccessibleSelection}:
109 * indicates that component supports single selection mode.</li>
112 * @param tParam test parameters
113 * @param log writer to log information while testing
115 * @see com.sun.star.awt.Toolkit
116 * @see com.sun.star.accessibility.AccessibleRole
117 * @see ifc.accessibility._XAccessibleEventBroadcaster
118 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
120 protected TestEnvironment
createTestEnvironment(
121 TestParameters tParam
, PrintWriter log
) {
123 log
.println( "creating a test environment" );
125 if (xTextDoc
!= null) xTextDoc
.dispose();
127 // get a soffice factory object
128 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
131 log
.println( "creating a text document" );
132 xTextDoc
= SOF
.createTextDoc(null);
133 } catch ( com
.sun
.star
.uno
.Exception e
) {
134 // Some exception occurs.FAILED
135 e
.printStackTrace( log
);
136 throw new StatusException( "Couldn't create document", e
);
141 XModel aModel1
= UnoRuntime
.queryInterface(XModel
.class, xTextDoc
);
143 XController secondController
= aModel1
.getCurrentController();
145 XDispatchProvider aProv
= UnoRuntime
.
146 queryInterface(XDispatchProvider
.class, secondController
);
148 XDispatch getting
= null;
150 log
.println( "opening DatasourceBrowser" );
151 URL the_url
= new URL();
152 the_url
.Complete
= ".component:DB/DataSourceBrowser";
153 getting
= aProv
.queryDispatch(the_url
, "_beamer", 12);
154 PropertyValue
[] noArgs
= new PropertyValue
[0];
155 getting
.dispatch(the_url
, noArgs
);
159 XFrame the_frame1
= the_Desk
.getCurrentFrame();
161 if (the_frame1
== null) {
162 log
.println("Current frame was not found !!!");
165 XFrame the_frame2
= the_frame1
.findFrame("_beamer", 4);
167 the_frame2
.setName("DatasourceBrowser");
169 XInterface oObj
= null;
171 AccessibilityTools at
= new AccessibilityTools();
173 XWindow xWindow
= secondController
.getFrame().getContainerWindow();
175 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
177 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.TREE
);
179 log
.println("ImplementationName: "+ util
.utils
.getImplName(oObj
));
181 TestEnvironment tEnv
= new TestEnvironment(oObj
);
183 final XInitialization xInit
= UnoRuntime
.queryInterface(
184 XInitialization
.class, the_frame2
.getController());
186 Object
[] params
= new Object
[3];
187 PropertyValue param1
= new PropertyValue();
188 param1
.Name
= "DataSourceName";
189 param1
.Value
= "Bibliography";
191 PropertyValue param2
= new PropertyValue();
192 param2
.Name
= "CommandType";
193 param2
.Value
= new Integer(com
.sun
.star
.sdb
.CommandType
.TABLE
);
195 PropertyValue param3
= new PropertyValue();
196 param3
.Name
= "Command";
197 param3
.Value
= "biblio";
200 final Object
[] fParams
= params
;
202 // tEnv.addObjRelation("EventProducer",
203 // new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
204 // public void fireEvent() {
205 // fXComp.grabFocus();
209 tEnv
.addObjRelation("EventProducer",
210 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer(){
211 public void fireEvent() {
213 xInit
.initialize(fParams
);
214 } catch(com
.sun
.star
.uno
.Exception e
) {
220 tEnv
.addObjRelation("XAccessibleSelection.multiSelection",
227 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
230 private void shortWait() {
233 } catch (InterruptedException e
) {
234 System
.out
.println("While waiting :" + e
) ;