Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleStatusBar.java
blob1197b9300cd7fce3431493735213fd8233f95cd0
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: AccessibleStatusBar.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::XAccessibleValue</code></li>
72 * <li><code>
73 * ::com::sun::star::accessibility::XAccessibleAction</code></li>
74 * </ul> <p>
76 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
77 * @see com.sun.star.accessibility.XAccessibleContext
78 * @see com.sun.star.accessibility.XAccessibleComponent
79 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
80 * @see com.sun.star.accessibility.XAccessibleValue
81 * @see com.sun.star.accessibility.XAccessibleAction
82 * @see ifc.accessibility._XAccessibleEventBroadcaster
83 * @see ifc.accessibility._XAccessibleContext
84 * @see ifc.accessibility._XAccessibleComponent
85 * @see ifc.accessibility.XAccessibleExtendedComponent
86 * @see ifc.accessibility.XAccessibleValue
87 * @see ifc.accessibility.XAccessibleAction
89 public class AccessibleStatusBar extends TestCase {
90 private static XDesktop the_Desk;
91 private static XTextDocument xTextDoc;
93 /**
94 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
96 protected void initialize(TestParameters Param, PrintWriter log) {
97 the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class,
98 DesktopTools.createDesktop(
99 (XMultiServiceFactory) Param.getMSF()));
103 * Disposes the document, if exists, created in
104 * <code>createTestEnvironment</code> method.
106 protected void cleanup(TestParameters Param, PrintWriter log) {
107 log.println("disposing xTextDoc");
109 if (xTextDoc != null) {
110 util.DesktopTools.closeDoc(xTextDoc);
116 * Creates a text document.
117 * Then obtains an accessible object with
118 * the role <code>AccessibleRole.SCROLLBAR</code>.
119 * Object relations created :
120 * <ul>
121 * <li> <code>'EventProducer'</code> for
122 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
123 * grabs focus </li>
124 * </ul>
126 * @param tParam test parameters
127 * @param log writer to log information while testing
129 * @see com.sun.star.awt.Toolkit
130 * @see com.sun.star.accessibility.AccessibleRole
131 * @see ifc.accessibility._XAccessibleEventBroadcaster
132 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
134 protected TestEnvironment createTestEnvironment(TestParameters tParam,
135 PrintWriter log) {
136 log.println("creating a test environment");
138 if (xTextDoc != null) {
139 util.DesktopTools.closeDoc(xTextDoc);
144 // get a soffice factory object
145 SOfficeFactory SOF = SOfficeFactory.getFactory(
146 (XMultiServiceFactory) tParam.getMSF());
148 XInterface toolkit = null;
150 try {
151 log.println("creating a text document");
152 xTextDoc = SOF.createTextDoc(null);
153 toolkit = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance(
154 "com.sun.star.awt.Toolkit");
155 } catch (com.sun.star.uno.Exception e) {
156 // Some exception occures.FAILED
157 e.printStackTrace(log);
158 throw new StatusException("Couldn't create document", e);
161 XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class,
162 xTextDoc);
164 XInterface oObj = null;
166 AccessibilityTools at = new AccessibilityTools();
168 XWindow xWindow = at.getCurrentContainerWindow(
169 (XMultiServiceFactory) tParam.getMSF(),
170 aModel);
172 XAccessible xRoot = at.getAccessibleObject(xWindow);
174 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.STATUS_BAR);
176 log.println("ImplementationName: " + util.utils.getImplName(oObj));
178 TestEnvironment tEnv = new TestEnvironment(oObj);
180 final XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface(
181 XExtendedToolkit.class, toolkit);
183 tEnv.addObjRelation("EventProducer",
184 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
185 public void fireEvent() {
186 XWindow xWin = (XWindow) UnoRuntime.queryInterface(
187 XWindow.class, tk.getActiveTopWindow());
188 Rectangle newPosSize = xWin.getPosSize();
189 newPosSize.Width = newPosSize.Width - 20;
190 newPosSize.Height = newPosSize.Height - 20;
191 newPosSize.X = newPosSize.X + 20;
192 newPosSize.Y = newPosSize.Y + 20;
193 xWin.setPosSize(newPosSize.X, newPosSize.Y, newPosSize.Width,
194 newPosSize.Height, PosSize.POSSIZE);
198 return tEnv;