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 /**
49  * Test for object that implements the following interfaces :
50  * <ul>
51  *  <li><code>
52  *  ::com::sun::star::accessibility::XAccessibleContext</code></li>
53  *  <li><code>
54  *  ::com::sun::star::accessibility::XAccessibleEventBroadcaster
55  *  </code></li>
56  *  <li><code>
57  *  ::com::sun::star::accessibility::XAccessibleComponent</code></li>
58  *  <li><code>
59  *  ::com::sun::star::accessibility::XAccessibleExtendedComponent
60  *  </code></li>
61  * <li><code>
62  *  ::com::sun::star::accessibility::XAccessibleAction</code></li>
63  *  <li><code>
64  *  ::com::sun::star::accessibility::XAccessibleText</code></li>
65  *  <li><code>
66  *  ::com::sun::star::accessibility::XAccessibleValue</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.XAccessibleExtendedComponent
73  * @see com.sun.star.accessibility.XAccessibleAction
74  * @see com.sun.star.accessibility.XAccessibleText
75  * @see com.sun.star.accessibility.XAccessibleValue
76  * @see ifc.accessibility._XAccessibleEventBroadcaster
77  * @see ifc.accessibility._XAccessibleContext
78  * @see ifc.accessibility._XAccessibleComponent
79  * @see ifc.accessibility._XAccessibleExtendedComponent
80  * @see ifc.accessibility._XAccessibleAction
81  * @see ifc.accessibility._XAccessibleText
82  * @see ifc.accessibility._XAccessibleValue
83  */
84 public class AccessibleToolBoxItem extends TestCase {
85     private static XDesktop the_Desk;
86     private static XTextDocument xTextDoc;
87 
88     /**
89      * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
90      */
initialize(TestParameters Param, PrintWriter log)91     protected void initialize(TestParameters Param, PrintWriter log) {
92         the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class,
93                                                         DesktopTools.createDesktop(
94                                                                 (XMultiServiceFactory) Param.getMSF()));
95     }
96 
97     /**
98      * Disposes the document, if exists, created in
99      * <code>createTestEnvironment</code> method.
100      */
cleanup(TestParameters Param, PrintWriter log)101     protected void cleanup(TestParameters Param, PrintWriter log) {
102         log.println("disposing xTextDoc");
103 
104         if (xTextDoc != null) {
105             closeDoc();
106         }
107     }
108 
109     /**
110      * Creates a text document.
111      * Then obtains an accessible object with
112      * the role <code>AccessibleRole.PUSHBUTTON</code> and with the name
113      * <code>"Bold"</code>.
114      * Object relations created :
115      * <ul>
116      *  <li> <code>'EventProducer'</code> for
117      *      {@link ifc.accessibility._XAccessibleEventBroadcaster}</li>
118      *  <li> <code>'XAccessibleText.Text'</code> for
119      *      {@link ifc.accessibility._XAccessibleText}: the name of button</li>
120      * </ul>
121      *
122      * @param tParam test parameters
123      * @param log writer to log information while testing
124      *
125      * @see com.sun.star.awt.Toolkit
126      * @see com.sun.star.accessibility.AccessibleRole
127      * @see ifc.accessibility._XAccessibleEventBroadcaster
128      * @see ifc.accessibility._XAccessibleText
129      * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
130      * @see com.sun.star.accessibility.XAccessibleText
131      */
createTestEnvironment(TestParameters tParam, PrintWriter log)132     protected TestEnvironment createTestEnvironment(TestParameters tParam,
133                                                     PrintWriter log) {
134         log.println("creating a test environment");
135 
136         if (xTextDoc != null) {
137             closeDoc();
138         }
139 
140         // get a soffice factory object
141         SOfficeFactory SOF = SOfficeFactory.getFactory(
142                                      (XMultiServiceFactory) tParam.getMSF());
143 
144         try {
145             log.println("creating a text document");
146             xTextDoc = SOF.createTextDoc(null);
147         } catch (com.sun.star.uno.Exception e) {
148             // Some exception occured.FAILED
149             e.printStackTrace(log);
150             throw new StatusException("Couldn't create document", e);
151         }
152 
153         XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class,
154                                                            xTextDoc);
155 
156         XInterface oObj = null;
157 
158         AccessibilityTools at = new AccessibilityTools();
159 
160         XWindow xWindow = at.getCurrentContainerWindow(
161                                   (XMultiServiceFactory) tParam.getMSF(),
162                                   aModel);
163 
164         XAccessible xRoot = at.getAccessibleObject(xWindow);
165 
166 
167         at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
168         oObj = at.getAccessibleObjectForRole(xRoot,
169                                              AccessibleRole.TOGGLE_BUTTON,
170                                              "Bold");
171 
172         log.println("ImplementationName: " + util.utils.getImplName(oObj));
173 
174         TestEnvironment tEnv = new TestEnvironment(oObj);
175 
176         tEnv.addObjRelation("EditOnly",
177                             "This method isn't supported in this dialog");
178 
179         tEnv.addObjRelation("LimitedBounds", "yes");
180 
181         final XAccessibleAction oAction = (XAccessibleAction) UnoRuntime.queryInterface(
182                                                   XAccessibleAction.class,
183                                                   oObj);
184 
185         tEnv.addObjRelation("EventProducer",
186                             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
187             public void fireEvent() {
188                 try {
189                     oAction.doAccessibleAction(0);
190                 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
191                 }
192             }
193         });
194 
195         tEnv.addObjRelation("XAccessibleText.Text", "Bold");
196 
197         return tEnv;
198     }
199 
closeDoc()200     protected void closeDoc() {
201         util.DesktopTools.closeDoc(xTextDoc);
202     }
203 }
204