bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _svtools / AccessibleBrowseBoxHeaderBar.java
blob9820f8091f1620da6b92ee76cbc99c837157337d
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._svtools;
20 import com.sun.star.view.XSelectionSupplier;
21 import java.awt.Robot;
22 import java.awt.event.InputEvent;
23 import java.io.PrintWriter;
25 import lib.StatusException;
26 import lib.TestCase;
27 import lib.TestEnvironment;
28 import lib.TestParameters;
29 import util.AccessibilityTools;
30 import util.DesktopTools;
31 import util.SOfficeFactory;
33 import com.sun.star.accessibility.AccessibleRole;
34 import com.sun.star.accessibility.XAccessible;
35 import com.sun.star.accessibility.XAccessibleComponent;
36 import com.sun.star.awt.Point;
37 import com.sun.star.awt.XWindow;
38 import com.sun.star.beans.PropertyValue;
39 import com.sun.star.frame.XController;
40 import com.sun.star.frame.XDesktop;
41 import com.sun.star.frame.XDispatch;
42 import com.sun.star.frame.XDispatchProvider;
43 import com.sun.star.frame.XFrame;
44 import com.sun.star.frame.XModel;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.text.XTextDocument;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
49 import com.sun.star.util.URL;
52 /**
53 * Test for object that implements the following interfaces :
54 * <ul>
55 * <li>
56 * <code>::com::sun::star::accessibility::XAccessibleContext
57 * </code></li>
58 * <li>
59 * <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
60 * </code></li>
61 * </ul> <p>
63 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
64 * @see com.sun.star.accessibility.XAccessibleContext
65 * @see ifc.accessibility._XAccessibleEventBroadcaster
66 * @see ifc.accessibility._XAccessibleContext
68 public class AccessibleBrowseBoxHeaderBar extends TestCase {
69 static XDesktop the_Desk;
70 static XTextDocument xTextDoc;
72 /**
73 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
75 protected void initialize(TestParameters Param, PrintWriter log) {
76 the_Desk = UnoRuntime.queryInterface(XDesktop.class,
77 DesktopTools.createDesktop(
78 (XMultiServiceFactory) Param.getMSF()));
81 /**
82 * Disposes the document, if exists, created in
83 * <code>createTestEnvironment</code> method.
85 protected void cleanup(TestParameters Param, PrintWriter log) {
86 log.println("disposing xTextDoc");
88 if (xTextDoc != null) {
89 xTextDoc.dispose();
93 /**
94 * Creates a text document. Opens the DataSource browser.
95 * Creates an instance of the service <code>com.sun.star.awt.Toolkit</code>
96 * and gets active top window. Then obtains an accessible object with
97 * the role <code>AccessibleRole.TABLE</code>.
98 * Object relations created :
99 * <ul>
100 * <li> <code>'EventProducer'</code> for
101 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
102 * </li>
103 * </ul>
105 * @param tParam test parameters
106 * @param log writer to log information while testing
108 * @see com.sun.star.awt.Toolkit
109 * @see com.sun.star.accessibility.AccessibleRole
110 * @see ifc.accessibility._XAccessibleEventBroadcaster
111 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
113 protected TestEnvironment createTestEnvironment(TestParameters tParam,
114 PrintWriter log) {
115 log.println("creating a test environment");
117 if (xTextDoc != null) {
118 xTextDoc.dispose();
121 // get a soffice factory object
122 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF());
124 try {
125 log.println("creating a text document");
126 xTextDoc = SOF.createTextDoc(null);
127 } catch (com.sun.star.uno.Exception e) {
128 // Some exception occurs.FAILED
129 e.printStackTrace(log);
130 throw new StatusException("Couldn't create document", e);
133 shortWait();
135 XModel aModel1 = UnoRuntime.queryInterface(XModel.class,
136 xTextDoc);
138 XController secondController = aModel1.getCurrentController();
140 XDispatchProvider aProv = UnoRuntime.queryInterface(
141 XDispatchProvider.class,
142 secondController);
144 XDispatch getting = null;
146 log.println("opening DatasourceBrowser");
148 URL the_url = new URL();
149 the_url.Complete = ".component:DB/DataSourceBrowser";
150 getting = aProv.queryDispatch(the_url, "_beamer", 12);
152 //am controller ein XSelectionSupplier->mit params rufen
153 PropertyValue[] noArgs = new PropertyValue[0];
154 getting.dispatch(the_url, noArgs);
156 PropertyValue[] params = new PropertyValue[3];
157 PropertyValue param1 = new PropertyValue();
158 param1.Name = "DataSourceName";
159 param1.Value = "Bibliography";
160 params[0] = param1;
162 PropertyValue param2 = new PropertyValue();
163 param2.Name = "CommandType";
164 param2.Value = new Integer(com.sun.star.sdb.CommandType.TABLE);
165 params[1] = param2;
167 PropertyValue param3 = new PropertyValue();
168 param3.Name = "Command";
169 param3.Value = "biblio";
170 params[2] = param3;
172 shortWait();
174 XFrame the_frame1 = the_Desk.getCurrentFrame();
176 if (the_frame1 == null) {
177 log.println("Current frame was not found !!!");
180 XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);
182 the_frame2.setName("DatasourceBrowser");
184 XController xCont = the_frame2.getController();
186 XSelectionSupplier xSelect = UnoRuntime.queryInterface(
187 XSelectionSupplier.class, xCont);
189 try {
190 xSelect.select(params);
191 } catch (com.sun.star.lang.IllegalArgumentException ex) {
192 throw new StatusException("Could not select Biblio-Database", ex);
195 XInterface oObj = null;
197 AccessibilityTools at = new AccessibilityTools();
199 XWindow xWindow = secondController.getFrame().getContainerWindow();
201 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
203 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE);
205 AccessibilityTools.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
206 log.println("ImplementationName: " + util.utils.getImplName(oObj));
208 TestEnvironment tEnv = new TestEnvironment(oObj);
210 shortWait();
212 XAccessibleComponent accComp = UnoRuntime.queryInterface(
213 XAccessibleComponent.class,
214 oObj);
215 final Point point = accComp.getLocationOnScreen();
217 shortWait();
219 tEnv.addObjRelation("EventProducer",
220 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
221 public void fireEvent() {
222 try {
223 Robot rob = new Robot();
224 rob.mouseMove(point.X + 5, point.Y + 5);
225 rob.mousePress(InputEvent.BUTTON1_MASK);
226 } catch (java.awt.AWTException e) {
227 System.out.println("couldn't fire event");
232 return tEnv;
236 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
237 * reset</code> call.
239 private void shortWait() {
240 try {
241 Thread.sleep(5000);
242 } catch (InterruptedException e) {
243 System.out.println("While waiting :" + e);