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.accessibility.XAccessibleAction;
39 import com.sun.star.accessibility.XAccessibleContext;
40 import com.sun.star.awt.XExtendedToolkit;
41 import com.sun.star.awt.XWindow;
42 import com.sun.star.beans.PropertyValue;
43 import com.sun.star.frame.XController;
44 import com.sun.star.frame.XDesktop;
45 import com.sun.star.frame.XDispatch;
46 import com.sun.star.frame.XDispatchProvider;
47 import com.sun.star.frame.XModel;
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 import com.sun.star.util.XURLTransformer;
54 
55 /**
56  * Test for object that implements the following interfaces :
57  * <ul>
58  *  <li><code>
59  *  ::com::sun::star::accessibility::XAccessibleContext</code></li>
60  *  <li><code>
61  *  ::com::sun::star::accessibility::XAccessibleEventBroadcaster
62  *  </code></li>
63  *  <li><code>
64  *  ::com::sun::star::accessibility::XAccessibleComponent</code></li>
65  *  <li><code>
66  *  ::com::sun::star::accessibility::XAccessibleText</code></li>
67  * </ul> <p>
68  *
69  * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
70  * @see com.sun.star.accessibility.XAccessibleContext
71  * @see com.sun.star.accessibility.XAccessibleComponent
72  * @see com.sun.star.accessibility.XAccessibleText
73  * @see ifc.accessibility._XAccessibleEventBroadcaster
74  * @see ifc.accessibility._XAccessibleContext
75  * @see ifc.accessibility._XAccessibleComponent
76  * @see ifc.accessibility._XAccessibleText
77  */
78 public class AccessibleIconChoiceCtrlEntry extends TestCase {
79 
80     static XDesktop the_Desk;
81     static XTextDocument xTextDoc;
82     static XAccessibleAction accCloseButton = null;
83 
84     /**
85      * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
86      */
initialize(TestParameters Param, PrintWriter log)87     protected void initialize(TestParameters Param, PrintWriter log) {
88         the_Desk = (XDesktop) UnoRuntime.queryInterface(
89                     XDesktop.class, DesktopTools.createDesktop((XMultiServiceFactory)Param.getMSF()));
90     }
91 
92     /**
93      * Closes the Hyperlink dialog.
94      * Disposes the document, if exists, created in
95      * <code>createTestEnvironment</code> method.
96      */
cleanup( TestParameters Param, PrintWriter log)97     protected void cleanup( TestParameters Param, PrintWriter log) {
98 
99         log.println("closing HyperlinkDialog");
100 
101         try {
102             if (accCloseButton != null) {
103                 accCloseButton.doAccessibleAction(0);
104             }
105         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
106             e.printStackTrace(log);
107         }
108 
109         log.println("disposing xTextDoc");
110 
111         if (xTextDoc != null) {
112             xTextDoc.dispose();
113         }
114     }
115 
116     /**
117      * Creates a text document. Opens the Hyperlink dialog.
118      * Creates an instance of the service
119      * <code>com.sun.star.awt.Toolkit</code> and gets active top window.
120      * Then obtains an accessible object with the role
121      * <code>AccessibleRole.LABEL</code> and with the name
122      * <code>"Internet"</code>.
123      * Object relations created :
124      * <ul>
125      *  <li> <code>'EventProducer'</code> for
126      *      {@link ifc.accessibility._XAccessibleEventBroadcaster}:
127      *      method <code>fireEvent()</code> is empty because object is transient
128      *   </li>
129      *  <li> <code>'XAccessibleText.Text'</code> for
130      *      {@link ifc.accessibility._XAccessibleText}:
131      *         the string representation of the item text
132      *   </li>
133      * </ul>
134      *
135      * @param tParam test parameters
136      * @param log writer to log information while testing
137      *
138      * @see com.sun.star.awt.Toolkit
139      * @see com.sun.star.accessibility.AccessibleRole
140      * @see ifc.accessibility._XAccessibleEventBroadcaster
141      * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
142      */
createTestEnvironment( TestParameters tParam, PrintWriter log)143     protected TestEnvironment createTestEnvironment(
144         TestParameters tParam, PrintWriter log) {
145 
146         log.println( "creating a test environment" );
147 
148         if (xTextDoc != null) xTextDoc.dispose();
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 occured.FAILED
158             e.printStackTrace( log );
159             throw new StatusException( "Couldn't create document", e );
160         }
161 
162         shortWait();
163 
164         XModel aModel1 = (XModel)
165                     UnoRuntime.queryInterface(XModel.class, xTextDoc);
166 
167         XController secondController = aModel1.getCurrentController();
168 
169         XDispatchProvider aProv = (XDispatchProvider)UnoRuntime.
170             queryInterface(XDispatchProvider.class, secondController);
171 
172         XURLTransformer urlTransf = null;
173 
174         try {
175             XInterface transf = (XInterface)((XMultiServiceFactory)tParam.getMSF()).createInstance
176                 ("com.sun.star.util.URLTransformer");
177             urlTransf = (XURLTransformer)UnoRuntime.queryInterface
178                 (XURLTransformer.class, transf);
179         } catch (com.sun.star.uno.Exception e) {
180             e.printStackTrace(log);
181             throw new StatusException("Couldn't create URLTransformer", e );
182         }
183 
184         XDispatch getting = null;
185         log.println( "opening HyperlinkDialog" );
186         URL[] url = new URL[1];
187         url[0] = new URL();
188         url[0].Complete = ".uno:HyperlinkDialog";
189         urlTransf.parseStrict(url);
190         getting = aProv.queryDispatch(url[0], "", 0);
191         PropertyValue[] noArgs = new PropertyValue[0];
192         getting.dispatch(url[0], noArgs);
193 
194         shortWait();
195 
196         XInterface oObj = null;
197         try {
198             oObj = (XInterface) ((XMultiServiceFactory)tParam.getMSF()).createInstance
199                 ("com.sun.star.awt.Toolkit") ;
200         } catch (com.sun.star.uno.Exception e) {
201             log.println("Couldn't get toolkit");
202             e.printStackTrace(log);
203             throw new StatusException("Couldn't get toolkit", e );
204         }
205 
206         XExtendedToolkit tk = (XExtendedToolkit)
207             UnoRuntime.queryInterface(XExtendedToolkit.class, oObj);
208 
209         AccessibilityTools at = new AccessibilityTools();
210 
211         shortWait();
212 
213         XWindow xWindow = (XWindow)
214             UnoRuntime.queryInterface(XWindow.class, tk.getActiveTopWindow());
215 
216         XAccessible xRoot = at.getAccessibleObject(xWindow);
217 
218         oObj = at.getAccessibleObjectForRole(xRoot,
219             AccessibleRole.LABEL, "Internet");
220 
221         XAccessibleContext closeButton = at.getAccessibleObjectForRole(xRoot,
222             AccessibleRole.PUSH_BUTTON, "Close");
223 
224         accCloseButton = (XAccessibleAction)
225             UnoRuntime.queryInterface(XAccessibleAction.class, closeButton);
226 
227         log.println("ImplementationName: "+ util.utils.getImplName(oObj));
228 
229         TestEnvironment tEnv = new TestEnvironment(oObj);
230 
231         tEnv.addObjRelation("EventProducer",
232             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
233                 public void fireEvent() {
234                 }
235             });
236 
237         tEnv.addObjRelation("XAccessibleText.Text", "Internet");
238 
239         tEnv.addObjRelation("EditOnly",
240                     "This method isn't supported in this dialog");
241 
242         tEnv.addObjRelation("LimitedBounds",
243                     "only delivers senseful values for getCharacterBounds(0,length-1)");
244 
245         return tEnv;
246     }
247 
248     /**
249     * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
250     * reset</code> call.
251     */
shortWait()252     private void shortWait() {
253         try {
254             Thread.sleep(5000);
255         } catch (InterruptedException e) {
256             System.out.println("While waiting :" + e) ;
257         }
258     }
259 
260 }
261