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 com.sun.star.view.XSelectionSupplier;
27 import java.io.PrintWriter;
28 
29 import lib.StatusException;
30 import lib.TestCase;
31 import lib.TestEnvironment;
32 import lib.TestParameters;
33 import util.AccessibilityTools;
34 import util.DesktopTools;
35 import util.SOfficeFactory;
36 
37 import com.sun.star.accessibility.AccessibleRole;
38 import com.sun.star.accessibility.XAccessible;
39 import com.sun.star.awt.XWindow;
40 import com.sun.star.beans.PropertyValue;
41 import com.sun.star.frame.XController;
42 import com.sun.star.frame.XDesktop;
43 import com.sun.star.frame.XDispatch;
44 import com.sun.star.frame.XDispatchProvider;
45 import com.sun.star.frame.XFrame;
46 import com.sun.star.frame.XModel;
47 import com.sun.star.lang.XInitialization;
48 import com.sun.star.lang.XMultiServiceFactory;
49 import com.sun.star.text.XTextDocument;
50 import com.sun.star.uno.UnoRuntime;
51 import com.sun.star.uno.XInterface;
52 import com.sun.star.util.URL;
53 
54 /**
55  * Test for object that implements the following interfaces :
56  * <ul>
57  *  <li>
58  *      <code>::com::sun::star::accessibility::XAccessibleContext
59  *  </code></li>
60  *  <li>
61  *      <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
62  *  </code></li>
63  * </ul> <p>
64  *
65  * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
66  * @see com.sun.star.accessibility.XAccessibleContext
67  * @see ifc.accessibility._XAccessibleEventBroadcaster
68  * @see ifc.accessibility._XAccessibleContext
69  */
70 public class AccessibleBrowseBoxHeaderCell extends TestCase {
71 
72     static XDesktop the_Desk;
73     static XTextDocument xTextDoc;
74 
75     /**
76      * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
77      */
initialize(TestParameters Param, PrintWriter log)78     protected void initialize(TestParameters Param, PrintWriter log) {
79         the_Desk = (XDesktop) UnoRuntime.queryInterface(
80                     XDesktop.class, DesktopTools.createDesktop((XMultiServiceFactory)Param.getMSF()));
81     }
82 
83     /**
84      * Disposes the document, if exists, created in
85      * <code>createTestEnvironment</code> method.
86      */
cleanup( TestParameters Param, PrintWriter log)87     protected void cleanup( TestParameters Param, PrintWriter log) {
88 
89         log.println("disposing xTextDoc");
90 
91         if (xTextDoc != null) {
92             xTextDoc.dispose();
93         }
94     }
95 
96     /**
97      * Creates a text document. Opens the DataSource browser and loads
98      * the table. Creates an instance of the service
99      * <code>com.sun.star.awt.Toolkit</code> and gets active top window.
100      * Then obtains an accessible object with the role
101      * <code>AccessibleRole.UNKNOWN</code> and with the name
102      * <code>"Identifier"</code>.
103      * Object relations created :
104      * <ul>
105      *  <li> <code>'EventProducer'</code> for
106      *      {@link ifc.accessibility._XAccessibleEventBroadcaster}:
107      *      method <code>fireEvent()</code> is empty because object is transient
108      *   </li>
109      * </ul>
110      *
111      * @param tParam test parameters
112      * @param log writer to log information while testing
113      *
114      * @see com.sun.star.awt.Toolkit
115      * @see com.sun.star.accessibility.AccessibleRole
116      * @see ifc.accessibility._XAccessibleEventBroadcaster
117      * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
118      */
createTestEnvironment( TestParameters tParam, PrintWriter log)119     protected TestEnvironment createTestEnvironment(
120         TestParameters tParam, PrintWriter log) {
121 
122         log.println( "creating a test environment" );
123 
124         if (xTextDoc != null) xTextDoc.dispose();
125 
126         // get a soffice factory object
127         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
128 
129         try {
130             log.println( "creating a text document" );
131             xTextDoc = SOF.createTextDoc(null);
132         } catch ( com.sun.star.uno.Exception e ) {
133             // Some exception occures.FAILED
134             e.printStackTrace( log );
135             throw new StatusException( "Couldn't create document", e );
136         }
137 
138         shortWait();
139 
140         XModel aModel1 = (XModel)
141                     UnoRuntime.queryInterface(XModel.class, xTextDoc);
142 
143         XController secondController = aModel1.getCurrentController();
144 
145         XDispatchProvider aProv = (XDispatchProvider)UnoRuntime.
146             queryInterface(XDispatchProvider.class, secondController);
147 
148         XDispatch getting = null;
149 
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);
156 
157         shortWait();
158 
159         XFrame the_frame1 = the_Desk.getCurrentFrame();
160 
161         if (the_frame1 == null) {
162             log.println("Current frame was not found !!!");
163         }
164 
165         XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);
166 
167         the_frame2.setName("DatasourceBrowser");
168 
169         XInterface oObj = null;
170 
171         final XInitialization xInit = (XInitialization)
172                 UnoRuntime.queryInterface(
173                         XInitialization.class, the_frame2.getController());
174 
175         PropertyValue[] params = new PropertyValue[3];
176         PropertyValue param1 = new PropertyValue();
177         param1.Name = "DataSourceName";
178         param1.Value = "Bibliography";
179         params[0] = param1;
180         PropertyValue param2 = new PropertyValue();
181         param2.Name = "CommandType";
182         param2.Value = new Integer(com.sun.star.sdb.CommandType.TABLE);
183         params[1] = param2;
184         PropertyValue param3 = new PropertyValue();
185         param3.Name = "Command";
186         param3.Value = "biblio";
187         params[2] = param3;
188 
189         XController xCont = the_frame2.getController();
190 
191         XSelectionSupplier xSelect = (XSelectionSupplier) UnoRuntime.queryInterface(
192             XSelectionSupplier.class, xCont);
193 
194         try {
195             xSelect.select(params);
196         } catch (com.sun.star.lang.IllegalArgumentException ex) {
197             throw new StatusException("Could not select Biblio-Database", ex);
198         }
199 
200         AccessibilityTools at = new AccessibilityTools();
201 
202         XWindow xWindow = secondController.getFrame().getContainerWindow();
203 
204         XAccessible xRoot = at.getAccessibleObject(xWindow);
205 
206         at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
207 
208         oObj = at.getAccessibleObjectForRole(xRoot,
209             AccessibleRole.ROW_HEADER);
210 
211         log.println("ImplementationName: "+ util.utils.getImplName(oObj));
212 
213         TestEnvironment tEnv = new TestEnvironment(oObj);
214 
215         tEnv.addObjRelation("EventProducer",
216             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
217                 public void fireEvent() {
218                 }
219             });
220 
221         return tEnv;
222     }
223 
224     /**
225     * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
226     * reset</code> call.
227     */
shortWait()228     private void shortWait() {
229         try {
230             Thread.sleep(5000);
231         } catch (InterruptedException e) {
232             System.out.println("While waiting :" + e) ;
233         }
234     }
235 
236 }
237