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._toolkit;
24 
25 import com.sun.star.accessibility.AccessibleRole;
26 import com.sun.star.accessibility.XAccessible;
27 import com.sun.star.accessibility.XAccessibleAction;
28 import com.sun.star.awt.XWindow;
29 import com.sun.star.frame.XDesktop;
30 import com.sun.star.frame.XModel;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.text.XTextDocument;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XInterface;
35 
36 import java.io.PrintWriter;
37 
38 import lib.StatusException;
39 import lib.TestCase;
40 import lib.TestEnvironment;
41 import lib.TestParameters;
42 
43 import util.AccessibilityTools;
44 import util.DesktopTools;
45 import util.SOfficeFactory;
46 
47 /**
48  * Test for object that implements the following interfaces :
49  * <ul>
50  *  <li><code>
51  *  ::com::sun::star::accessibility::XAccessibleContext</code></li>
52  *  <li><code>
53  *  ::com::sun::star::accessibility::XAccessibleEventBroadcaster
54  *  </code></li>
55  *  <li><code>
56  *  ::com::sun::star::accessibility::XAccessibleComponent</code></li>
57  *  <li><code>
58  *  ::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
59  * </ul> <p>
60  *
61  * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
62  * @see com.sun.star.accessibility.XAccessibleContext
63  * @see com.sun.star.accessibility.XAccessibleComponent
64  * @see com.sun.star.accessibility.XAccessibleExtendedComponent
65  * @see ifc.accessibility._XAccessibleEventBroadcaster
66  * @see ifc.accessibility._XAccessibleContext
67  * @see ifc.accessibility._XAccessibleComponent
68  * @see ifc.accessibility._XAccessibleExtendedComponent
69  */
70 public class AccessibleToolBox extends TestCase {
71     private static XDesktop the_Desk;
72     private static XTextDocument xTextDoc;
73 
74     /**
75      * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
76      */
initialize(TestParameters Param, PrintWriter log)77     protected void initialize(TestParameters Param, PrintWriter log) {
78         the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class,
79                 DesktopTools.createDesktop(
80                 (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         log.println("disposing xTextDoc");
89 
90         if (xTextDoc != null) {
91             util.DesktopTools.closeDoc(xTextDoc);
92         }
93     }
94 
95     /**
96      * Creates a text document.
97      * Then obtains an accessible object with
98      * the role <code>AccessibleRole.TOOLBAR</code>.
99      * Object relations created :
100      * <ul>
101      *  <li> <code>'EventProducer'</code> for
102      *      {@link ifc.accessibility._XAccessibleEventBroadcaster}:
103      *      grabs focus
104      *   </li>
105      * </ul>
106      *
107      * @param tParam test parameters
108      * @param log writer to log information while testing
109      *
110      * @see com.sun.star.awt.Toolkit
111      * @see com.sun.star.accessibility.AccessibleRole
112      * @see ifc.accessibility._XAccessibleEventBroadcaster
113      * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
114      */
createTestEnvironment(TestParameters tParam, PrintWriter log)115     protected TestEnvironment createTestEnvironment(TestParameters tParam,
116             PrintWriter log) {
117         log.println("creating a test environment");
118 
119         if (xTextDoc != null) {
120             util.DesktopTools.closeDoc(xTextDoc);
121         }
122 
123         XMultiServiceFactory msf = (XMultiServiceFactory) tParam.getMSF();
124 
125         // get a soffice factory object
126         SOfficeFactory SOF = SOfficeFactory.getFactory(msf);
127 
128         try {
129             log.println("creating a text document");
130             xTextDoc = SOF.createTextDoc(null);
131         } catch (com.sun.star.uno.Exception e) {
132             // Some exception occures.FAILED
133             e.printStackTrace(log);
134             throw new StatusException("Couldn't create document", e);
135         }
136 
137         XInterface oObj = null;
138 
139         XWindow xWindow = UnoRuntime.queryInterface(XModel.class, xTextDoc).
140             getCurrentController().getFrame().getContainerWindow();
141 
142         AccessibilityTools at = new AccessibilityTools();
143 
144         XAccessible xRoot = at.getAccessibleObject(xWindow);
145 
146         at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
147 
148         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TOOL_BAR);
149 
150         log.println("ImplementationName: " + util.utils.getImplName(oObj));
151 
152         TestEnvironment tEnv = new TestEnvironment(oObj);
153 
154         tEnv.addObjRelation("LimitedBounds", "yes");
155 
156         XAccessible acc = at.getAccessibleObject(oObj);
157         XAccessible child = null;
158 
159         try {
160             child = acc.getAccessibleContext().getAccessibleChild(0);
161         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
162         }
163 
164         util.dbg.printInterfaces(child);
165 
166         final XAccessibleAction action = (XAccessibleAction) UnoRuntime.queryInterface(
167                 XAccessibleAction.class,
168                 child);
169 
170         tEnv.addObjRelation("EventProducer",
171                 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
172             public void fireEvent() {
173                 try {
174                     action.doAccessibleAction(0);
175                 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
176                     System.out.println("Couldn't fire event");
177                 }
178             }
179         });
180 
181         return tEnv;
182     }
183 }
184