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 java.io.PrintWriter;
26 
27 import lib.StatusException;
28 import lib.TestCase;
29 import lib.TestEnvironment;
30 import lib.TestParameters;
31 import util.AccessibilityTools;
32 import util.DesktopTools;
33 import util.SOfficeFactory;
34 
35 import com.sun.star.accessibility.AccessibleRole;
36 import com.sun.star.accessibility.XAccessible;
37 import com.sun.star.awt.XWindow;
38 import com.sun.star.beans.PropertyValue;
39 import com.sun.star.frame.XController;
40 import com.sun.star.frame.XDesktop;
41 import com.sun.star.frame.XDispatch;
42 import com.sun.star.frame.XDispatchProvider;
43 import com.sun.star.frame.XFrame;
44 import com.sun.star.frame.XModel;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.text.XTextDocument;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
49 import com.sun.star.util.URL;
50 import com.sun.star.view.XSelectionSupplier;
51 
52 public class AccessibleBrowseBox extends TestCase {
53 
54     static XDesktop the_Desk;
55     static XTextDocument xTextDoc;
56 
57     /**
58      * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
59      */
initialize(TestParameters Param, PrintWriter log)60     protected void initialize(TestParameters Param, PrintWriter log) {
61         the_Desk = (XDesktop) UnoRuntime.queryInterface(
62             XDesktop.class, DesktopTools.createDesktop((XMultiServiceFactory) Param.getMSF()));
63     }
64 
65     /**
66      * Disposes the document, if exists, created in
67      * <code>createTestEnvironment</code> method.
68      */
cleanup(TestParameters Param, PrintWriter log)69     protected void cleanup(TestParameters Param, PrintWriter log) {
70 
71         log.println("disposing xTextDoc");
72 
73         if (xTextDoc != null) {
74             xTextDoc.dispose();
75         }
76     }
77 
78     /**
79      * Called to create an instance of <code>TestEnvironment</code> with an
80      * object to test and related objects. Subclasses should implement this
81      * method to provide the implementation and related objects. The method is
82      * called from <code>getTestEnvironment()</code>.
83      *
84      * @param tParam test parameters
85      * @param log writer to log information while testing
86      *
87      * @see TestEnvironment
88      * @see #getTestEnvironment
89      */
createTestEnvironment(TestParameters tParam, PrintWriter log)90     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
91 
92         log.println("creating a test environment");
93 
94         if (xTextDoc != null) {
95             xTextDoc.dispose();        // get a soffice factory object
96         }
97         SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory) tParam.getMSF());
98 
99         try {
100             log.println("creating a text document");
101             xTextDoc = SOF.createTextDoc(null);
102         } catch (com.sun.star.uno.Exception e) {
103             // Some exception occures.FAILED
104             e.printStackTrace(log);
105             throw new StatusException("Couldn't create document", e);
106         }
107 
108         shortWait();
109 
110         XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class, xTextDoc);
111 
112         XController secondController = aModel1.getCurrentController();
113 
114 
115         XDispatchProvider aProv = (XDispatchProvider) UnoRuntime.queryInterface(XDispatchProvider.class,
116             secondController);
117 
118         XDispatch getting = null;
119 
120         log.println("opening DatasourceBrowser");
121         URL the_url = new URL();
122         the_url.Complete = ".component:DB/DataSourceBrowser";
123         getting = aProv.queryDispatch(the_url, "_beamer", 12);
124         PropertyValue[] noArgs = new PropertyValue[0];
125         getting.dispatch(the_url, noArgs);
126 
127         shortWait();
128 
129         XFrame the_frame1 = the_Desk.getCurrentFrame();
130 
131         if (the_frame1 == null) {
132             log.println("Current frame was not found !!!");
133         }
134 
135         XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);
136 
137         the_frame2.setName("DatasourceBrowser");
138 
139         XInterface oObj = null;
140 
141         final XSelectionSupplier xSelect = (XSelectionSupplier) UnoRuntime.queryInterface(
142             XSelectionSupplier.class, the_frame2.getController());
143 
144         PropertyValue[] params = new PropertyValue[]{new PropertyValue(), new PropertyValue(), new PropertyValue()};
145         params[0].Name = "DataSourceName";
146         params[0].Value = "Bibliography";
147         params[1].Name = "CommandType";
148         params[1].Value = new Integer(com.sun.star.sdb.CommandType.TABLE);
149         params[2].Name = "Command";
150         params[2].Value = "biblio";
151 
152         final PropertyValue[] fParams = params;
153 
154         shortWait();
155 
156         AccessibilityTools at = new AccessibilityTools();
157 
158         XWindow xWindow = secondController.getFrame().getContainerWindow();
159 
160         XAccessible xRoot = at.getAccessibleObject(xWindow);
161 
162         at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
163 
164         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL, "", "AccessibleBrowseBox");
165 
166         log.println("ImplementationName: " + util.utils.getImplName(oObj));
167 
168         TestEnvironment tEnv = new TestEnvironment(oObj);
169 
170 
171         tEnv.addObjRelation("EventProducer",
172             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
173 
174                 public void fireEvent() {
175                     try {
176                         xSelect.select(fParams);
177                     } catch (com.sun.star.uno.Exception e) {
178                         e.printStackTrace();
179                     }
180                 }
181             });
182 
183         return tEnv;
184     }
185 
186     /**
187      * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
188      * reset</code> call.
189      */
shortWait()190     private void shortWait() {
191         try {
192             Thread.sleep(5000);
193         } catch (InterruptedException e) {
194             System.out.println("While waiting :" + e);
195         }
196     }
197 }
198