bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _svtools / AccessibleBrowseBoxTable.java
blob54cbf533b48abb501b94a574372682b961e5ffa3
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.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.AccessibilityTools;
28 import util.DesktopTools;
29 import util.SOfficeFactory;
31 import com.sun.star.accessibility.AccessibleRole;
32 import com.sun.star.accessibility.XAccessible;
33 import com.sun.star.awt.XWindow;
34 import com.sun.star.beans.PropertyValue;
35 import com.sun.star.frame.XController;
36 import com.sun.star.frame.XDesktop;
37 import com.sun.star.frame.XDispatch;
38 import com.sun.star.frame.XDispatchProvider;
39 import com.sun.star.frame.XFrame;
40 import com.sun.star.frame.XModel;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.text.XTextDocument;
43 import com.sun.star.uno.UnoRuntime;
44 import com.sun.star.uno.XInterface;
45 import com.sun.star.util.URL;
48 /**
49 * Test for object that implements the following interfaces :
50 * <ul>
51 * <li>
52 * <code>::com::sun::star::accessibility::XAccessibleContext
53 * </code></li>
54 * <li>
55 * <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
56 * </code></li>
57 * </ul> <p>
59 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
60 * @see com.sun.star.accessibility.XAccessibleContext
61 * @see ifc.accessibility._XAccessibleEventBroadcaster
62 * @see ifc.accessibility._XAccessibleContext
64 public class AccessibleBrowseBoxTable extends TestCase {
65 static XDesktop the_Desk;
66 static XTextDocument xTextDoc;
68 /**
69 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
71 protected void initialize(TestParameters Param, PrintWriter log) {
72 the_Desk = UnoRuntime.queryInterface(XDesktop.class,
73 DesktopTools.createDesktop(
74 (XMultiServiceFactory)Param.getMSF()));
77 /**
78 * Disposes the document, if exists, created in
79 * <code>createTestEnvironment</code> method.
81 protected void cleanup(TestParameters Param, PrintWriter log) {
82 log.println("disposing xTextDoc");
84 if (xTextDoc != null) {
85 xTextDoc.dispose();
89 /**
90 * Creates a text document. Opens the DataSource browser.
91 * Creates an instance of the service
92 * <code>com.sun.star.awt.Toolkit</code> and gets active top window.
93 * Then obtains an accessible object with the role
94 * <code>AccessibleRole.TABLE</code> and with the name
95 * <code>"Table"</code>.
96 * Object relations created :
97 * <ul>
98 * <li> <code>'EventProducer'</code> for
99 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
100 * method <code>fireEvent()</code> is empty because object is transient
101 * </li>
102 * </ul>
104 * @param tParam test parameters
105 * @param log writer to log information while testing
107 * @see com.sun.star.awt.Toolkit
108 * @see com.sun.star.accessibility.AccessibleRole
109 * @see ifc.accessibility._XAccessibleEventBroadcaster
110 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
112 protected TestEnvironment createTestEnvironment(TestParameters tParam,
113 PrintWriter log) {
114 log.println("creating a test environment");
116 if (xTextDoc != null) {
117 xTextDoc.dispose();
120 // get a soffice factory object
121 SOfficeFactory SOF = SOfficeFactory.getFactory(
122 (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 PropertyValue[] noArgs = new PropertyValue[0];
153 getting.dispatch(the_url, noArgs);
155 shortWait();
157 XFrame the_frame1 = the_Desk.getCurrentFrame();
159 if (the_frame1 == null) {
160 log.println("Current frame was not found !!!");
163 XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);
164 XController xCont = the_frame2.getController();
166 the_frame2.setName("DatasourceBrowser");
168 final PropertyValue[] params = new PropertyValue[3];
169 PropertyValue param1 = new PropertyValue();
170 param1.Name = "DataSourceName";
171 param1.Value = "Bibliography";
172 params[0] = param1;
174 PropertyValue param2 = new PropertyValue();
175 param2.Name = "CommandType";
176 param2.Value = new Integer(com.sun.star.sdb.CommandType.TABLE);
177 params[1] = param2;
179 PropertyValue param3 = new PropertyValue();
180 param3.Name = "Command";
181 param3.Value = "biblio";
182 params[2] = param3;
184 final XSelectionSupplier xSelect = UnoRuntime.queryInterface(
185 XSelectionSupplier.class, xCont);
188 XInterface oObj = null;
190 AccessibilityTools at = new AccessibilityTools();
192 XWindow xWindow = secondController.getFrame().getContainerWindow();
194 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
196 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE,
197 "Table");
199 log.println("ImplementationName: " + util.utils.getImplName(oObj));
201 TestEnvironment tEnv = new TestEnvironment(oObj);
203 tEnv.addObjRelation("EventProducer",
204 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
205 public void fireEvent() {
206 try {
207 xSelect.select(params);
208 } catch (com.sun.star.lang.IllegalArgumentException ex) {
213 return tEnv;
217 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
218 * reset</code> call.
220 private void shortWait() {
221 try {
222 Thread.sleep(5000);
223 } catch (InterruptedException e) {
224 System.out.println("While waiting :" + e);