bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / AccessibleEditableTextPara_HeaderFooter.java
blob9013668a1efef32c28dc5c13e928ad0ae1fe478c
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._sc;
20 import java.io.PrintWriter;
22 import lib.StatusException;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.AccessibilityTools;
27 import util.SOfficeFactory;
28 import util.utils;
30 import com.sun.star.accessibility.AccessibleRole;
31 import com.sun.star.accessibility.XAccessible;
32 import com.sun.star.accessibility.XAccessibleAction;
33 import com.sun.star.accessibility.XAccessibleContext;
34 import com.sun.star.accessibility.XAccessibleEditableText;
35 import com.sun.star.accessibility.XAccessibleText;
36 import com.sun.star.awt.XExtendedToolkit;
37 import com.sun.star.awt.XWindow;
38 import com.sun.star.frame.XController;
39 import com.sun.star.frame.XDispatch;
40 import com.sun.star.frame.XDispatchProvider;
41 import com.sun.star.frame.XModel;
42 import com.sun.star.lang.XComponent;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.util.URL;
46 import com.sun.star.util.XURLTransformer;
49 public class AccessibleEditableTextPara_HeaderFooter extends TestCase {
50 protected static XComponent xCalcDoc = null;
51 protected static XMultiServiceFactory msf = null;
52 protected static XAccessibleAction action = null;
54 protected TestEnvironment createTestEnvironment(TestParameters Param,
55 PrintWriter log) {
56 XAccessibleContext oObj = null;
57 Object toolkit = null;
59 try {
60 toolkit = msf.createInstance("com.sun.star.awt.Toolkit");
61 } catch (com.sun.star.uno.Exception e) {
62 log.println("Couldn't get toolkit");
63 e.printStackTrace(log);
64 throw new StatusException("Couldn't get toolkit", e);
67 XExtendedToolkit tk = UnoRuntime.queryInterface(
68 XExtendedToolkit.class, toolkit);
70 util.utils.shortWait(Param.getInt("ShortWait"));
72 DiagThread psDiag = new DiagThread(xCalcDoc, msf);
73 psDiag.start();
75 util.utils.shortWait(Param.getInt("ShortWait")*5);
77 Object atw = tk.getActiveTopWindow();
79 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class,
80 atw);
82 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
84 util.utils.shortWait(Param.getInt("ShortWait"));
86 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
87 XAccessibleContext ok_button = AccessibilityTools.getAccessibleObjectForRole(xRoot,
88 AccessibleRole.PUSH_BUTTON,
89 "Cancel");
91 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PARAGRAPH);
93 log.println("ImplementationName " + utils.getImplName(oObj));
94 log.println("AccessibleName " + oObj.getAccessibleName());
95 log.println("ParentDescription " +
96 oObj.getAccessibleParent().getAccessibleContext()
97 .getAccessibleDescription());
99 TestEnvironment tEnv = new TestEnvironment(oObj);
101 action = UnoRuntime.queryInterface(
102 XAccessibleAction.class, ok_button);
104 XAccessibleText text = UnoRuntime.queryInterface(
105 XAccessibleText.class, oObj);
107 XAccessibleEditableText eText = UnoRuntime.queryInterface(
108 XAccessibleEditableText.class,
109 oObj);
111 eText.setText("LEFT");
113 tEnv.addObjRelation("XAccessibleText.Text", text.getText());
115 tEnv.addObjRelation("Destroy", "AccessibleEditableTextPara_PreviewCell");
117 final XAccessibleEditableText editText = eText;
119 tEnv.addObjRelation("EventProducer",
120 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
121 public void fireEvent() {
122 editText.setText("LEFT_EVENT");
126 return tEnv;
130 * Closes the dialog using accessible button 'OK' found in
131 * <code>createTestEnvironment()</code>.
133 protected void cleanup(TestParameters Param, PrintWriter log) {
134 log.println(" disposing xCalcDoc ");
136 try {
137 action.doAccessibleAction(0);
138 } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
139 log.println("Couldn't close dialog");
140 } catch (com.sun.star.lang.DisposedException de) {
141 log.println("Dialog already disposed");
144 util.DesktopTools.closeDoc(xCalcDoc);
148 * Opens new writer document.
150 protected void initialize(TestParameters Param, PrintWriter log) {
151 msf = (XMultiServiceFactory) Param.getMSF();
153 try {
154 SOfficeFactory SOF = SOfficeFactory.getFactory(msf);
155 xCalcDoc = UnoRuntime.queryInterface(XComponent.class,
156 SOF.createCalcDoc(
157 null));
158 } catch (com.sun.star.uno.Exception e) {
159 throw new StatusException("Can't create document", e);
165 * Thread for opening modal dialog 'Print Settings'.
167 public class DiagThread extends Thread {
168 public XComponent xCalcDoc = null;
169 public XMultiServiceFactory msf = null;
171 public DiagThread(XComponent xCalcDoc, XMultiServiceFactory msf) {
172 this.xCalcDoc = xCalcDoc;
173 this.msf = msf;
176 public void run() {
177 XModel aModel = UnoRuntime.queryInterface(XModel.class,
178 xCalcDoc);
180 XController xController = aModel.getCurrentController();
182 //Opening HeaderFooterDialog
183 try {
184 String aSlotID = ".uno:EditHeaderAndFooter";
185 XDispatchProvider xDispProv = UnoRuntime.queryInterface(
186 XDispatchProvider.class,
187 xController);
188 XURLTransformer xParser = UnoRuntime.queryInterface(
189 XURLTransformer.class,
190 msf.createInstance(
191 "com.sun.star.util.URLTransformer"));
193 // Because it's an in/out parameter
194 // we must use an array of URL objects.
195 URL[] aParseURL = new URL[1];
196 aParseURL[0] = new URL();
197 aParseURL[0].Complete = aSlotID;
198 xParser.parseStrict(aParseURL);
200 URL aURL = aParseURL[0];
201 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
203 if (xDispatcher != null) {
204 xDispatcher.dispatch(aURL, null);
206 } catch (com.sun.star.uno.Exception e) {
207 log.println("Couldn't open dialog");