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.XAccessibleContext;
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::XAccessibleValue</code></li>
63  *  <li><code>
64  *  ::com::sun::star::accessibility::XAccessibleAction</code></li>
65  * </ul> <p>
66  *
67  * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
68  * @see com.sun.star.accessibility.XAccessibleContext
69  * @see com.sun.star.accessibility.XAccessibleComponent
70  * @see com.sun.star.accessibility.XAccessibleExtendedComponent
71  * @see com.sun.star.accessibility.XAccessibleValue
72  * @see com.sun.star.accessibility.XAccessibleAction
73  * @see ifc.accessibility._XAccessibleEventBroadcaster
74  * @see ifc.accessibility._XAccessibleContext
75  * @see ifc.accessibility._XAccessibleComponent
76  * @see ifc.accessibility.XAccessibleExtendedComponent
77  * @see ifc.accessibility.XAccessibleValue
78  * @see ifc.accessibility.XAccessibleAction
79  */
80 public class AccessibleStatusBarItem extends TestCase {
81     private static XDesktop the_Desk;
82     private static XTextDocument xTextDoc;
83 
84     /**
85      * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
86      */
87     protected void initialize(TestParameters Param, PrintWriter log) {
88         the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class,
89                                                         DesktopTools.createDesktop(
90                                                                 (XMultiServiceFactory) Param.getMSF()));
91     }
92 
93     /**
94      * Disposes the document, if exists, created in
95      * <code>createTestEnvironment</code> method.
96      */
97     protected void cleanup(TestParameters Param, PrintWriter log) {
98         log.println("disposing xTextDoc");
99 
100         if (xTextDoc != null) {
101             util.DesktopTools.closeDoc(xTextDoc);
102         }
103     }
104 
105     /**
106      * Creates a text document.
107      * Then obtains an accessible object with
108      * the role <code>AccessibleRole.SCROLLBAR</code>.
109      * Object relations created :
110      * <ul>
111      *  <li> <code>'EventProducer'</code> for
112      *      {@link ifc.accessibility._XAccessibleEventBroadcaster}:
113      *      grabs focus </li>
114      * </ul>
115      *
116      * @param tParam test parameters
117      * @param log writer to log information while testing
118      *
119      * @see com.sun.star.awt.Toolkit
120      * @see com.sun.star.accessibility.AccessibleRole
121      * @see ifc.accessibility._XAccessibleEventBroadcaster
122      * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
123      */
124     protected TestEnvironment createTestEnvironment(TestParameters tParam,
125                                                     PrintWriter log) {
126         log.println("creating a test environment");
127 
128         if (xTextDoc != null) {
129             util.DesktopTools.closeDoc(xTextDoc);
130         }
131 
132         // get a soffice factory object
133         SOfficeFactory SOF = SOfficeFactory.getFactory(
134                                      (XMultiServiceFactory) tParam.getMSF());
135 
136         try {
137             log.println("creating a text document");
138             xTextDoc = SOF.createTextDoc(null);
139         } catch (com.sun.star.uno.Exception e) {
140             // Some exception occures.FAILED
141             e.printStackTrace(log);
142             throw new StatusException("Couldn't create document", e);
143         }
144 
145         XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class,
146                                                            xTextDoc);
147 
148         XInterface oObj = null;
149         XInterface secondItem = null;
150 
151         AccessibilityTools at = new AccessibilityTools();
152 
153         XWindow xWindow = at.getCurrentContainerWindow(
154                                   (XMultiServiceFactory) tParam.getMSF(),
155                                   aModel);
156 
157         XAccessible xRoot = at.getAccessibleObject(xWindow);
158 
159         at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
160         XAccessibleContext statusbar = at.getAccessibleObjectForRole(xRoot,
161                                                                      AccessibleRole.STATUS_BAR);
162 
163         try {
164             oObj = statusbar.getAccessibleChild(6);
165             secondItem = statusbar.getAccessibleChild(1);
166         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
167         }
168 
169         log.println("ImplementationName: " + util.utils.getImplName(oObj));
170 
171         TestEnvironment tEnv = new TestEnvironment(oObj);
172 
173         tEnv.addObjRelation("EditOnly",
174                             "Can't change or select Text in StatusBarItem");
175         tEnv.addObjRelation("XAccessibleText", secondItem);
176 
177         tEnv.addObjRelation("LimitedBounds", "yes");
178 
179         final XTextDocument doc = xTextDoc;
180 
181         tEnv.addObjRelation("EventProducer",
182                             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
183             public void fireEvent() {
184                 doc.getText().setString("AccessibleStatusBarItem");
185             }
186         });
187 
188         return tEnv;
189     }
190 }
191