bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / AccessibleEditableTextPara_HeaderFooter.java
blob111b20c246b41a50143a56ce30878e018deca97d
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 @Override
55 protected TestEnvironment createTestEnvironment(TestParameters Param,
56 PrintWriter log) {
57 XAccessibleContext oObj = null;
58 Object toolkit = null;
60 try {
61 toolkit = msf.createInstance("com.sun.star.awt.Toolkit");
62 } catch (com.sun.star.uno.Exception e) {
63 log.println("Couldn't get toolkit");
64 e.printStackTrace(log);
65 throw new StatusException("Couldn't get toolkit", e);
68 XExtendedToolkit tk = UnoRuntime.queryInterface(
69 XExtendedToolkit.class, toolkit);
71 util.utils.pause(Param.getInt("ShortWait"));
73 DiagThread psDiag = new DiagThread(xCalcDoc, msf);
74 psDiag.start();
76 util.utils.pause(Param.getInt("ShortWait")*5);
78 Object atw = tk.getActiveTopWindow();
80 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class,
81 atw);
83 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
85 util.utils.pause(Param.getInt("ShortWait"));
87 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
88 XAccessibleContext ok_button = AccessibilityTools.getAccessibleObjectForRole(xRoot,
89 AccessibleRole.PUSH_BUTTON,
90 "Cancel");
92 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PARAGRAPH);
94 log.println("ImplementationName " + utils.getImplName(oObj));
95 log.println("AccessibleName " + oObj.getAccessibleName());
96 log.println("ParentDescription " +
97 oObj.getAccessibleParent().getAccessibleContext()
98 .getAccessibleDescription());
100 TestEnvironment tEnv = new TestEnvironment(oObj);
102 action = UnoRuntime.queryInterface(
103 XAccessibleAction.class, ok_button);
105 XAccessibleText text = UnoRuntime.queryInterface(
106 XAccessibleText.class, oObj);
108 XAccessibleEditableText eText = UnoRuntime.queryInterface(
109 XAccessibleEditableText.class,
110 oObj);
112 eText.setText("LEFT");
114 tEnv.addObjRelation("XAccessibleText.Text", text.getText());
116 tEnv.addObjRelation("Destroy", "AccessibleEditableTextPara_PreviewCell");
118 final XAccessibleEditableText editText = eText;
120 tEnv.addObjRelation("EventProducer",
121 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
122 public void fireEvent() {
123 editText.setText("LEFT_EVENT");
127 return tEnv;
131 * Closes the dialog using accessible button 'OK' found in
132 * <code>createTestEnvironment()</code>.
134 @Override
135 protected void cleanup(TestParameters Param, PrintWriter log) {
136 log.println(" disposing xCalcDoc ");
138 try {
139 action.doAccessibleAction(0);
140 } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
141 log.println("Couldn't close dialog");
142 } catch (com.sun.star.lang.DisposedException de) {
143 log.println("Dialog already disposed");
146 util.DesktopTools.closeDoc(xCalcDoc);
150 * Opens new writer document.
152 @Override
153 protected void initialize(TestParameters Param, PrintWriter log) {
154 msf = Param.getMSF();
156 try {
157 SOfficeFactory SOF = SOfficeFactory.getFactory(msf);
158 xCalcDoc = UnoRuntime.queryInterface(XComponent.class,
159 SOF.createCalcDoc(
160 null));
161 } catch (com.sun.star.uno.Exception e) {
162 throw new StatusException("Can't create document", e);
168 * Thread for opening modal dialog 'Print Settings'.
170 private class DiagThread extends Thread {
171 private XComponent xCalcDoc = null;
172 private XMultiServiceFactory msf = null;
174 private DiagThread(XComponent xCalcDoc, XMultiServiceFactory msf) {
175 this.xCalcDoc = xCalcDoc;
176 this.msf = msf;
179 @Override
180 public void run() {
181 XModel aModel = UnoRuntime.queryInterface(XModel.class,
182 xCalcDoc);
184 XController xController = aModel.getCurrentController();
186 //Opening HeaderFooterDialog
187 try {
188 String aSlotID = ".uno:EditHeaderAndFooter";
189 XDispatchProvider xDispProv = UnoRuntime.queryInterface(
190 XDispatchProvider.class,
191 xController);
192 XURLTransformer xParser = UnoRuntime.queryInterface(
193 XURLTransformer.class,
194 msf.createInstance(
195 "com.sun.star.util.URLTransformer"));
197 // Because it's an in/out parameter
198 // we must use an array of URL objects.
199 URL[] aParseURL = new URL[1];
200 aParseURL[0] = new URL();
201 aParseURL[0].Complete = aSlotID;
202 xParser.parseStrict(aParseURL);
204 URL aURL = aParseURL[0];
205 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
207 if (xDispatcher != null) {
208 xDispatcher.dispatch(aURL, null);
210 } catch (com.sun.star.uno.Exception e) {
211 log.println("Couldn't open dialog");