bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleFixedText.java
blobef85c6534c4e9812c2898acefe4004bb30dcaece
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package mod._toolkit;
20 import com.sun.star.accessibility.AccessibleRole;
21 import com.sun.star.accessibility.XAccessible;
22 import com.sun.star.accessibility.XAccessibleText;
23 import com.sun.star.awt.PosSize;
24 import com.sun.star.awt.XControl;
25 import com.sun.star.awt.XControlContainer;
26 import com.sun.star.awt.XControlModel;
27 import com.sun.star.awt.XFixedText;
28 import com.sun.star.awt.XWindow;
29 import com.sun.star.lang.XMultiServiceFactory;
30 import com.sun.star.uno.UnoRuntime;
31 import com.sun.star.uno.XInterface;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
40 import util.AccessibilityTools;
41 import util.utils;
44 /**
45 * Test for object which is represented by accesible component
46 * of the fixed text label in 'Hyperlink' Dialog. <p>
48 * Object implements the following interfaces :
49 * <ul>
50 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
51 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
52 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
53 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
54 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
55 * </ul> <p>
57 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
58 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
59 * @see com.sun.star.accessibility.XAccessibleComponent
60 * @see com.sun.star.accessibility.XAccessibleContext
61 * @see com.sun.star.accessibility.XAccessibleText
62 * @see ifc.accessibility._XAccessibleExtendedComponent
63 * @see ifc.accessibility._XAccessibleEventBroadcaster
64 * @see ifc.accessibility._XAccessibleComponent
65 * @see ifc.accessibility._XAccessibleContext
66 * @see ifc.accessibility._XAccessibleText
68 public class AccessibleFixedText extends TestCase {
69 private static XWindow xWinDlg = null;
71 /**
72 * Creates a new dialog adds fixed text control to it and
73 * displays it. Then the text's accessible component is
74 * obtained.
76 protected TestEnvironment createTestEnvironment(TestParameters Param,
77 PrintWriter log) {
78 XInterface oObj = null;
79 XMultiServiceFactory xMSF = (XMultiServiceFactory) Param.getMSF();
80 XControlModel dlgModel = null;
82 XControl txtControl = null;
83 XControlModel txtModel = null;
85 try {
86 dlgModel = UnoRuntime.queryInterface(
87 XControlModel.class,
88 xMSF.createInstance(
89 "com.sun.star.awt.UnoControlDialogModel"));
91 XControl dlgControl = UnoRuntime.queryInterface(
92 XControl.class,
93 xMSF.createInstance(
94 "com.sun.star.awt.UnoControlDialog"));
96 dlgControl.setModel(dlgModel);
98 txtModel = UnoRuntime.queryInterface(
99 XControlModel.class,
100 xMSF.createInstance(
101 "com.sun.star.awt.UnoControlFixedTextModel"));
103 txtControl = UnoRuntime.queryInterface(XControl.class,
104 xMSF.createInstance(
105 "com.sun.star.awt.UnoControlFixedText"));
107 txtControl.setModel(txtModel);
109 XFixedText xFT = UnoRuntime.queryInterface(
110 XFixedText.class, txtControl);
111 xFT.setText("FxedText");
113 XControlContainer ctrlCont = UnoRuntime.queryInterface(
114 XControlContainer.class,
115 dlgControl);
117 ctrlCont.addControl("Text", txtControl);
119 xWinDlg = UnoRuntime.queryInterface(XWindow.class,
120 dlgControl);
122 xWinDlg.setVisible(true);
124 xWinDlg.setPosSize(0, 0, 200, 100, PosSize.SIZE);
125 } catch (com.sun.star.uno.Exception e) {
126 log.println("Error creating dialog :");
127 e.printStackTrace(log);
130 try {
131 oObj = (XInterface) ((XMultiServiceFactory) Param.getMSF()).createInstance(
132 "com.sun.star.awt.Toolkit");
133 } catch (com.sun.star.uno.Exception e) {
134 log.println("Couldn't get toolkit");
135 e.printStackTrace(log);
136 throw new StatusException("Couldn't get toolkit", e);
139 shortWait();
141 AccessibilityTools at = new AccessibilityTools();
143 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWinDlg);
145 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
147 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.LABEL);
149 log.println("ImplementationName " + utils.getImplName(oObj));
151 TestEnvironment tEnv = new TestEnvironment(oObj);
153 final XWindow xWin = UnoRuntime.queryInterface(XWindow.class,
154 txtControl);
156 tEnv.addObjRelation("EventProducer",
157 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
158 public void fireEvent() {
159 xWin.setEnable(false);
160 xWin.setEnable(true);
164 XAccessibleText text = UnoRuntime.queryInterface(
165 XAccessibleText.class, oObj);
167 tEnv.addObjRelation("XAccessibleText.Text", text.getText());
169 tEnv.addObjRelation("EditOnly",
170 "This method isn't supported in this component");
172 tEnv.addObjRelation("LimitedBounds", "yes");
174 return tEnv;
178 * Closes dialog using action of button 'Close'
180 protected void cleanup(TestParameters Param, PrintWriter log) {
181 log.println(" Closing dialog ... ");
182 xWinDlg.dispose();
186 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
187 * reset</code> call.
189 private void shortWait() {
190 try {
191 Thread.sleep(500);
192 } catch (InterruptedException e) {
193 log.println("While waiting :" + e);