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