xref: /AOO41X/main/qadevOOo/tests/java/mod/_svtools/AccessibleTreeListBoxEntry.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package mod._svtools;
28 
29 import com.sun.star.view.XSelectionSupplier;
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.AccessibilityTools;
37 import util.DesktopTools;
38 import util.SOfficeFactory;
39 
40 import com.sun.star.accessibility.AccessibleRole;
41 import com.sun.star.accessibility.XAccessible;
42 import com.sun.star.awt.XWindow;
43 import com.sun.star.beans.PropertyValue;
44 import com.sun.star.frame.XController;
45 import com.sun.star.frame.XDesktop;
46 import com.sun.star.frame.XDispatch;
47 import com.sun.star.frame.XDispatchProvider;
48 import com.sun.star.frame.XFrame;
49 import com.sun.star.frame.XModel;
50 import com.sun.star.lang.XInitialization;
51 import com.sun.star.lang.XMultiServiceFactory;
52 import com.sun.star.text.XTextDocument;
53 import com.sun.star.uno.UnoRuntime;
54 import com.sun.star.uno.XInterface;
55 import com.sun.star.util.URL;
56 import com.sun.star.util.XCloseable;
57 
58 
59 /**
60  * Test for object that implements the following interfaces :
61  * <ul>
62  *  <li><code>::com::sun::star::accessibility::XAccessibleComponent
63  *  </code></li>
64  *  <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
65  *  </code></li>
66  *  <li><code>::com::sun::star::accessibility::XAccessibleContext
67  *  </code></li>
68  *  <li><code>::com::sun::star::accessibility::XAccessibleSelection
69  *  </code></li>
70  *  <li><code>::com::sun::star::accessibility::XAccessibleAction
71  *  </code></li>
72  *  <li><code>::com::sun::star::accessibility::XAccessibleText
73  *  </code></li>
74  * </ul> <p>
75  *
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.XAccessibleSelection
80  * @see com.sun.star.accessibility.XAccessibleAction
81  * @see com.sun.star.accessibility.XAccessibleText
82  * @see ifc.accessibility._XAccessibleEventBroadcaster
83  * @see ifc.accessibility._XAccessibleContext
84  * @see ifc.accessibility._XAccessibleComponent
85  * @see ifc.accessibility._XAccessibleSelection
86  * @see ifc.accessibility._XAccessibleAction
87  * @see ifc.accessibility._XAccessibleText
88  */
89 public class AccessibleTreeListBoxEntry extends TestCase {
90     static XDesktop the_Desk;
91     static XTextDocument xTextDoc;
92 
93     /**
94      * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
95      */
96     protected void initialize(TestParameters Param, PrintWriter log) {
97         the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class,
98                                                         DesktopTools.createDesktop(
99 		(XMultiServiceFactory) Param.getMSF()));
100     }
101 
102     /**
103      * Disposes the document, if exists, created in
104      * <code>createTestEnvironment</code> method.
105      */
106     protected void cleanup(TestParameters Param, PrintWriter log) {
107         log.println("disposing xTextDoc");
108 
109         if (xTextDoc != null) {
110             closeDoc();
111         }
112     }
113 
114     /**
115      * Creates a text document. Opens the DataSource browser.
116      * Creates an instance of the service <code>com.sun.star.awt.Toolkit</code>
117      * and gets active top window. Then obtains an accessible object with
118      * the role <code>AccessibleRole.LABEL</code> and with the name
119      * <code>"Bibliography"</code>.
120      * Object relations created :
121      * <ul>
122      *  <li> <code>'EventProducer'</code> for
123      *      {@link ifc.accessibility._XAccessibleEventBroadcaster}:
124      *   </li>
125      *  <li> <code>'XAccessibleSelection.multiSelection'</code>
126      *  of type <code>Boolean</code> for
127      *  {@link ifc.accessibility._XAccessibleSelection}:
128      *   indicates that component supports single selection mode.</li>
129      *   <li> <code>'XAccessibleText.Text'</code> for
130      *   {@link ifc.accessibility._XAccessibleText}:
131      *    the text of the component</li>
132      * </ul>
133      *
134      * @param tParam test parameters
135      * @param log writer to log information while testing
136      *
137      * @see com.sun.star.awt.Toolkit
138      * @see com.sun.star.accessibility.AccessibleRole
139      * @see ifc.accessibility._XAccessibleEventBroadcaster
140      * @see ifc.accessibility._XAccessibleSelection
141      * @see ifc.accessibility._XAccessibleText
142      * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
143      * @see com.sun.star.accessibility.XAccessibleSelection
144      * @see com.sun.star.accessibility.XAccessibleText
145      */
146     protected TestEnvironment createTestEnvironment(TestParameters tParam,
147                                                     PrintWriter log) {
148         log.println("creating a test environment");
149 
150         if (xTextDoc != null) {
151             closeDoc();
152         }
153 
154         // get a soffice factory object
155         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF());
156 
157         try {
158             log.println("creating a text document");
159             xTextDoc = SOF.createTextDoc(null);
160         } catch (com.sun.star.uno.Exception e) {
161             // Some exception occures.FAILED
162             e.printStackTrace(log);
163             throw new StatusException("Couldn't create document", e);
164         }
165 
166         shortWait();
167 
168         XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class,
169                                                             xTextDoc);
170 
171         XController secondController = aModel1.getCurrentController();
172 
173         XDispatchProvider aProv = (XDispatchProvider) UnoRuntime.queryInterface(
174                                           XDispatchProvider.class,
175                                           secondController);
176 
177         XDispatch getting = null;
178 
179         log.println("opening DatasourceBrowser");
180 
181         URL the_url = new URL();
182         the_url.Complete = ".component:DB/DataSourceBrowser";
183         getting = aProv.queryDispatch(the_url, "_beamer", 12);
184 
185         PropertyValue[] noArgs = new PropertyValue[0];
186         getting.dispatch(the_url, noArgs);
187 
188         shortWait();
189 
190         XFrame the_frame1 = the_Desk.getCurrentFrame();
191 
192         if (the_frame1 == null) {
193             log.println("Current frame was not found !!!");
194         }
195 
196         XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);
197 
198         the_frame2.setName("DatasourceBrowser");
199 
200         XInterface oObj = null;
201 
202         XInitialization xInit = (XInitialization) UnoRuntime.queryInterface(
203                                         XInitialization.class,
204                                         the_frame2.getController());
205 
206         PropertyValue[] params = new PropertyValue[3];
207         PropertyValue param1 = new PropertyValue();
208         param1.Name = "DataSourceName";
209         param1.Value = "Bibliography";
210         params[0] = param1;
211 
212         PropertyValue param2 = new PropertyValue();
213         param2.Name = "CommandType";
214         param2.Value = new Integer(com.sun.star.sdb.CommandType.QUERY);
215         params[1] = param2;
216 
217         PropertyValue param3 = new PropertyValue();
218         param3.Name = "Command";
219         param3.Value = "select * from biblio";
220         params[2] = param3;
221 
222         XController xCont = the_frame2.getController();
223 
224         XSelectionSupplier xSelect = (XSelectionSupplier) UnoRuntime.queryInterface(
225             XSelectionSupplier.class, xCont);
226 
227         try {
228             xSelect.select(params);
229         } catch (com.sun.star.lang.IllegalArgumentException ex) {
230             throw new StatusException("Could not select Biblio-Database", ex);
231         }
232 
233         shortWait();
234 
235         AccessibilityTools at = new AccessibilityTools();
236 
237         XWindow xWindow = secondController.getFrame().getContainerWindow();
238 
239         XAccessible xRoot = at.getAccessibleObject(xWindow);
240 
241         at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
242 
243         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.LABEL,
244                                              "Bibliography");
245 
246         log.println("ImplementationName: " + util.utils.getImplName(oObj));
247 
248         TestEnvironment tEnv = new TestEnvironment(oObj);
249 
250         tEnv.addObjRelation("EditOnly",
251                             "This method isn't supported in this component");
252 
253         //adding ObjectRelation for XAccessibleText
254         tEnv.addObjRelation("LimitedBounds", "true");
255 
256 
257         tEnv.addObjRelation("EventProducer",
258                             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
259             public void fireEvent() {
260             }
261         });
262 
263         tEnv.addObjRelation("XAccessibleSelection.multiSelection",
264                             new Boolean(false));
265 
266         tEnv.addObjRelation("XAccessibleText.Text", "Bibliography");
267 
268         return tEnv;
269     }
270 
271     /**
272     * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
273     * reset</code> call.
274     */
275     private void shortWait() {
276         try {
277             Thread.sleep(5000);
278         } catch (InterruptedException e) {
279             System.out.println("While waiting :" + e);
280         }
281     }
282 
283     protected void closeDoc() {
284         XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
285                                     XCloseable.class, xTextDoc);
286 
287         try {
288             closer.close(true);
289         } catch (com.sun.star.util.CloseVetoException e) {
290             log.println("Couldn't close document " + e.getMessage());
291         } catch (com.sun.star.lang.DisposedException e) {
292             log.println("Couldn't close document " + e.getMessage());
293         }
294     }
295 }