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 
24 package mod._svtools;
25 
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 
53 /**
54  * Test for object that implements the following interfaces :
55  * <ul>
56  *  <li><code>::com::sun::star::accessibility::XAccessibleComponent
57  *  </code></li>
58  *  <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
59  *  </code></li>
60  *  <li><code>::com::sun::star::accessibility::XAccessibleContext
61  *  </code></li>
62  *  <li><code>::com::sun::star::accessibility::XAccessibleSelection
63  *  </code></li>
64  * </ul> <p>
65  *
66  * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
67  * @see com.sun.star.accessibility.XAccessibleContext
68  * @see com.sun.star.accessibility.XAccessibleComponent
69  * @see com.sun.star.accessibility.XAccessibleSelection
70  * @see ifc.accessibility._XAccessibleEventBroadcaster
71  * @see ifc.accessibility._XAccessibleContext
72  * @see ifc.accessibility._XAccessibleComponent
73  * @see ifc.accessibility._XAccessibleSelection
74  */
75 public class AccessibleTreeListBox extends TestCase {
76 
77     static XDesktop the_Desk;
78     static XTextDocument xTextDoc;
79 
80     /**
81      * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
82      */
initialize(TestParameters Param, PrintWriter log)83     protected void initialize(TestParameters Param, PrintWriter log) {
84         the_Desk = (XDesktop) UnoRuntime.queryInterface(
85                     XDesktop.class, DesktopTools.createDesktop((XMultiServiceFactory)Param.getMSF()));
86     }
87 
88     /**
89      * Disposes the document, if exists, created in
90      * <code>createTestEnvironment</code> method.
91      */
cleanup( TestParameters Param, PrintWriter log)92     protected void cleanup( TestParameters Param, PrintWriter log) {
93 
94         log.println("disposing xTextDoc");
95 
96         if (xTextDoc != null) {
97             xTextDoc.dispose();
98         }
99     }
100 
101     /**
102      * Creates a text document. Opens the DataSource browser.
103      * Creates an instance of the service <code>com.sun.star.awt.Toolkit</code>
104      * and gets active top window. Then obtains an accessible object with
105      * the role <code>AccessibleRole.TREE</code>.
106      * Object relations created :
107      * <ul>
108      *  <li> <code>'EventProducer'</code> for
109      *      {@link ifc.accessibility._XAccessibleEventBroadcaster}:
110      *   </li>
111      *  <li> <code>'XAccessibleSelection.multiSelection'</code>
112      *  of type <code>Boolean</code> for
113      *  {@link ifc.accessibility._XAccessibleSelection}:
114      *   indicates that component supports single selection mode.</li>
115      * </ul>
116      *
117      * @param tParam test parameters
118      * @param log writer to log information while testing
119      *
120      * @see com.sun.star.awt.Toolkit
121      * @see com.sun.star.accessibility.AccessibleRole
122      * @see ifc.accessibility._XAccessibleEventBroadcaster
123      * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
124      */
createTestEnvironment( TestParameters tParam, PrintWriter log)125     protected TestEnvironment createTestEnvironment(
126         TestParameters tParam, PrintWriter log) {
127 
128         log.println( "creating a test environment" );
129 
130         if (xTextDoc != null) xTextDoc.dispose();
131 
132         // get a soffice factory object
133         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
134 
135         try {
136             log.println( "creating a text document" );
137             xTextDoc = SOF.createTextDoc(null);
138         } catch ( com.sun.star.uno.Exception e ) {
139             // Some exception occured.FAILED
140             e.printStackTrace( log );
141             throw new StatusException( "Couldn't create document", e );
142         }
143 
144         shortWait();
145 
146         XModel aModel1 = (XModel)
147                     UnoRuntime.queryInterface(XModel.class, xTextDoc);
148 
149         XController secondController = aModel1.getCurrentController();
150 
151         XDispatchProvider aProv = (XDispatchProvider)UnoRuntime.
152             queryInterface(XDispatchProvider.class, secondController);
153 
154         XDispatch getting = null;
155 
156         log.println( "opening DatasourceBrowser" );
157         URL the_url = new URL();
158         the_url.Complete = ".component:DB/DataSourceBrowser";
159         getting = aProv.queryDispatch(the_url, "_beamer", 12);
160         PropertyValue[] noArgs = new PropertyValue[0];
161         getting.dispatch(the_url, noArgs);
162 
163         shortWait();
164 
165         XFrame the_frame1 = the_Desk.getCurrentFrame();
166 
167         if (the_frame1 == null) {
168             log.println("Current frame was not found !!!");
169         }
170 
171         XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);
172 
173         the_frame2.setName("DatasourceBrowser");
174 
175         XInterface oObj = null;
176 
177         AccessibilityTools at = new AccessibilityTools();
178 
179         XWindow xWindow = secondController.getFrame().getContainerWindow();
180 
181         XAccessible xRoot = at.getAccessibleObject(xWindow);
182 
183         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TREE);
184 
185         log.println("ImplementationName: "+ util.utils.getImplName(oObj));
186 
187         TestEnvironment tEnv = new TestEnvironment(oObj);
188 
189         final XInitialization xInit = (XInitialization)
190                 UnoRuntime.queryInterface(
191                         XInitialization.class, the_frame2.getController());
192 
193         Object[] params = new Object[3];
194         PropertyValue param1 = new PropertyValue();
195         param1.Name = "DataSourceName";
196         param1.Value = "Bibliography";
197         params[0] = param1;
198         PropertyValue param2 = new PropertyValue();
199         param2.Name = "CommandType";
200         param2.Value = new Integer(com.sun.star.sdb.CommandType.TABLE);
201         params[1] = param2;
202         PropertyValue param3 = new PropertyValue();
203         param3.Name = "Command";
204         param3.Value = "biblio";
205         params[2] = param3;
206 
207         final Object[] fParams = params;
208 
209 //        tEnv.addObjRelation("EventProducer",
210 //            new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
211 //                public void fireEvent() {
212 //                    fXComp.grabFocus();
213 //                }
214 //            });
215 
216         tEnv.addObjRelation("EventProducer",
217             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
218                 public void fireEvent() {
219                     try {
220                         xInit.initialize(fParams);
221                     } catch(com.sun.star.uno.Exception e) {
222                         e.printStackTrace();
223                     }
224                 }
225             });
226 
227         tEnv.addObjRelation("XAccessibleSelection.multiSelection",
228             new Boolean(false));
229 
230         return tEnv;
231     }
232 
233     /**
234     * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
235     * reset</code> call.
236     */
shortWait()237     private void shortWait() {
238         try {
239             Thread.sleep(5000);
240         } catch (InterruptedException e) {
241             System.out.println("While waiting :" + e) ;
242         }
243     }
244 
245 }
246