merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleToolBoxItem.java
bloba6606ce18b2744cf784210a83342173e364cfa79
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: AccessibleToolBoxItem.java,v $
10 * $Revision: 1.16 $
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.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;
46 import lib.TestCase;
47 import lib.TestEnvironment;
48 import lib.TestParameters;
50 import util.AccessibilityTools;
51 import util.DesktopTools;
52 import util.SOfficeFactory;
55 /**
56 * Test for object that implements the following interfaces :
57 * <ul>
58 * <li><code>
59 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
60 * <li><code>
61 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
62 * </code></li>
63 * <li><code>
64 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
65 * <li><code>
66 * ::com::sun::star::accessibility::XAccessibleExtendedComponent
67 * </code></li>
68 * <li><code>
69 * ::com::sun::star::accessibility::XAccessibleAction</code></li>
70 * <li><code>
71 * ::com::sun::star::accessibility::XAccessibleText</code></li>
72 * <li><code>
73 * ::com::sun::star::accessibility::XAccessibleValue</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.XAccessibleAction
81 * @see com.sun.star.accessibility.XAccessibleText
82 * @see com.sun.star.accessibility.XAccessibleValue
83 * @see ifc.accessibility._XAccessibleEventBroadcaster
84 * @see ifc.accessibility._XAccessibleContext
85 * @see ifc.accessibility._XAccessibleComponent
86 * @see ifc.accessibility.XAccessibleExtendedComponent
87 * @see ifc.accessibility.XAccessibleAction
88 * @see ifc.accessibility.XAccessibleText
89 * @see ifc.accessibility.XAccessibleValue
91 public class AccessibleToolBoxItem extends TestCase {
92 private static XDesktop the_Desk;
93 private static XTextDocument xTextDoc;
95 /**
96 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
98 protected void initialize(TestParameters Param, PrintWriter log) {
99 the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class,
100 DesktopTools.createDesktop(
101 (XMultiServiceFactory) Param.getMSF()));
105 * Disposes the document, if exists, created in
106 * <code>createTestEnvironment</code> method.
108 protected void cleanup(TestParameters Param, PrintWriter log) {
109 log.println("disposing xTextDoc");
111 if (xTextDoc != null) {
112 closeDoc();
117 * Creates a text document.
118 * Then obtains an accessible object with
119 * the role <code>AccessibleRole.PUSHBUTTON</code> and with the name
120 * <code>"Bold"</code>.
121 * Object relations created :
122 * <ul>
123 * <li> <code>'EventProducer'</code> for
124 * {@link ifc.accessibility._XAccessibleEventBroadcaster}</li>
125 * <li> <code>'XAccessibleText.Text'</code> for
126 * {@link ifc.accessibility._XAccessibleText}: the name of button</li>
127 * </ul>
129 * @param tParam test parameters
130 * @param log writer to log information while testing
132 * @see com.sun.star.awt.Toolkit
133 * @see com.sun.star.accessibility.AccessibleRole
134 * @see ifc.accessibility._XAccessibleEventBroadcaster
135 * @see ifc.accessibility._XAccessibleText
136 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
137 * @see com.sun.star.accessibility.XAccessibleText
139 protected TestEnvironment createTestEnvironment(TestParameters tParam,
140 PrintWriter log) {
141 log.println("creating a test environment");
143 if (xTextDoc != null) {
144 closeDoc();
147 // get a soffice factory object
148 SOfficeFactory SOF = SOfficeFactory.getFactory(
149 (XMultiServiceFactory) tParam.getMSF());
151 try {
152 log.println("creating a text document");
153 xTextDoc = SOF.createTextDoc(null);
154 } catch (com.sun.star.uno.Exception e) {
155 // Some exception occures.FAILED
156 e.printStackTrace(log);
157 throw new StatusException("Couldn't create document", e);
160 XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class,
161 xTextDoc);
163 XInterface oObj = null;
165 AccessibilityTools at = new AccessibilityTools();
167 XWindow xWindow = at.getCurrentContainerWindow(
168 (XMultiServiceFactory) tParam.getMSF(),
169 aModel);
171 XAccessible xRoot = at.getAccessibleObject(xWindow);
174 at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
175 oObj = at.getAccessibleObjectForRole(xRoot,
176 AccessibleRole.TOGGLE_BUTTON,
177 "Bold");
179 log.println("ImplementationName: " + util.utils.getImplName(oObj));
181 TestEnvironment tEnv = new TestEnvironment(oObj);
183 tEnv.addObjRelation("EditOnly",
184 "This method isn't supported in this dialog");
186 tEnv.addObjRelation("LimitedBounds", "yes");
188 final XAccessibleAction oAction = (XAccessibleAction) UnoRuntime.queryInterface(
189 XAccessibleAction.class,
190 oObj);
192 tEnv.addObjRelation("EventProducer",
193 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
194 public void fireEvent() {
195 try {
196 oAction.doAccessibleAction(0);
197 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
202 tEnv.addObjRelation("XAccessibleText.Text", "Bold");
204 return tEnv;
207 protected void closeDoc() {
208 util.DesktopTools.closeDoc(xTextDoc);