bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _svtools / AccessibleBrowseBoxTableCell.java
blob8f699db8d8120faa7a7631de163a5e76ead9bd32
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 .
19 package mod._svtools;
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.XInitialization;
42 import com.sun.star.lang.XMultiServiceFactory;
43 import com.sun.star.text.XTextDocument;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
46 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 AccessibleBrowseBoxTableCell extends TestCase {
66 static XDesktop the_Desk;
67 static XTextDocument xTextDoc;
69 /**
70 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
72 protected void initialize(TestParameters Param, PrintWriter log) {
73 the_Desk = UnoRuntime.queryInterface(
74 XDesktop.class, DesktopTools.createDesktop((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) {
83 log.println("disposing xTextDoc");
85 if (xTextDoc != null) {
86 xTextDoc.dispose();
90 /**
91 * Creates a text document. Opens the DataSource browser and loads
92 * the table. Creates an instance of the service
93 * <code>com.sun.star.awt.Toolkit</code> and gets active top window.
94 * Then obtains an accessible object with the role
95 * <code>AccessibleRole.TABLE_CELL</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, PrintWriter log) {
114 log.println( "creating a test environment" );
116 if (xTextDoc != null) xTextDoc.dispose();
118 // get a soffice factory object
119 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
121 try {
122 log.println( "creating a text document" );
123 xTextDoc = SOF.createTextDoc(null);
124 } catch ( com.sun.star.uno.Exception e ) {
125 // Some exception occurs.FAILED
126 e.printStackTrace( log );
127 throw new StatusException( "Couldn't create document", e );
130 shortWait();
132 XModel aModel1 = UnoRuntime.queryInterface(XModel.class, xTextDoc);
134 XController secondController = aModel1.getCurrentController();
137 XDispatchProvider aProv = UnoRuntime.queryInterface(XDispatchProvider.class,secondController);
139 XDispatch getting = null;
141 log.println( "opening DatasourceBrowser" );
142 URL the_url = new URL();
143 the_url.Complete = ".component:DB/DataSourceBrowser";
144 getting = aProv.queryDispatch(the_url,"_beamer",12);
145 PropertyValue[] noArgs = new PropertyValue[0];
146 getting.dispatch(the_url,noArgs);
148 shortWait();
150 XFrame the_frame1 = the_Desk.getCurrentFrame();
152 if (the_frame1 == null) {
153 log.println("Current frame was not found !!!");
156 XFrame the_frame2 = the_frame1.findFrame("_beamer",4);
158 the_frame2.setName("DatasourceBrowser");
160 XInterface oObj = null;
162 UnoRuntime.queryInterface(
163 XInitialization.class, the_frame2.getController());
165 Object[] params = new Object[3];
166 PropertyValue param1 = new PropertyValue();
167 param1.Name = "DataSourceName";
168 param1.Value = "Bibliography";
169 params[0] = param1;
170 PropertyValue param2 = new PropertyValue();
171 param2.Name = "CommandType";
172 param2.Value = new Integer(com.sun.star.sdb.CommandType.TABLE);
173 params[1] = param2;
174 PropertyValue param3 = new PropertyValue();
175 param3.Name = "Command";
176 param3.Value = "biblio";
177 params[2] = param3;
179 shortWait();
181 AccessibilityTools at = new AccessibilityTools();
183 XWindow xWindow = secondController.getFrame().getContainerWindow();
185 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
187 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE_CELL);
189 log.println("ImplementationName: "+util.utils.getImplName(oObj));
191 TestEnvironment tEnv = new TestEnvironment( oObj );
193 tEnv.addObjRelation("EventProducer",
194 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
195 public void fireEvent() {
199 return tEnv;
203 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
204 * reset</code> call.
206 private void shortWait() {
207 try {
208 Thread.sleep(5000);
209 } catch (InterruptedException e) {
210 System.out.println("While waiting :" + e) ;