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.awt.PosSize;
28 import com.sun.star.awt.Rectangle;
29 import com.sun.star.awt.XExtendedToolkit;
30 import com.sun.star.awt.XWindow;
31 import com.sun.star.frame.XModel;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.text.XTextDocument;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XInterface;
36 
37 import java.io.PrintWriter;
38 
39 import lib.StatusException;
40 import lib.TestCase;
41 import lib.TestEnvironment;
42 import lib.TestParameters;
43 
44 import util.AccessibilityTools;
45 import util.DesktopTools;
46 import util.SOfficeFactory;
47 
48 
49 /**
50  * Test for object that implements the following interfaces :
51  * <ul>
52  *  <li><code>
53  *  ::com::sun::star::accessibility::XAccessibleContext</code></li>
54  *  <li><code>
55  *  ::com::sun::star::accessibility::XAccessibleEventBroadcaster
56  *  </code></li>
57  *  <li><code>
58  *  ::com::sun::star::accessibility::XAccessibleComponent</code></li>
59  *  <li><code>
60  *  ::com::sun::star::accessibility::XAccessibleExtendedComponent
61  *  </code></li>
62  *  <li><code>
63  *  ::com::sun::star::accessibility::XAccessibleValue</code></li>
64  *  <li><code>
65  *  ::com::sun::star::accessibility::XAccessibleAction</code></li>
66  * </ul> <p>
67  *
68  * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
69  * @see com.sun.star.accessibility.XAccessibleContext
70  * @see com.sun.star.accessibility.XAccessibleComponent
71  * @see com.sun.star.accessibility.XAccessibleExtendedComponent
72  * @see com.sun.star.accessibility.XAccessibleValue
73  * @see com.sun.star.accessibility.XAccessibleAction
74  * @see ifc.accessibility._XAccessibleEventBroadcaster
75  * @see ifc.accessibility._XAccessibleContext
76  * @see ifc.accessibility._XAccessibleComponent
77  * @see ifc.accessibility._XAccessibleExtendedComponent
78  * @see ifc.accessibility._XAccessibleValue
79  * @see ifc.accessibility._XAccessibleAction
80  */
81 public class AccessibleStatusBar extends TestCase {
82     private static XTextDocument xTextDoc;
83 
84     /**
85      * Disposes the document, if exists, created in
86      * <code>createTestEnvironment</code> method.
87      */
cleanup(TestParameters Param, PrintWriter log)88     protected void cleanup(TestParameters Param, PrintWriter log) {
89         log.println("disposing xTextDoc");
90 
91         if (xTextDoc != null) {
92             util.DesktopTools.closeDoc(xTextDoc);
93         }
94     }
95 
96     /**
97      * Creates a text document.
98      * Then obtains an accessible object with
99      * the role <code>AccessibleRole.SCROLLBAR</code>.
100      * Object relations created :
101      * <ul>
102      *  <li> <code>'EventProducer'</code> for
103      *      {@link ifc.accessibility._XAccessibleEventBroadcaster}:
104      *      grabs focus </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         // get a soffice factory object
124         SOfficeFactory SOF = SOfficeFactory.getFactory(
125                                      (XMultiServiceFactory) tParam.getMSF());
126 
127         XInterface toolkit = null;
128 
129         try {
130             log.println("creating a text document");
131             xTextDoc = SOF.createTextDoc(null);
132             toolkit = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance(
133                               "com.sun.star.awt.Toolkit");
134         } catch (com.sun.star.uno.Exception e) {
135             // Some exception occured.FAILED
136             e.printStackTrace(log);
137             throw new StatusException("Couldn't create document", e);
138         }
139 
140         XInterface oObj = null;
141 
142         AccessibilityTools at = new AccessibilityTools();
143 
144         final XWindow xWindow =
145             UnoRuntime.queryInterface(XModel.class, xTextDoc).
146             getCurrentController().getFrame().getContainerWindow();
147 
148         XAccessible xRoot = at.getAccessibleObject(xWindow);
149 
150         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.STATUS_BAR);
151 
152         log.println("ImplementationName: " + util.utils.getImplName(oObj));
153 
154         TestEnvironment tEnv = new TestEnvironment(oObj);
155 
156         final XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface(
157                                             XExtendedToolkit.class, toolkit);
158 
159         tEnv.addObjRelation("EventProducer",
160                             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
161             public void fireEvent() {
162                 Rectangle newPosSize = xWindow.getPosSize();
163                 newPosSize.Width = newPosSize.Width - 20;
164                 newPosSize.Height = newPosSize.Height - 20;
165                 newPosSize.X = newPosSize.X + 20;
166                 newPosSize.Y = newPosSize.Y + 20;
167                 xWindow.setPosSize(
168                     newPosSize.X, newPosSize.Y, newPosSize.Width,
169                     newPosSize.Height, PosSize.POSSIZE);
170             }
171         });
172 
173         return tEnv;
174     }
175 }
176