merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleWindow.java
blobf56b9d2022d6d31b6157049fe3e7c34ccc61f499
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleWindow.java,v $
10 * $Revision: 1.10 $
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 ************************************************************************/
30 package mod._toolkit;
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;
48 import lib.TestCase;
49 import lib.TestEnvironment;
50 import lib.TestParameters;
52 import util.AccessibilityTools;
53 import util.DesktopTools;
54 import util.SOfficeFactory;
57 /**
58 * Test for object that implements the following interfaces :
59 * <ul>
60 * <li><code>
61 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
62 * <li><code>
63 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
64 * </code></li>
65 * <li><code>
66 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
67 * <li><code>
68 * ::com::sun::star::accessibility::XAccessibleExtendedComponent
69 * </code></li>
70 * <li><code>
71 * ::com::sun::star::accessibility::XAccessibleAction</code></li>
72 * <li><code>
73 * ::com::sun::star::accessibility::XAccessibleText</code></li>
74 * <li><code>
75 * ::com::sun::star::accessibility::XAccessibleValue</code></li>
76 * </ul> <p>
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;
97 /**
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 :
125 * <ul>
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>
130 * </ul>
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,
143 PrintWriter log) {
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;
158 try {
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,
170 xTextDoc);
172 XInterface oObj = null;
174 AccessibilityTools at = new AccessibilityTools();
176 XWindow xWindow = at.getCurrentWindow(
177 (XMultiServiceFactory) tParam.getMSF(),
178 aModel);
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);
208 return tEnv;