xref: /AOO41X/main/qadevOOo/tests/java/mod/_toolkit/AccessibleToolBox.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package mod._toolkit;
28 
29 import com.sun.star.accessibility.AccessibleRole;
30 import com.sun.star.accessibility.XAccessible;
31 import com.sun.star.accessibility.XAccessibleAction;
32 import com.sun.star.awt.XWindow;
33 import com.sun.star.frame.XDesktop;
34 import com.sun.star.frame.XModel;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.text.XTextDocument;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
39 
40 import java.io.PrintWriter;
41 
42 import lib.StatusException;
43 import lib.TestCase;
44 import lib.TestEnvironment;
45 import lib.TestParameters;
46 
47 import util.AccessibilityTools;
48 import util.DesktopTools;
49 import util.SOfficeFactory;
50 
51 /**
52  * Test for object that implements the following interfaces :
53  * <ul>
54  *  <li><code>
55  *  ::com::sun::star::accessibility::XAccessibleContext</code></li>
56  *  <li><code>
57  *  ::com::sun::star::accessibility::XAccessibleEventBroadcaster
58  *  </code></li>
59  *  <li><code>
60  *  ::com::sun::star::accessibility::XAccessibleComponent</code></li>
61  *  <li><code>
62  *  ::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
63  * </ul> <p>
64  *
65  * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
66  * @see com.sun.star.accessibility.XAccessibleContext
67  * @see com.sun.star.accessibility.XAccessibleComponent
68  * @see com.sun.star.accessibility.XAccessibleExtendedComponent
69  * @see ifc.accessibility._XAccessibleEventBroadcaster
70  * @see ifc.accessibility._XAccessibleContext
71  * @see ifc.accessibility._XAccessibleComponent
72  * @see ifc.accessibility.XAccessibleExtendedComponent
73  */
74 public class AccessibleToolBox extends TestCase {
75     private static XDesktop the_Desk;
76     private static XTextDocument xTextDoc;
77 
78     /**
79      * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
80      */
81     protected void initialize(TestParameters Param, PrintWriter log) {
82         the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class,
83                 DesktopTools.createDesktop(
84                 (XMultiServiceFactory) Param.getMSF()));
85     }
86 
87     /**
88      * Disposes the document, if exists, created in
89      * <code>createTestEnvironment</code> method.
90      */
91     protected void cleanup(TestParameters Param, PrintWriter log) {
92         log.println("disposing xTextDoc");
93 
94         if (xTextDoc != null) {
95             util.DesktopTools.closeDoc(xTextDoc);
96             ;
97         }
98     }
99 
100     /**
101      * Creates a text document.
102      * Then obtains an accessible object with
103      * the role <code>AccessibleRole.TOOLBAR</code>.
104      * Object relations created :
105      * <ul>
106      *  <li> <code>'EventProducer'</code> for
107      *      {@link ifc.accessibility._XAccessibleEventBroadcaster}:
108      *      grabs focus
109      *   </li>
110      * </ul>
111      *
112      * @param tParam test parameters
113      * @param log writer to log information while testing
114      *
115      * @see com.sun.star.awt.Toolkit
116      * @see com.sun.star.accessibility.AccessibleRole
117      * @see ifc.accessibility._XAccessibleEventBroadcaster
118      * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
119      */
120     protected TestEnvironment createTestEnvironment(TestParameters tParam,
121             PrintWriter log) {
122         log.println("creating a test environment");
123 
124         if (xTextDoc != null) {
125             util.DesktopTools.closeDoc(xTextDoc);
126         }
127 
128         XMultiServiceFactory msf = (XMultiServiceFactory) tParam.getMSF();
129 
130         // get a soffice factory object
131         SOfficeFactory SOF = SOfficeFactory.getFactory(msf);
132 
133         try {
134             log.println("creating a text document");
135             xTextDoc = SOF.createTextDoc(null);
136         } catch (com.sun.star.uno.Exception e) {
137             // Some exception occures.FAILED
138             e.printStackTrace(log);
139             throw new StatusException("Couldn't create document", e);
140         }
141 
142         XInterface oObj = null;
143 
144         XWindow xWindow = UnoRuntime.queryInterface(XModel.class, xTextDoc).
145             getCurrentController().getFrame().getContainerWindow();
146 
147         AccessibilityTools at = new AccessibilityTools();
148 
149         XAccessible xRoot = at.getAccessibleObject(xWindow);
150 
151         at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
152 
153         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TOOL_BAR);
154 
155         log.println("ImplementationName: " + util.utils.getImplName(oObj));
156 
157         TestEnvironment tEnv = new TestEnvironment(oObj);
158 
159         tEnv.addObjRelation("LimitedBounds", "yes");
160 
161         XAccessible acc = at.getAccessibleObject(oObj);
162         XAccessible child = null;
163 
164         try {
165             child = acc.getAccessibleContext().getAccessibleChild(0);
166         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
167         }
168 
169         util.dbg.printInterfaces(child);
170 
171         final XAccessibleAction action = (XAccessibleAction) UnoRuntime.queryInterface(
172                 XAccessibleAction.class,
173                 child);
174 
175         tEnv.addObjRelation("EventProducer",
176                 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
177             public void fireEvent() {
178                 try {
179                     action.doAccessibleAction(0);
180                 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
181                     System.out.println("Couldn't fire event");
182                 }
183             }
184         });
185 
186         return tEnv;
187     }
188 }
189