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