1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleToolBox.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import com
.sun
.star
.accessibility
.AccessibleRole
;
33 import com
.sun
.star
.accessibility
.XAccessible
;
34 import com
.sun
.star
.accessibility
.XAccessibleAction
;
35 import com
.sun
.star
.awt
.XWindow
;
36 import com
.sun
.star
.frame
.XDesktop
;
37 import com
.sun
.star
.frame
.XModel
;
38 import com
.sun
.star
.lang
.XMultiServiceFactory
;
39 import com
.sun
.star
.text
.XTextDocument
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
43 import java
.io
.PrintWriter
;
45 import lib
.StatusException
;
47 import lib
.TestEnvironment
;
48 import lib
.TestParameters
;
50 import util
.AccessibilityTools
;
51 import util
.DesktopTools
;
52 import util
.SOfficeFactory
;
57 * Test for object that implements the following interfaces :
60 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
62 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
65 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
67 * ::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
70 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
71 * @see com.sun.star.accessibility.XAccessibleContext
72 * @see com.sun.star.accessibility.XAccessibleComponent
73 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
74 * @see ifc.accessibility._XAccessibleEventBroadcaster
75 * @see ifc.accessibility._XAccessibleContext
76 * @see ifc.accessibility._XAccessibleComponent
77 * @see ifc.accessibility.XAccessibleExtendedComponent
79 public class AccessibleToolBox
extends TestCase
{
80 private static XDesktop the_Desk
;
81 private static XTextDocument xTextDoc
;
84 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
86 protected void initialize(TestParameters Param
, PrintWriter log
) {
87 the_Desk
= (XDesktop
) UnoRuntime
.queryInterface(XDesktop
.class,
88 DesktopTools
.createDesktop(
89 (XMultiServiceFactory
) Param
.getMSF()));
93 * Disposes the document, if exists, created in
94 * <code>createTestEnvironment</code> method.
96 protected void cleanup(TestParameters Param
, PrintWriter log
) {
97 log
.println("disposing xTextDoc");
99 if (xTextDoc
!= null) {
100 util
.DesktopTools
.closeDoc(xTextDoc
);
106 * Creates a text document.
107 * Then obtains an accessible object with
108 * the role <code>AccessibleRole.TOOLBAR</code>.
109 * Object relations created :
111 * <li> <code>'EventProducer'</code> for
112 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
117 * @param tParam test parameters
118 * @param log writer to log information while testing
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
125 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
127 log
.println("creating a test environment");
129 if (xTextDoc
!= null) {
130 util
.DesktopTools
.closeDoc(xTextDoc
);
133 XMultiServiceFactory msf
= (XMultiServiceFactory
) tParam
.getMSF();
135 // get a soffice factory object
136 SOfficeFactory SOF
= SOfficeFactory
.getFactory(msf
);
139 log
.println("creating a text document");
140 xTextDoc
= SOF
.createTextDoc(null);
141 } catch (com
.sun
.star
.uno
.Exception e
) {
142 // Some exception occures.FAILED
143 e
.printStackTrace(log
);
144 throw new StatusException("Couldn't create document", e
);
147 XModel aModel
= (XModel
) UnoRuntime
.queryInterface(XModel
.class,
150 XInterface oObj
= null;
152 UITools oUI
= new UITools(msf
, aModel
);
154 XWindow xWindow
= null;
156 xWindow
= oUI
.getActiveTopWindow();
157 } catch (Exception ex
) {
158 ex
.printStackTrace(log
);
159 throw new StatusException("Couldn't get active top window", ex
);
162 AccessibilityTools at
= new AccessibilityTools();
164 XAccessible xRoot
= at
.getAccessibleObject(xWindow
);
166 at
.printAccessibleTree(log
, xRoot
, tParam
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
168 oObj
= at
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.TOOL_BAR
);
170 log
.println("ImplementationName: " + util
.utils
.getImplName(oObj
));
172 TestEnvironment tEnv
= new TestEnvironment(oObj
);
174 tEnv
.addObjRelation("LimitedBounds", "yes");
176 XAccessible acc
= at
.getAccessibleObject(oObj
);
177 XAccessible child
= null;
180 child
= acc
.getAccessibleContext().getAccessibleChild(0);
181 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
184 util
.dbg
.printInterfaces(child
);
186 final XAccessibleAction action
= (XAccessibleAction
) UnoRuntime
.queryInterface(
187 XAccessibleAction
.class,
190 tEnv
.addObjRelation("EventProducer",
191 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
192 public void fireEvent() {
194 action
.doAccessibleAction(0);
195 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
196 System
.out
.println("Couldn't fire event");