merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleFixedText.java
blob72142cc2c9be95b932dbba48b77a41869a3e6de4
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: AccessibleFixedText.java,v $
10 * $Revision: 1.12 $
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.accessibility.XAccessibleText;
36 import com.sun.star.awt.PosSize;
37 import com.sun.star.awt.XControl;
38 import com.sun.star.awt.XControlContainer;
39 import com.sun.star.awt.XControlModel;
40 import com.sun.star.awt.XExtendedToolkit;
41 import com.sun.star.awt.XFixedText;
42 import com.sun.star.awt.XWindow;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.text.XTextDocument;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.uno.XInterface;
48 import java.io.PrintWriter;
50 import lib.StatusException;
51 import lib.TestCase;
52 import lib.TestEnvironment;
53 import lib.TestParameters;
55 import util.AccessibilityTools;
56 import util.utils;
59 /**
60 * Test for object which is represented by accesible component
61 * of the fixed text label in 'Hyperlink' Dialog. <p>
63 * Object implements the following interfaces :
64 * <ul>
65 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
66 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
67 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
68 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
69 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
70 * </ul> <p>
72 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
73 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
74 * @see com.sun.star.accessibility.XAccessibleComponent
75 * @see com.sun.star.accessibility.XAccessibleContext
76 * @see com.sun.star.accessibility.XAccessibleText
77 * @see ifc.accessibility._XAccessibleExtendedComponent
78 * @see ifc.accessibility._XAccessibleEventBroadcaster
79 * @see ifc.accessibility._XAccessibleComponent
80 * @see ifc.accessibility._XAccessibleContext
81 * @see ifc.accessibility._XAccessibleText
83 public class AccessibleFixedText extends TestCase {
84 private static XTextDocument xTextDoc = null;
85 private static XAccessibleAction action = null;
86 private static XWindow xWinDlg = null;
88 /**
89 * Creates a new dialog adds fixed text control to it and
90 * displays it. Then the text's accessible component is
91 * obtained.
93 protected TestEnvironment createTestEnvironment(TestParameters Param,
94 PrintWriter log) {
95 XInterface oObj = null;
96 XMultiServiceFactory xMSF = (XMultiServiceFactory) Param.getMSF();
97 XControlModel dlgModel = null;
99 XControl txtControl = null;
100 XControlModel txtModel = null;
102 try {
103 dlgModel = (XControlModel) UnoRuntime.queryInterface(
104 XControlModel.class,
105 xMSF.createInstance(
106 "com.sun.star.awt.UnoControlDialogModel"));
108 XControl dlgControl = (XControl) UnoRuntime.queryInterface(
109 XControl.class,
110 xMSF.createInstance(
111 "com.sun.star.awt.UnoControlDialog"));
113 dlgControl.setModel(dlgModel);
115 txtModel = (XControlModel) UnoRuntime.queryInterface(
116 XControlModel.class,
117 xMSF.createInstance(
118 "com.sun.star.awt.UnoControlFixedTextModel"));
120 txtControl = (XControl) UnoRuntime.queryInterface(XControl.class,
121 xMSF.createInstance(
122 "com.sun.star.awt.UnoControlFixedText"));
124 txtControl.setModel(txtModel);
126 XFixedText xFT = (XFixedText) UnoRuntime.queryInterface(
127 XFixedText.class, txtControl);
128 xFT.setText("FxedText");
130 XControlContainer ctrlCont = (XControlContainer) UnoRuntime.queryInterface(
131 XControlContainer.class,
132 dlgControl);
134 ctrlCont.addControl("Text", txtControl);
136 xWinDlg = (XWindow) UnoRuntime.queryInterface(XWindow.class,
137 dlgControl);
139 xWinDlg.setVisible(true);
141 xWinDlg.setPosSize(0, 0, 200, 100, PosSize.SIZE);
142 } catch (com.sun.star.uno.Exception e) {
143 log.println("Error creating dialog :");
144 e.printStackTrace(log);
147 try {
148 oObj = (XInterface) ((XMultiServiceFactory) Param.getMSF()).createInstance(
149 "com.sun.star.awt.Toolkit");
150 } catch (com.sun.star.uno.Exception e) {
151 log.println("Couldn't get toolkit");
152 e.printStackTrace(log);
153 throw new StatusException("Couldn't get toolkit", e);
156 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface(
157 XExtendedToolkit.class, oObj);
159 shortWait();
161 AccessibilityTools at = new AccessibilityTools();
163 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class,
164 tk.getActiveTopWindow());
166 XAccessible xRoot = at.getAccessibleObject(xWindow);
168 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
170 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.LABEL);
172 log.println("ImplementationName " + utils.getImplName(oObj));
174 TestEnvironment tEnv = new TestEnvironment(oObj);
176 final XWindow xWin = (XWindow) UnoRuntime.queryInterface(XWindow.class,
177 txtControl);
179 tEnv.addObjRelation("EventProducer",
180 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
181 public void fireEvent() {
182 xWin.setEnable(false);
183 xWin.setEnable(true);
187 XAccessibleText text = (XAccessibleText) UnoRuntime.queryInterface(
188 XAccessibleText.class, oObj);
190 tEnv.addObjRelation("XAccessibleText.Text", text.getText());
192 tEnv.addObjRelation("EditOnly",
193 "This method isn't supported in this component");
195 tEnv.addObjRelation("LimitedBounds", "yes");
197 return tEnv;
201 * Closes dialog using action of button 'Close'
203 protected void cleanup(TestParameters Param, PrintWriter log) {
204 log.println(" Closing dialog ... ");
205 xWinDlg.dispose();
209 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
210 * reset</code> call.
212 private void shortWait() {
213 try {
214 Thread.sleep(500);
215 } catch (InterruptedException e) {
216 log.println("While waiting :" + e);