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