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     /**
107      * Creates a text document.
108      * Then obtains an accessible object with
109      * the role <code>AccessibleRole.SCROLLBAR</code>.
110      * Object relations created :
111      * <ul>
112      *  <li> <code>'EventProducer'</code> for
113      *      {@link ifc.accessibility._XAccessibleEventBroadcaster}:
114      *      grabs focus </li>
115      * </ul>
116      *
117      * @param tParam test parameters
118      * @param log writer to log information while testing
119      *
120      * @see com.sun.star.awt.Toolkit
121      * @see com.sun.star.accessibility.AccessibleRole
122      * @see ifc.accessibility._XAccessibleEventBroadcaster
123      * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
124      */
125     protected TestEnvironment createTestEnvironment(TestParameters tParam,
126                                                     PrintWriter log) {
127         log.println("creating a test environment");
128 
129         if (xTextDoc != null) {
130             util.DesktopTools.closeDoc(xTextDoc);
131         }
132 
133         ;
134 
135         // get a soffice factory object
136         SOfficeFactory SOF = SOfficeFactory.getFactory(
137                                      (XMultiServiceFactory) tParam.getMSF());
138 
139         try {
140             log.println("creating a text document");
141             xTextDoc = SOF.createTextDoc(null);
142         } catch (com.sun.star.uno.Exception e) {
143             // Some exception occures.FAILED
144             e.printStackTrace(log);
145             throw new StatusException("Couldn't create document", e);
146         }
147 
148         XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class,
149                                                            xTextDoc);
150 
151         XInterface oObj = null;
152         XInterface secondItem = null;
153 
154         AccessibilityTools at = new AccessibilityTools();
155 
156         XWindow xWindow = at.getCurrentContainerWindow(
157                                   (XMultiServiceFactory) tParam.getMSF(),
158                                   aModel);
159 
160         XAccessible xRoot = at.getAccessibleObject(xWindow);
161 
162         at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
163         XAccessibleContext statusbar = at.getAccessibleObjectForRole(xRoot,
164                                                                      AccessibleRole.STATUS_BAR);
165 
166         try {
167             oObj = statusbar.getAccessibleChild(6);
168             secondItem = statusbar.getAccessibleChild(1);
169         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
170         }
171 
172         log.println("ImplementationName: " + util.utils.getImplName(oObj));
173 
174         TestEnvironment tEnv = new TestEnvironment(oObj);
175 
176         tEnv.addObjRelation("EditOnly",
177                             "Can't change or select Text in StatusBarItem");
178         tEnv.addObjRelation("XAccessibleText", secondItem);
179 
180         tEnv.addObjRelation("LimitedBounds", "yes");
181 
182         final XTextDocument doc = xTextDoc;
183 
184         tEnv.addObjRelation("EventProducer",
185                             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
186             public void fireEvent() {
187                 doc.getText().setString("AccessibleStatusBarItem");
188             }
189         });
190 
191         return tEnv;
192     }
193 }