bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleCheckBox.java
blob6def9bb8fe934be3f0d501db491830880d0d1d5e
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.XAccessibleAction;
23 import com.sun.star.accessibility.XAccessibleComponent;
24 import com.sun.star.accessibility.XAccessibleText;
25 import com.sun.star.awt.XExtendedToolkit;
26 import com.sun.star.awt.XWindow;
27 import com.sun.star.frame.XController;
28 import com.sun.star.frame.XDispatch;
29 import com.sun.star.frame.XDispatchProvider;
30 import com.sun.star.frame.XModel;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.text.XTextDocument;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XInterface;
35 import com.sun.star.util.URL;
36 import com.sun.star.util.XURLTransformer;
38 import java.io.PrintWriter;
40 import lib.StatusException;
41 import lib.TestCase;
42 import lib.TestEnvironment;
43 import lib.TestParameters;
45 import util.AccessibilityTools;
46 import util.SOfficeFactory;
47 import util.utils;
50 /**
51 * Test for object which is represented by accessible compoent of
52 * check box in 'InsertTable' dialog. <p>
54 * Object implements the following interfaces :
55 * <ul>
56 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
57 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
58 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
59 * <li> <code>::com::sun::star::accessibility::XAccessibleValue</code></li>
60 * <li> <code>::com::sun::star::accessibility::XAccessibleAction</code></li>
61 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
62 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
63 * </ul> <p>
65 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
66 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
67 * @see com.sun.star.accessibility.XAccessibleComponent
68 * @see com.sun.star.accessibility.XAccessibleValue
69 * @see com.sun.star.accessibility.XAccessibleAction
70 * @see com.sun.star.accessibility.XAccessibleContext
71 * @see com.sun.star.accessibility.XAccessibleText
72 * @see ifc.accessibility._XAccessibleExtendedComponent
73 * @see ifc.accessibility._XAccessibleEventBroadcaster
74 * @see ifc.accessibility._XAccessibleComponent
75 * @see ifc.accessibility._XAccessibleValue
76 * @see ifc.accessibility._XAccessibleAction
77 * @see ifc.accessibility._XAccessibleContext
78 * @see ifc.accessibility._XAccessibleText
80 public class AccessibleCheckBox extends TestCase {
81 private static XTextDocument xTextDoc = null;
82 private static XAccessibleAction action = null;
83 private static DiagThread psDiag = null;
85 /**
86 * Opens 'Insert Table' dialog using document dispatch provider
87 * running in a separate thread. Finds active top window (the dialog
88 * window) and finds first accessible check box walking through the
89 * accessible component tree.
91 @Override
92 protected TestEnvironment createTestEnvironment(TestParameters Param,
93 PrintWriter log) {
94 XMultiServiceFactory msf = Param.getMSF();
95 log.println("Creating text document");
97 if (xTextDoc == null) {
98 try {
99 SOfficeFactory SOF = SOfficeFactory.getFactory(msf);
100 xTextDoc = SOF.createTextDoc(null);
101 } catch (com.sun.star.uno.Exception e) {
102 throw new StatusException("Can't create document", e);
106 util.utils.pause(Param.getInt("ShortWait"));
108 XInterface oObj = null;
110 log.println("getting toolkit");
112 try {
113 oObj = (XInterface) msf.createInstance("com.sun.star.awt.Toolkit");
114 } catch (com.sun.star.uno.Exception e) {
115 log.println("Couldn't get toolkit");
116 e.printStackTrace(log);
117 throw new StatusException("Couldn't get toolkit", e);
120 XExtendedToolkit tk = UnoRuntime.queryInterface(
121 XExtendedToolkit.class, oObj);
123 util.utils.pause(Param.getInt("ShortWait"));
125 log.println("Opening Dialog in second thread");
127 psDiag = new DiagThread(xTextDoc, msf);
128 psDiag.start();
130 util.utils.pause(Param.getInt("ShortWait"));
132 util.utils.pause(Param.getInt("ShortWait"));
134 log.println("Getting the active TopWindow");
136 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class,
137 tk.getActiveTopWindow());
139 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
142 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
143 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON,
144 "Cancel");
146 action = UnoRuntime.queryInterface(
147 XAccessibleAction.class, oObj);
149 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.CHECK_BOX);
151 log.println("ImplementationName " + utils.getImplName(oObj));
153 TestEnvironment tEnv = new TestEnvironment(oObj);
155 final XAccessibleComponent acomp = UnoRuntime.queryInterface(
156 XAccessibleComponent.class,
157 oObj);
159 tEnv.addObjRelation("EventProducer",
160 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
161 public void fireEvent() {
162 System.out.println("Grabbing focus ... ");
163 acomp.grabFocus();
167 XAccessibleText text = UnoRuntime.queryInterface(
168 XAccessibleText.class, oObj);
170 tEnv.addObjRelation("XAccessibleText.Text", text.getText());
172 tEnv.addObjRelation("EditOnly",
173 "This method isn't supported in this component");
175 tEnv.addObjRelation("LimitedBounds", "yes");
177 return tEnv;
181 * Closes the dialog using accessible button 'Cancel' found in
182 * <code>createTestEnvironment()</code>.
184 @Override
185 protected void cleanup(TestParameters Param, PrintWriter log) {
186 try {
187 log.println("closing dialog");
188 action.doAccessibleAction(0);
189 log.println("interrupting corresponding Thread");
190 psDiag.interrupt();
191 log.println("closing the document");
192 util.DesktopTools.closeDoc(xTextDoc);
193 log.println("reinitialize the variable");
194 xTextDoc = null;
195 } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
196 log.println("Couldn't close dialog");
197 } catch (com.sun.star.lang.DisposedException de) {
198 log.println("Dialog already disposed");
202 @Override
203 protected void initialize(TestParameters Param, PrintWriter log) {
207 * Thread for opening modal dialog 'Insert Table'.
209 private class DiagThread extends Thread {
210 private XTextDocument xTextDoc = null;
211 private XMultiServiceFactory msf = null;
213 private DiagThread(XTextDocument xTextDoc, XMultiServiceFactory msf) {
214 this.xTextDoc = xTextDoc;
215 this.msf = msf;
218 @Override
219 public void run() {
220 XModel aModel = UnoRuntime.queryInterface(XModel.class,
221 xTextDoc);
223 XController xController = aModel.getCurrentController();
225 //Opening PrinterSetupDialog
226 try {
227 String aSlotID = ".uno:InsertTable";
228 XDispatchProvider xDispProv = UnoRuntime.queryInterface(
229 XDispatchProvider.class,
230 xController);
231 XURLTransformer xParser = UnoRuntime.queryInterface(
232 XURLTransformer.class,
233 msf.createInstance(
234 "com.sun.star.util.URLTransformer"));
236 // Because it's an in/out parameter we must use an array of URL objects.
237 URL[] aParseURL = new URL[1];
238 aParseURL[0] = new URL();
239 aParseURL[0].Complete = aSlotID;
240 xParser.parseStrict(aParseURL);
242 URL aURL = aParseURL[0];
243 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
245 if (xDispatcher != null) {
246 xDispatcher.dispatch(aURL, null);
248 } catch (com.sun.star.uno.Exception e) {
249 log.println("Couldn't open dialog");